|
| 1 | +# Copyright 2014-2017 Insight Software Consortium. |
| 2 | +# Copyright 2004-2009 Roman Yakovenko. |
| 3 | +# Distributed under the Boost Software License, Version 1.0. |
| 4 | +# See http://www.boost.org/LICENSE_1_0.txt |
| 5 | + |
| 6 | +from pygccxml import utils |
| 7 | +from pygccxml import declarations |
| 8 | +from pygccxml import parser |
| 9 | + |
| 10 | +import os |
| 11 | +import sys |
| 12 | +import warnings |
| 13 | +warnings.simplefilter("error", Warning) |
| 14 | +# Find out the file location within the sources tree |
| 15 | +this_module_dir_path = os.path.abspath( |
| 16 | + os.path.dirname(sys.modules[__name__].__file__)) |
| 17 | + |
| 18 | +# Find out the c++ parser |
| 19 | +generator_path, generator_name = utils.find_xml_generator() |
| 20 | + |
| 21 | +# Configure the xml generator |
| 22 | +xml_generator_config = parser.xml_generator_configuration_t( |
| 23 | + xml_generator_path=generator_path, |
| 24 | + xml_generator=generator_name, |
| 25 | + castxml_epic_version=1) |
| 26 | + |
| 27 | +# The c++ file we want to parse |
| 28 | +filename = "example.hpp" |
| 29 | +filename = this_module_dir_path + "/" + filename |
| 30 | + |
| 31 | +decls = parser.parse([filename], xml_generator_config) |
| 32 | +global_namespace = declarations.get_global_namespace(decls) |
| 33 | + |
| 34 | +a1 = global_namespace.variable("a1") |
| 35 | +print(str(a1.decl_type), type(a1.decl_type)) |
| 36 | +# > 'A', <class 'pygccxml.declarations.cpptypes.declarated_t'> |
| 37 | + |
| 38 | +print(declarations.is_elaborated(a1.decl_type)) |
| 39 | +# > False |
| 40 | + |
| 41 | +a2 = global_namespace.variable("a2") |
| 42 | +print(str(a2.decl_type), type(a2.decl_type)) |
| 43 | +# > 'class ::A', <class 'pygccxml.declarations.cpptypes.elaborated_t'> |
| 44 | + |
| 45 | +print(declarations.is_elaborated(a2.decl_type)) |
| 46 | +# > True |
| 47 | + |
| 48 | +base = declarations.remove_elaborated(a2.decl_type) |
| 49 | +print(str(base), type(base)) |
| 50 | +# > 'A', <class 'pygccxml.declarations.cpptypes.declarated_t'> |
| 51 | + |
| 52 | +# The same can be done with function arguments: |
| 53 | +fun = global_namespace.free_function("function") |
| 54 | +print(type(fun.arguments[0].decl_type), type(fun.arguments[1].decl_type)) |
| 55 | +# > <class 'pygccxml.declarations.cpptypes.declarated_t'>, |
| 56 | +# <class 'pygccxml.declarations.cpptypes.elaborated_t'> |
0 commit comments