⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 c-tree.texi

📁 GCC
💻 TEXI
📖 第 1 页 / 共 5 页
字号:
whether or not a namespaces is the global one.  An unnamed namespace
will have a @code{DECL_NAME} equal to @code{anonymous_namespace_name}.
Within a single translation unit, all unnamed namespaces will have the
same name.

@item DECL_CONTEXT
This macro returns the enclosing namespace.  The @code{DECL_CONTEXT} for
the @code{global_namespace} is @code{NULL_TREE}.

@item DECL_NAMESPACE_ALIAS
If this declaration is for a namespace alias, then
@code{DECL_NAMESPACE_ALIAS} is the namespace for which this one is an
alias.

Do not attempt to use @code{cp_namespace_decls} for a namespace which is
an alias.  Instead, follow @code{DECL_NAMESPACE_ALIAS} links until you
reach an ordinary, non-alias, namespace, and call
@code{cp_namespace_decls} there.

@item DECL_NAMESPACE_STD_P
This predicate holds if the namespace is the special @code{::std}
namespace.

@item cp_namespace_decls
This 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 next
declaration in this list.

For more information on the kinds of declarations that can occur on this
list, @xref{Declarations}.  Some declarations will not appear on this
list.  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 TREE_VIA_PUBLIC
@findex TREE_VIA_PROTECTED
@findex TREE_VIA_PRIVATE
@findex TYPE_FIELDS
@findex TYPE_VFIELD
@findex TYPE_METHODS

A class type is represented by either a @code{RECORD_TYPE} or a
@code{UNION_TYPE}.  A class declared with the @code{union} tag is
represented by a @code{UNION_TYPE}, while classes declared with either
the @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} as
opposed to a @code{struct}.  This macro will be true only for classes
declared 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 in
which 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-static
data member, a @code{VAR_DECL} is used to represent a static data
member, and a @code{TYPE_DECL} is used to represent a type.  Note that
the @code{CONST_DECL} for an enumeration constant will appear on this
list, 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 an
object.

