Studying note of GCC-3.4.6 source (2)

1.1.1. Identifier of tree node - tree_code

Within the definition of tree_node, items like tree_type, tree_decl etc, are used for the semantics ingrediences, for example, tree_type is used for type definition, and type_decl is used for declaration. But further to tell, for example, what kind of declaration it is, we need a field in tree_node to provide the information. It is the code field at line 134 in tree_common definition.

 

31    #define DEFTREECODE(SYM, NAME, TYPE, LENGTH) SYM,

32   

33    enum tree_code {                                                                                              in tree.h

34    #include "tree.def"

35   

36      LAST_AND_UNUSED_TREE_CODE    /* A convenient way to get a value for

37                                          NUM_TREE_CODE.  */

38    };

39   

40    #undef DEFTREECODE

 

And for C++ front-end, an enum cplus_tree_code is defined to be appended after above definition.

 

887  enum cplus_tree_code {                                                                              in cp-tree.h

888    CP_DUMMY_TREE_CODE = LAST_C_TREE_CODE,

889  #include "cp-tree.def"

890    LAST_CPLUS_TREE_CODE

891  };

 

See the definition of part of tree_code common to all front-ends comes from tree.def. In this file, the content is a series of DEFTREECODE. See that at line 31, DEFTREECODE is defined to extract appropriate field accordingly. It is technique used broadly in GCC. The content of tree.def is shown in following table.

Tree Code

 

Type

Description

ERROR_MARK

x

Any erroneous construct is parsed into a node of this type.

IDENTIFIER_NODE

x

Used to represent a name (such as, in the DECL_NAME of a decl node).

TREE_LIST

x

Collection of tree_list

TREE_VEC

x

tree_vec

BLOCK

b

Code block

VOID_TYPE

t

The void type

INTEGER_TYPE

t

Integer types in all languages, including char in C.

REAL_TYPE

t

C's float and double.

COMPLEX_TYPE

t

 

VECTOR_TYPE

t

 

ENUMERAL_TYPE

t

C enums.

BOOLEAN_TYPE

t

Pascal's boolean type (true or false are the only values)

CHAR_TYPE

t

CHAR in Pascal; not used in C.

POINTER_TYPE

t

All pointer-to-x types have code POINTER_TYPE.

OFFSET_TYPE

t

An offset is a pointer relative to an object.

REFERENCE_TYPE

t

A reference is like a pointer except that it is coerced automatically to the value it points to. Used in C++.

METHOD_TYPE

t

METHOD_TYPE is the type of a function which takes an extra first argument for "self", which is not present in the declared argument list.

FILE_TYPE

t

Used for Pascal;

ARRAY_TYPE

t

 

SET_TYPE

t

Types of sets for Pascal.

RECORD_TYPE

t

Struct in C, or record in Pascal.

UNION_TYPE

t

Union in C. Like a struct, except that the offsets of the fields will all be zero.

QUAL_UNION_TYPE

t

 

FUNCTION_TYPE

t

Type of functions.

LANG_TYPE

t

This is a language-specific kind of type.

INTEGER_CST

c

Contents are in TREE_INT_CST_LOW and TREE_INT_CST_HIGH fields, 32 bits each, giving us a 64 bit constant capability.

REAL_CST

c

Floating constant

COMPLEX_CST

c

Complex constant

VECTOR_CST

c

Vector constant

STRING_CST

c

String constant

FUNCTION_DECL

d

Declaration of the function

LABEL_DECL

d

Declaration of label

CONST_DECL

d

Declaration of constant

TYPE_DECL

d

Declaration of type

VAR_DECL

d

Declaration of local variable, global variable, external variable, or static variable

PARM_DECL

d

Declaration of pararmeter for functions

RESULT_DECL

d

Declaration of returned value of functions

FIELD_DECL

d

Declaration of fields in struct/union/class

NAMESPACE_DECL

d

A namespace declaration.

TRANSLATION_UNIT_DECL

d

A translation unit.

COMPONENT_REF

r

References to storage.

BIT_FIELD_REF

r

Reference to a group of bits within an object.

INDIRECT_REF

r

C unary * or Pascal ^. One operand, an expression for a pointer.

BUFFER_REF

r

Pascal ^ on a file. One operand, an expression for the file.

ARRAY_REF

r

Array indexing. Operand 0 is the array; operand 1 is a (single) array index.

ARRAY_RANGE_REF

r

the result is a range ("slice") of the array.

VTABLE_REF

r

Vtable indexing. Carries data useful for emitting information for vtable garbage collection. Operand 0: an array_ref (or equivalent expression). Operand 1: the vtable base (must be a var_decl). Operand 2: index into vtable (must be an integer_cst).

CONSTRUCTOR

e

Constructor: return an aggregate value made from specified components.

COMPOUND_EXPR

e

Contains two expressions to compute, one followed by the other.

MODIFY_EXPR

e

Assignment expression. Operand 0 is the what to set; 1, the new value.

INIT_EXPR

e

Initialization expression. Operand 0 is the variable to initialize; Operand 1 is the initializer.

TARGET_EXPR

e

For TARGET_EXPR, operand 0 is the target of an initialization, operand 1 is the initializer for the target, and operand 2 is the cleanup for this node, if any. And operand 3 is the saved initializer after this node has been expanded once, this is so we can re-expand the tree later.

COND_EXPR

e

Conditional expression (... ? ... : ...  in C). Operand 0 is the condition. Operand 1 is the then-value. Operand 2 is the else-value. Operand 0 may be of any type. Operand 1 must have the same type as the entire expression, unless it unconditionally throws an exception, in which case it should have VOID_TYPE. The same constraints apply to operand 2.

BIND_EXPR

e

Declare local variables, including making RTL and allocating space. Operand 0 is a chain of VAR_DECL nodes for the variables. Operand 1 is the body, the expression to be computed using the variables. The value of operand 1 becomes that of the BIND_EXPR. Operand 2 is the BLOCK that corresponds to these bindings for debugging purposes.

CALL_EXPR

e

Function call. Operand 0 is the function. Operand 1 is the argument list, a list of expressions made out of a chain of TREE_LIST nodes.

WITH_CLEANUP_EXPR

e

Specify a value to compute along with its corresponding cleanup. Operand 0 argument is an expression whose value needs a cleanup. Operand 1 is the cleanup expression for the object. Operand 2 is an RTL_EXPR which will eventually represent that value. The RTL_EXPR is used in this expression, which is how the expression manages to act on the proper value.

CLEANUP_POINT_EXPR

e

Specify a cleanup point. Operand 0 is an expression that may have cleanups. If it does, those cleanups are executed after the expression is expanded.

PLACEHOLDER_EXPR

x

Denotes a record to later be supplied with a WITH_RECORD_EXPR when evaluating this expression. The type of this expression is used to find the record to replace it.

WITH_RECORD_EXPR

x

Provide an expression that references a record to be used in place of a PLACEHOLDER_EXPR. The record to be used is the record within operand 1 that has the same type as the PLACEHOLDER_EXPR in operand 0.

PLUS_EXPR

2

Plus expression

MINUS_EXPR

2

Minus expression

MULT_EXPR

2

Multiply expression

TRUNC_DIV_EXPR

2

Division for integer result that rounds the quotient toward zero.

CEIL_DIV_EXPR

2

Division for integer result that rounds the quotient toward infinity.

FLOOR_DIV_EXPR

2

Division for integer result that rounds toward minus infinity.

ROUND_DIV_EXPR

2

Division for integer result that rounds toward nearest integer.

TRUNC_MOD_EXPR

2

remainder

CEIL_MOD_EXPR

2

FLOOR_MOD_EXPR

2

ROUND_MOD_EXPR

2

RDIV_EXPR

2

Division for real result.

EXACT_DIV_EXPR

2

Division which is not supposed to need rounding. Used for pointer subtraction in C

FIX_TRUNC_EXPR

1

Conversion of real to fixed point

FIX_CEIL_EXPR

1

FIX_FLOOR_EXPR

1

FIX_ROUND_EXPR

1

FLOAT_EXPR

1

Conversion of an integer to a real.

NEGATE_EXPR

1

Unary negation.

MIN_EXPR

2

 

MAX_EXPR

2

 

ABS_EXPR

1

Represents the absolute value of the operand.

LSHIFT_EXPR

2

Shift means logical shift if done on an unsigned type, arithmetic shift if done on a signed type.

RSHIFT_EXPR

2

LROTATE_EXPR

2

RROTATE_EXPR

2

BIT_IOR_EXPR

2

Bitwise operations. Operands have same mode as result.

BIT_XOR_EXPR

2

BIT_AND_EXPR

2

BIT_NOT_EXPR

2

TRUTH_ANDIF_EXPR

e

ANDIF and ORIF allow the second operand not to be computed if the value of the expression is determined from the first operand. AND, OR, and XOR always compute the second operand whether its value is needed or not (for side effects). The operand may have BOOLEAN_TYPE or INTEGER_TYPE.

TRUTH_ORIF_EXPR

e

TRUTH_AND_EXPR

e

TRUTH_OR_EXPR

e

TRUTH_XOR_EXPR

e

TRUTH_NOT_EXPR

e

LT_EXPR

Relational operators. EQ_EXPR and NE_EXPR are allowed for any types. The others are allowed only for integer (or pointer or enumeral) or real types. In all cases the operands will have the same type, and the value is always the type used by the language for booleans.

LE_EXPR

GT_EXPR

GE_EXPR

EQ_EXPR

NE_EXPR

UNORDERED_EXPR

Additional relational operators for floating point unordered.

ORDERED_EXPR

UNLT_EXPR

These are unordered versions used by GCC. (GCC provides built-in versions of the ISO C99 floating point comparison macros that avoid raising exceptions for unordered operands. Floating point of NaN is unordered)

UNLE_EXPR

UNGT_EXPR

UNGE_EXPR

UNEQ_EXPR

IN_EXPR

2

Operations for Pascal sets. Not used now.

SET_LE_EXPR

CARD_EXPR

1

RANGE_EXPR

2

CONVERT_EXPR

1

Represents a conversion of type of a value.

NOP_EXPR

1

Represents a conversion expected to require no code to be generated.

NON_LVALUE_EXPR

1

Value is same as argument, but guaranteed not an lvalue.

VIEW_CONVERT_EXPR

1

Represents viewing something of one type as being of a second type. This corresponds to an Unchecked Conversion in Ada and roughly to the idiom *(type2 *)&X in C.

SAVE_EXPR

e

Represents something we computed once and will use multiple times.

UNSAVE_EXPR

e

By unsave, we mean that all _EXPRs such as TARGET_EXPRs, SAVE_EXPRs, CALL_EXPRs and RTL_EXPRs, that are protected from being evaluated more than once should be reset so that a new expand_expr call of this expr will cause those to be re-evaluated.

RTL_EXPR

e

Represents something whose RTL has already been expanded as a sequence which should be emitted when this expression is expanded.

ADDR_EXPR

e

& in C.

REFERENCE_EXPR

e

Non-lvalue reference or pointer to an object.

ENTRY_VALUE_EXPR

e

Operand is a function constant; result is a function variable value of type EPmode. Used only for languages that need static chains.

FDESC_EXPR

e

 

COMPLEX_EXPR

2

 

CONJ_EXPR

1

Complex conjugate of operand.

REALPART_EXPR

1

 

IMAGPART_EXPR

1

 

PREDECREMENT_EXPR

e

Nodes for ++ and -- in C. The second arg is how much to increment or decrement by. For a pointer, it would be the size of the object pointed to.

PREINCREMENT_EXPR

e

POSTDECREMENT_EXPR

e

POSTINCREMENT_EXPR

e

VA_ARG_EXPR

e

Used to implement va_arg.

TRY_CATCH_EXPR

e

 

TRY_FINALLY_EXPR

e

 

GOTO_SUBROUTINE_EXPR

e

Used internally for cleanups in the implementation of TRY_FINALLY_EXPR.

LABEL_EXPR

s

A label definition, encapsulated as a statement.

GOTO_EXPR

s

 

RETURN_EXPR

s

RETURN

EXIT_EXPR

s

Exit the inner most loop conditionally.

LOOP_EXPR

s

A loop.

LABELED_BLOCK_EXPR

e

A labeled block.

EXIT_BLOCK_EXPR

e

Exit a labeled block, possibly returning a value.

EXPR_WITH_FILE_LOCATION

e

Annotates a tree node (usually an expression) with source location nformation: a file name (EXPR_WFL_FILENAME); a line number   (EXPR_WFL_LINENO); and column number (EXPR_WFL_COLNO).

SWITCH_EXPR

e

Switch expression.

EXC_PTR_EXPR

e

The exception object from the runtime.

Table 1 Nodes definition in tree.def

 

In the Type column of the table, following characters are used for as class code, and their meaning are :

Ø       'x' for an exceptional code (fits no category).

Ø       't' for a type object code.

Ø       'b' for a lexical block.

Ø       'c' for codes for constants.

Ø       'd' for codes for declarations (also serving as variable refs).

Ø       'r' for codes for references to storage.

Ø       '<' for codes for comparison expressions.

Ø       '1' for codes for unary arithmetic expressions.

Ø       '2' for codes for binary arithmetic expressions.

Ø       's' for codes for "statement" expressions, which have side-effects, but usually no interesting value.

Ø       'e' for codes for other kinds of expressions.

For `r', `e', `<', `1', `2', and `s' class nodes, which associate with struct tree_exp, the 4th element of DEFTREECODE definition is the number of argument slots to allocate. This determines the size of the instance of the tree node. Other nodes use other structures in the union, and the size is determined by the structure; and the 4th element should be zero. Languages that define language-specific 'x' or 'c' nodes must define the tree_size hook in langhook to announce how big they are.

Again, for C++ front-end, for those language specific nodes, they are defined in cp-tree.def as below table shows.

Tree Code

 

Type

Description

OFFSET_REF

r

An OFFSET_REF is used in two situations:

1      An expression of the form A::m where A is a class and m is a non-static member. In this case, operand 0 will be a TYPE (corresponding to A) and operand 1 will be a FIELD_DECL, BASELINK, or TEMPLATE_ID_EXPR (corresponding to m).

The expression is a pointer-to-member if its address is taken, but simply denotes a member of the object if its address isnot taken.

This form is only used during the parsing phase; once semantic analysis has taken place they are eliminated.

2      An expression of the form x.*p. In this case, operand 0 will be an expression corresponding to x and operand 1 will be an expression with pointer-to-member type.

PTRMEM_CST

c

A pointer-to-member constant. For a pointer-to-member constant X::Y, the PTRMEM_CST_CLASS is the RECORD_TYPE for X and the  PTRMEM_CST_MEMBER is the _DECL for Y.

NEW_EXPR

VEC_NEW_EXPR

e

e

For NEW_EXPR, operand 0 is the placement list.  Operand 1 is the new-declarator. Operand 2 is the initializer.

DELETE_EXPR

VEC_DELETE_EXPR

e

e

For DELETE_EXPR, operand 0 is the store to be destroyed. Operand 1 is the value to pass to the destroying function saying whether the store should be deallocated as well.

SCOPE_REF

r

Value is reference to particular overloaded class method. Operand 0 is the class, operand 1 is the field. The COMPLEXITY field holds the class level (usually 0).

MEMBER_REF

r

When decomposing an object with a member, this is the result. Operand 0 is the object. Operand 1 is the member (usually a dereferenced pointer to member).

TYPE_EXPR

e

Type conversion operator in C++. TREE_TYPE is type that this operator converts to. Operand 0 is expression to be converted.

AGGR_INIT_EXPR

e

For AGGR_INIT_EXPR, operand 0 is function which performs initialization, operand 1 is argument list to initialization function, and operand 2 is the slot which was allocated for this expression.

THROW_EXPR

e

A throw expression. Operand 0 is the expression, if there was one, else it is NULL_TREE.

EMPTY_CLASS_EXPR

e

An empty class object. The TREE_TYPE gives the class type. We use these to avoid actually creating instances of the empty classes.

ALIAS_DECL

d

A DECL which is really just a placeholder for an expression. Used to implement non-class scope anonymous unions.

BASELINK

x

A reference to a member function or member functions from a base class. BASELINK_FUNCTIONS gives the FUNCTION_DECL, TEMPLATE_DECL, OVERLOAD, or TEMPLATE_ID_EXPR corresponding to the functions. BASELINK_BINFO gives the base from which the functions come, i.e., the base to which the this pointer must be converted before the functions are called. BASELINK_ACCESS_BINFO gives the base used to name the functions.

A BASELINK is an expression; the TREE_TYPE of the BASELINK gives the type of the expression. This type is either a FUNCTION_TYPE, METHOD_TYPE, or unknown_type_node indicating that the function is overloaded.

TEMPLATE_DECL

d

Template definition. The following fields have the specified uses, although there are other macros in cp-tree.h that should be used for accessing this data.

DECL_ARGUMENTS -- template parm vector

DECL_TEMPLATE_INFO -- template-specific information

DECL_VINDEX -- list of instantiations already produced; only done for functions so far

TREE_TYPE  -- type of object to be constructed

DECL_TEMPLATE_RESULT -- decl for object to be created (e.g., FUNCTION_DECL with tmpl parms used)

TEMPLATE_PARM_INDEX

x

Index into a template parameter list. The TEMPLATE_PARM_IDX gives the index (from 0) of the parameter, while the TEMPLATE_PARM_LEVEL gives the level (from 1) of the parameter.

   Here's an example:

   template <class T> // Index 0, Level 1.

   struct S

   {

      template <class U, // Index 0, Level 2.

                class V> // Index 1, Level 2.

      void f();

   }; 

The TEMPLATE_PARM_DESCENDANTS will be a chain of TEMPLATE_PARM_INDEXs descended from this one. The first descendant will have the same IDX, but its LEVEL will be one less. The TREE_CHAIN field is used to chain together the descendants. The TEMPLATE_PARM_DECL is the declaration of this parameter, either a TYPE_DECL or CONST_DECL.   The TEMPLATE_PARM_ORIG_LEVEL is the LEVEL of the most distant parent, i.e., the LEVEL that the parameter originally had when it was declared. For example, if we instantiate S<int>, we will have:

 struct S<int>

 {

   template <class U, // Index 0, Level 1, Orig Level 2

           class V> // Index 1, Level 1, Orig Level 2

   void f();

 };

The TEMPLATE_PARM_LEVEL is the level of the parameter when we are worrying about the types of things; the TEMPLATE_PARM_ORIG_LEVEL is the level when we are worrying about instantiating things.

TEMPLATE_TYPE_PARM

t

Index into a template parameter list. This parameter must be a type. The TYPE_FIELDS value will be a TEMPLATE_PARM_INDEX.

TEMPLATE_TEMPLATE_PARM

t

Index into a template parameter list for template template parameters. This parameter must be a type. The TYPE_FIELDS value will be a TEMPLATE_PARM_INDEX.

It is used without template arguments like TT in C<TT>,    TEMPLATE_TEMPLATE_PARM_TEMPLATE_INFO is NULL_TREE and TYPE_NAME is a TEMPLATE_DECL.

BOUND_TEMPLATE_TEMPLATE_PARM

t

Like TEMPLATE_TEMPLATE_PARM it is used with bound template arguments like TT<int>. In this case, TEMPLATE_TEMPLATE_PARM_TEMPLATE_INFO contains the template name and its bound arguments. TYPE_NAME is a TYPE_DECL.

TYPENAME_TYPE

t

A type designated by typename T::t. TYPE_CONTEXT is T, TYPE_NAME is an IDENTIFIER_NODE for t. If the type was named via template-id, TYPENAME_TYPE_FULLNAME will hold the TEMPLATE_ID_EXPR. If TREE_TYPE is present, this type was generated by the implicit typename extension, and the TREE_TYPE is a _TYPE from a baseclass of T.

UNBOUND_CLASS_TEMPLATE

t

For template template argument of the form T::template C. TYPE_CONTEXT is T, the template parameter dependent object. TYPE_NAME is an IDENTIFIER_NODE for C, the member class template.

TYPEOF_TYPE

t

A type designated by __typeof (expr). TYPE_FIELDS is the expression in question.

USING_DECL

d

A using declaration. DECL_INITIAL contains the specified scope. This is not an alias, but is later expanded into multiple aliases. The decl will have a NULL_TYPE iff the scope is a dependent scope, otherwise it will have a void type.

USING_STMT

e

A using directive. The operand is USING_STMT_NAMESPACE.

DEFAULT_ARG

x

An un-parsed default argument. TREE_CHAIN is used to hold instantiations of functions that had to be instantiated before the argument was parsed.

TEMPLATE_ID_EXPR

e

A template-id, like foo<int>. The first operand is the template. The second is NULL if there are no explicit arguments, or a TREE_VEC of arguments. The template will be a FUNCTION_DECL, TEMPLATE_DECL, or an OVERLOAD. If the template-id refers to a member template, the template may be an IDENTIFIER_NODE.

OVERLOAD

x

A list-like node for chaining overloading candidates.

WRAPPER

x

A generic wrapper for something not tree that we want to include in tree structure.

MODOP_EXPR

e

 

CAST_EXPR

1

 

REINTERPRET_CAST_EXPR

1

 

CONST_CAST_EXPR

1

 

STATIC_CAST_EXPR

1

 

DYNAMIC_CAST_EXPR

1

 

DOTSTAR_EXPR

e

 

TYPEID_EXPR

e

 

PSEUDO_DTOR_EXPR

e

 

NON_DEPENDENT_EXPR

e

A placeholder for an expression that is not type-dependent, but does occur in a template. When an expression that is not type-dependent appears in a larger expression, we must compute the type of that larger expression. That computation would normally modify the original expression, which would change the mangling of that expression if it appeared in a template argument list. In that situation, we create a NON_DEPENDENT_EXPR to take the place of the original expression. The expression is the only operand -- it is only needed for diagnostics.

CTOR_INITIALIZER

e

 

TRY_BLOCK

e

 

EH_SPEC_BLOCK

e

 

HANDLER

e

A HANDLER wraps a catch handler for the HANDLER_TYPE. The declaration of the catch variable is in HANDLER_PARMS, and the body block in HANDLER_BODY.

MUST_NOT_THROW_EXPR

e

A MUST_NOT_THROW_EXPR wraps an expression that may not throw, and must call terminate if it does.

TAG_DEFN

e

Used to represent implicit conversion sequences, in the sense of [over.best.ics]. The conversion sequences are connected through their first operands, with the first conversion to be performed at the end of the chain. The innermost conversion (i.e, the one at the end of the chain) is always an IDENTITY_CONV, corresponding to the identity conversion.

IDENTITY_CONV

e

LVALUE_CONV

e

QUAL_CONV

e

STD_CONV

e

PTR_CONV

e

PMEM_CONV

e

BASE_CONV

e

REF_BIND

e

USER_CONV

e

AMBIG_CONV

e

RVALUE_CONV

e

Table 2 Nodes definition in cp-tree.def

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值