gccint: Types

1 
1 11.3 Types
1 ==========
1 
1 All types have corresponding tree nodes.  However, you should not assume
1 that there is exactly one tree node corresponding to each type.  There
1 are often multiple nodes corresponding to the same type.
1 
1  For the most part, different kinds of types have different tree codes.
1 (For example, pointer types use a 'POINTER_TYPE' code while arrays use
1 an 'ARRAY_TYPE' code.)  However, pointers to member functions use the
1 'RECORD_TYPE' code.  Therefore, when writing a 'switch' statement that
1 depends on the code associated with a particular type, you should take
1 care to handle pointers to member functions under the 'RECORD_TYPE' case
1 label.
1 
1  The following functions and macros deal with cv-qualification of types:
1 'TYPE_MAIN_VARIANT'
1      This macro returns the unqualified version of a type.  It may be
1      applied to an unqualified type, but it is not always the identity
1      function in that case.
1 
1  A few other macros and functions are usable with all types:
1 'TYPE_SIZE'
1      The number of bits required to represent the type, represented as
1      an 'INTEGER_CST'.  For an incomplete type, 'TYPE_SIZE' will be
1      'NULL_TREE'.
1 
1 'TYPE_ALIGN'
1      The alignment of the type, in bits, represented as an 'int'.
1 
1 'TYPE_NAME'
1      This macro returns a declaration (in the form of a 'TYPE_DECL') for
1      the type.  (Note this macro does _not_ return an 'IDENTIFIER_NODE',
1      as you might expect, given its name!)  You can look at the
1      'DECL_NAME' of the 'TYPE_DECL' to obtain the actual name of the
1      type.  The 'TYPE_NAME' will be 'NULL_TREE' for a type that is not a
1      built-in type, the result of a typedef, or a named class type.
1 
1 'TYPE_CANONICAL'
1      This macro returns the "canonical" type for the given type node.
1      Canonical types are used to improve performance in the C++ and
1      Objective-C++ front ends by allowing efficient comparison between
1      two type nodes in 'same_type_p': if the 'TYPE_CANONICAL' values of
1      the types are equal, the types are equivalent; otherwise, the types
1      are not equivalent.  The notion of equivalence for canonical types
1      is the same as the notion of type equivalence in the language
1      itself.  For instance,
1 
1      When 'TYPE_CANONICAL' is 'NULL_TREE', there is no canonical type
1      for the given type node.  In this case, comparison between this
1      type and any other type requires the compiler to perform a deep,
1      "structural" comparison to see if the two type nodes have the same
1      form and properties.
1 
1      The canonical type for a node is always the most fundamental type
1      in the equivalence class of types.  For instance, 'int' is its own
1      canonical type.  A typedef 'I' of 'int' will have 'int' as its
1      canonical type.  Similarly, 'I*' and a typedef 'IP' (defined to
1      'I*') will has 'int*' as their canonical type.  When building a new
1      type node, be sure to set 'TYPE_CANONICAL' to the appropriate
1      canonical type.  If the new type is a compound type (built from
1      other types), and any of those other types require structural
1      equality, use 'SET_TYPE_STRUCTURAL_EQUALITY' to ensure that the new
1      type also requires structural equality.  Finally, if for some
1      reason you cannot guarantee that 'TYPE_CANONICAL' will point to the
1      canonical type, use 'SET_TYPE_STRUCTURAL_EQUALITY' to make sure
1      that the new type-and any type constructed based on it-requires
1      structural equality.  If you suspect that the canonical type system
1      is miscomparing types, pass '--param verify-canonical-types=1' to
1      the compiler or configure with '--enable-checking' to force the
1      compiler to verify its canonical-type comparisons against the
1      structural comparisons; the compiler will then print any warnings
1      if the canonical types miscompare.
1 
1 'TYPE_STRUCTURAL_EQUALITY_P'
1      This predicate holds when the node requires structural equality
1      checks, e.g., when 'TYPE_CANONICAL' is 'NULL_TREE'.
1 
1 'SET_TYPE_STRUCTURAL_EQUALITY'
1      This macro states that the type node it is given requires
1      structural equality checks, e.g., it sets 'TYPE_CANONICAL' to
1      'NULL_TREE'.
1 
1 'same_type_p'
1      This predicate takes two types as input, and holds if they are the
1      same type.  For example, if one type is a 'typedef' for the other,
1      or both are 'typedef's for the same type.  This predicate also
1      holds if the two trees given as input are simply copies of one
1      another; i.e., there is no difference between them at the source
1      level, but, for whatever reason, a duplicate has been made in the
1      representation.  You should never use '==' (pointer equality) to
1      compare types; always use 'same_type_p' instead.
1 
1  Detailed below are the various kinds of types, and the macros that can
1 be used to access them.  Although other kinds of types are used
1 elsewhere in G++, the types described here are the only ones that you
1 will encounter while examining the intermediate representation.
1 
1 'VOID_TYPE'
1      Used to represent the 'void' type.
1 
1 'INTEGER_TYPE'
1      Used to represent the various integral types, including 'char',
1      'short', 'int', 'long', and 'long long'.  This code is not used for
1      enumeration types, nor for the 'bool' type.  The 'TYPE_PRECISION'
1      is the number of bits used in the representation, represented as an
1      'unsigned int'.  (Note that in the general case this is not the
1      same value as 'TYPE_SIZE'; suppose that there were a 24-bit integer
1      type, but that alignment requirements for the ABI required 32-bit
1      alignment.  Then, 'TYPE_SIZE' would be an 'INTEGER_CST' for 32,
1      while 'TYPE_PRECISION' would be 24.)  The integer type is unsigned
1      if 'TYPE_UNSIGNED' holds; otherwise, it is signed.
1 
1      The 'TYPE_MIN_VALUE' is an 'INTEGER_CST' for the smallest integer
1      that may be represented by this type.  Similarly, the
1      'TYPE_MAX_VALUE' is an 'INTEGER_CST' for the largest integer that
1      may be represented by this type.
1 
1 'REAL_TYPE'
1      Used to represent the 'float', 'double', and 'long double' types.
1      The number of bits in the floating-point representation is given by
1      'TYPE_PRECISION', as in the 'INTEGER_TYPE' case.
1 
1 'FIXED_POINT_TYPE'
1      Used to represent the 'short _Fract', '_Fract', 'long _Fract',
1      'long long _Fract', 'short _Accum', '_Accum', 'long _Accum', and
1      'long long _Accum' types.  The number of bits in the fixed-point
1      representation is given by 'TYPE_PRECISION', as in the
1      'INTEGER_TYPE' case.  There may be padding bits, fractional bits
1      and integral bits.  The number of fractional bits is given by
1      'TYPE_FBIT', and the number of integral bits is given by
1      'TYPE_IBIT'.  The fixed-point type is unsigned if 'TYPE_UNSIGNED'
1      holds; otherwise, it is signed.  The fixed-point type is saturating
1      if 'TYPE_SATURATING' holds; otherwise, it is not saturating.
1 
1 'COMPLEX_TYPE'
1      Used to represent GCC built-in '__complex__' data types.  The
1      'TREE_TYPE' is the type of the real and imaginary parts.
1 
1 'ENUMERAL_TYPE'
1      Used to represent an enumeration type.  The 'TYPE_PRECISION' gives
1      (as an 'int'), the number of bits used to represent the type.  If
1      there are no negative enumeration constants, 'TYPE_UNSIGNED' will
1      hold.  The minimum and maximum enumeration constants may be
1      obtained with 'TYPE_MIN_VALUE' and 'TYPE_MAX_VALUE', respectively;
1      each of these macros returns an 'INTEGER_CST'.
1 
1      The actual enumeration constants themselves may be obtained by
1      looking at the 'TYPE_VALUES'.  This macro will return a
1      'TREE_LIST', containing the constants.  The 'TREE_PURPOSE' of each
1      node will be an 'IDENTIFIER_NODE' giving the name of the constant;
1      the 'TREE_VALUE' will be an 'INTEGER_CST' giving the value assigned
1      to that constant.  These constants will appear in the order in
1      which they were declared.  The 'TREE_TYPE' of each of these
1      constants will be the type of enumeration type itself.
1 
1 'BOOLEAN_TYPE'
1      Used to represent the 'bool' type.
1 
1 'POINTER_TYPE'
1      Used to represent pointer types, and pointer to data member types.
1      The 'TREE_TYPE' gives the type to which this type points.
1 
1 'REFERENCE_TYPE'
1      Used to represent reference types.  The 'TREE_TYPE' gives the type
1      to which this type refers.
1 
1 'FUNCTION_TYPE'
1      Used to represent the type of non-member functions and of static
1      member functions.  The 'TREE_TYPE' gives the return type of the
1      function.  The 'TYPE_ARG_TYPES' are a 'TREE_LIST' of the argument
1      types.  The 'TREE_VALUE' of each node in this list is the type of
1      the corresponding argument; the 'TREE_PURPOSE' is an expression for
1      the default argument value, if any.  If the last node in the list
1      is 'void_list_node' (a 'TREE_LIST' node whose 'TREE_VALUE' is the
1      'void_type_node'), then functions of this type do not take variable
1      arguments.  Otherwise, they do take a variable number of arguments.
1 
1      Note that in C (but not in C++) a function declared like 'void f()'
1      is an unprototyped function taking a variable number of arguments;
1      the 'TYPE_ARG_TYPES' of such a function will be 'NULL'.
1 
1 'METHOD_TYPE'
1      Used to represent the type of a non-static member function.  Like a
1      'FUNCTION_TYPE', the return type is given by the 'TREE_TYPE'.  The
1      type of '*this', i.e., the class of which functions of this type
1      are a member, is given by the 'TYPE_METHOD_BASETYPE'.  The
1      'TYPE_ARG_TYPES' is the parameter list, as for a 'FUNCTION_TYPE',
1      and includes the 'this' argument.
1 
1 'ARRAY_TYPE'
1      Used to represent array types.  The 'TREE_TYPE' gives the type of
1      the elements in the array.  If the array-bound is present in the
1      type, the 'TYPE_DOMAIN' is an 'INTEGER_TYPE' whose 'TYPE_MIN_VALUE'
1      and 'TYPE_MAX_VALUE' will be the lower and upper bounds of the
1      array, respectively.  The 'TYPE_MIN_VALUE' will always be an
1      'INTEGER_CST' for zero, while the 'TYPE_MAX_VALUE' will be one less
1      than the number of elements in the array, i.e., the highest value
1      which may be used to index an element in the array.
1 
1 'RECORD_TYPE'
1      Used to represent 'struct' and 'class' types, as well as pointers
1      to member functions and similar constructs in other languages.
1      'TYPE_FIELDS' contains the items contained in this type, each of
1      which can be a 'FIELD_DECL', 'VAR_DECL', 'CONST_DECL', or
1      'TYPE_DECL'.  You may not make any assumptions about the ordering
1      of the fields in the type or whether one or more of them overlap.
1 
1 'UNION_TYPE'
1      Used to represent 'union' types.  Similar to 'RECORD_TYPE' except
1      that all 'FIELD_DECL' nodes in 'TYPE_FIELD' start at bit position
1      zero.
1 
1 'QUAL_UNION_TYPE'
1      Used to represent part of a variant record in Ada.  Similar to
1      'UNION_TYPE' except that each 'FIELD_DECL' has a 'DECL_QUALIFIER'
1      field, which contains a boolean expression that indicates whether
1      the field is present in the object.  The type will only have one
1      field, so each field's 'DECL_QUALIFIER' is only evaluated if none
1      of the expressions in the previous fields in 'TYPE_FIELDS' are
1      nonzero.  Normally these expressions will reference a field in the
1      outer object using a 'PLACEHOLDER_EXPR'.
1 
1 'LANG_TYPE'
1      This node is used to represent a language-specific type.  The front
1      end must handle it.
1 
1 'OFFSET_TYPE'
1      This node is used to represent a pointer-to-data member.  For a
1      data member 'X::m' the 'TYPE_OFFSET_BASETYPE' is 'X' and the
1      'TREE_TYPE' is the type of 'm'.
1 
1  There are variables whose values represent some of the basic types.
1 These include:
1 'void_type_node'
1      A node for 'void'.
1 
1 'integer_type_node'
1      A node for 'int'.
1 
1 'unsigned_type_node.'
1      A node for 'unsigned int'.
1 
1 'char_type_node.'
1      A node for 'char'.
1 It may sometimes be useful to compare one of these variables with a type
1 in hand, using 'same_type_p'.
1