📄 c-tree.texi
字号:
continues until a non-array type is found, and the qualification of thistype is examined.) So, for example, @code{CP_TYPE_CONST_P} will hold ofthe type @code{const int ()[7]}, denoting an array of seven @code{int}s.The following functions and macros deal with cv-qualification of types:@ftable @code@item CP_TYPE_QUALSThis macro returns the set of type qualifiers applied to this type.This value is @code{TYPE_UNQUALIFIED} if no qualifiers have beenapplied. The @code{TYPE_QUAL_CONST} bit is set if the type is@code{const}-qualified. The @code{TYPE_QUAL_VOLATILE} bit is set if thetype is @code{volatile}-qualified. The @code{TYPE_QUAL_RESTRICT} bit isset if the type is @code{restrict}-qualified.@item CP_TYPE_CONST_PThis macro holds if the type is @code{const}-qualified.@item CP_TYPE_VOLATILE_PThis macro holds if the type is @code{volatile}-qualified.@item CP_TYPE_RESTRICT_PThis macro holds if the type is @code{restrict}-qualified.@item CP_TYPE_CONST_NON_VOLATILE_PThis predicate holds for a type that is @code{const}-qualified, but@emph{not} @code{volatile}-qualified; other cv-qualifiers are ignored aswell: only the @code{const}-ness is tested.@item TYPE_MAIN_VARIANTThis macro returns the unqualified version of a type. It may be appliedto an unqualified type, but it is not always the identity function inthat case.@end ftableA few other macros and functions are usable with all types:@ftable @code@item TYPE_SIZEThe number of bits required to represent the type, represented as an@code{INTEGER_CST}. For an incomplete type, @code{TYPE_SIZE} will be@code{NULL_TREE}.@item TYPE_ALIGNThe alignment of the type, in bits, represented as an @code{int}.@item TYPE_NAMEThis macro returns a declaration (in the form of a @code{TYPE_DECL}) forthe type. (Note this macro does @emph{not} return a@code{IDENTIFIER_NODE}, as you might expect, given its name!) You canlook at the @code{DECL_NAME} of the @code{TYPE_DECL} to obtain theactual name of the type. The @code{TYPE_NAME} will be @code{NULL_TREE}for a type that is not a built-in type, the result of a typedef, or anamed class type.@item CP_INTEGRAL_TYPEThis predicate holds if the type is an integral type. Notice that inC++, enumerations are @emph{not} integral types.@item ARITHMETIC_TYPE_PThis predicate holds if the type is an integral type (in the C++ sense)or a floating point type.@item CLASS_TYPE_PThis predicate holds for a class-type.@item TYPE_BUILT_INThis predicate holds for a built-in type.@item TYPE_PTRMEM_PThis predicate holds if the type is a pointer to data member.@item TYPE_PTR_PThis predicate holds if the type is a pointer type, and the pointee isnot a data member.@item TYPE_PTRFN_PThis predicate holds for a pointer to function type.@item TYPE_PTROB_PThis predicate holds for a pointer to object type. Note however that itdoes not hold for the generic pointer to object type @code{void *}. Youmay use @code{TYPE_PTROBV_P} to test for a pointer to object type aswell as @code{void *}.@item TYPE_CANONICALThis macro returns the ``canonical'' type for the given typenode. Canonical types are used to improve performance in the C++ andObjective-C++ front ends by allowing efficient comparison between twotype nodes in @code{same_type_p}: if the @code{TYPE_CANONICAL} valuesof the types are equal, the types are equivalent; otherwise, the typesare not equivalent. The notion of equivalence for canonical types isthe same as the notion of type equivalence in the language itself. Forinstance,When @code{TYPE_CANONICAL} is @code{NULL_TREE}, there is no canonicaltype for the given type node. In this case, comparison between thistype and any other type requires the compiler to perform a deep,``structural'' comparison to see if the two type nodes have the sameform and properties.The canonical type for a node is always the most fundamental type inthe equivalence class of types. For instance, @code{int} is its owncanonical type. A typedef @code{I} of @code{int} will have @code{int}as its canonical type. Similarly, @code{I*}@ and a typedef @code{IP}@(defined to @code{I*}) will has @code{int*} as their canonicaltype. When building a new type node, be sure to set@code{TYPE_CANONICAL} to the appropriate canonical type. If the newtype is a compound type (built from other types), and any of thoseother types require structural equality, use@code{SET_TYPE_STRUCTURAL_EQUALITY} to ensure that the new type alsorequires structural equality. Finally, if for some reason you cannotguarantee that @code{TYPE_CANONICAL} will point to the canonical type,use @code{SET_TYPE_STRUCTURAL_EQUALITY} to make sure that the newtype--and any type constructed based on it--requires structuralequality. If you suspect that the canonical type system ismiscomparing types, pass @code{--param verify-canonical-types=1} tothe compiler or configure with @code{--enable-checking} to force thecompiler to verify its canonical-type comparisons against thestructural comparisons; the compiler will then print any warnings ifthe canonical types miscompare.@item TYPE_STRUCTURAL_EQUALITY_PThis predicate holds when the node requires structural equalitychecks, e.g., when @code{TYPE_CANONICAL} is @code{NULL_TREE}.@item SET_TYPE_STRUCTURAL_EQUALITYThis macro states that the type node it is given requires structuralequality checks, e.g., it sets @code{TYPE_CANONICAL} to@code{NULL_TREE}.@item same_type_pThis predicate takes two types as input, and holds if they are the sametype. For example, if one type is a @code{typedef} for the other, orboth are @code{typedef}s for the same type. This predicate also holds ifthe two trees given as input are simply copies of one another; i.e.,there is no difference between them at the source level, but, forwhatever reason, a duplicate has been made in the representation. Youshould never use @code{==} (pointer equality) to compare types; alwaysuse @code{same_type_p} instead.@end ftableDetailed below are the various kinds of types, and the macros that canbe used to access them. Although other kinds of types are usedelsewhere in G++, the types described here are the only ones that youwill encounter while examining the intermediate representation.@table @code@item VOID_TYPEUsed to represent the @code{void} type.@item INTEGER_TYPEUsed to represent the various integral types, including @code{char},@code{short}, @code{int}, @code{long}, and @code{long long}. This codeis not used for enumeration types, nor for the @code{bool} type.The @code{TYPE_PRECISION} is the number of bits used inthe representation, represented as an @code{unsigned int}. (Note thatin the general case this is not the same value as @code{TYPE_SIZE};suppose that there were a 24-bit integer type, but that alignmentrequirements for the ABI required 32-bit alignment. Then,@code{TYPE_SIZE} would be an @code{INTEGER_CST} for 32, while@code{TYPE_PRECISION} would be 24.) The integer type is unsigned if@code{TYPE_UNSIGNED} holds; otherwise, it is signed.The @code{TYPE_MIN_VALUE} is an @code{INTEGER_CST} for the smallestinteger that may be represented by this type. Similarly, the@code{TYPE_MAX_VALUE} is an @code{INTEGER_CST} for the largest integerthat may be represented by this type.@item REAL_TYPEUsed to represent the @code{float}, @code{double}, and @code{longdouble} types. The number of bits in the floating-point representationis given by @code{TYPE_PRECISION}, as in the @code{INTEGER_TYPE} case.@item FIXED_POINT_TYPEUsed to represent the @code{short _Fract}, @code{_Fract}, @code{long_Fract}, @code{long long _Fract}, @code{short _Accum}, @code{_Accum},@code{long _Accum}, and @code{long long _Accum} types. The number of bitsin the fixed-point representation is given by @code{TYPE_PRECISION},as in the @code{INTEGER_TYPE} case. There may be padding bits, fractionalbits and integral bits. The number of fractional bits is given by@code{TYPE_FBIT}, and the number of integral bits is given by @code{TYPE_IBIT}.The fixed-point type is unsigned if @code{TYPE_UNSIGNED} holds; otherwise,it is signed.The fixed-point type is saturating if @code{TYPE_SATURATING} holds; otherwise,it is not saturating.@item COMPLEX_TYPEUsed to represent GCC built-in @code{__complex__} data types. The@code{TREE_TYPE} is the type of the real and imaginary parts.@item ENUMERAL_TYPEUsed to represent an enumeration type. The @code{TYPE_PRECISION} gives(as an @code{int}), the number of bits used to represent the type. Ifthere are no negative enumeration constants, @code{TYPE_UNSIGNED} willhold. The minimum and maximum enumeration constants may be obtainedwith @code{TYPE_MIN_VALUE} and @code{TYPE_MAX_VALUE}, respectively; eachof these macros returns an @code{INTEGER_CST}.The actual enumeration constants themselves may be obtained by lookingat the @code{TYPE_VALUES}. This macro will return a @code{TREE_LIST},containing the constants. The @code{TREE_PURPOSE} of each node will bean @code{IDENTIFIER_NODE} giving the name of the constant; the@code{TREE_VALUE} will be an @code{INTEGER_CST} giving the valueassigned to that constant. These constants will appear in the order inwhich they were declared. The @code{TREE_TYPE} of each of theseconstants will be the type of enumeration type itself.@item BOOLEAN_TYPEUsed to represent the @code{bool} type.@item POINTER_TYPEUsed to represent pointer types, and pointer to data member types. The@code{TREE_TYPE} gives the type to which this type points. If the typeis a pointer to data member type, then @code{TYPE_PTRMEM_P} will hold.For a pointer to data member type of the form @samp{T X::*},@code{TYPE_PTRMEM_CLASS_TYPE} will be the type @code{X}, while@code{TYPE_PTRMEM_POINTED_TO_TYPE} will be the type @code{T}.@item REFERENCE_TYPEUsed to represent reference types. The @code{TREE_TYPE} gives the typeto which this type refers.@item FUNCTION_TYPEUsed to represent the type of non-member functions and of static memberfunctions. The @code{TREE_TYPE} gives the return type of the function.The @code{TYPE_ARG_TYPES} are a @code{TREE_LIST} of the argument types.The @code{TREE_VALUE} of each node in this list is the type of thecorresponding argument; the @code{TREE_PURPOSE} is an expression for thedefault argument value, if any. If the last node in the list is@code{void_list_node} (a @code{TREE_LIST} node whose @code{TREE_VALUE}is the @code{void_type_node}), then functions of this type do not takevariable arguments. Otherwise, they do take a variable number ofarguments.Note that in C (but not in C++) a function declared like @code{void f()}is an unprototyped function taking a variable number of arguments; the@code{TYPE_ARG_TYPES} of such a function will be @code{NULL}.@item METHOD_TYPEUsed to represent the type of a non-static member function. Like a@code{FUNCTION_TYPE}, the return type is given by the @code{TREE_TYPE}.The type of @code{*this}, i.e., the class of which functions of thistype are a member, is given by the @code{TYPE_METHOD_BASETYPE}. The@code{TYPE_ARG_TYPES} is the parameter list, as for a@code{FUNCTION_TYPE}, and includes the @code{this} argument.@item ARRAY_TYPEUsed to represent array types. The @code{TREE_TYPE} gives the type ofthe elements in the array. If the array-bound is present in the type,the @code{TYPE_DOMAIN} is an @code{INTEGER_TYPE} whose@code{TYPE_MIN_VALUE} and @code{TYPE_MAX_VALUE} will be the lower andupper bounds of the array, respectively. The @code{TYPE_MIN_VALUE} willalways be an @code{INTEGER_CST} for zero, while the@code{TYPE_MAX_VALUE} will be one less than the number of elements inthe array, i.e., the highest value which may be used to index an elementin the array.@item RECORD_TYPEUsed to represent @code{struct} and @code{class} types, as well aspointers to member functions and similar constructs in other languages.@code{TYPE_FIELDS} contains the items contained in this type, each ofwhich can be a @code{FIELD_DECL}, @code{VAR_DECL}, @code{CONST_DECL}, or@code{TYPE_DECL}. You may not make any assumptions about the orderingof the fields in the type or whether one or more of them overlap. If@code{TYPE_PTRMEMFUNC_P} holds, then this type is a pointer-to-membertype. In that case, the @code{TYPE_PTRMEMFUNC_FN_TYPE} is a@code{POINTER_TYPE} pointing to a @code{METHOD_TYPE}. The@code{METHOD_TYPE} is the type of a function pointed to by thepointer-to-member function. If @code{TYPE_PTRMEMFUNC_P} does not hold,this type is a class type. For more information, see @pxref{Classes}.@item UNION_TYPEUsed to represent @code{union} types. Similar to @code{RECORD_TYPE}except that all @code{FIELD_DECL} nodes in @code{TYPE_FIELD} start atbit position zero.@item QUAL_UNION_TYPEUsed to represent part of a variant record in Ada. Similar to@code{UNION_TYPE} except that each @code{FIELD_DECL} has a@code{DECL_QUALIFIER} field, which contains a boolean expression thatindicates whether the field is present in the object. The type will onlyhave one field, so each field's @code{DECL_QUALIFIER} is only evaluatedif none of the expressions in the previous fields in @code{TYPE_FIELDS}are nonzero. Normally these expressions will reference a field in theouter object using a @code{PLACEHOLDER_EXPR}.@item UNKNOWN_TYPEThis node is used to represent a type the knowledge of which isinsufficient for a sound processing.@item OFFSET_TYPEThis node is used to represent a pointer-to-data member. For a datamember @code{X::m} the @code{TYPE_OFFSET_BASETYPE} is @code{X} and the@code{TREE_TYPE} is the type of @code{m}.@item TYPENAME_TYPEUsed to represent a construct of the form @code{typename T::A}. The@code{TYPE_CONTEXT} is @code{T}; the @code{TYPE_NAME} is an@code{IDENTIFIER_NODE} for @code{A}. If the type is specified via atemplate-id, then @code{TYPENAME_TYPE_FULLNAME} yields a@code{TEMPLATE_ID_EXPR}. The @code{TREE_TYPE} is non-@code{NULL} if thenode is implicitly generated in support for the implicit typenameextension; in which case the @code{TREE_TYPE} is a type node for thebase-class.@item TYPEOF_TYPEUsed to represent the @code{__typeof__} extension. The@code{TYPE_FIELDS} is the expression the type of which is beingrepresented.@end tableThere are variables whose values represent some of the basic types.These include:@table @code@item void_type_nodeA node for @code{void}.@item integer_type_nodeA node for @code{int}.@item unsigned_type_node.A node for @code{unsigned int}.@item char_type_node.A node for @code{char}.@end table@noindentIt may sometimes be useful to compare one of these variables with a typein hand, using @code{same_type_p}.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -