📄 c-tree.texi
字号:
type. (If the element type is itself an array, then the recursion
continues until a non-array type is found, and the qualification of this
type is examined.) So, for example, @code{CP_TYPE_CONST_P} will hold of
the 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_QUALS
This macro returns the set of type qualifiers applied to this type.
This value is @code{TYPE_UNQUALIFIED} if no qualifiers have been
applied. The @code{TYPE_QUAL_CONST} bit is set if the type is
@code{const}-qualified. The @code{TYPE_QUAL_VOLATILE} bit is set if the
type is @code{volatile}-qualified. The @code{TYPE_QUAL_RESTRICT} bit is
set if the type is @code{restrict}-qualified.
@item CP_TYPE_CONST_P
This macro holds if the type is @code{const}-qualified.
@item CP_TYPE_VOLATILE_P
This macro holds if the type is @code{volatile}-qualified.
@item CP_TYPE_RESTRICT_P
This macro holds if the type is @code{restrict}-qualified.
@item CP_TYPE_CONST_NON_VOLATILE_P
This predicate holds for a type that is @code{const}-qualified, but
@emph{not} @code{volatile}-qualified; other cv-qualifiers are ignored as
well: only the @code{const}-ness is tested.
@item TYPE_MAIN_VARIANT
This macro returns the unqualified version of a type. It may be applied
to an unqualified type, but it is not always the identity function in
that case.
@end ftable
A few other macros and functions are usable with all types:
@ftable @code
@item TYPE_SIZE
The 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_ALIGN
The alignment of the type, in bits, represented as an @code{int}.
@item TYPE_NAME
This macro returns a declaration (in the form of a @code{TYPE_DECL}) for
the type. (Note this macro does @emph{not} return a
@code{IDENTIFIER_NODE}, as you might expect, given its name!) You can
look at the @code{DECL_NAME} of the @code{TYPE_DECL} to obtain the
actual 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 a
named class type.
@item CP_INTEGRAL_TYPE
This predicate holds if the type is an integral type. Notice that in
C++, enumerations are @emph{not} integral types.
@item ARITHMETIC_TYPE_P
This predicate holds if the type is an integral type (in the C++ sense)
or a floating point type.
@item CLASS_TYPE_P
This predicate holds for a class-type.
@item TYPE_BUILT_IN
This predicate holds for a built-in type.
@item TYPE_PTRMEM_P
This predicate holds if the type is a pointer to data member.
@item TYPE_PTR_P
This predicate holds if the type is a pointer type, and the pointee is
not a data member.
@item TYPE_PTRFN_P
This predicate holds for a pointer to function type.
@item TYPE_PTROB_P
This predicate holds for a pointer to object type. Note however that it
does not hold for the generic pointer to object type @code{void *}. You
may use @code{TYPE_PTROBV_P} to test for a pointer to object type as
well as @code{void *}.
@item same_type_p
This predicate takes two types as input, and holds if they are the same
type. For example, if one type is a @code{typedef} for the other, or
both are @code{typedef}s for the same type. This predicate also holds if
the two trees given as input are simply copies of one another; i.e.,
there is no difference between them at the source level, but, for
whatever reason, a duplicate has been made in the representation. You
should never use @code{==} (pointer equality) to compare types; always
use @code{same_type_p} instead.
@end ftable
Detailed below are the various kinds of types, and the macros that can
be used to access them. Although other kinds of types are used
elsewhere in G++, the types described here are the only ones that you
will encounter while examining the intermediate representation.
@table @code
@item VOID_TYPE
Used to represent the @code{void} type.
@item INTEGER_TYPE
Used to represent the various integral types, including @code{char},
@code{short}, @code{int}, @code{long}, and @code{long long}. This code
is not used for enumeration types, nor for the @code{bool} type. Note
that GCC's @code{CHAR_TYPE} node is @emph{not} used to represent
@code{char}. The @code{TYPE_PRECISION} is the number of bits used in
the representation, represented as an @code{unsigned int}. (Note that
in the general case this is not the same value as @code{TYPE_SIZE};
suppose that there were a 24-bit integer type, but that alignment
requirements 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{TREE_UNSIGNED} holds; otherwise, it is signed.
The @code{TYPE_MIN_VALUE} is an @code{INTEGER_CST} for the smallest
integer that may be represented by this type. Similarly, the
@code{TYPE_MAX_VALUE} is an @code{INTEGER_CST} for the largest integer
that may be represented by this type.
@item REAL_TYPE
Used to represent the @code{float}, @code{double}, and @code{long
double} types. The number of bits in the floating-point representation
is given by @code{TYPE_PRECISION}, as in the @code{INTEGER_TYPE} case.
@item COMPLEX_TYPE
Used to represent GCC built-in @code{__complex__} data types. The
@code{TREE_TYPE} is the type of the real and imaginary parts.
@item ENUMERAL_TYPE
Used to represent an enumeration type. The @code{TYPE_PRECISION} gives
(as an @code{int}), the number of bits used to represent the type. If
there are no negative enumeration constants, @code{TREE_UNSIGNED} will
hold. The minimum and maximum enumeration constants may be obtained
with @code{TYPE_MIN_VALUE} and @code{TYPE_MAX_VALUE}, respectively; each
of these macros returns an @code{INTEGER_CST}.
The actual enumeration constants themselves may be obtained by looking
at the @code{TYPE_VALUES}. This macro will return a @code{TREE_LIST},
containing the constants. The @code{TREE_PURPOSE} of each node will be
an @code{IDENTIFIER_NODE} giving the name of the constant; the
@code{TREE_VALUE} will be an @code{INTEGER_CST} giving the value
assigned to that constant. These constants will appear in the order in
which they were declared. The @code{TREE_TYPE} of each of these
constants will be the type of enumeration type itself.
@item BOOLEAN_TYPE
Used to represent the @code{bool} type.
@item POINTER_TYPE
Used to represent pointer types, and pointer to data member types. The
@code{TREE_TYPE} gives the type to which this type points. If the type
is 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_TYPE
Used to represent reference types. The @code{TREE_TYPE} gives the type
to which this type refers.
@item FUNCTION_TYPE
Used to represent the type of non-member functions and of static member
functions. 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 the
corresponding argument; the @code{TREE_PURPOSE} is an expression for the
default 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 take
variable arguments. Otherwise, they do take a variable number of
arguments.
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 NULL.
@item METHOD_TYPE
Used 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 this
type 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_TYPE
Used to represent array types. The @code{TREE_TYPE} gives the type of
the 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 and
upper bounds of the array, respectively. The @code{TYPE_MIN_VALUE} will
always be an @code{INTEGER_CST} for zero, while the
@code{TYPE_MAX_VALUE} will be one less than the number of elements in
the array, i.e., the highest value which may be used to index an element
in the array.
@item RECORD_TYPE
Used to represent @code{struct} and @code{class} types, as well as
pointers to member functions. If @code{TYPE_PTRMEMFUNC_P} holds, then
this type is a pointer-to-member type. 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 the pointer-to-member function. If
@code{TYPE_PTRMEMFUNC_P} does not hold, this type is a class type. For
more information, see @pxref{Classes}.
@item UNKNOWN_TYPE
This node is used to represent a type the knowledge of which is
insufficient for a sound processing.
@item OFFSET_TYPE
This node is used to represent a data member; for example a
pointer-to-data-member is represented by a @code{POINTER_TYPE} whose
@code{TREE_TYPE} is an @code{OFFSET_TYPE}. For a data member @code{X::m}
the @code{TYPE_OFFSET_BASETYPE} is @code{X} and the @code{TREE_TYPE} is
the type of @code{m}.
@item TYPENAME_TYPE
Used 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 a
template-id, then @code{TYPENAME_TYPE_FULLNAME} yields a
@code{TEMPLATE_ID_EXPR}. The @code{TREE_TYPE} is non-@code{NULL} if the
node is implicitly generated in support for the implicit typename
extension; in which case the @code{TREE_TYPE} is a type node for the
base-class.
@item TYPEOF_TYPE
Used to represent the @code{__typeof__} extension. The
@code{TYPE_FIELDS} is the expression the type of which is being
represented.
@item UNION_TYPE
Used to represent @code{union} types. For more information, @pxref{Classes}.
@end table
There are variables whose values represent some of the basic types.
These include:
@table @code
@item void_type_node
A node for @code{void}.
@item integer_type_node
A 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
@noindent
It may sometimes be useful to compare one of these variables with a type
in hand, using @code{same_type_p}.
@c ---------------------------------------------------------------------
@c Scopes
@c ---------------------------------------------------------------------
@node Scopes
@section Scopes
@cindex namespace, class, scope
The 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 the
class. (Throughout this manual the term @dfn{class} is used to mean the
types referred to in the ANSI/ISO C++ Standard as classes; these include
types 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_DECL
A namespace is represented by a @code{NAMESPACE_DECL} node.
However, except for the fact that it is distinguished as the root of the
representation, the global namespace is no different from any other
namespace. Thus, in what follows, we describe namespaces generally,
rather than the global namespace in particular.
The @code{::std} namespace, however, @emph{is} special when
@code{flag_honor_std} is not set. When @code{flag_honor_std} is set,
the @code{std} namespace is just like any other namespace. When
@code{flag_honor_std} is not set, however, the @code{::std} namespace is
treated as a synonym for the global namespace, thereby allowing users to
write code that will work with compilers that put the standard library
in the @code{::std} namespace. The @code{std} namespace is represented
by the variable @code{std_node}. Although @code{std_node} is a
@code{NAMESPACE_DECL}, it does not have all the fields required of a
real namespace, and the macros and functions described here do not work,
in general. It is safest simply to ignore @code{std_node} should you
encounter it while examining the internal representation. In
particular, you will encounter @code{std_node} while looking at the
members of the global namespace. Just skip it without attempting to
examine its members.
The following macros and functions can be used on a @code{NAMESPACE_DECL}:
@ftable @code
@item DECL_NAME
This macro is used to obtain the @code{IDENTIFIER_NODE} corresponding to
the unqualified name of the name of the namespace (@pxref{Identifiers}).
The name of the global namespace is @samp{::}, even though in C++ the
global namespace is unnamed. However, you should use comparison with
@code{global_namespace}, rather than @code{DECL_NAME} to determine
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -