A function is represented by a FUNCTION_DECL node. A set of
overloaded functions is sometimes represented by a OVERLOAD node.
An OVERLOAD node is not a declaration, so none of the
`DECL_' macros should be used on an OVERLOAD. An
OVERLOAD node is similar to a TREE_LIST. Use
OVL_CURRENT to get the function associated with an
OVERLOAD node; use OVL_NEXT to get the next
OVERLOAD node in the list of overloaded functions. The macros
OVL_CURRENT and OVL_NEXT are actually polymorphic; you can
use them to work with FUNCTION_DECL nodes as well as with
overloads. In the case of a FUNCTION_DECL, OVL_CURRENT
will always return the function itself, and OVL_NEXT will always
be NULL_TREE.
To determine the scope of a function, you can use the
DECL_REAL_CONTEXT macro. This macro will return the class
(either a RECORD_TYPE or a UNION_TYPE) or namespace (a
NAMESPACE_DECL) of which the function is a member. For a virtual
function, this macro returns the class in which the function was
actually defined, not the base class in which the virtual declaration
occurred. If a friend function is defined in a class scope, the
DECL_CLASS_CONTEXT macro can be used to determine the class in
which it was defined. For example, in
class C { friend void f() {} };
the DECL_REAL_CONTEXT for f will be the
global_namespace, but the DECL_CLASS_CONTEXT will be the
RECORD_TYPE for C.
The DECL_REAL_CONTEXT and DECL_CLASS_CONTEXT are not
available in C; instead you should simply use DECL_CONTEXT. In C,
the DECL_CONTEXT for a function maybe another function. This
representation indicates that the GNU nested function extension is in
use. For details on the semantics of nested functions, see the GCC
Manual. The nested function can refer to local variables in its
containing function. Such references are not explicitly marked in the
tree structure; back-ends must look at the DECL_CONTEXT for the
referenced VAR_DECL. If the DECL_CONTEXT for the
referenced VAR_DECL is not the same as the function currently
being processed, and neither DECL_EXTERNAL nor DECL_STATIC
hold, then the reference is to a local variable in a containing
function, and the back-end must take appropriate action.
The following macros and functions can be used on a FUNCTION_DECL:
DECL_MAIN_P
::code.
DECL_NAME
IDENTIFIER_NODE. For an instantiation of a function template,
the DECL_NAME is the unqualified name of the template, not
something like f<int>. The value of DECL_NAME is
undefined when used on a constructor, destructor, overloaded operator,
or type-conversion operator, or any function that is implicitly
generated by the compiler. See below for macros that can be used to
distinguish these cases.
DECL_ASSEMBLER_NAME
IDENTIFIER_NODE. This name does not contain leading underscores
on systems that prefix all identifiers with underscores. The mangled
name is computed in the same way on all platforms; if special processing
is required to deal with the object file format used on a particular
platform, it is the responsibility of the back-end to perform those
modifications. (Of course, the back-end should not modify
DECL_ASSEMBLER_NAME itself.)
DECL_EXTERNAL
TREE_PUBLIC
DECL_LOCAL_FUNCTION_P
DECL_ANTICIPATED
DECL_EXTERN_C_FUNCTION_P
extern "C"' function.
DECL_LINKONCE_P
DECL_LINKONCE_P holds; G++
instantiates needed templates in all translation units which require them,
and then relies on the linker to remove duplicate instantiations.
FIXME: This macro is not yet implemented.
DECL_FUNCTION_MEMBER_P
DECL_STATIC_FUNCTION_P
DECL_NONSTATIC_MEMBER_FUNCTION_P
DECL_CONST_MEMFUNC_P
const-member function.
DECL_VOLATILE_MEMFUNC_P
volatile-member function.
DECL_CONSTRUCTOR_P
DECL_NONCONVERTING_P
DECL_COMPLETE_CONSTRUCTOR_P
DECL_BASE_CONSTRUCTOR_P
DECL_COPY_CONSTRUCTOR_P
DECL_DESTRUCTOR_P
DECL_COMPLETE_DESTRUCTOR_P
DECL_OVERLOADED_OPERATOR_P
DECL_CONV_FN_P
DECL_GLOBAL_CTOR_P
DECL_GLOBAL_DTOR_P
DECL_THUNK_P
this pointer
and then jumps to another function. When the jumped-to function
returns, control is transferred directly to the caller, without
returning to the thunk. The first parameter to the thunk is always the
this pointer; the thunk should add THUNK_DELTA to this
value. (The THUNK_DELTA is an int, not an
INTEGER_CST.)
Then, if THUNK_VCALL_OFFSET (an INTEGER_CST) is non-zero
the adjusted this pointer must be adjusted again. The complete
calculation is given by the following pseudo-code:
this += THUNK_DELTA if (THUNK_VCALL_OFFSET) this += (*((ptrdiff_t **) this))[THUNK_VCALL_OFFSET]Finally, the thunk should jump to the location given by
DECL_INITIAL; this will always be an expression for the
address of a function.
DECL_NON_THUNK_FUNCTION_P
GLOBAL_INIT_PRIORITY
DECL_GLOBAL_CTOR_P or DECL_GLOBAL_DTOR_P holds,
then this gives the initialization priority for the function. The
linker will arrange that all functions for which
DECL_GLOBAL_CTOR_P holds are run in increasing order of priority
before main is called. When the program exits, all functions for
which DECL_GLOBAL_DTOR_P holds are run in the reverse order.
DECL_ARTIFICIAL
DECL_ARGUMENTS
PARM_DECL for the first argument to the
function. Subsequent PARM_DECL nodes can be obtained by
following the TREE_CHAIN links.
DECL_RESULT
RESULT_DECL for the function.
TREE_TYPE
FUNCTION_TYPE or METHOD_TYPE for
the function.
TYPE_RAISES_EXCEPTIONS
NULL, is comprised of nodes
whose TREE_VALUE represents a type.
TYPE_NOTHROW_P
()'.
DECL_ARRAY_DELETE_OPERATOR_P
operator delete[].
A function that has a definition in the current translation unit will
have a non-NULL DECL_INITIAL. However, back-ends should not make
use of the particular value given by DECL_INITIAL.
The DECL_SAVED_TREE macro will give the complete body of the
function. This node will usually be a COMPOUND_STMT representing
the outermost block of the function, but it may also be a
TRY_BLOCK, a RETURN_INIT, or any other valid statement.
There are tree nodes corresponding to all of the source-level statement constructs. These are enumerated here, together with a list of the various macros that can be used to obtain information about them. There are a few macros that can be used with all statements:
STMT_LINENO
CASE_LABEL below
as if it were a statement, they do not allow the use of
STMT_LINENO. There is no way to obtain the line number for a
CASE_LABEL.
Statements do not contain information about
the file from which they came; that information is implicit in the
FUNCTION_DECL from which the statements originate.
STMT_IS_FULL_EXPR_P
STMT_IS_FULL_EXPR_P set. Temporaries
created during such statements should be destroyed when the innermost
enclosing statement with STMT_IS_FULL_EXPR_P set is exited.
Here is the list of the various statement nodes, and the macros used to access them. This documentation describes the use of these nodes in non-template functions (including instantiations of template functions). In template functions, the same nodes are used, but sometimes in slightly different ways.
Many of the statements have substatements. For example, a while
loop will have a body, which is itself a statement. If the substatement
is NULL_TREE, it is considered equivalent to a statement
consisting of a single ;, i.e., an expression statement in which
the expression has been omitted. A substatement may in fact be a list
of statements, connected via their TREE_CHAINs. So, you should
always process the statement tree by looping over substatements, like
this:
void process_stmt (stmt)
tree stmt;
{
while (stmt)
{
switch (TREE_CODE (stmt))
{
case IF_STMT:
process_stmt (THEN_CLAUSE (stmt));
/* More processing here. */
break;
...
}
stmt = TREE_CHAIN (stmt);
}
}
In other words, while the then clause of an if statement
in C++ can be only one statement (although that one statement may be a
compound statement), the intermediate representation will sometimes use
several statements chained together.
ASM_STMT
asm ("mov x, y");
The ASM_STRING macro will return a STRING_CST node for
"mov x, y". If the original statement made use of the
extended-assembly syntax, then ASM_OUTPUTS,
ASM_INPUTS, and ASM_CLOBBERS will be the outputs, inputs,
and clobbers for the statement, represented as STRING_CST nodes.
The extended-assembly syntax looks like:
asm ("fsinx %1,%0" : "=f" (result) : "f" (angle));
The first string is the ASM_STRING, containing the instruction
template. The next two strings are the output and inputs, respectively;
this statement has no clobbers. As this example indicates, "plain"
assembly statements are merely a special case of extended assembly
statements; they have no cv-qualifiers, outputs, inputs, or clobbers.
All of the strings will be NUL-terminated, and will contain no
embedded NUL-characters.
If the assembly statement is declared volatile, or if the
statement was not an extended assembly statement, and is therefore
implicitly volatile, then the predicate ASM_VOLATILE_P will hold
of the ASM_STMT.
BREAK_STMT
break statement. There are no additional
fields.
CASE_LABEL
case label, range of case labels, or a
default label. If CASE_LOW is NULL_TREE, then this is a a
default label. Otherwise, if CASE_HIGH is NULL_TREE, then
this is an ordinary case label. In this case, CASE_LOW is
an expression giving the value of the label. Both CASE_LOW and
CASE_HIGH are INTEGER_CST nodes. These values will have
the same type as the condition expression in the switch statement.
Otherwise, if both CASE_LOW and CASE_HIGH are defined, the
statement is a range of case labels. Such statements originate with the
extension that allows users to write things of the form:
case 2 ... 5:The first value will be
CASE_LOW, while the second will be
CASE_HIGH.
CLEANUP_STMT
CLEANUP_DECL will be
the VAR_DECL destroyed. Otherwise, CLEANUP_DECL will be
NULL_TREE. In any case, the CLEANUP_EXPR is the
expression to execute. The cleanups executed on exit from a scope
should be run in the reverse order of the order in which the associated
CLEANUP_STMTs were encountered.
COMPOUND_STMT
COMPOUND_BODY. Subsequent substatements are found by
following the TREE_CHAIN link from one substatement to the next.
CONTINUE_STMT
continue statement. There are no additional
fields.
CTOR_STMT
CTOR_BEGIN_P holds) or end (if
CTOR_END_P holds of the main body of a constructor. See also
SUBOBJECT for more information on how to use these nodes.
DECL_STMT
DECL_STMT_DECL macro
can be used to obtain the entity declared. This declaration may be a
LABEL_DECL, indicating that the label declared is a local label.
(As an extension, GCC allows the declaration of labels with scope.) In
C, this declaration may be a FUNCTION_DECL, indicating the
use of the GCC nested function extension. For more information,
see section Functions.
DO_STMT
do loop. The body of the loop is given by
DO_BODY while the termination condition for the loop is given by
DO_COND. The condition for a do-statement is always an
expression.
EMPTY_CLASS_EXPR
TREE_TYPE represents the type of the object.
EXPR_STMT
EXPR_STMT_EXPR to
obtain the expression.
FOR_STMT
for statement. The FOR_INIT_STMT is
the initialization statement for the loop. The FOR_COND is the
termination condition. The FOR_EXPR is the expression executed
right before the FOR_COND on each loop iteration; often, this
expression increments a counter. The body of the loop is given by
FOR_BODY. Note that FOR_INIT_STMT and FOR_BODY
return statements, while FOR_COND and FOR_EXPR return
expressions.
GOTO_STMT
goto statement. The GOTO_DESTINATION
will usually be a LABEL_DECL. However, if the "computed
goto" extension has been used, the GOTO_DESTINATION will be an
arbitrary expression indicating the destination. This expression will
always have pointer type.
IF_STMT
if statement. The IF_COND is the
expression.
If the condition is a TREE_LIST, then the TREE_PURPOSE is
a statement (usually a DECL_STMT). Each time the coondition is
evaluated, the statement should be executed. Then, the
TREE_VALUE should be used as the conditional expression itself.
This representation is used to handle C++ code like this:
if (int i = 7) ...where there is a new local variable (or variables) declared within the condition. The
THEN_CLAUSE represents the statement given by the then
condition, while the ELSE_CLAUSE represents the statement given
by the else condition.
LABEL_STMT
LABEL_DECL declared by this
statement can be obtained with the LABEL_STMT_LABEL macro. The
IDENTIFIER_NODE giving the name of the label can be obtained from
the LABEL_DECL with DECL_NAME.
RETURN_INIT
S f(int) return s {...}
then there will be a RETURN_INIT. There is never a named
returned value for a constructor. The first argument to the
RETURN_INIT is the name of the object returned; the second
argument is the initializer for the object. The object is initialized
when the RETURN_INIT is encountered. The object referred to is
the actual object returned; this extension is a manual way of doing the
"return-value optimization." Therefore, the object must actually be
constructed in the place where the object will be returned.
RETURN_STMT
return statement. The RETURN_EXPR is
the expression returned; it will be NULL_TREE if the statement
was just
return;
SCOPE_STMT
SCOPE_BEGIN_P holds, this statement represents the beginning of a
scope; if SCOPE_END_P holds this statement represents the end of
a scope. On exit from a scope, all cleanups from CLEANUP_STMTs
occurring in the scope must be run, in reverse order to the order in
which they were encountered. If SCOPE_NULLIFIED_P or
SCOPE_NO_CLEANUPS_P holds of the scope, back-ends should behave
as if the SCOPE_STMT were not present at all.
START_CATCH_STMT
START_CATCH_TYPE is the type of
exception that will be caught by this handler; it is equal (by pointer
equality) to CATCH_ALL_TYPE if this handler is for all types.
SUBOBJECT
this is fully constructed. If, after this point, an
exception is thrown before a CTOR_STMT with CTOR_END_P set
is encountered, the SUBOBJECT_CLEANUP must be executed. The
cleanups must be executed in the reverse order in which they appear.
SWITCH_STMT
switch statement. The SWITCH_COND is
the expression on which the switch is occurring. See the documentation
for an IF_STMT for more information on the representation used
for the condition. The SWITCH_BODY is the body of the switch
statement.
TRY_BLOCK
try block. The body of the try block is
given by TRY_STMTS. Each of the catch blocks is a HANDLER
node. The first handler is given by TRY_HANDLERS. Subsequent
handlers are obtained by following the TREE_CHAIN link from one
handler to the next. The body of the handler is given by
HANDLER_BODY.
If CLEANUP_P holds of the TRY_BLOCK, then the
TRY_HANDLERS will not be a HANDLER node. Instead, it will
be an expression that should be executed if an exception is thrown in
the try block. It must rethrow the exception after executing that code.
And, if an exception is thrown while the expression is executing,
terminate must be called.
WHILE_STMT
while loop. The WHILE_COND is the
termination condition for the loop. See the documentation for an
IF_STMT for more information on the representation used for the
condition.
The WHILE_BODY is the body of the loop.
Go to the first, previous, next, last section, table of contents.