c-tree.texi revision 132718
1132718Skan@c Copyright (c) 1999, 2000, 2001, 2002, 2003, 2004 Free Software Foundation, Inc. 290075Sobrien@c Free Software Foundation, Inc. 390075Sobrien@c This is part of the GCC manual. 490075Sobrien@c For copying conditions, see the file gcc.texi. 590075Sobrien 690075Sobrien@c --------------------------------------------------------------------- 790075Sobrien@c Trees 890075Sobrien@c --------------------------------------------------------------------- 990075Sobrien 1090075Sobrien@node Trees 1190075Sobrien@chapter Trees: The intermediate representation used by the C and C++ front ends 1290075Sobrien@cindex Trees 1390075Sobrien@cindex C/C++ Internal Representation 1490075Sobrien 1590075SobrienThis chapter documents the internal representation used by GCC to 1690075Sobrienrepresent C and C++ source programs. When presented with a C or C++ 1790075Sobriensource program, GCC parses the program, performs semantic analysis 1890075Sobrien(including the generation of error messages), and then produces the 1990075Sobrieninternal representation described here. This representation contains a 2090075Sobriencomplete representation for the entire translation unit provided as 2190075Sobrieninput to the front end. This representation is then typically processed 2290075Sobrienby a code-generator in order to produce machine code, but could also be 2390075Sobrienused in the creation of source browsers, intelligent editors, automatic 2490075Sobriendocumentation generators, interpreters, and any other programs needing 2590075Sobrienthe ability to process C or C++ code. 2690075Sobrien 2790075SobrienThis chapter explains the internal representation. In particular, it 2890075Sobriendocuments the internal representation for C and C++ source 2990075Sobrienconstructs, and the macros, functions, and variables that can be used to 3096263Sobrienaccess these constructs. The C++ representation is largely a superset 3190075Sobrienof the representation used in the C front end. There is only one 3290075Sobrienconstruct used in C that does not appear in the C++ front end and that 3390075Sobrienis the GNU ``nested function'' extension. Many of the macros documented 3490075Sobrienhere do not apply in C because the corresponding language constructs do 3590075Sobriennot appear in C@. 3690075Sobrien 3790075SobrienIf you are developing a ``back end'', be it is a code-generator or some 3890075Sobrienother tool, that uses this representation, you may occasionally find 3990075Sobrienthat you need to ask questions not easily answered by the functions and 4090075Sobrienmacros available here. If that situation occurs, it is quite likely 4190075Sobrienthat GCC already supports the functionality you desire, but that the 4290075Sobrieninterface is simply not documented here. In that case, you should ask 4390075Sobrienthe GCC maintainers (via mail to @email{gcc@@gcc.gnu.org}) about 4490075Sobriendocumenting the functionality you require. Similarly, if you find 4590075Sobrienyourself writing functions that do not deal directly with your back end, 4690075Sobrienbut instead might be useful to other people using the GCC front end, you 4790075Sobrienshould submit your patches for inclusion in GCC@. 4890075Sobrien 4990075Sobrien@menu 5090075Sobrien* Deficiencies:: Topics net yet covered in this document. 5190075Sobrien* Tree overview:: All about @code{tree}s. 5290075Sobrien* Types:: Fundamental and aggregate types. 5390075Sobrien* Scopes:: Namespaces and classes. 5490075Sobrien* Functions:: Overloading, function bodies, and linkage. 5590075Sobrien* Declarations:: Type declarations and variables. 5690075Sobrien* Attributes:: Declaration and type attributes. 5790075Sobrien* Expression trees:: From @code{typeid} to @code{throw}. 5890075Sobrien@end menu 5990075Sobrien 6090075Sobrien@c --------------------------------------------------------------------- 6190075Sobrien@c Deficiencies 6290075Sobrien@c --------------------------------------------------------------------- 6390075Sobrien 6490075Sobrien@node Deficiencies 6590075Sobrien@section Deficiencies 6690075Sobrien 6790075SobrienThere are many places in which this document is incomplet and incorrekt. 6890075SobrienIt is, as of yet, only @emph{preliminary} documentation. 6990075Sobrien 7090075Sobrien@c --------------------------------------------------------------------- 7190075Sobrien@c Overview 7290075Sobrien@c --------------------------------------------------------------------- 7390075Sobrien 7490075Sobrien@node Tree overview 7590075Sobrien@section Overview 7690075Sobrien@cindex tree 7790075Sobrien@findex TREE_CODE 7890075Sobrien 7990075SobrienThe central data structure used by the internal representation is the 8090075Sobrien@code{tree}. These nodes, while all of the C type @code{tree}, are of 8190075Sobrienmany varieties. A @code{tree} is a pointer type, but the object to 8290075Sobrienwhich it points may be of a variety of types. From this point forward, 8390075Sobrienwe will refer to trees in ordinary type, rather than in @code{this 8490075Sobrienfont}, except when talking about the actual C type @code{tree}. 8590075Sobrien 8690075SobrienYou can tell what kind of node a particular tree is by using the 87117395Skan@code{TREE_CODE} macro. Many, many macros take trees as input and 88117395Skanreturn trees as output. However, most macros require a certain kind of 8990075Sobrientree node as input. In other words, there is a type-system for trees, 9090075Sobrienbut it is not reflected in the C type-system. 9190075Sobrien 9290075SobrienFor safety, it is useful to configure GCC with @option{--enable-checking}. 9390075SobrienAlthough this results in a significant performance penalty (since all 9490075Sobrientree types are checked at run-time), and is therefore inappropriate in a 9590075Sobrienrelease version, it is extremely helpful during the development process. 9690075Sobrien 9790075SobrienMany macros behave as predicates. Many, although not all, of these 9890075Sobrienpredicates end in @samp{_P}. Do not rely on the result type of these 9990075Sobrienmacros being of any particular type. You may, however, rely on the fact 10090075Sobrienthat the type can be compared to @code{0}, so that statements like 101132718Skan@smallexample 10290075Sobrienif (TEST_P (t) && !TEST_P (y)) 10390075Sobrien x = 1; 104132718Skan@end smallexample 10590075Sobrien@noindent 10690075Sobrienand 107132718Skan@smallexample 10890075Sobrienint i = (TEST_P (t) != 0); 109132718Skan@end smallexample 11090075Sobrien@noindent 11190075Sobrienare legal. Macros that return @code{int} values now may be changed to 11290075Sobrienreturn @code{tree} values, or other pointers in the future. Even those 11390075Sobrienthat continue to return @code{int} may return multiple nonzero codes 11490075Sobrienwhere previously they returned only zero and one. Therefore, you should 11590075Sobriennot write code like 116132718Skan@smallexample 11790075Sobrienif (TEST_P (t) == 1) 118132718Skan@end smallexample 11990075Sobrien@noindent 12090075Sobrienas this code is not guaranteed to work correctly in the future. 12190075Sobrien 12290075SobrienYou should not take the address of values returned by the macros or 12390075Sobrienfunctions described here. In particular, no guarantee is given that the 12490075Sobrienvalues are lvalues. 12590075Sobrien 12690075SobrienIn general, the names of macros are all in uppercase, while the names of 127132718Skanfunctions are entirely in lowercase. There are rare exceptions to this 12890075Sobrienrule. You should assume that any macro or function whose name is made 12990075Sobrienup entirely of uppercase letters may evaluate its arguments more than 13090075Sobrienonce. You may assume that a macro or function whose name is made up 13190075Sobrienentirely of lowercase letters will evaluate its arguments only once. 13290075Sobrien 13390075SobrienThe @code{error_mark_node} is a special tree. Its tree code is 13490075Sobrien@code{ERROR_MARK}, but since there is only ever one node with that code, 13590075Sobrienthe usual practice is to compare the tree against 13690075Sobrien@code{error_mark_node}. (This test is just a test for pointer 13790075Sobrienequality.) If an error has occurred during front-end processing the 13890075Sobrienflag @code{errorcount} will be set. If the front end has encountered 13990075Sobriencode it cannot handle, it will issue a message to the user and set 14090075Sobrien@code{sorrycount}. When these flags are set, any macro or function 14190075Sobrienwhich normally returns a tree of a particular kind may instead return 14290075Sobrienthe @code{error_mark_node}. Thus, if you intend to do any processing of 14390075Sobrienerroneous code, you must be prepared to deal with the 14490075Sobrien@code{error_mark_node}. 14590075Sobrien 14690075SobrienOccasionally, a particular tree slot (like an operand to an expression, 14790075Sobrienor a particular field in a declaration) will be referred to as 14890075Sobrien``reserved for the back end.'' These slots are used to store RTL when 14990075Sobrienthe tree is converted to RTL for use by the GCC back end. However, if 15090075Sobrienthat process is not taking place (e.g., if the front end is being hooked 15190075Sobrienup to an intelligent editor), then those slots may be used by the 15290075Sobrienback end presently in use. 15390075Sobrien 15490075SobrienIf you encounter situations that do not match this documentation, such 15590075Sobrienas tree nodes of types not mentioned here, or macros documented to 15690075Sobrienreturn entities of a particular kind that instead return entities of 15790075Sobriensome different kind, you have found a bug, either in the front end or in 15890075Sobrienthe documentation. Please report these bugs as you would any other 15990075Sobrienbug. 16090075Sobrien 16190075Sobrien@menu 16290075Sobrien* Macros and Functions::Macros and functions that can be used with all trees. 16390075Sobrien* Identifiers:: The names of things. 16490075Sobrien* Containers:: Lists and vectors. 16590075Sobrien@end menu 16690075Sobrien 16790075Sobrien@c --------------------------------------------------------------------- 16890075Sobrien@c Trees 16990075Sobrien@c --------------------------------------------------------------------- 17090075Sobrien 17190075Sobrien@node Macros and Functions 17290075Sobrien@subsection Trees 17390075Sobrien@cindex tree 17490075Sobrien 17590075SobrienThis section is not here yet. 17690075Sobrien 17790075Sobrien@c --------------------------------------------------------------------- 17890075Sobrien@c Identifiers 17990075Sobrien@c --------------------------------------------------------------------- 18090075Sobrien 18190075Sobrien@node Identifiers 18290075Sobrien@subsection Identifiers 18390075Sobrien@cindex identifier 18490075Sobrien@cindex name 18590075Sobrien@tindex IDENTIFIER_NODE 18690075Sobrien 18790075SobrienAn @code{IDENTIFIER_NODE} represents a slightly more general concept 18890075Sobrienthat the standard C or C++ concept of identifier. In particular, an 18990075Sobrien@code{IDENTIFIER_NODE} may contain a @samp{$}, or other extraordinary 19090075Sobriencharacters. 19190075Sobrien 19290075SobrienThere are never two distinct @code{IDENTIFIER_NODE}s representing the 19390075Sobriensame identifier. Therefore, you may use pointer equality to compare 19490075Sobrien@code{IDENTIFIER_NODE}s, rather than using a routine like @code{strcmp}. 19590075Sobrien 19690075SobrienYou can use the following macros to access identifiers: 19790075Sobrien@ftable @code 19890075Sobrien@item IDENTIFIER_POINTER 19990075SobrienThe string represented by the identifier, represented as a 20090075Sobrien@code{char*}. This string is always @code{NUL}-terminated, and contains 20190075Sobrienno embedded @code{NUL} characters. 20290075Sobrien 20390075Sobrien@item IDENTIFIER_LENGTH 20490075SobrienThe length of the string returned by @code{IDENTIFIER_POINTER}, not 20590075Sobrienincluding the trailing @code{NUL}. This value of 20690075Sobrien@code{IDENTIFIER_LENGTH (x)} is always the same as @code{strlen 20790075Sobrien(IDENTIFIER_POINTER (x))}. 20890075Sobrien 20990075Sobrien@item IDENTIFIER_OPNAME_P 21090075SobrienThis predicate holds if the identifier represents the name of an 21190075Sobrienoverloaded operator. In this case, you should not depend on the 21290075Sobriencontents of either the @code{IDENTIFIER_POINTER} or the 21390075Sobrien@code{IDENTIFIER_LENGTH}. 21490075Sobrien 21590075Sobrien@item IDENTIFIER_TYPENAME_P 21690075SobrienThis predicate holds if the identifier represents the name of a 21790075Sobrienuser-defined conversion operator. In this case, the @code{TREE_TYPE} of 21890075Sobrienthe @code{IDENTIFIER_NODE} holds the type to which the conversion 21990075Sobrienoperator converts. 22090075Sobrien 22190075Sobrien@end ftable 22290075Sobrien 22390075Sobrien@c --------------------------------------------------------------------- 22490075Sobrien@c Containers 22590075Sobrien@c --------------------------------------------------------------------- 22690075Sobrien 22790075Sobrien@node Containers 22890075Sobrien@subsection Containers 22990075Sobrien@cindex container 23090075Sobrien@cindex list 23190075Sobrien@cindex vector 23290075Sobrien@tindex TREE_LIST 23390075Sobrien@tindex TREE_VEC 23490075Sobrien@findex TREE_PURPOSE 23590075Sobrien@findex TREE_VALUE 23690075Sobrien@findex TREE_VEC_LENGTH 23790075Sobrien@findex TREE_VEC_ELT 23890075Sobrien 23990075SobrienTwo common container data structures can be represented directly with 24090075Sobrientree nodes. A @code{TREE_LIST} is a singly linked list containing two 24190075Sobrientrees per node. These are the @code{TREE_PURPOSE} and @code{TREE_VALUE} 24290075Sobrienof each node. (Often, the @code{TREE_PURPOSE} contains some kind of 24390075Sobrientag, or additional information, while the @code{TREE_VALUE} contains the 24490075Sobrienmajority of the payload. In other cases, the @code{TREE_PURPOSE} is 24590075Sobriensimply @code{NULL_TREE}, while in still others both the 24690075Sobrien@code{TREE_PURPOSE} and @code{TREE_VALUE} are of equal stature.) Given 24790075Sobrienone @code{TREE_LIST} node, the next node is found by following the 24890075Sobrien@code{TREE_CHAIN}. If the @code{TREE_CHAIN} is @code{NULL_TREE}, then 24990075Sobrienyou have reached the end of the list. 25090075Sobrien 25190075SobrienA @code{TREE_VEC} is a simple vector. The @code{TREE_VEC_LENGTH} is an 25290075Sobrieninteger (not a tree) giving the number of nodes in the vector. The 25390075Sobriennodes themselves are accessed using the @code{TREE_VEC_ELT} macro, which 25490075Sobrientakes two arguments. The first is the @code{TREE_VEC} in question; the 25590075Sobriensecond is an integer indicating which element in the vector is desired. 25690075SobrienThe elements are indexed from zero. 25790075Sobrien 25890075Sobrien@c --------------------------------------------------------------------- 25990075Sobrien@c Types 26090075Sobrien@c --------------------------------------------------------------------- 26190075Sobrien 26290075Sobrien@node Types 26390075Sobrien@section Types 26490075Sobrien@cindex type 26590075Sobrien@cindex pointer 26690075Sobrien@cindex reference 26790075Sobrien@cindex fundamental type 26890075Sobrien@cindex array 26990075Sobrien@tindex VOID_TYPE 27090075Sobrien@tindex INTEGER_TYPE 27190075Sobrien@tindex TYPE_MIN_VALUE 27290075Sobrien@tindex TYPE_MAX_VALUE 27390075Sobrien@tindex REAL_TYPE 27490075Sobrien@tindex COMPLEX_TYPE 27590075Sobrien@tindex ENUMERAL_TYPE 27690075Sobrien@tindex BOOLEAN_TYPE 27790075Sobrien@tindex POINTER_TYPE 27890075Sobrien@tindex REFERENCE_TYPE 27990075Sobrien@tindex FUNCTION_TYPE 28090075Sobrien@tindex METHOD_TYPE 28190075Sobrien@tindex ARRAY_TYPE 28290075Sobrien@tindex RECORD_TYPE 28390075Sobrien@tindex UNION_TYPE 28490075Sobrien@tindex UNKNOWN_TYPE 28590075Sobrien@tindex OFFSET_TYPE 28690075Sobrien@tindex TYPENAME_TYPE 28790075Sobrien@tindex TYPEOF_TYPE 28890075Sobrien@findex CP_TYPE_QUALS 28990075Sobrien@findex TYPE_UNQUALIFIED 29090075Sobrien@findex TYPE_QUAL_CONST 29190075Sobrien@findex TYPE_QUAL_VOLATILE 29290075Sobrien@findex TYPE_QUAL_RESTRICT 29390075Sobrien@findex TYPE_MAIN_VARIANT 29490075Sobrien@cindex qualified type 29590075Sobrien@findex TYPE_SIZE 29690075Sobrien@findex TYPE_ALIGN 29790075Sobrien@findex TYPE_PRECISION 29890075Sobrien@findex TYPE_ARG_TYPES 29990075Sobrien@findex TYPE_METHOD_BASETYPE 30090075Sobrien@findex TYPE_PTRMEM_P 30190075Sobrien@findex TYPE_OFFSET_BASETYPE 30290075Sobrien@findex TREE_TYPE 30390075Sobrien@findex TYPE_CONTEXT 30490075Sobrien@findex TYPE_NAME 30590075Sobrien@findex TYPENAME_TYPE_FULLNAME 30690075Sobrien@findex TYPE_FIELDS 30790075Sobrien@findex TYPE_PTROBV_P 30890075Sobrien 30990075SobrienAll types have corresponding tree nodes. However, you should not assume 31090075Sobrienthat there is exactly one tree node corresponding to each type. There 31190075Sobrienare often several nodes each of which correspond to the same type. 31290075Sobrien 31390075SobrienFor the most part, different kinds of types have different tree codes. 31490075Sobrien(For example, pointer types use a @code{POINTER_TYPE} code while arrays 31590075Sobrienuse an @code{ARRAY_TYPE} code.) However, pointers to member functions 31690075Sobrienuse the @code{RECORD_TYPE} code. Therefore, when writing a 31790075Sobrien@code{switch} statement that depends on the code associated with a 31890075Sobrienparticular type, you should take care to handle pointers to member 31990075Sobrienfunctions under the @code{RECORD_TYPE} case label. 32090075Sobrien 32190075SobrienIn C++, an array type is not qualified; rather the type of the array 32290075Sobrienelements is qualified. This situation is reflected in the intermediate 32390075Sobrienrepresentation. The macros described here will always examine the 32490075Sobrienqualification of the underlying element type when applied to an array 32590075Sobrientype. (If the element type is itself an array, then the recursion 32690075Sobriencontinues until a non-array type is found, and the qualification of this 32790075Sobrientype is examined.) So, for example, @code{CP_TYPE_CONST_P} will hold of 32890075Sobrienthe type @code{const int ()[7]}, denoting an array of seven @code{int}s. 32990075Sobrien 33090075SobrienThe following functions and macros deal with cv-qualification of types: 33190075Sobrien@ftable @code 33290075Sobrien@item CP_TYPE_QUALS 33390075SobrienThis macro returns the set of type qualifiers applied to this type. 33490075SobrienThis value is @code{TYPE_UNQUALIFIED} if no qualifiers have been 33590075Sobrienapplied. The @code{TYPE_QUAL_CONST} bit is set if the type is 33690075Sobrien@code{const}-qualified. The @code{TYPE_QUAL_VOLATILE} bit is set if the 33790075Sobrientype is @code{volatile}-qualified. The @code{TYPE_QUAL_RESTRICT} bit is 33890075Sobrienset if the type is @code{restrict}-qualified. 33990075Sobrien 34090075Sobrien@item CP_TYPE_CONST_P 34190075SobrienThis macro holds if the type is @code{const}-qualified. 34290075Sobrien 34390075Sobrien@item CP_TYPE_VOLATILE_P 34490075SobrienThis macro holds if the type is @code{volatile}-qualified. 34590075Sobrien 34690075Sobrien@item CP_TYPE_RESTRICT_P 34790075SobrienThis macro holds if the type is @code{restrict}-qualified. 34890075Sobrien 34990075Sobrien@item CP_TYPE_CONST_NON_VOLATILE_P 35090075SobrienThis predicate holds for a type that is @code{const}-qualified, but 35190075Sobrien@emph{not} @code{volatile}-qualified; other cv-qualifiers are ignored as 35290075Sobrienwell: only the @code{const}-ness is tested. 35390075Sobrien 35490075Sobrien@item TYPE_MAIN_VARIANT 35590075SobrienThis macro returns the unqualified version of a type. It may be applied 35690075Sobriento an unqualified type, but it is not always the identity function in 35790075Sobrienthat case. 35890075Sobrien@end ftable 35990075Sobrien 36090075SobrienA few other macros and functions are usable with all types: 36190075Sobrien@ftable @code 36290075Sobrien@item TYPE_SIZE 36390075SobrienThe number of bits required to represent the type, represented as an 36490075Sobrien@code{INTEGER_CST}. For an incomplete type, @code{TYPE_SIZE} will be 36590075Sobrien@code{NULL_TREE}. 36690075Sobrien 36790075Sobrien@item TYPE_ALIGN 36890075SobrienThe alignment of the type, in bits, represented as an @code{int}. 36990075Sobrien 37090075Sobrien@item TYPE_NAME 37190075SobrienThis macro returns a declaration (in the form of a @code{TYPE_DECL}) for 37290075Sobrienthe type. (Note this macro does @emph{not} return a 37390075Sobrien@code{IDENTIFIER_NODE}, as you might expect, given its name!) You can 37490075Sobrienlook at the @code{DECL_NAME} of the @code{TYPE_DECL} to obtain the 37590075Sobrienactual name of the type. The @code{TYPE_NAME} will be @code{NULL_TREE} 37690075Sobrienfor a type that is not a built-in type, the result of a typedef, or a 37790075Sobriennamed class type. 37890075Sobrien 37990075Sobrien@item CP_INTEGRAL_TYPE 38090075SobrienThis predicate holds if the type is an integral type. Notice that in 38190075SobrienC++, enumerations are @emph{not} integral types. 38290075Sobrien 38390075Sobrien@item ARITHMETIC_TYPE_P 38490075SobrienThis predicate holds if the type is an integral type (in the C++ sense) 38590075Sobrienor a floating point type. 38690075Sobrien 38790075Sobrien@item CLASS_TYPE_P 38890075SobrienThis predicate holds for a class-type. 38990075Sobrien 39090075Sobrien@item TYPE_BUILT_IN 39190075SobrienThis predicate holds for a built-in type. 39290075Sobrien 39390075Sobrien@item TYPE_PTRMEM_P 39490075SobrienThis predicate holds if the type is a pointer to data member. 39590075Sobrien 39690075Sobrien@item TYPE_PTR_P 39790075SobrienThis predicate holds if the type is a pointer type, and the pointee is 39890075Sobriennot a data member. 39990075Sobrien 40090075Sobrien@item TYPE_PTRFN_P 40190075SobrienThis predicate holds for a pointer to function type. 40290075Sobrien 40390075Sobrien@item TYPE_PTROB_P 40490075SobrienThis predicate holds for a pointer to object type. Note however that it 40590075Sobriendoes not hold for the generic pointer to object type @code{void *}. You 40690075Sobrienmay use @code{TYPE_PTROBV_P} to test for a pointer to object type as 40790075Sobrienwell as @code{void *}. 40890075Sobrien 40990075Sobrien@item same_type_p 41090075SobrienThis predicate takes two types as input, and holds if they are the same 41190075Sobrientype. For example, if one type is a @code{typedef} for the other, or 41290075Sobrienboth are @code{typedef}s for the same type. This predicate also holds if 41390075Sobrienthe two trees given as input are simply copies of one another; i.e., 41490075Sobrienthere is no difference between them at the source level, but, for 41590075Sobrienwhatever reason, a duplicate has been made in the representation. You 41690075Sobrienshould never use @code{==} (pointer equality) to compare types; always 41790075Sobrienuse @code{same_type_p} instead. 41890075Sobrien@end ftable 41990075Sobrien 42090075SobrienDetailed below are the various kinds of types, and the macros that can 42190075Sobrienbe used to access them. Although other kinds of types are used 42290075Sobrienelsewhere in G++, the types described here are the only ones that you 42390075Sobrienwill encounter while examining the intermediate representation. 42490075Sobrien 42590075Sobrien@table @code 42690075Sobrien@item VOID_TYPE 42790075SobrienUsed to represent the @code{void} type. 42890075Sobrien 42990075Sobrien@item INTEGER_TYPE 43090075SobrienUsed to represent the various integral types, including @code{char}, 43190075Sobrien@code{short}, @code{int}, @code{long}, and @code{long long}. This code 43290075Sobrienis not used for enumeration types, nor for the @code{bool} type. Note 43390075Sobrienthat GCC's @code{CHAR_TYPE} node is @emph{not} used to represent 43490075Sobrien@code{char}. The @code{TYPE_PRECISION} is the number of bits used in 43590075Sobrienthe representation, represented as an @code{unsigned int}. (Note that 43690075Sobrienin the general case this is not the same value as @code{TYPE_SIZE}; 43790075Sobriensuppose that there were a 24-bit integer type, but that alignment 43890075Sobrienrequirements for the ABI required 32-bit alignment. Then, 43990075Sobrien@code{TYPE_SIZE} would be an @code{INTEGER_CST} for 32, while 44090075Sobrien@code{TYPE_PRECISION} would be 24.) The integer type is unsigned if 44190075Sobrien@code{TREE_UNSIGNED} holds; otherwise, it is signed. 44290075Sobrien 44390075SobrienThe @code{TYPE_MIN_VALUE} is an @code{INTEGER_CST} for the smallest 44490075Sobrieninteger that may be represented by this type. Similarly, the 44590075Sobrien@code{TYPE_MAX_VALUE} is an @code{INTEGER_CST} for the largest integer 44690075Sobrienthat may be represented by this type. 44790075Sobrien 44890075Sobrien@item REAL_TYPE 44990075SobrienUsed to represent the @code{float}, @code{double}, and @code{long 45090075Sobriendouble} types. The number of bits in the floating-point representation 45190075Sobrienis given by @code{TYPE_PRECISION}, as in the @code{INTEGER_TYPE} case. 45290075Sobrien 45390075Sobrien@item COMPLEX_TYPE 45490075SobrienUsed to represent GCC built-in @code{__complex__} data types. The 45590075Sobrien@code{TREE_TYPE} is the type of the real and imaginary parts. 45690075Sobrien 45790075Sobrien@item ENUMERAL_TYPE 45890075SobrienUsed to represent an enumeration type. The @code{TYPE_PRECISION} gives 45990075Sobrien(as an @code{int}), the number of bits used to represent the type. If 46090075Sobrienthere are no negative enumeration constants, @code{TREE_UNSIGNED} will 46190075Sobrienhold. The minimum and maximum enumeration constants may be obtained 46290075Sobrienwith @code{TYPE_MIN_VALUE} and @code{TYPE_MAX_VALUE}, respectively; each 46390075Sobrienof these macros returns an @code{INTEGER_CST}. 46490075Sobrien 46590075SobrienThe actual enumeration constants themselves may be obtained by looking 46690075Sobrienat the @code{TYPE_VALUES}. This macro will return a @code{TREE_LIST}, 46790075Sobriencontaining the constants. The @code{TREE_PURPOSE} of each node will be 46890075Sobrienan @code{IDENTIFIER_NODE} giving the name of the constant; the 46990075Sobrien@code{TREE_VALUE} will be an @code{INTEGER_CST} giving the value 47090075Sobrienassigned to that constant. These constants will appear in the order in 47190075Sobrienwhich they were declared. The @code{TREE_TYPE} of each of these 47290075Sobrienconstants will be the type of enumeration type itself. 47390075Sobrien 47490075Sobrien@item BOOLEAN_TYPE 47590075SobrienUsed to represent the @code{bool} type. 47690075Sobrien 47790075Sobrien@item POINTER_TYPE 47890075SobrienUsed to represent pointer types, and pointer to data member types. The 47990075Sobrien@code{TREE_TYPE} gives the type to which this type points. If the type 48090075Sobrienis a pointer to data member type, then @code{TYPE_PTRMEM_P} will hold. 48190075SobrienFor a pointer to data member type of the form @samp{T X::*}, 48290075Sobrien@code{TYPE_PTRMEM_CLASS_TYPE} will be the type @code{X}, while 48390075Sobrien@code{TYPE_PTRMEM_POINTED_TO_TYPE} will be the type @code{T}. 48490075Sobrien 48590075Sobrien@item REFERENCE_TYPE 48690075SobrienUsed to represent reference types. The @code{TREE_TYPE} gives the type 48790075Sobriento which this type refers. 48890075Sobrien 48990075Sobrien@item FUNCTION_TYPE 49090075SobrienUsed to represent the type of non-member functions and of static member 49190075Sobrienfunctions. The @code{TREE_TYPE} gives the return type of the function. 49290075SobrienThe @code{TYPE_ARG_TYPES} are a @code{TREE_LIST} of the argument types. 49390075SobrienThe @code{TREE_VALUE} of each node in this list is the type of the 49490075Sobriencorresponding argument; the @code{TREE_PURPOSE} is an expression for the 49590075Sobriendefault argument value, if any. If the last node in the list is 49690075Sobrien@code{void_list_node} (a @code{TREE_LIST} node whose @code{TREE_VALUE} 49790075Sobrienis the @code{void_type_node}), then functions of this type do not take 49890075Sobrienvariable arguments. Otherwise, they do take a variable number of 49990075Sobrienarguments. 50090075Sobrien 50190075SobrienNote that in C (but not in C++) a function declared like @code{void f()} 50290075Sobrienis an unprototyped function taking a variable number of arguments; the 50390075Sobrien@code{TYPE_ARG_TYPES} of such a function will be @code{NULL}. 50490075Sobrien 50590075Sobrien@item METHOD_TYPE 50690075SobrienUsed to represent the type of a non-static member function. Like a 50790075Sobrien@code{FUNCTION_TYPE}, the return type is given by the @code{TREE_TYPE}. 50890075SobrienThe type of @code{*this}, i.e., the class of which functions of this 50990075Sobrientype are a member, is given by the @code{TYPE_METHOD_BASETYPE}. The 51090075Sobrien@code{TYPE_ARG_TYPES} is the parameter list, as for a 51190075Sobrien@code{FUNCTION_TYPE}, and includes the @code{this} argument. 51290075Sobrien 51390075Sobrien@item ARRAY_TYPE 51490075SobrienUsed to represent array types. The @code{TREE_TYPE} gives the type of 51590075Sobrienthe elements in the array. If the array-bound is present in the type, 51690075Sobrienthe @code{TYPE_DOMAIN} is an @code{INTEGER_TYPE} whose 51790075Sobrien@code{TYPE_MIN_VALUE} and @code{TYPE_MAX_VALUE} will be the lower and 51890075Sobrienupper bounds of the array, respectively. The @code{TYPE_MIN_VALUE} will 51990075Sobrienalways be an @code{INTEGER_CST} for zero, while the 52090075Sobrien@code{TYPE_MAX_VALUE} will be one less than the number of elements in 52190075Sobrienthe array, i.e., the highest value which may be used to index an element 52290075Sobrienin the array. 52390075Sobrien 52490075Sobrien@item RECORD_TYPE 52590075SobrienUsed to represent @code{struct} and @code{class} types, as well as 52690075Sobrienpointers to member functions and similar constructs in other languages. 52790075Sobrien@code{TYPE_FIELDS} contains the items contained in this type, each of 52890075Sobrienwhich can be a @code{FIELD_DECL}, @code{VAR_DECL}, @code{CONST_DECL}, or 52990075Sobrien@code{TYPE_DECL}. You may not make any assumptions about the ordering 53090075Sobrienof the fields in the type or whether one or more of them overlap. If 53190075Sobrien@code{TYPE_PTRMEMFUNC_P} holds, then this type is a pointer-to-member 53290075Sobrientype. In that case, the @code{TYPE_PTRMEMFUNC_FN_TYPE} is a 53390075Sobrien@code{POINTER_TYPE} pointing to a @code{METHOD_TYPE}. The 53490075Sobrien@code{METHOD_TYPE} is the type of a function pointed to by the 53590075Sobrienpointer-to-member function. If @code{TYPE_PTRMEMFUNC_P} does not hold, 53690075Sobrienthis type is a class type. For more information, see @pxref{Classes}. 53790075Sobrien 53890075Sobrien@item UNION_TYPE 53990075SobrienUsed to represent @code{union} types. Similar to @code{RECORD_TYPE} 54090075Sobrienexcept that all @code{FIELD_DECL} nodes in @code{TYPE_FIELD} start at 54190075Sobrienbit position zero. 54290075Sobrien 54390075Sobrien@item QUAL_UNION_TYPE 54490075SobrienUsed to represent part of a variant record in Ada. Similar to 54590075Sobrien@code{UNION_TYPE} except that each @code{FIELD_DECL} has a 54690075Sobrien@code{DECL_QUALIFIER} field, which contains a boolean expression that 54790075Sobrienindicates whether the field is present in the object. The type will only 54890075Sobrienhave one field, so each field's @code{DECL_QUALIFIER} is only evaluated 54990075Sobrienif none of the expressions in the previous fields in @code{TYPE_FIELDS} 55090075Sobrienare nonzero. Normally these expressions will reference a field in the 55190075Sobrienouter object using a @code{PLACEHOLDER_EXPR}. 55290075Sobrien 55390075Sobrien@item UNKNOWN_TYPE 55490075SobrienThis node is used to represent a type the knowledge of which is 55590075Sobrieninsufficient for a sound processing. 55690075Sobrien 55790075Sobrien@item OFFSET_TYPE 558132718SkanThis node is used to represent a pointer-to-data member. For a data 559132718Skanmember @code{X::m} the @code{TYPE_OFFSET_BASETYPE} is @code{X} and the 560132718Skan@code{TREE_TYPE} is the type of @code{m}. 56190075Sobrien 56290075Sobrien@item TYPENAME_TYPE 56390075SobrienUsed to represent a construct of the form @code{typename T::A}. The 56490075Sobrien@code{TYPE_CONTEXT} is @code{T}; the @code{TYPE_NAME} is an 56590075Sobrien@code{IDENTIFIER_NODE} for @code{A}. If the type is specified via a 56690075Sobrientemplate-id, then @code{TYPENAME_TYPE_FULLNAME} yields a 56790075Sobrien@code{TEMPLATE_ID_EXPR}. The @code{TREE_TYPE} is non-@code{NULL} if the 56890075Sobriennode is implicitly generated in support for the implicit typename 56990075Sobrienextension; in which case the @code{TREE_TYPE} is a type node for the 57090075Sobrienbase-class. 57190075Sobrien 57290075Sobrien@item TYPEOF_TYPE 57390075SobrienUsed to represent the @code{__typeof__} extension. The 57490075Sobrien@code{TYPE_FIELDS} is the expression the type of which is being 57590075Sobrienrepresented. 57690075Sobrien@end table 57790075Sobrien 57890075SobrienThere are variables whose values represent some of the basic types. 57990075SobrienThese include: 58090075Sobrien@table @code 58190075Sobrien@item void_type_node 58290075SobrienA node for @code{void}. 58390075Sobrien 58490075Sobrien@item integer_type_node 58590075SobrienA node for @code{int}. 58690075Sobrien 58790075Sobrien@item unsigned_type_node. 58890075SobrienA node for @code{unsigned int}. 58990075Sobrien 59090075Sobrien@item char_type_node. 59190075SobrienA node for @code{char}. 59290075Sobrien@end table 59390075Sobrien@noindent 59490075SobrienIt may sometimes be useful to compare one of these variables with a type 59590075Sobrienin hand, using @code{same_type_p}. 59690075Sobrien 59790075Sobrien@c --------------------------------------------------------------------- 59890075Sobrien@c Scopes 59990075Sobrien@c --------------------------------------------------------------------- 60090075Sobrien 60190075Sobrien@node Scopes 60290075Sobrien@section Scopes 60390075Sobrien@cindex namespace, class, scope 60490075Sobrien 60590075SobrienThe root of the entire intermediate representation is the variable 60690075Sobrien@code{global_namespace}. This is the namespace specified with @code{::} 60790075Sobrienin C++ source code. All other namespaces, types, variables, functions, 60890075Sobrienand so forth can be found starting with this namespace. 60990075Sobrien 61090075SobrienBesides namespaces, the other high-level scoping construct in C++ is the 61190075Sobrienclass. (Throughout this manual the term @dfn{class} is used to mean the 61290075Sobrientypes referred to in the ANSI/ISO C++ Standard as classes; these include 61390075Sobrientypes defined with the @code{class}, @code{struct}, and @code{union} 61490075Sobrienkeywords.) 61590075Sobrien 61690075Sobrien@menu 61790075Sobrien* Namespaces:: Member functions, types, etc. 61890075Sobrien* Classes:: Members, bases, friends, etc. 61990075Sobrien@end menu 62090075Sobrien 62190075Sobrien@c --------------------------------------------------------------------- 62290075Sobrien@c Namespaces 62390075Sobrien@c --------------------------------------------------------------------- 62490075Sobrien 62590075Sobrien@node Namespaces 62690075Sobrien@subsection Namespaces 62790075Sobrien@cindex namespace 62890075Sobrien@tindex NAMESPACE_DECL 62990075Sobrien 63090075SobrienA namespace is represented by a @code{NAMESPACE_DECL} node. 63190075Sobrien 63290075SobrienHowever, except for the fact that it is distinguished as the root of the 63390075Sobrienrepresentation, the global namespace is no different from any other 63490075Sobriennamespace. Thus, in what follows, we describe namespaces generally, 63590075Sobrienrather than the global namespace in particular. 63690075Sobrien 63790075SobrienThe following macros and functions can be used on a @code{NAMESPACE_DECL}: 63890075Sobrien 63990075Sobrien@ftable @code 64090075Sobrien@item DECL_NAME 64190075SobrienThis macro is used to obtain the @code{IDENTIFIER_NODE} corresponding to 64290075Sobrienthe unqualified name of the name of the namespace (@pxref{Identifiers}). 64390075SobrienThe name of the global namespace is @samp{::}, even though in C++ the 64490075Sobrienglobal namespace is unnamed. However, you should use comparison with 64590075Sobrien@code{global_namespace}, rather than @code{DECL_NAME} to determine 646119256Skanwhether or not a namespace is the global one. An unnamed namespace 64790075Sobrienwill have a @code{DECL_NAME} equal to @code{anonymous_namespace_name}. 64890075SobrienWithin a single translation unit, all unnamed namespaces will have the 64990075Sobriensame name. 65090075Sobrien 65190075Sobrien@item DECL_CONTEXT 65290075SobrienThis macro returns the enclosing namespace. The @code{DECL_CONTEXT} for 65390075Sobrienthe @code{global_namespace} is @code{NULL_TREE}. 65490075Sobrien 65590075Sobrien@item DECL_NAMESPACE_ALIAS 65690075SobrienIf this declaration is for a namespace alias, then 65790075Sobrien@code{DECL_NAMESPACE_ALIAS} is the namespace for which this one is an 65890075Sobrienalias. 65990075Sobrien 66090075SobrienDo not attempt to use @code{cp_namespace_decls} for a namespace which is 66190075Sobrienan alias. Instead, follow @code{DECL_NAMESPACE_ALIAS} links until you 66290075Sobrienreach an ordinary, non-alias, namespace, and call 66390075Sobrien@code{cp_namespace_decls} there. 66490075Sobrien 66590075Sobrien@item DECL_NAMESPACE_STD_P 66690075SobrienThis predicate holds if the namespace is the special @code{::std} 66790075Sobriennamespace. 66890075Sobrien 66990075Sobrien@item cp_namespace_decls 67090075SobrienThis function will return the declarations contained in the namespace, 67190075Sobrienincluding types, overloaded functions, other namespaces, and so forth. 67290075SobrienIf there are no declarations, this function will return 67390075Sobrien@code{NULL_TREE}. The declarations are connected through their 67490075Sobrien@code{TREE_CHAIN} fields. 67590075Sobrien 67690075SobrienAlthough most entries on this list will be declarations, 67790075Sobrien@code{TREE_LIST} nodes may also appear. In this case, the 67890075Sobrien@code{TREE_VALUE} will be an @code{OVERLOAD}. The value of the 67990075Sobrien@code{TREE_PURPOSE} is unspecified; back ends should ignore this value. 68090075SobrienAs with the other kinds of declarations returned by 68190075Sobrien@code{cp_namespace_decls}, the @code{TREE_CHAIN} will point to the next 68290075Sobriendeclaration in this list. 68390075Sobrien 68490075SobrienFor more information on the kinds of declarations that can occur on this 68590075Sobrienlist, @xref{Declarations}. Some declarations will not appear on this 68690075Sobrienlist. In particular, no @code{FIELD_DECL}, @code{LABEL_DECL}, or 68790075Sobrien@code{PARM_DECL} nodes will appear here. 68890075Sobrien 68990075SobrienThis function cannot be used with namespaces that have 69090075Sobrien@code{DECL_NAMESPACE_ALIAS} set. 69190075Sobrien 69290075Sobrien@end ftable 69390075Sobrien 69490075Sobrien@c --------------------------------------------------------------------- 69590075Sobrien@c Classes 69690075Sobrien@c --------------------------------------------------------------------- 69790075Sobrien 69890075Sobrien@node Classes 69990075Sobrien@subsection Classes 70090075Sobrien@cindex class 70190075Sobrien@tindex RECORD_TYPE 70290075Sobrien@tindex UNION_TYPE 70390075Sobrien@findex CLASSTYPE_DECLARED_CLASS 70490075Sobrien@findex TYPE_BINFO 70590075Sobrien@findex BINFO_TYPE 70690075Sobrien@findex TREE_VIA_PUBLIC 70790075Sobrien@findex TREE_VIA_PROTECTED 70890075Sobrien@findex TREE_VIA_PRIVATE 70990075Sobrien@findex TYPE_FIELDS 71090075Sobrien@findex TYPE_VFIELD 71190075Sobrien@findex TYPE_METHODS 71290075Sobrien 71390075SobrienA class type is represented by either a @code{RECORD_TYPE} or a 71490075Sobrien@code{UNION_TYPE}. A class declared with the @code{union} tag is 71590075Sobrienrepresented by a @code{UNION_TYPE}, while classes declared with either 71690075Sobrienthe @code{struct} or the @code{class} tag are represented by 71790075Sobrien@code{RECORD_TYPE}s. You can use the @code{CLASSTYPE_DECLARED_CLASS} 71890075Sobrienmacro to discern whether or not a particular type is a @code{class} as 71990075Sobrienopposed to a @code{struct}. This macro will be true only for classes 72090075Sobriendeclared with the @code{class} tag. 72190075Sobrien 72290075SobrienAlmost all non-function members are available on the @code{TYPE_FIELDS} 72390075Sobrienlist. Given one member, the next can be found by following the 72490075Sobrien@code{TREE_CHAIN}. You should not depend in any way on the order in 72590075Sobrienwhich fields appear on this list. All nodes on this list will be 72690075Sobrien@samp{DECL} nodes. A @code{FIELD_DECL} is used to represent a non-static 72790075Sobriendata member, a @code{VAR_DECL} is used to represent a static data 72890075Sobrienmember, and a @code{TYPE_DECL} is used to represent a type. Note that 72990075Sobrienthe @code{CONST_DECL} for an enumeration constant will appear on this 73090075Sobrienlist, if the enumeration type was declared in the class. (Of course, 73190075Sobrienthe @code{TYPE_DECL} for the enumeration type will appear here as well.) 73290075SobrienThere are no entries for base classes on this list. In particular, 73390075Sobrienthere is no @code{FIELD_DECL} for the ``base-class portion'' of an 73490075Sobrienobject. 73590075Sobrien 73690075SobrienThe @code{TYPE_VFIELD} is a compiler-generated field used to point to 73790075Sobrienvirtual function tables. It may or may not appear on the 73890075Sobrien@code{TYPE_FIELDS} list. However, back ends should handle the 73990075Sobrien@code{TYPE_VFIELD} just like all the entries on the @code{TYPE_FIELDS} 74090075Sobrienlist. 74190075Sobrien 74290075SobrienThe function members are available on the @code{TYPE_METHODS} list. 74390075SobrienAgain, subsequent members are found by following the @code{TREE_CHAIN} 74490075Sobrienfield. If a function is overloaded, each of the overloaded functions 74590075Sobrienappears; no @code{OVERLOAD} nodes appear on the @code{TYPE_METHODS} 74690075Sobrienlist. Implicitly declared functions (including default constructors, 74790075Sobriencopy constructors, assignment operators, and destructors) will appear on 74890075Sobrienthis list as well. 74990075Sobrien 75090075SobrienEvery class has an associated @dfn{binfo}, which can be obtained with 75190075Sobrien@code{TYPE_BINFO}. Binfos are used to represent base-classes. The 75290075Sobrienbinfo given by @code{TYPE_BINFO} is the degenerate case, whereby every 75390075Sobrienclass is considered to be its own base-class. The base classes for a 75490075Sobrienparticular binfo can be obtained with @code{BINFO_BASETYPES}. These 75590075Sobrienbase-classes are themselves binfos. The class type associated with a 75690075Sobrienbinfo is given by @code{BINFO_TYPE}. It is always the case that 75790075Sobrien@code{BINFO_TYPE (TYPE_BINFO (x))} is the same type as @code{x}, up to 75890075Sobrienqualifiers. However, it is not always the case that @code{TYPE_BINFO 75990075Sobrien(BINFO_TYPE (y))} is always the same binfo as @code{y}. The reason is 76090075Sobrienthat if @code{y} is a binfo representing a base-class @code{B} of a 76196263Sobrienderived class @code{D}, then @code{BINFO_TYPE (y)} will be @code{B}, 76296263Sobrienand @code{TYPE_BINFO (BINFO_TYPE (y))} will be @code{B} as its own 76390075Sobrienbase-class, rather than as a base-class of @code{D}. 76490075Sobrien 76590075SobrienThe @code{BINFO_BASETYPES} is a @code{TREE_VEC} (@pxref{Containers}). 76690075SobrienBase types appear in left-to-right order in this vector. You can tell 76790075Sobrienwhether or @code{public}, @code{protected}, or @code{private} 76890075Sobrieninheritance was used by using the @code{TREE_VIA_PUBLIC}, 76990075Sobrien@code{TREE_VIA_PROTECTED}, and @code{TREE_VIA_PRIVATE} macros. Each of 77090075Sobrienthese macros takes a @code{BINFO} and is true if and only if the 77190075Sobrienindicated kind of inheritance was used. If @code{TREE_VIA_VIRTUAL} 77290075Sobrienholds of a binfo, then its @code{BINFO_TYPE} was inherited from 77390075Sobrienvirtually. 77490075Sobrien 77590075SobrienThe following macros can be used on a tree node representing a class-type. 77690075Sobrien 77790075Sobrien@ftable @code 77890075Sobrien@item LOCAL_CLASS_P 77990075SobrienThis predicate holds if the class is local class @emph{i.e.} declared 78090075Sobrieninside a function body. 78190075Sobrien 78290075Sobrien@item TYPE_POLYMORPHIC_P 78390075SobrienThis predicate holds if the class has at least one virtual function 78490075Sobrien(declared or inherited). 78590075Sobrien 78690075Sobrien@item TYPE_HAS_DEFAULT_CONSTRUCTOR 78790075SobrienThis predicate holds whenever its argument represents a class-type with 78890075Sobriendefault constructor. 78990075Sobrien 79090075Sobrien@item CLASSTYPE_HAS_MUTABLE 791132718Skan@itemx TYPE_HAS_MUTABLE_P 79290075SobrienThese predicates hold for a class-type having a mutable data member. 79390075Sobrien 79490075Sobrien@item CLASSTYPE_NON_POD_P 79590075SobrienThis predicate holds only for class-types that are not PODs. 79690075Sobrien 79790075Sobrien@item TYPE_HAS_NEW_OPERATOR 79890075SobrienThis predicate holds for a class-type that defines 79990075Sobrien@code{operator new}. 80090075Sobrien 80190075Sobrien@item TYPE_HAS_ARRAY_NEW_OPERATOR 80290075SobrienThis predicate holds for a class-type for which 80390075Sobrien@code{operator new[]} is defined. 80490075Sobrien 80590075Sobrien@item TYPE_OVERLOADS_CALL_EXPR 80690075SobrienThis predicate holds for class-type for which the function call 80790075Sobrien@code{operator()} is overloaded. 80890075Sobrien 80990075Sobrien@item TYPE_OVERLOADS_ARRAY_REF 81090075SobrienThis predicate holds for a class-type that overloads 81190075Sobrien@code{operator[]} 81290075Sobrien 81390075Sobrien@item TYPE_OVERLOADS_ARROW 81490075SobrienThis predicate holds for a class-type for which @code{operator->} is 81590075Sobrienoverloaded. 81690075Sobrien 81790075Sobrien@end ftable 81890075Sobrien 81990075Sobrien@c --------------------------------------------------------------------- 82090075Sobrien@c Declarations 82190075Sobrien@c --------------------------------------------------------------------- 82290075Sobrien 82390075Sobrien@node Declarations 82490075Sobrien@section Declarations 82590075Sobrien@cindex declaration 82690075Sobrien@cindex variable 82790075Sobrien@cindex type declaration 82890075Sobrien@tindex LABEL_DECL 82990075Sobrien@tindex CONST_DECL 83090075Sobrien@tindex TYPE_DECL 83190075Sobrien@tindex VAR_DECL 83290075Sobrien@tindex PARM_DECL 83390075Sobrien@tindex FIELD_DECL 83490075Sobrien@tindex NAMESPACE_DECL 83590075Sobrien@tindex RESULT_DECL 83690075Sobrien@tindex TEMPLATE_DECL 83790075Sobrien@tindex THUNK_DECL 83890075Sobrien@tindex USING_DECL 83990075Sobrien@findex THUNK_DELTA 84090075Sobrien@findex DECL_INITIAL 84190075Sobrien@findex DECL_SIZE 84290075Sobrien@findex DECL_ALIGN 84390075Sobrien@findex DECL_EXTERNAL 84490075Sobrien 84590075SobrienThis section covers the various kinds of declarations that appear in the 84690075Sobrieninternal representation, except for declarations of functions 84790075Sobrien(represented by @code{FUNCTION_DECL} nodes), which are described in 84890075Sobrien@ref{Functions}. 84990075Sobrien 85090075SobrienSome macros can be used with any kind of declaration. These include: 85190075Sobrien@ftable @code 85290075Sobrien@item DECL_NAME 85390075SobrienThis macro returns an @code{IDENTIFIER_NODE} giving the name of the 85490075Sobrienentity. 85590075Sobrien 85690075Sobrien@item TREE_TYPE 85790075SobrienThis macro returns the type of the entity declared. 85890075Sobrien 85990075Sobrien@item DECL_SOURCE_FILE 86090075SobrienThis macro returns the name of the file in which the entity was 86190075Sobriendeclared, as a @code{char*}. For an entity declared implicitly by the 86290075Sobriencompiler (like @code{__builtin_memcpy}), this will be the string 86390075Sobrien@code{"<internal>"}. 86490075Sobrien 86590075Sobrien@item DECL_SOURCE_LINE 86690075SobrienThis macro returns the line number at which the entity was declared, as 86790075Sobrienan @code{int}. 86890075Sobrien 86990075Sobrien@item DECL_ARTIFICIAL 87090075SobrienThis predicate holds if the declaration was implicitly generated by the 87190075Sobriencompiler. For example, this predicate will hold of an implicitly 87290075Sobriendeclared member function, or of the @code{TYPE_DECL} implicitly 87390075Sobriengenerated for a class type. Recall that in C++ code like: 874132718Skan@smallexample 87590075Sobrienstruct S @{@}; 876132718Skan@end smallexample 87790075Sobrien@noindent 87890075Sobrienis roughly equivalent to C code like: 879132718Skan@smallexample 88090075Sobrienstruct S @{@}; 88190075Sobrientypedef struct S S; 882132718Skan@end smallexample 88390075SobrienThe implicitly generated @code{typedef} declaration is represented by a 88490075Sobrien@code{TYPE_DECL} for which @code{DECL_ARTIFICIAL} holds. 88590075Sobrien 88690075Sobrien@item DECL_NAMESPACE_SCOPE_P 88790075SobrienThis predicate holds if the entity was declared at a namespace scope. 88890075Sobrien 88990075Sobrien@item DECL_CLASS_SCOPE_P 89090075SobrienThis predicate holds if the entity was declared at a class scope. 89190075Sobrien 89290075Sobrien@item DECL_FUNCTION_SCOPE_P 89390075SobrienThis predicate holds if the entity was declared inside a function 89490075Sobrienbody. 89590075Sobrien 89690075Sobrien@end ftable 89790075Sobrien 89890075SobrienThe various kinds of declarations include: 89990075Sobrien@table @code 90090075Sobrien@item LABEL_DECL 90190075SobrienThese nodes are used to represent labels in function bodies. For more 90290075Sobrieninformation, see @ref{Functions}. These nodes only appear in block 90390075Sobrienscopes. 90490075Sobrien 90590075Sobrien@item CONST_DECL 90690075SobrienThese nodes are used to represent enumeration constants. The value of 90790075Sobrienthe constant is given by @code{DECL_INITIAL} which will be an 90890075Sobrien@code{INTEGER_CST} with the same type as the @code{TREE_TYPE} of the 90990075Sobrien@code{CONST_DECL}, i.e., an @code{ENUMERAL_TYPE}. 91090075Sobrien 91190075Sobrien@item RESULT_DECL 91290075SobrienThese nodes represent the value returned by a function. When a value is 91390075Sobrienassigned to a @code{RESULT_DECL}, that indicates that the value should 91490075Sobrienbe returned, via bitwise copy, by the function. You can use 91590075Sobrien@code{DECL_SIZE} and @code{DECL_ALIGN} on a @code{RESULT_DECL}, just as 91690075Sobrienwith a @code{VAR_DECL}. 91790075Sobrien 91890075Sobrien@item TYPE_DECL 91990075SobrienThese nodes represent @code{typedef} declarations. The @code{TREE_TYPE} 92090075Sobrienis the type declared to have the name given by @code{DECL_NAME}. In 92190075Sobriensome cases, there is no associated name. 92290075Sobrien 92390075Sobrien@item VAR_DECL 92490075SobrienThese nodes represent variables with namespace or block scope, as well 92590075Sobrienas static data members. The @code{DECL_SIZE} and @code{DECL_ALIGN} are 92690075Sobrienanalogous to @code{TYPE_SIZE} and @code{TYPE_ALIGN}. For a declaration, 92790075Sobrienyou should always use the @code{DECL_SIZE} and @code{DECL_ALIGN} rather 92890075Sobrienthan the @code{TYPE_SIZE} and @code{TYPE_ALIGN} given by the 92990075Sobrien@code{TREE_TYPE}, since special attributes may have been applied to the 93090075Sobrienvariable to give it a particular size and alignment. You may use the 93190075Sobrienpredicates @code{DECL_THIS_STATIC} or @code{DECL_THIS_EXTERN} to test 93290075Sobrienwhether the storage class specifiers @code{static} or @code{extern} were 93390075Sobrienused to declare a variable. 93490075Sobrien 93590075SobrienIf this variable is initialized (but does not require a constructor), 93690075Sobrienthe @code{DECL_INITIAL} will be an expression for the initializer. The 93790075Sobrieninitializer should be evaluated, and a bitwise copy into the variable 93890075Sobrienperformed. If the @code{DECL_INITIAL} is the @code{error_mark_node}, 93990075Sobrienthere is an initializer, but it is given by an explicit statement later 94090075Sobrienin the code; no bitwise copy is required. 94190075Sobrien 94290075SobrienGCC provides an extension that allows either automatic variables, or 94390075Sobrienglobal variables, to be placed in particular registers. This extension 94490075Sobrienis being used for a particular @code{VAR_DECL} if @code{DECL_REGISTER} 94590075Sobrienholds for the @code{VAR_DECL}, and if @code{DECL_ASSEMBLER_NAME} is not 94690075Sobrienequal to @code{DECL_NAME}. In that case, @code{DECL_ASSEMBLER_NAME} is 94790075Sobrienthe name of the register into which the variable will be placed. 94890075Sobrien 94990075Sobrien@item PARM_DECL 95090075SobrienUsed to represent a parameter to a function. Treat these nodes 95190075Sobriensimilarly to @code{VAR_DECL} nodes. These nodes only appear in the 95290075Sobrien@code{DECL_ARGUMENTS} for a @code{FUNCTION_DECL}. 95390075Sobrien 95490075SobrienThe @code{DECL_ARG_TYPE} for a @code{PARM_DECL} is the type that will 95590075Sobrienactually be used when a value is passed to this function. It may be a 95690075Sobrienwider type than the @code{TREE_TYPE} of the parameter; for example, the 95790075Sobrienordinary type might be @code{short} while the @code{DECL_ARG_TYPE} is 95890075Sobrien@code{int}. 95990075Sobrien 96090075Sobrien@item FIELD_DECL 96190075SobrienThese nodes represent non-static data members. The @code{DECL_SIZE} and 96290075Sobrien@code{DECL_ALIGN} behave as for @code{VAR_DECL} nodes. The 96390075Sobrien@code{DECL_FIELD_BITPOS} gives the first bit used for this field, as an 96490075Sobrien@code{INTEGER_CST}. These values are indexed from zero, where zero 96590075Sobrienindicates the first bit in the object. 96690075Sobrien 96790075SobrienIf @code{DECL_C_BIT_FIELD} holds, this field is a bit-field. 96890075Sobrien 96990075Sobrien@item NAMESPACE_DECL 97090075Sobrien@xref{Namespaces}. 97190075Sobrien 97290075Sobrien@item TEMPLATE_DECL 97390075Sobrien 97490075SobrienThese nodes are used to represent class, function, and variable (static 97590075Sobriendata member) templates. The @code{DECL_TEMPLATE_SPECIALIZATIONS} are a 97690075Sobrien@code{TREE_LIST}. The @code{TREE_VALUE} of each node in the list is a 97790075Sobrien@code{TEMPLATE_DECL}s or @code{FUNCTION_DECL}s representing 97890075Sobrienspecializations (including instantiations) of this template. Back ends 97990075Sobriencan safely ignore @code{TEMPLATE_DECL}s, but should examine 98090075Sobrien@code{FUNCTION_DECL} nodes on the specializations list just as they 98190075Sobrienwould ordinary @code{FUNCTION_DECL} nodes. 98290075Sobrien 98390075SobrienFor a class template, the @code{DECL_TEMPLATE_INSTANTIATIONS} list 98490075Sobriencontains the instantiations. The @code{TREE_VALUE} of each node is an 98590075Sobrieninstantiation of the class. The @code{DECL_TEMPLATE_SPECIALIZATIONS} 98690075Sobriencontains partial specializations of the class. 98790075Sobrien 98890075Sobrien@item USING_DECL 98990075Sobrien 99090075SobrienBack ends can safely ignore these nodes. 99190075Sobrien 99290075Sobrien@end table 99390075Sobrien 99490075Sobrien@c --------------------------------------------------------------------- 99590075Sobrien@c Functions 99690075Sobrien@c --------------------------------------------------------------------- 99790075Sobrien 99890075Sobrien@node Functions 99990075Sobrien@section Functions 100090075Sobrien@cindex function 100190075Sobrien@tindex FUNCTION_DECL 100290075Sobrien@tindex OVERLOAD 100390075Sobrien@findex OVL_CURRENT 100490075Sobrien@findex OVL_NEXT 100590075Sobrien 100690075SobrienA function is represented by a @code{FUNCTION_DECL} node. A set of 100790075Sobrienoverloaded functions is sometimes represented by a @code{OVERLOAD} node. 100890075Sobrien 100990075SobrienAn @code{OVERLOAD} node is not a declaration, so none of the 101090075Sobrien@samp{DECL_} macros should be used on an @code{OVERLOAD}. An 101190075Sobrien@code{OVERLOAD} node is similar to a @code{TREE_LIST}. Use 101290075Sobrien@code{OVL_CURRENT} to get the function associated with an 101390075Sobrien@code{OVERLOAD} node; use @code{OVL_NEXT} to get the next 101490075Sobrien@code{OVERLOAD} node in the list of overloaded functions. The macros 101590075Sobrien@code{OVL_CURRENT} and @code{OVL_NEXT} are actually polymorphic; you can 101690075Sobrienuse them to work with @code{FUNCTION_DECL} nodes as well as with 101790075Sobrienoverloads. In the case of a @code{FUNCTION_DECL}, @code{OVL_CURRENT} 101890075Sobrienwill always return the function itself, and @code{OVL_NEXT} will always 101990075Sobrienbe @code{NULL_TREE}. 102090075Sobrien 102190075SobrienTo determine the scope of a function, you can use the 1022132718Skan@code{DECL_CONTEXT} macro. This macro will return the class 102390075Sobrien(either a @code{RECORD_TYPE} or a @code{UNION_TYPE}) or namespace (a 102490075Sobrien@code{NAMESPACE_DECL}) of which the function is a member. For a virtual 102590075Sobrienfunction, this macro returns the class in which the function was 102690075Sobrienactually defined, not the base class in which the virtual declaration 1027132718Skanoccurred. 1028132718Skan 1029132718SkanIf a friend function is defined in a class scope, the 1030132718Skan@code{DECL_FRIEND_CONTEXT} macro can be used to determine the class in 103190075Sobrienwhich it was defined. For example, in 1032132718Skan@smallexample 103390075Sobrienclass C @{ friend void f() @{@} @}; 1034132718Skan@end smallexample 1035132718Skan@noindent 1036132718Skanthe @code{DECL_CONTEXT} for @code{f} will be the 1037132718Skan@code{global_namespace}, but the @code{DECL_FRIEND_CONTEXT} will be the 103890075Sobrien@code{RECORD_TYPE} for @code{C}. 103990075Sobrien 1040132718SkanIn C, the @code{DECL_CONTEXT} for a function maybe another function. 1041132718SkanThis representation indicates that the GNU nested function extension 1042132718Skanis in use. For details on the semantics of nested functions, see the 1043132718SkanGCC Manual. The nested function can refer to local variables in its 104490075Sobriencontaining function. Such references are not explicitly marked in the 104590075Sobrientree structure; back ends must look at the @code{DECL_CONTEXT} for the 104690075Sobrienreferenced @code{VAR_DECL}. If the @code{DECL_CONTEXT} for the 104790075Sobrienreferenced @code{VAR_DECL} is not the same as the function currently 1048132718Skanbeing processed, and neither @code{DECL_EXTERNAL} nor 1049132718Skan@code{DECL_STATIC} hold, then the reference is to a local variable in 1050132718Skana containing function, and the back end must take appropriate action. 105190075Sobrien 105290075Sobrien@menu 105390075Sobrien* Function Basics:: Function names, linkage, and so forth. 105490075Sobrien* Function Bodies:: The statements that make up a function body. 105590075Sobrien@end menu 105690075Sobrien 105790075Sobrien@c --------------------------------------------------------------------- 105890075Sobrien@c Function Basics 105990075Sobrien@c --------------------------------------------------------------------- 106090075Sobrien 106190075Sobrien@node Function Basics 106290075Sobrien@subsection Function Basics 106390075Sobrien@cindex constructor 106490075Sobrien@cindex destructor 106590075Sobrien@cindex copy constructor 106690075Sobrien@cindex assignment operator 106790075Sobrien@cindex linkage 106890075Sobrien@findex DECL_NAME 106990075Sobrien@findex DECL_ASSEMBLER_NAME 107090075Sobrien@findex TREE_PUBLIC 107190075Sobrien@findex DECL_LINKONCE_P 107290075Sobrien@findex DECL_FUNCTION_MEMBER_P 107390075Sobrien@findex DECL_CONSTRUCTOR_P 107490075Sobrien@findex DECL_DESTRUCTOR_P 107590075Sobrien@findex DECL_OVERLOADED_OPERATOR_P 107690075Sobrien@findex DECL_CONV_FN_P 107790075Sobrien@findex DECL_ARTIFICIAL 107890075Sobrien@findex DECL_GLOBAL_CTOR_P 107990075Sobrien@findex DECL_GLOBAL_DTOR_P 108090075Sobrien@findex GLOBAL_INIT_PRIORITY 108190075Sobrien 108290075SobrienThe following macros and functions can be used on a @code{FUNCTION_DECL}: 108390075Sobrien@ftable @code 108490075Sobrien@item DECL_MAIN_P 108590075SobrienThis predicate holds for a function that is the program entry point 108690075Sobrien@code{::code}. 108790075Sobrien 108890075Sobrien@item DECL_NAME 108990075SobrienThis macro returns the unqualified name of the function, as an 109090075Sobrien@code{IDENTIFIER_NODE}. For an instantiation of a function template, 109190075Sobrienthe @code{DECL_NAME} is the unqualified name of the template, not 109290075Sobriensomething like @code{f<int>}. The value of @code{DECL_NAME} is 109390075Sobrienundefined when used on a constructor, destructor, overloaded operator, 109490075Sobrienor type-conversion operator, or any function that is implicitly 109590075Sobriengenerated by the compiler. See below for macros that can be used to 109690075Sobriendistinguish these cases. 109790075Sobrien 109890075Sobrien@item DECL_ASSEMBLER_NAME 109990075SobrienThis macro returns the mangled name of the function, also an 110090075Sobrien@code{IDENTIFIER_NODE}. This name does not contain leading underscores 110190075Sobrienon systems that prefix all identifiers with underscores. The mangled 110290075Sobrienname is computed in the same way on all platforms; if special processing 110390075Sobrienis required to deal with the object file format used on a particular 110490075Sobrienplatform, it is the responsibility of the back end to perform those 110590075Sobrienmodifications. (Of course, the back end should not modify 110690075Sobrien@code{DECL_ASSEMBLER_NAME} itself.) 110790075Sobrien 110890075Sobrien@item DECL_EXTERNAL 110990075SobrienThis predicate holds if the function is undefined. 111090075Sobrien 111190075Sobrien@item TREE_PUBLIC 111290075SobrienThis predicate holds if the function has external linkage. 111390075Sobrien 111490075Sobrien@item DECL_LOCAL_FUNCTION_P 111590075SobrienThis predicate holds if the function was declared at block scope, even 111690075Sobrienthough it has a global scope. 111790075Sobrien 111890075Sobrien@item DECL_ANTICIPATED 111990075SobrienThis predicate holds if the function is a built-in function but its 112090075Sobrienprototype is not yet explicitly declared. 112190075Sobrien 112290075Sobrien@item DECL_EXTERN_C_FUNCTION_P 112390075SobrienThis predicate holds if the function is declared as an 112490075Sobrien`@code{extern "C"}' function. 112590075Sobrien 112690075Sobrien@item DECL_LINKONCE_P 112790075SobrienThis macro holds if multiple copies of this function may be emitted in 112890075Sobrienvarious translation units. It is the responsibility of the linker to 112990075Sobrienmerge the various copies. Template instantiations are the most common 113090075Sobrienexample of functions for which @code{DECL_LINKONCE_P} holds; G++ 113190075Sobrieninstantiates needed templates in all translation units which require them, 113290075Sobrienand then relies on the linker to remove duplicate instantiations. 113390075Sobrien 113490075SobrienFIXME: This macro is not yet implemented. 113590075Sobrien 113690075Sobrien@item DECL_FUNCTION_MEMBER_P 113790075SobrienThis macro holds if the function is a member of a class, rather than a 113890075Sobrienmember of a namespace. 113990075Sobrien 114090075Sobrien@item DECL_STATIC_FUNCTION_P 114190075SobrienThis predicate holds if the function a static member function. 114290075Sobrien 114390075Sobrien@item DECL_NONSTATIC_MEMBER_FUNCTION_P 114490075SobrienThis macro holds for a non-static member function. 114590075Sobrien 114690075Sobrien@item DECL_CONST_MEMFUNC_P 114790075SobrienThis predicate holds for a @code{const}-member function. 114890075Sobrien 114990075Sobrien@item DECL_VOLATILE_MEMFUNC_P 115090075SobrienThis predicate holds for a @code{volatile}-member function. 115190075Sobrien 115290075Sobrien@item DECL_CONSTRUCTOR_P 115390075SobrienThis macro holds if the function is a constructor. 115490075Sobrien 115590075Sobrien@item DECL_NONCONVERTING_P 115690075SobrienThis predicate holds if the constructor is a non-converting constructor. 115790075Sobrien 115890075Sobrien@item DECL_COMPLETE_CONSTRUCTOR_P 115990075SobrienThis predicate holds for a function which is a constructor for an object 116090075Sobrienof a complete type. 116190075Sobrien 116290075Sobrien@item DECL_BASE_CONSTRUCTOR_P 116390075SobrienThis predicate holds for a function which is a constructor for a base 116490075Sobrienclass sub-object. 116590075Sobrien 116690075Sobrien@item DECL_COPY_CONSTRUCTOR_P 116790075SobrienThis predicate holds for a function which is a copy-constructor. 116890075Sobrien 116990075Sobrien@item DECL_DESTRUCTOR_P 117090075SobrienThis macro holds if the function is a destructor. 117190075Sobrien 117290075Sobrien@item DECL_COMPLETE_DESTRUCTOR_P 117390075SobrienThis predicate holds if the function is the destructor for an object a 117490075Sobriencomplete type. 117590075Sobrien 117690075Sobrien@item DECL_OVERLOADED_OPERATOR_P 117790075SobrienThis macro holds if the function is an overloaded operator. 117890075Sobrien 117990075Sobrien@item DECL_CONV_FN_P 118090075SobrienThis macro holds if the function is a type-conversion operator. 118190075Sobrien 118290075Sobrien@item DECL_GLOBAL_CTOR_P 118390075SobrienThis predicate holds if the function is a file-scope initialization 118490075Sobrienfunction. 118590075Sobrien 118690075Sobrien@item DECL_GLOBAL_DTOR_P 118790075SobrienThis predicate holds if the function is a file-scope finalization 118890075Sobrienfunction. 118990075Sobrien 119090075Sobrien@item DECL_THUNK_P 119190075SobrienThis predicate holds if the function is a thunk. 119290075Sobrien 119390075SobrienThese functions represent stub code that adjusts the @code{this} pointer 119490075Sobrienand then jumps to another function. When the jumped-to function 119590075Sobrienreturns, control is transferred directly to the caller, without 119690075Sobrienreturning to the thunk. The first parameter to the thunk is always the 119790075Sobrien@code{this} pointer; the thunk should add @code{THUNK_DELTA} to this 119890075Sobrienvalue. (The @code{THUNK_DELTA} is an @code{int}, not an 119990075Sobrien@code{INTEGER_CST}.) 120090075Sobrien 120190075SobrienThen, if @code{THUNK_VCALL_OFFSET} (an @code{INTEGER_CST}) is nonzero 120290075Sobrienthe adjusted @code{this} pointer must be adjusted again. The complete 120390075Sobriencalculation is given by the following pseudo-code: 120490075Sobrien 1205103445Skan@smallexample 120690075Sobrienthis += THUNK_DELTA 120790075Sobrienif (THUNK_VCALL_OFFSET) 120890075Sobrien this += (*((ptrdiff_t **) this))[THUNK_VCALL_OFFSET] 1209103445Skan@end smallexample 121090075Sobrien 121190075SobrienFinally, the thunk should jump to the location given 121290075Sobrienby @code{DECL_INITIAL}; this will always be an expression for the 121390075Sobrienaddress of a function. 121490075Sobrien 121590075Sobrien@item DECL_NON_THUNK_FUNCTION_P 121690075SobrienThis predicate holds if the function is @emph{not} a thunk function. 121790075Sobrien 121890075Sobrien@item GLOBAL_INIT_PRIORITY 121990075SobrienIf either @code{DECL_GLOBAL_CTOR_P} or @code{DECL_GLOBAL_DTOR_P} holds, 122090075Sobrienthen this gives the initialization priority for the function. The 122190075Sobrienlinker will arrange that all functions for which 122290075Sobrien@code{DECL_GLOBAL_CTOR_P} holds are run in increasing order of priority 122390075Sobrienbefore @code{main} is called. When the program exits, all functions for 122490075Sobrienwhich @code{DECL_GLOBAL_DTOR_P} holds are run in the reverse order. 122590075Sobrien 122690075Sobrien@item DECL_ARTIFICIAL 122790075SobrienThis macro holds if the function was implicitly generated by the 122890075Sobriencompiler, rather than explicitly declared. In addition to implicitly 122990075Sobriengenerated class member functions, this macro holds for the special 123090075Sobrienfunctions created to implement static initialization and destruction, to 123190075Sobriencompute run-time type information, and so forth. 123290075Sobrien 123390075Sobrien@item DECL_ARGUMENTS 123490075SobrienThis macro returns the @code{PARM_DECL} for the first argument to the 123590075Sobrienfunction. Subsequent @code{PARM_DECL} nodes can be obtained by 123690075Sobrienfollowing the @code{TREE_CHAIN} links. 123790075Sobrien 123890075Sobrien@item DECL_RESULT 123990075SobrienThis macro returns the @code{RESULT_DECL} for the function. 124090075Sobrien 124190075Sobrien@item TREE_TYPE 124290075SobrienThis macro returns the @code{FUNCTION_TYPE} or @code{METHOD_TYPE} for 124390075Sobrienthe function. 124490075Sobrien 124590075Sobrien@item TYPE_RAISES_EXCEPTIONS 124690075SobrienThis macro returns the list of exceptions that a (member-)function can 124790075Sobrienraise. The returned list, if non @code{NULL}, is comprised of nodes 124890075Sobrienwhose @code{TREE_VALUE} represents a type. 124990075Sobrien 125090075Sobrien@item TYPE_NOTHROW_P 125190075SobrienThis predicate holds when the exception-specification of its arguments 125290075Sobrienif of the form `@code{()}'. 125390075Sobrien 125490075Sobrien@item DECL_ARRAY_DELETE_OPERATOR_P 125590075SobrienThis predicate holds if the function an overloaded 125690075Sobrien@code{operator delete[]}. 125790075Sobrien 125890075Sobrien@end ftable 125990075Sobrien 126090075Sobrien@c --------------------------------------------------------------------- 126190075Sobrien@c Function Bodies 126290075Sobrien@c --------------------------------------------------------------------- 126390075Sobrien 126490075Sobrien@node Function Bodies 126590075Sobrien@subsection Function Bodies 126690075Sobrien@cindex function body 126790075Sobrien@cindex statements 126890075Sobrien@tindex ASM_STMT 126990075Sobrien@findex ASM_STRING 127090075Sobrien@findex ASM_CV_QUAL 127190075Sobrien@findex ASM_INPUTS 127290075Sobrien@findex ASM_OUTPUTS 127390075Sobrien@findex ASM_CLOBBERS 127490075Sobrien@tindex BREAK_STMT 127590075Sobrien@tindex CLEANUP_STMT 127690075Sobrien@findex CLEANUP_DECL 127790075Sobrien@findex CLEANUP_EXPR 127890075Sobrien@tindex COMPOUND_STMT 127990075Sobrien@findex COMPOUND_BODY 128090075Sobrien@tindex CONTINUE_STMT 128190075Sobrien@tindex DECL_STMT 128290075Sobrien@findex DECL_STMT_DECL 128390075Sobrien@tindex DO_STMT 128490075Sobrien@findex DO_BODY 128590075Sobrien@findex DO_COND 128690075Sobrien@tindex EMPTY_CLASS_EXPR 128790075Sobrien@tindex EXPR_STMT 128890075Sobrien@findex EXPR_STMT_EXPR 128990075Sobrien@tindex FOR_STMT 129090075Sobrien@findex FOR_INIT_STMT 129190075Sobrien@findex FOR_COND 129290075Sobrien@findex FOR_EXPR 129390075Sobrien@findex FOR_BODY 129490075Sobrien@tindex FILE_STMT 129590075Sobrien@findex FILE_STMT_FILENAME 129690075Sobrien@tindex GOTO_STMT 129790075Sobrien@findex GOTO_DESTINATION 129890075Sobrien@findex GOTO_FAKE_P 129990075Sobrien@tindex HANDLER 130090075Sobrien@tindex IF_STMT 130190075Sobrien@findex IF_COND 130290075Sobrien@findex THEN_CLAUSE 130390075Sobrien@findex ELSE_CLAUSE 130490075Sobrien@tindex LABEL_STMT 130590075Sobrien@tindex LABEL_STMT_LABEL 130690075Sobrien@tindex RETURN_INIT 130790075Sobrien@tindex RETURN_STMT 130890075Sobrien@findex RETURN_EXPR 130990075Sobrien@tindex SCOPE_STMT 131090075Sobrien@findex SCOPE_BEGIN_P 131190075Sobrien@findex SCOPE_END_P 131290075Sobrien@findex SCOPE_NULLIFIED_P 131390075Sobrien@tindex SUBOBJECT 131490075Sobrien@findex SUBOBJECT_CLEANUP 131590075Sobrien@tindex SWITCH_STMT 131690075Sobrien@findex SWITCH_COND 131790075Sobrien@findex SWITCH_BODY 131890075Sobrien@tindex TRY_BLOCK 131990075Sobrien@findex TRY_STMTS 132090075Sobrien@findex TRY_HANDLERS 132190075Sobrien@findex HANDLER_PARMS 132290075Sobrien@findex HANDLER_BODY 132390075Sobrien@findex USING_STMT 132490075Sobrien@tindex WHILE_STMT 132590075Sobrien@findex WHILE_BODY 132690075Sobrien@findex WHILE_COND 132790075Sobrien 132890075SobrienA function that has a definition in the current translation unit will 132990075Sobrienhave a non-@code{NULL} @code{DECL_INITIAL}. However, back ends should not make 133090075Sobrienuse of the particular value given by @code{DECL_INITIAL}. 133190075Sobrien 133290075SobrienThe @code{DECL_SAVED_TREE} macro will give the complete body of the 133390075Sobrienfunction. This node will usually be a @code{COMPOUND_STMT} representing 133490075Sobrienthe outermost block of the function, but it may also be a 133590075Sobrien@code{TRY_BLOCK}, a @code{RETURN_INIT}, or any other valid statement. 133690075Sobrien 133790075Sobrien@subsubsection Statements 133890075Sobrien 133990075SobrienThere are tree nodes corresponding to all of the source-level statement 134090075Sobrienconstructs. These are enumerated here, together with a list of the 134190075Sobrienvarious macros that can be used to obtain information about them. There 134290075Sobrienare a few macros that can be used with all statements: 134390075Sobrien 134490075Sobrien@ftable @code 134590075Sobrien@item STMT_LINENO 134690075SobrienThis macro returns the line number for the statement. If the statement 134790075Sobrienspans multiple lines, this value will be the number of the first line on 134890075Sobrienwhich the statement occurs. Although we mention @code{CASE_LABEL} below 134990075Sobrienas if it were a statement, they do not allow the use of 135090075Sobrien@code{STMT_LINENO}. There is no way to obtain the line number for a 135190075Sobrien@code{CASE_LABEL}. 135290075Sobrien 135390075SobrienStatements do not contain information about 135490075Sobrienthe file from which they came; that information is implicit in the 135590075Sobrien@code{FUNCTION_DECL} from which the statements originate. 135690075Sobrien 135790075Sobrien@item STMT_IS_FULL_EXPR_P 135890075SobrienIn C++, statements normally constitute ``full expressions''; temporaries 135990075Sobriencreated during a statement are destroyed when the statement is complete. 136090075SobrienHowever, G++ sometimes represents expressions by statements; these 136190075Sobrienstatements will not have @code{STMT_IS_FULL_EXPR_P} set. Temporaries 136290075Sobriencreated during such statements should be destroyed when the innermost 136390075Sobrienenclosing statement with @code{STMT_IS_FULL_EXPR_P} set is exited. 136490075Sobrien 136590075Sobrien@end ftable 136690075Sobrien 136790075SobrienHere is the list of the various statement nodes, and the macros used to 136890075Sobrienaccess them. This documentation describes the use of these nodes in 136990075Sobriennon-template functions (including instantiations of template functions). 137090075SobrienIn template functions, the same nodes are used, but sometimes in 137190075Sobrienslightly different ways. 137290075Sobrien 137390075SobrienMany of the statements have substatements. For example, a @code{while} 137490075Sobrienloop will have a body, which is itself a statement. If the substatement 137590075Sobrienis @code{NULL_TREE}, it is considered equivalent to a statement 137690075Sobrienconsisting of a single @code{;}, i.e., an expression statement in which 137790075Sobrienthe expression has been omitted. A substatement may in fact be a list 137890075Sobrienof statements, connected via their @code{TREE_CHAIN}s. So, you should 137990075Sobrienalways process the statement tree by looping over substatements, like 138090075Sobrienthis: 1381132718Skan@smallexample 138290075Sobrienvoid process_stmt (stmt) 138390075Sobrien tree stmt; 138490075Sobrien@{ 138590075Sobrien while (stmt) 138690075Sobrien @{ 138790075Sobrien switch (TREE_CODE (stmt)) 138890075Sobrien @{ 138990075Sobrien case IF_STMT: 139090075Sobrien process_stmt (THEN_CLAUSE (stmt)); 139190075Sobrien /* More processing here. */ 139290075Sobrien break; 139390075Sobrien 139490075Sobrien @dots{} 139590075Sobrien @} 139690075Sobrien 139790075Sobrien stmt = TREE_CHAIN (stmt); 139890075Sobrien @} 139990075Sobrien@} 1400132718Skan@end smallexample 140190075SobrienIn other words, while the @code{then} clause of an @code{if} statement 140290075Sobrienin C++ can be only one statement (although that one statement may be a 140390075Sobriencompound statement), the intermediate representation will sometimes use 140490075Sobrienseveral statements chained together. 140590075Sobrien 140690075Sobrien@table @code 140790075Sobrien@item ASM_STMT 140890075Sobrien 140990075SobrienUsed to represent an inline assembly statement. For an inline assembly 141090075Sobrienstatement like: 1411132718Skan@smallexample 141290075Sobrienasm ("mov x, y"); 1413132718Skan@end smallexample 141490075SobrienThe @code{ASM_STRING} macro will return a @code{STRING_CST} node for 141590075Sobrien@code{"mov x, y"}. If the original statement made use of the 141690075Sobrienextended-assembly syntax, then @code{ASM_OUTPUTS}, 141790075Sobrien@code{ASM_INPUTS}, and @code{ASM_CLOBBERS} will be the outputs, inputs, 141890075Sobrienand clobbers for the statement, represented as @code{STRING_CST} nodes. 141990075SobrienThe extended-assembly syntax looks like: 1420132718Skan@smallexample 142190075Sobrienasm ("fsinx %1,%0" : "=f" (result) : "f" (angle)); 1422132718Skan@end smallexample 142390075SobrienThe first string is the @code{ASM_STRING}, containing the instruction 142490075Sobrientemplate. The next two strings are the output and inputs, respectively; 142590075Sobrienthis statement has no clobbers. As this example indicates, ``plain'' 142690075Sobrienassembly statements are merely a special case of extended assembly 142790075Sobrienstatements; they have no cv-qualifiers, outputs, inputs, or clobbers. 142890075SobrienAll of the strings will be @code{NUL}-terminated, and will contain no 142990075Sobrienembedded @code{NUL}-characters. 143090075Sobrien 143190075SobrienIf the assembly statement is declared @code{volatile}, or if the 143290075Sobrienstatement was not an extended assembly statement, and is therefore 143390075Sobrienimplicitly volatile, then the predicate @code{ASM_VOLATILE_P} will hold 143490075Sobrienof the @code{ASM_STMT}. 143590075Sobrien 143690075Sobrien@item BREAK_STMT 143790075Sobrien 143890075SobrienUsed to represent a @code{break} statement. There are no additional 143990075Sobrienfields. 144090075Sobrien 144190075Sobrien@item CASE_LABEL 144290075Sobrien 144390075SobrienUse to represent a @code{case} label, range of @code{case} labels, or a 144490075Sobrien@code{default} label. If @code{CASE_LOW} is @code{NULL_TREE}, then this is a 144590075Sobrien@code{default} label. Otherwise, if @code{CASE_HIGH} is @code{NULL_TREE}, then 144690075Sobrienthis is an ordinary @code{case} label. In this case, @code{CASE_LOW} is 144790075Sobrienan expression giving the value of the label. Both @code{CASE_LOW} and 144890075Sobrien@code{CASE_HIGH} are @code{INTEGER_CST} nodes. These values will have 144990075Sobrienthe same type as the condition expression in the switch statement. 145090075Sobrien 145190075SobrienOtherwise, if both @code{CASE_LOW} and @code{CASE_HIGH} are defined, the 145290075Sobrienstatement is a range of case labels. Such statements originate with the 145390075Sobrienextension that allows users to write things of the form: 1454132718Skan@smallexample 145590075Sobriencase 2 ... 5: 1456132718Skan@end smallexample 145790075SobrienThe first value will be @code{CASE_LOW}, while the second will be 145890075Sobrien@code{CASE_HIGH}. 145990075Sobrien 146090075Sobrien@item CLEANUP_STMT 146190075Sobrien 146290075SobrienUsed to represent an action that should take place upon exit from the 146390075Sobrienenclosing scope. Typically, these actions are calls to destructors for 146490075Sobrienlocal objects, but back ends cannot rely on this fact. If these nodes 146590075Sobrienare in fact representing such destructors, @code{CLEANUP_DECL} will be 146690075Sobrienthe @code{VAR_DECL} destroyed. Otherwise, @code{CLEANUP_DECL} will be 146790075Sobrien@code{NULL_TREE}. In any case, the @code{CLEANUP_EXPR} is the 146890075Sobrienexpression to execute. The cleanups executed on exit from a scope 146990075Sobrienshould be run in the reverse order of the order in which the associated 147090075Sobrien@code{CLEANUP_STMT}s were encountered. 147190075Sobrien 147290075Sobrien@item COMPOUND_STMT 147390075Sobrien 147490075SobrienUsed to represent a brace-enclosed block. The first substatement is 147590075Sobriengiven by @code{COMPOUND_BODY}. Subsequent substatements are found by 147690075Sobrienfollowing the @code{TREE_CHAIN} link from one substatement to the next. 147790075SobrienThe @code{COMPOUND_BODY} will be @code{NULL_TREE} if there are no 147890075Sobriensubstatements. 147990075Sobrien 148090075Sobrien@item CONTINUE_STMT 148190075Sobrien 148290075SobrienUsed to represent a @code{continue} statement. There are no additional 148390075Sobrienfields. 148490075Sobrien 148590075Sobrien@item CTOR_STMT 148690075Sobrien 148790075SobrienUsed to mark the beginning (if @code{CTOR_BEGIN_P} holds) or end (if 148890075Sobrien@code{CTOR_END_P} holds of the main body of a constructor. See also 148990075Sobrien@code{SUBOBJECT} for more information on how to use these nodes. 149090075Sobrien 149190075Sobrien@item DECL_STMT 149290075Sobrien 149390075SobrienUsed to represent a local declaration. The @code{DECL_STMT_DECL} macro 149490075Sobriencan be used to obtain the entity declared. This declaration may be a 149590075Sobrien@code{LABEL_DECL}, indicating that the label declared is a local label. 149690075Sobrien(As an extension, GCC allows the declaration of labels with scope.) In 149790075SobrienC, this declaration may be a @code{FUNCTION_DECL}, indicating the 149890075Sobrienuse of the GCC nested function extension. For more information, 149990075Sobrien@pxref{Functions}. 150090075Sobrien 150190075Sobrien@item DO_STMT 150290075Sobrien 150390075SobrienUsed to represent a @code{do} loop. The body of the loop is given by 150490075Sobrien@code{DO_BODY} while the termination condition for the loop is given by 150590075Sobrien@code{DO_COND}. The condition for a @code{do}-statement is always an 150690075Sobrienexpression. 150790075Sobrien 150890075Sobrien@item EMPTY_CLASS_EXPR 150990075Sobrien 151090075SobrienUsed to represent a temporary object of a class with no data whose 151190075Sobrienaddress is never taken. (All such objects are interchangeable.) The 151290075Sobrien@code{TREE_TYPE} represents the type of the object. 151390075Sobrien 151490075Sobrien@item EXPR_STMT 151590075Sobrien 151690075SobrienUsed to represent an expression statement. Use @code{EXPR_STMT_EXPR} to 151790075Sobrienobtain the expression. 151890075Sobrien 151990075Sobrien@item FILE_STMT 152090075Sobrien 152190075SobrienUsed to record a change in filename within the body of a function. 152290075SobrienUse @code{FILE_STMT_FILENAME} to obtain the new filename. 152390075Sobrien 152490075Sobrien@item FOR_STMT 152590075Sobrien 152690075SobrienUsed to represent a @code{for} statement. The @code{FOR_INIT_STMT} is 152790075Sobrienthe initialization statement for the loop. The @code{FOR_COND} is the 152890075Sobrientermination condition. The @code{FOR_EXPR} is the expression executed 152990075Sobrienright before the @code{FOR_COND} on each loop iteration; often, this 153090075Sobrienexpression increments a counter. The body of the loop is given by 153190075Sobrien@code{FOR_BODY}. Note that @code{FOR_INIT_STMT} and @code{FOR_BODY} 153290075Sobrienreturn statements, while @code{FOR_COND} and @code{FOR_EXPR} return 153390075Sobrienexpressions. 153490075Sobrien 153590075Sobrien@item GOTO_STMT 153690075Sobrien 153790075SobrienUsed to represent a @code{goto} statement. The @code{GOTO_DESTINATION} will 153890075Sobrienusually be a @code{LABEL_DECL}. However, if the ``computed goto'' extension 153990075Sobrienhas been used, the @code{GOTO_DESTINATION} will be an arbitrary expression 154090075Sobrienindicating the destination. This expression will always have pointer type. 154190075SobrienAdditionally the @code{GOTO_FAKE_P} flag is set whenever the goto statement 154290075Sobriendoes not come from source code, but it is generated implicitly by the compiler. 154390075SobrienThis is used for branch prediction. 154490075Sobrien 154590075Sobrien@item HANDLER 154690075Sobrien 154790075SobrienUsed to represent a C++ @code{catch} block. The @code{HANDLER_TYPE} 154890075Sobrienis the type of exception that will be caught by this handler; it is 1549132718Skanequal (by pointer equality) to @code{NULL} if this handler is for all 1550132718Skantypes. @code{HANDLER_PARMS} is the @code{DECL_STMT} for the catch 1551132718Skanparameter, and @code{HANDLER_BODY} is the @code{COMPOUND_STMT} for the 1552132718Skanblock itself. 155390075Sobrien 155490075Sobrien@item IF_STMT 155590075Sobrien 155690075SobrienUsed to represent an @code{if} statement. The @code{IF_COND} is the 155790075Sobrienexpression. 155890075Sobrien 155990075SobrienIf the condition is a @code{TREE_LIST}, then the @code{TREE_PURPOSE} is 156090075Sobriena statement (usually a @code{DECL_STMT}). Each time the condition is 156190075Sobrienevaluated, the statement should be executed. Then, the 156290075Sobrien@code{TREE_VALUE} should be used as the conditional expression itself. 156390075SobrienThis representation is used to handle C++ code like this: 156490075Sobrien 1565132718Skan@smallexample 156690075Sobrienif (int i = 7) @dots{} 1567132718Skan@end smallexample 156890075Sobrien 156990075Sobrienwhere there is a new local variable (or variables) declared within the 157090075Sobriencondition. 157190075Sobrien 157290075SobrienThe @code{THEN_CLAUSE} represents the statement given by the @code{then} 157390075Sobriencondition, while the @code{ELSE_CLAUSE} represents the statement given 157490075Sobrienby the @code{else} condition. 157590075Sobrien 157690075Sobrien@item LABEL_STMT 157790075Sobrien 157890075SobrienUsed to represent a label. The @code{LABEL_DECL} declared by this 157990075Sobrienstatement can be obtained with the @code{LABEL_STMT_LABEL} macro. The 158090075Sobrien@code{IDENTIFIER_NODE} giving the name of the label can be obtained from 158190075Sobrienthe @code{LABEL_DECL} with @code{DECL_NAME}. 158290075Sobrien 158390075Sobrien@item RETURN_INIT 158490075Sobrien 158590075SobrienIf the function uses the G++ ``named return value'' extension, meaning 158690075Sobrienthat the function has been defined like: 1587132718Skan@smallexample 158890075SobrienS f(int) return s @{@dots{}@} 1589132718Skan@end smallexample 159090075Sobrienthen there will be a @code{RETURN_INIT}. There is never a named 159190075Sobrienreturned value for a constructor. The first argument to the 159290075Sobrien@code{RETURN_INIT} is the name of the object returned; the second 159390075Sobrienargument is the initializer for the object. The object is initialized 159490075Sobrienwhen the @code{RETURN_INIT} is encountered. The object referred to is 159590075Sobrienthe actual object returned; this extension is a manual way of doing the 159690075Sobrien``return-value optimization.'' Therefore, the object must actually be 159790075Sobrienconstructed in the place where the object will be returned. 159890075Sobrien 159990075Sobrien@item RETURN_STMT 160090075Sobrien 160190075SobrienUsed to represent a @code{return} statement. The @code{RETURN_EXPR} is 160290075Sobrienthe expression returned; it will be @code{NULL_TREE} if the statement 160390075Sobrienwas just 1604132718Skan@smallexample 160590075Sobrienreturn; 1606132718Skan@end smallexample 160790075Sobrien 160890075Sobrien@item SCOPE_STMT 160990075Sobrien 161090075SobrienA scope-statement represents the beginning or end of a scope. If 161190075Sobrien@code{SCOPE_BEGIN_P} holds, this statement represents the beginning of a 161290075Sobrienscope; if @code{SCOPE_END_P} holds this statement represents the end of 161390075Sobriena scope. On exit from a scope, all cleanups from @code{CLEANUP_STMT}s 161490075Sobrienoccurring in the scope must be run, in reverse order to the order in 161590075Sobrienwhich they were encountered. If @code{SCOPE_NULLIFIED_P} or 161690075Sobrien@code{SCOPE_NO_CLEANUPS_P} holds of the scope, back ends should behave 161790075Sobrienas if the @code{SCOPE_STMT} were not present at all. 161890075Sobrien 161990075Sobrien@item SUBOBJECT 162090075Sobrien 162190075SobrienIn a constructor, these nodes are used to mark the point at which a 162290075Sobriensubobject of @code{this} is fully constructed. If, after this point, an 162390075Sobrienexception is thrown before a @code{CTOR_STMT} with @code{CTOR_END_P} set 162490075Sobrienis encountered, the @code{SUBOBJECT_CLEANUP} must be executed. The 162590075Sobriencleanups must be executed in the reverse order in which they appear. 162690075Sobrien 162790075Sobrien@item SWITCH_STMT 162890075Sobrien 162990075SobrienUsed to represent a @code{switch} statement. The @code{SWITCH_COND} is 163090075Sobrienthe expression on which the switch is occurring. See the documentation 163190075Sobrienfor an @code{IF_STMT} for more information on the representation used 163290075Sobrienfor the condition. The @code{SWITCH_BODY} is the body of the switch 163396263Sobrienstatement. The @code{SWITCH_TYPE} is the original type of switch 163496263Sobrienexpression as given in the source, before any compiler conversions. 163590075Sobrien 163690075Sobrien@item TRY_BLOCK 163790075SobrienUsed to represent a @code{try} block. The body of the try block is 163890075Sobriengiven by @code{TRY_STMTS}. Each of the catch blocks is a @code{HANDLER} 163990075Sobriennode. The first handler is given by @code{TRY_HANDLERS}. Subsequent 164090075Sobrienhandlers are obtained by following the @code{TREE_CHAIN} link from one 164190075Sobrienhandler to the next. The body of the handler is given by 164290075Sobrien@code{HANDLER_BODY}. 164390075Sobrien 164490075SobrienIf @code{CLEANUP_P} holds of the @code{TRY_BLOCK}, then the 164590075Sobrien@code{TRY_HANDLERS} will not be a @code{HANDLER} node. Instead, it will 164690075Sobrienbe an expression that should be executed if an exception is thrown in 164790075Sobrienthe try block. It must rethrow the exception after executing that code. 164890075SobrienAnd, if an exception is thrown while the expression is executing, 164990075Sobrien@code{terminate} must be called. 165090075Sobrien 165190075Sobrien@item USING_STMT 165290075SobrienUsed to represent a @code{using} directive. The namespace is given by 165390075Sobrien@code{USING_STMT_NAMESPACE}, which will be a NAMESPACE_DECL@. This node 165490075Sobrienis needed inside template functions, to implement using directives 165590075Sobrienduring instantiation. 165690075Sobrien 165790075Sobrien@item WHILE_STMT 165890075Sobrien 165990075SobrienUsed to represent a @code{while} loop. The @code{WHILE_COND} is the 166090075Sobrientermination condition for the loop. See the documentation for an 166190075Sobrien@code{IF_STMT} for more information on the representation used for the 166290075Sobriencondition. 166390075Sobrien 166490075SobrienThe @code{WHILE_BODY} is the body of the loop. 166590075Sobrien 166690075Sobrien@end table 166790075Sobrien 166890075Sobrien@c --------------------------------------------------------------------- 166990075Sobrien@c Attributes 167090075Sobrien@c --------------------------------------------------------------------- 167190075Sobrien@node Attributes 167290075Sobrien@section Attributes in trees 167390075Sobrien@cindex attributes 167490075Sobrien 167590075SobrienAttributes, as specified using the @code{__attribute__} keyword, are 167690075Sobrienrepresented internally as a @code{TREE_LIST}. The @code{TREE_PURPOSE} 167790075Sobrienis the name of the attribute, as an @code{IDENTIFIER_NODE}. The 167890075Sobrien@code{TREE_VALUE} is a @code{TREE_LIST} of the arguments of the 167990075Sobrienattribute, if any, or @code{NULL_TREE} if there are no arguments; the 168090075Sobrienarguments are stored as the @code{TREE_VALUE} of successive entries in 168190075Sobrienthe list, and may be identifiers or expressions. The @code{TREE_CHAIN} 168290075Sobrienof the attribute is the next attribute in a list of attributes applying 168390075Sobriento the same declaration or type, or @code{NULL_TREE} if there are no 168490075Sobrienfurther attributes in the list. 168590075Sobrien 168690075SobrienAttributes may be attached to declarations and to types; these 168790075Sobrienattributes may be accessed with the following macros. All attributes 168890075Sobrienare stored in this way, and many also cause other changes to the 168990075Sobriendeclaration or type or to other internal compiler data structures. 169090075Sobrien 169190075Sobrien@deftypefn {Tree Macro} tree DECL_ATTRIBUTES (tree @var{decl}) 169290075SobrienThis macro returns the attributes on the declaration @var{decl}. 169390075Sobrien@end deftypefn 169490075Sobrien 169590075Sobrien@deftypefn {Tree Macro} tree TYPE_ATTRIBUTES (tree @var{type}) 169690075SobrienThis macro returns the attributes on the type @var{type}. 169790075Sobrien@end deftypefn 169890075Sobrien 169990075Sobrien@c --------------------------------------------------------------------- 170090075Sobrien@c Expressions 170190075Sobrien@c --------------------------------------------------------------------- 170290075Sobrien 170390075Sobrien@node Expression trees 170490075Sobrien@section Expressions 170590075Sobrien@cindex expression 170690075Sobrien@findex TREE_OPERAND 170790075Sobrien@tindex INTEGER_CST 170890075Sobrien@findex TREE_INT_CST_HIGH 170990075Sobrien@findex TREE_INT_CST_LOW 171090075Sobrien@findex tree_int_cst_lt 171190075Sobrien@findex tree_int_cst_equal 171290075Sobrien@tindex REAL_CST 171390075Sobrien@tindex COMPLEX_CST 171496263Sobrien@tindex VECTOR_CST 171590075Sobrien@tindex STRING_CST 171690075Sobrien@findex TREE_STRING_LENGTH 171790075Sobrien@findex TREE_STRING_POINTER 171890075Sobrien@tindex PTRMEM_CST 171990075Sobrien@findex PTRMEM_CST_CLASS 172090075Sobrien@findex PTRMEM_CST_MEMBER 172190075Sobrien@tindex VAR_DECL 172290075Sobrien@tindex NEGATE_EXPR 1723132718Skan@tindex ABS_EXPR 172490075Sobrien@tindex BIT_NOT_EXPR 172590075Sobrien@tindex TRUTH_NOT_EXPR 172690075Sobrien@tindex ADDR_EXPR 172790075Sobrien@tindex INDIRECT_REF 172890075Sobrien@tindex FIX_TRUNC_EXPR 172990075Sobrien@tindex FLOAT_EXPR 173090075Sobrien@tindex COMPLEX_EXPR 173190075Sobrien@tindex CONJ_EXPR 173290075Sobrien@tindex REALPART_EXPR 173390075Sobrien@tindex IMAGPART_EXPR 173490075Sobrien@tindex NOP_EXPR 173590075Sobrien@tindex CONVERT_EXPR 173690075Sobrien@tindex THROW_EXPR 173790075Sobrien@tindex LSHIFT_EXPR 173890075Sobrien@tindex RSHIFT_EXPR 173990075Sobrien@tindex BIT_IOR_EXPR 174090075Sobrien@tindex BIT_XOR_EXPR 174190075Sobrien@tindex BIT_AND_EXPR 174290075Sobrien@tindex TRUTH_ANDIF_EXPR 174390075Sobrien@tindex TRUTH_ORIF_EXPR 174490075Sobrien@tindex TRUTH_AND_EXPR 174590075Sobrien@tindex TRUTH_OR_EXPR 174690075Sobrien@tindex TRUTH_XOR_EXPR 174790075Sobrien@tindex PLUS_EXPR 174890075Sobrien@tindex MINUS_EXPR 174990075Sobrien@tindex MULT_EXPR 175090075Sobrien@tindex TRUNC_DIV_EXPR 175190075Sobrien@tindex TRUNC_MOD_EXPR 175290075Sobrien@tindex RDIV_EXPR 175390075Sobrien@tindex LT_EXPR 175490075Sobrien@tindex LE_EXPR 175590075Sobrien@tindex GT_EXPR 175690075Sobrien@tindex GE_EXPR 175790075Sobrien@tindex EQ_EXPR 175890075Sobrien@tindex NE_EXPR 175990075Sobrien@tindex INIT_EXPR 176090075Sobrien@tindex MODIFY_EXPR 176190075Sobrien@tindex COMPONENT_REF 176290075Sobrien@tindex COMPOUND_EXPR 176390075Sobrien@tindex COND_EXPR 176490075Sobrien@tindex CALL_EXPR 176590075Sobrien@tindex CONSTRUCTOR 176690075Sobrien@tindex COMPOUND_LITERAL_EXPR 176790075Sobrien@tindex STMT_EXPR 176890075Sobrien@tindex BIND_EXPR 176990075Sobrien@tindex LOOP_EXPR 177090075Sobrien@tindex EXIT_EXPR 177190075Sobrien@tindex CLEANUP_POINT_EXPR 177290075Sobrien@tindex ARRAY_REF 177390075Sobrien@tindex VTABLE_REF 1774117395Skan@tindex VA_ARG_EXPR 177590075Sobrien 177690075SobrienThe internal representation for expressions is for the most part quite 177790075Sobrienstraightforward. However, there are a few facts that one must bear in 177890075Sobrienmind. In particular, the expression ``tree'' is actually a directed 177990075Sobrienacyclic graph. (For example there may be many references to the integer 178090075Sobrienconstant zero throughout the source program; many of these will be 178190075Sobrienrepresented by the same expression node.) You should not rely on 178290075Sobriencertain kinds of node being shared, nor should rely on certain kinds of 178390075Sobriennodes being unshared. 178490075Sobrien 178590075SobrienThe following macros can be used with all expression nodes: 178690075Sobrien 178790075Sobrien@ftable @code 178890075Sobrien@item TREE_TYPE 178990075SobrienReturns the type of the expression. This value may not be precisely the 179090075Sobriensame type that would be given the expression in the original program. 179190075Sobrien@end ftable 179290075Sobrien 179390075SobrienIn what follows, some nodes that one might expect to always have type 179490075Sobrien@code{bool} are documented to have either integral or boolean type. At 179590075Sobriensome point in the future, the C front end may also make use of this same 179690075Sobrienintermediate representation, and at this point these nodes will 179790075Sobriencertainly have integral type. The previous sentence is not meant to 179890075Sobrienimply that the C++ front end does not or will not give these nodes 179990075Sobrienintegral type. 180090075Sobrien 180190075SobrienBelow, we list the various kinds of expression nodes. Except where 180290075Sobriennoted otherwise, the operands to an expression are accessed using the 180390075Sobrien@code{TREE_OPERAND} macro. For example, to access the first operand to 180490075Sobriena binary plus expression @code{expr}, use: 180590075Sobrien 1806132718Skan@smallexample 180790075SobrienTREE_OPERAND (expr, 0) 1808132718Skan@end smallexample 180990075Sobrien@noindent 181090075SobrienAs this example indicates, the operands are zero-indexed. 181190075Sobrien 181290075SobrienThe table below begins with constants, moves on to unary expressions, 181390075Sobrienthen proceeds to binary expressions, and concludes with various other 181490075Sobrienkinds of expressions: 181590075Sobrien 181690075Sobrien@table @code 181790075Sobrien@item INTEGER_CST 181890075SobrienThese nodes represent integer constants. Note that the type of these 181990075Sobrienconstants is obtained with @code{TREE_TYPE}; they are not always of type 182090075Sobrien@code{int}. In particular, @code{char} constants are represented with 182190075Sobrien@code{INTEGER_CST} nodes. The value of the integer constant @code{e} is 1822132718Skangiven by 1823132718Skan@smallexample 182490075Sobrien((TREE_INT_CST_HIGH (e) << HOST_BITS_PER_WIDE_INT) 182590075Sobrien+ TREE_INST_CST_LOW (e)) 1826132718Skan@end smallexample 182790075Sobrien@noindent 182890075SobrienHOST_BITS_PER_WIDE_INT is at least thirty-two on all platforms. Both 182990075Sobrien@code{TREE_INT_CST_HIGH} and @code{TREE_INT_CST_LOW} return a 183090075Sobrien@code{HOST_WIDE_INT}. The value of an @code{INTEGER_CST} is interpreted 183190075Sobrienas a signed or unsigned quantity depending on the type of the constant. 183290075SobrienIn general, the expression given above will overflow, so it should not 183390075Sobrienbe used to calculate the value of the constant. 183490075Sobrien 183590075SobrienThe variable @code{integer_zero_node} is an integer constant with value 183690075Sobrienzero. Similarly, @code{integer_one_node} is an integer constant with 183790075Sobrienvalue one. The @code{size_zero_node} and @code{size_one_node} variables 183890075Sobrienare analogous, but have type @code{size_t} rather than @code{int}. 183990075Sobrien 184090075SobrienThe function @code{tree_int_cst_lt} is a predicate which holds if its 184190075Sobrienfirst argument is less than its second. Both constants are assumed to 184290075Sobrienhave the same signedness (i.e., either both should be signed or both 184390075Sobrienshould be unsigned.) The full width of the constant is used when doing 184490075Sobrienthe comparison; the usual rules about promotions and conversions are 184590075Sobrienignored. Similarly, @code{tree_int_cst_equal} holds if the two 184690075Sobrienconstants are equal. The @code{tree_int_cst_sgn} function returns the 184790075Sobriensign of a constant. The value is @code{1}, @code{0}, or @code{-1} 184890075Sobrienaccording on whether the constant is greater than, equal to, or less 184990075Sobrienthan zero. Again, the signedness of the constant's type is taken into 185090075Sobrienaccount; an unsigned constant is never less than zero, no matter what 185190075Sobrienits bit-pattern. 185290075Sobrien 185390075Sobrien@item REAL_CST 185490075Sobrien 185590075SobrienFIXME: Talk about how to obtain representations of this constant, do 185690075Sobriencomparisons, and so forth. 185790075Sobrien 185890075Sobrien@item COMPLEX_CST 185990075SobrienThese nodes are used to represent complex number constants, that is a 186090075Sobrien@code{__complex__} whose parts are constant nodes. The 186190075Sobrien@code{TREE_REALPART} and @code{TREE_IMAGPART} return the real and the 186290075Sobrienimaginary parts respectively. 186390075Sobrien 186496263Sobrien@item VECTOR_CST 186596263SobrienThese nodes are used to represent vector constants, whose parts are 186696263Sobrienconstant nodes. Each individual constant node is either an integer or a 186796263Sobriendouble constant node. The first operand is a @code{TREE_LIST} of the 186896263Sobrienconstant nodes and is accessed through @code{TREE_VECTOR_CST_ELTS}. 186996263Sobrien 187090075Sobrien@item STRING_CST 187190075SobrienThese nodes represent string-constants. The @code{TREE_STRING_LENGTH} 187290075Sobrienreturns the length of the string, as an @code{int}. The 187390075Sobrien@code{TREE_STRING_POINTER} is a @code{char*} containing the string 187490075Sobrienitself. The string may not be @code{NUL}-terminated, and it may contain 187590075Sobrienembedded @code{NUL} characters. Therefore, the 187690075Sobrien@code{TREE_STRING_LENGTH} includes the trailing @code{NUL} if it is 187790075Sobrienpresent. 187890075Sobrien 187990075SobrienFor wide string constants, the @code{TREE_STRING_LENGTH} is the number 188090075Sobrienof bytes in the string, and the @code{TREE_STRING_POINTER} 188190075Sobrienpoints to an array of the bytes of the string, as represented on the 188290075Sobrientarget system (that is, as integers in the target endianness). Wide and 188390075Sobriennon-wide string constants are distinguished only by the @code{TREE_TYPE} 188490075Sobrienof the @code{STRING_CST}. 188590075Sobrien 188690075SobrienFIXME: The formats of string constants are not well-defined when the 188790075Sobrientarget system bytes are not the same width as host system bytes. 188890075Sobrien 188990075Sobrien@item PTRMEM_CST 189090075SobrienThese nodes are used to represent pointer-to-member constants. The 189190075Sobrien@code{PTRMEM_CST_CLASS} is the class type (either a @code{RECORD_TYPE} 189290075Sobrienor @code{UNION_TYPE} within which the pointer points), and the 189390075Sobrien@code{PTRMEM_CST_MEMBER} is the declaration for the pointed to object. 189490075SobrienNote that the @code{DECL_CONTEXT} for the @code{PTRMEM_CST_MEMBER} is in 189590075Sobriengeneral different from the @code{PTRMEM_CST_CLASS}. For example, 189690075Sobriengiven: 1897132718Skan@smallexample 189890075Sobrienstruct B @{ int i; @}; 189990075Sobrienstruct D : public B @{@}; 190090075Sobrienint D::*dp = &D::i; 1901132718Skan@end smallexample 190290075Sobrien@noindent 190390075SobrienThe @code{PTRMEM_CST_CLASS} for @code{&D::i} is @code{D}, even though 190490075Sobrienthe @code{DECL_CONTEXT} for the @code{PTRMEM_CST_MEMBER} is @code{B}, 190590075Sobriensince @code{B::i} is a member of @code{B}, not @code{D}. 190690075Sobrien 190790075Sobrien@item VAR_DECL 190890075Sobrien 190990075SobrienThese nodes represent variables, including static data members. For 191090075Sobrienmore information, @pxref{Declarations}. 191190075Sobrien 191290075Sobrien@item NEGATE_EXPR 191390075SobrienThese nodes represent unary negation of the single operand, for both 191490075Sobrieninteger and floating-point types. The type of negation can be 191590075Sobriendetermined by looking at the type of the expression. 191690075Sobrien 1917132718SkanThe behavior of this operation on signed arithmetic overflow is 1918132718Skancontrolled by the @code{flag_wrapv} and @code{flag_trapv} variables. 1919132718Skan 1920132718Skan@item ABS_EXPR 1921132718SkanThese nodes represent the absolute value of the single operand, for 1922132718Skanboth integer and floating-point types. This is typically used to 1923132718Skanimplement the @code{abs}, @code{labs} and @code{llabs} builtins for 1924132718Skaninteger types, and the @code{fabs}, @code{fabsf} and @code{fabsl} 1925132718Skanbuiltins for floating point types. The type of abs operation can 1926132718Skanbe determined by looking at the type of the expression. 1927132718Skan 1928132718SkanThis node is not used for complex types. To represent the modulus 1929132718Skanor complex abs of a complex value, use the @code{BUILT_IN_CABS}, 1930132718Skan@code{BUILT_IN_CABSF} or @code{BUILT_IN_CABSL} builtins, as used 1931132718Skanto implement the C99 @code{cabs}, @code{cabsf} and @code{cabsl} 1932132718Skanbuilt-in functions. 1933132718Skan 193490075Sobrien@item BIT_NOT_EXPR 193590075SobrienThese nodes represent bitwise complement, and will always have integral 193690075Sobrientype. The only operand is the value to be complemented. 193790075Sobrien 193890075Sobrien@item TRUTH_NOT_EXPR 193990075SobrienThese nodes represent logical negation, and will always have integral 194090075Sobrien(or boolean) type. The operand is the value being negated. 194190075Sobrien 194290075Sobrien@item PREDECREMENT_EXPR 194390075Sobrien@itemx PREINCREMENT_EXPR 194490075Sobrien@itemx POSTDECREMENT_EXPR 194590075Sobrien@itemx POSTINCREMENT_EXPR 194690075SobrienThese nodes represent increment and decrement expressions. The value of 194790075Sobrienthe single operand is computed, and the operand incremented or 194890075Sobriendecremented. In the case of @code{PREDECREMENT_EXPR} and 194990075Sobrien@code{PREINCREMENT_EXPR}, the value of the expression is the value 195090075Sobrienresulting after the increment or decrement; in the case of 195190075Sobrien@code{POSTDECREMENT_EXPR} and @code{POSTINCREMENT_EXPR} is the value 195290075Sobrienbefore the increment or decrement occurs. The type of the operand, like 195390075Sobrienthat of the result, will be either integral, boolean, or floating-point. 195490075Sobrien 195590075Sobrien@item ADDR_EXPR 195690075SobrienThese nodes are used to represent the address of an object. (These 195790075Sobrienexpressions will always have pointer or reference type.) The operand may 195890075Sobrienbe another expression, or it may be a declaration. 195990075Sobrien 196090075SobrienAs an extension, GCC allows users to take the address of a label. In 196190075Sobrienthis case, the operand of the @code{ADDR_EXPR} will be a 196290075Sobrien@code{LABEL_DECL}. The type of such an expression is @code{void*}. 196390075Sobrien 196490075SobrienIf the object addressed is not an lvalue, a temporary is created, and 196590075Sobrienthe address of the temporary is used. 196690075Sobrien 196790075Sobrien@item INDIRECT_REF 196890075SobrienThese nodes are used to represent the object pointed to by a pointer. 196990075SobrienThe operand is the pointer being dereferenced; it will always have 197090075Sobrienpointer or reference type. 197190075Sobrien 197290075Sobrien@item FIX_TRUNC_EXPR 197390075SobrienThese nodes represent conversion of a floating-point value to an 197490075Sobrieninteger. The single operand will have a floating-point type, while the 197590075Sobrienthe complete expression will have an integral (or boolean) type. The 197690075Sobrienoperand is rounded towards zero. 197790075Sobrien 197890075Sobrien@item FLOAT_EXPR 197990075SobrienThese nodes represent conversion of an integral (or boolean) value to a 198090075Sobrienfloating-point value. The single operand will have integral type, while 198190075Sobrienthe complete expression will have a floating-point type. 198290075Sobrien 198390075SobrienFIXME: How is the operand supposed to be rounded? Is this dependent on 198490075Sobrien@option{-mieee}? 198590075Sobrien 198690075Sobrien@item COMPLEX_EXPR 198790075SobrienThese nodes are used to represent complex numbers constructed from two 198890075Sobrienexpressions of the same (integer or real) type. The first operand is the 198990075Sobrienreal part and the second operand is the imaginary part. 199090075Sobrien 199190075Sobrien@item CONJ_EXPR 199290075SobrienThese nodes represent the conjugate of their operand. 199390075Sobrien 199490075Sobrien@item REALPART_EXPR 1995132718Skan@itemx IMAGPART_EXPR 199690075SobrienThese nodes represent respectively the real and the imaginary parts 199790075Sobrienof complex numbers (their sole argument). 199890075Sobrien 199990075Sobrien@item NON_LVALUE_EXPR 200090075SobrienThese nodes indicate that their one and only operand is not an lvalue. 200190075SobrienA back end can treat these identically to the single operand. 200290075Sobrien 200390075Sobrien@item NOP_EXPR 200490075SobrienThese nodes are used to represent conversions that do not require any 200590075Sobriencode-generation. For example, conversion of a @code{char*} to an 200690075Sobrien@code{int*} does not require any code be generated; such a conversion is 200790075Sobrienrepresented by a @code{NOP_EXPR}. The single operand is the expression 200890075Sobriento be converted. The conversion from a pointer to a reference is also 200990075Sobrienrepresented with a @code{NOP_EXPR}. 201090075Sobrien 201190075Sobrien@item CONVERT_EXPR 201290075SobrienThese nodes are similar to @code{NOP_EXPR}s, but are used in those 201390075Sobriensituations where code may need to be generated. For example, if an 201490075Sobrien@code{int*} is converted to an @code{int} code may need to be generated 201590075Sobrienon some platforms. These nodes are never used for C++-specific 201690075Sobrienconversions, like conversions between pointers to different classes in 201790075Sobrienan inheritance hierarchy. Any adjustments that need to be made in such 201890075Sobriencases are always indicated explicitly. Similarly, a user-defined 201990075Sobrienconversion is never represented by a @code{CONVERT_EXPR}; instead, the 202090075Sobrienfunction calls are made explicit. 202190075Sobrien 202290075Sobrien@item THROW_EXPR 202390075SobrienThese nodes represent @code{throw} expressions. The single operand is 202490075Sobrienan expression for the code that should be executed to throw the 202590075Sobrienexception. However, there is one implicit action not represented in 202690075Sobrienthat expression; namely the call to @code{__throw}. This function takes 202790075Sobrienno arguments. If @code{setjmp}/@code{longjmp} exceptions are used, the 202890075Sobrienfunction @code{__sjthrow} is called instead. The normal GCC back end 202990075Sobrienuses the function @code{emit_throw} to generate this code; you can 203090075Sobrienexamine this function to see what needs to be done. 203190075Sobrien 203290075Sobrien@item LSHIFT_EXPR 203390075Sobrien@itemx RSHIFT_EXPR 203490075SobrienThese nodes represent left and right shifts, respectively. The first 203590075Sobrienoperand is the value to shift; it will always be of integral type. The 203690075Sobriensecond operand is an expression for the number of bits by which to 203790075Sobrienshift. Right shift should be treated as arithmetic, i.e., the 203890075Sobrienhigh-order bits should be zero-filled when the expression has unsigned 203990075Sobrientype and filled with the sign bit when the expression has signed type. 204090075SobrienNote that the result is undefined if the second operand is larger 204190075Sobrienthan the first operand's type size. 204290075Sobrien 204390075Sobrien 204490075Sobrien@item BIT_IOR_EXPR 204590075Sobrien@itemx BIT_XOR_EXPR 204690075Sobrien@itemx BIT_AND_EXPR 204790075SobrienThese nodes represent bitwise inclusive or, bitwise exclusive or, and 204890075Sobrienbitwise and, respectively. Both operands will always have integral 204990075Sobrientype. 205090075Sobrien 205190075Sobrien@item TRUTH_ANDIF_EXPR 205290075Sobrien@itemx TRUTH_ORIF_EXPR 205390075SobrienThese nodes represent logical and and logical or, respectively. These 205490075Sobrienoperators are not strict; i.e., the second operand is evaluated only if 205590075Sobrienthe value of the expression is not determined by evaluation of the first 205690075Sobrienoperand. The type of the operands, and the result type, is always of 205790075Sobrienboolean or integral type. 205890075Sobrien 205990075Sobrien@item TRUTH_AND_EXPR 206090075Sobrien@itemx TRUTH_OR_EXPR 206190075Sobrien@itemx TRUTH_XOR_EXPR 206290075SobrienThese nodes represent logical and, logical or, and logical exclusive or. 206390075SobrienThey are strict; both arguments are always evaluated. There are no 206490075Sobriencorresponding operators in C or C++, but the front end will sometimes 206590075Sobriengenerate these expressions anyhow, if it can tell that strictness does 206690075Sobriennot matter. 206790075Sobrien 206890075Sobrien@itemx PLUS_EXPR 206990075Sobrien@itemx MINUS_EXPR 207090075Sobrien@itemx MULT_EXPR 207190075Sobrien@itemx TRUNC_DIV_EXPR 207290075Sobrien@itemx TRUNC_MOD_EXPR 207390075Sobrien@itemx RDIV_EXPR 207490075SobrienThese nodes represent various binary arithmetic operations. 207590075SobrienRespectively, these operations are addition, subtraction (of the second 207690075Sobrienoperand from the first), multiplication, integer division, integer 207790075Sobrienremainder, and floating-point division. The operands to the first three 207890075Sobrienof these may have either integral or floating type, but there will never 207990075Sobrienbe case in which one operand is of floating type and the other is of 208090075Sobrienintegral type. 208190075Sobrien 208290075SobrienThe result of a @code{TRUNC_DIV_EXPR} is always rounded towards zero. 208390075SobrienThe @code{TRUNC_MOD_EXPR} of two operands @code{a} and @code{b} is 2084117395Skanalways @code{a - (a/b)*b} where the division is as if computed by a 208590075Sobrien@code{TRUNC_DIV_EXPR}. 208690075Sobrien 2087132718SkanThe behavior of these operations on signed arithmetic overflow is 2088132718Skancontrolled by the @code{flag_wrapv} and @code{flag_trapv} variables. 2089132718Skan 209090075Sobrien@item ARRAY_REF 209190075SobrienThese nodes represent array accesses. The first operand is the array; 209290075Sobrienthe second is the index. To calculate the address of the memory 209390075Sobrienaccessed, you must scale the index by the size of the type of the array 209490075Sobrienelements. The type of these expressions must be the type of a component of 209590075Sobrienthe array. 209690075Sobrien 209790075Sobrien@item ARRAY_RANGE_REF 209890075SobrienThese nodes represent access to a range (or ``slice'') of an array. The 209990075Sobrienoperands are the same as that for @code{ARRAY_REF} and have the same 210090075Sobrienmeanings. The type of these expressions must be an array whose component 210190075Sobrientype is the same as that of the first operand. The range of that array 210290075Sobrientype determines the amount of data these expressions access. 210390075Sobrien 210490075Sobrien@item EXACT_DIV_EXPR 210590075SobrienDocument. 210690075Sobrien 210790075Sobrien@item LT_EXPR 210890075Sobrien@itemx LE_EXPR 210990075Sobrien@itemx GT_EXPR 211090075Sobrien@itemx GE_EXPR 211190075Sobrien@itemx EQ_EXPR 211290075Sobrien@itemx NE_EXPR 211390075Sobrien 211490075SobrienThese nodes represent the less than, less than or equal to, greater 211590075Sobrienthan, greater than or equal to, equal, and not equal comparison 211690075Sobrienoperators. The first and second operand with either be both of integral 211790075Sobrientype or both of floating type. The result type of these expressions 211890075Sobrienwill always be of integral or boolean type. 211990075Sobrien 212090075Sobrien@item MODIFY_EXPR 212190075SobrienThese nodes represent assignment. The left-hand side is the first 212290075Sobrienoperand; the right-hand side is the second operand. The left-hand side 212390075Sobrienwill be a @code{VAR_DECL}, @code{INDIRECT_REF}, @code{COMPONENT_REF}, or 212490075Sobrienother lvalue. 212590075Sobrien 212690075SobrienThese nodes are used to represent not only assignment with @samp{=} but 212790075Sobrienalso compound assignments (like @samp{+=}), by reduction to @samp{=} 212890075Sobrienassignment. In other words, the representation for @samp{i += 3} looks 212990075Sobrienjust like that for @samp{i = i + 3}. 213090075Sobrien 213190075Sobrien@item INIT_EXPR 213290075SobrienThese nodes are just like @code{MODIFY_EXPR}, but are used only when a 213390075Sobrienvariable is initialized, rather than assigned to subsequently. 213490075Sobrien 213590075Sobrien@item COMPONENT_REF 213690075SobrienThese nodes represent non-static data member accesses. The first 213790075Sobrienoperand is the object (rather than a pointer to it); the second operand 213890075Sobrienis the @code{FIELD_DECL} for the data member. 213990075Sobrien 214090075Sobrien@item COMPOUND_EXPR 214190075SobrienThese nodes represent comma-expressions. The first operand is an 214290075Sobrienexpression whose value is computed and thrown away prior to the 214390075Sobrienevaluation of the second operand. The value of the entire expression is 214490075Sobrienthe value of the second operand. 214590075Sobrien 214690075Sobrien@item COND_EXPR 214790075SobrienThese nodes represent @code{?:} expressions. The first operand 214890075Sobrienis of boolean or integral type. If it evaluates to a nonzero value, 214990075Sobrienthe second operand should be evaluated, and returned as the value of the 215090075Sobrienexpression. Otherwise, the third operand is evaluated, and returned as 2151117395Skanthe value of the expression. 215290075Sobrien 2153117395SkanThe second operand must have the same type as the entire expression, 2154117395Skanunless it unconditionally throws an exception or calls a noreturn 2155117395Skanfunction, in which case it should have void type. The same constraints 2156117395Skanapply to the third operand. This allows array bounds checks to be 2157117395Skanrepresented conveniently as @code{(i >= 0 && i < 10) ? i : abort()}. 215890075Sobrien 2159117395SkanAs a GNU extension, the C language front-ends allow the second 2160117395Skanoperand of the @code{?:} operator may be omitted in the source. 2161117395SkanFor example, @code{x ? : 3} is equivalent to @code{x ? x : 3}, 2162117395Skanassuming that @code{x} is an expression without side-effects. 2163117395SkanIn the tree representation, however, the second operand is always 2164117395Skanpresent, possibly protected by @code{SAVE_EXPR} if the first 2165117395Skanargument does cause side-effects. 216690075Sobrien 216790075Sobrien@item CALL_EXPR 216890075SobrienThese nodes are used to represent calls to functions, including 216990075Sobriennon-static member functions. The first operand is a pointer to the 217090075Sobrienfunction to call; it is always an expression whose type is a 217190075Sobrien@code{POINTER_TYPE}. The second argument is a @code{TREE_LIST}. The 217290075Sobrienarguments to the call appear left-to-right in the list. The 217390075Sobrien@code{TREE_VALUE} of each list node contains the expression 217490075Sobriencorresponding to that argument. (The value of @code{TREE_PURPOSE} for 217590075Sobrienthese nodes is unspecified, and should be ignored.) For non-static 217690075Sobrienmember functions, there will be an operand corresponding to the 217790075Sobrien@code{this} pointer. There will always be expressions corresponding to 217890075Sobrienall of the arguments, even if the function is declared with default 217990075Sobrienarguments and some arguments are not explicitly provided at the call 218090075Sobriensites. 218190075Sobrien 218290075Sobrien@item STMT_EXPR 218390075SobrienThese nodes are used to represent GCC's statement-expression extension. 218490075SobrienThe statement-expression extension allows code like this: 2185132718Skan@smallexample 218690075Sobrienint f() @{ return (@{ int j; j = 3; j + 7; @}); @} 2187132718Skan@end smallexample 218890075SobrienIn other words, an sequence of statements may occur where a single 218990075Sobrienexpression would normally appear. The @code{STMT_EXPR} node represents 219090075Sobriensuch an expression. The @code{STMT_EXPR_STMT} gives the statement 219190075Sobriencontained in the expression; this is always a @code{COMPOUND_STMT}. The 219290075Sobrienvalue of the expression is the value of the last sub-statement in the 219390075Sobrien@code{COMPOUND_STMT}. More precisely, the value is the value computed 219490075Sobrienby the last @code{EXPR_STMT} in the outermost scope of the 219590075Sobrien@code{COMPOUND_STMT}. For example, in: 2196132718Skan@smallexample 219790075Sobrien(@{ 3; @}) 2198132718Skan@end smallexample 219990075Sobrienthe value is @code{3} while in: 2200132718Skan@smallexample 220190075Sobrien(@{ if (x) @{ 3; @} @}) 2202132718Skan@end smallexample 220390075Sobrien(represented by a nested @code{COMPOUND_STMT}), there is no value. If 220490075Sobrienthe @code{STMT_EXPR} does not yield a value, it's type will be 220590075Sobrien@code{void}. 220690075Sobrien 220790075Sobrien@item BIND_EXPR 220890075SobrienThese nodes represent local blocks. The first operand is a list of 220990075Sobrientemporary variables, connected via their @code{TREE_CHAIN} field. These 221090075Sobrienwill never require cleanups. The scope of these variables is just the 221190075Sobrienbody of the @code{BIND_EXPR}. The body of the @code{BIND_EXPR} is the 221290075Sobriensecond operand. 221390075Sobrien 221490075Sobrien@item LOOP_EXPR 221590075SobrienThese nodes represent ``infinite'' loops. The @code{LOOP_EXPR_BODY} 221690075Sobrienrepresents the body of the loop. It should be executed forever, unless 221790075Sobrienan @code{EXIT_EXPR} is encountered. 221890075Sobrien 221990075Sobrien@item EXIT_EXPR 222090075SobrienThese nodes represent conditional exits from the nearest enclosing 222190075Sobrien@code{LOOP_EXPR}. The single operand is the condition; if it is 222290075Sobriennonzero, then the loop should be exited. An @code{EXIT_EXPR} will only 222390075Sobrienappear within a @code{LOOP_EXPR}. 222490075Sobrien 222590075Sobrien@item CLEANUP_POINT_EXPR 222690075SobrienThese nodes represent full-expressions. The single operand is an 222790075Sobrienexpression to evaluate. Any destructor calls engendered by the creation 222890075Sobrienof temporaries during the evaluation of that expression should be 222990075Sobrienperformed immediately after the expression is evaluated. 223090075Sobrien 223190075Sobrien@item CONSTRUCTOR 223290075SobrienThese nodes represent the brace-enclosed initializers for a structure or 223390075Sobrienarray. The first operand is reserved for use by the back end. The 223490075Sobriensecond operand is a @code{TREE_LIST}. If the @code{TREE_TYPE} of the 223590075Sobrien@code{CONSTRUCTOR} is a @code{RECORD_TYPE} or @code{UNION_TYPE}, then 223690075Sobrienthe @code{TREE_PURPOSE} of each node in the @code{TREE_LIST} will be a 223790075Sobrien@code{FIELD_DECL} and the @code{TREE_VALUE} of each node will be the 2238132718Skanexpression used to initialize that field. 223990075Sobrien 224090075SobrienIf the @code{TREE_TYPE} of the @code{CONSTRUCTOR} is an 224190075Sobrien@code{ARRAY_TYPE}, then the @code{TREE_PURPOSE} of each element in the 224290075Sobrien@code{TREE_LIST} will be an @code{INTEGER_CST}. This constant indicates 224390075Sobrienwhich element of the array (indexed from zero) is being assigned to; 224490075Sobrienagain, the @code{TREE_VALUE} is the corresponding initializer. If the 224590075Sobrien@code{TREE_PURPOSE} is @code{NULL_TREE}, then the initializer is for the 224690075Sobriennext available array element. 224790075Sobrien 2248132718SkanIn the front end, you should not depend on the fields appearing in any 2249132718Skanparticular order. However, in the middle end, fields must appear in 2250132718Skandeclaration order. You should not assume that all fields will be 2251132718Skanrepresented. Unrepresented fields will be set to zero. 225290075Sobrien 225390075Sobrien@item COMPOUND_LITERAL_EXPR 225490075Sobrien@findex COMPOUND_LITERAL_EXPR_DECL_STMT 225590075Sobrien@findex COMPOUND_LITERAL_EXPR_DECL 225690075SobrienThese nodes represent ISO C99 compound literals. The 225790075Sobrien@code{COMPOUND_LITERAL_EXPR_DECL_STMT} is a @code{DECL_STMT} 225890075Sobriencontaining an anonymous @code{VAR_DECL} for 225990075Sobrienthe unnamed object represented by the compound literal; the 226090075Sobrien@code{DECL_INITIAL} of that @code{VAR_DECL} is a @code{CONSTRUCTOR} 226190075Sobrienrepresenting the brace-enclosed list of initializers in the compound 226290075Sobrienliteral. That anonymous @code{VAR_DECL} can also be accessed directly 226390075Sobrienby the @code{COMPOUND_LITERAL_EXPR_DECL} macro. 226490075Sobrien 226590075Sobrien@item SAVE_EXPR 226690075Sobrien 226790075SobrienA @code{SAVE_EXPR} represents an expression (possibly involving 226890075Sobrienside-effects) that is used more than once. The side-effects should 226990075Sobrienoccur only the first time the expression is evaluated. Subsequent uses 227090075Sobrienshould just reuse the computed value. The first operand to the 227190075Sobrien@code{SAVE_EXPR} is the expression to evaluate. The side-effects should 227290075Sobrienbe executed where the @code{SAVE_EXPR} is first encountered in a 227390075Sobriendepth-first preorder traversal of the expression tree. 227490075Sobrien 227590075Sobrien@item TARGET_EXPR 227690075SobrienA @code{TARGET_EXPR} represents a temporary object. The first operand 227790075Sobrienis a @code{VAR_DECL} for the temporary variable. The second operand is 227890075Sobrienthe initializer for the temporary. The initializer is evaluated, and 227990075Sobriencopied (bitwise) into the temporary. 228090075Sobrien 228190075SobrienOften, a @code{TARGET_EXPR} occurs on the right-hand side of an 228290075Sobrienassignment, or as the second operand to a comma-expression which is 228390075Sobrienitself the right-hand side of an assignment, etc. In this case, we say 228490075Sobrienthat the @code{TARGET_EXPR} is ``normal''; otherwise, we say it is 228590075Sobrien``orphaned''. For a normal @code{TARGET_EXPR} the temporary variable 228690075Sobrienshould be treated as an alias for the left-hand side of the assignment, 228790075Sobrienrather than as a new temporary variable. 228890075Sobrien 228990075SobrienThe third operand to the @code{TARGET_EXPR}, if present, is a 229090075Sobriencleanup-expression (i.e., destructor call) for the temporary. If this 229190075Sobrienexpression is orphaned, then this expression must be executed when the 229290075Sobrienstatement containing this expression is complete. These cleanups must 229390075Sobrienalways be executed in the order opposite to that in which they were 229490075Sobrienencountered. Note that if a temporary is created on one branch of a 229590075Sobrienconditional operator (i.e., in the second or third operand to a 229690075Sobrien@code{COND_EXPR}), the cleanup must be run only if that branch is 229790075Sobrienactually executed. 229890075Sobrien 229990075SobrienSee @code{STMT_IS_FULL_EXPR_P} for more information about running these 230090075Sobriencleanups. 230190075Sobrien 230290075Sobrien@item AGGR_INIT_EXPR 230390075SobrienAn @code{AGGR_INIT_EXPR} represents the initialization as the return 230490075Sobrienvalue of a function call, or as the result of a constructor. An 230590075Sobrien@code{AGGR_INIT_EXPR} will only appear as the second operand of a 230690075Sobrien@code{TARGET_EXPR}. The first operand to the @code{AGGR_INIT_EXPR} is 230790075Sobrienthe address of a function to call, just as in a @code{CALL_EXPR}. The 230890075Sobriensecond operand are the arguments to pass that function, as a 230990075Sobrien@code{TREE_LIST}, again in a manner similar to that of a 231090075Sobrien@code{CALL_EXPR}. The value of the expression is that returned by the 231190075Sobrienfunction. 231290075Sobrien 231390075SobrienIf @code{AGGR_INIT_VIA_CTOR_P} holds of the @code{AGGR_INIT_EXPR}, then 231490075Sobrienthe initialization is via a constructor call. The address of the third 231590075Sobrienoperand of the @code{AGGR_INIT_EXPR}, which is always a @code{VAR_DECL}, 231690075Sobrienis taken, and this value replaces the first argument in the argument 231790075Sobrienlist. In this case, the value of the expression is the @code{VAR_DECL} 231890075Sobriengiven by the third operand to the @code{AGGR_INIT_EXPR}; constructors do 231990075Sobriennot return a value. 232090075Sobrien 232190075Sobrien@item VTABLE_REF 232290075SobrienA @code{VTABLE_REF} indicates that the interior expression computes 232390075Sobriena value that is a vtable entry. It is used with @option{-fvtable-gc} 232490075Sobriento track the reference through to front end to the middle end, at 232590075Sobrienwhich point we transform this to a @code{REG_VTABLE_REF} note, which 232690075Sobriensurvives the balance of code generation. 232790075Sobrien 232890075SobrienThe first operand is the expression that computes the vtable reference. 232990075SobrienThe second operand is the @code{VAR_DECL} of the vtable. The third 233090075Sobrienoperand is an @code{INTEGER_CST} of the byte offset into the vtable. 233190075Sobrien 2332117395Skan@item VA_ARG_EXPR 2333117395SkanThis node is used to implement support for the C/C++ variable argument-list 2334117395Skanmechanism. It represents expressions like @code{va_arg (ap, type)}. 2335117395SkanIts @code{TREE_TYPE} yields the tree representation for @code{type} and 2336117395Skanits sole argument yields the representation for @code{ap}. 2337117395Skan 233890075Sobrien@end table 2339