Elaborated type specifiers

Elaborated type specifiers are one of these four possibilities: class, struct, union or enum.

In C++ they can often be skipped (but may be useful; see this interesting topic for example). In C code they are mandatory.

Let’s consider the following c++ file:

class A {};

A a1;
class A a2;

void function(A arg1, class A arg2);

The following code will show how the elaborated type specifiers are treated in pygccxml. Please note that this feature is only available since recent versions of CastXML (Mar 1, 2017), and a special flag needs to be passed to pygccxml to make this work (castxml_epic_version=1).

from pygccxml import utils
from pygccxml import declarations
from pygccxml import parser

# Find out the c++ parser
generator_path, generator_name = utils.find_xml_generator()

# Configure the xml generator
xml_generator_config = parser.xml_generator_configuration_t(
    xml_generator_path=generator_path,
    xml_generator=generator_name,
    castxml_epic_version=1)

# The c++ file we want to parse
filename = this_module_dir_path + "/" + filename

decls = parser.parse([filename], xml_generator_config)
global_namespace = declarations.get_global_namespace(decls)

a1 = global_namespace.variable("a1")
print(str(a1.decl_type), type(a1.decl_type))
# > 'A', <class 'pygccxml.declarations.cpptypes.declarated_t'>

print(declarations.is_elaborated(a1.decl_type))
# > False

a2 = global_namespace.variable("a2")
print(str(a2.decl_type), type(a2.decl_type))
# > 'class ::A', <class 'pygccxml.declarations.cpptypes.elaborated_t'>

print(declarations.is_elaborated(a2.decl_type))
# > True

base = declarations.remove_elaborated(a2.decl_type)
print(str(base), type(base))
# > 'A', <class 'pygccxml.declarations.cpptypes.declarated_t'>

# The same can be done with function arguments:
fun = global_namespace.free_function("function")
print(type(fun.arguments[0].decl_type), type(fun.arguments[1].decl_type))
# > <class 'pygccxml.declarations.cpptypes.declarated_t'>,
#   <class 'pygccxml.declarations.cpptypes.elaborated_t'>