📄 c-tree.texi
字号:
If @code{DECL_C_BIT_FIELD} holds, this field is a bit-field.
@item NAMESPACE_DECL
@xref{Namespaces}.
@item TEMPLATE_DECL
These nodes are used to represent class, function, and variable (static
data member) templates. The @code{DECL_TEMPLATE_SPECIALIZATIONS} are a
@code{TREE_LIST}. The @code{TREE_VALUE} of each node in the list is a
@code{TEMPLATE_DECL}s or @code{FUNCTION_DECL}s representing
specializations (including instantiations) of this template. Back-ends
can safely ignore @code{TEMPLATE_DECL}s, but should examine
@code{FUNCTION_DECL} nodes on the specializations list just as they
would ordinary @code{FUNCTION_DECL} nodes.
For a class template, the @code{DECL_TEMPLATE_INSTANTIATIONS} list
contains the instantiations. The @code{TREE_VALUE} of each node is an
instantiation of the class. The @code{DECL_TEMPLATE_SPECIALIZATIONS}
contains partial specializations of the class.
@item USING_DECL
Back-ends can safely ignore these nodes.
@end table
@c ---------------------------------------------------------------------
@c Functions
@c ---------------------------------------------------------------------
@node Functions
@section Functions
@cindex function
@tindex FUNCTION_DECL
@tindex OVERLOAD
@findex OVL_CURRENT
@findex OVL_NEXT
A function is represented by a @code{FUNCTION_DECL} node. A set of
overloaded functions is sometimes represented by a @code{OVERLOAD} node.
An @code{OVERLOAD} node is not a declaration, so none of the
@samp{DECL_} macros should be used on an @code{OVERLOAD}. An
@code{OVERLOAD} node is similar to a @code{TREE_LIST}. Use
@code{OVL_CURRENT} to get the function associated with an
@code{OVERLOAD} node; use @code{OVL_NEXT} to get the next
@code{OVERLOAD} node in the list of overloaded functions. The macros
@code{OVL_CURRENT} and @code{OVL_NEXT} are actually polymorphic; you can
use them to work with @code{FUNCTION_DECL} nodes as well as with
overloads. In the case of a @code{FUNCTION_DECL}, @code{OVL_CURRENT}
will always return the function itself, and @code{OVL_NEXT} will always
be @code{NULL_TREE}.
To determine the scope of a function, you can use the
@code{DECL_REAL_CONTEXT} macro. This macro will return the class
(either a @code{RECORD_TYPE} or a @code{UNION_TYPE}) or namespace (a
@code{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
@code{DECL_CLASS_CONTEXT} macro can be used to determine the class in
which it was defined. For example, in
@example
class C @{ friend void f() @{@} @};
@end example
the @code{DECL_REAL_CONTEXT} for @code{f} will be the
@code{global_namespace}, but the @code{DECL_CLASS_CONTEXT} will be the
@code{RECORD_TYPE} for @code{C}.
The @code{DECL_REAL_CONTEXT} and @code{DECL_CLASS_CONTEXT} are not
available in C; instead you should simply use @code{DECL_CONTEXT}. In C,
the @code{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 @code{DECL_CONTEXT} for the
referenced @code{VAR_DECL}. If the @code{DECL_CONTEXT} for the
referenced @code{VAR_DECL} is not the same as the function currently
being processed, and neither @code{DECL_EXTERNAL} nor @code{DECL_STATIC}
hold, then the reference is to a local variable in a containing
function, and the back-end must take appropriate action.
@menu
* Function Basics:: Function names, linkage, and so forth.
* Function Bodies:: The statements that make up a function body.
@end menu
@c ---------------------------------------------------------------------
@c Function Basics
@c ---------------------------------------------------------------------
@node Function Basics
@subsection Function Basics
@cindex constructor
@cindex destructor
@cindex copy constructor
@cindex assignment operator
@cindex linkage
@findex DECL_NAME
@findex DECL_ASSEMBLER_NAME
@findex TREE_PUBLIC
@findex DECL_LINKONCE_P
@findex DECL_FUNCTION_MEMBER_P
@findex DECL_CONSTRUCTOR_P
@findex DECL_DESTRUCTOR_P
@findex DECL_OVERLOADED_OPERATOR_P
@findex DECL_CONV_FN_P
@findex DECL_ARTIFICIAL
@findex DECL_GLOBAL_CTOR_P
@findex DECL_GLOBAL_DTOR_P
@findex GLOBAL_INIT_PRIORITY
The following macros and functions can be used on a @code{FUNCTION_DECL}:
@ftable @code
@item DECL_MAIN_P
This predicate holds for a function that is the program entry point
@code{::code}.
@item DECL_NAME
This macro returns the unqualified name of the function, as an
@code{IDENTIFIER_NODE}. For an instantiation of a function template,
the @code{DECL_NAME} is the unqualified name of the template, not
something like @code{f<int>}. The value of @code{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.
@item DECL_ASSEMBLER_NAME
This macro returns the mangled name of the function, also an
@code{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
@code{DECL_ASSEMBLER_NAME} itself.)
@item DECL_EXTERNAL
This predicate holds if the function is undefined.
@item TREE_PUBLIC
This predicate holds if the function has external linkage.
@item DECL_LOCAL_FUNCTION_P
This predicate holds if the function was declared at block scope, even
though it has a global scope.
@item DECL_ANTICIPATED
This predicate holds if the function is a built-in function but its
prototype is not yet explicitly declared.
@item DECL_EXTERN_C_FUNCTION_P
This predicate holds if the function is declared as an
`@code{extern "C"}' function.
@item 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 @code{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.
@item DECL_FUNCTION_MEMBER_P
This macro holds if the function is a member of a class, rather than a
member of a namespace.
@item DECL_STATIC_FUNCTION_P
This predicate holds if the function a static member function.
@item DECL_NONSTATIC_MEMBER_FUNCTION_P
This macro holds for a non-static member function.
@item DECL_CONST_MEMFUNC_P
This predicate holds for a @code{const}-member function.
@item DECL_VOLATILE_MEMFUNC_P
This predicate holds for a @code{volatile}-member function.
@item DECL_CONSTRUCTOR_P
This macro holds if the function is a constructor.
@item DECL_NONCONVERTING_P
This predicate holds if the constructor is a non-converting constructor.
@item DECL_COMPLETE_CONSTRUCTOR_P
This predicate holds for a function which is a constructor for an object
of a complete type.
@item DECL_BASE_CONSTRUCTOR_P
This predicate holds for a function which is a constructor for a base
class sub-object.
@item DECL_COPY_CONSTRUCTOR_P
This predicate holds for a function which is a copy-constructor.
@item DECL_DESTRUCTOR_P
This macro holds if the function is a destructor.
@item DECL_COMPLETE_DESTRUCTOR_P
This predicate holds if the function is the destructor for an object a
complete type.
@item DECL_OVERLOADED_OPERATOR_P
This macro holds if the function is an overloaded operator.
@item DECL_CONV_FN_P
This macro holds if the function is a type-conversion operator.
@item DECL_GLOBAL_CTOR_P
This predicate holds if the function is a file-scope initialization
function.
@item DECL_GLOBAL_DTOR_P
This predicate holds if the function is a file-scope finalization
function.
@item DECL_THUNK_P
This predicate holds if the function is a thunk.
These functions represent stub code that adjusts the @code{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
@code{this} pointer; the thunk should add @code{THUNK_DELTA} to this
value. (The @code{THUNK_DELTA} is an @code{int}, not an
@code{INTEGER_CST}.)
Then, if @code{THUNK_VCALL_OFFSET} (an @code{INTEGER_CST}) is non-zero
the adjusted @code{this} pointer must be adjusted again. The complete
calculation is given by the following pseudo-code:
@example
this += THUNK_DELTA
if (THUNK_VCALL_OFFSET)
this += (*((ptrdiff_t **) this))[THUNK_VCALL_OFFSET]
@end example
Finally, the thunk should jump to the location given
by @code{DECL_INITIAL}; this will always be an expression for the
address of a function.
@item DECL_NON_THUNK_FUNCTION_P
This predicate holds if the function is @emph{not} a thunk function.
@item GLOBAL_INIT_PRIORITY
If either @code{DECL_GLOBAL_CTOR_P} or @code{DECL_GLOBAL_DTOR_P} holds,
then this gives the initialization priority for the function. The
linker will arrange that all functions for which
@code{DECL_GLOBAL_CTOR_P} holds are run in increasing order of priority
before @code{main} is called. When the program exits, all functions for
which @code{DECL_GLOBAL_DTOR_P} holds are run in the reverse order.
@item 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.
@item DECL_ARGUMENTS
This macro returns the @code{PARM_DECL} for the first argument to the
function. Subsequent @code{PARM_DECL} nodes can be obtained by
following the @code{TREE_CHAIN} links.
@item DECL_RESULT
This macro returns the @code{RESULT_DECL} for the function.
@item TREE_TYPE
This macro returns the @code{FUNCTION_TYPE} or @code{METHOD_TYPE} for
the function.
@item TYPE_RAISES_EXCEPTIONS
This macro returns the list of exceptions that a (member-)function can
raise. The returned list, if non @code{NULL}, is comprised of nodes
whose @code{TREE_VALUE} represents a type.
@item TYPE_NOTHROW_P
This predicate holds when the exception-specification of its arguments
if of the form `@code{()}'.
@item DECL_ARRAY_DELETE_OPERATOR_P
This predicate holds if the function an overloaded
@code{operator delete[]}.
@end ftable
@c ---------------------------------------------------------------------
@c Function Bodies
@c ---------------------------------------------------------------------
@node Function Bodies
@subsection Function Bodies
@cindex function body
@cindex statements
@tindex ASM_STMT
@findex ASM_STRING
@findex ASM_CV_QUAL
@findex ASM_INPUTS
@findex ASM_OUTPUTS
@findex ASM_CLOBBERS
@tindex BREAK_STMT
@tindex CLEANUP_STMT
@findex CLEANUP_DECL
@findex CLEANUP_EXPR
@tindex COMPOUND_STMT
@findex COMPOUND_BODY
@tindex CONTINUE_STMT
@tindex DECL_STMT
@findex DECL_STMT_DECL
@tindex DO_STMT
@findex DO_BODY
@findex DO_COND
@tindex EMPTY_CLASS_EXPR
@tindex EXPR_STMT
@findex EXPR_STMT_EXPR
@tindex FOR_STMT
@findex FOR_INIT_STMT
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -