Next: Declarations, Previous: Scopes, Up: Trees
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_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_FRIEND_CONTEXT
macro can be used to determine the class in
which it was defined. For example, in
class C { friend void f() {} };
the DECL_CONTEXT
for f
will be the
global_namespace
, but the DECL_FRIEND_CONTEXT
will be the
RECORD_TYPE
for C
.
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.