📄 c-tree.texi
字号:
@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_PRIORITYThe following macros and functions can be used on a @code{FUNCTION_DECL}:@ftable @code@item DECL_MAIN_PThis predicate holds for a function that is the program entry point@code{::code}.@item DECL_NAMEThis 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, notsomething like @code{f<int>}. The value of @code{DECL_NAME} isundefined when used on a constructor, destructor, overloaded operator,or type-conversion operator, or any function that is implicitlygenerated by the compiler. See below for macros that can be used todistinguish these cases.@item DECL_ASSEMBLER_NAMEThis macro returns the mangled name of the function, also an@code{IDENTIFIER_NODE}. This name does not contain leading underscoreson systems that prefix all identifiers with underscores. The mangledname is computed in the same way on all platforms; if special processingis required to deal with the object file format used on a particularplatform, it is the responsibility of the back end to perform thosemodifications. (Of course, the back end should not modify@code{DECL_ASSEMBLER_NAME} itself.)Using @code{DECL_ASSEMBLER_NAME} will cause additional memory to beallocated (for the mangled name of the entity) so it should be usedonly when emitting assembly code. It should not be used within theoptimizers 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.@item DECL_EXTERNALThis predicate holds if the function is undefined.@item TREE_PUBLICThis predicate holds if the function has external linkage.@item DECL_LOCAL_FUNCTION_PThis predicate holds if the function was declared at block scope, eventhough it has a global scope.@item DECL_ANTICIPATEDThis predicate holds if the function is a built-in function but itsprototype is not yet explicitly declared.@item DECL_EXTERN_C_FUNCTION_PThis predicate holds if the function is declared as an`@code{extern "C"}' function.@item DECL_LINKONCE_PThis macro holds if multiple copies of this function may be emitted invarious translation units. It is the responsibility of the linker tomerge the various copies. Template instantiations are the most commonexample 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_PThis macro holds if the function is a member of a class, rather than amember of a namespace.@item DECL_STATIC_FUNCTION_PThis predicate holds if the function a static member function.@item DECL_NONSTATIC_MEMBER_FUNCTION_PThis macro holds for a non-static member function.@item DECL_CONST_MEMFUNC_PThis predicate holds for a @code{const}-member function.@item DECL_VOLATILE_MEMFUNC_PThis predicate holds for a @code{volatile}-member function.@item DECL_CONSTRUCTOR_PThis macro holds if the function is a constructor.@item DECL_NONCONVERTING_PThis predicate holds if the constructor is a non-converting constructor.@item DECL_COMPLETE_CONSTRUCTOR_PThis predicate holds for a function which is a constructor for an objectof a complete type.@item DECL_BASE_CONSTRUCTOR_PThis predicate holds for a function which is a constructor for a baseclass sub-object.@item DECL_COPY_CONSTRUCTOR_PThis predicate holds for a function which is a copy-constructor.@item DECL_DESTRUCTOR_PThis macro holds if the function is a destructor.@item DECL_COMPLETE_DESTRUCTOR_PThis predicate holds if the function is the destructor for an object acomplete type.@item DECL_OVERLOADED_OPERATOR_PThis macro holds if the function is an overloaded operator.@item DECL_CONV_FN_PThis macro holds if the function is a type-conversion operator.@item DECL_GLOBAL_CTOR_PThis predicate holds if the function is a file-scope initializationfunction.@item DECL_GLOBAL_DTOR_PThis predicate holds if the function is a file-scope finalizationfunction.@item DECL_THUNK_PThis predicate holds if the function is a thunk.These functions represent stub code that adjusts the @code{this} pointerand then jumps to another function. When the jumped-to functionreturns, control is transferred directly to the caller, withoutreturning to the thunk. The first parameter to the thunk is always the@code{this} pointer; the thunk should add @code{THUNK_DELTA} to thisvalue. (The @code{THUNK_DELTA} is an @code{int}, not an@code{INTEGER_CST}.)Then, if @code{THUNK_VCALL_OFFSET} (an @code{INTEGER_CST}) is nonzerothe adjusted @code{this} pointer must be adjusted again. The completecalculation is given by the following pseudo-code:@smallexamplethis += THUNK_DELTAif (THUNK_VCALL_OFFSET) this += (*((ptrdiff_t **) this))[THUNK_VCALL_OFFSET]@end smallexampleFinally, the thunk should jump to the location givenby @code{DECL_INITIAL}; this will always be an expression for theaddress of a function.@item DECL_NON_THUNK_FUNCTION_PThis predicate holds if the function is @emph{not} a thunk function.@item GLOBAL_INIT_PRIORITYIf either @code{DECL_GLOBAL_CTOR_P} or @code{DECL_GLOBAL_DTOR_P} holds,then this gives the initialization priority for the function. Thelinker will arrange that all functions for which@code{DECL_GLOBAL_CTOR_P} holds are run in increasing order of prioritybefore @code{main} is called. When the program exits, all functions forwhich @code{DECL_GLOBAL_DTOR_P} holds are run in the reverse order.@item DECL_ARTIFICIALThis macro holds if the function was implicitly generated by thecompiler, rather than explicitly declared. In addition to implicitlygenerated class member functions, this macro holds for the specialfunctions created to implement static initialization and destruction, tocompute run-time type information, and so forth.@item DECL_ARGUMENTSThis macro returns the @code{PARM_DECL} for the first argument to thefunction. Subsequent @code{PARM_DECL} nodes can be obtained byfollowing the @code{TREE_CHAIN} links.@item DECL_RESULTThis macro returns the @code{RESULT_DECL} for the function.@item TREE_TYPEThis macro returns the @code{FUNCTION_TYPE} or @code{METHOD_TYPE} forthe function.@item TYPE_RAISES_EXCEPTIONSThis macro returns the list of exceptions that a (member-)function canraise. The returned list, if non @code{NULL}, is comprised of nodeswhose @code{TREE_VALUE} represents a type.@item TYPE_NOTHROW_PThis predicate holds when the exception-specification of its argumentsif of the form `@code{()}'.@item DECL_ARRAY_DELETE_OPERATOR_PThis 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 BREAK_STMT@tindex CLEANUP_STMT@findex CLEANUP_DECL@findex CLEANUP_EXPR@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@findex FOR_COND@findex FOR_EXPR@findex FOR_BODY@tindex HANDLER@tindex IF_STMT@findex IF_COND@findex THEN_CLAUSE@findex ELSE_CLAUSE@tindex RETURN_STMT@findex RETURN_EXPR@tindex SUBOBJECT@findex SUBOBJECT_CLEANUP@tindex SWITCH_STMT@findex SWITCH_COND@findex SWITCH_BODY@tindex TRY_BLOCK@findex TRY_STMTS@findex TRY_HANDLERS@findex HANDLER_PARMS@findex HANDLER_BODY@findex USING_STMT@tindex WHILE_STMT@findex WHILE_BODY@findex WHILE_CONDA function that has a definition in the current translation unit willhave a non-@code{NULL} @code{DECL_INITIAL}. However, back ends should not makeuse of the particular value given by @code{DECL_INITIAL}.The @code{DECL_SAVED_TREE} macro will give the complete body of thefunction.@subsubsection StatementsThere are tree nodes corresponding to all of the source-levelstatement constructs, used within the C and C++ frontends. These areenumerated here, together with a list of the various macros that canbe used to obtain information about them. There are a few macros thatcan be used with all statements:@ftable @code@item STMT_IS_FULL_EXPR_PIn C++, statements normally constitute ``full expressions''; temporariescreated during a statement are destroyed when the statement is complete.However, G++ sometimes represents expressions by statements; thesestatements will not have @code{STMT_IS_FULL_EXPR_P} set. Temporariescreated during such statements should be destroyed when the innermostenclosing statement with @code{STMT_IS_FULL_EXPR_P} set is exited.@end ftableHere is the list of the various statement nodes, and the macros used toaccess them. This documentation describes the use of these nodes innon-template functions (including instantiations of template functions).In template functions, the same nodes are used, but sometimes inslightly different ways.Many of the statements have substatements. For example, a @code{while}loop will have a body, which is itself a statement. If the substatementis @code{NULL_TREE}, it is considered equivalent to a statementconsisting of a single @code{;}, i.e., an expression statement in whichthe expression has been omitted. A substatement may in fact be a listof statements, connected via their @code{TREE_CHAIN}s. So, you shouldalways process the statement tree by looping over substatements, likethis:@smallexamplevoid process_stmt (stmt) tree stmt;@{ while (stmt) @{ switch (TREE_CODE (stmt)) @{ case IF_STMT: process_stmt (THEN_CLAUSE (stmt)); /* @r{More processing here.} */ break; @dots{} @} stmt = TREE_CHAIN (stmt); @}@}@end smallexampleIn other words, while the @code{then} clause of an @code{if} statementin C++ can be only one statement (although that one statement may be acompound statement), the intermediate representation will sometimes useseveral statements chained together.@table @code@item ASM_EXPRUsed to represent an inline assembly statement. For an inline assemblystatement like:@smallexampleasm ("mov x, y");@end smallexampleThe @code{ASM_STRING} macro will return a @code{STRING_CST} node for@code{"mov x, y"}. If the original statement made use of theextended-assembly syntax, then @code{ASM_OUTPUTS},@code{ASM_INPUTS}, and @code{ASM_CLOBBERS} will be the outputs, inputs,and clobbers for the statement, represent
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -