Next: Internal structure, Up: Declarations
9.5.1 Working with declarations
Some macros can be used with any kind of declaration. These include:
DECL_NAME- This macro returns an
IDENTIFIER_NODEgiving the name of the entity. TREE_TYPE- This macro returns the type of the entity declared.
TREE_FILENAME- This macro returns the name of the file in which the entity was
declared, as a
char*. For an entity declared implicitly by the compiler (like__builtin_memcpy), this will be the string"<internal>". TREE_LINENO- This macro returns the line number at which the entity was declared, as
an
int. DECL_ARTIFICIAL- This predicate holds if the declaration was implicitly generated by the
compiler. For example, this predicate will hold of an implicitly
declared member function, or of the
TYPE_DECLimplicitly generated for a class type. Recall that in C++ code like:struct S {};is roughly equivalent to C code like:
struct S {}; typedef struct S S;The implicitly generated
typedefdeclaration is represented by aTYPE_DECLfor whichDECL_ARTIFICIALholds. DECL_NAMESPACE_SCOPE_P- This predicate holds if the entity was declared at a namespace scope.
DECL_CLASS_SCOPE_P- This predicate holds if the entity was declared at a class scope.
DECL_FUNCTION_SCOPE_P- This predicate holds if the entity was declared inside a function body.
The various kinds of declarations include:
LABEL_DECL- These nodes are used to represent labels in function bodies. For more
information, see Functions. These nodes only appear in block
scopes.
CONST_DECL- These nodes are used to represent enumeration constants. The value of
the constant is given by
DECL_INITIALwhich will be anINTEGER_CSTwith the same type as theTREE_TYPEof theCONST_DECL, i.e., anENUMERAL_TYPE. RESULT_DECL- These nodes represent the value returned by a function. When a value is
assigned to a
RESULT_DECL, that indicates that the value should be returned, via bitwise copy, by the function. You can useDECL_SIZEandDECL_ALIGNon aRESULT_DECL, just as with aVAR_DECL. TYPE_DECL- These nodes represent
typedefdeclarations. TheTREE_TYPEis the type declared to have the name given byDECL_NAME. In some cases, there is no associated name. VAR_DECL- These nodes represent variables with namespace or block scope, as well
as static data members. The
DECL_SIZEandDECL_ALIGNare analogous toTYPE_SIZEandTYPE_ALIGN. For a declaration, you should always use theDECL_SIZEandDECL_ALIGNrather than theTYPE_SIZEandTYPE_ALIGNgiven by theTREE_TYPE, since special attributes may have been applied to the variable to give it a particular size and alignment. You may use the predicatesDECL_THIS_STATICorDECL_THIS_EXTERNto test whether the storage class specifiersstaticorexternwere used to declare a variable.If this variable is initialized (but does not require a constructor), the
DECL_INITIALwill be an expression for the initializer. The initializer should be evaluated, and a bitwise copy into the variable performed. If theDECL_INITIALis theerror_mark_node, there is an initializer, but it is given by an explicit statement later in the code; no bitwise copy is required.GCC provides an extension that allows either automatic variables, or global variables, to be placed in particular registers. This extension is being used for a particular
VAR_DECLifDECL_REGISTERholds for theVAR_DECL, and ifDECL_ASSEMBLER_NAMEis not equal toDECL_NAME. In that case,DECL_ASSEMBLER_NAMEis the name of the register into which the variable will be placed. PARM_DECL- Used to represent a parameter to a function. Treat these nodes
similarly to
VAR_DECLnodes. These nodes only appear in theDECL_ARGUMENTSfor aFUNCTION_DECL.The
DECL_ARG_TYPEfor aPARM_DECLis the type that will actually be used when a value is passed to this function. It may be a wider type than theTREE_TYPEof the parameter; for example, the ordinary type might beshortwhile theDECL_ARG_TYPEisint. FIELD_DECL- These nodes represent non-static data members. The
DECL_SIZEandDECL_ALIGNbehave as forVAR_DECLnodes. The position of the field within the parent record is specified by a combination of three attributes.DECL_FIELD_OFFSETis the position, counting in bytes, of theDECL_OFFSET_ALIGN-bit sized word containing the bit of the field closest to the beginning of the structure.DECL_FIELD_BIT_OFFSETis the bit offset of the first bit of the field within this word; this may be nonzero even for fields that are not bit-fields, sinceDECL_OFFSET_ALIGNmay be greater than the natural alignment of the field's type.If
DECL_C_BIT_FIELDholds, this field is a bit-field. In a bit-field,DECL_BIT_FIELD_TYPEalso contains the type that was originally specified for it, while DECL_TYPE may be a modified type with lesser precision, according to the size of the bit field. NAMESPACE_DECL- See Namespaces.
TEMPLATE_DECL-
These nodes are used to represent class, function, and variable (static
data member) templates. The
DECL_TEMPLATE_SPECIALIZATIONSare aTREE_LIST. TheTREE_VALUEof each node in the list is aTEMPLATE_DECLs orFUNCTION_DECLs representing specializations (including instantiations) of this template. Back ends can safely ignoreTEMPLATE_DECLs, but should examineFUNCTION_DECLnodes on the specializations list just as they would ordinaryFUNCTION_DECLnodes.For a class template, the
DECL_TEMPLATE_INSTANTIATIONSlist contains the instantiations. TheTREE_VALUEof each node is an instantiation of the class. TheDECL_TEMPLATE_SPECIALIZATIONScontains partial specializations of the class. USING_DECL- Back ends can safely ignore these nodes.