📄 c-tree.texi
字号:
@c ---------------------------------------------------------------------@c Scopes@c ---------------------------------------------------------------------@node Scopes@section Scopes@cindex namespace, class, scopeThe root of the entire intermediate representation is the variable@code{global_namespace}. This is the namespace specified with @code{::}in C++ source code. All other namespaces, types, variables, functions,and so forth can be found starting with this namespace.Besides namespaces, the other high-level scoping construct in C++ is theclass. (Throughout this manual the term @dfn{class} is used to mean thetypes referred to in the ANSI/ISO C++ Standard as classes; these includetypes defined with the @code{class}, @code{struct}, and @code{union}keywords.)@menu* Namespaces:: Member functions, types, etc.* Classes:: Members, bases, friends, etc.@end menu@c ---------------------------------------------------------------------@c Namespaces@c ---------------------------------------------------------------------@node Namespaces@subsection Namespaces@cindex namespace@tindex NAMESPACE_DECLA namespace is represented by a @code{NAMESPACE_DECL} node.However, except for the fact that it is distinguished as the root of therepresentation, the global namespace is no different from any othernamespace. Thus, in what follows, we describe namespaces generally,rather than the global namespace in particular.The following macros and functions can be used on a @code{NAMESPACE_DECL}:@ftable @code@item DECL_NAMEThis macro is used to obtain the @code{IDENTIFIER_NODE} corresponding tothe unqualified name of the name of the namespace (@pxref{Identifiers}).The name of the global namespace is @samp{::}, even though in C++ theglobal namespace is unnamed. However, you should use comparison with@code{global_namespace}, rather than @code{DECL_NAME} to determinewhether or not a namespace is the global one. An unnamed namespacewill have a @code{DECL_NAME} equal to @code{anonymous_namespace_name}.Within a single translation unit, all unnamed namespaces will have thesame name.@item DECL_CONTEXTThis macro returns the enclosing namespace. The @code{DECL_CONTEXT} forthe @code{global_namespace} is @code{NULL_TREE}.@item DECL_NAMESPACE_ALIASIf this declaration is for a namespace alias, then@code{DECL_NAMESPACE_ALIAS} is the namespace for which this one is analias.Do not attempt to use @code{cp_namespace_decls} for a namespace which isan alias. Instead, follow @code{DECL_NAMESPACE_ALIAS} links until youreach an ordinary, non-alias, namespace, and call@code{cp_namespace_decls} there.@item DECL_NAMESPACE_STD_PThis predicate holds if the namespace is the special @code{::std}namespace.@item cp_namespace_declsThis function will return the declarations contained in the namespace,including types, overloaded functions, other namespaces, and so forth.If there are no declarations, this function will return@code{NULL_TREE}. The declarations are connected through their@code{TREE_CHAIN} fields.Although most entries on this list will be declarations,@code{TREE_LIST} nodes may also appear. In this case, the@code{TREE_VALUE} will be an @code{OVERLOAD}. The value of the@code{TREE_PURPOSE} is unspecified; back ends should ignore this value.As with the other kinds of declarations returned by@code{cp_namespace_decls}, the @code{TREE_CHAIN} will point to the nextdeclaration in this list.For more information on the kinds of declarations that can occur on thislist, @xref{Declarations}. Some declarations will not appear on thislist. In particular, no @code{FIELD_DECL}, @code{LABEL_DECL}, or@code{PARM_DECL} nodes will appear here.This function cannot be used with namespaces that have@code{DECL_NAMESPACE_ALIAS} set.@end ftable@c ---------------------------------------------------------------------@c Classes@c ---------------------------------------------------------------------@node Classes@subsection Classes@cindex class@tindex RECORD_TYPE@tindex UNION_TYPE@findex CLASSTYPE_DECLARED_CLASS@findex TYPE_BINFO@findex BINFO_TYPE@findex TYPE_FIELDS@findex TYPE_VFIELD@findex TYPE_METHODSA class type is represented by either a @code{RECORD_TYPE} or a@code{UNION_TYPE}. A class declared with the @code{union} tag isrepresented by a @code{UNION_TYPE}, while classes declared with eitherthe @code{struct} or the @code{class} tag are represented by@code{RECORD_TYPE}s. You can use the @code{CLASSTYPE_DECLARED_CLASS}macro to discern whether or not a particular type is a @code{class} asopposed to a @code{struct}. This macro will be true only for classesdeclared with the @code{class} tag.Almost all non-function members are available on the @code{TYPE_FIELDS}list. Given one member, the next can be found by following the@code{TREE_CHAIN}. You should not depend in any way on the order inwhich fields appear on this list. All nodes on this list will be@samp{DECL} nodes. A @code{FIELD_DECL} is used to represent a non-staticdata member, a @code{VAR_DECL} is used to represent a static datamember, and a @code{TYPE_DECL} is used to represent a type. Note thatthe @code{CONST_DECL} for an enumeration constant will appear on thislist, if the enumeration type was declared in the class. (Of course,the @code{TYPE_DECL} for the enumeration type will appear here as well.)There are no entries for base classes on this list. In particular,there is no @code{FIELD_DECL} for the ``base-class portion'' of anobject.The @code{TYPE_VFIELD} is a compiler-generated field used to point tovirtual function tables. It may or may not appear on the@code{TYPE_FIELDS} list. However, back ends should handle the@code{TYPE_VFIELD} just like all the entries on the @code{TYPE_FIELDS}list.The function members are available on the @code{TYPE_METHODS} list.Again, subsequent members are found by following the @code{TREE_CHAIN}field. If a function is overloaded, each of the overloaded functionsappears; no @code{OVERLOAD} nodes appear on the @code{TYPE_METHODS}list. Implicitly declared functions (including default constructors,copy constructors, assignment operators, and destructors) will appear onthis list as well.Every class has an associated @dfn{binfo}, which can be obtained with@code{TYPE_BINFO}. Binfos are used to represent base-classes. Thebinfo given by @code{TYPE_BINFO} is the degenerate case, whereby everyclass is considered to be its own base-class. The base binfos for aparticular binfo are held in a vector, whose length is obtained with@code{BINFO_N_BASE_BINFOS}. The base binfos themselves are obtainedwith @code{BINFO_BASE_BINFO} and @code{BINFO_BASE_ITERATE}. To add anew binfo, use @code{BINFO_BASE_APPEND}. The vector of base binfos canbe obtained with @code{BINFO_BASE_BINFOS}, but normally you do not needto use that. The class type associated with a binfo is given by@code{BINFO_TYPE}. It is not always the case that @code{BINFO_TYPE(TYPE_BINFO (x))}, because of typedefs and qualified types. Neither isit the case that @code{TYPE_BINFO (BINFO_TYPE (y))} is the same binfo as@code{y}. The reason is that if @code{y} is a binfo representing abase-class @code{B} of a derived class @code{D}, then @code{BINFO_TYPE(y)} will be @code{B}, and @code{TYPE_BINFO (BINFO_TYPE (y))} will be@code{B} as its own base-class, rather than as a base-class of @code{D}.The access to a base type can be found with @code{BINFO_BASE_ACCESS}.This will produce @code{access_public_node}, @code{access_private_node}or @code{access_protected_node}. If bases are always public,@code{BINFO_BASE_ACCESSES} may be @code{NULL}.@code{BINFO_VIRTUAL_P} is used to specify whether the binfo is inheritedvirtually or not. The other flags, @code{BINFO_MARKED_P} and@code{BINFO_FLAG_1} to @code{BINFO_FLAG_6} can be used for languagespecific use.The following macros can be used on a tree node representing a class-type.@ftable @code@item LOCAL_CLASS_PThis predicate holds if the class is local class @emph{i.e.}@: declaredinside a function body.@item TYPE_POLYMORPHIC_PThis predicate holds if the class has at least one virtual function(declared or inherited).@item TYPE_HAS_DEFAULT_CONSTRUCTORThis predicate holds whenever its argument represents a class-type withdefault constructor.@item CLASSTYPE_HAS_MUTABLE@itemx TYPE_HAS_MUTABLE_PThese predicates hold for a class-type having a mutable data member.@item CLASSTYPE_NON_POD_PThis predicate holds only for class-types that are not PODs.@item TYPE_HAS_NEW_OPERATORThis predicate holds for a class-type that defines@code{operator new}.@item TYPE_HAS_ARRAY_NEW_OPERATORThis predicate holds for a class-type for which@code{operator new[]} is defined.@item TYPE_OVERLOADS_CALL_EXPRThis predicate holds for class-type for which the function call@code{operator()} is overloaded.@item TYPE_OVERLOADS_ARRAY_REFThis predicate holds for a class-type that overloads@code{operator[]}@item TYPE_OVERLOADS_ARROWThis predicate holds for a class-type for which @code{operator->} isoverloaded.@end ftable@c ---------------------------------------------------------------------@c Declarations@c ---------------------------------------------------------------------@node Declarations@section Declarations@cindex declaration@cindex variable@cindex type declaration@tindex LABEL_DECL@tindex CONST_DECL@tindex TYPE_DECL@tindex VAR_DECL@tindex PARM_DECL@tindex FIELD_DECL@tindex NAMESPACE_DECL@tindex RESULT_DECL@tindex TEMPLATE_DECL@tindex THUNK_DECL@tindex USING_DECL@findex THUNK_DELTA@findex DECL_INITIAL@findex DECL_SIZE@findex DECL_ALIGN@findex DECL_EXTERNALThis section covers the various kinds of declarations that appear in theinternal representation, except for declarations of functions(represented by @code{FUNCTION_DECL} nodes), which are described in@ref{Functions}.@menu* Working with declarations:: Macros and functions that work ondeclarations.* Internal structure:: How declaration nodes are represented. @end menu@node Working with declarations@subsection Working with declarationsSome macros can be used with any kind of declaration. These include:@ftable @code@item DECL_NAMEThis macro returns an @code{IDENTIFIER_NODE} giving the name of theentity.@item TREE_TYPEThis macro returns the type of the entity declared.@item TREE_FILENAMEThis macro returns the name of the file in which the entity wasdeclared, as a @code{char*}. For an entity declared implicitly by thecompiler (like @code{__builtin_memcpy}), this will be the string@code{"<internal>"}.@item TREE_LINENOThis macro returns the line number at which the entity was declared, asan @code{int}.@item DECL_ARTIFICIALThis predicate holds if the declaration was implicitly generated by thecompiler. For example, this predicate will hold of an implicitlydeclared member function, or of the @code{TYPE_DECL} implicitlygenerated for a class type. Recall that in C++ code like:@smallexamplestruct S @{@};@end smallexample@noindentis roughly equivalent to C code like:@smallexamplestruct S @{@};typedef struct S S;@end smallexampleThe implicitly generated @code{typedef} declaration is represented by a@code{TYPE_DECL} for which @code{DECL_ARTIFICIAL} holds.@item DECL_NAMESPACE_SCOPE_PThis predicate holds if the entity was declared at a namespace scope.@item DECL_CLASS_SCOPE_PThis predicate holds if the entity was declared at a class scope.@item DECL_FUNCTION_SCOPE_PThis predicate holds if the entity was declared inside a functionbody.@end ftableThe various kinds of declarations include:@table @code@item LABEL_DECLThese nodes are used to represent labels in function bodies. For moreinformation, see @ref{Functions}. These nodes only appear in blockscopes.@item CONST_DECLThese nodes are used to represent enumeration constants. The value ofthe constant is given by @code{DECL_INITIAL} which will be an@code{INTEGER_CST} with the same type as the @code{TREE_TYPE} of the@code{CONST_DECL}, i.e., an @code{ENUMERAL_TYPE}.@item RESULT_DECLThese nodes represent the value returned by a function. When a value isassigned to a @code{RESULT_DECL}, that indicates that the value shouldbe returned, via bitwise copy, by the function. You can use@code{DECL_SIZE} and @code{DECL_ALIGN} on a @code{RESULT_DECL}, just aswith a @code{VAR_DECL}.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -