Next: Statements for C++, Previous: Classes, Up: C and C++ Trees
A function is represented by a FUNCTION_DECL
node. A set of
overloaded functions is sometimes represented by an 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
.
The following macros and functions can be used on a FUNCTION_DECL
:
DECL_MAIN_P
::code
.
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
These functions represent stub code that adjusts the 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 nonzero
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.
TYPE_RAISES_EXCEPTIONS
NULL
, is comprised of nodes
whose TREE_VALUE
represents a type.
TYPE_NOTHROW_P
()
'.
DECL_ARRAY_DELETE_OPERATOR_P
operator delete[]
.