The root of the entire intermediate representation is the variable
global_namespace
. This is the namespace specified with ::
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 class is used to mean the
types referred to in the ANSI/ISO C++ Standard as classes; these include
types defined with the class
, struct
, and union
keywords.)
A namespace is represented by a 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 ::std
namespace, however, is special, unless
flag_honor_std
is set. This variable is set by the use
`-fhonor-std' (or an option that implies it, like
`-fnew-abi'), when invoking G++. When flag_honor_std
is
set, the std
namespace is just like any other namespace. When
flag_honor_std
is not set, however, the ::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 ::std
namespace, even though the library supplied with G++
does not do so, as of GCC 2.95. The std
namespace is represented
by the variable std_node
. Although std_node
is a
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 std_node
should you
encounter it while examining the internal representation. In
particular, you will encounter 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 NAMESPACE_DECL
:
DECL_NAME
IDENTIFIER_NODE
corresponding to
the unqualified name of the name of the namespace (see section Identifiers).
The name of the global namespace is `::', even though in C++ the
global namespace is unnamed. However, you should use comparison with
global_namespace
, rather than DECL_NAME
to determine
whether or not a namespaces is the global one. An unnamed namespace
will have a DECL_NAME
equal to anonymous_namespace_name
.
Within a single translation unit, all unnamed namespaces will have the
same name.
DECL_CONTEXT
DECL_CONTEXT
for
the global_namespace
is NULL_TREE
.
DECL_NAMESPACE_ALIAS
DECL_NAMESPACE_ALIAS
is the namespace for which this one is an
alias.
Do not attempt to use cp_namespace_decls
for a namespace which is
an alias. Instead, follow DECL_NAMESPACE_ALIAS
links until you
reach an ordinary, non-alias, namespace, and call
cp_namespace_decls
there.
DECL_NAMESPACE_STD_P
::std
namespace.
cp_namespace_decls
NULL_TREE
. The declarations are connected through their
TREE_CHAIN
fields.
Although most entries on this list will be declarations,
TREE_LIST
nodes may also appear. In this case, the
TREE_VALUE
will be an OVERLOAD
. The value of the
TREE_PURPOSE
is unspecified; back-ends should ignore this value.
As with the other kinds of declarations returned by
cp_namespace_decls
, the TREE_CHAIN
will point to the next
declaration in this list.
For more information on the kinds of declarations that can occur on this
list, See section Declarations. Some declarations will not appear on this
list. In particular, no FIELD_DECL
, LABEL_DECL
, or
PARM_DECL
nodes will appear here.
This function cannot be used with namespaces that have
DECL_NAMESPACE_ALIAS
set.
A class type is represented by either a RECORD_TYPE
or a
UNION_TYPE
. A class declared with the union
tag is
represented by a UNION_TYPE
, while classes declared with either
the struct
or the class
tag are represented by
RECORD_TYPE
s. You can use the CLASSTYPE_DECLARED_CLASS
macro to discern whether or not a particular type is a class
as
opposed to a struct
. This macro will be true only for classes
declared with the class
tag.
Almost all non-function members are available on the TYPE_FIELDS
list. Given one member, the next can be found by following the
TREE_CHAIN
. You should not depend in any way on the order in
which fields appear on this list. All nodes on this list will be
`DECL' nodes. A FIELD_DECL
is used to represent a non-static
data member, a VAR_DECL
is used to represent a static data
member, and a TYPE_DECL
is used to represent a type. Note that
the CONST_DECL
for an enumeration constant will appear on this
list, if the enumeration type was declared in the class. (Of course,
the 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 FIELD_DECL
for the "base-class portion" of an
object.
The TYPE_VFIELD
is a compiler-generated field used to point to
virtual function tables. It may or may not appear on the
TYPE_FIELDS
list. However, back-ends should handle the
TYPE_VFIELD
just like all the entries on the TYPE_FIELDS
list.
The function members are available on the TYPE_METHODS
list.
Again, subsequent members are found by following the TREE_CHAIN
field. If a function is overloaded, each of the overloaded functions
appears; no OVERLOAD
nodes appear on the TYPE_METHODS
list. Implicitly declared functions (including default constructors,
copy constructors, assignment operators, and destructors) will appear on
this list as well.
Every class has an associated binfo, which can be obtained with
TYPE_BINFO
. Binfos are used to represent base-classes. The
binfo given by TYPE_BINFO
is the degenerate case, whereby every
class is considered to be its own base-class. The base classes for a
particular binfo can be obtained with BINFO_BASETYPES
. These
base-classes are themselves binfos. The class type associated with a
binfo is given by BINFO_TYPE
. It is always the case that
BINFO_TYPE (TYPE_BINFO (x))
is the same type as x
, up to
qualifiers. However, it is not always the case that TYPE_BINFO
(BINFO_TYPE (y))
is always the same binfo as y
. The reason is
that if y
is a binfo representing a base-class B
of a
derived class D
, then BINFO_TYPE (y)
will be B
, and
TYPE_INFO (BINFO_TYPE (y))
will be B
as its own
base-class, rather than as a base-class of D
.
The BINFO_BASETYPES
is a TREE_VEC
(see section Containers).
Base types appear in left-to-right order in this vector. You can tell
whether or public
, protected
, or private
inheritance was used by using the TREE_VIA_PUBLIC
,
TREE_VIA_PROTECTED
, and TREE_VIA_PRIVATE
macros. Each of
these macros takes a BINFO
and is true if and only if the
indicated kind of inheritance was used. If TREE_VIA_VIRTUAL
holds of a binfo, then its BINFO_TYPE
was inherited from
virtually.
FIXME: Talk about TYPE_NONCOPIED_PARTS
.
The following macros can be used on a tree node representing a class-type.
LOCAL_CLASS_P
TYPE_POLYMORPHIC_P
TYPE_HAS_DEFAULT_CONSTRUCTOR
CLASSTYPE_HAS_MUTABLE
TYPE_HAS_MUTABLE_P
CLASSTYPE_NON_POD_P
TYPE_HAS_NEW_OPERATOR
operator new
.
TYPE_HAS_ARRAY_NEW_OPERATOR
operator new[]
is defined.
TYPE_OVERLOADS_CALL_EXPR
operator()
is overloaded.
TYPE_OVERLOADS_ARRAY_REF
operator[]
TYPE_OVERLOADS_ARROW
operator->
is
overloaded.
Go to the first, previous, next, last section, table of contents.