c-tree.texi revision 96263
190075Sobrien@c Copyright (c) 1999, 2000, 2001 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 8790075Sobrien@code{TREE_CODE} macro. Many, many macros take a trees as input and 8890075Sobrienreturn trees as output. However, most macros require a certain kinds 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 10190075Sobrien@example 10290075Sobrienif (TEST_P (t) && !TEST_P (y)) 10390075Sobrien x = 1; 10490075Sobrien@end example 10590075Sobrien@noindent 10690075Sobrienand 10790075Sobrien@example 10890075Sobrienint i = (TEST_P (t) != 0); 10990075Sobrien@end example 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 11690075Sobrien@example 11790075Sobrienif (TEST_P (t) == 1) 11890075Sobrien@end example 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 12790075Sobrienfunctions are entirely in lower case. 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 55890075SobrienThis node is used to represent a data member; for example a 55990075Sobrienpointer-to-data-member is represented by a @code{POINTER_TYPE} whose 56090075Sobrien@code{TREE_TYPE} is an @code{OFFSET_TYPE}. For a data member @code{X::m} 56190075Sobrienthe @code{TYPE_OFFSET_BASETYPE} is @code{X} and the @code{TREE_TYPE} is 56290075Sobrienthe type of @code{m}. 56390075Sobrien 56490075Sobrien@item TYPENAME_TYPE 56590075SobrienUsed to represent a construct of the form @code{typename T::A}. The 56690075Sobrien@code{TYPE_CONTEXT} is @code{T}; the @code{TYPE_NAME} is an 56790075Sobrien@code{IDENTIFIER_NODE} for @code{A}. If the type is specified via a 56890075Sobrientemplate-id, then @code{TYPENAME_TYPE_FULLNAME} yields a 56990075Sobrien@code{TEMPLATE_ID_EXPR}. The @code{TREE_TYPE} is non-@code{NULL} if the 57090075Sobriennode is implicitly generated in support for the implicit typename 57190075Sobrienextension; in which case the @code{TREE_TYPE} is a type node for the 57290075Sobrienbase-class. 57390075Sobrien 57490075Sobrien@item TYPEOF_TYPE 57590075SobrienUsed to represent the @code{__typeof__} extension. The 57690075Sobrien@code{TYPE_FIELDS} is the expression the type of which is being 57790075Sobrienrepresented. 57890075Sobrien@end table 57990075Sobrien 58090075SobrienThere are variables whose values represent some of the basic types. 58190075SobrienThese include: 58290075Sobrien@table @code 58390075Sobrien@item void_type_node 58490075SobrienA node for @code{void}. 58590075Sobrien 58690075Sobrien@item integer_type_node 58790075SobrienA node for @code{int}. 58890075Sobrien 58990075Sobrien@item unsigned_type_node. 59090075SobrienA node for @code{unsigned int}. 59190075Sobrien 59290075Sobrien@item char_type_node. 59390075SobrienA node for @code{char}. 59490075Sobrien@end table 59590075Sobrien@noindent 59690075SobrienIt may sometimes be useful to compare one of these variables with a type 59790075Sobrienin hand, using @code{same_type_p}. 59890075Sobrien 59990075Sobrien@c --------------------------------------------------------------------- 60090075Sobrien@c Scopes 60190075Sobrien@c --------------------------------------------------------------------- 60290075Sobrien 60390075Sobrien@node Scopes 60490075Sobrien@section Scopes 60590075Sobrien@cindex namespace, class, scope 60690075Sobrien 60790075SobrienThe root of the entire intermediate representation is the variable 60890075Sobrien@code{global_namespace}. This is the namespace specified with @code{::} 60990075Sobrienin C++ source code. All other namespaces, types, variables, functions, 61090075Sobrienand so forth can be found starting with this namespace. 61190075Sobrien 61290075SobrienBesides namespaces, the other high-level scoping construct in C++ is the 61390075Sobrienclass. (Throughout this manual the term @dfn{class} is used to mean the 61490075Sobrientypes referred to in the ANSI/ISO C++ Standard as classes; these include 61590075Sobrientypes defined with the @code{class}, @code{struct}, and @code{union} 61690075Sobrienkeywords.) 61790075Sobrien 61890075Sobrien@menu 61990075Sobrien* Namespaces:: Member functions, types, etc. 62090075Sobrien* Classes:: Members, bases, friends, etc. 62190075Sobrien@end menu 62290075Sobrien 62390075Sobrien@c --------------------------------------------------------------------- 62490075Sobrien@c Namespaces 62590075Sobrien@c --------------------------------------------------------------------- 62690075Sobrien 62790075Sobrien@node Namespaces 62890075Sobrien@subsection Namespaces 62990075Sobrien@cindex namespace 63090075Sobrien@tindex NAMESPACE_DECL 63190075Sobrien 63290075SobrienA namespace is represented by a @code{NAMESPACE_DECL} node. 63390075Sobrien 63490075SobrienHowever, except for the fact that it is distinguished as the root of the 63590075Sobrienrepresentation, the global namespace is no different from any other 63690075Sobriennamespace. Thus, in what follows, we describe namespaces generally, 63790075Sobrienrather than the global namespace in particular. 63890075Sobrien 63990075SobrienThe following macros and functions can be used on a @code{NAMESPACE_DECL}: 64090075Sobrien 64190075Sobrien@ftable @code 64290075Sobrien@item DECL_NAME 64390075SobrienThis macro is used to obtain the @code{IDENTIFIER_NODE} corresponding to 64490075Sobrienthe unqualified name of the name of the namespace (@pxref{Identifiers}). 64590075SobrienThe name of the global namespace is @samp{::}, even though in C++ the 64690075Sobrienglobal namespace is unnamed. However, you should use comparison with 64790075Sobrien@code{global_namespace}, rather than @code{DECL_NAME} to determine 64890075Sobrienwhether or not a namespaces is the global one. An unnamed namespace 64990075Sobrienwill have a @code{DECL_NAME} equal to @code{anonymous_namespace_name}. 65090075SobrienWithin a single translation unit, all unnamed namespaces will have the 65190075Sobriensame name. 65290075Sobrien 65390075Sobrien@item DECL_CONTEXT 65490075SobrienThis macro returns the enclosing namespace. The @code{DECL_CONTEXT} for 65590075Sobrienthe @code{global_namespace} is @code{NULL_TREE}. 65690075Sobrien 65790075Sobrien@item DECL_NAMESPACE_ALIAS 65890075SobrienIf this declaration is for a namespace alias, then 65990075Sobrien@code{DECL_NAMESPACE_ALIAS} is the namespace for which this one is an 66090075Sobrienalias. 66190075Sobrien 66290075SobrienDo not attempt to use @code{cp_namespace_decls} for a namespace which is 66390075Sobrienan alias. Instead, follow @code{DECL_NAMESPACE_ALIAS} links until you 66490075Sobrienreach an ordinary, non-alias, namespace, and call 66590075Sobrien@code{cp_namespace_decls} there. 66690075Sobrien 66790075Sobrien@item DECL_NAMESPACE_STD_P 66890075SobrienThis predicate holds if the namespace is the special @code{::std} 66990075Sobriennamespace. 67090075Sobrien 67190075Sobrien@item cp_namespace_decls 67290075SobrienThis function will return the declarations contained in the namespace, 67390075Sobrienincluding types, overloaded functions, other namespaces, and so forth. 67490075SobrienIf there are no declarations, this function will return 67590075Sobrien@code{NULL_TREE}. The declarations are connected through their 67690075Sobrien@code{TREE_CHAIN} fields. 67790075Sobrien 67890075SobrienAlthough most entries on this list will be declarations, 67990075Sobrien@code{TREE_LIST} nodes may also appear. In this case, the 68090075Sobrien@code{TREE_VALUE} will be an @code{OVERLOAD}. The value of the 68190075Sobrien@code{TREE_PURPOSE} is unspecified; back ends should ignore this value. 68290075SobrienAs with the other kinds of declarations returned by 68390075Sobrien@code{cp_namespace_decls}, the @code{TREE_CHAIN} will point to the next 68490075Sobriendeclaration in this list. 68590075Sobrien 68690075SobrienFor more information on the kinds of declarations that can occur on this 68790075Sobrienlist, @xref{Declarations}. Some declarations will not appear on this 68890075Sobrienlist. In particular, no @code{FIELD_DECL}, @code{LABEL_DECL}, or 68990075Sobrien@code{PARM_DECL} nodes will appear here. 69090075Sobrien 69190075SobrienThis function cannot be used with namespaces that have 69290075Sobrien@code{DECL_NAMESPACE_ALIAS} set. 69390075Sobrien 69490075Sobrien@end ftable 69590075Sobrien 69690075Sobrien@c --------------------------------------------------------------------- 69790075Sobrien@c Classes 69890075Sobrien@c --------------------------------------------------------------------- 69990075Sobrien 70090075Sobrien@node Classes 70190075Sobrien@subsection Classes 70290075Sobrien@cindex class 70390075Sobrien@tindex RECORD_TYPE 70490075Sobrien@tindex UNION_TYPE 70590075Sobrien@findex CLASSTYPE_DECLARED_CLASS 70690075Sobrien@findex TYPE_BINFO 70790075Sobrien@findex BINFO_TYPE 70890075Sobrien@findex TREE_VIA_PUBLIC 70990075Sobrien@findex TREE_VIA_PROTECTED 71090075Sobrien@findex TREE_VIA_PRIVATE 71190075Sobrien@findex TYPE_FIELDS 71290075Sobrien@findex TYPE_VFIELD 71390075Sobrien@findex TYPE_METHODS 71490075Sobrien 71590075SobrienA class type is represented by either a @code{RECORD_TYPE} or a 71690075Sobrien@code{UNION_TYPE}. A class declared with the @code{union} tag is 71790075Sobrienrepresented by a @code{UNION_TYPE}, while classes declared with either 71890075Sobrienthe @code{struct} or the @code{class} tag are represented by 71990075Sobrien@code{RECORD_TYPE}s. You can use the @code{CLASSTYPE_DECLARED_CLASS} 72090075Sobrienmacro to discern whether or not a particular type is a @code{class} as 72190075Sobrienopposed to a @code{struct}. This macro will be true only for classes 72290075Sobriendeclared with the @code{class} tag. 72390075Sobrien 72490075SobrienAlmost all non-function members are available on the @code{TYPE_FIELDS} 72590075Sobrienlist. Given one member, the next can be found by following the 72690075Sobrien@code{TREE_CHAIN}. You should not depend in any way on the order in 72790075Sobrienwhich fields appear on this list. All nodes on this list will be 72890075Sobrien@samp{DECL} nodes. A @code{FIELD_DECL} is used to represent a non-static 72990075Sobriendata member, a @code{VAR_DECL} is used to represent a static data 73090075Sobrienmember, and a @code{TYPE_DECL} is used to represent a type. Note that 73190075Sobrienthe @code{CONST_DECL} for an enumeration constant will appear on this 73290075Sobrienlist, if the enumeration type was declared in the class. (Of course, 73390075Sobrienthe @code{TYPE_DECL} for the enumeration type will appear here as well.) 73490075SobrienThere are no entries for base classes on this list. In particular, 73590075Sobrienthere is no @code{FIELD_DECL} for the ``base-class portion'' of an 73690075Sobrienobject. 73790075Sobrien 73890075SobrienThe @code{TYPE_VFIELD} is a compiler-generated field used to point to 73990075Sobrienvirtual function tables. It may or may not appear on the 74090075Sobrien@code{TYPE_FIELDS} list. However, back ends should handle the 74190075Sobrien@code{TYPE_VFIELD} just like all the entries on the @code{TYPE_FIELDS} 74290075Sobrienlist. 74390075Sobrien 74490075SobrienThe function members are available on the @code{TYPE_METHODS} list. 74590075SobrienAgain, subsequent members are found by following the @code{TREE_CHAIN} 74690075Sobrienfield. If a function is overloaded, each of the overloaded functions 74790075Sobrienappears; no @code{OVERLOAD} nodes appear on the @code{TYPE_METHODS} 74890075Sobrienlist. Implicitly declared functions (including default constructors, 74990075Sobriencopy constructors, assignment operators, and destructors) will appear on 75090075Sobrienthis list as well. 75190075Sobrien 75290075SobrienEvery class has an associated @dfn{binfo}, which can be obtained with 75390075Sobrien@code{TYPE_BINFO}. Binfos are used to represent base-classes. The 75490075Sobrienbinfo given by @code{TYPE_BINFO} is the degenerate case, whereby every 75590075Sobrienclass is considered to be its own base-class. The base classes for a 75690075Sobrienparticular binfo can be obtained with @code{BINFO_BASETYPES}. These 75790075Sobrienbase-classes are themselves binfos. The class type associated with a 75890075Sobrienbinfo is given by @code{BINFO_TYPE}. It is always the case that 75990075Sobrien@code{BINFO_TYPE (TYPE_BINFO (x))} is the same type as @code{x}, up to 76090075Sobrienqualifiers. However, it is not always the case that @code{TYPE_BINFO 76190075Sobrien(BINFO_TYPE (y))} is always the same binfo as @code{y}. The reason is 76290075Sobrienthat if @code{y} is a binfo representing a base-class @code{B} of a 76396263Sobrienderived class @code{D}, then @code{BINFO_TYPE (y)} will be @code{B}, 76496263Sobrienand @code{TYPE_BINFO (BINFO_TYPE (y))} will be @code{B} as its own 76590075Sobrienbase-class, rather than as a base-class of @code{D}. 76690075Sobrien 76790075SobrienThe @code{BINFO_BASETYPES} is a @code{TREE_VEC} (@pxref{Containers}). 76890075SobrienBase types appear in left-to-right order in this vector. You can tell 76990075Sobrienwhether or @code{public}, @code{protected}, or @code{private} 77090075Sobrieninheritance was used by using the @code{TREE_VIA_PUBLIC}, 77190075Sobrien@code{TREE_VIA_PROTECTED}, and @code{TREE_VIA_PRIVATE} macros. Each of 77290075Sobrienthese macros takes a @code{BINFO} and is true if and only if the 77390075Sobrienindicated kind of inheritance was used. If @code{TREE_VIA_VIRTUAL} 77490075Sobrienholds of a binfo, then its @code{BINFO_TYPE} was inherited from 77590075Sobrienvirtually. 77690075Sobrien 77790075SobrienThe following macros can be used on a tree node representing a class-type. 77890075Sobrien 77990075Sobrien@ftable @code 78090075Sobrien@item LOCAL_CLASS_P 78190075SobrienThis predicate holds if the class is local class @emph{i.e.} declared 78290075Sobrieninside a function body. 78390075Sobrien 78490075Sobrien@item TYPE_POLYMORPHIC_P 78590075SobrienThis predicate holds if the class has at least one virtual function 78690075Sobrien(declared or inherited). 78790075Sobrien 78890075Sobrien@item TYPE_HAS_DEFAULT_CONSTRUCTOR 78990075SobrienThis predicate holds whenever its argument represents a class-type with 79090075Sobriendefault constructor. 79190075Sobrien 79290075Sobrien@item CLASSTYPE_HAS_MUTABLE 79390075Sobrien@item TYPE_HAS_MUTABLE_P 79490075SobrienThese predicates hold for a class-type having a mutable data member. 79590075Sobrien 79690075Sobrien@item CLASSTYPE_NON_POD_P 79790075SobrienThis predicate holds only for class-types that are not PODs. 79890075Sobrien 79990075Sobrien@item TYPE_HAS_NEW_OPERATOR 80090075SobrienThis predicate holds for a class-type that defines 80190075Sobrien@code{operator new}. 80290075Sobrien 80390075Sobrien@item TYPE_HAS_ARRAY_NEW_OPERATOR 80490075SobrienThis predicate holds for a class-type for which 80590075Sobrien@code{operator new[]} is defined. 80690075Sobrien 80790075Sobrien@item TYPE_OVERLOADS_CALL_EXPR 80890075SobrienThis predicate holds for class-type for which the function call 80990075Sobrien@code{operator()} is overloaded. 81090075Sobrien 81190075Sobrien@item TYPE_OVERLOADS_ARRAY_REF 81290075SobrienThis predicate holds for a class-type that overloads 81390075Sobrien@code{operator[]} 81490075Sobrien 81590075Sobrien@item TYPE_OVERLOADS_ARROW 81690075SobrienThis predicate holds for a class-type for which @code{operator->} is 81790075Sobrienoverloaded. 81890075Sobrien 81990075Sobrien@end ftable 82090075Sobrien 82190075Sobrien@c --------------------------------------------------------------------- 82290075Sobrien@c Declarations 82390075Sobrien@c --------------------------------------------------------------------- 82490075Sobrien 82590075Sobrien@node Declarations 82690075Sobrien@section Declarations 82790075Sobrien@cindex declaration 82890075Sobrien@cindex variable 82990075Sobrien@cindex type declaration 83090075Sobrien@tindex LABEL_DECL 83190075Sobrien@tindex CONST_DECL 83290075Sobrien@tindex TYPE_DECL 83390075Sobrien@tindex VAR_DECL 83490075Sobrien@tindex PARM_DECL 83590075Sobrien@tindex FIELD_DECL 83690075Sobrien@tindex NAMESPACE_DECL 83790075Sobrien@tindex RESULT_DECL 83890075Sobrien@tindex TEMPLATE_DECL 83990075Sobrien@tindex THUNK_DECL 84090075Sobrien@tindex USING_DECL 84190075Sobrien@findex THUNK_DELTA 84290075Sobrien@findex DECL_INITIAL 84390075Sobrien@findex DECL_SIZE 84490075Sobrien@findex DECL_ALIGN 84590075Sobrien@findex DECL_EXTERNAL 84690075Sobrien 84790075SobrienThis section covers the various kinds of declarations that appear in the 84890075Sobrieninternal representation, except for declarations of functions 84990075Sobrien(represented by @code{FUNCTION_DECL} nodes), which are described in 85090075Sobrien@ref{Functions}. 85190075Sobrien 85290075SobrienSome macros can be used with any kind of declaration. These include: 85390075Sobrien@ftable @code 85490075Sobrien@item DECL_NAME 85590075SobrienThis macro returns an @code{IDENTIFIER_NODE} giving the name of the 85690075Sobrienentity. 85790075Sobrien 85890075Sobrien@item TREE_TYPE 85990075SobrienThis macro returns the type of the entity declared. 86090075Sobrien 86190075Sobrien@item DECL_SOURCE_FILE 86290075SobrienThis macro returns the name of the file in which the entity was 86390075Sobriendeclared, as a @code{char*}. For an entity declared implicitly by the 86490075Sobriencompiler (like @code{__builtin_memcpy}), this will be the string 86590075Sobrien@code{"<internal>"}. 86690075Sobrien 86790075Sobrien@item DECL_SOURCE_LINE 86890075SobrienThis macro returns the line number at which the entity was declared, as 86990075Sobrienan @code{int}. 87090075Sobrien 87190075Sobrien@item DECL_ARTIFICIAL 87290075SobrienThis predicate holds if the declaration was implicitly generated by the 87390075Sobriencompiler. For example, this predicate will hold of an implicitly 87490075Sobriendeclared member function, or of the @code{TYPE_DECL} implicitly 87590075Sobriengenerated for a class type. Recall that in C++ code like: 87690075Sobrien@example 87790075Sobrienstruct S @{@}; 87890075Sobrien@end example 87990075Sobrien@noindent 88090075Sobrienis roughly equivalent to C code like: 88190075Sobrien@example 88290075Sobrienstruct S @{@}; 88390075Sobrientypedef struct S S; 88490075Sobrien@end example 88590075SobrienThe implicitly generated @code{typedef} declaration is represented by a 88690075Sobrien@code{TYPE_DECL} for which @code{DECL_ARTIFICIAL} holds. 88790075Sobrien 88890075Sobrien@item DECL_NAMESPACE_SCOPE_P 88990075SobrienThis predicate holds if the entity was declared at a namespace scope. 89090075Sobrien 89190075Sobrien@item DECL_CLASS_SCOPE_P 89290075SobrienThis predicate holds if the entity was declared at a class scope. 89390075Sobrien 89490075Sobrien@item DECL_FUNCTION_SCOPE_P 89590075SobrienThis predicate holds if the entity was declared inside a function 89690075Sobrienbody. 89790075Sobrien 89890075Sobrien@end ftable 89990075Sobrien 90090075SobrienThe various kinds of declarations include: 90190075Sobrien@table @code 90290075Sobrien@item LABEL_DECL 90390075SobrienThese nodes are used to represent labels in function bodies. For more 90490075Sobrieninformation, see @ref{Functions}. These nodes only appear in block 90590075Sobrienscopes. 90690075Sobrien 90790075Sobrien@item CONST_DECL 90890075SobrienThese nodes are used to represent enumeration constants. The value of 90990075Sobrienthe constant is given by @code{DECL_INITIAL} which will be an 91090075Sobrien@code{INTEGER_CST} with the same type as the @code{TREE_TYPE} of the 91190075Sobrien@code{CONST_DECL}, i.e., an @code{ENUMERAL_TYPE}. 91290075Sobrien 91390075Sobrien@item RESULT_DECL 91490075SobrienThese nodes represent the value returned by a function. When a value is 91590075Sobrienassigned to a @code{RESULT_DECL}, that indicates that the value should 91690075Sobrienbe returned, via bitwise copy, by the function. You can use 91790075Sobrien@code{DECL_SIZE} and @code{DECL_ALIGN} on a @code{RESULT_DECL}, just as 91890075Sobrienwith a @code{VAR_DECL}. 91990075Sobrien 92090075Sobrien@item TYPE_DECL 92190075SobrienThese nodes represent @code{typedef} declarations. The @code{TREE_TYPE} 92290075Sobrienis the type declared to have the name given by @code{DECL_NAME}. In 92390075Sobriensome cases, there is no associated name. 92490075Sobrien 92590075Sobrien@item VAR_DECL 92690075SobrienThese nodes represent variables with namespace or block scope, as well 92790075Sobrienas static data members. The @code{DECL_SIZE} and @code{DECL_ALIGN} are 92890075Sobrienanalogous to @code{TYPE_SIZE} and @code{TYPE_ALIGN}. For a declaration, 92990075Sobrienyou should always use the @code{DECL_SIZE} and @code{DECL_ALIGN} rather 93090075Sobrienthan the @code{TYPE_SIZE} and @code{TYPE_ALIGN} given by the 93190075Sobrien@code{TREE_TYPE}, since special attributes may have been applied to the 93290075Sobrienvariable to give it a particular size and alignment. You may use the 93390075Sobrienpredicates @code{DECL_THIS_STATIC} or @code{DECL_THIS_EXTERN} to test 93490075Sobrienwhether the storage class specifiers @code{static} or @code{extern} were 93590075Sobrienused to declare a variable. 93690075Sobrien 93790075SobrienIf this variable is initialized (but does not require a constructor), 93890075Sobrienthe @code{DECL_INITIAL} will be an expression for the initializer. The 93990075Sobrieninitializer should be evaluated, and a bitwise copy into the variable 94090075Sobrienperformed. If the @code{DECL_INITIAL} is the @code{error_mark_node}, 94190075Sobrienthere is an initializer, but it is given by an explicit statement later 94290075Sobrienin the code; no bitwise copy is required. 94390075Sobrien 94490075SobrienGCC provides an extension that allows either automatic variables, or 94590075Sobrienglobal variables, to be placed in particular registers. This extension 94690075Sobrienis being used for a particular @code{VAR_DECL} if @code{DECL_REGISTER} 94790075Sobrienholds for the @code{VAR_DECL}, and if @code{DECL_ASSEMBLER_NAME} is not 94890075Sobrienequal to @code{DECL_NAME}. In that case, @code{DECL_ASSEMBLER_NAME} is 94990075Sobrienthe name of the register into which the variable will be placed. 95090075Sobrien 95190075Sobrien@item PARM_DECL 95290075SobrienUsed to represent a parameter to a function. Treat these nodes 95390075Sobriensimilarly to @code{VAR_DECL} nodes. These nodes only appear in the 95490075Sobrien@code{DECL_ARGUMENTS} for a @code{FUNCTION_DECL}. 95590075Sobrien 95690075SobrienThe @code{DECL_ARG_TYPE} for a @code{PARM_DECL} is the type that will 95790075Sobrienactually be used when a value is passed to this function. It may be a 95890075Sobrienwider type than the @code{TREE_TYPE} of the parameter; for example, the 95990075Sobrienordinary type might be @code{short} while the @code{DECL_ARG_TYPE} is 96090075Sobrien@code{int}. 96190075Sobrien 96290075Sobrien@item FIELD_DECL 96390075SobrienThese nodes represent non-static data members. The @code{DECL_SIZE} and 96490075Sobrien@code{DECL_ALIGN} behave as for @code{VAR_DECL} nodes. The 96590075Sobrien@code{DECL_FIELD_BITPOS} gives the first bit used for this field, as an 96690075Sobrien@code{INTEGER_CST}. These values are indexed from zero, where zero 96790075Sobrienindicates the first bit in the object. 96890075Sobrien 96990075SobrienIf @code{DECL_C_BIT_FIELD} holds, this field is a bit-field. 97090075Sobrien 97190075Sobrien@item NAMESPACE_DECL 97290075Sobrien@xref{Namespaces}. 97390075Sobrien 97490075Sobrien@item TEMPLATE_DECL 97590075Sobrien 97690075SobrienThese nodes are used to represent class, function, and variable (static 97790075Sobriendata member) templates. The @code{DECL_TEMPLATE_SPECIALIZATIONS} are a 97890075Sobrien@code{TREE_LIST}. The @code{TREE_VALUE} of each node in the list is a 97990075Sobrien@code{TEMPLATE_DECL}s or @code{FUNCTION_DECL}s representing 98090075Sobrienspecializations (including instantiations) of this template. Back ends 98190075Sobriencan safely ignore @code{TEMPLATE_DECL}s, but should examine 98290075Sobrien@code{FUNCTION_DECL} nodes on the specializations list just as they 98390075Sobrienwould ordinary @code{FUNCTION_DECL} nodes. 98490075Sobrien 98590075SobrienFor a class template, the @code{DECL_TEMPLATE_INSTANTIATIONS} list 98690075Sobriencontains the instantiations. The @code{TREE_VALUE} of each node is an 98790075Sobrieninstantiation of the class. The @code{DECL_TEMPLATE_SPECIALIZATIONS} 98890075Sobriencontains partial specializations of the class. 98990075Sobrien 99090075Sobrien@item USING_DECL 99190075Sobrien 99290075SobrienBack ends can safely ignore these nodes. 99390075Sobrien 99490075Sobrien@end table 99590075Sobrien 99690075Sobrien@c --------------------------------------------------------------------- 99790075Sobrien@c Functions 99890075Sobrien@c --------------------------------------------------------------------- 99990075Sobrien 100090075Sobrien@node Functions 100190075Sobrien@section Functions 100290075Sobrien@cindex function 100390075Sobrien@tindex FUNCTION_DECL 100490075Sobrien@tindex OVERLOAD 100590075Sobrien@findex OVL_CURRENT 100690075Sobrien@findex OVL_NEXT 100790075Sobrien 100890075SobrienA function is represented by a @code{FUNCTION_DECL} node. A set of 100990075Sobrienoverloaded functions is sometimes represented by a @code{OVERLOAD} node. 101090075Sobrien 101190075SobrienAn @code{OVERLOAD} node is not a declaration, so none of the 101290075Sobrien@samp{DECL_} macros should be used on an @code{OVERLOAD}. An 101390075Sobrien@code{OVERLOAD} node is similar to a @code{TREE_LIST}. Use 101490075Sobrien@code{OVL_CURRENT} to get the function associated with an 101590075Sobrien@code{OVERLOAD} node; use @code{OVL_NEXT} to get the next 101690075Sobrien@code{OVERLOAD} node in the list of overloaded functions. The macros 101790075Sobrien@code{OVL_CURRENT} and @code{OVL_NEXT} are actually polymorphic; you can 101890075Sobrienuse them to work with @code{FUNCTION_DECL} nodes as well as with 101990075Sobrienoverloads. In the case of a @code{FUNCTION_DECL}, @code{OVL_CURRENT} 102090075Sobrienwill always return the function itself, and @code{OVL_NEXT} will always 102190075Sobrienbe @code{NULL_TREE}. 102290075Sobrien 102390075SobrienTo determine the scope of a function, you can use the 102490075Sobrien@code{DECL_REAL_CONTEXT} macro. This macro will return the class 102590075Sobrien(either a @code{RECORD_TYPE} or a @code{UNION_TYPE}) or namespace (a 102690075Sobrien@code{NAMESPACE_DECL}) of which the function is a member. For a virtual 102790075Sobrienfunction, this macro returns the class in which the function was 102890075Sobrienactually defined, not the base class in which the virtual declaration 102990075Sobrienoccurred. If a friend function is defined in a class scope, the 103090075Sobrien@code{DECL_CLASS_CONTEXT} macro can be used to determine the class in 103190075Sobrienwhich it was defined. For example, in 103290075Sobrien@example 103390075Sobrienclass C @{ friend void f() @{@} @}; 103490075Sobrien@end example 103590075Sobrienthe @code{DECL_REAL_CONTEXT} for @code{f} will be the 103690075Sobrien@code{global_namespace}, but the @code{DECL_CLASS_CONTEXT} will be the 103790075Sobrien@code{RECORD_TYPE} for @code{C}. 103890075Sobrien 103990075SobrienThe @code{DECL_REAL_CONTEXT} and @code{DECL_CLASS_CONTEXT} are not 104090075Sobrienavailable in C; instead you should simply use @code{DECL_CONTEXT}. In C, 104190075Sobrienthe @code{DECL_CONTEXT} for a function maybe another function. This 104290075Sobrienrepresentation indicates that the GNU nested function extension is in 104390075Sobrienuse. For details on the semantics of nested functions, see the GCC 104490075SobrienManual. The nested function can refer to local variables in its 104590075Sobriencontaining function. Such references are not explicitly marked in the 104690075Sobrientree structure; back ends must look at the @code{DECL_CONTEXT} for the 104790075Sobrienreferenced @code{VAR_DECL}. If the @code{DECL_CONTEXT} for the 104890075Sobrienreferenced @code{VAR_DECL} is not the same as the function currently 104990075Sobrienbeing processed, and neither @code{DECL_EXTERNAL} nor @code{DECL_STATIC} 105090075Sobrienhold, then the reference is to a local variable in a containing 105190075Sobrienfunction, and the back end must take appropriate action. 105290075Sobrien 105390075Sobrien@menu 105490075Sobrien* Function Basics:: Function names, linkage, and so forth. 105590075Sobrien* Function Bodies:: The statements that make up a function body. 105690075Sobrien@end menu 105790075Sobrien 105890075Sobrien@c --------------------------------------------------------------------- 105990075Sobrien@c Function Basics 106090075Sobrien@c --------------------------------------------------------------------- 106190075Sobrien 106290075Sobrien@node Function Basics 106390075Sobrien@subsection Function Basics 106490075Sobrien@cindex constructor 106590075Sobrien@cindex destructor 106690075Sobrien@cindex copy constructor 106790075Sobrien@cindex assignment operator 106890075Sobrien@cindex linkage 106990075Sobrien@findex DECL_NAME 107090075Sobrien@findex DECL_ASSEMBLER_NAME 107190075Sobrien@findex TREE_PUBLIC 107290075Sobrien@findex DECL_LINKONCE_P 107390075Sobrien@findex DECL_FUNCTION_MEMBER_P 107490075Sobrien@findex DECL_CONSTRUCTOR_P 107590075Sobrien@findex DECL_DESTRUCTOR_P 107690075Sobrien@findex DECL_OVERLOADED_OPERATOR_P 107790075Sobrien@findex DECL_CONV_FN_P 107890075Sobrien@findex DECL_ARTIFICIAL 107990075Sobrien@findex DECL_GLOBAL_CTOR_P 108090075Sobrien@findex DECL_GLOBAL_DTOR_P 108190075Sobrien@findex GLOBAL_INIT_PRIORITY 108290075Sobrien 108390075SobrienThe following macros and functions can be used on a @code{FUNCTION_DECL}: 108490075Sobrien@ftable @code 108590075Sobrien@item DECL_MAIN_P 108690075SobrienThis predicate holds for a function that is the program entry point 108790075Sobrien@code{::code}. 108890075Sobrien 108990075Sobrien@item DECL_NAME 109090075SobrienThis macro returns the unqualified name of the function, as an 109190075Sobrien@code{IDENTIFIER_NODE}. For an instantiation of a function template, 109290075Sobrienthe @code{DECL_NAME} is the unqualified name of the template, not 109390075Sobriensomething like @code{f<int>}. The value of @code{DECL_NAME} is 109490075Sobrienundefined when used on a constructor, destructor, overloaded operator, 109590075Sobrienor type-conversion operator, or any function that is implicitly 109690075Sobriengenerated by the compiler. See below for macros that can be used to 109790075Sobriendistinguish these cases. 109890075Sobrien 109990075Sobrien@item DECL_ASSEMBLER_NAME 110090075SobrienThis macro returns the mangled name of the function, also an 110190075Sobrien@code{IDENTIFIER_NODE}. This name does not contain leading underscores 110290075Sobrienon systems that prefix all identifiers with underscores. The mangled 110390075Sobrienname is computed in the same way on all platforms; if special processing 110490075Sobrienis required to deal with the object file format used on a particular 110590075Sobrienplatform, it is the responsibility of the back end to perform those 110690075Sobrienmodifications. (Of course, the back end should not modify 110790075Sobrien@code{DECL_ASSEMBLER_NAME} itself.) 110890075Sobrien 110990075Sobrien@item DECL_EXTERNAL 111090075SobrienThis predicate holds if the function is undefined. 111190075Sobrien 111290075Sobrien@item TREE_PUBLIC 111390075SobrienThis predicate holds if the function has external linkage. 111490075Sobrien 111590075Sobrien@item DECL_LOCAL_FUNCTION_P 111690075SobrienThis predicate holds if the function was declared at block scope, even 111790075Sobrienthough it has a global scope. 111890075Sobrien 111990075Sobrien@item DECL_ANTICIPATED 112090075SobrienThis predicate holds if the function is a built-in function but its 112190075Sobrienprototype is not yet explicitly declared. 112290075Sobrien 112390075Sobrien@item DECL_EXTERN_C_FUNCTION_P 112490075SobrienThis predicate holds if the function is declared as an 112590075Sobrien`@code{extern "C"}' function. 112690075Sobrien 112790075Sobrien@item DECL_LINKONCE_P 112890075SobrienThis macro holds if multiple copies of this function may be emitted in 112990075Sobrienvarious translation units. It is the responsibility of the linker to 113090075Sobrienmerge the various copies. Template instantiations are the most common 113190075Sobrienexample of functions for which @code{DECL_LINKONCE_P} holds; G++ 113290075Sobrieninstantiates needed templates in all translation units which require them, 113390075Sobrienand then relies on the linker to remove duplicate instantiations. 113490075Sobrien 113590075SobrienFIXME: This macro is not yet implemented. 113690075Sobrien 113790075Sobrien@item DECL_FUNCTION_MEMBER_P 113890075SobrienThis macro holds if the function is a member of a class, rather than a 113990075Sobrienmember of a namespace. 114090075Sobrien 114190075Sobrien@item DECL_STATIC_FUNCTION_P 114290075SobrienThis predicate holds if the function a static member function. 114390075Sobrien 114490075Sobrien@item DECL_NONSTATIC_MEMBER_FUNCTION_P 114590075SobrienThis macro holds for a non-static member function. 114690075Sobrien 114790075Sobrien@item DECL_CONST_MEMFUNC_P 114890075SobrienThis predicate holds for a @code{const}-member function. 114990075Sobrien 115090075Sobrien@item DECL_VOLATILE_MEMFUNC_P 115190075SobrienThis predicate holds for a @code{volatile}-member function. 115290075Sobrien 115390075Sobrien@item DECL_CONSTRUCTOR_P 115490075SobrienThis macro holds if the function is a constructor. 115590075Sobrien 115690075Sobrien@item DECL_NONCONVERTING_P 115790075SobrienThis predicate holds if the constructor is a non-converting constructor. 115890075Sobrien 115990075Sobrien@item DECL_COMPLETE_CONSTRUCTOR_P 116090075SobrienThis predicate holds for a function which is a constructor for an object 116190075Sobrienof a complete type. 116290075Sobrien 116390075Sobrien@item DECL_BASE_CONSTRUCTOR_P 116490075SobrienThis predicate holds for a function which is a constructor for a base 116590075Sobrienclass sub-object. 116690075Sobrien 116790075Sobrien@item DECL_COPY_CONSTRUCTOR_P 116890075SobrienThis predicate holds for a function which is a copy-constructor. 116990075Sobrien 117090075Sobrien@item DECL_DESTRUCTOR_P 117190075SobrienThis macro holds if the function is a destructor. 117290075Sobrien 117390075Sobrien@item DECL_COMPLETE_DESTRUCTOR_P 117490075SobrienThis predicate holds if the function is the destructor for an object a 117590075Sobriencomplete type. 117690075Sobrien 117790075Sobrien@item DECL_OVERLOADED_OPERATOR_P 117890075SobrienThis macro holds if the function is an overloaded operator. 117990075Sobrien 118090075Sobrien@item DECL_CONV_FN_P 118190075SobrienThis macro holds if the function is a type-conversion operator. 118290075Sobrien 118390075Sobrien@item DECL_GLOBAL_CTOR_P 118490075SobrienThis predicate holds if the function is a file-scope initialization 118590075Sobrienfunction. 118690075Sobrien 118790075Sobrien@item DECL_GLOBAL_DTOR_P 118890075SobrienThis predicate holds if the function is a file-scope finalization 118990075Sobrienfunction. 119090075Sobrien 119190075Sobrien@item DECL_THUNK_P 119290075SobrienThis predicate holds if the function is a thunk. 119390075Sobrien 119490075SobrienThese functions represent stub code that adjusts the @code{this} pointer 119590075Sobrienand then jumps to another function. When the jumped-to function 119690075Sobrienreturns, control is transferred directly to the caller, without 119790075Sobrienreturning to the thunk. The first parameter to the thunk is always the 119890075Sobrien@code{this} pointer; the thunk should add @code{THUNK_DELTA} to this 119990075Sobrienvalue. (The @code{THUNK_DELTA} is an @code{int}, not an 120090075Sobrien@code{INTEGER_CST}.) 120190075Sobrien 120290075SobrienThen, if @code{THUNK_VCALL_OFFSET} (an @code{INTEGER_CST}) is nonzero 120390075Sobrienthe adjusted @code{this} pointer must be adjusted again. The complete 120490075Sobriencalculation is given by the following pseudo-code: 120590075Sobrien 120690075Sobrien@example 120790075Sobrienthis += THUNK_DELTA 120890075Sobrienif (THUNK_VCALL_OFFSET) 120990075Sobrien this += (*((ptrdiff_t **) this))[THUNK_VCALL_OFFSET] 121090075Sobrien@end example 121190075Sobrien 121290075SobrienFinally, the thunk should jump to the location given 121390075Sobrienby @code{DECL_INITIAL}; this will always be an expression for the 121490075Sobrienaddress of a function. 121590075Sobrien 121690075Sobrien@item DECL_NON_THUNK_FUNCTION_P 121790075SobrienThis predicate holds if the function is @emph{not} a thunk function. 121890075Sobrien 121990075Sobrien@item GLOBAL_INIT_PRIORITY 122090075SobrienIf either @code{DECL_GLOBAL_CTOR_P} or @code{DECL_GLOBAL_DTOR_P} holds, 122190075Sobrienthen this gives the initialization priority for the function. The 122290075Sobrienlinker will arrange that all functions for which 122390075Sobrien@code{DECL_GLOBAL_CTOR_P} holds are run in increasing order of priority 122490075Sobrienbefore @code{main} is called. When the program exits, all functions for 122590075Sobrienwhich @code{DECL_GLOBAL_DTOR_P} holds are run in the reverse order. 122690075Sobrien 122790075Sobrien@item DECL_ARTIFICIAL 122890075SobrienThis macro holds if the function was implicitly generated by the 122990075Sobriencompiler, rather than explicitly declared. In addition to implicitly 123090075Sobriengenerated class member functions, this macro holds for the special 123190075Sobrienfunctions created to implement static initialization and destruction, to 123290075Sobriencompute run-time type information, and so forth. 123390075Sobrien 123490075Sobrien@item DECL_ARGUMENTS 123590075SobrienThis macro returns the @code{PARM_DECL} for the first argument to the 123690075Sobrienfunction. Subsequent @code{PARM_DECL} nodes can be obtained by 123790075Sobrienfollowing the @code{TREE_CHAIN} links. 123890075Sobrien 123990075Sobrien@item DECL_RESULT 124090075SobrienThis macro returns the @code{RESULT_DECL} for the function. 124190075Sobrien 124290075Sobrien@item TREE_TYPE 124390075SobrienThis macro returns the @code{FUNCTION_TYPE} or @code{METHOD_TYPE} for 124490075Sobrienthe function. 124590075Sobrien 124690075Sobrien@item TYPE_RAISES_EXCEPTIONS 124790075SobrienThis macro returns the list of exceptions that a (member-)function can 124890075Sobrienraise. The returned list, if non @code{NULL}, is comprised of nodes 124990075Sobrienwhose @code{TREE_VALUE} represents a type. 125090075Sobrien 125190075Sobrien@item TYPE_NOTHROW_P 125290075SobrienThis predicate holds when the exception-specification of its arguments 125390075Sobrienif of the form `@code{()}'. 125490075Sobrien 125590075Sobrien@item DECL_ARRAY_DELETE_OPERATOR_P 125690075SobrienThis predicate holds if the function an overloaded 125790075Sobrien@code{operator delete[]}. 125890075Sobrien 125990075Sobrien@end ftable 126090075Sobrien 126190075Sobrien@c --------------------------------------------------------------------- 126290075Sobrien@c Function Bodies 126390075Sobrien@c --------------------------------------------------------------------- 126490075Sobrien 126590075Sobrien@node Function Bodies 126690075Sobrien@subsection Function Bodies 126790075Sobrien@cindex function body 126890075Sobrien@cindex statements 126990075Sobrien@tindex ASM_STMT 127090075Sobrien@findex ASM_STRING 127190075Sobrien@findex ASM_CV_QUAL 127290075Sobrien@findex ASM_INPUTS 127390075Sobrien@findex ASM_OUTPUTS 127490075Sobrien@findex ASM_CLOBBERS 127590075Sobrien@tindex BREAK_STMT 127690075Sobrien@tindex CLEANUP_STMT 127790075Sobrien@findex CLEANUP_DECL 127890075Sobrien@findex CLEANUP_EXPR 127990075Sobrien@tindex COMPOUND_STMT 128090075Sobrien@findex COMPOUND_BODY 128190075Sobrien@tindex CONTINUE_STMT 128290075Sobrien@tindex DECL_STMT 128390075Sobrien@findex DECL_STMT_DECL 128490075Sobrien@tindex DO_STMT 128590075Sobrien@findex DO_BODY 128690075Sobrien@findex DO_COND 128790075Sobrien@tindex EMPTY_CLASS_EXPR 128890075Sobrien@tindex EXPR_STMT 128990075Sobrien@findex EXPR_STMT_EXPR 129090075Sobrien@tindex FOR_STMT 129190075Sobrien@findex FOR_INIT_STMT 129290075Sobrien@findex FOR_COND 129390075Sobrien@findex FOR_EXPR 129490075Sobrien@findex FOR_BODY 129590075Sobrien@tindex FILE_STMT 129690075Sobrien@findex FILE_STMT_FILENAME 129790075Sobrien@tindex GOTO_STMT 129890075Sobrien@findex GOTO_DESTINATION 129990075Sobrien@findex GOTO_FAKE_P 130090075Sobrien@tindex HANDLER 130190075Sobrien@tindex IF_STMT 130290075Sobrien@findex IF_COND 130390075Sobrien@findex THEN_CLAUSE 130490075Sobrien@findex ELSE_CLAUSE 130590075Sobrien@tindex LABEL_STMT 130690075Sobrien@tindex LABEL_STMT_LABEL 130790075Sobrien@tindex RETURN_INIT 130890075Sobrien@tindex RETURN_STMT 130990075Sobrien@findex RETURN_EXPR 131090075Sobrien@tindex SCOPE_STMT 131190075Sobrien@findex SCOPE_BEGIN_P 131290075Sobrien@findex SCOPE_END_P 131390075Sobrien@findex SCOPE_NULLIFIED_P 131490075Sobrien@tindex SUBOBJECT 131590075Sobrien@findex SUBOBJECT_CLEANUP 131690075Sobrien@tindex SWITCH_STMT 131790075Sobrien@findex SWITCH_COND 131890075Sobrien@findex SWITCH_BODY 131990075Sobrien@tindex TRY_BLOCK 132090075Sobrien@findex TRY_STMTS 132190075Sobrien@findex TRY_HANDLERS 132290075Sobrien@findex HANDLER_PARMS 132390075Sobrien@findex HANDLER_BODY 132490075Sobrien@findex USING_STMT 132590075Sobrien@tindex WHILE_STMT 132690075Sobrien@findex WHILE_BODY 132790075Sobrien@findex WHILE_COND 132890075Sobrien 132990075SobrienA function that has a definition in the current translation unit will 133090075Sobrienhave a non-@code{NULL} @code{DECL_INITIAL}. However, back ends should not make 133190075Sobrienuse of the particular value given by @code{DECL_INITIAL}. 133290075Sobrien 133390075SobrienThe @code{DECL_SAVED_TREE} macro will give the complete body of the 133490075Sobrienfunction. This node will usually be a @code{COMPOUND_STMT} representing 133590075Sobrienthe outermost block of the function, but it may also be a 133690075Sobrien@code{TRY_BLOCK}, a @code{RETURN_INIT}, or any other valid statement. 133790075Sobrien 133890075Sobrien@subsubsection Statements 133990075Sobrien 134090075SobrienThere are tree nodes corresponding to all of the source-level statement 134190075Sobrienconstructs. These are enumerated here, together with a list of the 134290075Sobrienvarious macros that can be used to obtain information about them. There 134390075Sobrienare a few macros that can be used with all statements: 134490075Sobrien 134590075Sobrien@ftable @code 134690075Sobrien@item STMT_LINENO 134790075SobrienThis macro returns the line number for the statement. If the statement 134890075Sobrienspans multiple lines, this value will be the number of the first line on 134990075Sobrienwhich the statement occurs. Although we mention @code{CASE_LABEL} below 135090075Sobrienas if it were a statement, they do not allow the use of 135190075Sobrien@code{STMT_LINENO}. There is no way to obtain the line number for a 135290075Sobrien@code{CASE_LABEL}. 135390075Sobrien 135490075SobrienStatements do not contain information about 135590075Sobrienthe file from which they came; that information is implicit in the 135690075Sobrien@code{FUNCTION_DECL} from which the statements originate. 135790075Sobrien 135890075Sobrien@item STMT_IS_FULL_EXPR_P 135990075SobrienIn C++, statements normally constitute ``full expressions''; temporaries 136090075Sobriencreated during a statement are destroyed when the statement is complete. 136190075SobrienHowever, G++ sometimes represents expressions by statements; these 136290075Sobrienstatements will not have @code{STMT_IS_FULL_EXPR_P} set. Temporaries 136390075Sobriencreated during such statements should be destroyed when the innermost 136490075Sobrienenclosing statement with @code{STMT_IS_FULL_EXPR_P} set is exited. 136590075Sobrien 136690075Sobrien@end ftable 136790075Sobrien 136890075SobrienHere is the list of the various statement nodes, and the macros used to 136990075Sobrienaccess them. This documentation describes the use of these nodes in 137090075Sobriennon-template functions (including instantiations of template functions). 137190075SobrienIn template functions, the same nodes are used, but sometimes in 137290075Sobrienslightly different ways. 137390075Sobrien 137490075SobrienMany of the statements have substatements. For example, a @code{while} 137590075Sobrienloop will have a body, which is itself a statement. If the substatement 137690075Sobrienis @code{NULL_TREE}, it is considered equivalent to a statement 137790075Sobrienconsisting of a single @code{;}, i.e., an expression statement in which 137890075Sobrienthe expression has been omitted. A substatement may in fact be a list 137990075Sobrienof statements, connected via their @code{TREE_CHAIN}s. So, you should 138090075Sobrienalways process the statement tree by looping over substatements, like 138190075Sobrienthis: 138290075Sobrien@example 138390075Sobrienvoid process_stmt (stmt) 138490075Sobrien tree stmt; 138590075Sobrien@{ 138690075Sobrien while (stmt) 138790075Sobrien @{ 138890075Sobrien switch (TREE_CODE (stmt)) 138990075Sobrien @{ 139090075Sobrien case IF_STMT: 139190075Sobrien process_stmt (THEN_CLAUSE (stmt)); 139290075Sobrien /* More processing here. */ 139390075Sobrien break; 139490075Sobrien 139590075Sobrien @dots{} 139690075Sobrien @} 139790075Sobrien 139890075Sobrien stmt = TREE_CHAIN (stmt); 139990075Sobrien @} 140090075Sobrien@} 140190075Sobrien@end example 140290075SobrienIn other words, while the @code{then} clause of an @code{if} statement 140390075Sobrienin C++ can be only one statement (although that one statement may be a 140490075Sobriencompound statement), the intermediate representation will sometimes use 140590075Sobrienseveral statements chained together. 140690075Sobrien 140790075Sobrien@table @code 140890075Sobrien@item ASM_STMT 140990075Sobrien 141090075SobrienUsed to represent an inline assembly statement. For an inline assembly 141190075Sobrienstatement like: 141290075Sobrien@example 141390075Sobrienasm ("mov x, y"); 141490075Sobrien@end example 141590075SobrienThe @code{ASM_STRING} macro will return a @code{STRING_CST} node for 141690075Sobrien@code{"mov x, y"}. If the original statement made use of the 141790075Sobrienextended-assembly syntax, then @code{ASM_OUTPUTS}, 141890075Sobrien@code{ASM_INPUTS}, and @code{ASM_CLOBBERS} will be the outputs, inputs, 141990075Sobrienand clobbers for the statement, represented as @code{STRING_CST} nodes. 142090075SobrienThe extended-assembly syntax looks like: 142190075Sobrien@example 142290075Sobrienasm ("fsinx %1,%0" : "=f" (result) : "f" (angle)); 142390075Sobrien@end example 142490075SobrienThe first string is the @code{ASM_STRING}, containing the instruction 142590075Sobrientemplate. The next two strings are the output and inputs, respectively; 142690075Sobrienthis statement has no clobbers. As this example indicates, ``plain'' 142790075Sobrienassembly statements are merely a special case of extended assembly 142890075Sobrienstatements; they have no cv-qualifiers, outputs, inputs, or clobbers. 142990075SobrienAll of the strings will be @code{NUL}-terminated, and will contain no 143090075Sobrienembedded @code{NUL}-characters. 143190075Sobrien 143290075SobrienIf the assembly statement is declared @code{volatile}, or if the 143390075Sobrienstatement was not an extended assembly statement, and is therefore 143490075Sobrienimplicitly volatile, then the predicate @code{ASM_VOLATILE_P} will hold 143590075Sobrienof the @code{ASM_STMT}. 143690075Sobrien 143790075Sobrien@item BREAK_STMT 143890075Sobrien 143990075SobrienUsed to represent a @code{break} statement. There are no additional 144090075Sobrienfields. 144190075Sobrien 144290075Sobrien@item CASE_LABEL 144390075Sobrien 144490075SobrienUse to represent a @code{case} label, range of @code{case} labels, or a 144590075Sobrien@code{default} label. If @code{CASE_LOW} is @code{NULL_TREE}, then this is a 144690075Sobrien@code{default} label. Otherwise, if @code{CASE_HIGH} is @code{NULL_TREE}, then 144790075Sobrienthis is an ordinary @code{case} label. In this case, @code{CASE_LOW} is 144890075Sobrienan expression giving the value of the label. Both @code{CASE_LOW} and 144990075Sobrien@code{CASE_HIGH} are @code{INTEGER_CST} nodes. These values will have 145090075Sobrienthe same type as the condition expression in the switch statement. 145190075Sobrien 145290075SobrienOtherwise, if both @code{CASE_LOW} and @code{CASE_HIGH} are defined, the 145390075Sobrienstatement is a range of case labels. Such statements originate with the 145490075Sobrienextension that allows users to write things of the form: 145590075Sobrien@example 145690075Sobriencase 2 ... 5: 145790075Sobrien@end example 145890075SobrienThe first value will be @code{CASE_LOW}, while the second will be 145990075Sobrien@code{CASE_HIGH}. 146090075Sobrien 146190075Sobrien@item CLEANUP_STMT 146290075Sobrien 146390075SobrienUsed to represent an action that should take place upon exit from the 146490075Sobrienenclosing scope. Typically, these actions are calls to destructors for 146590075Sobrienlocal objects, but back ends cannot rely on this fact. If these nodes 146690075Sobrienare in fact representing such destructors, @code{CLEANUP_DECL} will be 146790075Sobrienthe @code{VAR_DECL} destroyed. Otherwise, @code{CLEANUP_DECL} will be 146890075Sobrien@code{NULL_TREE}. In any case, the @code{CLEANUP_EXPR} is the 146990075Sobrienexpression to execute. The cleanups executed on exit from a scope 147090075Sobrienshould be run in the reverse order of the order in which the associated 147190075Sobrien@code{CLEANUP_STMT}s were encountered. 147290075Sobrien 147390075Sobrien@item COMPOUND_STMT 147490075Sobrien 147590075SobrienUsed to represent a brace-enclosed block. The first substatement is 147690075Sobriengiven by @code{COMPOUND_BODY}. Subsequent substatements are found by 147790075Sobrienfollowing the @code{TREE_CHAIN} link from one substatement to the next. 147890075SobrienThe @code{COMPOUND_BODY} will be @code{NULL_TREE} if there are no 147990075Sobriensubstatements. 148090075Sobrien 148190075Sobrien@item CONTINUE_STMT 148290075Sobrien 148390075SobrienUsed to represent a @code{continue} statement. There are no additional 148490075Sobrienfields. 148590075Sobrien 148690075Sobrien@item CTOR_STMT 148790075Sobrien 148890075SobrienUsed to mark the beginning (if @code{CTOR_BEGIN_P} holds) or end (if 148990075Sobrien@code{CTOR_END_P} holds of the main body of a constructor. See also 149090075Sobrien@code{SUBOBJECT} for more information on how to use these nodes. 149190075Sobrien 149290075Sobrien@item DECL_STMT 149390075Sobrien 149490075SobrienUsed to represent a local declaration. The @code{DECL_STMT_DECL} macro 149590075Sobriencan be used to obtain the entity declared. This declaration may be a 149690075Sobrien@code{LABEL_DECL}, indicating that the label declared is a local label. 149790075Sobrien(As an extension, GCC allows the declaration of labels with scope.) In 149890075SobrienC, this declaration may be a @code{FUNCTION_DECL}, indicating the 149990075Sobrienuse of the GCC nested function extension. For more information, 150090075Sobrien@pxref{Functions}. 150190075Sobrien 150290075Sobrien@item DO_STMT 150390075Sobrien 150490075SobrienUsed to represent a @code{do} loop. The body of the loop is given by 150590075Sobrien@code{DO_BODY} while the termination condition for the loop is given by 150690075Sobrien@code{DO_COND}. The condition for a @code{do}-statement is always an 150790075Sobrienexpression. 150890075Sobrien 150990075Sobrien@item EMPTY_CLASS_EXPR 151090075Sobrien 151190075SobrienUsed to represent a temporary object of a class with no data whose 151290075Sobrienaddress is never taken. (All such objects are interchangeable.) The 151390075Sobrien@code{TREE_TYPE} represents the type of the object. 151490075Sobrien 151590075Sobrien@item EXPR_STMT 151690075Sobrien 151790075SobrienUsed to represent an expression statement. Use @code{EXPR_STMT_EXPR} to 151890075Sobrienobtain the expression. 151990075Sobrien 152090075Sobrien@item FILE_STMT 152190075Sobrien 152290075SobrienUsed to record a change in filename within the body of a function. 152390075SobrienUse @code{FILE_STMT_FILENAME} to obtain the new filename. 152490075Sobrien 152590075Sobrien@item FOR_STMT 152690075Sobrien 152790075SobrienUsed to represent a @code{for} statement. The @code{FOR_INIT_STMT} is 152890075Sobrienthe initialization statement for the loop. The @code{FOR_COND} is the 152990075Sobrientermination condition. The @code{FOR_EXPR} is the expression executed 153090075Sobrienright before the @code{FOR_COND} on each loop iteration; often, this 153190075Sobrienexpression increments a counter. The body of the loop is given by 153290075Sobrien@code{FOR_BODY}. Note that @code{FOR_INIT_STMT} and @code{FOR_BODY} 153390075Sobrienreturn statements, while @code{FOR_COND} and @code{FOR_EXPR} return 153490075Sobrienexpressions. 153590075Sobrien 153690075Sobrien@item GOTO_STMT 153790075Sobrien 153890075SobrienUsed to represent a @code{goto} statement. The @code{GOTO_DESTINATION} will 153990075Sobrienusually be a @code{LABEL_DECL}. However, if the ``computed goto'' extension 154090075Sobrienhas been used, the @code{GOTO_DESTINATION} will be an arbitrary expression 154190075Sobrienindicating the destination. This expression will always have pointer type. 154290075SobrienAdditionally the @code{GOTO_FAKE_P} flag is set whenever the goto statement 154390075Sobriendoes not come from source code, but it is generated implicitly by the compiler. 154490075SobrienThis is used for branch prediction. 154590075Sobrien 154690075Sobrien@item HANDLER 154790075Sobrien 154890075SobrienUsed to represent a C++ @code{catch} block. The @code{HANDLER_TYPE} 154990075Sobrienis the type of exception that will be caught by this handler; it is 155090075Sobrienequal (by pointer equality) to @code{CATCH_ALL_TYPE} if this handler 155190075Sobrienis for all types. @code{HANDLER_PARMS} is the @code{DECL_STMT} for 155290075Sobrienthe catch parameter, and @code{HANDLER_BODY} is the 155390075Sobrien@code{COMPOUND_STMT} for the block itself. 155490075Sobrien 155590075Sobrien@item IF_STMT 155690075Sobrien 155790075SobrienUsed to represent an @code{if} statement. The @code{IF_COND} is the 155890075Sobrienexpression. 155990075Sobrien 156090075SobrienIf the condition is a @code{TREE_LIST}, then the @code{TREE_PURPOSE} is 156190075Sobriena statement (usually a @code{DECL_STMT}). Each time the condition is 156290075Sobrienevaluated, the statement should be executed. Then, the 156390075Sobrien@code{TREE_VALUE} should be used as the conditional expression itself. 156490075SobrienThis representation is used to handle C++ code like this: 156590075Sobrien 156690075Sobrien@example 156790075Sobrienif (int i = 7) @dots{} 156890075Sobrien@end example 156990075Sobrien 157090075Sobrienwhere there is a new local variable (or variables) declared within the 157190075Sobriencondition. 157290075Sobrien 157390075SobrienThe @code{THEN_CLAUSE} represents the statement given by the @code{then} 157490075Sobriencondition, while the @code{ELSE_CLAUSE} represents the statement given 157590075Sobrienby the @code{else} condition. 157690075Sobrien 157790075Sobrien@item LABEL_STMT 157890075Sobrien 157990075SobrienUsed to represent a label. The @code{LABEL_DECL} declared by this 158090075Sobrienstatement can be obtained with the @code{LABEL_STMT_LABEL} macro. The 158190075Sobrien@code{IDENTIFIER_NODE} giving the name of the label can be obtained from 158290075Sobrienthe @code{LABEL_DECL} with @code{DECL_NAME}. 158390075Sobrien 158490075Sobrien@item RETURN_INIT 158590075Sobrien 158690075SobrienIf the function uses the G++ ``named return value'' extension, meaning 158790075Sobrienthat the function has been defined like: 158890075Sobrien@example 158990075SobrienS f(int) return s @{@dots{}@} 159090075Sobrien@end example 159190075Sobrienthen there will be a @code{RETURN_INIT}. There is never a named 159290075Sobrienreturned value for a constructor. The first argument to the 159390075Sobrien@code{RETURN_INIT} is the name of the object returned; the second 159490075Sobrienargument is the initializer for the object. The object is initialized 159590075Sobrienwhen the @code{RETURN_INIT} is encountered. The object referred to is 159690075Sobrienthe actual object returned; this extension is a manual way of doing the 159790075Sobrien``return-value optimization.'' Therefore, the object must actually be 159890075Sobrienconstructed in the place where the object will be returned. 159990075Sobrien 160090075Sobrien@item RETURN_STMT 160190075Sobrien 160290075SobrienUsed to represent a @code{return} statement. The @code{RETURN_EXPR} is 160390075Sobrienthe expression returned; it will be @code{NULL_TREE} if the statement 160490075Sobrienwas just 160590075Sobrien@example 160690075Sobrienreturn; 160790075Sobrien@end example 160890075Sobrien 160990075Sobrien@item SCOPE_STMT 161090075Sobrien 161190075SobrienA scope-statement represents the beginning or end of a scope. If 161290075Sobrien@code{SCOPE_BEGIN_P} holds, this statement represents the beginning of a 161390075Sobrienscope; if @code{SCOPE_END_P} holds this statement represents the end of 161490075Sobriena scope. On exit from a scope, all cleanups from @code{CLEANUP_STMT}s 161590075Sobrienoccurring in the scope must be run, in reverse order to the order in 161690075Sobrienwhich they were encountered. If @code{SCOPE_NULLIFIED_P} or 161790075Sobrien@code{SCOPE_NO_CLEANUPS_P} holds of the scope, back ends should behave 161890075Sobrienas if the @code{SCOPE_STMT} were not present at all. 161990075Sobrien 162090075Sobrien@item SUBOBJECT 162190075Sobrien 162290075SobrienIn a constructor, these nodes are used to mark the point at which a 162390075Sobriensubobject of @code{this} is fully constructed. If, after this point, an 162490075Sobrienexception is thrown before a @code{CTOR_STMT} with @code{CTOR_END_P} set 162590075Sobrienis encountered, the @code{SUBOBJECT_CLEANUP} must be executed. The 162690075Sobriencleanups must be executed in the reverse order in which they appear. 162790075Sobrien 162890075Sobrien@item SWITCH_STMT 162990075Sobrien 163090075SobrienUsed to represent a @code{switch} statement. The @code{SWITCH_COND} is 163190075Sobrienthe expression on which the switch is occurring. See the documentation 163290075Sobrienfor an @code{IF_STMT} for more information on the representation used 163390075Sobrienfor the condition. The @code{SWITCH_BODY} is the body of the switch 163496263Sobrienstatement. The @code{SWITCH_TYPE} is the original type of switch 163596263Sobrienexpression as given in the source, before any compiler conversions. 163690075Sobrien 163790075Sobrien@item TRY_BLOCK 163890075SobrienUsed to represent a @code{try} block. The body of the try block is 163990075Sobriengiven by @code{TRY_STMTS}. Each of the catch blocks is a @code{HANDLER} 164090075Sobriennode. The first handler is given by @code{TRY_HANDLERS}. Subsequent 164190075Sobrienhandlers are obtained by following the @code{TREE_CHAIN} link from one 164290075Sobrienhandler to the next. The body of the handler is given by 164390075Sobrien@code{HANDLER_BODY}. 164490075Sobrien 164590075SobrienIf @code{CLEANUP_P} holds of the @code{TRY_BLOCK}, then the 164690075Sobrien@code{TRY_HANDLERS} will not be a @code{HANDLER} node. Instead, it will 164790075Sobrienbe an expression that should be executed if an exception is thrown in 164890075Sobrienthe try block. It must rethrow the exception after executing that code. 164990075SobrienAnd, if an exception is thrown while the expression is executing, 165090075Sobrien@code{terminate} must be called. 165190075Sobrien 165290075Sobrien@item USING_STMT 165390075SobrienUsed to represent a @code{using} directive. The namespace is given by 165490075Sobrien@code{USING_STMT_NAMESPACE}, which will be a NAMESPACE_DECL@. This node 165590075Sobrienis needed inside template functions, to implement using directives 165690075Sobrienduring instantiation. 165790075Sobrien 165890075Sobrien@item WHILE_STMT 165990075Sobrien 166090075SobrienUsed to represent a @code{while} loop. The @code{WHILE_COND} is the 166190075Sobrientermination condition for the loop. See the documentation for an 166290075Sobrien@code{IF_STMT} for more information on the representation used for the 166390075Sobriencondition. 166490075Sobrien 166590075SobrienThe @code{WHILE_BODY} is the body of the loop. 166690075Sobrien 166790075Sobrien@end table 166890075Sobrien 166990075Sobrien@c --------------------------------------------------------------------- 167090075Sobrien@c Attributes 167190075Sobrien@c --------------------------------------------------------------------- 167290075Sobrien@node Attributes 167390075Sobrien@section Attributes in trees 167490075Sobrien@cindex attributes 167590075Sobrien 167690075SobrienAttributes, as specified using the @code{__attribute__} keyword, are 167790075Sobrienrepresented internally as a @code{TREE_LIST}. The @code{TREE_PURPOSE} 167890075Sobrienis the name of the attribute, as an @code{IDENTIFIER_NODE}. The 167990075Sobrien@code{TREE_VALUE} is a @code{TREE_LIST} of the arguments of the 168090075Sobrienattribute, if any, or @code{NULL_TREE} if there are no arguments; the 168190075Sobrienarguments are stored as the @code{TREE_VALUE} of successive entries in 168290075Sobrienthe list, and may be identifiers or expressions. The @code{TREE_CHAIN} 168390075Sobrienof the attribute is the next attribute in a list of attributes applying 168490075Sobriento the same declaration or type, or @code{NULL_TREE} if there are no 168590075Sobrienfurther attributes in the list. 168690075Sobrien 168790075SobrienAttributes may be attached to declarations and to types; these 168890075Sobrienattributes may be accessed with the following macros. All attributes 168990075Sobrienare stored in this way, and many also cause other changes to the 169090075Sobriendeclaration or type or to other internal compiler data structures. 169190075Sobrien 169290075Sobrien@deftypefn {Tree Macro} tree DECL_ATTRIBUTES (tree @var{decl}) 169390075SobrienThis macro returns the attributes on the declaration @var{decl}. 169490075Sobrien@end deftypefn 169590075Sobrien 169690075Sobrien@deftypefn {Tree Macro} tree TYPE_ATTRIBUTES (tree @var{type}) 169790075SobrienThis macro returns the attributes on the type @var{type}. 169890075Sobrien@end deftypefn 169990075Sobrien 170090075Sobrien@c --------------------------------------------------------------------- 170190075Sobrien@c Expressions 170290075Sobrien@c --------------------------------------------------------------------- 170390075Sobrien 170490075Sobrien@node Expression trees 170590075Sobrien@section Expressions 170690075Sobrien@cindex expression 170790075Sobrien@findex TREE_OPERAND 170890075Sobrien@tindex INTEGER_CST 170990075Sobrien@findex TREE_INT_CST_HIGH 171090075Sobrien@findex TREE_INT_CST_LOW 171190075Sobrien@findex tree_int_cst_lt 171290075Sobrien@findex tree_int_cst_equal 171390075Sobrien@tindex REAL_CST 171490075Sobrien@tindex COMPLEX_CST 171596263Sobrien@tindex VECTOR_CST 171690075Sobrien@tindex STRING_CST 171790075Sobrien@findex TREE_STRING_LENGTH 171890075Sobrien@findex TREE_STRING_POINTER 171990075Sobrien@tindex PTRMEM_CST 172090075Sobrien@findex PTRMEM_CST_CLASS 172190075Sobrien@findex PTRMEM_CST_MEMBER 172290075Sobrien@tindex VAR_DECL 172390075Sobrien@tindex NEGATE_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 177490075Sobrien 177590075SobrienThe internal representation for expressions is for the most part quite 177690075Sobrienstraightforward. However, there are a few facts that one must bear in 177790075Sobrienmind. In particular, the expression ``tree'' is actually a directed 177890075Sobrienacyclic graph. (For example there may be many references to the integer 177990075Sobrienconstant zero throughout the source program; many of these will be 178090075Sobrienrepresented by the same expression node.) You should not rely on 178190075Sobriencertain kinds of node being shared, nor should rely on certain kinds of 178290075Sobriennodes being unshared. 178390075Sobrien 178490075SobrienThe following macros can be used with all expression nodes: 178590075Sobrien 178690075Sobrien@ftable @code 178790075Sobrien@item TREE_TYPE 178890075SobrienReturns the type of the expression. This value may not be precisely the 178990075Sobriensame type that would be given the expression in the original program. 179090075Sobrien@end ftable 179190075Sobrien 179290075SobrienIn what follows, some nodes that one might expect to always have type 179390075Sobrien@code{bool} are documented to have either integral or boolean type. At 179490075Sobriensome point in the future, the C front end may also make use of this same 179590075Sobrienintermediate representation, and at this point these nodes will 179690075Sobriencertainly have integral type. The previous sentence is not meant to 179790075Sobrienimply that the C++ front end does not or will not give these nodes 179890075Sobrienintegral type. 179990075Sobrien 180090075SobrienBelow, we list the various kinds of expression nodes. Except where 180190075Sobriennoted otherwise, the operands to an expression are accessed using the 180290075Sobrien@code{TREE_OPERAND} macro. For example, to access the first operand to 180390075Sobriena binary plus expression @code{expr}, use: 180490075Sobrien 180590075Sobrien@example 180690075SobrienTREE_OPERAND (expr, 0) 180790075Sobrien@end example 180890075Sobrien@noindent 180990075SobrienAs this example indicates, the operands are zero-indexed. 181090075Sobrien 181190075SobrienThe table below begins with constants, moves on to unary expressions, 181290075Sobrienthen proceeds to binary expressions, and concludes with various other 181390075Sobrienkinds of expressions: 181490075Sobrien 181590075Sobrien@table @code 181690075Sobrien@item INTEGER_CST 181790075SobrienThese nodes represent integer constants. Note that the type of these 181890075Sobrienconstants is obtained with @code{TREE_TYPE}; they are not always of type 181990075Sobrien@code{int}. In particular, @code{char} constants are represented with 182090075Sobrien@code{INTEGER_CST} nodes. The value of the integer constant @code{e} is 182190075Sobriengiven by @example 182290075Sobrien((TREE_INT_CST_HIGH (e) << HOST_BITS_PER_WIDE_INT) 182390075Sobrien+ TREE_INST_CST_LOW (e)) 182490075Sobrien@end example 182590075Sobrien@noindent 182690075SobrienHOST_BITS_PER_WIDE_INT is at least thirty-two on all platforms. Both 182790075Sobrien@code{TREE_INT_CST_HIGH} and @code{TREE_INT_CST_LOW} return a 182890075Sobrien@code{HOST_WIDE_INT}. The value of an @code{INTEGER_CST} is interpreted 182990075Sobrienas a signed or unsigned quantity depending on the type of the constant. 183090075SobrienIn general, the expression given above will overflow, so it should not 183190075Sobrienbe used to calculate the value of the constant. 183290075Sobrien 183390075SobrienThe variable @code{integer_zero_node} is an integer constant with value 183490075Sobrienzero. Similarly, @code{integer_one_node} is an integer constant with 183590075Sobrienvalue one. The @code{size_zero_node} and @code{size_one_node} variables 183690075Sobrienare analogous, but have type @code{size_t} rather than @code{int}. 183790075Sobrien 183890075SobrienThe function @code{tree_int_cst_lt} is a predicate which holds if its 183990075Sobrienfirst argument is less than its second. Both constants are assumed to 184090075Sobrienhave the same signedness (i.e., either both should be signed or both 184190075Sobrienshould be unsigned.) The full width of the constant is used when doing 184290075Sobrienthe comparison; the usual rules about promotions and conversions are 184390075Sobrienignored. Similarly, @code{tree_int_cst_equal} holds if the two 184490075Sobrienconstants are equal. The @code{tree_int_cst_sgn} function returns the 184590075Sobriensign of a constant. The value is @code{1}, @code{0}, or @code{-1} 184690075Sobrienaccording on whether the constant is greater than, equal to, or less 184790075Sobrienthan zero. Again, the signedness of the constant's type is taken into 184890075Sobrienaccount; an unsigned constant is never less than zero, no matter what 184990075Sobrienits bit-pattern. 185090075Sobrien 185190075Sobrien@item REAL_CST 185290075Sobrien 185390075SobrienFIXME: Talk about how to obtain representations of this constant, do 185490075Sobriencomparisons, and so forth. 185590075Sobrien 185690075Sobrien@item COMPLEX_CST 185790075SobrienThese nodes are used to represent complex number constants, that is a 185890075Sobrien@code{__complex__} whose parts are constant nodes. The 185990075Sobrien@code{TREE_REALPART} and @code{TREE_IMAGPART} return the real and the 186090075Sobrienimaginary parts respectively. 186190075Sobrien 186296263Sobrien@item VECTOR_CST 186396263SobrienThese nodes are used to represent vector constants, whose parts are 186496263Sobrienconstant nodes. Each individual constant node is either an integer or a 186596263Sobriendouble constant node. The first operand is a @code{TREE_LIST} of the 186696263Sobrienconstant nodes and is accessed through @code{TREE_VECTOR_CST_ELTS}. 186796263Sobrien 186890075Sobrien@item STRING_CST 186990075SobrienThese nodes represent string-constants. The @code{TREE_STRING_LENGTH} 187090075Sobrienreturns the length of the string, as an @code{int}. The 187190075Sobrien@code{TREE_STRING_POINTER} is a @code{char*} containing the string 187290075Sobrienitself. The string may not be @code{NUL}-terminated, and it may contain 187390075Sobrienembedded @code{NUL} characters. Therefore, the 187490075Sobrien@code{TREE_STRING_LENGTH} includes the trailing @code{NUL} if it is 187590075Sobrienpresent. 187690075Sobrien 187790075SobrienFor wide string constants, the @code{TREE_STRING_LENGTH} is the number 187890075Sobrienof bytes in the string, and the @code{TREE_STRING_POINTER} 187990075Sobrienpoints to an array of the bytes of the string, as represented on the 188090075Sobrientarget system (that is, as integers in the target endianness). Wide and 188190075Sobriennon-wide string constants are distinguished only by the @code{TREE_TYPE} 188290075Sobrienof the @code{STRING_CST}. 188390075Sobrien 188490075SobrienFIXME: The formats of string constants are not well-defined when the 188590075Sobrientarget system bytes are not the same width as host system bytes. 188690075Sobrien 188790075Sobrien@item PTRMEM_CST 188890075SobrienThese nodes are used to represent pointer-to-member constants. The 188990075Sobrien@code{PTRMEM_CST_CLASS} is the class type (either a @code{RECORD_TYPE} 189090075Sobrienor @code{UNION_TYPE} within which the pointer points), and the 189190075Sobrien@code{PTRMEM_CST_MEMBER} is the declaration for the pointed to object. 189290075SobrienNote that the @code{DECL_CONTEXT} for the @code{PTRMEM_CST_MEMBER} is in 189390075Sobriengeneral different from the @code{PTRMEM_CST_CLASS}. For example, 189490075Sobriengiven: 189590075Sobrien@example 189690075Sobrienstruct B @{ int i; @}; 189790075Sobrienstruct D : public B @{@}; 189890075Sobrienint D::*dp = &D::i; 189990075Sobrien@end example 190090075Sobrien@noindent 190190075SobrienThe @code{PTRMEM_CST_CLASS} for @code{&D::i} is @code{D}, even though 190290075Sobrienthe @code{DECL_CONTEXT} for the @code{PTRMEM_CST_MEMBER} is @code{B}, 190390075Sobriensince @code{B::i} is a member of @code{B}, not @code{D}. 190490075Sobrien 190590075Sobrien@item VAR_DECL 190690075Sobrien 190790075SobrienThese nodes represent variables, including static data members. For 190890075Sobrienmore information, @pxref{Declarations}. 190990075Sobrien 191090075Sobrien@item NEGATE_EXPR 191190075SobrienThese nodes represent unary negation of the single operand, for both 191290075Sobrieninteger and floating-point types. The type of negation can be 191390075Sobriendetermined by looking at the type of the expression. 191490075Sobrien 191590075Sobrien@item BIT_NOT_EXPR 191690075SobrienThese nodes represent bitwise complement, and will always have integral 191790075Sobrientype. The only operand is the value to be complemented. 191890075Sobrien 191990075Sobrien@item TRUTH_NOT_EXPR 192090075SobrienThese nodes represent logical negation, and will always have integral 192190075Sobrien(or boolean) type. The operand is the value being negated. 192290075Sobrien 192390075Sobrien@item PREDECREMENT_EXPR 192490075Sobrien@itemx PREINCREMENT_EXPR 192590075Sobrien@itemx POSTDECREMENT_EXPR 192690075Sobrien@itemx POSTINCREMENT_EXPR 192790075SobrienThese nodes represent increment and decrement expressions. The value of 192890075Sobrienthe single operand is computed, and the operand incremented or 192990075Sobriendecremented. In the case of @code{PREDECREMENT_EXPR} and 193090075Sobrien@code{PREINCREMENT_EXPR}, the value of the expression is the value 193190075Sobrienresulting after the increment or decrement; in the case of 193290075Sobrien@code{POSTDECREMENT_EXPR} and @code{POSTINCREMENT_EXPR} is the value 193390075Sobrienbefore the increment or decrement occurs. The type of the operand, like 193490075Sobrienthat of the result, will be either integral, boolean, or floating-point. 193590075Sobrien 193690075Sobrien@item ADDR_EXPR 193790075SobrienThese nodes are used to represent the address of an object. (These 193890075Sobrienexpressions will always have pointer or reference type.) The operand may 193990075Sobrienbe another expression, or it may be a declaration. 194090075Sobrien 194190075SobrienAs an extension, GCC allows users to take the address of a label. In 194290075Sobrienthis case, the operand of the @code{ADDR_EXPR} will be a 194390075Sobrien@code{LABEL_DECL}. The type of such an expression is @code{void*}. 194490075Sobrien 194590075SobrienIf the object addressed is not an lvalue, a temporary is created, and 194690075Sobrienthe address of the temporary is used. 194790075Sobrien 194890075Sobrien@item INDIRECT_REF 194990075SobrienThese nodes are used to represent the object pointed to by a pointer. 195090075SobrienThe operand is the pointer being dereferenced; it will always have 195190075Sobrienpointer or reference type. 195290075Sobrien 195390075Sobrien@item FIX_TRUNC_EXPR 195490075SobrienThese nodes represent conversion of a floating-point value to an 195590075Sobrieninteger. The single operand will have a floating-point type, while the 195690075Sobrienthe complete expression will have an integral (or boolean) type. The 195790075Sobrienoperand is rounded towards zero. 195890075Sobrien 195990075Sobrien@item FLOAT_EXPR 196090075SobrienThese nodes represent conversion of an integral (or boolean) value to a 196190075Sobrienfloating-point value. The single operand will have integral type, while 196290075Sobrienthe complete expression will have a floating-point type. 196390075Sobrien 196490075SobrienFIXME: How is the operand supposed to be rounded? Is this dependent on 196590075Sobrien@option{-mieee}? 196690075Sobrien 196790075Sobrien@item COMPLEX_EXPR 196890075SobrienThese nodes are used to represent complex numbers constructed from two 196990075Sobrienexpressions of the same (integer or real) type. The first operand is the 197090075Sobrienreal part and the second operand is the imaginary part. 197190075Sobrien 197290075Sobrien@item CONJ_EXPR 197390075SobrienThese nodes represent the conjugate of their operand. 197490075Sobrien 197590075Sobrien@item REALPART_EXPR 197690075Sobrien@item IMAGPART_EXPR 197790075SobrienThese nodes represent respectively the real and the imaginary parts 197890075Sobrienof complex numbers (their sole argument). 197990075Sobrien 198090075Sobrien@item NON_LVALUE_EXPR 198190075SobrienThese nodes indicate that their one and only operand is not an lvalue. 198290075SobrienA back end can treat these identically to the single operand. 198390075Sobrien 198490075Sobrien@item NOP_EXPR 198590075SobrienThese nodes are used to represent conversions that do not require any 198690075Sobriencode-generation. For example, conversion of a @code{char*} to an 198790075Sobrien@code{int*} does not require any code be generated; such a conversion is 198890075Sobrienrepresented by a @code{NOP_EXPR}. The single operand is the expression 198990075Sobriento be converted. The conversion from a pointer to a reference is also 199090075Sobrienrepresented with a @code{NOP_EXPR}. 199190075Sobrien 199290075Sobrien@item CONVERT_EXPR 199390075SobrienThese nodes are similar to @code{NOP_EXPR}s, but are used in those 199490075Sobriensituations where code may need to be generated. For example, if an 199590075Sobrien@code{int*} is converted to an @code{int} code may need to be generated 199690075Sobrienon some platforms. These nodes are never used for C++-specific 199790075Sobrienconversions, like conversions between pointers to different classes in 199890075Sobrienan inheritance hierarchy. Any adjustments that need to be made in such 199990075Sobriencases are always indicated explicitly. Similarly, a user-defined 200090075Sobrienconversion is never represented by a @code{CONVERT_EXPR}; instead, the 200190075Sobrienfunction calls are made explicit. 200290075Sobrien 200390075Sobrien@item THROW_EXPR 200490075SobrienThese nodes represent @code{throw} expressions. The single operand is 200590075Sobrienan expression for the code that should be executed to throw the 200690075Sobrienexception. However, there is one implicit action not represented in 200790075Sobrienthat expression; namely the call to @code{__throw}. This function takes 200890075Sobrienno arguments. If @code{setjmp}/@code{longjmp} exceptions are used, the 200990075Sobrienfunction @code{__sjthrow} is called instead. The normal GCC back end 201090075Sobrienuses the function @code{emit_throw} to generate this code; you can 201190075Sobrienexamine this function to see what needs to be done. 201290075Sobrien 201390075Sobrien@item LSHIFT_EXPR 201490075Sobrien@itemx RSHIFT_EXPR 201590075SobrienThese nodes represent left and right shifts, respectively. The first 201690075Sobrienoperand is the value to shift; it will always be of integral type. The 201790075Sobriensecond operand is an expression for the number of bits by which to 201890075Sobrienshift. Right shift should be treated as arithmetic, i.e., the 201990075Sobrienhigh-order bits should be zero-filled when the expression has unsigned 202090075Sobrientype and filled with the sign bit when the expression has signed type. 202190075SobrienNote that the result is undefined if the second operand is larger 202290075Sobrienthan the first operand's type size. 202390075Sobrien 202490075Sobrien 202590075Sobrien@item BIT_IOR_EXPR 202690075Sobrien@itemx BIT_XOR_EXPR 202790075Sobrien@itemx BIT_AND_EXPR 202890075SobrienThese nodes represent bitwise inclusive or, bitwise exclusive or, and 202990075Sobrienbitwise and, respectively. Both operands will always have integral 203090075Sobrientype. 203190075Sobrien 203290075Sobrien@item TRUTH_ANDIF_EXPR 203390075Sobrien@itemx TRUTH_ORIF_EXPR 203490075SobrienThese nodes represent logical and and logical or, respectively. These 203590075Sobrienoperators are not strict; i.e., the second operand is evaluated only if 203690075Sobrienthe value of the expression is not determined by evaluation of the first 203790075Sobrienoperand. The type of the operands, and the result type, is always of 203890075Sobrienboolean or integral type. 203990075Sobrien 204090075Sobrien@item TRUTH_AND_EXPR 204190075Sobrien@itemx TRUTH_OR_EXPR 204290075Sobrien@itemx TRUTH_XOR_EXPR 204390075SobrienThese nodes represent logical and, logical or, and logical exclusive or. 204490075SobrienThey are strict; both arguments are always evaluated. There are no 204590075Sobriencorresponding operators in C or C++, but the front end will sometimes 204690075Sobriengenerate these expressions anyhow, if it can tell that strictness does 204790075Sobriennot matter. 204890075Sobrien 204990075Sobrien@itemx PLUS_EXPR 205090075Sobrien@itemx MINUS_EXPR 205190075Sobrien@itemx MULT_EXPR 205290075Sobrien@itemx TRUNC_DIV_EXPR 205390075Sobrien@itemx TRUNC_MOD_EXPR 205490075Sobrien@itemx RDIV_EXPR 205590075SobrienThese nodes represent various binary arithmetic operations. 205690075SobrienRespectively, these operations are addition, subtraction (of the second 205790075Sobrienoperand from the first), multiplication, integer division, integer 205890075Sobrienremainder, and floating-point division. The operands to the first three 205990075Sobrienof these may have either integral or floating type, but there will never 206090075Sobrienbe case in which one operand is of floating type and the other is of 206190075Sobrienintegral type. 206290075Sobrien 206390075SobrienThe result of a @code{TRUNC_DIV_EXPR} is always rounded towards zero. 206490075SobrienThe @code{TRUNC_MOD_EXPR} of two operands @code{a} and @code{b} is 206590075Sobrienalways @code{a - a/b} where the division is as if computed by a 206690075Sobrien@code{TRUNC_DIV_EXPR}. 206790075Sobrien 206890075Sobrien@item ARRAY_REF 206990075SobrienThese nodes represent array accesses. The first operand is the array; 207090075Sobrienthe second is the index. To calculate the address of the memory 207190075Sobrienaccessed, you must scale the index by the size of the type of the array 207290075Sobrienelements. The type of these expressions must be the type of a component of 207390075Sobrienthe array. 207490075Sobrien 207590075Sobrien@item ARRAY_RANGE_REF 207690075SobrienThese nodes represent access to a range (or ``slice'') of an array. The 207790075Sobrienoperands are the same as that for @code{ARRAY_REF} and have the same 207890075Sobrienmeanings. The type of these expressions must be an array whose component 207990075Sobrientype is the same as that of the first operand. The range of that array 208090075Sobrientype determines the amount of data these expressions access. 208190075Sobrien 208290075Sobrien@item EXACT_DIV_EXPR 208390075SobrienDocument. 208490075Sobrien 208590075Sobrien@item LT_EXPR 208690075Sobrien@itemx LE_EXPR 208790075Sobrien@itemx GT_EXPR 208890075Sobrien@itemx GE_EXPR 208990075Sobrien@itemx EQ_EXPR 209090075Sobrien@itemx NE_EXPR 209190075Sobrien 209290075SobrienThese nodes represent the less than, less than or equal to, greater 209390075Sobrienthan, greater than or equal to, equal, and not equal comparison 209490075Sobrienoperators. The first and second operand with either be both of integral 209590075Sobrientype or both of floating type. The result type of these expressions 209690075Sobrienwill always be of integral or boolean type. 209790075Sobrien 209890075Sobrien@item MODIFY_EXPR 209990075SobrienThese nodes represent assignment. The left-hand side is the first 210090075Sobrienoperand; the right-hand side is the second operand. The left-hand side 210190075Sobrienwill be a @code{VAR_DECL}, @code{INDIRECT_REF}, @code{COMPONENT_REF}, or 210290075Sobrienother lvalue. 210390075Sobrien 210490075SobrienThese nodes are used to represent not only assignment with @samp{=} but 210590075Sobrienalso compound assignments (like @samp{+=}), by reduction to @samp{=} 210690075Sobrienassignment. In other words, the representation for @samp{i += 3} looks 210790075Sobrienjust like that for @samp{i = i + 3}. 210890075Sobrien 210990075Sobrien@item INIT_EXPR 211090075SobrienThese nodes are just like @code{MODIFY_EXPR}, but are used only when a 211190075Sobrienvariable is initialized, rather than assigned to subsequently. 211290075Sobrien 211390075Sobrien@item COMPONENT_REF 211490075SobrienThese nodes represent non-static data member accesses. The first 211590075Sobrienoperand is the object (rather than a pointer to it); the second operand 211690075Sobrienis the @code{FIELD_DECL} for the data member. 211790075Sobrien 211890075Sobrien@item COMPOUND_EXPR 211990075SobrienThese nodes represent comma-expressions. The first operand is an 212090075Sobrienexpression whose value is computed and thrown away prior to the 212190075Sobrienevaluation of the second operand. The value of the entire expression is 212290075Sobrienthe value of the second operand. 212390075Sobrien 212490075Sobrien@item COND_EXPR 212590075SobrienThese nodes represent @code{?:} expressions. The first operand 212690075Sobrienis of boolean or integral type. If it evaluates to a nonzero value, 212790075Sobrienthe second operand should be evaluated, and returned as the value of the 212890075Sobrienexpression. Otherwise, the third operand is evaluated, and returned as 212990075Sobrienthe value of the expression. As a GNU extension, the middle operand of 213090075Sobrienthe @code{?:} operator may be omitted in the source, like this: 213190075Sobrien 213290075Sobrien@example 213390075Sobrienx ? : 3 213490075Sobrien@end example 213590075Sobrien@noindent 213690075Sobrienwhich is equivalent to 213790075Sobrien 213890075Sobrien@example 213990075Sobrienx ? x : 3 214090075Sobrien@end example 214190075Sobrien 214290075Sobrien@noindent 214390075Sobrienassuming that @code{x} is an expression without side-effects. However, 214490075Sobrienin the case that the first operation causes side effects, the 214590075Sobrienside-effects occur only once. Consumers of the internal representation 214690075Sobriendo not need to worry about this oddity; the second operand will be 214790075Sobrienalways be present in the internal representation. 214890075Sobrien 214990075Sobrien@item CALL_EXPR 215090075SobrienThese nodes are used to represent calls to functions, including 215190075Sobriennon-static member functions. The first operand is a pointer to the 215290075Sobrienfunction to call; it is always an expression whose type is a 215390075Sobrien@code{POINTER_TYPE}. The second argument is a @code{TREE_LIST}. The 215490075Sobrienarguments to the call appear left-to-right in the list. The 215590075Sobrien@code{TREE_VALUE} of each list node contains the expression 215690075Sobriencorresponding to that argument. (The value of @code{TREE_PURPOSE} for 215790075Sobrienthese nodes is unspecified, and should be ignored.) For non-static 215890075Sobrienmember functions, there will be an operand corresponding to the 215990075Sobrien@code{this} pointer. There will always be expressions corresponding to 216090075Sobrienall of the arguments, even if the function is declared with default 216190075Sobrienarguments and some arguments are not explicitly provided at the call 216290075Sobriensites. 216390075Sobrien 216490075Sobrien@item STMT_EXPR 216590075SobrienThese nodes are used to represent GCC's statement-expression extension. 216690075SobrienThe statement-expression extension allows code like this: 216790075Sobrien@example 216890075Sobrienint f() @{ return (@{ int j; j = 3; j + 7; @}); @} 216990075Sobrien@end example 217090075SobrienIn other words, an sequence of statements may occur where a single 217190075Sobrienexpression would normally appear. The @code{STMT_EXPR} node represents 217290075Sobriensuch an expression. The @code{STMT_EXPR_STMT} gives the statement 217390075Sobriencontained in the expression; this is always a @code{COMPOUND_STMT}. The 217490075Sobrienvalue of the expression is the value of the last sub-statement in the 217590075Sobrien@code{COMPOUND_STMT}. More precisely, the value is the value computed 217690075Sobrienby the last @code{EXPR_STMT} in the outermost scope of the 217790075Sobrien@code{COMPOUND_STMT}. For example, in: 217890075Sobrien@example 217990075Sobrien(@{ 3; @}) 218090075Sobrien@end example 218190075Sobrienthe value is @code{3} while in: 218290075Sobrien@example 218390075Sobrien(@{ if (x) @{ 3; @} @}) 218490075Sobrien@end example 218590075Sobrien(represented by a nested @code{COMPOUND_STMT}), there is no value. If 218690075Sobrienthe @code{STMT_EXPR} does not yield a value, it's type will be 218790075Sobrien@code{void}. 218890075Sobrien 218990075Sobrien@item BIND_EXPR 219090075SobrienThese nodes represent local blocks. The first operand is a list of 219190075Sobrientemporary variables, connected via their @code{TREE_CHAIN} field. These 219290075Sobrienwill never require cleanups. The scope of these variables is just the 219390075Sobrienbody of the @code{BIND_EXPR}. The body of the @code{BIND_EXPR} is the 219490075Sobriensecond operand. 219590075Sobrien 219690075Sobrien@item LOOP_EXPR 219790075SobrienThese nodes represent ``infinite'' loops. The @code{LOOP_EXPR_BODY} 219890075Sobrienrepresents the body of the loop. It should be executed forever, unless 219990075Sobrienan @code{EXIT_EXPR} is encountered. 220090075Sobrien 220190075Sobrien@item EXIT_EXPR 220290075SobrienThese nodes represent conditional exits from the nearest enclosing 220390075Sobrien@code{LOOP_EXPR}. The single operand is the condition; if it is 220490075Sobriennonzero, then the loop should be exited. An @code{EXIT_EXPR} will only 220590075Sobrienappear within a @code{LOOP_EXPR}. 220690075Sobrien 220790075Sobrien@item CLEANUP_POINT_EXPR 220890075SobrienThese nodes represent full-expressions. The single operand is an 220990075Sobrienexpression to evaluate. Any destructor calls engendered by the creation 221090075Sobrienof temporaries during the evaluation of that expression should be 221190075Sobrienperformed immediately after the expression is evaluated. 221290075Sobrien 221390075Sobrien@item CONSTRUCTOR 221490075SobrienThese nodes represent the brace-enclosed initializers for a structure or 221590075Sobrienarray. The first operand is reserved for use by the back end. The 221690075Sobriensecond operand is a @code{TREE_LIST}. If the @code{TREE_TYPE} of the 221790075Sobrien@code{CONSTRUCTOR} is a @code{RECORD_TYPE} or @code{UNION_TYPE}, then 221890075Sobrienthe @code{TREE_PURPOSE} of each node in the @code{TREE_LIST} will be a 221990075Sobrien@code{FIELD_DECL} and the @code{TREE_VALUE} of each node will be the 222090075Sobrienexpression used to initialize that field. You should not depend on the 222190075Sobrienfields appearing in any particular order, nor should you assume that all 222290075Sobrienfields will be represented. Unrepresented fields may be assigned any 222390075Sobrienvalue. 222490075Sobrien 222590075SobrienIf the @code{TREE_TYPE} of the @code{CONSTRUCTOR} is an 222690075Sobrien@code{ARRAY_TYPE}, then the @code{TREE_PURPOSE} of each element in the 222790075Sobrien@code{TREE_LIST} will be an @code{INTEGER_CST}. This constant indicates 222890075Sobrienwhich element of the array (indexed from zero) is being assigned to; 222990075Sobrienagain, the @code{TREE_VALUE} is the corresponding initializer. If the 223090075Sobrien@code{TREE_PURPOSE} is @code{NULL_TREE}, then the initializer is for the 223190075Sobriennext available array element. 223290075Sobrien 223390075SobrienConceptually, before any initialization is done, the entire area of 223490075Sobrienstorage is initialized to zero. 223590075Sobrien 223690075Sobrien@item COMPOUND_LITERAL_EXPR 223790075Sobrien@findex COMPOUND_LITERAL_EXPR_DECL_STMT 223890075Sobrien@findex COMPOUND_LITERAL_EXPR_DECL 223990075SobrienThese nodes represent ISO C99 compound literals. The 224090075Sobrien@code{COMPOUND_LITERAL_EXPR_DECL_STMT} is a @code{DECL_STMT} 224190075Sobriencontaining an anonymous @code{VAR_DECL} for 224290075Sobrienthe unnamed object represented by the compound literal; the 224390075Sobrien@code{DECL_INITIAL} of that @code{VAR_DECL} is a @code{CONSTRUCTOR} 224490075Sobrienrepresenting the brace-enclosed list of initializers in the compound 224590075Sobrienliteral. That anonymous @code{VAR_DECL} can also be accessed directly 224690075Sobrienby the @code{COMPOUND_LITERAL_EXPR_DECL} macro. 224790075Sobrien 224890075Sobrien@item SAVE_EXPR 224990075Sobrien 225090075SobrienA @code{SAVE_EXPR} represents an expression (possibly involving 225190075Sobrienside-effects) that is used more than once. The side-effects should 225290075Sobrienoccur only the first time the expression is evaluated. Subsequent uses 225390075Sobrienshould just reuse the computed value. The first operand to the 225490075Sobrien@code{SAVE_EXPR} is the expression to evaluate. The side-effects should 225590075Sobrienbe executed where the @code{SAVE_EXPR} is first encountered in a 225690075Sobriendepth-first preorder traversal of the expression tree. 225790075Sobrien 225890075Sobrien@item TARGET_EXPR 225990075SobrienA @code{TARGET_EXPR} represents a temporary object. The first operand 226090075Sobrienis a @code{VAR_DECL} for the temporary variable. The second operand is 226190075Sobrienthe initializer for the temporary. The initializer is evaluated, and 226290075Sobriencopied (bitwise) into the temporary. 226390075Sobrien 226490075SobrienOften, a @code{TARGET_EXPR} occurs on the right-hand side of an 226590075Sobrienassignment, or as the second operand to a comma-expression which is 226690075Sobrienitself the right-hand side of an assignment, etc. In this case, we say 226790075Sobrienthat the @code{TARGET_EXPR} is ``normal''; otherwise, we say it is 226890075Sobrien``orphaned''. For a normal @code{TARGET_EXPR} the temporary variable 226990075Sobrienshould be treated as an alias for the left-hand side of the assignment, 227090075Sobrienrather than as a new temporary variable. 227190075Sobrien 227290075SobrienThe third operand to the @code{TARGET_EXPR}, if present, is a 227390075Sobriencleanup-expression (i.e., destructor call) for the temporary. If this 227490075Sobrienexpression is orphaned, then this expression must be executed when the 227590075Sobrienstatement containing this expression is complete. These cleanups must 227690075Sobrienalways be executed in the order opposite to that in which they were 227790075Sobrienencountered. Note that if a temporary is created on one branch of a 227890075Sobrienconditional operator (i.e., in the second or third operand to a 227990075Sobrien@code{COND_EXPR}), the cleanup must be run only if that branch is 228090075Sobrienactually executed. 228190075Sobrien 228290075SobrienSee @code{STMT_IS_FULL_EXPR_P} for more information about running these 228390075Sobriencleanups. 228490075Sobrien 228590075Sobrien@item AGGR_INIT_EXPR 228690075SobrienAn @code{AGGR_INIT_EXPR} represents the initialization as the return 228790075Sobrienvalue of a function call, or as the result of a constructor. An 228890075Sobrien@code{AGGR_INIT_EXPR} will only appear as the second operand of a 228990075Sobrien@code{TARGET_EXPR}. The first operand to the @code{AGGR_INIT_EXPR} is 229090075Sobrienthe address of a function to call, just as in a @code{CALL_EXPR}. The 229190075Sobriensecond operand are the arguments to pass that function, as a 229290075Sobrien@code{TREE_LIST}, again in a manner similar to that of a 229390075Sobrien@code{CALL_EXPR}. The value of the expression is that returned by the 229490075Sobrienfunction. 229590075Sobrien 229690075SobrienIf @code{AGGR_INIT_VIA_CTOR_P} holds of the @code{AGGR_INIT_EXPR}, then 229790075Sobrienthe initialization is via a constructor call. The address of the third 229890075Sobrienoperand of the @code{AGGR_INIT_EXPR}, which is always a @code{VAR_DECL}, 229990075Sobrienis taken, and this value replaces the first argument in the argument 230090075Sobrienlist. In this case, the value of the expression is the @code{VAR_DECL} 230190075Sobriengiven by the third operand to the @code{AGGR_INIT_EXPR}; constructors do 230290075Sobriennot return a value. 230390075Sobrien 230490075Sobrien@item VTABLE_REF 230590075SobrienA @code{VTABLE_REF} indicates that the interior expression computes 230690075Sobriena value that is a vtable entry. It is used with @option{-fvtable-gc} 230790075Sobriento track the reference through to front end to the middle end, at 230890075Sobrienwhich point we transform this to a @code{REG_VTABLE_REF} note, which 230990075Sobriensurvives the balance of code generation. 231090075Sobrien 231190075SobrienThe first operand is the expression that computes the vtable reference. 231290075SobrienThe second operand is the @code{VAR_DECL} of the vtable. The third 231390075Sobrienoperand is an @code{INTEGER_CST} of the byte offset into the vtable. 231490075Sobrien 231590075Sobrien@end table 2316