Classes

Classes in GCC include classes, structs and unions.

A class is either a RECORD_TYPE (structs/classes) or a UNION_TYPE.

Every class has a TREE_BINFO, obtained with TYPE_BINFO. BINFOs represent base classes. Although every BINFO assumes it is its own base class, the base BINFOs for a particular class are held in a vector. This vector can be accessed using BINFO_BASE_BINFO and BINFO_BASE_ITERATE. The vector can be accessed directly using BINFO_BASE_BINFOS. BINFO_N_BASE_BINFOS returns the length of this vector. BINFO_BASE_APPEND will a add a new BINFO. BINFO_TYPE will return the class type of a BINFO. The access to a base type can be found using BINFO_BASE_ACCESS, producing access_public_node, access_private_node or access_protected_node. If bases are always public, BINFO_BASE_ACCESS may be null.

Classes are commonly referred to as "types", since classes are technically their own types.

You can get the name of a class by doing IDENTIFIER_POINTER(DECL_NAME(TYPE_NAME(my_class))). You can get the name of a TREE_BINFO by doing IDENTIFIER_POINTER(DECL_NAME(TYPE_NAME(BINFO_TYPE(my_binfo)))).

Class Members
Almost all members are accessible on the TYPE_FIELDS list. Given one member, the next can be found by following the TREE_CHAIN. All nodes in this list are declaration nodes. FIELD_DECL s represent non-static data members, VAR_DECL s are used to represent static data members, and TYPE_DECL s represent types. TYPE_VFIELD s may also appear on this list.

You can cycle through members using:

For example, if you had the following class:

The following fields would be returned: hello, goodbye, AmazingClass (yes, it seems to have itself as a field by default).