The @code{TYPE_VFIELD} is a compiler-generated field used to point to
virtual 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 functions
appears; 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 on
this 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.  The
binfo given by @code{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 @code{BINFO_BASETYPES}.  These
base-classes are themselves binfos.  The class type associated with a
binfo is given by @code{BINFO_TYPE}.  It is always the case that
@code{BINFO_TYPE (TYPE_BINFO (x))} is the same type as @code{x}, up to
qualifiers.  However, it is not always the case that @code{TYPE_BINFO
(BINFO_TYPE (y))} is always the same binfo as @code{y}.  The reason is
that if @code{y} is a binfo representing a base-class @code{B} of a
derived class @code{D}, then @code{BINFO_TYPE (y)} will be @code{B}, and
@code{TYPE_INFO (BINFO_TYPE (y))} will be @code{B} as its own
base-class, rather than as a base-class of @code{D}.

The @code{BINFO_BASETYPES} is a @code{TREE_VEC} (@pxref{Containers}).
Base types appear in left-to-right order in this vector.  You can tell
whether or @code{public}, @code{protected}, or @code{private}
inheritance was used by using the @code{TREE_VIA_PUBLIC},
@code{TREE_VIA_PROTECTED}, and @code{TREE_VIA_PRIVATE} macros.  Each of
these macros takes a @code{BINFO} and is true if and only if the
indicated kind of inheritance was used.  If @code{TREE_VIA_VIRTUAL}
holds of a binfo, then its @code{BINFO_TYPE} was inherited from
virtually.

FIXME: Talk about @code{TYPE_NONCOPIED_PARTS}.

The following macros can be used on a tree node representing a class-type.

@ftable @code
@item LOCAL_CLASS_P
This predicate holds if the class is local class @emph{i.e.} declared
inside a function body.

@item TYPE_POLYMORPHIC_P
This predicate holds if the class has at least one virtual function
(declared or inherited).

@item TYPE_HAS_DEFAULT_CONSTRUCTOR
This predicate holds whenever its argument represents a class-type with
default constructor.

@item CLASSTYPE_HAS_MUTABLE
@item TYPE_HAS_MUTABLE_P
These predicates hold for a class-type having a mutable data member.

@item CLASSTYPE_NON_POD_P
This predicate holds only for class-types that are not PODs.

@item TYPE_HAS_NEW_OPERATOR
This predicate holds for a class-type that defines
@code{operator new}.

@item TYPE_HAS_ARRAY_NEW_OPERATOR
This predicate holds for a class-type for which
@code{operator new[]} is defined.

@item TYPE_OVERLOADS_CALL_EXPR
This predicate holds for class-type for which the function call
@code{operator()} is overloaded.

@item TYPE_OVERLOADS_ARRAY_REF
This predicate holds for a class-type that overloads
@code{operator[]}

@item TYPE_OVERLOADS_ARROW
This predicate holds for a class-type for which @code{operator->} is
overloaded.

@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_EXTERNAL

This section covers the various kinds of declarations that appear in the
internal representation, except for declarations of functions
(represented by @code{FUNCTION_DECL} nodes), which are described in
@ref{Functions}.

Some macros can be used with any kind of declaration.  These include:
@ftable @code
@item DECL_NAME
This macro returns an @code{IDENTIFIER_NODE} giving the name of the
entity.

@item TREE_TYPE
This macro returns the type of the entity declared.

@item DECL_SOURCE_FILE
This macro returns the name of the file in which the entity was
declared, as a @code{char*}.  For an entity declared implicitly by the
compiler (like @code{__builtin_memcpy}), this will be the string
@code{"<internal>"}.

@item DECL_SOURCE_LINE
This macro returns the line number at which the entity was declared, as
an @code{int}.

@item DECL_ARTIFICIAL
This predicate holds if the declaration was implicitly generated by the
compiler.  For example, this predicate will hold of an implicitly
declared member function, or of the @code{TYPE_DECL} implicitly
generated for a class type.  Recall that in C++ code like:
@example
struct S @{@};
@end example
@noindent
is roughly equivalent to C code like:
@example
struct S @{@};
typedef struct S S;
@end example
The implicitly generated @code{typedef} declaration is represented by a
@code{TYPE_DECL} for which @code{DECL_ARTIFICIAL} holds.

@item DECL_NAMESPACE_SCOPE_P
This predicate holds if the entity was declared at a namespace scope.

@item DECL_CLASS_SCOPE_P
This predicate holds if the entity was declared at a class scope.

@item DECL_FUNCTION_SCOPE_P
This predicate holds if the entity was declared inside a function
body.

@end ftable

The various kinds of declarations include:
@table @code
@item LABEL_DECL
These nodes are used to represent labels in function bodies.  For more
information, see @ref{Functions}.  These nodes only appear in block
scopes.

@item CONST_DECL
These nodes are used to represent enumeration constants.  The value of
the 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_DECL
These nodes represent the value returned by a function.  When a value is
assigned to a @code{RESULT_DECL}, that indicates that the value should
be returned, via bitwise copy, by the function.  You can use
@code{DECL_SIZE} and @code{DECL_ALIGN} on a @code{RESULT_DECL}, just as
with a @code{VAR_DECL}.

@item TYPE_DECL
These nodes represent @code{typedef} declarations.  The @code{TREE_TYPE}
is the type declared to have the name given by @code{DECL_NAME}.  In
some cases, there is no associated name.

@item VAR_DECL
These nodes represent variables with namespace or block scope, as well
as static data members.  The @code{DECL_SIZE} and @code{DECL_ALIGN} are
analogous to @code{TYPE_SIZE} and @code{TYPE_ALIGN}.  For a declaration,
you should always use the @code{DECL_SIZE} and @code{DECL_ALIGN} rather
than the @code{TYPE_SIZE} and @code{TYPE_ALIGN} given by the
@code{TREE_TYPE}, since special attributes may have been applied to the
variable to give it a particular size and alignment. You may use the
predicates @code{DECL_THIS_STATIC} or @code{DECL_THIS_EXTERN} to test
whether the storage class specifiers @code{static} or @code{extern} were
used to declare a variable.

If this variable is initialized (but does not require a constructor),
the @code{DECL_INITIAL} will be an expression for the initializer.  The
initializer should be evaluated, and a bitwise copy into the variable
performed.  If the @code{DECL_INITIAL} is the @code{error_mark_node},
there is an initializer, but it is given by an explicit statement later
in the code; no bitwise copy is required.

GCC provides an extension that allows either automatic variables, or
global variables, to be placed in particular registers.  This extension
is being used for a particular @code{VAR_DECL} if @code{DECL_REGISTER}
holds for the @code{VAR_DECL}, and if @code{DECL_ASSEMBLER_NAME} is not
equal to @code{DECL_NAME}.  In that case, @code{DECL_ASSEMBLER_NAME} is
the name of the register into which the variable will be placed.

@item PARM_DECL
Used to represent a parameter to a function.  Treat these nodes
similarly to @code{VAR_DECL} nodes.  These nodes only appear in the
@code{DECL_ARGUMENTS} for a @code{FUNCTION_DECL}.

The @code{DECL_ARG_TYPE} for a @code{PARM_DECL} is the type that will
actually be used when a value is passed to this function.  It may be a
wider type than the @code{TREE_TYPE} of the parameter; for example, the
ordinary type might be @code{short} while the @code{DECL_ARG_TYPE} is
@code{int}.

@item FIELD_DECL
These nodes represent non-static data members.  The @code{DECL_SIZE} and
@code{DECL_ALIGN} behave as for @code{VAR_DECL} nodes.  The
@code{DECL_FIELD_BITPOS} gives the first bit used for this field, as an
@code{INTEGER_CST}.  These values are indexed from zero, where zero
indicates the first bit in the object.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -