Next: , Up: Functions


8.6.1 Function Basics

The following macros and functions can be used on a FUNCTION_DECL:

DECL_MAIN_P
This predicate holds for a function that is the program entry point ::code.
DECL_NAME
This macro returns the unqualified name of the function, as an 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
This macro returns the mangled name of the function, also an 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.)

Using DECL_ASSEMBLER_NAME will cause additional memory to be allocated (for the mangled name of the entity) so it should be used only when emitting assembly code. It should not be used within the optimizers to determine whether or not two declarations are the same, even though some of the existing optimizers do use it in that way. These uses will be removed over time.

DECL_EXTERNAL
This predicate holds if the function is undefined.
TREE_PUBLIC
This predicate holds if the function has external linkage.
DECL_LOCAL_FUNCTION_P
This predicate holds if the function was declared at block scope, even though it has a global scope.
DECL_ANTICIPATED
This predicate holds if the function is a built-in function but its prototype is not yet explicitly declared.
DECL_EXTERN_C_FUNCTION_P
This predicate holds if the function is declared as an `extern "C"' function.
DECL_LINKONCE_P
This macro holds if multiple copies of this function may be emitted in various translation units. It is the responsibility of the linker to merge the various copies. Template instantiations are the most common example of functions for which 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
This macro holds if the function is a member of a class, rather than a member of a namespace.
DECL_STATIC_FUNCTION_P
This predicate holds if the function a static member function.
DECL_NONSTATIC_MEMBER_FUNCTION_P
This macro holds for a non-static member function.
DECL_CONST_MEMFUNC_P
This predicate holds for a const-member function.
DECL_VOLATILE_MEMFUNC_P
This predicate holds for a volatile-member function.
DECL_CONSTRUCTOR_P
This macro holds if the function is a constructor.
DECL_NONCONVERTING_P
This predicate holds if the constructor is a non-converting constructor.
DECL_COMPLETE_CONSTRUCTOR_P
This predicate holds for a function which is a constructor for an object of a complete type.
DECL_BASE_CONSTRUCTOR_P
This predicate holds for a function which is a constructor for a base class sub-object.
DECL_COPY_CONSTRUCTOR_P
This predicate holds for a function which is a copy-constructor.
DECL_DESTRUCTOR_P
This macro holds if the function is a destructor.
DECL_COMPLETE_DESTRUCTOR_P
This predicate holds if the function is the destructor for an object a complete type.
DECL_OVERLOADED_OPERATOR_P
This macro holds if the function is an overloaded operator.
DECL_CONV_FN_P
This macro holds if the function is a type-conversion operator.
DECL_GLOBAL_CTOR_P
This predicate holds if the function is a file-scope initialization function.
DECL_GLOBAL_DTOR_P
This predicate holds if the function is a file-scope finalization function.
DECL_THUNK_P
This predicate holds if the function is a thunk.

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
This predicate holds if the function is not a thunk function.
GLOBAL_INIT_PRIORITY
If either 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
This macro holds if the function was implicitly generated by the compiler, rather than explicitly declared. In addition to implicitly generated class member functions, this macro holds for the special functions created to implement static initialization and destruction, to compute run-time type information, and so forth.
DECL_ARGUMENTS
This macro returns the PARM_DECL for the first argument to the function. Subsequent PARM_DECL nodes can be obtained by following the TREE_CHAIN links.
DECL_RESULT
This macro returns the RESULT_DECL for the function.
TREE_TYPE
This macro returns the FUNCTION_TYPE or METHOD_TYPE for the function.
TYPE_RAISES_EXCEPTIONS
This macro returns the list of exceptions that a (member-)function can raise. The returned list, if non NULL, is comprised of nodes whose TREE_VALUE represents a type.
TYPE_NOTHROW_P
This predicate holds when the exception-specification of its arguments if of the form `()'.
DECL_ARRAY_DELETE_OPERATOR_P
This predicate holds if the function an overloaded operator delete[].