1e4b17023SJohn Marino@c Copyright (c) 2004, 2005, 2007, 2008, 2010 Free Software Foundation, Inc. 2e4b17023SJohn Marino@c Free Software Foundation, Inc. 3e4b17023SJohn Marino@c This is part of the GCC manual. 4e4b17023SJohn Marino@c For copying conditions, see the file gcc.texi. 5e4b17023SJohn Marino 6e4b17023SJohn Marino@c --------------------------------------------------------------------- 7e4b17023SJohn Marino@c GENERIC 8e4b17023SJohn Marino@c --------------------------------------------------------------------- 9e4b17023SJohn Marino 10e4b17023SJohn Marino@node GENERIC 11e4b17023SJohn Marino@chapter GENERIC 12e4b17023SJohn Marino@cindex GENERIC 13e4b17023SJohn Marino 14e4b17023SJohn MarinoThe purpose of GENERIC is simply to provide a 15e4b17023SJohn Marinolanguage-independent way of representing an entire function in 16e4b17023SJohn Marinotrees. To this end, it was necessary to add a few new tree codes 17e4b17023SJohn Marinoto the back end, but most everything was already there. If you 18e4b17023SJohn Marinocan express it with the codes in @code{gcc/tree.def}, it's 19e4b17023SJohn MarinoGENERIC@. 20e4b17023SJohn Marino 21e4b17023SJohn MarinoEarly on, there was a great deal of debate about how to think 22e4b17023SJohn Marinoabout statements in a tree IL@. In GENERIC, a statement is 23e4b17023SJohn Marinodefined as any expression whose value, if any, is ignored. A 24e4b17023SJohn Marinostatement will always have @code{TREE_SIDE_EFFECTS} set (or it 25e4b17023SJohn Marinowill be discarded), but a non-statement expression may also have 26e4b17023SJohn Marinoside effects. A @code{CALL_EXPR}, for instance. 27e4b17023SJohn Marino 28e4b17023SJohn MarinoIt would be possible for some local optimizations to work on the 29e4b17023SJohn MarinoGENERIC form of a function; indeed, the adapted tree inliner 30e4b17023SJohn Marinoworks fine on GENERIC, but the current compiler performs inlining 31e4b17023SJohn Marinoafter lowering to GIMPLE (a restricted form described in the next 32e4b17023SJohn Marinosection). Indeed, currently the frontends perform this lowering 33e4b17023SJohn Marinobefore handing off to @code{tree_rest_of_compilation}, but this 34e4b17023SJohn Marinoseems inelegant. 35e4b17023SJohn Marino 36e4b17023SJohn Marino@menu 37e4b17023SJohn Marino* Deficiencies:: Topics net yet covered in this document. 38e4b17023SJohn Marino* Tree overview:: All about @code{tree}s. 39e4b17023SJohn Marino* Types:: Fundamental and aggregate types. 40e4b17023SJohn Marino* Declarations:: Type declarations and variables. 41e4b17023SJohn Marino* Attributes:: Declaration and type attributes. 42e4b17023SJohn Marino* Expressions: Expression trees. Operating on data. 43e4b17023SJohn Marino* Statements:: Control flow and related trees. 44e4b17023SJohn Marino* Functions:: Function bodies, linkage, and other aspects. 45e4b17023SJohn Marino* Language-dependent trees:: Topics and trees specific to language front ends. 46e4b17023SJohn Marino* C and C++ Trees:: Trees specific to C and C++. 47e4b17023SJohn Marino* Java Trees:: Trees specific to Java. 48e4b17023SJohn Marino@end menu 49e4b17023SJohn Marino 50e4b17023SJohn Marino@c --------------------------------------------------------------------- 51e4b17023SJohn Marino@c Deficiencies 52e4b17023SJohn Marino@c --------------------------------------------------------------------- 53e4b17023SJohn Marino 54e4b17023SJohn Marino@node Deficiencies 55e4b17023SJohn Marino@section Deficiencies 56e4b17023SJohn Marino 57e4b17023SJohn MarinoThere are many places in which this document is incomplet and incorrekt. 58e4b17023SJohn MarinoIt is, as of yet, only @emph{preliminary} documentation. 59e4b17023SJohn Marino 60e4b17023SJohn Marino@c --------------------------------------------------------------------- 61e4b17023SJohn Marino@c Overview 62e4b17023SJohn Marino@c --------------------------------------------------------------------- 63e4b17023SJohn Marino 64e4b17023SJohn Marino@node Tree overview 65e4b17023SJohn Marino@section Overview 66e4b17023SJohn Marino@cindex tree 67e4b17023SJohn Marino@findex TREE_CODE 68e4b17023SJohn Marino 69e4b17023SJohn MarinoThe central data structure used by the internal representation is the 70e4b17023SJohn Marino@code{tree}. These nodes, while all of the C type @code{tree}, are of 71e4b17023SJohn Marinomany varieties. A @code{tree} is a pointer type, but the object to 72e4b17023SJohn Marinowhich it points may be of a variety of types. From this point forward, 73e4b17023SJohn Marinowe will refer to trees in ordinary type, rather than in @code{this 74e4b17023SJohn Marinofont}, except when talking about the actual C type @code{tree}. 75e4b17023SJohn Marino 76e4b17023SJohn MarinoYou can tell what kind of node a particular tree is by using the 77e4b17023SJohn Marino@code{TREE_CODE} macro. Many, many macros take trees as input and 78e4b17023SJohn Marinoreturn trees as output. However, most macros require a certain kind of 79e4b17023SJohn Marinotree node as input. In other words, there is a type-system for trees, 80e4b17023SJohn Marinobut it is not reflected in the C type-system. 81e4b17023SJohn Marino 82e4b17023SJohn MarinoFor safety, it is useful to configure GCC with @option{--enable-checking}. 83e4b17023SJohn MarinoAlthough this results in a significant performance penalty (since all 84e4b17023SJohn Marinotree types are checked at run-time), and is therefore inappropriate in a 85e4b17023SJohn Marinorelease version, it is extremely helpful during the development process. 86e4b17023SJohn Marino 87e4b17023SJohn MarinoMany macros behave as predicates. Many, although not all, of these 88e4b17023SJohn Marinopredicates end in @samp{_P}. Do not rely on the result type of these 89e4b17023SJohn Marinomacros being of any particular type. You may, however, rely on the fact 90e4b17023SJohn Marinothat the type can be compared to @code{0}, so that statements like 91e4b17023SJohn Marino@smallexample 92e4b17023SJohn Marinoif (TEST_P (t) && !TEST_P (y)) 93e4b17023SJohn Marino x = 1; 94e4b17023SJohn Marino@end smallexample 95e4b17023SJohn Marino@noindent 96e4b17023SJohn Marinoand 97e4b17023SJohn Marino@smallexample 98e4b17023SJohn Marinoint i = (TEST_P (t) != 0); 99e4b17023SJohn Marino@end smallexample 100e4b17023SJohn Marino@noindent 101e4b17023SJohn Marinoare legal. Macros that return @code{int} values now may be changed to 102e4b17023SJohn Marinoreturn @code{tree} values, or other pointers in the future. Even those 103e4b17023SJohn Marinothat continue to return @code{int} may return multiple nonzero codes 104e4b17023SJohn Marinowhere previously they returned only zero and one. Therefore, you should 105e4b17023SJohn Marinonot write code like 106e4b17023SJohn Marino@smallexample 107e4b17023SJohn Marinoif (TEST_P (t) == 1) 108e4b17023SJohn Marino@end smallexample 109e4b17023SJohn Marino@noindent 110e4b17023SJohn Marinoas this code is not guaranteed to work correctly in the future. 111e4b17023SJohn Marino 112e4b17023SJohn MarinoYou should not take the address of values returned by the macros or 113e4b17023SJohn Marinofunctions described here. In particular, no guarantee is given that the 114e4b17023SJohn Marinovalues are lvalues. 115e4b17023SJohn Marino 116e4b17023SJohn MarinoIn general, the names of macros are all in uppercase, while the names of 117e4b17023SJohn Marinofunctions are entirely in lowercase. There are rare exceptions to this 118e4b17023SJohn Marinorule. You should assume that any macro or function whose name is made 119e4b17023SJohn Marinoup entirely of uppercase letters may evaluate its arguments more than 120e4b17023SJohn Marinoonce. You may assume that a macro or function whose name is made up 121e4b17023SJohn Marinoentirely of lowercase letters will evaluate its arguments only once. 122e4b17023SJohn Marino 123e4b17023SJohn MarinoThe @code{error_mark_node} is a special tree. Its tree code is 124e4b17023SJohn Marino@code{ERROR_MARK}, but since there is only ever one node with that code, 125e4b17023SJohn Marinothe usual practice is to compare the tree against 126e4b17023SJohn Marino@code{error_mark_node}. (This test is just a test for pointer 127e4b17023SJohn Marinoequality.) If an error has occurred during front-end processing the 128e4b17023SJohn Marinoflag @code{errorcount} will be set. If the front end has encountered 129e4b17023SJohn Marinocode it cannot handle, it will issue a message to the user and set 130e4b17023SJohn Marino@code{sorrycount}. When these flags are set, any macro or function 131e4b17023SJohn Marinowhich normally returns a tree of a particular kind may instead return 132e4b17023SJohn Marinothe @code{error_mark_node}. Thus, if you intend to do any processing of 133e4b17023SJohn Marinoerroneous code, you must be prepared to deal with the 134e4b17023SJohn Marino@code{error_mark_node}. 135e4b17023SJohn Marino 136e4b17023SJohn MarinoOccasionally, a particular tree slot (like an operand to an expression, 137e4b17023SJohn Marinoor a particular field in a declaration) will be referred to as 138e4b17023SJohn Marino``reserved for the back end''. These slots are used to store RTL when 139e4b17023SJohn Marinothe tree is converted to RTL for use by the GCC back end. However, if 140e4b17023SJohn Marinothat process is not taking place (e.g., if the front end is being hooked 141e4b17023SJohn Marinoup to an intelligent editor), then those slots may be used by the 142e4b17023SJohn Marinoback end presently in use. 143e4b17023SJohn Marino 144e4b17023SJohn MarinoIf you encounter situations that do not match this documentation, such 145e4b17023SJohn Marinoas tree nodes of types not mentioned here, or macros documented to 146e4b17023SJohn Marinoreturn entities of a particular kind that instead return entities of 147e4b17023SJohn Marinosome different kind, you have found a bug, either in the front end or in 148e4b17023SJohn Marinothe documentation. Please report these bugs as you would any other 149e4b17023SJohn Marinobug. 150e4b17023SJohn Marino 151e4b17023SJohn Marino@menu 152e4b17023SJohn Marino* Macros and Functions::Macros and functions that can be used with all trees. 153e4b17023SJohn Marino* Identifiers:: The names of things. 154e4b17023SJohn Marino* Containers:: Lists and vectors. 155e4b17023SJohn Marino@end menu 156e4b17023SJohn Marino 157e4b17023SJohn Marino@c --------------------------------------------------------------------- 158e4b17023SJohn Marino@c Trees 159e4b17023SJohn Marino@c --------------------------------------------------------------------- 160e4b17023SJohn Marino 161e4b17023SJohn Marino@node Macros and Functions 162e4b17023SJohn Marino@subsection Trees 163e4b17023SJohn Marino@cindex tree 164e4b17023SJohn Marino@findex TREE_CHAIN 165e4b17023SJohn Marino@findex TREE_TYPE 166e4b17023SJohn Marino 167e4b17023SJohn MarinoAll GENERIC trees have two fields in common. First, @code{TREE_CHAIN} 168e4b17023SJohn Marinois a pointer that can be used as a singly-linked list to other trees. 169e4b17023SJohn MarinoThe other is @code{TREE_TYPE}. Many trees store the type of an 170e4b17023SJohn Marinoexpression or declaration in this field. 171e4b17023SJohn Marino 172e4b17023SJohn MarinoThese are some other functions for handling trees: 173e4b17023SJohn Marino 174e4b17023SJohn Marino@ftable @code 175e4b17023SJohn Marino 176e4b17023SJohn Marino@item tree_size 177e4b17023SJohn MarinoReturn the number of bytes a tree takes. 178e4b17023SJohn Marino 179e4b17023SJohn Marino@item build0 180e4b17023SJohn Marino@itemx build1 181e4b17023SJohn Marino@itemx build2 182e4b17023SJohn Marino@itemx build3 183e4b17023SJohn Marino@itemx build4 184e4b17023SJohn Marino@itemx build5 185e4b17023SJohn Marino@itemx build6 186e4b17023SJohn Marino 187e4b17023SJohn MarinoThese functions build a tree and supply values to put in each 188e4b17023SJohn Marinoparameter. The basic signature is @samp{@w{code, type, [operands]}}. 189e4b17023SJohn Marino@code{code} is the @code{TREE_CODE}, and @code{type} is a tree 190e4b17023SJohn Marinorepresenting the @code{TREE_TYPE}. These are followed by the 191e4b17023SJohn Marinooperands, each of which is also a tree. 192e4b17023SJohn Marino 193e4b17023SJohn Marino@end ftable 194e4b17023SJohn Marino 195e4b17023SJohn Marino 196e4b17023SJohn Marino@c --------------------------------------------------------------------- 197e4b17023SJohn Marino@c Identifiers 198e4b17023SJohn Marino@c --------------------------------------------------------------------- 199e4b17023SJohn Marino 200e4b17023SJohn Marino@node Identifiers 201e4b17023SJohn Marino@subsection Identifiers 202e4b17023SJohn Marino@cindex identifier 203e4b17023SJohn Marino@cindex name 204e4b17023SJohn Marino@tindex IDENTIFIER_NODE 205e4b17023SJohn Marino 206e4b17023SJohn MarinoAn @code{IDENTIFIER_NODE} represents a slightly more general concept 207e4b17023SJohn Marinothat the standard C or C++ concept of identifier. In particular, an 208e4b17023SJohn Marino@code{IDENTIFIER_NODE} may contain a @samp{$}, or other extraordinary 209e4b17023SJohn Marinocharacters. 210e4b17023SJohn Marino 211e4b17023SJohn MarinoThere are never two distinct @code{IDENTIFIER_NODE}s representing the 212e4b17023SJohn Marinosame identifier. Therefore, you may use pointer equality to compare 213e4b17023SJohn Marino@code{IDENTIFIER_NODE}s, rather than using a routine like 214e4b17023SJohn Marino@code{strcmp}. Use @code{get_identifier} to obtain the unique 215e4b17023SJohn Marino@code{IDENTIFIER_NODE} for a supplied string. 216e4b17023SJohn Marino 217e4b17023SJohn MarinoYou can use the following macros to access identifiers: 218e4b17023SJohn Marino@ftable @code 219e4b17023SJohn Marino@item IDENTIFIER_POINTER 220e4b17023SJohn MarinoThe string represented by the identifier, represented as a 221e4b17023SJohn Marino@code{char*}. This string is always @code{NUL}-terminated, and contains 222e4b17023SJohn Marinono embedded @code{NUL} characters. 223e4b17023SJohn Marino 224e4b17023SJohn Marino@item IDENTIFIER_LENGTH 225e4b17023SJohn MarinoThe length of the string returned by @code{IDENTIFIER_POINTER}, not 226e4b17023SJohn Marinoincluding the trailing @code{NUL}. This value of 227e4b17023SJohn Marino@code{IDENTIFIER_LENGTH (x)} is always the same as @code{strlen 228e4b17023SJohn Marino(IDENTIFIER_POINTER (x))}. 229e4b17023SJohn Marino 230e4b17023SJohn Marino@item IDENTIFIER_OPNAME_P 231e4b17023SJohn MarinoThis predicate holds if the identifier represents the name of an 232e4b17023SJohn Marinooverloaded operator. In this case, you should not depend on the 233e4b17023SJohn Marinocontents of either the @code{IDENTIFIER_POINTER} or the 234e4b17023SJohn Marino@code{IDENTIFIER_LENGTH}. 235e4b17023SJohn Marino 236e4b17023SJohn Marino@item IDENTIFIER_TYPENAME_P 237e4b17023SJohn MarinoThis predicate holds if the identifier represents the name of a 238e4b17023SJohn Marinouser-defined conversion operator. In this case, the @code{TREE_TYPE} of 239e4b17023SJohn Marinothe @code{IDENTIFIER_NODE} holds the type to which the conversion 240e4b17023SJohn Marinooperator converts. 241e4b17023SJohn Marino 242e4b17023SJohn Marino@end ftable 243e4b17023SJohn Marino 244e4b17023SJohn Marino@c --------------------------------------------------------------------- 245e4b17023SJohn Marino@c Containers 246e4b17023SJohn Marino@c --------------------------------------------------------------------- 247e4b17023SJohn Marino 248e4b17023SJohn Marino@node Containers 249e4b17023SJohn Marino@subsection Containers 250e4b17023SJohn Marino@cindex container 251e4b17023SJohn Marino@cindex list 252e4b17023SJohn Marino@cindex vector 253e4b17023SJohn Marino@tindex TREE_LIST 254e4b17023SJohn Marino@tindex TREE_VEC 255e4b17023SJohn Marino@findex TREE_PURPOSE 256e4b17023SJohn Marino@findex TREE_VALUE 257e4b17023SJohn Marino@findex TREE_VEC_LENGTH 258e4b17023SJohn Marino@findex TREE_VEC_ELT 259e4b17023SJohn Marino 260e4b17023SJohn MarinoTwo common container data structures can be represented directly with 261e4b17023SJohn Marinotree nodes. A @code{TREE_LIST} is a singly linked list containing two 262e4b17023SJohn Marinotrees per node. These are the @code{TREE_PURPOSE} and @code{TREE_VALUE} 263e4b17023SJohn Marinoof each node. (Often, the @code{TREE_PURPOSE} contains some kind of 264e4b17023SJohn Marinotag, or additional information, while the @code{TREE_VALUE} contains the 265e4b17023SJohn Marinomajority of the payload. In other cases, the @code{TREE_PURPOSE} is 266e4b17023SJohn Marinosimply @code{NULL_TREE}, while in still others both the 267e4b17023SJohn Marino@code{TREE_PURPOSE} and @code{TREE_VALUE} are of equal stature.) Given 268e4b17023SJohn Marinoone @code{TREE_LIST} node, the next node is found by following the 269e4b17023SJohn Marino@code{TREE_CHAIN}. If the @code{TREE_CHAIN} is @code{NULL_TREE}, then 270e4b17023SJohn Marinoyou have reached the end of the list. 271e4b17023SJohn Marino 272e4b17023SJohn MarinoA @code{TREE_VEC} is a simple vector. The @code{TREE_VEC_LENGTH} is an 273e4b17023SJohn Marinointeger (not a tree) giving the number of nodes in the vector. The 274e4b17023SJohn Marinonodes themselves are accessed using the @code{TREE_VEC_ELT} macro, which 275e4b17023SJohn Marinotakes two arguments. The first is the @code{TREE_VEC} in question; the 276e4b17023SJohn Marinosecond is an integer indicating which element in the vector is desired. 277e4b17023SJohn MarinoThe elements are indexed from zero. 278e4b17023SJohn Marino 279e4b17023SJohn Marino@c --------------------------------------------------------------------- 280e4b17023SJohn Marino@c Types 281e4b17023SJohn Marino@c --------------------------------------------------------------------- 282e4b17023SJohn Marino 283e4b17023SJohn Marino@node Types 284e4b17023SJohn Marino@section Types 285e4b17023SJohn Marino@cindex type 286e4b17023SJohn Marino@cindex pointer 287e4b17023SJohn Marino@cindex reference 288e4b17023SJohn Marino@cindex fundamental type 289e4b17023SJohn Marino@cindex array 290e4b17023SJohn Marino@tindex VOID_TYPE 291e4b17023SJohn Marino@tindex INTEGER_TYPE 292e4b17023SJohn Marino@tindex TYPE_MIN_VALUE 293e4b17023SJohn Marino@tindex TYPE_MAX_VALUE 294e4b17023SJohn Marino@tindex REAL_TYPE 295e4b17023SJohn Marino@tindex FIXED_POINT_TYPE 296e4b17023SJohn Marino@tindex COMPLEX_TYPE 297e4b17023SJohn Marino@tindex ENUMERAL_TYPE 298e4b17023SJohn Marino@tindex BOOLEAN_TYPE 299e4b17023SJohn Marino@tindex POINTER_TYPE 300e4b17023SJohn Marino@tindex REFERENCE_TYPE 301e4b17023SJohn Marino@tindex FUNCTION_TYPE 302e4b17023SJohn Marino@tindex METHOD_TYPE 303e4b17023SJohn Marino@tindex ARRAY_TYPE 304e4b17023SJohn Marino@tindex RECORD_TYPE 305e4b17023SJohn Marino@tindex UNION_TYPE 306e4b17023SJohn Marino@tindex UNKNOWN_TYPE 307e4b17023SJohn Marino@tindex OFFSET_TYPE 308e4b17023SJohn Marino@findex TYPE_UNQUALIFIED 309e4b17023SJohn Marino@findex TYPE_QUAL_CONST 310e4b17023SJohn Marino@findex TYPE_QUAL_VOLATILE 311e4b17023SJohn Marino@findex TYPE_QUAL_RESTRICT 312e4b17023SJohn Marino@findex TYPE_MAIN_VARIANT 313e4b17023SJohn Marino@cindex qualified type 314e4b17023SJohn Marino@findex TYPE_SIZE 315e4b17023SJohn Marino@findex TYPE_ALIGN 316e4b17023SJohn Marino@findex TYPE_PRECISION 317e4b17023SJohn Marino@findex TYPE_ARG_TYPES 318e4b17023SJohn Marino@findex TYPE_METHOD_BASETYPE 319e4b17023SJohn Marino@findex TYPE_OFFSET_BASETYPE 320e4b17023SJohn Marino@findex TREE_TYPE 321e4b17023SJohn Marino@findex TYPE_CONTEXT 322e4b17023SJohn Marino@findex TYPE_NAME 323e4b17023SJohn Marino@findex TYPENAME_TYPE_FULLNAME 324e4b17023SJohn Marino@findex TYPE_FIELDS 325e4b17023SJohn Marino@findex TYPE_CANONICAL 326e4b17023SJohn Marino@findex TYPE_STRUCTURAL_EQUALITY_P 327e4b17023SJohn Marino@findex SET_TYPE_STRUCTURAL_EQUALITY 328e4b17023SJohn Marino 329e4b17023SJohn MarinoAll types have corresponding tree nodes. However, you should not assume 330e4b17023SJohn Marinothat there is exactly one tree node corresponding to each type. There 331e4b17023SJohn Marinoare often multiple nodes corresponding to the same type. 332e4b17023SJohn Marino 333e4b17023SJohn MarinoFor the most part, different kinds of types have different tree codes. 334e4b17023SJohn Marino(For example, pointer types use a @code{POINTER_TYPE} code while arrays 335e4b17023SJohn Marinouse an @code{ARRAY_TYPE} code.) However, pointers to member functions 336e4b17023SJohn Marinouse the @code{RECORD_TYPE} code. Therefore, when writing a 337e4b17023SJohn Marino@code{switch} statement that depends on the code associated with a 338e4b17023SJohn Marinoparticular type, you should take care to handle pointers to member 339e4b17023SJohn Marinofunctions under the @code{RECORD_TYPE} case label. 340e4b17023SJohn Marino 341e4b17023SJohn MarinoThe following functions and macros deal with cv-qualification of types: 342e4b17023SJohn Marino@ftable @code 343e4b17023SJohn Marino@item TYPE_MAIN_VARIANT 344e4b17023SJohn MarinoThis macro returns the unqualified version of a type. It may be applied 345e4b17023SJohn Marinoto an unqualified type, but it is not always the identity function in 346e4b17023SJohn Marinothat case. 347e4b17023SJohn Marino@end ftable 348e4b17023SJohn Marino 349e4b17023SJohn MarinoA few other macros and functions are usable with all types: 350e4b17023SJohn Marino@ftable @code 351e4b17023SJohn Marino@item TYPE_SIZE 352e4b17023SJohn MarinoThe number of bits required to represent the type, represented as an 353e4b17023SJohn Marino@code{INTEGER_CST}. For an incomplete type, @code{TYPE_SIZE} will be 354e4b17023SJohn Marino@code{NULL_TREE}. 355e4b17023SJohn Marino 356e4b17023SJohn Marino@item TYPE_ALIGN 357e4b17023SJohn MarinoThe alignment of the type, in bits, represented as an @code{int}. 358e4b17023SJohn Marino 359e4b17023SJohn Marino@item TYPE_NAME 360e4b17023SJohn MarinoThis macro returns a declaration (in the form of a @code{TYPE_DECL}) for 361e4b17023SJohn Marinothe type. (Note this macro does @emph{not} return an 362e4b17023SJohn Marino@code{IDENTIFIER_NODE}, as you might expect, given its name!) You can 363e4b17023SJohn Marinolook at the @code{DECL_NAME} of the @code{TYPE_DECL} to obtain the 364e4b17023SJohn Marinoactual name of the type. The @code{TYPE_NAME} will be @code{NULL_TREE} 365e4b17023SJohn Marinofor a type that is not a built-in type, the result of a typedef, or a 366e4b17023SJohn Marinonamed class type. 367e4b17023SJohn Marino 368e4b17023SJohn Marino@item TYPE_CANONICAL 369e4b17023SJohn MarinoThis macro returns the ``canonical'' type for the given type 370e4b17023SJohn Marinonode. Canonical types are used to improve performance in the C++ and 371e4b17023SJohn MarinoObjective-C++ front ends by allowing efficient comparison between two 372e4b17023SJohn Marinotype nodes in @code{same_type_p}: if the @code{TYPE_CANONICAL} values 373e4b17023SJohn Marinoof the types are equal, the types are equivalent; otherwise, the types 374e4b17023SJohn Marinoare not equivalent. The notion of equivalence for canonical types is 375e4b17023SJohn Marinothe same as the notion of type equivalence in the language itself. For 376e4b17023SJohn Marinoinstance, 377e4b17023SJohn Marino 378e4b17023SJohn MarinoWhen @code{TYPE_CANONICAL} is @code{NULL_TREE}, there is no canonical 379e4b17023SJohn Marinotype for the given type node. In this case, comparison between this 380e4b17023SJohn Marinotype and any other type requires the compiler to perform a deep, 381e4b17023SJohn Marino``structural'' comparison to see if the two type nodes have the same 382e4b17023SJohn Marinoform and properties. 383e4b17023SJohn Marino 384e4b17023SJohn MarinoThe canonical type for a node is always the most fundamental type in 385e4b17023SJohn Marinothe equivalence class of types. For instance, @code{int} is its own 386e4b17023SJohn Marinocanonical type. A typedef @code{I} of @code{int} will have @code{int} 387e4b17023SJohn Marinoas its canonical type. Similarly, @code{I*}@ and a typedef @code{IP}@ 388e4b17023SJohn Marino(defined to @code{I*}) will has @code{int*} as their canonical 389e4b17023SJohn Marinotype. When building a new type node, be sure to set 390e4b17023SJohn Marino@code{TYPE_CANONICAL} to the appropriate canonical type. If the new 391e4b17023SJohn Marinotype is a compound type (built from other types), and any of those 392e4b17023SJohn Marinoother types require structural equality, use 393e4b17023SJohn Marino@code{SET_TYPE_STRUCTURAL_EQUALITY} to ensure that the new type also 394e4b17023SJohn Marinorequires structural equality. Finally, if for some reason you cannot 395e4b17023SJohn Marinoguarantee that @code{TYPE_CANONICAL} will point to the canonical type, 396e4b17023SJohn Marinouse @code{SET_TYPE_STRUCTURAL_EQUALITY} to make sure that the new 397e4b17023SJohn Marinotype--and any type constructed based on it--requires structural 398e4b17023SJohn Marinoequality. If you suspect that the canonical type system is 399e4b17023SJohn Marinomiscomparing types, pass @code{--param verify-canonical-types=1} to 400e4b17023SJohn Marinothe compiler or configure with @code{--enable-checking} to force the 401e4b17023SJohn Marinocompiler to verify its canonical-type comparisons against the 402e4b17023SJohn Marinostructural comparisons; the compiler will then print any warnings if 403e4b17023SJohn Marinothe canonical types miscompare. 404e4b17023SJohn Marino 405e4b17023SJohn Marino@item TYPE_STRUCTURAL_EQUALITY_P 406e4b17023SJohn MarinoThis predicate holds when the node requires structural equality 407e4b17023SJohn Marinochecks, e.g., when @code{TYPE_CANONICAL} is @code{NULL_TREE}. 408e4b17023SJohn Marino 409e4b17023SJohn Marino@item SET_TYPE_STRUCTURAL_EQUALITY 410e4b17023SJohn MarinoThis macro states that the type node it is given requires structural 411e4b17023SJohn Marinoequality checks, e.g., it sets @code{TYPE_CANONICAL} to 412e4b17023SJohn Marino@code{NULL_TREE}. 413e4b17023SJohn Marino 414e4b17023SJohn Marino@item same_type_p 415e4b17023SJohn MarinoThis predicate takes two types as input, and holds if they are the same 416e4b17023SJohn Marinotype. For example, if one type is a @code{typedef} for the other, or 417e4b17023SJohn Marinoboth are @code{typedef}s for the same type. This predicate also holds if 418e4b17023SJohn Marinothe two trees given as input are simply copies of one another; i.e., 419e4b17023SJohn Marinothere is no difference between them at the source level, but, for 420e4b17023SJohn Marinowhatever reason, a duplicate has been made in the representation. You 421e4b17023SJohn Marinoshould never use @code{==} (pointer equality) to compare types; always 422e4b17023SJohn Marinouse @code{same_type_p} instead. 423e4b17023SJohn Marino@end ftable 424e4b17023SJohn Marino 425e4b17023SJohn MarinoDetailed below are the various kinds of types, and the macros that can 426e4b17023SJohn Marinobe used to access them. Although other kinds of types are used 427e4b17023SJohn Marinoelsewhere in G++, the types described here are the only ones that you 428e4b17023SJohn Marinowill encounter while examining the intermediate representation. 429e4b17023SJohn Marino 430e4b17023SJohn Marino@table @code 431e4b17023SJohn Marino@item VOID_TYPE 432e4b17023SJohn MarinoUsed to represent the @code{void} type. 433e4b17023SJohn Marino 434e4b17023SJohn Marino@item INTEGER_TYPE 435e4b17023SJohn MarinoUsed to represent the various integral types, including @code{char}, 436e4b17023SJohn Marino@code{short}, @code{int}, @code{long}, and @code{long long}. This code 437e4b17023SJohn Marinois not used for enumeration types, nor for the @code{bool} type. 438e4b17023SJohn MarinoThe @code{TYPE_PRECISION} is the number of bits used in 439e4b17023SJohn Marinothe representation, represented as an @code{unsigned int}. (Note that 440e4b17023SJohn Marinoin the general case this is not the same value as @code{TYPE_SIZE}; 441e4b17023SJohn Marinosuppose that there were a 24-bit integer type, but that alignment 442e4b17023SJohn Marinorequirements for the ABI required 32-bit alignment. Then, 443e4b17023SJohn Marino@code{TYPE_SIZE} would be an @code{INTEGER_CST} for 32, while 444e4b17023SJohn Marino@code{TYPE_PRECISION} would be 24.) The integer type is unsigned if 445e4b17023SJohn Marino@code{TYPE_UNSIGNED} holds; otherwise, it is signed. 446e4b17023SJohn Marino 447e4b17023SJohn MarinoThe @code{TYPE_MIN_VALUE} is an @code{INTEGER_CST} for the smallest 448e4b17023SJohn Marinointeger that may be represented by this type. Similarly, the 449e4b17023SJohn Marino@code{TYPE_MAX_VALUE} is an @code{INTEGER_CST} for the largest integer 450e4b17023SJohn Marinothat may be represented by this type. 451e4b17023SJohn Marino 452e4b17023SJohn Marino@item REAL_TYPE 453e4b17023SJohn MarinoUsed to represent the @code{float}, @code{double}, and @code{long 454e4b17023SJohn Marinodouble} types. The number of bits in the floating-point representation 455e4b17023SJohn Marinois given by @code{TYPE_PRECISION}, as in the @code{INTEGER_TYPE} case. 456e4b17023SJohn Marino 457e4b17023SJohn Marino@item FIXED_POINT_TYPE 458e4b17023SJohn MarinoUsed to represent the @code{short _Fract}, @code{_Fract}, @code{long 459e4b17023SJohn Marino_Fract}, @code{long long _Fract}, @code{short _Accum}, @code{_Accum}, 460e4b17023SJohn Marino@code{long _Accum}, and @code{long long _Accum} types. The number of bits 461e4b17023SJohn Marinoin the fixed-point representation is given by @code{TYPE_PRECISION}, 462e4b17023SJohn Marinoas in the @code{INTEGER_TYPE} case. There may be padding bits, fractional 463e4b17023SJohn Marinobits and integral bits. The number of fractional bits is given by 464e4b17023SJohn Marino@code{TYPE_FBIT}, and the number of integral bits is given by @code{TYPE_IBIT}. 465e4b17023SJohn MarinoThe fixed-point type is unsigned if @code{TYPE_UNSIGNED} holds; otherwise, 466e4b17023SJohn Marinoit is signed. 467e4b17023SJohn MarinoThe fixed-point type is saturating if @code{TYPE_SATURATING} holds; otherwise, 468e4b17023SJohn Marinoit is not saturating. 469e4b17023SJohn Marino 470e4b17023SJohn Marino@item COMPLEX_TYPE 471e4b17023SJohn MarinoUsed to represent GCC built-in @code{__complex__} data types. The 472e4b17023SJohn Marino@code{TREE_TYPE} is the type of the real and imaginary parts. 473e4b17023SJohn Marino 474e4b17023SJohn Marino@item ENUMERAL_TYPE 475e4b17023SJohn MarinoUsed to represent an enumeration type. The @code{TYPE_PRECISION} gives 476e4b17023SJohn Marino(as an @code{int}), the number of bits used to represent the type. If 477e4b17023SJohn Marinothere are no negative enumeration constants, @code{TYPE_UNSIGNED} will 478e4b17023SJohn Marinohold. The minimum and maximum enumeration constants may be obtained 479e4b17023SJohn Marinowith @code{TYPE_MIN_VALUE} and @code{TYPE_MAX_VALUE}, respectively; each 480e4b17023SJohn Marinoof these macros returns an @code{INTEGER_CST}. 481e4b17023SJohn Marino 482e4b17023SJohn MarinoThe actual enumeration constants themselves may be obtained by looking 483e4b17023SJohn Marinoat the @code{TYPE_VALUES}. This macro will return a @code{TREE_LIST}, 484e4b17023SJohn Marinocontaining the constants. The @code{TREE_PURPOSE} of each node will be 485e4b17023SJohn Marinoan @code{IDENTIFIER_NODE} giving the name of the constant; the 486e4b17023SJohn Marino@code{TREE_VALUE} will be an @code{INTEGER_CST} giving the value 487e4b17023SJohn Marinoassigned to that constant. These constants will appear in the order in 488e4b17023SJohn Marinowhich they were declared. The @code{TREE_TYPE} of each of these 489e4b17023SJohn Marinoconstants will be the type of enumeration type itself. 490e4b17023SJohn Marino 491e4b17023SJohn Marino@item BOOLEAN_TYPE 492e4b17023SJohn MarinoUsed to represent the @code{bool} type. 493e4b17023SJohn Marino 494e4b17023SJohn Marino@item POINTER_TYPE 495e4b17023SJohn MarinoUsed to represent pointer types, and pointer to data member types. The 496e4b17023SJohn Marino@code{TREE_TYPE} gives the type to which this type points. 497e4b17023SJohn Marino 498e4b17023SJohn Marino@item REFERENCE_TYPE 499e4b17023SJohn MarinoUsed to represent reference types. The @code{TREE_TYPE} gives the type 500e4b17023SJohn Marinoto which this type refers. 501e4b17023SJohn Marino 502e4b17023SJohn Marino@item FUNCTION_TYPE 503e4b17023SJohn MarinoUsed to represent the type of non-member functions and of static member 504e4b17023SJohn Marinofunctions. The @code{TREE_TYPE} gives the return type of the function. 505e4b17023SJohn MarinoThe @code{TYPE_ARG_TYPES} are a @code{TREE_LIST} of the argument types. 506e4b17023SJohn MarinoThe @code{TREE_VALUE} of each node in this list is the type of the 507e4b17023SJohn Marinocorresponding argument; the @code{TREE_PURPOSE} is an expression for the 508e4b17023SJohn Marinodefault argument value, if any. If the last node in the list is 509e4b17023SJohn Marino@code{void_list_node} (a @code{TREE_LIST} node whose @code{TREE_VALUE} 510e4b17023SJohn Marinois the @code{void_type_node}), then functions of this type do not take 511e4b17023SJohn Marinovariable arguments. Otherwise, they do take a variable number of 512e4b17023SJohn Marinoarguments. 513e4b17023SJohn Marino 514e4b17023SJohn MarinoNote that in C (but not in C++) a function declared like @code{void f()} 515e4b17023SJohn Marinois an unprototyped function taking a variable number of arguments; the 516e4b17023SJohn Marino@code{TYPE_ARG_TYPES} of such a function will be @code{NULL}. 517e4b17023SJohn Marino 518e4b17023SJohn Marino@item METHOD_TYPE 519e4b17023SJohn MarinoUsed to represent the type of a non-static member function. Like a 520e4b17023SJohn Marino@code{FUNCTION_TYPE}, the return type is given by the @code{TREE_TYPE}. 521e4b17023SJohn MarinoThe type of @code{*this}, i.e., the class of which functions of this 522e4b17023SJohn Marinotype are a member, is given by the @code{TYPE_METHOD_BASETYPE}. The 523e4b17023SJohn Marino@code{TYPE_ARG_TYPES} is the parameter list, as for a 524e4b17023SJohn Marino@code{FUNCTION_TYPE}, and includes the @code{this} argument. 525e4b17023SJohn Marino 526e4b17023SJohn Marino@item ARRAY_TYPE 527e4b17023SJohn MarinoUsed to represent array types. The @code{TREE_TYPE} gives the type of 528e4b17023SJohn Marinothe elements in the array. If the array-bound is present in the type, 529e4b17023SJohn Marinothe @code{TYPE_DOMAIN} is an @code{INTEGER_TYPE} whose 530e4b17023SJohn Marino@code{TYPE_MIN_VALUE} and @code{TYPE_MAX_VALUE} will be the lower and 531e4b17023SJohn Marinoupper bounds of the array, respectively. The @code{TYPE_MIN_VALUE} will 532e4b17023SJohn Marinoalways be an @code{INTEGER_CST} for zero, while the 533e4b17023SJohn Marino@code{TYPE_MAX_VALUE} will be one less than the number of elements in 534e4b17023SJohn Marinothe array, i.e., the highest value which may be used to index an element 535e4b17023SJohn Marinoin the array. 536e4b17023SJohn Marino 537e4b17023SJohn Marino@item RECORD_TYPE 538e4b17023SJohn MarinoUsed to represent @code{struct} and @code{class} types, as well as 539e4b17023SJohn Marinopointers to member functions and similar constructs in other languages. 540e4b17023SJohn Marino@code{TYPE_FIELDS} contains the items contained in this type, each of 541e4b17023SJohn Marinowhich can be a @code{FIELD_DECL}, @code{VAR_DECL}, @code{CONST_DECL}, or 542e4b17023SJohn Marino@code{TYPE_DECL}. You may not make any assumptions about the ordering 543e4b17023SJohn Marinoof the fields in the type or whether one or more of them overlap. 544e4b17023SJohn Marino 545e4b17023SJohn Marino@item UNION_TYPE 546e4b17023SJohn MarinoUsed to represent @code{union} types. Similar to @code{RECORD_TYPE} 547e4b17023SJohn Marinoexcept that all @code{FIELD_DECL} nodes in @code{TYPE_FIELD} start at 548e4b17023SJohn Marinobit position zero. 549e4b17023SJohn Marino 550e4b17023SJohn Marino@item QUAL_UNION_TYPE 551e4b17023SJohn MarinoUsed to represent part of a variant record in Ada. Similar to 552e4b17023SJohn Marino@code{UNION_TYPE} except that each @code{FIELD_DECL} has a 553e4b17023SJohn Marino@code{DECL_QUALIFIER} field, which contains a boolean expression that 554e4b17023SJohn Marinoindicates whether the field is present in the object. The type will only 555e4b17023SJohn Marinohave one field, so each field's @code{DECL_QUALIFIER} is only evaluated 556e4b17023SJohn Marinoif none of the expressions in the previous fields in @code{TYPE_FIELDS} 557e4b17023SJohn Marinoare nonzero. Normally these expressions will reference a field in the 558e4b17023SJohn Marinoouter object using a @code{PLACEHOLDER_EXPR}. 559e4b17023SJohn Marino 560e4b17023SJohn Marino@item LANG_TYPE 561e4b17023SJohn MarinoThis node is used to represent a language-specific type. The front 562e4b17023SJohn Marinoend must handle it. 563e4b17023SJohn Marino 564e4b17023SJohn Marino@item OFFSET_TYPE 565e4b17023SJohn MarinoThis node is used to represent a pointer-to-data member. For a data 566e4b17023SJohn Marinomember @code{X::m} the @code{TYPE_OFFSET_BASETYPE} is @code{X} and the 567e4b17023SJohn Marino@code{TREE_TYPE} is the type of @code{m}. 568e4b17023SJohn Marino 569e4b17023SJohn Marino@end table 570e4b17023SJohn Marino 571e4b17023SJohn MarinoThere are variables whose values represent some of the basic types. 572e4b17023SJohn MarinoThese include: 573e4b17023SJohn Marino@table @code 574e4b17023SJohn Marino@item void_type_node 575e4b17023SJohn MarinoA node for @code{void}. 576e4b17023SJohn Marino 577e4b17023SJohn Marino@item integer_type_node 578e4b17023SJohn MarinoA node for @code{int}. 579e4b17023SJohn Marino 580e4b17023SJohn Marino@item unsigned_type_node. 581e4b17023SJohn MarinoA node for @code{unsigned int}. 582e4b17023SJohn Marino 583e4b17023SJohn Marino@item char_type_node. 584e4b17023SJohn MarinoA node for @code{char}. 585e4b17023SJohn Marino@end table 586e4b17023SJohn Marino@noindent 587e4b17023SJohn MarinoIt may sometimes be useful to compare one of these variables with a type 588e4b17023SJohn Marinoin hand, using @code{same_type_p}. 589e4b17023SJohn Marino 590e4b17023SJohn Marino@c --------------------------------------------------------------------- 591e4b17023SJohn Marino@c Declarations 592e4b17023SJohn Marino@c --------------------------------------------------------------------- 593e4b17023SJohn Marino 594e4b17023SJohn Marino@node Declarations 595e4b17023SJohn Marino@section Declarations 596e4b17023SJohn Marino@cindex declaration 597e4b17023SJohn Marino@cindex variable 598e4b17023SJohn Marino@cindex type declaration 599e4b17023SJohn Marino@tindex LABEL_DECL 600e4b17023SJohn Marino@tindex CONST_DECL 601e4b17023SJohn Marino@tindex TYPE_DECL 602e4b17023SJohn Marino@tindex VAR_DECL 603e4b17023SJohn Marino@tindex PARM_DECL 604e4b17023SJohn Marino@tindex DEBUG_EXPR_DECL 605e4b17023SJohn Marino@tindex FIELD_DECL 606e4b17023SJohn Marino@tindex NAMESPACE_DECL 607e4b17023SJohn Marino@tindex RESULT_DECL 608e4b17023SJohn Marino@tindex TEMPLATE_DECL 609e4b17023SJohn Marino@tindex THUNK_DECL 610e4b17023SJohn Marino@findex THUNK_DELTA 611e4b17023SJohn Marino@findex DECL_INITIAL 612e4b17023SJohn Marino@findex DECL_SIZE 613e4b17023SJohn Marino@findex DECL_ALIGN 614e4b17023SJohn Marino@findex DECL_EXTERNAL 615e4b17023SJohn Marino 616e4b17023SJohn MarinoThis section covers the various kinds of declarations that appear in the 617e4b17023SJohn Marinointernal representation, except for declarations of functions 618e4b17023SJohn Marino(represented by @code{FUNCTION_DECL} nodes), which are described in 619e4b17023SJohn Marino@ref{Functions}. 620e4b17023SJohn Marino 621e4b17023SJohn Marino@menu 622e4b17023SJohn Marino* Working with declarations:: Macros and functions that work on 623e4b17023SJohn Marinodeclarations. 624e4b17023SJohn Marino* Internal structure:: How declaration nodes are represented. 625e4b17023SJohn Marino@end menu 626e4b17023SJohn Marino 627e4b17023SJohn Marino@node Working with declarations 628e4b17023SJohn Marino@subsection Working with declarations 629e4b17023SJohn Marino 630e4b17023SJohn MarinoSome macros can be used with any kind of declaration. These include: 631e4b17023SJohn Marino@ftable @code 632e4b17023SJohn Marino@item DECL_NAME 633e4b17023SJohn MarinoThis macro returns an @code{IDENTIFIER_NODE} giving the name of the 634e4b17023SJohn Marinoentity. 635e4b17023SJohn Marino 636e4b17023SJohn Marino@item TREE_TYPE 637e4b17023SJohn MarinoThis macro returns the type of the entity declared. 638e4b17023SJohn Marino 639e4b17023SJohn Marino@item EXPR_FILENAME 640e4b17023SJohn MarinoThis macro returns the name of the file in which the entity was 641e4b17023SJohn Marinodeclared, as a @code{char*}. For an entity declared implicitly by the 642e4b17023SJohn Marinocompiler (like @code{__builtin_memcpy}), this will be the string 643e4b17023SJohn Marino@code{"<internal>"}. 644e4b17023SJohn Marino 645e4b17023SJohn Marino@item EXPR_LINENO 646e4b17023SJohn MarinoThis macro returns the line number at which the entity was declared, as 647e4b17023SJohn Marinoan @code{int}. 648e4b17023SJohn Marino 649e4b17023SJohn Marino@item DECL_ARTIFICIAL 650e4b17023SJohn MarinoThis predicate holds if the declaration was implicitly generated by the 651e4b17023SJohn Marinocompiler. For example, this predicate will hold of an implicitly 652e4b17023SJohn Marinodeclared member function, or of the @code{TYPE_DECL} implicitly 653e4b17023SJohn Marinogenerated for a class type. Recall that in C++ code like: 654e4b17023SJohn Marino@smallexample 655e4b17023SJohn Marinostruct S @{@}; 656e4b17023SJohn Marino@end smallexample 657e4b17023SJohn Marino@noindent 658e4b17023SJohn Marinois roughly equivalent to C code like: 659e4b17023SJohn Marino@smallexample 660e4b17023SJohn Marinostruct S @{@}; 661e4b17023SJohn Marinotypedef struct S S; 662e4b17023SJohn Marino@end smallexample 663e4b17023SJohn MarinoThe implicitly generated @code{typedef} declaration is represented by a 664e4b17023SJohn Marino@code{TYPE_DECL} for which @code{DECL_ARTIFICIAL} holds. 665e4b17023SJohn Marino 666e4b17023SJohn Marino@end ftable 667e4b17023SJohn Marino 668e4b17023SJohn MarinoThe various kinds of declarations include: 669e4b17023SJohn Marino@table @code 670e4b17023SJohn Marino@item LABEL_DECL 671e4b17023SJohn MarinoThese nodes are used to represent labels in function bodies. For more 672e4b17023SJohn Marinoinformation, see @ref{Functions}. These nodes only appear in block 673e4b17023SJohn Marinoscopes. 674e4b17023SJohn Marino 675e4b17023SJohn Marino@item CONST_DECL 676e4b17023SJohn MarinoThese nodes are used to represent enumeration constants. The value of 677e4b17023SJohn Marinothe constant is given by @code{DECL_INITIAL} which will be an 678e4b17023SJohn Marino@code{INTEGER_CST} with the same type as the @code{TREE_TYPE} of the 679e4b17023SJohn Marino@code{CONST_DECL}, i.e., an @code{ENUMERAL_TYPE}. 680e4b17023SJohn Marino 681e4b17023SJohn Marino@item RESULT_DECL 682e4b17023SJohn MarinoThese nodes represent the value returned by a function. When a value is 683e4b17023SJohn Marinoassigned to a @code{RESULT_DECL}, that indicates that the value should 684e4b17023SJohn Marinobe returned, via bitwise copy, by the function. You can use 685e4b17023SJohn Marino@code{DECL_SIZE} and @code{DECL_ALIGN} on a @code{RESULT_DECL}, just as 686e4b17023SJohn Marinowith a @code{VAR_DECL}. 687e4b17023SJohn Marino 688e4b17023SJohn Marino@item TYPE_DECL 689e4b17023SJohn MarinoThese nodes represent @code{typedef} declarations. The @code{TREE_TYPE} 690e4b17023SJohn Marinois the type declared to have the name given by @code{DECL_NAME}. In 691e4b17023SJohn Marinosome cases, there is no associated name. 692e4b17023SJohn Marino 693e4b17023SJohn Marino@item VAR_DECL 694e4b17023SJohn MarinoThese nodes represent variables with namespace or block scope, as well 695e4b17023SJohn Marinoas static data members. The @code{DECL_SIZE} and @code{DECL_ALIGN} are 696e4b17023SJohn Marinoanalogous to @code{TYPE_SIZE} and @code{TYPE_ALIGN}. For a declaration, 697e4b17023SJohn Marinoyou should always use the @code{DECL_SIZE} and @code{DECL_ALIGN} rather 698e4b17023SJohn Marinothan the @code{TYPE_SIZE} and @code{TYPE_ALIGN} given by the 699e4b17023SJohn Marino@code{TREE_TYPE}, since special attributes may have been applied to the 700e4b17023SJohn Marinovariable to give it a particular size and alignment. You may use the 701e4b17023SJohn Marinopredicates @code{DECL_THIS_STATIC} or @code{DECL_THIS_EXTERN} to test 702e4b17023SJohn Marinowhether the storage class specifiers @code{static} or @code{extern} were 703e4b17023SJohn Marinoused to declare a variable. 704e4b17023SJohn Marino 705e4b17023SJohn MarinoIf this variable is initialized (but does not require a constructor), 706e4b17023SJohn Marinothe @code{DECL_INITIAL} will be an expression for the initializer. The 707e4b17023SJohn Marinoinitializer should be evaluated, and a bitwise copy into the variable 708e4b17023SJohn Marinoperformed. If the @code{DECL_INITIAL} is the @code{error_mark_node}, 709e4b17023SJohn Marinothere is an initializer, but it is given by an explicit statement later 710e4b17023SJohn Marinoin the code; no bitwise copy is required. 711e4b17023SJohn Marino 712e4b17023SJohn MarinoGCC provides an extension that allows either automatic variables, or 713e4b17023SJohn Marinoglobal variables, to be placed in particular registers. This extension 714e4b17023SJohn Marinois being used for a particular @code{VAR_DECL} if @code{DECL_REGISTER} 715e4b17023SJohn Marinoholds for the @code{VAR_DECL}, and if @code{DECL_ASSEMBLER_NAME} is not 716e4b17023SJohn Marinoequal to @code{DECL_NAME}. In that case, @code{DECL_ASSEMBLER_NAME} is 717e4b17023SJohn Marinothe name of the register into which the variable will be placed. 718e4b17023SJohn Marino 719e4b17023SJohn Marino@item PARM_DECL 720e4b17023SJohn MarinoUsed to represent a parameter to a function. Treat these nodes 721e4b17023SJohn Marinosimilarly to @code{VAR_DECL} nodes. These nodes only appear in the 722e4b17023SJohn Marino@code{DECL_ARGUMENTS} for a @code{FUNCTION_DECL}. 723e4b17023SJohn Marino 724e4b17023SJohn MarinoThe @code{DECL_ARG_TYPE} for a @code{PARM_DECL} is the type that will 725e4b17023SJohn Marinoactually be used when a value is passed to this function. It may be a 726e4b17023SJohn Marinowider type than the @code{TREE_TYPE} of the parameter; for example, the 727e4b17023SJohn Marinoordinary type might be @code{short} while the @code{DECL_ARG_TYPE} is 728e4b17023SJohn Marino@code{int}. 729e4b17023SJohn Marino 730e4b17023SJohn Marino@item DEBUG_EXPR_DECL 731e4b17023SJohn MarinoUsed to represent an anonymous debug-information temporary created to 732e4b17023SJohn Marinohold an expression as it is optimized away, so that its value can be 733e4b17023SJohn Marinoreferenced in debug bind statements. 734e4b17023SJohn Marino 735e4b17023SJohn Marino@item FIELD_DECL 736e4b17023SJohn MarinoThese nodes represent non-static data members. The @code{DECL_SIZE} and 737e4b17023SJohn Marino@code{DECL_ALIGN} behave as for @code{VAR_DECL} nodes. 738e4b17023SJohn MarinoThe position of the field within the parent record is specified by a 739e4b17023SJohn Marinocombination of three attributes. @code{DECL_FIELD_OFFSET} is the position, 740e4b17023SJohn Marinocounting in bytes, of the @code{DECL_OFFSET_ALIGN}-bit sized word containing 741e4b17023SJohn Marinothe bit of the field closest to the beginning of the structure. 742e4b17023SJohn Marino@code{DECL_FIELD_BIT_OFFSET} is the bit offset of the first bit of the field 743e4b17023SJohn Marinowithin this word; this may be nonzero even for fields that are not bit-fields, 744e4b17023SJohn Marinosince @code{DECL_OFFSET_ALIGN} may be greater than the natural alignment 745e4b17023SJohn Marinoof the field's type. 746e4b17023SJohn Marino 747e4b17023SJohn MarinoIf @code{DECL_C_BIT_FIELD} holds, this field is a bit-field. In a bit-field, 748e4b17023SJohn Marino@code{DECL_BIT_FIELD_TYPE} also contains the type that was originally 749e4b17023SJohn Marinospecified for it, while DECL_TYPE may be a modified type with lesser precision, 750e4b17023SJohn Marinoaccording to the size of the bit field. 751e4b17023SJohn Marino 752e4b17023SJohn Marino@item NAMESPACE_DECL 753e4b17023SJohn MarinoNamespaces provide a name hierarchy for other declarations. They 754e4b17023SJohn Marinoappear in the @code{DECL_CONTEXT} of other @code{_DECL} nodes. 755e4b17023SJohn Marino 756e4b17023SJohn Marino@end table 757e4b17023SJohn Marino 758e4b17023SJohn Marino@node Internal structure 759e4b17023SJohn Marino@subsection Internal structure 760e4b17023SJohn Marino 761e4b17023SJohn Marino@code{DECL} nodes are represented internally as a hierarchy of 762e4b17023SJohn Marinostructures. 763e4b17023SJohn Marino 764e4b17023SJohn Marino@menu 765e4b17023SJohn Marino* Current structure hierarchy:: The current DECL node structure 766e4b17023SJohn Marinohierarchy. 767e4b17023SJohn Marino* Adding new DECL node types:: How to add a new DECL node to a 768e4b17023SJohn Marinofrontend. 769e4b17023SJohn Marino@end menu 770e4b17023SJohn Marino 771e4b17023SJohn Marino@node Current structure hierarchy 772e4b17023SJohn Marino@subsubsection Current structure hierarchy 773e4b17023SJohn Marino 774e4b17023SJohn Marino@table @code 775e4b17023SJohn Marino 776e4b17023SJohn Marino@item struct tree_decl_minimal 777e4b17023SJohn MarinoThis is the minimal structure to inherit from in order for common 778e4b17023SJohn Marino@code{DECL} macros to work. The fields it contains are a unique ID, 779e4b17023SJohn Marinosource location, context, and name. 780e4b17023SJohn Marino 781e4b17023SJohn Marino@item struct tree_decl_common 782e4b17023SJohn MarinoThis structure inherits from @code{struct tree_decl_minimal}. It 783e4b17023SJohn Marinocontains fields that most @code{DECL} nodes need, such as a field to 784e4b17023SJohn Marinostore alignment, machine mode, size, and attributes. 785e4b17023SJohn Marino 786e4b17023SJohn Marino@item struct tree_field_decl 787e4b17023SJohn MarinoThis structure inherits from @code{struct tree_decl_common}. It is 788e4b17023SJohn Marinoused to represent @code{FIELD_DECL}. 789e4b17023SJohn Marino 790e4b17023SJohn Marino@item struct tree_label_decl 791e4b17023SJohn MarinoThis structure inherits from @code{struct tree_decl_common}. It is 792e4b17023SJohn Marinoused to represent @code{LABEL_DECL}. 793e4b17023SJohn Marino 794e4b17023SJohn Marino@item struct tree_translation_unit_decl 795e4b17023SJohn MarinoThis structure inherits from @code{struct tree_decl_common}. It is 796e4b17023SJohn Marinoused to represent @code{TRANSLATION_UNIT_DECL}. 797e4b17023SJohn Marino 798e4b17023SJohn Marino@item struct tree_decl_with_rtl 799e4b17023SJohn MarinoThis structure inherits from @code{struct tree_decl_common}. It 800e4b17023SJohn Marinocontains a field to store the low-level RTL associated with a 801e4b17023SJohn Marino@code{DECL} node. 802e4b17023SJohn Marino 803e4b17023SJohn Marino@item struct tree_result_decl 804e4b17023SJohn MarinoThis structure inherits from @code{struct tree_decl_with_rtl}. It is 805e4b17023SJohn Marinoused to represent @code{RESULT_DECL}. 806e4b17023SJohn Marino 807e4b17023SJohn Marino@item struct tree_const_decl 808e4b17023SJohn MarinoThis structure inherits from @code{struct tree_decl_with_rtl}. It is 809e4b17023SJohn Marinoused to represent @code{CONST_DECL}. 810e4b17023SJohn Marino 811e4b17023SJohn Marino@item struct tree_parm_decl 812e4b17023SJohn MarinoThis structure inherits from @code{struct tree_decl_with_rtl}. It is 813e4b17023SJohn Marinoused to represent @code{PARM_DECL}. 814e4b17023SJohn Marino 815e4b17023SJohn Marino@item struct tree_decl_with_vis 816e4b17023SJohn MarinoThis structure inherits from @code{struct tree_decl_with_rtl}. It 817e4b17023SJohn Marinocontains fields necessary to store visibility information, as well as 818e4b17023SJohn Marinoa section name and assembler name. 819e4b17023SJohn Marino 820e4b17023SJohn Marino@item struct tree_var_decl 821e4b17023SJohn MarinoThis structure inherits from @code{struct tree_decl_with_vis}. It is 822e4b17023SJohn Marinoused to represent @code{VAR_DECL}. 823e4b17023SJohn Marino 824e4b17023SJohn Marino@item struct tree_function_decl 825e4b17023SJohn MarinoThis structure inherits from @code{struct tree_decl_with_vis}. It is 826e4b17023SJohn Marinoused to represent @code{FUNCTION_DECL}. 827e4b17023SJohn Marino 828e4b17023SJohn Marino@end table 829e4b17023SJohn Marino@node Adding new DECL node types 830e4b17023SJohn Marino@subsubsection Adding new DECL node types 831e4b17023SJohn Marino 832e4b17023SJohn MarinoAdding a new @code{DECL} tree consists of the following steps 833e4b17023SJohn Marino 834e4b17023SJohn Marino@table @asis 835e4b17023SJohn Marino 836e4b17023SJohn Marino@item Add a new tree code for the @code{DECL} node 837e4b17023SJohn MarinoFor language specific @code{DECL} nodes, there is a @file{.def} file 838e4b17023SJohn Marinoin each frontend directory where the tree code should be added. 839e4b17023SJohn MarinoFor @code{DECL} nodes that are part of the middle-end, the code should 840e4b17023SJohn Marinobe added to @file{tree.def}. 841e4b17023SJohn Marino 842e4b17023SJohn Marino@item Create a new structure type for the @code{DECL} node 843e4b17023SJohn MarinoThese structures should inherit from one of the existing structures in 844e4b17023SJohn Marinothe language hierarchy by using that structure as the first member. 845e4b17023SJohn Marino 846e4b17023SJohn Marino@smallexample 847e4b17023SJohn Marinostruct tree_foo_decl 848e4b17023SJohn Marino@{ 849e4b17023SJohn Marino struct tree_decl_with_vis common; 850e4b17023SJohn Marino@} 851e4b17023SJohn Marino@end smallexample 852e4b17023SJohn Marino 853e4b17023SJohn MarinoWould create a structure name @code{tree_foo_decl} that inherits from 854e4b17023SJohn Marino@code{struct tree_decl_with_vis}. 855e4b17023SJohn Marino 856e4b17023SJohn MarinoFor language specific @code{DECL} nodes, this new structure type 857e4b17023SJohn Marinoshould go in the appropriate @file{.h} file. 858e4b17023SJohn MarinoFor @code{DECL} nodes that are part of the middle-end, the structure 859e4b17023SJohn Marinotype should go in @file{tree.h}. 860e4b17023SJohn Marino 861e4b17023SJohn Marino@item Add a member to the tree structure enumerator for the node 862e4b17023SJohn MarinoFor garbage collection and dynamic checking purposes, each @code{DECL} 863e4b17023SJohn Marinonode structure type is required to have a unique enumerator value 864e4b17023SJohn Marinospecified with it. 865e4b17023SJohn MarinoFor language specific @code{DECL} nodes, this new enumerator value 866e4b17023SJohn Marinoshould go in the appropriate @file{.def} file. 867e4b17023SJohn MarinoFor @code{DECL} nodes that are part of the middle-end, the enumerator 868e4b17023SJohn Marinovalues are specified in @file{treestruct.def}. 869e4b17023SJohn Marino 870e4b17023SJohn Marino@item Update @code{union tree_node} 871e4b17023SJohn MarinoIn order to make your new structure type usable, it must be added to 872e4b17023SJohn Marino@code{union tree_node}. 873e4b17023SJohn MarinoFor language specific @code{DECL} nodes, a new entry should be added 874e4b17023SJohn Marinoto the appropriate @file{.h} file of the form 875e4b17023SJohn Marino@smallexample 876e4b17023SJohn Marino struct tree_foo_decl GTY ((tag ("TS_VAR_DECL"))) foo_decl; 877e4b17023SJohn Marino@end smallexample 878e4b17023SJohn MarinoFor @code{DECL} nodes that are part of the middle-end, the additional 879e4b17023SJohn Marinomember goes directly into @code{union tree_node} in @file{tree.h}. 880e4b17023SJohn Marino 881e4b17023SJohn Marino@item Update dynamic checking info 882e4b17023SJohn MarinoIn order to be able to check whether accessing a named portion of 883e4b17023SJohn Marino@code{union tree_node} is legal, and whether a certain @code{DECL} node 884e4b17023SJohn Marinocontains one of the enumerated @code{DECL} node structures in the 885e4b17023SJohn Marinohierarchy, a simple lookup table is used. 886e4b17023SJohn MarinoThis lookup table needs to be kept up to date with the tree structure 887e4b17023SJohn Marinohierarchy, or else checking and containment macros will fail 888e4b17023SJohn Marinoinappropriately. 889e4b17023SJohn Marino 890e4b17023SJohn MarinoFor language specific @code{DECL} nodes, their is an @code{init_ts} 891e4b17023SJohn Marinofunction in an appropriate @file{.c} file, which initializes the lookup 892e4b17023SJohn Marinotable. 893e4b17023SJohn MarinoCode setting up the table for new @code{DECL} nodes should be added 894e4b17023SJohn Marinothere. 895e4b17023SJohn MarinoFor each @code{DECL} tree code and enumerator value representing a 896e4b17023SJohn Marinomember of the inheritance hierarchy, the table should contain 1 if 897e4b17023SJohn Marinothat tree code inherits (directly or indirectly) from that member. 898e4b17023SJohn MarinoThus, a @code{FOO_DECL} node derived from @code{struct decl_with_rtl}, 899e4b17023SJohn Marinoand enumerator value @code{TS_FOO_DECL}, would be set up as follows 900e4b17023SJohn Marino@smallexample 901e4b17023SJohn Marinotree_contains_struct[FOO_DECL][TS_FOO_DECL] = 1; 902e4b17023SJohn Marinotree_contains_struct[FOO_DECL][TS_DECL_WRTL] = 1; 903e4b17023SJohn Marinotree_contains_struct[FOO_DECL][TS_DECL_COMMON] = 1; 904e4b17023SJohn Marinotree_contains_struct[FOO_DECL][TS_DECL_MINIMAL] = 1; 905e4b17023SJohn Marino@end smallexample 906e4b17023SJohn Marino 907e4b17023SJohn MarinoFor @code{DECL} nodes that are part of the middle-end, the setup code 908e4b17023SJohn Marinogoes into @file{tree.c}. 909e4b17023SJohn Marino 910e4b17023SJohn Marino@item Add macros to access any new fields and flags 911e4b17023SJohn Marino 912e4b17023SJohn MarinoEach added field or flag should have a macro that is used to access 913e4b17023SJohn Marinoit, that performs appropriate checking to ensure only the right type of 914e4b17023SJohn Marino@code{DECL} nodes access the field. 915e4b17023SJohn Marino 916e4b17023SJohn MarinoThese macros generally take the following form 917e4b17023SJohn Marino@smallexample 918e4b17023SJohn Marino#define FOO_DECL_FIELDNAME(NODE) FOO_DECL_CHECK(NODE)->foo_decl.fieldname 919e4b17023SJohn Marino@end smallexample 920e4b17023SJohn MarinoHowever, if the structure is simply a base class for further 921e4b17023SJohn Marinostructures, something like the following should be used 922e4b17023SJohn Marino@smallexample 923e4b17023SJohn Marino#define BASE_STRUCT_CHECK(T) CONTAINS_STRUCT_CHECK(T, TS_BASE_STRUCT) 924e4b17023SJohn Marino#define BASE_STRUCT_FIELDNAME(NODE) \ 925e4b17023SJohn Marino (BASE_STRUCT_CHECK(NODE)->base_struct.fieldname 926e4b17023SJohn Marino@end smallexample 927e4b17023SJohn Marino 928e4b17023SJohn Marino@end table 929e4b17023SJohn Marino 930e4b17023SJohn Marino 931e4b17023SJohn Marino@c --------------------------------------------------------------------- 932e4b17023SJohn Marino@c Attributes 933e4b17023SJohn Marino@c --------------------------------------------------------------------- 934e4b17023SJohn Marino@node Attributes 935e4b17023SJohn Marino@section Attributes in trees 936e4b17023SJohn Marino@cindex attributes 937e4b17023SJohn Marino 938e4b17023SJohn MarinoAttributes, as specified using the @code{__attribute__} keyword, are 939e4b17023SJohn Marinorepresented internally as a @code{TREE_LIST}. The @code{TREE_PURPOSE} 940e4b17023SJohn Marinois the name of the attribute, as an @code{IDENTIFIER_NODE}. The 941e4b17023SJohn Marino@code{TREE_VALUE} is a @code{TREE_LIST} of the arguments of the 942e4b17023SJohn Marinoattribute, if any, or @code{NULL_TREE} if there are no arguments; the 943e4b17023SJohn Marinoarguments are stored as the @code{TREE_VALUE} of successive entries in 944e4b17023SJohn Marinothe list, and may be identifiers or expressions. The @code{TREE_CHAIN} 945e4b17023SJohn Marinoof the attribute is the next attribute in a list of attributes applying 946e4b17023SJohn Marinoto the same declaration or type, or @code{NULL_TREE} if there are no 947e4b17023SJohn Marinofurther attributes in the list. 948e4b17023SJohn Marino 949e4b17023SJohn MarinoAttributes may be attached to declarations and to types; these 950e4b17023SJohn Marinoattributes may be accessed with the following macros. All attributes 951e4b17023SJohn Marinoare stored in this way, and many also cause other changes to the 952e4b17023SJohn Marinodeclaration or type or to other internal compiler data structures. 953e4b17023SJohn Marino 954e4b17023SJohn Marino@deftypefn {Tree Macro} tree DECL_ATTRIBUTES (tree @var{decl}) 955e4b17023SJohn MarinoThis macro returns the attributes on the declaration @var{decl}. 956e4b17023SJohn Marino@end deftypefn 957e4b17023SJohn Marino 958e4b17023SJohn Marino@deftypefn {Tree Macro} tree TYPE_ATTRIBUTES (tree @var{type}) 959e4b17023SJohn MarinoThis macro returns the attributes on the type @var{type}. 960e4b17023SJohn Marino@end deftypefn 961e4b17023SJohn Marino 962e4b17023SJohn Marino 963e4b17023SJohn Marino@c --------------------------------------------------------------------- 964e4b17023SJohn Marino@c Expressions 965e4b17023SJohn Marino@c --------------------------------------------------------------------- 966e4b17023SJohn Marino 967e4b17023SJohn Marino@node Expression trees 968e4b17023SJohn Marino@section Expressions 969e4b17023SJohn Marino@cindex expression 970e4b17023SJohn Marino@findex TREE_TYPE 971e4b17023SJohn Marino@findex TREE_OPERAND 972e4b17023SJohn Marino 973e4b17023SJohn MarinoThe internal representation for expressions is for the most part quite 974e4b17023SJohn Marinostraightforward. However, there are a few facts that one must bear in 975e4b17023SJohn Marinomind. In particular, the expression ``tree'' is actually a directed 976e4b17023SJohn Marinoacyclic graph. (For example there may be many references to the integer 977e4b17023SJohn Marinoconstant zero throughout the source program; many of these will be 978e4b17023SJohn Marinorepresented by the same expression node.) You should not rely on 979e4b17023SJohn Marinocertain kinds of node being shared, nor should you rely on certain kinds of 980e4b17023SJohn Marinonodes being unshared. 981e4b17023SJohn Marino 982e4b17023SJohn MarinoThe following macros can be used with all expression nodes: 983e4b17023SJohn Marino 984e4b17023SJohn Marino@ftable @code 985e4b17023SJohn Marino@item TREE_TYPE 986e4b17023SJohn MarinoReturns the type of the expression. This value may not be precisely the 987e4b17023SJohn Marinosame type that would be given the expression in the original program. 988e4b17023SJohn Marino@end ftable 989e4b17023SJohn Marino 990e4b17023SJohn MarinoIn what follows, some nodes that one might expect to always have type 991e4b17023SJohn Marino@code{bool} are documented to have either integral or boolean type. At 992e4b17023SJohn Marinosome point in the future, the C front end may also make use of this same 993e4b17023SJohn Marinointermediate representation, and at this point these nodes will 994e4b17023SJohn Marinocertainly have integral type. The previous sentence is not meant to 995e4b17023SJohn Marinoimply that the C++ front end does not or will not give these nodes 996e4b17023SJohn Marinointegral type. 997e4b17023SJohn Marino 998e4b17023SJohn MarinoBelow, we list the various kinds of expression nodes. Except where 999e4b17023SJohn Marinonoted otherwise, the operands to an expression are accessed using the 1000e4b17023SJohn Marino@code{TREE_OPERAND} macro. For example, to access the first operand to 1001e4b17023SJohn Marinoa binary plus expression @code{expr}, use: 1002e4b17023SJohn Marino 1003e4b17023SJohn Marino@smallexample 1004e4b17023SJohn MarinoTREE_OPERAND (expr, 0) 1005e4b17023SJohn Marino@end smallexample 1006e4b17023SJohn Marino@noindent 1007e4b17023SJohn Marino 1008e4b17023SJohn MarinoAs this example indicates, the operands are zero-indexed. 1009e4b17023SJohn Marino 1010e4b17023SJohn Marino 1011e4b17023SJohn Marino@menu 1012e4b17023SJohn Marino* Constants: Constant expressions. 1013e4b17023SJohn Marino* Storage References:: 1014e4b17023SJohn Marino* Unary and Binary Expressions:: 1015e4b17023SJohn Marino* Vectors:: 1016e4b17023SJohn Marino@end menu 1017e4b17023SJohn Marino 1018e4b17023SJohn Marino@node Constant expressions 1019e4b17023SJohn Marino@subsection Constant expressions 1020e4b17023SJohn Marino@tindex INTEGER_CST 1021e4b17023SJohn Marino@findex TREE_INT_CST_HIGH 1022e4b17023SJohn Marino@findex TREE_INT_CST_LOW 1023e4b17023SJohn Marino@findex tree_int_cst_lt 1024e4b17023SJohn Marino@findex tree_int_cst_equal 1025e4b17023SJohn Marino@tindex REAL_CST 1026e4b17023SJohn Marino@tindex FIXED_CST 1027e4b17023SJohn Marino@tindex COMPLEX_CST 1028e4b17023SJohn Marino@tindex VECTOR_CST 1029e4b17023SJohn Marino@tindex STRING_CST 1030e4b17023SJohn Marino@findex TREE_STRING_LENGTH 1031e4b17023SJohn Marino@findex TREE_STRING_POINTER 1032e4b17023SJohn Marino 1033e4b17023SJohn MarinoThe table below begins with constants, moves on to unary expressions, 1034e4b17023SJohn Marinothen proceeds to binary expressions, and concludes with various other 1035e4b17023SJohn Marinokinds of expressions: 1036e4b17023SJohn Marino 1037e4b17023SJohn Marino@table @code 1038e4b17023SJohn Marino@item INTEGER_CST 1039e4b17023SJohn MarinoThese nodes represent integer constants. Note that the type of these 1040e4b17023SJohn Marinoconstants is obtained with @code{TREE_TYPE}; they are not always of type 1041e4b17023SJohn Marino@code{int}. In particular, @code{char} constants are represented with 1042e4b17023SJohn Marino@code{INTEGER_CST} nodes. The value of the integer constant @code{e} is 1043e4b17023SJohn Marinogiven by 1044e4b17023SJohn Marino@smallexample 1045e4b17023SJohn Marino((TREE_INT_CST_HIGH (e) << HOST_BITS_PER_WIDE_INT) 1046e4b17023SJohn Marino+ TREE_INST_CST_LOW (e)) 1047e4b17023SJohn Marino@end smallexample 1048e4b17023SJohn Marino@noindent 1049e4b17023SJohn MarinoHOST_BITS_PER_WIDE_INT is at least thirty-two on all platforms. Both 1050e4b17023SJohn Marino@code{TREE_INT_CST_HIGH} and @code{TREE_INT_CST_LOW} return a 1051e4b17023SJohn Marino@code{HOST_WIDE_INT}. The value of an @code{INTEGER_CST} is interpreted 1052e4b17023SJohn Marinoas a signed or unsigned quantity depending on the type of the constant. 1053e4b17023SJohn MarinoIn general, the expression given above will overflow, so it should not 1054e4b17023SJohn Marinobe used to calculate the value of the constant. 1055e4b17023SJohn Marino 1056e4b17023SJohn MarinoThe variable @code{integer_zero_node} is an integer constant with value 1057e4b17023SJohn Marinozero. Similarly, @code{integer_one_node} is an integer constant with 1058e4b17023SJohn Marinovalue one. The @code{size_zero_node} and @code{size_one_node} variables 1059e4b17023SJohn Marinoare analogous, but have type @code{size_t} rather than @code{int}. 1060e4b17023SJohn Marino 1061e4b17023SJohn MarinoThe function @code{tree_int_cst_lt} is a predicate which holds if its 1062e4b17023SJohn Marinofirst argument is less than its second. Both constants are assumed to 1063e4b17023SJohn Marinohave the same signedness (i.e., either both should be signed or both 1064e4b17023SJohn Marinoshould be unsigned.) The full width of the constant is used when doing 1065e4b17023SJohn Marinothe comparison; the usual rules about promotions and conversions are 1066e4b17023SJohn Marinoignored. Similarly, @code{tree_int_cst_equal} holds if the two 1067e4b17023SJohn Marinoconstants are equal. The @code{tree_int_cst_sgn} function returns the 1068e4b17023SJohn Marinosign of a constant. The value is @code{1}, @code{0}, or @code{-1} 1069e4b17023SJohn Marinoaccording on whether the constant is greater than, equal to, or less 1070e4b17023SJohn Marinothan zero. Again, the signedness of the constant's type is taken into 1071e4b17023SJohn Marinoaccount; an unsigned constant is never less than zero, no matter what 1072e4b17023SJohn Marinoits bit-pattern. 1073e4b17023SJohn Marino 1074e4b17023SJohn Marino@item REAL_CST 1075e4b17023SJohn Marino 1076e4b17023SJohn MarinoFIXME: Talk about how to obtain representations of this constant, do 1077e4b17023SJohn Marinocomparisons, and so forth. 1078e4b17023SJohn Marino 1079e4b17023SJohn Marino@item FIXED_CST 1080e4b17023SJohn Marino 1081e4b17023SJohn MarinoThese nodes represent fixed-point constants. The type of these constants 1082e4b17023SJohn Marinois obtained with @code{TREE_TYPE}. @code{TREE_FIXED_CST_PTR} points to 1083e4b17023SJohn Marinoa @code{struct fixed_value}; @code{TREE_FIXED_CST} returns the structure 1084e4b17023SJohn Marinoitself. @code{struct fixed_value} contains @code{data} with the size of two 1085e4b17023SJohn Marino@code{HOST_BITS_PER_WIDE_INT} and @code{mode} as the associated fixed-point 1086e4b17023SJohn Marinomachine mode for @code{data}. 1087e4b17023SJohn Marino 1088e4b17023SJohn Marino@item COMPLEX_CST 1089e4b17023SJohn MarinoThese nodes are used to represent complex number constants, that is a 1090e4b17023SJohn Marino@code{__complex__} whose parts are constant nodes. The 1091e4b17023SJohn Marino@code{TREE_REALPART} and @code{TREE_IMAGPART} return the real and the 1092e4b17023SJohn Marinoimaginary parts respectively. 1093e4b17023SJohn Marino 1094e4b17023SJohn Marino@item VECTOR_CST 1095e4b17023SJohn MarinoThese nodes are used to represent vector constants, whose parts are 1096e4b17023SJohn Marinoconstant nodes. Each individual constant node is either an integer or a 1097e4b17023SJohn Marinodouble constant node. The first operand is a @code{TREE_LIST} of the 1098e4b17023SJohn Marinoconstant nodes and is accessed through @code{TREE_VECTOR_CST_ELTS}. 1099e4b17023SJohn Marino 1100e4b17023SJohn Marino@item STRING_CST 1101e4b17023SJohn MarinoThese nodes represent string-constants. The @code{TREE_STRING_LENGTH} 1102e4b17023SJohn Marinoreturns the length of the string, as an @code{int}. The 1103e4b17023SJohn Marino@code{TREE_STRING_POINTER} is a @code{char*} containing the string 1104e4b17023SJohn Marinoitself. The string may not be @code{NUL}-terminated, and it may contain 1105e4b17023SJohn Marinoembedded @code{NUL} characters. Therefore, the 1106e4b17023SJohn Marino@code{TREE_STRING_LENGTH} includes the trailing @code{NUL} if it is 1107e4b17023SJohn Marinopresent. 1108e4b17023SJohn Marino 1109e4b17023SJohn MarinoFor wide string constants, the @code{TREE_STRING_LENGTH} is the number 1110e4b17023SJohn Marinoof bytes in the string, and the @code{TREE_STRING_POINTER} 1111e4b17023SJohn Marinopoints to an array of the bytes of the string, as represented on the 1112e4b17023SJohn Marinotarget system (that is, as integers in the target endianness). Wide and 1113e4b17023SJohn Marinonon-wide string constants are distinguished only by the @code{TREE_TYPE} 1114e4b17023SJohn Marinoof the @code{STRING_CST}. 1115e4b17023SJohn Marino 1116e4b17023SJohn MarinoFIXME: The formats of string constants are not well-defined when the 1117e4b17023SJohn Marinotarget system bytes are not the same width as host system bytes. 1118e4b17023SJohn Marino 1119e4b17023SJohn Marino@end table 1120e4b17023SJohn Marino 1121e4b17023SJohn Marino@node Storage References 1122e4b17023SJohn Marino@subsection References to storage 1123e4b17023SJohn Marino@tindex ADDR_EXPR 1124e4b17023SJohn Marino@tindex INDIRECT_REF 1125e4b17023SJohn Marino@tindex MEM_REF 1126e4b17023SJohn Marino@tindex ARRAY_REF 1127e4b17023SJohn Marino@tindex ARRAY_RANGE_REF 1128e4b17023SJohn Marino@tindex TARGET_MEM_REF 1129e4b17023SJohn Marino@tindex COMPONENT_REF 1130e4b17023SJohn Marino 1131e4b17023SJohn Marino@table @code 1132e4b17023SJohn Marino@item ARRAY_REF 1133e4b17023SJohn MarinoThese nodes represent array accesses. The first operand is the array; 1134e4b17023SJohn Marinothe second is the index. To calculate the address of the memory 1135e4b17023SJohn Marinoaccessed, you must scale the index by the size of the type of the array 1136e4b17023SJohn Marinoelements. The type of these expressions must be the type of a component of 1137e4b17023SJohn Marinothe array. The third and fourth operands are used after gimplification 1138e4b17023SJohn Marinoto represent the lower bound and component size but should not be used 1139e4b17023SJohn Marinodirectly; call @code{array_ref_low_bound} and @code{array_ref_element_size} 1140e4b17023SJohn Marinoinstead. 1141e4b17023SJohn Marino 1142e4b17023SJohn Marino@item ARRAY_RANGE_REF 1143e4b17023SJohn MarinoThese nodes represent access to a range (or ``slice'') of an array. The 1144e4b17023SJohn Marinooperands are the same as that for @code{ARRAY_REF} and have the same 1145e4b17023SJohn Marinomeanings. The type of these expressions must be an array whose component 1146e4b17023SJohn Marinotype is the same as that of the first operand. The range of that array 1147e4b17023SJohn Marinotype determines the amount of data these expressions access. 1148e4b17023SJohn Marino 1149e4b17023SJohn Marino@item TARGET_MEM_REF 1150e4b17023SJohn MarinoThese nodes represent memory accesses whose address directly map to 1151e4b17023SJohn Marinoan addressing mode of the target architecture. The first argument 1152e4b17023SJohn Marinois @code{TMR_SYMBOL} and must be a @code{VAR_DECL} of an object with 1153e4b17023SJohn Marinoa fixed address. The second argument is @code{TMR_BASE} and the 1154e4b17023SJohn Marinothird one is @code{TMR_INDEX}. The fourth argument is 1155e4b17023SJohn Marino@code{TMR_STEP} and must be an @code{INTEGER_CST}. The fifth 1156e4b17023SJohn Marinoargument is @code{TMR_OFFSET} and must be an @code{INTEGER_CST}. 1157e4b17023SJohn MarinoAny of the arguments may be NULL if the appropriate component 1158e4b17023SJohn Marinodoes not appear in the address. Address of the @code{TARGET_MEM_REF} 1159e4b17023SJohn Marinois determined in the following way. 1160e4b17023SJohn Marino 1161e4b17023SJohn Marino@smallexample 1162e4b17023SJohn Marino&TMR_SYMBOL + TMR_BASE + TMR_INDEX * TMR_STEP + TMR_OFFSET 1163e4b17023SJohn Marino@end smallexample 1164e4b17023SJohn Marino 1165e4b17023SJohn MarinoThe sixth argument is the reference to the original memory access, which 1166e4b17023SJohn Marinois preserved for the purposes of the RTL alias analysis. The seventh 1167e4b17023SJohn Marinoargument is a tag representing the results of tree level alias analysis. 1168e4b17023SJohn Marino 1169e4b17023SJohn Marino@item ADDR_EXPR 1170e4b17023SJohn MarinoThese nodes are used to represent the address of an object. (These 1171e4b17023SJohn Marinoexpressions will always have pointer or reference type.) The operand may 1172e4b17023SJohn Marinobe another expression, or it may be a declaration. 1173e4b17023SJohn Marino 1174e4b17023SJohn MarinoAs an extension, GCC allows users to take the address of a label. In 1175e4b17023SJohn Marinothis case, the operand of the @code{ADDR_EXPR} will be a 1176e4b17023SJohn Marino@code{LABEL_DECL}. The type of such an expression is @code{void*}. 1177e4b17023SJohn Marino 1178e4b17023SJohn MarinoIf the object addressed is not an lvalue, a temporary is created, and 1179e4b17023SJohn Marinothe address of the temporary is used. 1180e4b17023SJohn Marino 1181e4b17023SJohn Marino@item INDIRECT_REF 1182e4b17023SJohn MarinoThese nodes are used to represent the object pointed to by a pointer. 1183e4b17023SJohn MarinoThe operand is the pointer being dereferenced; it will always have 1184e4b17023SJohn Marinopointer or reference type. 1185e4b17023SJohn Marino 1186e4b17023SJohn Marino@item MEM_REF 1187e4b17023SJohn MarinoThese nodes are used to represent the object pointed to by a pointer 1188e4b17023SJohn Marinooffset by a constant. 1189e4b17023SJohn MarinoThe first operand is the pointer being dereferenced; it will always have 1190e4b17023SJohn Marinopointer or reference type. The second operand is a pointer constant. 1191e4b17023SJohn MarinoIts type is specifying the type to be used for type-based alias analysis. 1192e4b17023SJohn Marino 1193e4b17023SJohn Marino@item COMPONENT_REF 1194e4b17023SJohn MarinoThese nodes represent non-static data member accesses. The first 1195e4b17023SJohn Marinooperand is the object (rather than a pointer to it); the second operand 1196e4b17023SJohn Marinois the @code{FIELD_DECL} for the data member. The third operand represents 1197e4b17023SJohn Marinothe byte offset of the field, but should not be used directly; call 1198e4b17023SJohn Marino@code{component_ref_field_offset} instead. 1199e4b17023SJohn Marino 1200e4b17023SJohn Marino 1201e4b17023SJohn Marino@end table 1202e4b17023SJohn Marino 1203e4b17023SJohn Marino@node Unary and Binary Expressions 1204e4b17023SJohn Marino@subsection Unary and Binary Expressions 1205e4b17023SJohn Marino@tindex NEGATE_EXPR 1206e4b17023SJohn Marino@tindex ABS_EXPR 1207e4b17023SJohn Marino@tindex BIT_NOT_EXPR 1208e4b17023SJohn Marino@tindex TRUTH_NOT_EXPR 1209e4b17023SJohn Marino@tindex PREDECREMENT_EXPR 1210e4b17023SJohn Marino@tindex PREINCREMENT_EXPR 1211e4b17023SJohn Marino@tindex POSTDECREMENT_EXPR 1212e4b17023SJohn Marino@tindex POSTINCREMENT_EXPR 1213e4b17023SJohn Marino@tindex FIX_TRUNC_EXPR 1214e4b17023SJohn Marino@tindex FLOAT_EXPR 1215e4b17023SJohn Marino@tindex COMPLEX_EXPR 1216e4b17023SJohn Marino@tindex CONJ_EXPR 1217e4b17023SJohn Marino@tindex REALPART_EXPR 1218e4b17023SJohn Marino@tindex IMAGPART_EXPR 1219e4b17023SJohn Marino@tindex NON_LVALUE_EXPR 1220e4b17023SJohn Marino@tindex NOP_EXPR 1221e4b17023SJohn Marino@tindex CONVERT_EXPR 1222e4b17023SJohn Marino@tindex FIXED_CONVERT_EXPR 1223e4b17023SJohn Marino@tindex THROW_EXPR 1224e4b17023SJohn Marino@tindex LSHIFT_EXPR 1225e4b17023SJohn Marino@tindex RSHIFT_EXPR 1226e4b17023SJohn Marino@tindex BIT_IOR_EXPR 1227e4b17023SJohn Marino@tindex BIT_XOR_EXPR 1228e4b17023SJohn Marino@tindex BIT_AND_EXPR 1229e4b17023SJohn Marino@tindex TRUTH_ANDIF_EXPR 1230e4b17023SJohn Marino@tindex TRUTH_ORIF_EXPR 1231e4b17023SJohn Marino@tindex TRUTH_AND_EXPR 1232e4b17023SJohn Marino@tindex TRUTH_OR_EXPR 1233e4b17023SJohn Marino@tindex TRUTH_XOR_EXPR 1234e4b17023SJohn Marino@tindex POINTER_PLUS_EXPR 1235e4b17023SJohn Marino@tindex PLUS_EXPR 1236e4b17023SJohn Marino@tindex MINUS_EXPR 1237e4b17023SJohn Marino@tindex MULT_EXPR 1238e4b17023SJohn Marino@tindex RDIV_EXPR 1239e4b17023SJohn Marino@tindex TRUNC_DIV_EXPR 1240e4b17023SJohn Marino@tindex FLOOR_DIV_EXPR 1241e4b17023SJohn Marino@tindex CEIL_DIV_EXPR 1242e4b17023SJohn Marino@tindex ROUND_DIV_EXPR 1243e4b17023SJohn Marino@tindex TRUNC_MOD_EXPR 1244e4b17023SJohn Marino@tindex FLOOR_MOD_EXPR 1245e4b17023SJohn Marino@tindex CEIL_MOD_EXPR 1246e4b17023SJohn Marino@tindex ROUND_MOD_EXPR 1247e4b17023SJohn Marino@tindex EXACT_DIV_EXPR 1248e4b17023SJohn Marino@tindex LT_EXPR 1249e4b17023SJohn Marino@tindex LE_EXPR 1250e4b17023SJohn Marino@tindex GT_EXPR 1251e4b17023SJohn Marino@tindex GE_EXPR 1252e4b17023SJohn Marino@tindex EQ_EXPR 1253e4b17023SJohn Marino@tindex NE_EXPR 1254e4b17023SJohn Marino@tindex ORDERED_EXPR 1255e4b17023SJohn Marino@tindex UNORDERED_EXPR 1256e4b17023SJohn Marino@tindex UNLT_EXPR 1257e4b17023SJohn Marino@tindex UNLE_EXPR 1258e4b17023SJohn Marino@tindex UNGT_EXPR 1259e4b17023SJohn Marino@tindex UNGE_EXPR 1260e4b17023SJohn Marino@tindex UNEQ_EXPR 1261e4b17023SJohn Marino@tindex LTGT_EXPR 1262e4b17023SJohn Marino@tindex MODIFY_EXPR 1263e4b17023SJohn Marino@tindex INIT_EXPR 1264e4b17023SJohn Marino@tindex COMPOUND_EXPR 1265e4b17023SJohn Marino@tindex COND_EXPR 1266e4b17023SJohn Marino@tindex CALL_EXPR 1267e4b17023SJohn Marino@tindex STMT_EXPR 1268e4b17023SJohn Marino@tindex BIND_EXPR 1269e4b17023SJohn Marino@tindex LOOP_EXPR 1270e4b17023SJohn Marino@tindex EXIT_EXPR 1271e4b17023SJohn Marino@tindex CLEANUP_POINT_EXPR 1272e4b17023SJohn Marino@tindex CONSTRUCTOR 1273e4b17023SJohn Marino@tindex COMPOUND_LITERAL_EXPR 1274e4b17023SJohn Marino@tindex SAVE_EXPR 1275e4b17023SJohn Marino@tindex TARGET_EXPR 1276e4b17023SJohn Marino@tindex VA_ARG_EXPR 1277e4b17023SJohn Marino 1278e4b17023SJohn Marino@table @code 1279e4b17023SJohn Marino@item NEGATE_EXPR 1280e4b17023SJohn MarinoThese nodes represent unary negation of the single operand, for both 1281e4b17023SJohn Marinointeger and floating-point types. The type of negation can be 1282e4b17023SJohn Marinodetermined by looking at the type of the expression. 1283e4b17023SJohn Marino 1284e4b17023SJohn MarinoThe behavior of this operation on signed arithmetic overflow is 1285e4b17023SJohn Marinocontrolled by the @code{flag_wrapv} and @code{flag_trapv} variables. 1286e4b17023SJohn Marino 1287e4b17023SJohn Marino@item ABS_EXPR 1288e4b17023SJohn MarinoThese nodes represent the absolute value of the single operand, for 1289e4b17023SJohn Marinoboth integer and floating-point types. This is typically used to 1290e4b17023SJohn Marinoimplement the @code{abs}, @code{labs} and @code{llabs} builtins for 1291e4b17023SJohn Marinointeger types, and the @code{fabs}, @code{fabsf} and @code{fabsl} 1292e4b17023SJohn Marinobuiltins for floating point types. The type of abs operation can 1293e4b17023SJohn Marinobe determined by looking at the type of the expression. 1294e4b17023SJohn Marino 1295e4b17023SJohn MarinoThis node is not used for complex types. To represent the modulus 1296e4b17023SJohn Marinoor complex abs of a complex value, use the @code{BUILT_IN_CABS}, 1297e4b17023SJohn Marino@code{BUILT_IN_CABSF} or @code{BUILT_IN_CABSL} builtins, as used 1298e4b17023SJohn Marinoto implement the C99 @code{cabs}, @code{cabsf} and @code{cabsl} 1299e4b17023SJohn Marinobuilt-in functions. 1300e4b17023SJohn Marino 1301e4b17023SJohn Marino@item BIT_NOT_EXPR 1302e4b17023SJohn MarinoThese nodes represent bitwise complement, and will always have integral 1303e4b17023SJohn Marinotype. The only operand is the value to be complemented. 1304e4b17023SJohn Marino 1305e4b17023SJohn Marino@item TRUTH_NOT_EXPR 1306e4b17023SJohn MarinoThese nodes represent logical negation, and will always have integral 1307e4b17023SJohn Marino(or boolean) type. The operand is the value being negated. The type 1308e4b17023SJohn Marinoof the operand and that of the result are always of @code{BOOLEAN_TYPE} 1309e4b17023SJohn Marinoor @code{INTEGER_TYPE}. 1310e4b17023SJohn Marino 1311e4b17023SJohn Marino@item PREDECREMENT_EXPR 1312e4b17023SJohn Marino@itemx PREINCREMENT_EXPR 1313e4b17023SJohn Marino@itemx POSTDECREMENT_EXPR 1314e4b17023SJohn Marino@itemx POSTINCREMENT_EXPR 1315e4b17023SJohn MarinoThese nodes represent increment and decrement expressions. The value of 1316e4b17023SJohn Marinothe single operand is computed, and the operand incremented or 1317e4b17023SJohn Marinodecremented. In the case of @code{PREDECREMENT_EXPR} and 1318e4b17023SJohn Marino@code{PREINCREMENT_EXPR}, the value of the expression is the value 1319e4b17023SJohn Marinoresulting after the increment or decrement; in the case of 1320e4b17023SJohn Marino@code{POSTDECREMENT_EXPR} and @code{POSTINCREMENT_EXPR} is the value 1321e4b17023SJohn Marinobefore the increment or decrement occurs. The type of the operand, like 1322e4b17023SJohn Marinothat of the result, will be either integral, boolean, or floating-point. 1323e4b17023SJohn Marino 1324e4b17023SJohn Marino@item FIX_TRUNC_EXPR 1325e4b17023SJohn MarinoThese nodes represent conversion of a floating-point value to an 1326e4b17023SJohn Marinointeger. The single operand will have a floating-point type, while 1327e4b17023SJohn Marinothe complete expression will have an integral (or boolean) type. The 1328e4b17023SJohn Marinooperand is rounded towards zero. 1329e4b17023SJohn Marino 1330e4b17023SJohn Marino@item FLOAT_EXPR 1331e4b17023SJohn MarinoThese nodes represent conversion of an integral (or boolean) value to a 1332e4b17023SJohn Marinofloating-point value. The single operand will have integral type, while 1333e4b17023SJohn Marinothe complete expression will have a floating-point type. 1334e4b17023SJohn Marino 1335e4b17023SJohn MarinoFIXME: How is the operand supposed to be rounded? Is this dependent on 1336e4b17023SJohn Marino@option{-mieee}? 1337e4b17023SJohn Marino 1338e4b17023SJohn Marino@item COMPLEX_EXPR 1339e4b17023SJohn MarinoThese nodes are used to represent complex numbers constructed from two 1340e4b17023SJohn Marinoexpressions of the same (integer or real) type. The first operand is the 1341e4b17023SJohn Marinoreal part and the second operand is the imaginary part. 1342e4b17023SJohn Marino 1343e4b17023SJohn Marino@item CONJ_EXPR 1344e4b17023SJohn MarinoThese nodes represent the conjugate of their operand. 1345e4b17023SJohn Marino 1346e4b17023SJohn Marino@item REALPART_EXPR 1347e4b17023SJohn Marino@itemx IMAGPART_EXPR 1348e4b17023SJohn MarinoThese nodes represent respectively the real and the imaginary parts 1349e4b17023SJohn Marinoof complex numbers (their sole argument). 1350e4b17023SJohn Marino 1351e4b17023SJohn Marino@item NON_LVALUE_EXPR 1352e4b17023SJohn MarinoThese nodes indicate that their one and only operand is not an lvalue. 1353e4b17023SJohn MarinoA back end can treat these identically to the single operand. 1354e4b17023SJohn Marino 1355e4b17023SJohn Marino@item NOP_EXPR 1356e4b17023SJohn MarinoThese nodes are used to represent conversions that do not require any 1357e4b17023SJohn Marinocode-generation. For example, conversion of a @code{char*} to an 1358e4b17023SJohn Marino@code{int*} does not require any code be generated; such a conversion is 1359e4b17023SJohn Marinorepresented by a @code{NOP_EXPR}. The single operand is the expression 1360e4b17023SJohn Marinoto be converted. The conversion from a pointer to a reference is also 1361e4b17023SJohn Marinorepresented with a @code{NOP_EXPR}. 1362e4b17023SJohn Marino 1363e4b17023SJohn Marino@item CONVERT_EXPR 1364e4b17023SJohn MarinoThese nodes are similar to @code{NOP_EXPR}s, but are used in those 1365e4b17023SJohn Marinosituations where code may need to be generated. For example, if an 1366e4b17023SJohn Marino@code{int*} is converted to an @code{int} code may need to be generated 1367e4b17023SJohn Marinoon some platforms. These nodes are never used for C++-specific 1368e4b17023SJohn Marinoconversions, like conversions between pointers to different classes in 1369e4b17023SJohn Marinoan inheritance hierarchy. Any adjustments that need to be made in such 1370e4b17023SJohn Marinocases are always indicated explicitly. Similarly, a user-defined 1371e4b17023SJohn Marinoconversion is never represented by a @code{CONVERT_EXPR}; instead, the 1372e4b17023SJohn Marinofunction calls are made explicit. 1373e4b17023SJohn Marino 1374e4b17023SJohn Marino@item FIXED_CONVERT_EXPR 1375e4b17023SJohn MarinoThese nodes are used to represent conversions that involve fixed-point 1376e4b17023SJohn Marinovalues. For example, from a fixed-point value to another fixed-point value, 1377e4b17023SJohn Marinofrom an integer to a fixed-point value, from a fixed-point value to an 1378e4b17023SJohn Marinointeger, from a floating-point value to a fixed-point value, or from 1379e4b17023SJohn Marinoa fixed-point value to a floating-point value. 1380e4b17023SJohn Marino 1381e4b17023SJohn Marino@item LSHIFT_EXPR 1382e4b17023SJohn Marino@itemx RSHIFT_EXPR 1383e4b17023SJohn MarinoThese nodes represent left and right shifts, respectively. The first 1384e4b17023SJohn Marinooperand is the value to shift; it will always be of integral type. The 1385e4b17023SJohn Marinosecond operand is an expression for the number of bits by which to 1386e4b17023SJohn Marinoshift. Right shift should be treated as arithmetic, i.e., the 1387e4b17023SJohn Marinohigh-order bits should be zero-filled when the expression has unsigned 1388e4b17023SJohn Marinotype and filled with the sign bit when the expression has signed type. 1389e4b17023SJohn MarinoNote that the result is undefined if the second operand is larger 1390e4b17023SJohn Marinothan or equal to the first operand's type size. 1391e4b17023SJohn Marino 1392e4b17023SJohn Marino 1393e4b17023SJohn Marino@item BIT_IOR_EXPR 1394e4b17023SJohn Marino@itemx BIT_XOR_EXPR 1395e4b17023SJohn Marino@itemx BIT_AND_EXPR 1396e4b17023SJohn MarinoThese nodes represent bitwise inclusive or, bitwise exclusive or, and 1397e4b17023SJohn Marinobitwise and, respectively. Both operands will always have integral 1398e4b17023SJohn Marinotype. 1399e4b17023SJohn Marino 1400e4b17023SJohn Marino@item TRUTH_ANDIF_EXPR 1401e4b17023SJohn Marino@itemx TRUTH_ORIF_EXPR 1402e4b17023SJohn MarinoThese nodes represent logical ``and'' and logical ``or'', respectively. 1403e4b17023SJohn MarinoThese operators are not strict; i.e., the second operand is evaluated 1404e4b17023SJohn Marinoonly if the value of the expression is not determined by evaluation of 1405e4b17023SJohn Marinothe first operand. The type of the operands and that of the result are 1406e4b17023SJohn Marinoalways of @code{BOOLEAN_TYPE} or @code{INTEGER_TYPE}. 1407e4b17023SJohn Marino 1408e4b17023SJohn Marino@item TRUTH_AND_EXPR 1409e4b17023SJohn Marino@itemx TRUTH_OR_EXPR 1410e4b17023SJohn Marino@itemx TRUTH_XOR_EXPR 1411e4b17023SJohn MarinoThese nodes represent logical and, logical or, and logical exclusive or. 1412e4b17023SJohn MarinoThey are strict; both arguments are always evaluated. There are no 1413e4b17023SJohn Marinocorresponding operators in C or C++, but the front end will sometimes 1414e4b17023SJohn Marinogenerate these expressions anyhow, if it can tell that strictness does 1415e4b17023SJohn Marinonot matter. The type of the operands and that of the result are 1416e4b17023SJohn Marinoalways of @code{BOOLEAN_TYPE} or @code{INTEGER_TYPE}. 1417e4b17023SJohn Marino 1418*5ce9237cSJohn Marino@item POINTER_PLUS_EXPR 1419e4b17023SJohn MarinoThis node represents pointer arithmetic. The first operand is always 1420e4b17023SJohn Marinoa pointer/reference type. The second operand is always an unsigned 1421e4b17023SJohn Marinointeger type compatible with sizetype. This is the only binary 1422e4b17023SJohn Marinoarithmetic operand that can operate on pointer types. 1423e4b17023SJohn Marino 1424*5ce9237cSJohn Marino@item PLUS_EXPR 1425e4b17023SJohn Marino@itemx MINUS_EXPR 1426e4b17023SJohn Marino@itemx MULT_EXPR 1427e4b17023SJohn MarinoThese nodes represent various binary arithmetic operations. 1428e4b17023SJohn MarinoRespectively, these operations are addition, subtraction (of the second 1429e4b17023SJohn Marinooperand from the first) and multiplication. Their operands may have 1430e4b17023SJohn Marinoeither integral or floating type, but there will never be case in which 1431e4b17023SJohn Marinoone operand is of floating type and the other is of integral type. 1432e4b17023SJohn Marino 1433e4b17023SJohn MarinoThe behavior of these operations on signed arithmetic overflow is 1434e4b17023SJohn Marinocontrolled by the @code{flag_wrapv} and @code{flag_trapv} variables. 1435e4b17023SJohn Marino 1436e4b17023SJohn Marino@item RDIV_EXPR 1437e4b17023SJohn MarinoThis node represents a floating point division operation. 1438e4b17023SJohn Marino 1439e4b17023SJohn Marino@item TRUNC_DIV_EXPR 1440e4b17023SJohn Marino@itemx FLOOR_DIV_EXPR 1441e4b17023SJohn Marino@itemx CEIL_DIV_EXPR 1442e4b17023SJohn Marino@itemx ROUND_DIV_EXPR 1443e4b17023SJohn MarinoThese nodes represent integer division operations that return an integer 1444e4b17023SJohn Marinoresult. @code{TRUNC_DIV_EXPR} rounds towards zero, @code{FLOOR_DIV_EXPR} 1445e4b17023SJohn Marinorounds towards negative infinity, @code{CEIL_DIV_EXPR} rounds towards 1446e4b17023SJohn Marinopositive infinity and @code{ROUND_DIV_EXPR} rounds to the closest integer. 1447e4b17023SJohn MarinoInteger division in C and C++ is truncating, i.e.@: @code{TRUNC_DIV_EXPR}. 1448e4b17023SJohn Marino 1449e4b17023SJohn MarinoThe behavior of these operations on signed arithmetic overflow, when 1450e4b17023SJohn Marinodividing the minimum signed integer by minus one, is controlled by the 1451e4b17023SJohn Marino@code{flag_wrapv} and @code{flag_trapv} variables. 1452e4b17023SJohn Marino 1453e4b17023SJohn Marino@item TRUNC_MOD_EXPR 1454e4b17023SJohn Marino@itemx FLOOR_MOD_EXPR 1455e4b17023SJohn Marino@itemx CEIL_MOD_EXPR 1456e4b17023SJohn Marino@itemx ROUND_MOD_EXPR 1457e4b17023SJohn MarinoThese nodes represent the integer remainder or modulus operation. 1458e4b17023SJohn MarinoThe integer modulus of two operands @code{a} and @code{b} is 1459e4b17023SJohn Marinodefined as @code{a - (a/b)*b} where the division calculated using 1460e4b17023SJohn Marinothe corresponding division operator. Hence for @code{TRUNC_MOD_EXPR} 1461e4b17023SJohn Marinothis definition assumes division using truncation towards zero, i.e.@: 1462e4b17023SJohn Marino@code{TRUNC_DIV_EXPR}. Integer remainder in C and C++ uses truncating 1463e4b17023SJohn Marinodivision, i.e.@: @code{TRUNC_MOD_EXPR}. 1464e4b17023SJohn Marino 1465e4b17023SJohn Marino@item EXACT_DIV_EXPR 1466e4b17023SJohn MarinoThe @code{EXACT_DIV_EXPR} code is used to represent integer divisions where 1467e4b17023SJohn Marinothe numerator is known to be an exact multiple of the denominator. This 1468e4b17023SJohn Marinoallows the backend to choose between the faster of @code{TRUNC_DIV_EXPR}, 1469e4b17023SJohn Marino@code{CEIL_DIV_EXPR} and @code{FLOOR_DIV_EXPR} for the current target. 1470e4b17023SJohn Marino 1471e4b17023SJohn Marino@item LT_EXPR 1472e4b17023SJohn Marino@itemx LE_EXPR 1473e4b17023SJohn Marino@itemx GT_EXPR 1474e4b17023SJohn Marino@itemx GE_EXPR 1475e4b17023SJohn Marino@itemx EQ_EXPR 1476e4b17023SJohn Marino@itemx NE_EXPR 1477e4b17023SJohn MarinoThese nodes represent the less than, less than or equal to, greater 1478e4b17023SJohn Marinothan, greater than or equal to, equal, and not equal comparison 1479e4b17023SJohn Marinooperators. The first and second operand with either be both of integral 1480e4b17023SJohn Marinotype or both of floating type. The result type of these expressions 1481e4b17023SJohn Marinowill always be of integral or boolean type. These operations return 1482e4b17023SJohn Marinothe result type's zero value for false, and the result type's one value 1483e4b17023SJohn Marinofor true. 1484e4b17023SJohn Marino 1485e4b17023SJohn MarinoFor floating point comparisons, if we honor IEEE NaNs and either operand 1486e4b17023SJohn Marinois NaN, then @code{NE_EXPR} always returns true and the remaining operators 1487e4b17023SJohn Marinoalways return false. On some targets, comparisons against an IEEE NaN, 1488e4b17023SJohn Marinoother than equality and inequality, may generate a floating point exception. 1489e4b17023SJohn Marino 1490e4b17023SJohn Marino@item ORDERED_EXPR 1491e4b17023SJohn Marino@itemx UNORDERED_EXPR 1492e4b17023SJohn MarinoThese nodes represent non-trapping ordered and unordered comparison 1493e4b17023SJohn Marinooperators. These operations take two floating point operands and 1494e4b17023SJohn Marinodetermine whether they are ordered or unordered relative to each other. 1495e4b17023SJohn MarinoIf either operand is an IEEE NaN, their comparison is defined to be 1496e4b17023SJohn Marinounordered, otherwise the comparison is defined to be ordered. The 1497e4b17023SJohn Marinoresult type of these expressions will always be of integral or boolean 1498e4b17023SJohn Marinotype. These operations return the result type's zero value for false, 1499e4b17023SJohn Marinoand the result type's one value for true. 1500e4b17023SJohn Marino 1501e4b17023SJohn Marino@item UNLT_EXPR 1502e4b17023SJohn Marino@itemx UNLE_EXPR 1503e4b17023SJohn Marino@itemx UNGT_EXPR 1504e4b17023SJohn Marino@itemx UNGE_EXPR 1505e4b17023SJohn Marino@itemx UNEQ_EXPR 1506e4b17023SJohn Marino@itemx LTGT_EXPR 1507e4b17023SJohn MarinoThese nodes represent the unordered comparison operators. 1508e4b17023SJohn MarinoThese operations take two floating point operands and determine whether 1509e4b17023SJohn Marinothe operands are unordered or are less than, less than or equal to, 1510e4b17023SJohn Marinogreater than, greater than or equal to, or equal respectively. For 1511e4b17023SJohn Marinoexample, @code{UNLT_EXPR} returns true if either operand is an IEEE 1512e4b17023SJohn MarinoNaN or the first operand is less than the second. With the possible 1513e4b17023SJohn Marinoexception of @code{LTGT_EXPR}, all of these operations are guaranteed 1514e4b17023SJohn Marinonot to generate a floating point exception. The result 1515e4b17023SJohn Marinotype of these expressions will always be of integral or boolean type. 1516e4b17023SJohn MarinoThese operations return the result type's zero value for false, 1517e4b17023SJohn Marinoand the result type's one value for true. 1518e4b17023SJohn Marino 1519e4b17023SJohn Marino@item MODIFY_EXPR 1520e4b17023SJohn MarinoThese nodes represent assignment. The left-hand side is the first 1521e4b17023SJohn Marinooperand; the right-hand side is the second operand. The left-hand side 1522e4b17023SJohn Marinowill be a @code{VAR_DECL}, @code{INDIRECT_REF}, @code{COMPONENT_REF}, or 1523e4b17023SJohn Marinoother lvalue. 1524e4b17023SJohn Marino 1525e4b17023SJohn MarinoThese nodes are used to represent not only assignment with @samp{=} but 1526e4b17023SJohn Marinoalso compound assignments (like @samp{+=}), by reduction to @samp{=} 1527e4b17023SJohn Marinoassignment. In other words, the representation for @samp{i += 3} looks 1528e4b17023SJohn Marinojust like that for @samp{i = i + 3}. 1529e4b17023SJohn Marino 1530e4b17023SJohn Marino@item INIT_EXPR 1531e4b17023SJohn MarinoThese nodes are just like @code{MODIFY_EXPR}, but are used only when a 1532e4b17023SJohn Marinovariable is initialized, rather than assigned to subsequently. This 1533e4b17023SJohn Marinomeans that we can assume that the target of the initialization is not 1534e4b17023SJohn Marinoused in computing its own value; any reference to the lhs in computing 1535e4b17023SJohn Marinothe rhs is undefined. 1536e4b17023SJohn Marino 1537e4b17023SJohn Marino@item COMPOUND_EXPR 1538e4b17023SJohn MarinoThese nodes represent comma-expressions. The first operand is an 1539e4b17023SJohn Marinoexpression whose value is computed and thrown away prior to the 1540e4b17023SJohn Marinoevaluation of the second operand. The value of the entire expression is 1541e4b17023SJohn Marinothe value of the second operand. 1542e4b17023SJohn Marino 1543e4b17023SJohn Marino@item COND_EXPR 1544e4b17023SJohn MarinoThese nodes represent @code{?:} expressions. The first operand 1545e4b17023SJohn Marinois of boolean or integral type. If it evaluates to a nonzero value, 1546e4b17023SJohn Marinothe second operand should be evaluated, and returned as the value of the 1547e4b17023SJohn Marinoexpression. Otherwise, the third operand is evaluated, and returned as 1548e4b17023SJohn Marinothe value of the expression. 1549e4b17023SJohn Marino 1550e4b17023SJohn MarinoThe second operand must have the same type as the entire expression, 1551e4b17023SJohn Marinounless it unconditionally throws an exception or calls a noreturn 1552e4b17023SJohn Marinofunction, in which case it should have void type. The same constraints 1553e4b17023SJohn Marinoapply to the third operand. This allows array bounds checks to be 1554e4b17023SJohn Marinorepresented conveniently as @code{(i >= 0 && i < 10) ? i : abort()}. 1555e4b17023SJohn Marino 1556e4b17023SJohn MarinoAs a GNU extension, the C language front-ends allow the second 1557e4b17023SJohn Marinooperand of the @code{?:} operator may be omitted in the source. 1558e4b17023SJohn MarinoFor example, @code{x ? : 3} is equivalent to @code{x ? x : 3}, 1559e4b17023SJohn Marinoassuming that @code{x} is an expression without side-effects. 1560e4b17023SJohn MarinoIn the tree representation, however, the second operand is always 1561e4b17023SJohn Marinopresent, possibly protected by @code{SAVE_EXPR} if the first 1562e4b17023SJohn Marinoargument does cause side-effects. 1563e4b17023SJohn Marino 1564e4b17023SJohn Marino@item CALL_EXPR 1565e4b17023SJohn MarinoThese nodes are used to represent calls to functions, including 1566e4b17023SJohn Marinonon-static member functions. @code{CALL_EXPR}s are implemented as 1567e4b17023SJohn Marinoexpression nodes with a variable number of operands. Rather than using 1568e4b17023SJohn Marino@code{TREE_OPERAND} to extract them, it is preferable to use the 1569e4b17023SJohn Marinospecialized accessor macros and functions that operate specifically on 1570e4b17023SJohn Marino@code{CALL_EXPR} nodes. 1571e4b17023SJohn Marino 1572e4b17023SJohn Marino@code{CALL_EXPR_FN} returns a pointer to the 1573e4b17023SJohn Marinofunction to call; it is always an expression whose type is a 1574e4b17023SJohn Marino@code{POINTER_TYPE}. 1575e4b17023SJohn Marino 1576e4b17023SJohn MarinoThe number of arguments to the call is returned by @code{call_expr_nargs}, 1577e4b17023SJohn Marinowhile the arguments themselves can be accessed with the @code{CALL_EXPR_ARG} 1578e4b17023SJohn Marinomacro. The arguments are zero-indexed and numbered left-to-right. 1579e4b17023SJohn MarinoYou can iterate over the arguments using @code{FOR_EACH_CALL_EXPR_ARG}, as in: 1580e4b17023SJohn Marino 1581e4b17023SJohn Marino@smallexample 1582e4b17023SJohn Marinotree call, arg; 1583e4b17023SJohn Marinocall_expr_arg_iterator iter; 1584e4b17023SJohn MarinoFOR_EACH_CALL_EXPR_ARG (arg, iter, call) 1585e4b17023SJohn Marino /* arg is bound to successive arguments of call. */ 1586e4b17023SJohn Marino @dots{}; 1587e4b17023SJohn Marino@end smallexample 1588e4b17023SJohn Marino 1589e4b17023SJohn MarinoFor non-static 1590e4b17023SJohn Marinomember functions, there will be an operand corresponding to the 1591e4b17023SJohn Marino@code{this} pointer. There will always be expressions corresponding to 1592e4b17023SJohn Marinoall of the arguments, even if the function is declared with default 1593e4b17023SJohn Marinoarguments and some arguments are not explicitly provided at the call 1594e4b17023SJohn Marinosites. 1595e4b17023SJohn Marino 1596e4b17023SJohn Marino@code{CALL_EXPR}s also have a @code{CALL_EXPR_STATIC_CHAIN} operand that 1597e4b17023SJohn Marinois used to implement nested functions. This operand is otherwise null. 1598e4b17023SJohn Marino 1599e4b17023SJohn Marino@item CLEANUP_POINT_EXPR 1600e4b17023SJohn MarinoThese nodes represent full-expressions. The single operand is an 1601e4b17023SJohn Marinoexpression to evaluate. Any destructor calls engendered by the creation 1602e4b17023SJohn Marinoof temporaries during the evaluation of that expression should be 1603e4b17023SJohn Marinoperformed immediately after the expression is evaluated. 1604e4b17023SJohn Marino 1605e4b17023SJohn Marino@item CONSTRUCTOR 1606e4b17023SJohn MarinoThese nodes represent the brace-enclosed initializers for a structure or 1607e4b17023SJohn Marinoarray. The first operand is reserved for use by the back end. The 1608e4b17023SJohn Marinosecond operand is a @code{TREE_LIST}. If the @code{TREE_TYPE} of the 1609e4b17023SJohn Marino@code{CONSTRUCTOR} is a @code{RECORD_TYPE} or @code{UNION_TYPE}, then 1610e4b17023SJohn Marinothe @code{TREE_PURPOSE} of each node in the @code{TREE_LIST} will be a 1611e4b17023SJohn Marino@code{FIELD_DECL} and the @code{TREE_VALUE} of each node will be the 1612e4b17023SJohn Marinoexpression used to initialize that field. 1613e4b17023SJohn Marino 1614e4b17023SJohn MarinoIf the @code{TREE_TYPE} of the @code{CONSTRUCTOR} is an 1615e4b17023SJohn Marino@code{ARRAY_TYPE}, then the @code{TREE_PURPOSE} of each element in the 1616e4b17023SJohn Marino@code{TREE_LIST} will be an @code{INTEGER_CST} or a @code{RANGE_EXPR} of 1617e4b17023SJohn Marinotwo @code{INTEGER_CST}s. A single @code{INTEGER_CST} indicates which 1618e4b17023SJohn Marinoelement of the array (indexed from zero) is being assigned to. A 1619e4b17023SJohn Marino@code{RANGE_EXPR} indicates an inclusive range of elements to 1620e4b17023SJohn Marinoinitialize. In both cases the @code{TREE_VALUE} is the corresponding 1621e4b17023SJohn Marinoinitializer. It is re-evaluated for each element of a 1622e4b17023SJohn Marino@code{RANGE_EXPR}. If the @code{TREE_PURPOSE} is @code{NULL_TREE}, then 1623e4b17023SJohn Marinothe initializer is for the next available array element. 1624e4b17023SJohn Marino 1625e4b17023SJohn MarinoIn the front end, you should not depend on the fields appearing in any 1626e4b17023SJohn Marinoparticular order. However, in the middle end, fields must appear in 1627e4b17023SJohn Marinodeclaration order. You should not assume that all fields will be 1628e4b17023SJohn Marinorepresented. Unrepresented fields will be set to zero. 1629e4b17023SJohn Marino 1630e4b17023SJohn Marino@item COMPOUND_LITERAL_EXPR 1631e4b17023SJohn Marino@findex COMPOUND_LITERAL_EXPR_DECL_EXPR 1632e4b17023SJohn Marino@findex COMPOUND_LITERAL_EXPR_DECL 1633e4b17023SJohn MarinoThese nodes represent ISO C99 compound literals. The 1634e4b17023SJohn Marino@code{COMPOUND_LITERAL_EXPR_DECL_EXPR} is a @code{DECL_EXPR} 1635e4b17023SJohn Marinocontaining an anonymous @code{VAR_DECL} for 1636e4b17023SJohn Marinothe unnamed object represented by the compound literal; the 1637e4b17023SJohn Marino@code{DECL_INITIAL} of that @code{VAR_DECL} is a @code{CONSTRUCTOR} 1638e4b17023SJohn Marinorepresenting the brace-enclosed list of initializers in the compound 1639e4b17023SJohn Marinoliteral. That anonymous @code{VAR_DECL} can also be accessed directly 1640e4b17023SJohn Marinoby the @code{COMPOUND_LITERAL_EXPR_DECL} macro. 1641e4b17023SJohn Marino 1642e4b17023SJohn Marino@item SAVE_EXPR 1643e4b17023SJohn Marino 1644e4b17023SJohn MarinoA @code{SAVE_EXPR} represents an expression (possibly involving 1645e4b17023SJohn Marinoside-effects) that is used more than once. The side-effects should 1646e4b17023SJohn Marinooccur only the first time the expression is evaluated. Subsequent uses 1647e4b17023SJohn Marinoshould just reuse the computed value. The first operand to the 1648e4b17023SJohn Marino@code{SAVE_EXPR} is the expression to evaluate. The side-effects should 1649e4b17023SJohn Marinobe executed where the @code{SAVE_EXPR} is first encountered in a 1650e4b17023SJohn Marinodepth-first preorder traversal of the expression tree. 1651e4b17023SJohn Marino 1652e4b17023SJohn Marino@item TARGET_EXPR 1653e4b17023SJohn MarinoA @code{TARGET_EXPR} represents a temporary object. The first operand 1654e4b17023SJohn Marinois a @code{VAR_DECL} for the temporary variable. The second operand is 1655e4b17023SJohn Marinothe initializer for the temporary. The initializer is evaluated and, 1656e4b17023SJohn Marinoif non-void, copied (bitwise) into the temporary. If the initializer 1657e4b17023SJohn Marinois void, that means that it will perform the initialization itself. 1658e4b17023SJohn Marino 1659e4b17023SJohn MarinoOften, a @code{TARGET_EXPR} occurs on the right-hand side of an 1660e4b17023SJohn Marinoassignment, or as the second operand to a comma-expression which is 1661e4b17023SJohn Marinoitself the right-hand side of an assignment, etc. In this case, we say 1662e4b17023SJohn Marinothat the @code{TARGET_EXPR} is ``normal''; otherwise, we say it is 1663e4b17023SJohn Marino``orphaned''. For a normal @code{TARGET_EXPR} the temporary variable 1664e4b17023SJohn Marinoshould be treated as an alias for the left-hand side of the assignment, 1665e4b17023SJohn Marinorather than as a new temporary variable. 1666e4b17023SJohn Marino 1667e4b17023SJohn MarinoThe third operand to the @code{TARGET_EXPR}, if present, is a 1668e4b17023SJohn Marinocleanup-expression (i.e., destructor call) for the temporary. If this 1669e4b17023SJohn Marinoexpression is orphaned, then this expression must be executed when the 1670e4b17023SJohn Marinostatement containing this expression is complete. These cleanups must 1671e4b17023SJohn Marinoalways be executed in the order opposite to that in which they were 1672e4b17023SJohn Marinoencountered. Note that if a temporary is created on one branch of a 1673e4b17023SJohn Marinoconditional operator (i.e., in the second or third operand to a 1674e4b17023SJohn Marino@code{COND_EXPR}), the cleanup must be run only if that branch is 1675e4b17023SJohn Marinoactually executed. 1676e4b17023SJohn Marino 1677e4b17023SJohn Marino@item VA_ARG_EXPR 1678e4b17023SJohn MarinoThis node is used to implement support for the C/C++ variable argument-list 1679e4b17023SJohn Marinomechanism. It represents expressions like @code{va_arg (ap, type)}. 1680e4b17023SJohn MarinoIts @code{TREE_TYPE} yields the tree representation for @code{type} and 1681e4b17023SJohn Marinoits sole argument yields the representation for @code{ap}. 1682e4b17023SJohn Marino 1683e4b17023SJohn Marino@end table 1684e4b17023SJohn Marino 1685e4b17023SJohn Marino@node Vectors 1686e4b17023SJohn Marino@subsection Vectors 1687e4b17023SJohn Marino@tindex VEC_LSHIFT_EXPR 1688e4b17023SJohn Marino@tindex VEC_RSHIFT_EXPR 1689e4b17023SJohn Marino@tindex VEC_WIDEN_MULT_HI_EXPR 1690e4b17023SJohn Marino@tindex VEC_WIDEN_MULT_LO_EXPR 1691e4b17023SJohn Marino@tindex VEC_UNPACK_HI_EXPR 1692e4b17023SJohn Marino@tindex VEC_UNPACK_LO_EXPR 1693e4b17023SJohn Marino@tindex VEC_UNPACK_FLOAT_HI_EXPR 1694e4b17023SJohn Marino@tindex VEC_UNPACK_FLOAT_LO_EXPR 1695e4b17023SJohn Marino@tindex VEC_PACK_TRUNC_EXPR 1696e4b17023SJohn Marino@tindex VEC_PACK_SAT_EXPR 1697e4b17023SJohn Marino@tindex VEC_PACK_FIX_TRUNC_EXPR 1698e4b17023SJohn Marino 1699e4b17023SJohn Marino@table @code 1700e4b17023SJohn Marino@item VEC_LSHIFT_EXPR 1701e4b17023SJohn Marino@itemx VEC_RSHIFT_EXPR 1702e4b17023SJohn MarinoThese nodes represent whole vector left and right shifts, respectively. 1703e4b17023SJohn MarinoThe first operand is the vector to shift; it will always be of vector type. 1704e4b17023SJohn MarinoThe second operand is an expression for the number of bits by which to 1705e4b17023SJohn Marinoshift. Note that the result is undefined if the second operand is larger 1706e4b17023SJohn Marinothan or equal to the first operand's type size. 1707e4b17023SJohn Marino 1708e4b17023SJohn Marino@item VEC_WIDEN_MULT_HI_EXPR 1709e4b17023SJohn Marino@itemx VEC_WIDEN_MULT_LO_EXPR 1710e4b17023SJohn MarinoThese nodes represent widening vector multiplication of the high and low 1711e4b17023SJohn Marinoparts of the two input vectors, respectively. Their operands are vectors 1712e4b17023SJohn Marinothat contain the same number of elements (@code{N}) of the same integral type. 1713e4b17023SJohn MarinoThe result is a vector that contains half as many elements, of an integral type 1714e4b17023SJohn Marinowhose size is twice as wide. In the case of @code{VEC_WIDEN_MULT_HI_EXPR} the 1715e4b17023SJohn Marinohigh @code{N/2} elements of the two vector are multiplied to produce the 1716e4b17023SJohn Marinovector of @code{N/2} products. In the case of @code{VEC_WIDEN_MULT_LO_EXPR} the 1717e4b17023SJohn Marinolow @code{N/2} elements of the two vector are multiplied to produce the 1718e4b17023SJohn Marinovector of @code{N/2} products. 1719e4b17023SJohn Marino 1720e4b17023SJohn Marino@item VEC_UNPACK_HI_EXPR 1721e4b17023SJohn Marino@itemx VEC_UNPACK_LO_EXPR 1722e4b17023SJohn MarinoThese nodes represent unpacking of the high and low parts of the input vector, 1723e4b17023SJohn Marinorespectively. The single operand is a vector that contains @code{N} elements 1724e4b17023SJohn Marinoof the same integral or floating point type. The result is a vector 1725e4b17023SJohn Marinothat contains half as many elements, of an integral or floating point type 1726e4b17023SJohn Marinowhose size is twice as wide. In the case of @code{VEC_UNPACK_HI_EXPR} the 1727e4b17023SJohn Marinohigh @code{N/2} elements of the vector are extracted and widened (promoted). 1728e4b17023SJohn MarinoIn the case of @code{VEC_UNPACK_LO_EXPR} the low @code{N/2} elements of the 1729e4b17023SJohn Marinovector are extracted and widened (promoted). 1730e4b17023SJohn Marino 1731e4b17023SJohn Marino@item VEC_UNPACK_FLOAT_HI_EXPR 1732e4b17023SJohn Marino@itemx VEC_UNPACK_FLOAT_LO_EXPR 1733e4b17023SJohn MarinoThese nodes represent unpacking of the high and low parts of the input vector, 1734e4b17023SJohn Marinowhere the values are converted from fixed point to floating point. The 1735e4b17023SJohn Marinosingle operand is a vector that contains @code{N} elements of the same 1736e4b17023SJohn Marinointegral type. The result is a vector that contains half as many elements 1737e4b17023SJohn Marinoof a floating point type whose size is twice as wide. In the case of 1738e4b17023SJohn Marino@code{VEC_UNPACK_HI_EXPR} the high @code{N/2} elements of the vector are 1739e4b17023SJohn Marinoextracted, converted and widened. In the case of @code{VEC_UNPACK_LO_EXPR} 1740e4b17023SJohn Marinothe low @code{N/2} elements of the vector are extracted, converted and widened. 1741e4b17023SJohn Marino 1742e4b17023SJohn Marino@item VEC_PACK_TRUNC_EXPR 1743e4b17023SJohn MarinoThis node represents packing of truncated elements of the two input vectors 1744e4b17023SJohn Marinointo the output vector. Input operands are vectors that contain the same 1745e4b17023SJohn Marinonumber of elements of the same integral or floating point type. The result 1746e4b17023SJohn Marinois a vector that contains twice as many elements of an integral or floating 1747e4b17023SJohn Marinopoint type whose size is half as wide. The elements of the two vectors are 1748e4b17023SJohn Marinodemoted and merged (concatenated) to form the output vector. 1749e4b17023SJohn Marino 1750e4b17023SJohn Marino@item VEC_PACK_SAT_EXPR 1751e4b17023SJohn MarinoThis node represents packing of elements of the two input vectors into the 1752e4b17023SJohn Marinooutput vector using saturation. Input operands are vectors that contain 1753e4b17023SJohn Marinothe same number of elements of the same integral type. The result is a 1754e4b17023SJohn Marinovector that contains twice as many elements of an integral type whose size 1755e4b17023SJohn Marinois half as wide. The elements of the two vectors are demoted and merged 1756e4b17023SJohn Marino(concatenated) to form the output vector. 1757e4b17023SJohn Marino 1758e4b17023SJohn Marino@item VEC_PACK_FIX_TRUNC_EXPR 1759e4b17023SJohn MarinoThis node represents packing of elements of the two input vectors into the 1760e4b17023SJohn Marinooutput vector, where the values are converted from floating point 1761e4b17023SJohn Marinoto fixed point. Input operands are vectors that contain the same number 1762e4b17023SJohn Marinoof elements of a floating point type. The result is a vector that contains 1763e4b17023SJohn Marinotwice as many elements of an integral type whose size is half as wide. The 1764e4b17023SJohn Marinoelements of the two vectors are merged (concatenated) to form the output 1765e4b17023SJohn Marinovector. 1766e4b17023SJohn Marino@end table 1767e4b17023SJohn Marino 1768e4b17023SJohn Marino 1769e4b17023SJohn Marino@c --------------------------------------------------------------------- 1770e4b17023SJohn Marino@c Statements 1771e4b17023SJohn Marino@c --------------------------------------------------------------------- 1772e4b17023SJohn Marino 1773e4b17023SJohn Marino@node Statements 1774e4b17023SJohn Marino@section Statements 1775e4b17023SJohn Marino@cindex Statements 1776e4b17023SJohn Marino 1777e4b17023SJohn MarinoMost statements in GIMPLE are assignment statements, represented by 1778e4b17023SJohn Marino@code{GIMPLE_ASSIGN}. No other C expressions can appear at statement level; 1779e4b17023SJohn Marinoa reference to a volatile object is converted into a 1780e4b17023SJohn Marino@code{GIMPLE_ASSIGN}. 1781e4b17023SJohn Marino 1782e4b17023SJohn MarinoThere are also several varieties of complex statements. 1783e4b17023SJohn Marino 1784e4b17023SJohn Marino@menu 1785e4b17023SJohn Marino* Basic Statements:: 1786e4b17023SJohn Marino* Blocks:: 1787e4b17023SJohn Marino* Statement Sequences:: 1788e4b17023SJohn Marino* Empty Statements:: 1789e4b17023SJohn Marino* Jumps:: 1790e4b17023SJohn Marino* Cleanups:: 1791e4b17023SJohn Marino* OpenMP:: 1792e4b17023SJohn Marino@end menu 1793e4b17023SJohn Marino 1794e4b17023SJohn Marino@node Basic Statements 1795e4b17023SJohn Marino@subsection Basic Statements 1796e4b17023SJohn Marino@cindex Basic Statements 1797e4b17023SJohn Marino 1798e4b17023SJohn Marino@table @code 1799e4b17023SJohn Marino@item ASM_EXPR 1800e4b17023SJohn Marino 1801e4b17023SJohn MarinoUsed to represent an inline assembly statement. For an inline assembly 1802e4b17023SJohn Marinostatement like: 1803e4b17023SJohn Marino@smallexample 1804e4b17023SJohn Marinoasm ("mov x, y"); 1805e4b17023SJohn Marino@end smallexample 1806e4b17023SJohn MarinoThe @code{ASM_STRING} macro will return a @code{STRING_CST} node for 1807e4b17023SJohn Marino@code{"mov x, y"}. If the original statement made use of the 1808e4b17023SJohn Marinoextended-assembly syntax, then @code{ASM_OUTPUTS}, 1809e4b17023SJohn Marino@code{ASM_INPUTS}, and @code{ASM_CLOBBERS} will be the outputs, inputs, 1810e4b17023SJohn Marinoand clobbers for the statement, represented as @code{STRING_CST} nodes. 1811e4b17023SJohn MarinoThe extended-assembly syntax looks like: 1812e4b17023SJohn Marino@smallexample 1813e4b17023SJohn Marinoasm ("fsinx %1,%0" : "=f" (result) : "f" (angle)); 1814e4b17023SJohn Marino@end smallexample 1815e4b17023SJohn MarinoThe first string is the @code{ASM_STRING}, containing the instruction 1816e4b17023SJohn Marinotemplate. The next two strings are the output and inputs, respectively; 1817e4b17023SJohn Marinothis statement has no clobbers. As this example indicates, ``plain'' 1818e4b17023SJohn Marinoassembly statements are merely a special case of extended assembly 1819e4b17023SJohn Marinostatements; they have no cv-qualifiers, outputs, inputs, or clobbers. 1820e4b17023SJohn MarinoAll of the strings will be @code{NUL}-terminated, and will contain no 1821e4b17023SJohn Marinoembedded @code{NUL}-characters. 1822e4b17023SJohn Marino 1823e4b17023SJohn MarinoIf the assembly statement is declared @code{volatile}, or if the 1824e4b17023SJohn Marinostatement was not an extended assembly statement, and is therefore 1825e4b17023SJohn Marinoimplicitly volatile, then the predicate @code{ASM_VOLATILE_P} will hold 1826e4b17023SJohn Marinoof the @code{ASM_EXPR}. 1827e4b17023SJohn Marino 1828e4b17023SJohn Marino@item DECL_EXPR 1829e4b17023SJohn Marino 1830e4b17023SJohn MarinoUsed to represent a local declaration. The @code{DECL_EXPR_DECL} macro 1831e4b17023SJohn Marinocan be used to obtain the entity declared. This declaration may be a 1832e4b17023SJohn Marino@code{LABEL_DECL}, indicating that the label declared is a local label. 1833e4b17023SJohn Marino(As an extension, GCC allows the declaration of labels with scope.) In 1834e4b17023SJohn MarinoC, this declaration may be a @code{FUNCTION_DECL}, indicating the 1835e4b17023SJohn Marinouse of the GCC nested function extension. For more information, 1836e4b17023SJohn Marino@pxref{Functions}. 1837e4b17023SJohn Marino 1838e4b17023SJohn Marino@item LABEL_EXPR 1839e4b17023SJohn Marino 1840e4b17023SJohn MarinoUsed to represent a label. The @code{LABEL_DECL} declared by this 1841e4b17023SJohn Marinostatement can be obtained with the @code{LABEL_EXPR_LABEL} macro. The 1842e4b17023SJohn Marino@code{IDENTIFIER_NODE} giving the name of the label can be obtained from 1843e4b17023SJohn Marinothe @code{LABEL_DECL} with @code{DECL_NAME}. 1844e4b17023SJohn Marino 1845e4b17023SJohn Marino@item GOTO_EXPR 1846e4b17023SJohn Marino 1847e4b17023SJohn MarinoUsed to represent a @code{goto} statement. The @code{GOTO_DESTINATION} will 1848e4b17023SJohn Marinousually be a @code{LABEL_DECL}. However, if the ``computed goto'' extension 1849e4b17023SJohn Marinohas been used, the @code{GOTO_DESTINATION} will be an arbitrary expression 1850e4b17023SJohn Marinoindicating the destination. This expression will always have pointer type. 1851e4b17023SJohn Marino 1852e4b17023SJohn Marino@item RETURN_EXPR 1853e4b17023SJohn Marino 1854e4b17023SJohn MarinoUsed to represent a @code{return} statement. Operand 0 represents the 1855e4b17023SJohn Marinovalue to return. It should either be the @code{RESULT_DECL} for the 1856e4b17023SJohn Marinocontaining function, or a @code{MODIFY_EXPR} or @code{INIT_EXPR} 1857e4b17023SJohn Marinosetting the function's @code{RESULT_DECL}. It will be 1858e4b17023SJohn Marino@code{NULL_TREE} if the statement was just 1859e4b17023SJohn Marino@smallexample 1860e4b17023SJohn Marinoreturn; 1861e4b17023SJohn Marino@end smallexample 1862e4b17023SJohn Marino 1863e4b17023SJohn Marino@item LOOP_EXPR 1864e4b17023SJohn MarinoThese nodes represent ``infinite'' loops. The @code{LOOP_EXPR_BODY} 1865e4b17023SJohn Marinorepresents the body of the loop. It should be executed forever, unless 1866e4b17023SJohn Marinoan @code{EXIT_EXPR} is encountered. 1867e4b17023SJohn Marino 1868e4b17023SJohn Marino@item EXIT_EXPR 1869e4b17023SJohn MarinoThese nodes represent conditional exits from the nearest enclosing 1870e4b17023SJohn Marino@code{LOOP_EXPR}. The single operand is the condition; if it is 1871e4b17023SJohn Marinononzero, then the loop should be exited. An @code{EXIT_EXPR} will only 1872e4b17023SJohn Marinoappear within a @code{LOOP_EXPR}. 1873e4b17023SJohn Marino 1874e4b17023SJohn Marino@item SWITCH_STMT 1875e4b17023SJohn Marino 1876e4b17023SJohn MarinoUsed to represent a @code{switch} statement. The @code{SWITCH_STMT_COND} 1877e4b17023SJohn Marinois the expression on which the switch is occurring. See the documentation 1878e4b17023SJohn Marinofor an @code{IF_STMT} for more information on the representation used 1879e4b17023SJohn Marinofor the condition. The @code{SWITCH_STMT_BODY} is the body of the switch 1880e4b17023SJohn Marinostatement. The @code{SWITCH_STMT_TYPE} is the original type of switch 1881e4b17023SJohn Marinoexpression as given in the source, before any compiler conversions. 1882e4b17023SJohn Marino 1883e4b17023SJohn Marino@item CASE_LABEL_EXPR 1884e4b17023SJohn Marino 1885e4b17023SJohn MarinoUse to represent a @code{case} label, range of @code{case} labels, or a 1886e4b17023SJohn Marino@code{default} label. If @code{CASE_LOW} is @code{NULL_TREE}, then this is a 1887e4b17023SJohn Marino@code{default} label. Otherwise, if @code{CASE_HIGH} is @code{NULL_TREE}, then 1888e4b17023SJohn Marinothis is an ordinary @code{case} label. In this case, @code{CASE_LOW} is 1889e4b17023SJohn Marinoan expression giving the value of the label. Both @code{CASE_LOW} and 1890e4b17023SJohn Marino@code{CASE_HIGH} are @code{INTEGER_CST} nodes. These values will have 1891e4b17023SJohn Marinothe same type as the condition expression in the switch statement. 1892e4b17023SJohn Marino 1893e4b17023SJohn MarinoOtherwise, if both @code{CASE_LOW} and @code{CASE_HIGH} are defined, the 1894e4b17023SJohn Marinostatement is a range of case labels. Such statements originate with the 1895e4b17023SJohn Marinoextension that allows users to write things of the form: 1896e4b17023SJohn Marino@smallexample 1897e4b17023SJohn Marinocase 2 ... 5: 1898e4b17023SJohn Marino@end smallexample 1899e4b17023SJohn MarinoThe first value will be @code{CASE_LOW}, while the second will be 1900e4b17023SJohn Marino@code{CASE_HIGH}. 1901e4b17023SJohn Marino 1902e4b17023SJohn Marino@end table 1903e4b17023SJohn Marino 1904e4b17023SJohn Marino 1905e4b17023SJohn Marino@node Blocks 1906e4b17023SJohn Marino@subsection Blocks 1907e4b17023SJohn Marino@cindex Blocks 1908e4b17023SJohn Marino 1909e4b17023SJohn MarinoBlock scopes and the variables they declare in GENERIC are 1910e4b17023SJohn Marinoexpressed using the @code{BIND_EXPR} code, which in previous 1911e4b17023SJohn Marinoversions of GCC was primarily used for the C statement-expression 1912e4b17023SJohn Marinoextension. 1913e4b17023SJohn Marino 1914e4b17023SJohn MarinoVariables in a block are collected into @code{BIND_EXPR_VARS} in 1915e4b17023SJohn Marinodeclaration order through their @code{TREE_CHAIN} field. Any runtime 1916e4b17023SJohn Marinoinitialization is moved out of @code{DECL_INITIAL} and into a 1917e4b17023SJohn Marinostatement in the controlled block. When gimplifying from C or C++, 1918e4b17023SJohn Marinothis initialization replaces the @code{DECL_STMT}. These variables 1919e4b17023SJohn Marinowill never require cleanups. The scope of these variables is just the 1920e4b17023SJohn Marinobody 1921e4b17023SJohn Marino 1922e4b17023SJohn MarinoVariable-length arrays (VLAs) complicate this process, as their 1923e4b17023SJohn Marinosize often refers to variables initialized earlier in the block. 1924e4b17023SJohn MarinoTo handle this, we currently split the block at that point, and 1925e4b17023SJohn Marinomove the VLA into a new, inner @code{BIND_EXPR}. This strategy 1926e4b17023SJohn Marinomay change in the future. 1927e4b17023SJohn Marino 1928e4b17023SJohn MarinoA C++ program will usually contain more @code{BIND_EXPR}s than 1929e4b17023SJohn Marinothere are syntactic blocks in the source code, since several C++ 1930e4b17023SJohn Marinoconstructs have implicit scopes associated with them. On the 1931e4b17023SJohn Marinoother hand, although the C++ front end uses pseudo-scopes to 1932e4b17023SJohn Marinohandle cleanups for objects with destructors, these don't 1933e4b17023SJohn Marinotranslate into the GIMPLE form; multiple declarations at the same 1934e4b17023SJohn Marinolevel use the same @code{BIND_EXPR}. 1935e4b17023SJohn Marino 1936e4b17023SJohn Marino@node Statement Sequences 1937e4b17023SJohn Marino@subsection Statement Sequences 1938e4b17023SJohn Marino@cindex Statement Sequences 1939e4b17023SJohn Marino 1940e4b17023SJohn MarinoMultiple statements at the same nesting level are collected into 1941e4b17023SJohn Marinoa @code{STATEMENT_LIST}. Statement lists are modified and 1942e4b17023SJohn Marinotraversed using the interface in @samp{tree-iterator.h}. 1943e4b17023SJohn Marino 1944e4b17023SJohn Marino@node Empty Statements 1945e4b17023SJohn Marino@subsection Empty Statements 1946e4b17023SJohn Marino@cindex Empty Statements 1947e4b17023SJohn Marino 1948e4b17023SJohn MarinoWhenever possible, statements with no effect are discarded. But 1949e4b17023SJohn Marinoif they are nested within another construct which cannot be 1950e4b17023SJohn Marinodiscarded for some reason, they are instead replaced with an 1951e4b17023SJohn Marinoempty statement, generated by @code{build_empty_stmt}. 1952e4b17023SJohn MarinoInitially, all empty statements were shared, after the pattern of 1953e4b17023SJohn Marinothe Java front end, but this caused a lot of trouble in practice. 1954e4b17023SJohn Marino 1955e4b17023SJohn MarinoAn empty statement is represented as @code{(void)0}. 1956e4b17023SJohn Marino 1957e4b17023SJohn Marino@node Jumps 1958e4b17023SJohn Marino@subsection Jumps 1959e4b17023SJohn Marino@cindex Jumps 1960e4b17023SJohn Marino 1961e4b17023SJohn MarinoOther jumps are expressed by either @code{GOTO_EXPR} or 1962e4b17023SJohn Marino@code{RETURN_EXPR}. 1963e4b17023SJohn Marino 1964e4b17023SJohn MarinoThe operand of a @code{GOTO_EXPR} must be either a label or a 1965e4b17023SJohn Marinovariable containing the address to jump to. 1966e4b17023SJohn Marino 1967e4b17023SJohn MarinoThe operand of a @code{RETURN_EXPR} is either @code{NULL_TREE}, 1968e4b17023SJohn Marino@code{RESULT_DECL}, or a @code{MODIFY_EXPR} which sets the return 1969e4b17023SJohn Marinovalue. It would be nice to move the @code{MODIFY_EXPR} into a 1970e4b17023SJohn Marinoseparate statement, but the special return semantics in 1971e4b17023SJohn Marino@code{expand_return} make that difficult. It may still happen in 1972e4b17023SJohn Marinothe future, perhaps by moving most of that logic into 1973e4b17023SJohn Marino@code{expand_assignment}. 1974e4b17023SJohn Marino 1975e4b17023SJohn Marino@node Cleanups 1976e4b17023SJohn Marino@subsection Cleanups 1977e4b17023SJohn Marino@cindex Cleanups 1978e4b17023SJohn Marino 1979e4b17023SJohn MarinoDestructors for local C++ objects and similar dynamic cleanups are 1980e4b17023SJohn Marinorepresented in GIMPLE by a @code{TRY_FINALLY_EXPR}. 1981e4b17023SJohn Marino@code{TRY_FINALLY_EXPR} has two operands, both of which are a sequence 1982e4b17023SJohn Marinoof statements to execute. The first sequence is executed. When it 1983e4b17023SJohn Marinocompletes the second sequence is executed. 1984e4b17023SJohn Marino 1985e4b17023SJohn MarinoThe first sequence may complete in the following ways: 1986e4b17023SJohn Marino 1987e4b17023SJohn Marino@enumerate 1988e4b17023SJohn Marino 1989e4b17023SJohn Marino@item Execute the last statement in the sequence and fall off the 1990e4b17023SJohn Marinoend. 1991e4b17023SJohn Marino 1992e4b17023SJohn Marino@item Execute a goto statement (@code{GOTO_EXPR}) to an ordinary 1993e4b17023SJohn Marinolabel outside the sequence. 1994e4b17023SJohn Marino 1995e4b17023SJohn Marino@item Execute a return statement (@code{RETURN_EXPR}). 1996e4b17023SJohn Marino 1997e4b17023SJohn Marino@item Throw an exception. This is currently not explicitly represented in 1998e4b17023SJohn MarinoGIMPLE. 1999e4b17023SJohn Marino 2000e4b17023SJohn Marino@end enumerate 2001e4b17023SJohn Marino 2002e4b17023SJohn MarinoThe second sequence is not executed if the first sequence completes by 2003e4b17023SJohn Marinocalling @code{setjmp} or @code{exit} or any other function that does 2004e4b17023SJohn Marinonot return. The second sequence is also not executed if the first 2005e4b17023SJohn Marinosequence completes via a non-local goto or a computed goto (in general 2006e4b17023SJohn Marinothe compiler does not know whether such a goto statement exits the 2007e4b17023SJohn Marinofirst sequence or not, so we assume that it doesn't). 2008e4b17023SJohn Marino 2009e4b17023SJohn MarinoAfter the second sequence is executed, if it completes normally by 2010e4b17023SJohn Marinofalling off the end, execution continues wherever the first sequence 2011e4b17023SJohn Marinowould have continued, by falling off the end, or doing a goto, etc. 2012e4b17023SJohn Marino 2013e4b17023SJohn Marino@code{TRY_FINALLY_EXPR} complicates the flow graph, since the cleanup 2014e4b17023SJohn Marinoneeds to appear on every edge out of the controlled block; this 2015e4b17023SJohn Marinoreduces the freedom to move code across these edges. Therefore, the 2016e4b17023SJohn MarinoEH lowering pass which runs before most of the optimization passes 2017e4b17023SJohn Marinoeliminates these expressions by explicitly adding the cleanup to each 2018e4b17023SJohn Marinoedge. Rethrowing the exception is represented using @code{RESX_EXPR}. 2019e4b17023SJohn Marino 2020e4b17023SJohn Marino@node OpenMP 2021e4b17023SJohn Marino@subsection OpenMP 2022e4b17023SJohn Marino@tindex OMP_PARALLEL 2023e4b17023SJohn Marino@tindex OMP_FOR 2024e4b17023SJohn Marino@tindex OMP_SECTIONS 2025e4b17023SJohn Marino@tindex OMP_SINGLE 2026e4b17023SJohn Marino@tindex OMP_SECTION 2027e4b17023SJohn Marino@tindex OMP_MASTER 2028e4b17023SJohn Marino@tindex OMP_ORDERED 2029e4b17023SJohn Marino@tindex OMP_CRITICAL 2030e4b17023SJohn Marino@tindex OMP_RETURN 2031e4b17023SJohn Marino@tindex OMP_CONTINUE 2032e4b17023SJohn Marino@tindex OMP_ATOMIC 2033e4b17023SJohn Marino@tindex OMP_CLAUSE 2034e4b17023SJohn Marino 2035e4b17023SJohn MarinoAll the statements starting with @code{OMP_} represent directives and 2036e4b17023SJohn Marinoclauses used by the OpenMP API @w{@uref{http://www.openmp.org/}}. 2037e4b17023SJohn Marino 2038e4b17023SJohn Marino@table @code 2039e4b17023SJohn Marino@item OMP_PARALLEL 2040e4b17023SJohn Marino 2041e4b17023SJohn MarinoRepresents @code{#pragma omp parallel [clause1 @dots{} clauseN]}. It 2042e4b17023SJohn Marinohas four operands: 2043e4b17023SJohn Marino 2044e4b17023SJohn MarinoOperand @code{OMP_PARALLEL_BODY} is valid while in GENERIC and 2045e4b17023SJohn MarinoHigh GIMPLE forms. It contains the body of code to be executed 2046e4b17023SJohn Marinoby all the threads. During GIMPLE lowering, this operand becomes 2047e4b17023SJohn Marino@code{NULL} and the body is emitted linearly after 2048e4b17023SJohn Marino@code{OMP_PARALLEL}. 2049e4b17023SJohn Marino 2050e4b17023SJohn MarinoOperand @code{OMP_PARALLEL_CLAUSES} is the list of clauses 2051e4b17023SJohn Marinoassociated with the directive. 2052e4b17023SJohn Marino 2053e4b17023SJohn MarinoOperand @code{OMP_PARALLEL_FN} is created by 2054e4b17023SJohn Marino@code{pass_lower_omp}, it contains the @code{FUNCTION_DECL} 2055e4b17023SJohn Marinofor the function that will contain the body of the parallel 2056e4b17023SJohn Marinoregion. 2057e4b17023SJohn Marino 2058e4b17023SJohn MarinoOperand @code{OMP_PARALLEL_DATA_ARG} is also created by 2059e4b17023SJohn Marino@code{pass_lower_omp}. If there are shared variables to be 2060e4b17023SJohn Marinocommunicated to the children threads, this operand will contain 2061e4b17023SJohn Marinothe @code{VAR_DECL} that contains all the shared values and 2062e4b17023SJohn Marinovariables. 2063e4b17023SJohn Marino 2064e4b17023SJohn Marino@item OMP_FOR 2065e4b17023SJohn Marino 2066e4b17023SJohn MarinoRepresents @code{#pragma omp for [clause1 @dots{} clauseN]}. It 2067e4b17023SJohn Marinohas 5 operands: 2068e4b17023SJohn Marino 2069e4b17023SJohn MarinoOperand @code{OMP_FOR_BODY} contains the loop body. 2070e4b17023SJohn Marino 2071e4b17023SJohn MarinoOperand @code{OMP_FOR_CLAUSES} is the list of clauses 2072e4b17023SJohn Marinoassociated with the directive. 2073e4b17023SJohn Marino 2074e4b17023SJohn MarinoOperand @code{OMP_FOR_INIT} is the loop initialization code of 2075e4b17023SJohn Marinothe form @code{VAR = N1}. 2076e4b17023SJohn Marino 2077e4b17023SJohn MarinoOperand @code{OMP_FOR_COND} is the loop conditional expression 2078e4b17023SJohn Marinoof the form @code{VAR @{<,>,<=,>=@} N2}. 2079e4b17023SJohn Marino 2080e4b17023SJohn MarinoOperand @code{OMP_FOR_INCR} is the loop index increment of the 2081e4b17023SJohn Marinoform @code{VAR @{+=,-=@} INCR}. 2082e4b17023SJohn Marino 2083e4b17023SJohn MarinoOperand @code{OMP_FOR_PRE_BODY} contains side-effect code from 2084e4b17023SJohn Marinooperands @code{OMP_FOR_INIT}, @code{OMP_FOR_COND} and 2085e4b17023SJohn Marino@code{OMP_FOR_INC}. These side-effects are part of the 2086e4b17023SJohn Marino@code{OMP_FOR} block but must be evaluated before the start of 2087e4b17023SJohn Marinoloop body. 2088e4b17023SJohn Marino 2089e4b17023SJohn MarinoThe loop index variable @code{VAR} must be a signed integer variable, 2090e4b17023SJohn Marinowhich is implicitly private to each thread. Bounds 2091e4b17023SJohn Marino@code{N1} and @code{N2} and the increment expression 2092e4b17023SJohn Marino@code{INCR} are required to be loop invariant integer 2093e4b17023SJohn Marinoexpressions that are evaluated without any synchronization. The 2094e4b17023SJohn Marinoevaluation order, frequency of evaluation and side-effects are 2095e4b17023SJohn Marinounspecified by the standard. 2096e4b17023SJohn Marino 2097e4b17023SJohn Marino@item OMP_SECTIONS 2098e4b17023SJohn Marino 2099e4b17023SJohn MarinoRepresents @code{#pragma omp sections [clause1 @dots{} clauseN]}. 2100e4b17023SJohn Marino 2101e4b17023SJohn MarinoOperand @code{OMP_SECTIONS_BODY} contains the sections body, 2102e4b17023SJohn Marinowhich in turn contains a set of @code{OMP_SECTION} nodes for 2103e4b17023SJohn Marinoeach of the concurrent sections delimited by @code{#pragma omp 2104e4b17023SJohn Marinosection}. 2105e4b17023SJohn Marino 2106e4b17023SJohn MarinoOperand @code{OMP_SECTIONS_CLAUSES} is the list of clauses 2107e4b17023SJohn Marinoassociated with the directive. 2108e4b17023SJohn Marino 2109e4b17023SJohn Marino@item OMP_SECTION 2110e4b17023SJohn Marino 2111e4b17023SJohn MarinoSection delimiter for @code{OMP_SECTIONS}. 2112e4b17023SJohn Marino 2113e4b17023SJohn Marino@item OMP_SINGLE 2114e4b17023SJohn Marino 2115e4b17023SJohn MarinoRepresents @code{#pragma omp single}. 2116e4b17023SJohn Marino 2117e4b17023SJohn MarinoOperand @code{OMP_SINGLE_BODY} contains the body of code to be 2118e4b17023SJohn Marinoexecuted by a single thread. 2119e4b17023SJohn Marino 2120e4b17023SJohn MarinoOperand @code{OMP_SINGLE_CLAUSES} is the list of clauses 2121e4b17023SJohn Marinoassociated with the directive. 2122e4b17023SJohn Marino 2123e4b17023SJohn Marino@item OMP_MASTER 2124e4b17023SJohn Marino 2125e4b17023SJohn MarinoRepresents @code{#pragma omp master}. 2126e4b17023SJohn Marino 2127e4b17023SJohn MarinoOperand @code{OMP_MASTER_BODY} contains the body of code to be 2128e4b17023SJohn Marinoexecuted by the master thread. 2129e4b17023SJohn Marino 2130e4b17023SJohn Marino@item OMP_ORDERED 2131e4b17023SJohn Marino 2132e4b17023SJohn MarinoRepresents @code{#pragma omp ordered}. 2133e4b17023SJohn Marino 2134e4b17023SJohn MarinoOperand @code{OMP_ORDERED_BODY} contains the body of code to be 2135e4b17023SJohn Marinoexecuted in the sequential order dictated by the loop index 2136e4b17023SJohn Marinovariable. 2137e4b17023SJohn Marino 2138e4b17023SJohn Marino@item OMP_CRITICAL 2139e4b17023SJohn Marino 2140e4b17023SJohn MarinoRepresents @code{#pragma omp critical [name]}. 2141e4b17023SJohn Marino 2142e4b17023SJohn MarinoOperand @code{OMP_CRITICAL_BODY} is the critical section. 2143e4b17023SJohn Marino 2144e4b17023SJohn MarinoOperand @code{OMP_CRITICAL_NAME} is an optional identifier to 2145e4b17023SJohn Marinolabel the critical section. 2146e4b17023SJohn Marino 2147e4b17023SJohn Marino@item OMP_RETURN 2148e4b17023SJohn Marino 2149e4b17023SJohn MarinoThis does not represent any OpenMP directive, it is an artificial 2150e4b17023SJohn Marinomarker to indicate the end of the body of an OpenMP@. It is used 2151e4b17023SJohn Marinoby the flow graph (@code{tree-cfg.c}) and OpenMP region 2152e4b17023SJohn Marinobuilding code (@code{omp-low.c}). 2153e4b17023SJohn Marino 2154e4b17023SJohn Marino@item OMP_CONTINUE 2155e4b17023SJohn Marino 2156e4b17023SJohn MarinoSimilarly, this instruction does not represent an OpenMP 2157e4b17023SJohn Marinodirective, it is used by @code{OMP_FOR} and 2158e4b17023SJohn Marino@code{OMP_SECTIONS} to mark the place where the code needs to 2159e4b17023SJohn Marinoloop to the next iteration (in the case of @code{OMP_FOR}) or 2160e4b17023SJohn Marinothe next section (in the case of @code{OMP_SECTIONS}). 2161e4b17023SJohn Marino 2162e4b17023SJohn MarinoIn some cases, @code{OMP_CONTINUE} is placed right before 2163e4b17023SJohn Marino@code{OMP_RETURN}. But if there are cleanups that need to 2164e4b17023SJohn Marinooccur right after the looping body, it will be emitted between 2165e4b17023SJohn Marino@code{OMP_CONTINUE} and @code{OMP_RETURN}. 2166e4b17023SJohn Marino 2167e4b17023SJohn Marino@item OMP_ATOMIC 2168e4b17023SJohn Marino 2169e4b17023SJohn MarinoRepresents @code{#pragma omp atomic}. 2170e4b17023SJohn Marino 2171e4b17023SJohn MarinoOperand 0 is the address at which the atomic operation is to be 2172e4b17023SJohn Marinoperformed. 2173e4b17023SJohn Marino 2174e4b17023SJohn MarinoOperand 1 is the expression to evaluate. The gimplifier tries 2175e4b17023SJohn Marinothree alternative code generation strategies. Whenever possible, 2176e4b17023SJohn Marinoan atomic update built-in is used. If that fails, a 2177e4b17023SJohn Marinocompare-and-swap loop is attempted. If that also fails, a 2178e4b17023SJohn Marinoregular critical section around the expression is used. 2179e4b17023SJohn Marino 2180e4b17023SJohn Marino@item OMP_CLAUSE 2181e4b17023SJohn Marino 2182e4b17023SJohn MarinoRepresents clauses associated with one of the @code{OMP_} directives. 2183e4b17023SJohn MarinoClauses are represented by separate sub-codes defined in 2184e4b17023SJohn Marino@file{tree.h}. Clauses codes can be one of: 2185e4b17023SJohn Marino@code{OMP_CLAUSE_PRIVATE}, @code{OMP_CLAUSE_SHARED}, 2186e4b17023SJohn Marino@code{OMP_CLAUSE_FIRSTPRIVATE}, 2187e4b17023SJohn Marino@code{OMP_CLAUSE_LASTPRIVATE}, @code{OMP_CLAUSE_COPYIN}, 2188e4b17023SJohn Marino@code{OMP_CLAUSE_COPYPRIVATE}, @code{OMP_CLAUSE_IF}, 2189e4b17023SJohn Marino@code{OMP_CLAUSE_NUM_THREADS}, @code{OMP_CLAUSE_SCHEDULE}, 2190e4b17023SJohn Marino@code{OMP_CLAUSE_NOWAIT}, @code{OMP_CLAUSE_ORDERED}, 2191e4b17023SJohn Marino@code{OMP_CLAUSE_DEFAULT}, @code{OMP_CLAUSE_REDUCTION}, 2192e4b17023SJohn Marino@code{OMP_CLAUSE_COLLAPSE}, @code{OMP_CLAUSE_UNTIED}, 2193e4b17023SJohn Marino@code{OMP_CLAUSE_FINAL}, and @code{OMP_CLAUSE_MERGEABLE}. Each code 2194e4b17023SJohn Marinorepresents the corresponding OpenMP clause. 2195e4b17023SJohn Marino 2196e4b17023SJohn MarinoClauses associated with the same directive are chained together 2197e4b17023SJohn Marinovia @code{OMP_CLAUSE_CHAIN}. Those clauses that accept a list 2198e4b17023SJohn Marinoof variables are restricted to exactly one, accessed with 2199e4b17023SJohn Marino@code{OMP_CLAUSE_VAR}. Therefore, multiple variables under the 2200e4b17023SJohn Marinosame clause @code{C} need to be represented as multiple @code{C} clauses 2201e4b17023SJohn Marinochained together. This facilitates adding new clauses during 2202e4b17023SJohn Marinocompilation. 2203e4b17023SJohn Marino 2204e4b17023SJohn Marino@end table 2205e4b17023SJohn Marino 2206e4b17023SJohn Marino@c --------------------------------------------------------------------- 2207e4b17023SJohn Marino@c Functions 2208e4b17023SJohn Marino@c --------------------------------------------------------------------- 2209e4b17023SJohn Marino 2210e4b17023SJohn Marino@node Functions 2211e4b17023SJohn Marino@section Functions 2212e4b17023SJohn Marino@cindex function 2213e4b17023SJohn Marino@tindex FUNCTION_DECL 2214e4b17023SJohn Marino 2215e4b17023SJohn MarinoA function is represented by a @code{FUNCTION_DECL} node. It stores 2216e4b17023SJohn Marinothe basic pieces of the function such as body, parameters, and return 2217e4b17023SJohn Marinotype as well as information on the surrounding context, visibility, 2218e4b17023SJohn Marinoand linkage. 2219e4b17023SJohn Marino 2220e4b17023SJohn Marino@menu 2221e4b17023SJohn Marino* Function Basics:: Function names, body, and parameters. 2222e4b17023SJohn Marino* Function Properties:: Context, linkage, etc. 2223e4b17023SJohn Marino@end menu 2224e4b17023SJohn Marino 2225e4b17023SJohn Marino@c --------------------------------------------------------------------- 2226e4b17023SJohn Marino@c Function Basics 2227e4b17023SJohn Marino@c --------------------------------------------------------------------- 2228e4b17023SJohn Marino 2229e4b17023SJohn Marino@node Function Basics 2230e4b17023SJohn Marino@subsection Function Basics 2231e4b17023SJohn Marino@findex DECL_NAME 2232e4b17023SJohn Marino@findex DECL_ASSEMBLER_NAME 2233e4b17023SJohn Marino@findex TREE_PUBLIC 2234e4b17023SJohn Marino@findex DECL_ARTIFICIAL 2235e4b17023SJohn Marino@findex DECL_FUNCTION_SPECIFIC_TARGET 2236e4b17023SJohn Marino@findex DECL_FUNCTION_SPECIFIC_OPTIMIZATION 2237e4b17023SJohn Marino 2238e4b17023SJohn MarinoA function has four core parts: the name, the parameters, the result, 2239e4b17023SJohn Marinoand the body. The following macros and functions access these parts 2240e4b17023SJohn Marinoof a @code{FUNCTION_DECL} as well as other basic features: 2241e4b17023SJohn Marino@ftable @code 2242e4b17023SJohn Marino@item DECL_NAME 2243e4b17023SJohn MarinoThis macro returns the unqualified name of the function, as an 2244e4b17023SJohn Marino@code{IDENTIFIER_NODE}. For an instantiation of a function template, 2245e4b17023SJohn Marinothe @code{DECL_NAME} is the unqualified name of the template, not 2246e4b17023SJohn Marinosomething like @code{f<int>}. The value of @code{DECL_NAME} is 2247e4b17023SJohn Marinoundefined when used on a constructor, destructor, overloaded operator, 2248e4b17023SJohn Marinoor type-conversion operator, or any function that is implicitly 2249e4b17023SJohn Marinogenerated by the compiler. See below for macros that can be used to 2250e4b17023SJohn Marinodistinguish these cases. 2251e4b17023SJohn Marino 2252e4b17023SJohn Marino@item DECL_ASSEMBLER_NAME 2253e4b17023SJohn MarinoThis macro returns the mangled name of the function, also an 2254e4b17023SJohn Marino@code{IDENTIFIER_NODE}. This name does not contain leading underscores 2255e4b17023SJohn Marinoon systems that prefix all identifiers with underscores. The mangled 2256e4b17023SJohn Marinoname is computed in the same way on all platforms; if special processing 2257e4b17023SJohn Marinois required to deal with the object file format used on a particular 2258e4b17023SJohn Marinoplatform, it is the responsibility of the back end to perform those 2259e4b17023SJohn Marinomodifications. (Of course, the back end should not modify 2260e4b17023SJohn Marino@code{DECL_ASSEMBLER_NAME} itself.) 2261e4b17023SJohn Marino 2262e4b17023SJohn MarinoUsing @code{DECL_ASSEMBLER_NAME} will cause additional memory to be 2263e4b17023SJohn Marinoallocated (for the mangled name of the entity) so it should be used 2264e4b17023SJohn Marinoonly when emitting assembly code. It should not be used within the 2265e4b17023SJohn Marinooptimizers to determine whether or not two declarations are the same, 2266e4b17023SJohn Marinoeven though some of the existing optimizers do use it in that way. 2267e4b17023SJohn MarinoThese uses will be removed over time. 2268e4b17023SJohn Marino 2269e4b17023SJohn Marino@item DECL_ARGUMENTS 2270e4b17023SJohn MarinoThis macro returns the @code{PARM_DECL} for the first argument to the 2271e4b17023SJohn Marinofunction. Subsequent @code{PARM_DECL} nodes can be obtained by 2272e4b17023SJohn Marinofollowing the @code{TREE_CHAIN} links. 2273e4b17023SJohn Marino 2274e4b17023SJohn Marino@item DECL_RESULT 2275e4b17023SJohn MarinoThis macro returns the @code{RESULT_DECL} for the function. 2276e4b17023SJohn Marino 2277e4b17023SJohn Marino@item DECL_SAVED_TREE 2278e4b17023SJohn MarinoThis macro returns the complete body of the function. 2279e4b17023SJohn Marino 2280e4b17023SJohn Marino@item TREE_TYPE 2281e4b17023SJohn MarinoThis macro returns the @code{FUNCTION_TYPE} or @code{METHOD_TYPE} for 2282e4b17023SJohn Marinothe function. 2283e4b17023SJohn Marino 2284e4b17023SJohn Marino@item DECL_INITIAL 2285e4b17023SJohn MarinoA function that has a definition in the current translation unit will 2286e4b17023SJohn Marinohave a non-@code{NULL} @code{DECL_INITIAL}. However, back ends should not make 2287e4b17023SJohn Marinouse of the particular value given by @code{DECL_INITIAL}. 2288e4b17023SJohn Marino 2289e4b17023SJohn MarinoIt should contain a tree of @code{BLOCK} nodes that mirrors the scopes 2290e4b17023SJohn Marinothat variables are bound in the function. Each block contains a list 2291e4b17023SJohn Marinoof decls declared in a basic block, a pointer to a chain of blocks at 2292e4b17023SJohn Marinothe next lower scope level, then a pointer to the next block at the 2293e4b17023SJohn Marinosame level and a backpointer to the parent @code{BLOCK} or 2294e4b17023SJohn Marino@code{FUNCTION_DECL}. So given a function as follows: 2295e4b17023SJohn Marino 2296e4b17023SJohn Marino@smallexample 2297e4b17023SJohn Marinovoid foo() 2298e4b17023SJohn Marino@{ 2299e4b17023SJohn Marino int a; 2300e4b17023SJohn Marino @{ 2301e4b17023SJohn Marino int b; 2302e4b17023SJohn Marino @} 2303e4b17023SJohn Marino int c; 2304e4b17023SJohn Marino@} 2305e4b17023SJohn Marino@end smallexample 2306e4b17023SJohn Marino 2307e4b17023SJohn Marinoyou would get the following: 2308e4b17023SJohn Marino 2309e4b17023SJohn Marino@smallexample 2310e4b17023SJohn Marinotree foo = FUNCTION_DECL; 2311e4b17023SJohn Marinotree decl_a = VAR_DECL; 2312e4b17023SJohn Marinotree decl_b = VAR_DECL; 2313e4b17023SJohn Marinotree decl_c = VAR_DECL; 2314e4b17023SJohn Marinotree block_a = BLOCK; 2315e4b17023SJohn Marinotree block_b = BLOCK; 2316e4b17023SJohn Marinotree block_c = BLOCK; 2317e4b17023SJohn MarinoBLOCK_VARS(block_a) = decl_a; 2318e4b17023SJohn MarinoBLOCK_SUBBLOCKS(block_a) = block_b; 2319e4b17023SJohn MarinoBLOCK_CHAIN(block_a) = block_c; 2320e4b17023SJohn MarinoBLOCK_SUPERCONTEXT(block_a) = foo; 2321e4b17023SJohn MarinoBLOCK_VARS(block_b) = decl_b; 2322e4b17023SJohn MarinoBLOCK_SUPERCONTEXT(block_b) = block_a; 2323e4b17023SJohn MarinoBLOCK_VARS(block_c) = decl_c; 2324e4b17023SJohn MarinoBLOCK_SUPERCONTEXT(block_c) = foo; 2325e4b17023SJohn MarinoDECL_INITIAL(foo) = block_a; 2326e4b17023SJohn Marino@end smallexample 2327e4b17023SJohn Marino 2328e4b17023SJohn Marino@end ftable 2329e4b17023SJohn Marino 2330e4b17023SJohn Marino@c --------------------------------------------------------------------- 2331e4b17023SJohn Marino@c Function Properties 2332e4b17023SJohn Marino@c --------------------------------------------------------------------- 2333e4b17023SJohn Marino 2334e4b17023SJohn Marino@node Function Properties 2335e4b17023SJohn Marino@subsection Function Properties 2336e4b17023SJohn Marino@cindex function properties 2337e4b17023SJohn Marino@cindex statements 2338e4b17023SJohn Marino 2339e4b17023SJohn MarinoTo determine the scope of a function, you can use the 2340e4b17023SJohn Marino@code{DECL_CONTEXT} macro. This macro will return the class 2341e4b17023SJohn Marino(either a @code{RECORD_TYPE} or a @code{UNION_TYPE}) or namespace (a 2342e4b17023SJohn Marino@code{NAMESPACE_DECL}) of which the function is a member. For a virtual 2343e4b17023SJohn Marinofunction, this macro returns the class in which the function was 2344e4b17023SJohn Marinoactually defined, not the base class in which the virtual declaration 2345e4b17023SJohn Marinooccurred. 2346e4b17023SJohn Marino 2347e4b17023SJohn MarinoIn C, the @code{DECL_CONTEXT} for a function maybe another function. 2348e4b17023SJohn MarinoThis representation indicates that the GNU nested function extension 2349e4b17023SJohn Marinois in use. For details on the semantics of nested functions, see the 2350e4b17023SJohn MarinoGCC Manual. The nested function can refer to local variables in its 2351e4b17023SJohn Marinocontaining function. Such references are not explicitly marked in the 2352e4b17023SJohn Marinotree structure; back ends must look at the @code{DECL_CONTEXT} for the 2353e4b17023SJohn Marinoreferenced @code{VAR_DECL}. If the @code{DECL_CONTEXT} for the 2354e4b17023SJohn Marinoreferenced @code{VAR_DECL} is not the same as the function currently 2355e4b17023SJohn Marinobeing processed, and neither @code{DECL_EXTERNAL} nor 2356e4b17023SJohn Marino@code{TREE_STATIC} hold, then the reference is to a local variable in 2357e4b17023SJohn Marinoa containing function, and the back end must take appropriate action. 2358e4b17023SJohn Marino 2359e4b17023SJohn Marino@ftable @code 2360e4b17023SJohn Marino@item DECL_EXTERNAL 2361e4b17023SJohn MarinoThis predicate holds if the function is undefined. 2362e4b17023SJohn Marino 2363e4b17023SJohn Marino@item TREE_PUBLIC 2364e4b17023SJohn MarinoThis predicate holds if the function has external linkage. 2365e4b17023SJohn Marino 2366e4b17023SJohn Marino@item TREE_STATIC 2367e4b17023SJohn MarinoThis predicate holds if the function has been defined. 2368e4b17023SJohn Marino 2369e4b17023SJohn Marino@item TREE_THIS_VOLATILE 2370e4b17023SJohn MarinoThis predicate holds if the function does not return normally. 2371e4b17023SJohn Marino 2372e4b17023SJohn Marino@item TREE_READONLY 2373e4b17023SJohn MarinoThis predicate holds if the function can only read its arguments. 2374e4b17023SJohn Marino 2375e4b17023SJohn Marino@item DECL_PURE_P 2376e4b17023SJohn MarinoThis predicate holds if the function can only read its arguments, but 2377e4b17023SJohn Marinomay also read global memory. 2378e4b17023SJohn Marino 2379e4b17023SJohn Marino@item DECL_VIRTUAL_P 2380e4b17023SJohn MarinoThis predicate holds if the function is virtual. 2381e4b17023SJohn Marino 2382e4b17023SJohn Marino@item DECL_ARTIFICIAL 2383e4b17023SJohn MarinoThis macro holds if the function was implicitly generated by the 2384e4b17023SJohn Marinocompiler, rather than explicitly declared. In addition to implicitly 2385e4b17023SJohn Marinogenerated class member functions, this macro holds for the special 2386e4b17023SJohn Marinofunctions created to implement static initialization and destruction, to 2387e4b17023SJohn Marinocompute run-time type information, and so forth. 2388e4b17023SJohn Marino 2389e4b17023SJohn Marino@item DECL_FUNCTION_SPECIFIC_TARGET 2390e4b17023SJohn MarinoThis macro returns a tree node that holds the target options that are 2391e4b17023SJohn Marinoto be used to compile this particular function or @code{NULL_TREE} if 2392e4b17023SJohn Marinothe function is to be compiled with the target options specified on 2393e4b17023SJohn Marinothe command line. 2394e4b17023SJohn Marino 2395e4b17023SJohn Marino@item DECL_FUNCTION_SPECIFIC_OPTIMIZATION 2396e4b17023SJohn MarinoThis macro returns a tree node that holds the optimization options 2397e4b17023SJohn Marinothat are to be used to compile this particular function or 2398e4b17023SJohn Marino@code{NULL_TREE} if the function is to be compiled with the 2399e4b17023SJohn Marinooptimization options specified on the command line. 2400e4b17023SJohn Marino 2401e4b17023SJohn Marino@end ftable 2402e4b17023SJohn Marino 2403e4b17023SJohn Marino@c --------------------------------------------------------------------- 2404e4b17023SJohn Marino@c Language-dependent trees 2405e4b17023SJohn Marino@c --------------------------------------------------------------------- 2406e4b17023SJohn Marino 2407e4b17023SJohn Marino@node Language-dependent trees 2408e4b17023SJohn Marino@section Language-dependent trees 2409e4b17023SJohn Marino@cindex language-dependent trees 2410e4b17023SJohn Marino 2411e4b17023SJohn MarinoFront ends may wish to keep some state associated with various GENERIC 2412e4b17023SJohn Marinotrees while parsing. To support this, trees provide a set of flags 2413e4b17023SJohn Marinothat may be used by the front end. They are accessed using 2414e4b17023SJohn Marino@code{TREE_LANG_FLAG_n} where @samp{n} is currently 0 through 6. 2415e4b17023SJohn Marino 2416e4b17023SJohn MarinoIf necessary, a front end can use some language-dependent tree 2417e4b17023SJohn Marinocodes in its GENERIC representation, so long as it provides a 2418e4b17023SJohn Marinohook for converting them to GIMPLE and doesn't expect them to 2419e4b17023SJohn Marinowork with any (hypothetical) optimizers that run before the 2420e4b17023SJohn Marinoconversion to GIMPLE@. The intermediate representation used while 2421e4b17023SJohn Marinoparsing C and C++ looks very little like GENERIC, but the C and 2422e4b17023SJohn MarinoC++ gimplifier hooks are perfectly happy to take it as input and 2423e4b17023SJohn Marinospit out GIMPLE@. 2424e4b17023SJohn Marino 2425e4b17023SJohn Marino 2426e4b17023SJohn Marino 2427e4b17023SJohn Marino@node C and C++ Trees 2428e4b17023SJohn Marino@section C and C++ Trees 2429e4b17023SJohn Marino 2430e4b17023SJohn MarinoThis section documents the internal representation used by GCC to 2431e4b17023SJohn Marinorepresent C and C++ source programs. When presented with a C or C++ 2432e4b17023SJohn Marinosource program, GCC parses the program, performs semantic analysis 2433e4b17023SJohn Marino(including the generation of error messages), and then produces the 2434e4b17023SJohn Marinointernal representation described here. This representation contains a 2435e4b17023SJohn Marinocomplete representation for the entire translation unit provided as 2436e4b17023SJohn Marinoinput to the front end. This representation is then typically processed 2437e4b17023SJohn Marinoby a code-generator in order to produce machine code, but could also be 2438e4b17023SJohn Marinoused in the creation of source browsers, intelligent editors, automatic 2439e4b17023SJohn Marinodocumentation generators, interpreters, and any other programs needing 2440e4b17023SJohn Marinothe ability to process C or C++ code. 2441e4b17023SJohn Marino 2442e4b17023SJohn MarinoThis section explains the internal representation. In particular, it 2443e4b17023SJohn Marinodocuments the internal representation for C and C++ source 2444e4b17023SJohn Marinoconstructs, and the macros, functions, and variables that can be used to 2445e4b17023SJohn Marinoaccess these constructs. The C++ representation is largely a superset 2446e4b17023SJohn Marinoof the representation used in the C front end. There is only one 2447e4b17023SJohn Marinoconstruct used in C that does not appear in the C++ front end and that 2448e4b17023SJohn Marinois the GNU ``nested function'' extension. Many of the macros documented 2449e4b17023SJohn Marinohere do not apply in C because the corresponding language constructs do 2450e4b17023SJohn Marinonot appear in C@. 2451e4b17023SJohn Marino 2452e4b17023SJohn MarinoThe C and C++ front ends generate a mix of GENERIC trees and ones 2453e4b17023SJohn Marinospecific to C and C++. These language-specific trees are higher-level 2454e4b17023SJohn Marinoconstructs than the ones in GENERIC to make the parser's job easier. 2455e4b17023SJohn MarinoThis section describes those trees that aren't part of GENERIC as well 2456e4b17023SJohn Marinoas aspects of GENERIC trees that are treated in a language-specific 2457e4b17023SJohn Marinomanner. 2458e4b17023SJohn Marino 2459e4b17023SJohn MarinoIf you are developing a ``back end'', be it is a code-generator or some 2460e4b17023SJohn Marinoother tool, that uses this representation, you may occasionally find 2461e4b17023SJohn Marinothat you need to ask questions not easily answered by the functions and 2462e4b17023SJohn Marinomacros available here. If that situation occurs, it is quite likely 2463e4b17023SJohn Marinothat GCC already supports the functionality you desire, but that the 2464e4b17023SJohn Marinointerface is simply not documented here. In that case, you should ask 2465e4b17023SJohn Marinothe GCC maintainers (via mail to @email{gcc@@gcc.gnu.org}) about 2466e4b17023SJohn Marinodocumenting the functionality you require. Similarly, if you find 2467e4b17023SJohn Marinoyourself writing functions that do not deal directly with your back end, 2468e4b17023SJohn Marinobut instead might be useful to other people using the GCC front end, you 2469e4b17023SJohn Marinoshould submit your patches for inclusion in GCC@. 2470e4b17023SJohn Marino 2471e4b17023SJohn Marino@menu 2472e4b17023SJohn Marino* Types for C++:: Fundamental and aggregate types. 2473e4b17023SJohn Marino* Namespaces:: Namespaces. 2474e4b17023SJohn Marino* Classes:: Classes. 2475e4b17023SJohn Marino* Functions for C++:: Overloading and accessors for C++. 2476e4b17023SJohn Marino* Statements for C++:: Statements specific to C and C++. 2477e4b17023SJohn Marino* C++ Expressions:: From @code{typeid} to @code{throw}. 2478e4b17023SJohn Marino@end menu 2479e4b17023SJohn Marino 2480e4b17023SJohn Marino@node Types for C++ 2481e4b17023SJohn Marino@subsection Types for C++ 2482e4b17023SJohn Marino@tindex UNKNOWN_TYPE 2483e4b17023SJohn Marino@tindex TYPENAME_TYPE 2484e4b17023SJohn Marino@tindex TYPEOF_TYPE 2485e4b17023SJohn Marino@findex cp_type_quals 2486e4b17023SJohn Marino@findex TYPE_UNQUALIFIED 2487e4b17023SJohn Marino@findex TYPE_QUAL_CONST 2488e4b17023SJohn Marino@findex TYPE_QUAL_VOLATILE 2489e4b17023SJohn Marino@findex TYPE_QUAL_RESTRICT 2490e4b17023SJohn Marino@findex TYPE_MAIN_VARIANT 2491e4b17023SJohn Marino@cindex qualified type 2492e4b17023SJohn Marino@findex TYPE_SIZE 2493e4b17023SJohn Marino@findex TYPE_ALIGN 2494e4b17023SJohn Marino@findex TYPE_PRECISION 2495e4b17023SJohn Marino@findex TYPE_ARG_TYPES 2496e4b17023SJohn Marino@findex TYPE_METHOD_BASETYPE 2497e4b17023SJohn Marino@findex TYPE_PTRMEM_P 2498e4b17023SJohn Marino@findex TYPE_OFFSET_BASETYPE 2499e4b17023SJohn Marino@findex TREE_TYPE 2500e4b17023SJohn Marino@findex TYPE_CONTEXT 2501e4b17023SJohn Marino@findex TYPE_NAME 2502e4b17023SJohn Marino@findex TYPENAME_TYPE_FULLNAME 2503e4b17023SJohn Marino@findex TYPE_FIELDS 2504e4b17023SJohn Marino@findex TYPE_PTROBV_P 2505e4b17023SJohn Marino 2506e4b17023SJohn MarinoIn C++, an array type is not qualified; rather the type of the array 2507e4b17023SJohn Marinoelements is qualified. This situation is reflected in the intermediate 2508e4b17023SJohn Marinorepresentation. The macros described here will always examine the 2509e4b17023SJohn Marinoqualification of the underlying element type when applied to an array 2510e4b17023SJohn Marinotype. (If the element type is itself an array, then the recursion 2511e4b17023SJohn Marinocontinues until a non-array type is found, and the qualification of this 2512e4b17023SJohn Marinotype is examined.) So, for example, @code{CP_TYPE_CONST_P} will hold of 2513e4b17023SJohn Marinothe type @code{const int ()[7]}, denoting an array of seven @code{int}s. 2514e4b17023SJohn Marino 2515e4b17023SJohn MarinoThe following functions and macros deal with cv-qualification of types: 2516e4b17023SJohn Marino@ftable @code 2517e4b17023SJohn Marino@item cp_type_quals 2518e4b17023SJohn MarinoThis function returns the set of type qualifiers applied to this type. 2519e4b17023SJohn MarinoThis value is @code{TYPE_UNQUALIFIED} if no qualifiers have been 2520e4b17023SJohn Marinoapplied. The @code{TYPE_QUAL_CONST} bit is set if the type is 2521e4b17023SJohn Marino@code{const}-qualified. The @code{TYPE_QUAL_VOLATILE} bit is set if the 2522e4b17023SJohn Marinotype is @code{volatile}-qualified. The @code{TYPE_QUAL_RESTRICT} bit is 2523e4b17023SJohn Marinoset if the type is @code{restrict}-qualified. 2524e4b17023SJohn Marino 2525e4b17023SJohn Marino@item CP_TYPE_CONST_P 2526e4b17023SJohn MarinoThis macro holds if the type is @code{const}-qualified. 2527e4b17023SJohn Marino 2528e4b17023SJohn Marino@item CP_TYPE_VOLATILE_P 2529e4b17023SJohn MarinoThis macro holds if the type is @code{volatile}-qualified. 2530e4b17023SJohn Marino 2531e4b17023SJohn Marino@item CP_TYPE_RESTRICT_P 2532e4b17023SJohn MarinoThis macro holds if the type is @code{restrict}-qualified. 2533e4b17023SJohn Marino 2534e4b17023SJohn Marino@item CP_TYPE_CONST_NON_VOLATILE_P 2535e4b17023SJohn MarinoThis predicate holds for a type that is @code{const}-qualified, but 2536e4b17023SJohn Marino@emph{not} @code{volatile}-qualified; other cv-qualifiers are ignored as 2537e4b17023SJohn Marinowell: only the @code{const}-ness is tested. 2538e4b17023SJohn Marino 2539e4b17023SJohn Marino@end ftable 2540e4b17023SJohn Marino 2541e4b17023SJohn MarinoA few other macros and functions are usable with all types: 2542e4b17023SJohn Marino@ftable @code 2543e4b17023SJohn Marino@item TYPE_SIZE 2544e4b17023SJohn MarinoThe number of bits required to represent the type, represented as an 2545e4b17023SJohn Marino@code{INTEGER_CST}. For an incomplete type, @code{TYPE_SIZE} will be 2546e4b17023SJohn Marino@code{NULL_TREE}. 2547e4b17023SJohn Marino 2548e4b17023SJohn Marino@item TYPE_ALIGN 2549e4b17023SJohn MarinoThe alignment of the type, in bits, represented as an @code{int}. 2550e4b17023SJohn Marino 2551e4b17023SJohn Marino@item TYPE_NAME 2552e4b17023SJohn MarinoThis macro returns a declaration (in the form of a @code{TYPE_DECL}) for 2553e4b17023SJohn Marinothe type. (Note this macro does @emph{not} return an 2554e4b17023SJohn Marino@code{IDENTIFIER_NODE}, as you might expect, given its name!) You can 2555e4b17023SJohn Marinolook at the @code{DECL_NAME} of the @code{TYPE_DECL} to obtain the 2556e4b17023SJohn Marinoactual name of the type. The @code{TYPE_NAME} will be @code{NULL_TREE} 2557e4b17023SJohn Marinofor a type that is not a built-in type, the result of a typedef, or a 2558e4b17023SJohn Marinonamed class type. 2559e4b17023SJohn Marino 2560e4b17023SJohn Marino@item CP_INTEGRAL_TYPE 2561e4b17023SJohn MarinoThis predicate holds if the type is an integral type. Notice that in 2562e4b17023SJohn MarinoC++, enumerations are @emph{not} integral types. 2563e4b17023SJohn Marino 2564e4b17023SJohn Marino@item ARITHMETIC_TYPE_P 2565e4b17023SJohn MarinoThis predicate holds if the type is an integral type (in the C++ sense) 2566e4b17023SJohn Marinoor a floating point type. 2567e4b17023SJohn Marino 2568e4b17023SJohn Marino@item CLASS_TYPE_P 2569e4b17023SJohn MarinoThis predicate holds for a class-type. 2570e4b17023SJohn Marino 2571e4b17023SJohn Marino@item TYPE_BUILT_IN 2572e4b17023SJohn MarinoThis predicate holds for a built-in type. 2573e4b17023SJohn Marino 2574e4b17023SJohn Marino@item TYPE_PTRMEM_P 2575e4b17023SJohn MarinoThis predicate holds if the type is a pointer to data member. 2576e4b17023SJohn Marino 2577e4b17023SJohn Marino@item TYPE_PTR_P 2578e4b17023SJohn MarinoThis predicate holds if the type is a pointer type, and the pointee is 2579e4b17023SJohn Marinonot a data member. 2580e4b17023SJohn Marino 2581e4b17023SJohn Marino@item TYPE_PTRFN_P 2582e4b17023SJohn MarinoThis predicate holds for a pointer to function type. 2583e4b17023SJohn Marino 2584e4b17023SJohn Marino@item TYPE_PTROB_P 2585e4b17023SJohn MarinoThis predicate holds for a pointer to object type. Note however that it 2586e4b17023SJohn Marinodoes not hold for the generic pointer to object type @code{void *}. You 2587e4b17023SJohn Marinomay use @code{TYPE_PTROBV_P} to test for a pointer to object type as 2588e4b17023SJohn Marinowell as @code{void *}. 2589e4b17023SJohn Marino 2590e4b17023SJohn Marino@end ftable 2591e4b17023SJohn Marino 2592e4b17023SJohn MarinoThe table below describes types specific to C and C++ as well as 2593e4b17023SJohn Marinolanguage-dependent info about GENERIC types. 2594e4b17023SJohn Marino 2595e4b17023SJohn Marino@table @code 2596e4b17023SJohn Marino 2597e4b17023SJohn Marino@item POINTER_TYPE 2598e4b17023SJohn MarinoUsed to represent pointer types, and pointer to data member types. If 2599e4b17023SJohn Marino@code{TREE_TYPE} 2600e4b17023SJohn Marinois a pointer to data member type, then @code{TYPE_PTRMEM_P} will hold. 2601e4b17023SJohn MarinoFor a pointer to data member type of the form @samp{T X::*}, 2602e4b17023SJohn Marino@code{TYPE_PTRMEM_CLASS_TYPE} will be the type @code{X}, while 2603e4b17023SJohn Marino@code{TYPE_PTRMEM_POINTED_TO_TYPE} will be the type @code{T}. 2604e4b17023SJohn Marino 2605e4b17023SJohn Marino@item RECORD_TYPE 2606e4b17023SJohn MarinoUsed to represent @code{struct} and @code{class} types in C and C++. If 2607e4b17023SJohn Marino@code{TYPE_PTRMEMFUNC_P} holds, then this type is a pointer-to-member 2608e4b17023SJohn Marinotype. In that case, the @code{TYPE_PTRMEMFUNC_FN_TYPE} is a 2609e4b17023SJohn Marino@code{POINTER_TYPE} pointing to a @code{METHOD_TYPE}. The 2610e4b17023SJohn Marino@code{METHOD_TYPE} is the type of a function pointed to by the 2611e4b17023SJohn Marinopointer-to-member function. If @code{TYPE_PTRMEMFUNC_P} does not hold, 2612e4b17023SJohn Marinothis type is a class type. For more information, @pxref{Classes}. 2613e4b17023SJohn Marino 2614e4b17023SJohn Marino@item UNKNOWN_TYPE 2615e4b17023SJohn MarinoThis node is used to represent a type the knowledge of which is 2616e4b17023SJohn Marinoinsufficient for a sound processing. 2617e4b17023SJohn Marino 2618e4b17023SJohn Marino@item TYPENAME_TYPE 2619e4b17023SJohn MarinoUsed to represent a construct of the form @code{typename T::A}. The 2620e4b17023SJohn Marino@code{TYPE_CONTEXT} is @code{T}; the @code{TYPE_NAME} is an 2621e4b17023SJohn Marino@code{IDENTIFIER_NODE} for @code{A}. If the type is specified via a 2622e4b17023SJohn Marinotemplate-id, then @code{TYPENAME_TYPE_FULLNAME} yields a 2623e4b17023SJohn Marino@code{TEMPLATE_ID_EXPR}. The @code{TREE_TYPE} is non-@code{NULL} if the 2624e4b17023SJohn Marinonode is implicitly generated in support for the implicit typename 2625e4b17023SJohn Marinoextension; in which case the @code{TREE_TYPE} is a type node for the 2626e4b17023SJohn Marinobase-class. 2627e4b17023SJohn Marino 2628e4b17023SJohn Marino@item TYPEOF_TYPE 2629e4b17023SJohn MarinoUsed to represent the @code{__typeof__} extension. The 2630e4b17023SJohn Marino@code{TYPE_FIELDS} is the expression the type of which is being 2631e4b17023SJohn Marinorepresented. 2632e4b17023SJohn Marino 2633e4b17023SJohn Marino@end table 2634e4b17023SJohn Marino 2635e4b17023SJohn Marino 2636e4b17023SJohn Marino@c --------------------------------------------------------------------- 2637e4b17023SJohn Marino@c Namespaces 2638e4b17023SJohn Marino@c --------------------------------------------------------------------- 2639e4b17023SJohn Marino 2640e4b17023SJohn Marino@node Namespaces 2641e4b17023SJohn Marino@subsection Namespaces 2642e4b17023SJohn Marino@cindex namespace, scope 2643e4b17023SJohn Marino@tindex NAMESPACE_DECL 2644e4b17023SJohn Marino 2645e4b17023SJohn MarinoThe root of the entire intermediate representation is the variable 2646e4b17023SJohn Marino@code{global_namespace}. This is the namespace specified with @code{::} 2647e4b17023SJohn Marinoin C++ source code. All other namespaces, types, variables, functions, 2648e4b17023SJohn Marinoand so forth can be found starting with this namespace. 2649e4b17023SJohn Marino 2650e4b17023SJohn MarinoHowever, except for the fact that it is distinguished as the root of the 2651e4b17023SJohn Marinorepresentation, the global namespace is no different from any other 2652e4b17023SJohn Marinonamespace. Thus, in what follows, we describe namespaces generally, 2653e4b17023SJohn Marinorather than the global namespace in particular. 2654e4b17023SJohn Marino 2655e4b17023SJohn MarinoA namespace is represented by a @code{NAMESPACE_DECL} node. 2656e4b17023SJohn Marino 2657e4b17023SJohn MarinoThe following macros and functions can be used on a @code{NAMESPACE_DECL}: 2658e4b17023SJohn Marino 2659e4b17023SJohn Marino@ftable @code 2660e4b17023SJohn Marino@item DECL_NAME 2661e4b17023SJohn MarinoThis macro is used to obtain the @code{IDENTIFIER_NODE} corresponding to 2662e4b17023SJohn Marinothe unqualified name of the name of the namespace (@pxref{Identifiers}). 2663e4b17023SJohn MarinoThe name of the global namespace is @samp{::}, even though in C++ the 2664e4b17023SJohn Marinoglobal namespace is unnamed. However, you should use comparison with 2665e4b17023SJohn Marino@code{global_namespace}, rather than @code{DECL_NAME} to determine 2666e4b17023SJohn Marinowhether or not a namespace is the global one. An unnamed namespace 2667e4b17023SJohn Marinowill have a @code{DECL_NAME} equal to @code{anonymous_namespace_name}. 2668e4b17023SJohn MarinoWithin a single translation unit, all unnamed namespaces will have the 2669e4b17023SJohn Marinosame name. 2670e4b17023SJohn Marino 2671e4b17023SJohn Marino@item DECL_CONTEXT 2672e4b17023SJohn MarinoThis macro returns the enclosing namespace. The @code{DECL_CONTEXT} for 2673e4b17023SJohn Marinothe @code{global_namespace} is @code{NULL_TREE}. 2674e4b17023SJohn Marino 2675e4b17023SJohn Marino@item DECL_NAMESPACE_ALIAS 2676e4b17023SJohn MarinoIf this declaration is for a namespace alias, then 2677e4b17023SJohn Marino@code{DECL_NAMESPACE_ALIAS} is the namespace for which this one is an 2678e4b17023SJohn Marinoalias. 2679e4b17023SJohn Marino 2680e4b17023SJohn MarinoDo not attempt to use @code{cp_namespace_decls} for a namespace which is 2681e4b17023SJohn Marinoan alias. Instead, follow @code{DECL_NAMESPACE_ALIAS} links until you 2682e4b17023SJohn Marinoreach an ordinary, non-alias, namespace, and call 2683e4b17023SJohn Marino@code{cp_namespace_decls} there. 2684e4b17023SJohn Marino 2685e4b17023SJohn Marino@item DECL_NAMESPACE_STD_P 2686e4b17023SJohn MarinoThis predicate holds if the namespace is the special @code{::std} 2687e4b17023SJohn Marinonamespace. 2688e4b17023SJohn Marino 2689e4b17023SJohn Marino@item cp_namespace_decls 2690e4b17023SJohn MarinoThis function will return the declarations contained in the namespace, 2691e4b17023SJohn Marinoincluding types, overloaded functions, other namespaces, and so forth. 2692e4b17023SJohn MarinoIf there are no declarations, this function will return 2693e4b17023SJohn Marino@code{NULL_TREE}. The declarations are connected through their 2694e4b17023SJohn Marino@code{TREE_CHAIN} fields. 2695e4b17023SJohn Marino 2696e4b17023SJohn MarinoAlthough most entries on this list will be declarations, 2697e4b17023SJohn Marino@code{TREE_LIST} nodes may also appear. In this case, the 2698e4b17023SJohn Marino@code{TREE_VALUE} will be an @code{OVERLOAD}. The value of the 2699e4b17023SJohn Marino@code{TREE_PURPOSE} is unspecified; back ends should ignore this value. 2700e4b17023SJohn MarinoAs with the other kinds of declarations returned by 2701e4b17023SJohn Marino@code{cp_namespace_decls}, the @code{TREE_CHAIN} will point to the next 2702e4b17023SJohn Marinodeclaration in this list. 2703e4b17023SJohn Marino 2704e4b17023SJohn MarinoFor more information on the kinds of declarations that can occur on this 2705e4b17023SJohn Marinolist, @xref{Declarations}. Some declarations will not appear on this 2706e4b17023SJohn Marinolist. In particular, no @code{FIELD_DECL}, @code{LABEL_DECL}, or 2707e4b17023SJohn Marino@code{PARM_DECL} nodes will appear here. 2708e4b17023SJohn Marino 2709e4b17023SJohn MarinoThis function cannot be used with namespaces that have 2710e4b17023SJohn Marino@code{DECL_NAMESPACE_ALIAS} set. 2711e4b17023SJohn Marino 2712e4b17023SJohn Marino@end ftable 2713e4b17023SJohn Marino 2714e4b17023SJohn Marino@c --------------------------------------------------------------------- 2715e4b17023SJohn Marino@c Classes 2716e4b17023SJohn Marino@c --------------------------------------------------------------------- 2717e4b17023SJohn Marino 2718e4b17023SJohn Marino@node Classes 2719e4b17023SJohn Marino@subsection Classes 2720e4b17023SJohn Marino@cindex class, scope 2721e4b17023SJohn Marino@tindex RECORD_TYPE 2722e4b17023SJohn Marino@tindex UNION_TYPE 2723e4b17023SJohn Marino@findex CLASSTYPE_DECLARED_CLASS 2724e4b17023SJohn Marino@findex TYPE_BINFO 2725e4b17023SJohn Marino@findex BINFO_TYPE 2726e4b17023SJohn Marino@findex TYPE_FIELDS 2727e4b17023SJohn Marino@findex TYPE_VFIELD 2728e4b17023SJohn Marino@findex TYPE_METHODS 2729e4b17023SJohn Marino 2730e4b17023SJohn MarinoBesides namespaces, the other high-level scoping construct in C++ is the 2731e4b17023SJohn Marinoclass. (Throughout this manual the term @dfn{class} is used to mean the 2732e4b17023SJohn Marinotypes referred to in the ANSI/ISO C++ Standard as classes; these include 2733e4b17023SJohn Marinotypes defined with the @code{class}, @code{struct}, and @code{union} 2734e4b17023SJohn Marinokeywords.) 2735e4b17023SJohn Marino 2736e4b17023SJohn MarinoA class type is represented by either a @code{RECORD_TYPE} or a 2737e4b17023SJohn Marino@code{UNION_TYPE}. A class declared with the @code{union} tag is 2738e4b17023SJohn Marinorepresented by a @code{UNION_TYPE}, while classes declared with either 2739e4b17023SJohn Marinothe @code{struct} or the @code{class} tag are represented by 2740e4b17023SJohn Marino@code{RECORD_TYPE}s. You can use the @code{CLASSTYPE_DECLARED_CLASS} 2741e4b17023SJohn Marinomacro to discern whether or not a particular type is a @code{class} as 2742e4b17023SJohn Marinoopposed to a @code{struct}. This macro will be true only for classes 2743e4b17023SJohn Marinodeclared with the @code{class} tag. 2744e4b17023SJohn Marino 2745e4b17023SJohn MarinoAlmost all non-function members are available on the @code{TYPE_FIELDS} 2746e4b17023SJohn Marinolist. Given one member, the next can be found by following the 2747e4b17023SJohn Marino@code{TREE_CHAIN}. You should not depend in any way on the order in 2748e4b17023SJohn Marinowhich fields appear on this list. All nodes on this list will be 2749e4b17023SJohn Marino@samp{DECL} nodes. A @code{FIELD_DECL} is used to represent a non-static 2750e4b17023SJohn Marinodata member, a @code{VAR_DECL} is used to represent a static data 2751e4b17023SJohn Marinomember, and a @code{TYPE_DECL} is used to represent a type. Note that 2752e4b17023SJohn Marinothe @code{CONST_DECL} for an enumeration constant will appear on this 2753e4b17023SJohn Marinolist, if the enumeration type was declared in the class. (Of course, 2754e4b17023SJohn Marinothe @code{TYPE_DECL} for the enumeration type will appear here as well.) 2755e4b17023SJohn MarinoThere are no entries for base classes on this list. In particular, 2756e4b17023SJohn Marinothere is no @code{FIELD_DECL} for the ``base-class portion'' of an 2757e4b17023SJohn Marinoobject. 2758e4b17023SJohn Marino 2759e4b17023SJohn MarinoThe @code{TYPE_VFIELD} is a compiler-generated field used to point to 2760e4b17023SJohn Marinovirtual function tables. It may or may not appear on the 2761e4b17023SJohn Marino@code{TYPE_FIELDS} list. However, back ends should handle the 2762e4b17023SJohn Marino@code{TYPE_VFIELD} just like all the entries on the @code{TYPE_FIELDS} 2763e4b17023SJohn Marinolist. 2764e4b17023SJohn Marino 2765e4b17023SJohn MarinoThe function members are available on the @code{TYPE_METHODS} list. 2766e4b17023SJohn MarinoAgain, subsequent members are found by following the @code{TREE_CHAIN} 2767e4b17023SJohn Marinofield. If a function is overloaded, each of the overloaded functions 2768e4b17023SJohn Marinoappears; no @code{OVERLOAD} nodes appear on the @code{TYPE_METHODS} 2769e4b17023SJohn Marinolist. Implicitly declared functions (including default constructors, 2770e4b17023SJohn Marinocopy constructors, assignment operators, and destructors) will appear on 2771e4b17023SJohn Marinothis list as well. 2772e4b17023SJohn Marino 2773e4b17023SJohn MarinoEvery class has an associated @dfn{binfo}, which can be obtained with 2774e4b17023SJohn Marino@code{TYPE_BINFO}. Binfos are used to represent base-classes. The 2775e4b17023SJohn Marinobinfo given by @code{TYPE_BINFO} is the degenerate case, whereby every 2776e4b17023SJohn Marinoclass is considered to be its own base-class. The base binfos for a 2777e4b17023SJohn Marinoparticular binfo are held in a vector, whose length is obtained with 2778e4b17023SJohn Marino@code{BINFO_N_BASE_BINFOS}. The base binfos themselves are obtained 2779e4b17023SJohn Marinowith @code{BINFO_BASE_BINFO} and @code{BINFO_BASE_ITERATE}. To add a 2780e4b17023SJohn Marinonew binfo, use @code{BINFO_BASE_APPEND}. The vector of base binfos can 2781e4b17023SJohn Marinobe obtained with @code{BINFO_BASE_BINFOS}, but normally you do not need 2782e4b17023SJohn Marinoto use that. The class type associated with a binfo is given by 2783e4b17023SJohn Marino@code{BINFO_TYPE}. It is not always the case that @code{BINFO_TYPE 2784e4b17023SJohn Marino(TYPE_BINFO (x))}, because of typedefs and qualified types. Neither is 2785e4b17023SJohn Marinoit the case that @code{TYPE_BINFO (BINFO_TYPE (y))} is the same binfo as 2786e4b17023SJohn Marino@code{y}. The reason is that if @code{y} is a binfo representing a 2787e4b17023SJohn Marinobase-class @code{B} of a derived class @code{D}, then @code{BINFO_TYPE 2788e4b17023SJohn Marino(y)} will be @code{B}, and @code{TYPE_BINFO (BINFO_TYPE (y))} will be 2789e4b17023SJohn Marino@code{B} as its own base-class, rather than as a base-class of @code{D}. 2790e4b17023SJohn Marino 2791e4b17023SJohn MarinoThe access to a base type can be found with @code{BINFO_BASE_ACCESS}. 2792e4b17023SJohn MarinoThis will produce @code{access_public_node}, @code{access_private_node} 2793e4b17023SJohn Marinoor @code{access_protected_node}. If bases are always public, 2794e4b17023SJohn Marino@code{BINFO_BASE_ACCESSES} may be @code{NULL}. 2795e4b17023SJohn Marino 2796e4b17023SJohn Marino@code{BINFO_VIRTUAL_P} is used to specify whether the binfo is inherited 2797e4b17023SJohn Marinovirtually or not. The other flags, @code{BINFO_MARKED_P} and 2798e4b17023SJohn Marino@code{BINFO_FLAG_1} to @code{BINFO_FLAG_6} can be used for language 2799e4b17023SJohn Marinospecific use. 2800e4b17023SJohn Marino 2801e4b17023SJohn MarinoThe following macros can be used on a tree node representing a class-type. 2802e4b17023SJohn Marino 2803e4b17023SJohn Marino@ftable @code 2804e4b17023SJohn Marino@item LOCAL_CLASS_P 2805e4b17023SJohn MarinoThis predicate holds if the class is local class @emph{i.e.}@: declared 2806e4b17023SJohn Marinoinside a function body. 2807e4b17023SJohn Marino 2808e4b17023SJohn Marino@item TYPE_POLYMORPHIC_P 2809e4b17023SJohn MarinoThis predicate holds if the class has at least one virtual function 2810e4b17023SJohn Marino(declared or inherited). 2811e4b17023SJohn Marino 2812e4b17023SJohn Marino@item TYPE_HAS_DEFAULT_CONSTRUCTOR 2813e4b17023SJohn MarinoThis predicate holds whenever its argument represents a class-type with 2814e4b17023SJohn Marinodefault constructor. 2815e4b17023SJohn Marino 2816e4b17023SJohn Marino@item CLASSTYPE_HAS_MUTABLE 2817e4b17023SJohn Marino@itemx TYPE_HAS_MUTABLE_P 2818e4b17023SJohn MarinoThese predicates hold for a class-type having a mutable data member. 2819e4b17023SJohn Marino 2820e4b17023SJohn Marino@item CLASSTYPE_NON_POD_P 2821e4b17023SJohn MarinoThis predicate holds only for class-types that are not PODs. 2822e4b17023SJohn Marino 2823e4b17023SJohn Marino@item TYPE_HAS_NEW_OPERATOR 2824e4b17023SJohn MarinoThis predicate holds for a class-type that defines 2825e4b17023SJohn Marino@code{operator new}. 2826e4b17023SJohn Marino 2827e4b17023SJohn Marino@item TYPE_HAS_ARRAY_NEW_OPERATOR 2828e4b17023SJohn MarinoThis predicate holds for a class-type for which 2829e4b17023SJohn Marino@code{operator new[]} is defined. 2830e4b17023SJohn Marino 2831e4b17023SJohn Marino@item TYPE_OVERLOADS_CALL_EXPR 2832e4b17023SJohn MarinoThis predicate holds for class-type for which the function call 2833e4b17023SJohn Marino@code{operator()} is overloaded. 2834e4b17023SJohn Marino 2835e4b17023SJohn Marino@item TYPE_OVERLOADS_ARRAY_REF 2836e4b17023SJohn MarinoThis predicate holds for a class-type that overloads 2837e4b17023SJohn Marino@code{operator[]} 2838e4b17023SJohn Marino 2839e4b17023SJohn Marino@item TYPE_OVERLOADS_ARROW 2840e4b17023SJohn MarinoThis predicate holds for a class-type for which @code{operator->} is 2841e4b17023SJohn Marinooverloaded. 2842e4b17023SJohn Marino 2843e4b17023SJohn Marino@end ftable 2844e4b17023SJohn Marino 2845e4b17023SJohn Marino@node Functions for C++ 2846e4b17023SJohn Marino@subsection Functions for C++ 2847e4b17023SJohn Marino@cindex function 2848e4b17023SJohn Marino@tindex FUNCTION_DECL 2849e4b17023SJohn Marino@tindex OVERLOAD 2850e4b17023SJohn Marino@findex OVL_CURRENT 2851e4b17023SJohn Marino@findex OVL_NEXT 2852e4b17023SJohn Marino 2853e4b17023SJohn MarinoA function is represented by a @code{FUNCTION_DECL} node. A set of 2854e4b17023SJohn Marinooverloaded functions is sometimes represented by an @code{OVERLOAD} node. 2855e4b17023SJohn Marino 2856e4b17023SJohn MarinoAn @code{OVERLOAD} node is not a declaration, so none of the 2857e4b17023SJohn Marino@samp{DECL_} macros should be used on an @code{OVERLOAD}. An 2858e4b17023SJohn Marino@code{OVERLOAD} node is similar to a @code{TREE_LIST}. Use 2859e4b17023SJohn Marino@code{OVL_CURRENT} to get the function associated with an 2860e4b17023SJohn Marino@code{OVERLOAD} node; use @code{OVL_NEXT} to get the next 2861e4b17023SJohn Marino@code{OVERLOAD} node in the list of overloaded functions. The macros 2862e4b17023SJohn Marino@code{OVL_CURRENT} and @code{OVL_NEXT} are actually polymorphic; you can 2863e4b17023SJohn Marinouse them to work with @code{FUNCTION_DECL} nodes as well as with 2864e4b17023SJohn Marinooverloads. In the case of a @code{FUNCTION_DECL}, @code{OVL_CURRENT} 2865e4b17023SJohn Marinowill always return the function itself, and @code{OVL_NEXT} will always 2866e4b17023SJohn Marinobe @code{NULL_TREE}. 2867e4b17023SJohn Marino 2868e4b17023SJohn MarinoTo determine the scope of a function, you can use the 2869e4b17023SJohn Marino@code{DECL_CONTEXT} macro. This macro will return the class 2870e4b17023SJohn Marino(either a @code{RECORD_TYPE} or a @code{UNION_TYPE}) or namespace (a 2871e4b17023SJohn Marino@code{NAMESPACE_DECL}) of which the function is a member. For a virtual 2872e4b17023SJohn Marinofunction, this macro returns the class in which the function was 2873e4b17023SJohn Marinoactually defined, not the base class in which the virtual declaration 2874e4b17023SJohn Marinooccurred. 2875e4b17023SJohn Marino 2876e4b17023SJohn MarinoIf a friend function is defined in a class scope, the 2877e4b17023SJohn Marino@code{DECL_FRIEND_CONTEXT} macro can be used to determine the class in 2878e4b17023SJohn Marinowhich it was defined. For example, in 2879e4b17023SJohn Marino@smallexample 2880e4b17023SJohn Marinoclass C @{ friend void f() @{@} @}; 2881e4b17023SJohn Marino@end smallexample 2882e4b17023SJohn Marino@noindent 2883e4b17023SJohn Marinothe @code{DECL_CONTEXT} for @code{f} will be the 2884e4b17023SJohn Marino@code{global_namespace}, but the @code{DECL_FRIEND_CONTEXT} will be the 2885e4b17023SJohn Marino@code{RECORD_TYPE} for @code{C}. 2886e4b17023SJohn Marino 2887e4b17023SJohn Marino 2888e4b17023SJohn MarinoThe following macros and functions can be used on a @code{FUNCTION_DECL}: 2889e4b17023SJohn Marino@ftable @code 2890e4b17023SJohn Marino@item DECL_MAIN_P 2891e4b17023SJohn MarinoThis predicate holds for a function that is the program entry point 2892e4b17023SJohn Marino@code{::code}. 2893e4b17023SJohn Marino 2894e4b17023SJohn Marino@item DECL_LOCAL_FUNCTION_P 2895e4b17023SJohn MarinoThis predicate holds if the function was declared at block scope, even 2896e4b17023SJohn Marinothough it has a global scope. 2897e4b17023SJohn Marino 2898e4b17023SJohn Marino@item DECL_ANTICIPATED 2899e4b17023SJohn MarinoThis predicate holds if the function is a built-in function but its 2900e4b17023SJohn Marinoprototype is not yet explicitly declared. 2901e4b17023SJohn Marino 2902e4b17023SJohn Marino@item DECL_EXTERN_C_FUNCTION_P 2903e4b17023SJohn MarinoThis predicate holds if the function is declared as an 2904e4b17023SJohn Marino`@code{extern "C"}' function. 2905e4b17023SJohn Marino 2906e4b17023SJohn Marino@item DECL_LINKONCE_P 2907e4b17023SJohn MarinoThis macro holds if multiple copies of this function may be emitted in 2908e4b17023SJohn Marinovarious translation units. It is the responsibility of the linker to 2909e4b17023SJohn Marinomerge the various copies. Template instantiations are the most common 2910e4b17023SJohn Marinoexample of functions for which @code{DECL_LINKONCE_P} holds; G++ 2911e4b17023SJohn Marinoinstantiates needed templates in all translation units which require them, 2912e4b17023SJohn Marinoand then relies on the linker to remove duplicate instantiations. 2913e4b17023SJohn Marino 2914e4b17023SJohn MarinoFIXME: This macro is not yet implemented. 2915e4b17023SJohn Marino 2916e4b17023SJohn Marino@item DECL_FUNCTION_MEMBER_P 2917e4b17023SJohn MarinoThis macro holds if the function is a member of a class, rather than a 2918e4b17023SJohn Marinomember of a namespace. 2919e4b17023SJohn Marino 2920e4b17023SJohn Marino@item DECL_STATIC_FUNCTION_P 2921e4b17023SJohn MarinoThis predicate holds if the function a static member function. 2922e4b17023SJohn Marino 2923e4b17023SJohn Marino@item DECL_NONSTATIC_MEMBER_FUNCTION_P 2924e4b17023SJohn MarinoThis macro holds for a non-static member function. 2925e4b17023SJohn Marino 2926e4b17023SJohn Marino@item DECL_CONST_MEMFUNC_P 2927e4b17023SJohn MarinoThis predicate holds for a @code{const}-member function. 2928e4b17023SJohn Marino 2929e4b17023SJohn Marino@item DECL_VOLATILE_MEMFUNC_P 2930e4b17023SJohn MarinoThis predicate holds for a @code{volatile}-member function. 2931e4b17023SJohn Marino 2932e4b17023SJohn Marino@item DECL_CONSTRUCTOR_P 2933e4b17023SJohn MarinoThis macro holds if the function is a constructor. 2934e4b17023SJohn Marino 2935e4b17023SJohn Marino@item DECL_NONCONVERTING_P 2936e4b17023SJohn MarinoThis predicate holds if the constructor is a non-converting constructor. 2937e4b17023SJohn Marino 2938e4b17023SJohn Marino@item DECL_COMPLETE_CONSTRUCTOR_P 2939e4b17023SJohn MarinoThis predicate holds for a function which is a constructor for an object 2940e4b17023SJohn Marinoof a complete type. 2941e4b17023SJohn Marino 2942e4b17023SJohn Marino@item DECL_BASE_CONSTRUCTOR_P 2943e4b17023SJohn MarinoThis predicate holds for a function which is a constructor for a base 2944e4b17023SJohn Marinoclass sub-object. 2945e4b17023SJohn Marino 2946e4b17023SJohn Marino@item DECL_COPY_CONSTRUCTOR_P 2947e4b17023SJohn MarinoThis predicate holds for a function which is a copy-constructor. 2948e4b17023SJohn Marino 2949e4b17023SJohn Marino@item DECL_DESTRUCTOR_P 2950e4b17023SJohn MarinoThis macro holds if the function is a destructor. 2951e4b17023SJohn Marino 2952e4b17023SJohn Marino@item DECL_COMPLETE_DESTRUCTOR_P 2953e4b17023SJohn MarinoThis predicate holds if the function is the destructor for an object a 2954e4b17023SJohn Marinocomplete type. 2955e4b17023SJohn Marino 2956e4b17023SJohn Marino@item DECL_OVERLOADED_OPERATOR_P 2957e4b17023SJohn MarinoThis macro holds if the function is an overloaded operator. 2958e4b17023SJohn Marino 2959e4b17023SJohn Marino@item DECL_CONV_FN_P 2960e4b17023SJohn MarinoThis macro holds if the function is a type-conversion operator. 2961e4b17023SJohn Marino 2962e4b17023SJohn Marino@item DECL_GLOBAL_CTOR_P 2963e4b17023SJohn MarinoThis predicate holds if the function is a file-scope initialization 2964e4b17023SJohn Marinofunction. 2965e4b17023SJohn Marino 2966e4b17023SJohn Marino@item DECL_GLOBAL_DTOR_P 2967e4b17023SJohn MarinoThis predicate holds if the function is a file-scope finalization 2968e4b17023SJohn Marinofunction. 2969e4b17023SJohn Marino 2970e4b17023SJohn Marino@item DECL_THUNK_P 2971e4b17023SJohn MarinoThis predicate holds if the function is a thunk. 2972e4b17023SJohn Marino 2973e4b17023SJohn MarinoThese functions represent stub code that adjusts the @code{this} pointer 2974e4b17023SJohn Marinoand then jumps to another function. When the jumped-to function 2975e4b17023SJohn Marinoreturns, control is transferred directly to the caller, without 2976e4b17023SJohn Marinoreturning to the thunk. The first parameter to the thunk is always the 2977e4b17023SJohn Marino@code{this} pointer; the thunk should add @code{THUNK_DELTA} to this 2978e4b17023SJohn Marinovalue. (The @code{THUNK_DELTA} is an @code{int}, not an 2979e4b17023SJohn Marino@code{INTEGER_CST}.) 2980e4b17023SJohn Marino 2981e4b17023SJohn MarinoThen, if @code{THUNK_VCALL_OFFSET} (an @code{INTEGER_CST}) is nonzero 2982e4b17023SJohn Marinothe adjusted @code{this} pointer must be adjusted again. The complete 2983e4b17023SJohn Marinocalculation is given by the following pseudo-code: 2984e4b17023SJohn Marino 2985e4b17023SJohn Marino@smallexample 2986e4b17023SJohn Marinothis += THUNK_DELTA 2987e4b17023SJohn Marinoif (THUNK_VCALL_OFFSET) 2988e4b17023SJohn Marino this += (*((ptrdiff_t **) this))[THUNK_VCALL_OFFSET] 2989e4b17023SJohn Marino@end smallexample 2990e4b17023SJohn Marino 2991e4b17023SJohn MarinoFinally, the thunk should jump to the location given 2992e4b17023SJohn Marinoby @code{DECL_INITIAL}; this will always be an expression for the 2993e4b17023SJohn Marinoaddress of a function. 2994e4b17023SJohn Marino 2995e4b17023SJohn Marino@item DECL_NON_THUNK_FUNCTION_P 2996e4b17023SJohn MarinoThis predicate holds if the function is @emph{not} a thunk function. 2997e4b17023SJohn Marino 2998e4b17023SJohn Marino@item GLOBAL_INIT_PRIORITY 2999e4b17023SJohn MarinoIf either @code{DECL_GLOBAL_CTOR_P} or @code{DECL_GLOBAL_DTOR_P} holds, 3000e4b17023SJohn Marinothen this gives the initialization priority for the function. The 3001e4b17023SJohn Marinolinker will arrange that all functions for which 3002e4b17023SJohn Marino@code{DECL_GLOBAL_CTOR_P} holds are run in increasing order of priority 3003e4b17023SJohn Marinobefore @code{main} is called. When the program exits, all functions for 3004e4b17023SJohn Marinowhich @code{DECL_GLOBAL_DTOR_P} holds are run in the reverse order. 3005e4b17023SJohn Marino 3006e4b17023SJohn Marino@item TYPE_RAISES_EXCEPTIONS 3007e4b17023SJohn MarinoThis macro returns the list of exceptions that a (member-)function can 3008e4b17023SJohn Marinoraise. The returned list, if non @code{NULL}, is comprised of nodes 3009e4b17023SJohn Marinowhose @code{TREE_VALUE} represents a type. 3010e4b17023SJohn Marino 3011e4b17023SJohn Marino@item TYPE_NOTHROW_P 3012e4b17023SJohn MarinoThis predicate holds when the exception-specification of its arguments 3013e4b17023SJohn Marinois of the form `@code{()}'. 3014e4b17023SJohn Marino 3015e4b17023SJohn Marino@item DECL_ARRAY_DELETE_OPERATOR_P 3016e4b17023SJohn MarinoThis predicate holds if the function an overloaded 3017e4b17023SJohn Marino@code{operator delete[]}. 3018e4b17023SJohn Marino 3019e4b17023SJohn Marino@end ftable 3020e4b17023SJohn Marino 3021e4b17023SJohn Marino@c --------------------------------------------------------------------- 3022e4b17023SJohn Marino@c Function Bodies 3023e4b17023SJohn Marino@c --------------------------------------------------------------------- 3024e4b17023SJohn Marino 3025e4b17023SJohn Marino@node Statements for C++ 3026e4b17023SJohn Marino@subsection Statements for C++ 3027e4b17023SJohn Marino@cindex statements 3028e4b17023SJohn Marino@tindex BREAK_STMT 3029e4b17023SJohn Marino@tindex CLEANUP_STMT 3030e4b17023SJohn Marino@findex CLEANUP_DECL 3031e4b17023SJohn Marino@findex CLEANUP_EXPR 3032e4b17023SJohn Marino@tindex CONTINUE_STMT 3033e4b17023SJohn Marino@tindex DECL_STMT 3034e4b17023SJohn Marino@findex DECL_STMT_DECL 3035e4b17023SJohn Marino@tindex DO_STMT 3036e4b17023SJohn Marino@findex DO_BODY 3037e4b17023SJohn Marino@findex DO_COND 3038e4b17023SJohn Marino@tindex EMPTY_CLASS_EXPR 3039e4b17023SJohn Marino@tindex EXPR_STMT 3040e4b17023SJohn Marino@findex EXPR_STMT_EXPR 3041e4b17023SJohn Marino@tindex FOR_STMT 3042e4b17023SJohn Marino@findex FOR_INIT_STMT 3043e4b17023SJohn Marino@findex FOR_COND 3044e4b17023SJohn Marino@findex FOR_EXPR 3045e4b17023SJohn Marino@findex FOR_BODY 3046e4b17023SJohn Marino@tindex HANDLER 3047e4b17023SJohn Marino@tindex IF_STMT 3048e4b17023SJohn Marino@findex IF_COND 3049e4b17023SJohn Marino@findex THEN_CLAUSE 3050e4b17023SJohn Marino@findex ELSE_CLAUSE 3051e4b17023SJohn Marino@tindex RETURN_STMT 3052e4b17023SJohn Marino@findex RETURN_EXPR 3053e4b17023SJohn Marino@tindex SUBOBJECT 3054e4b17023SJohn Marino@findex SUBOBJECT_CLEANUP 3055e4b17023SJohn Marino@tindex SWITCH_STMT 3056e4b17023SJohn Marino@findex SWITCH_COND 3057e4b17023SJohn Marino@findex SWITCH_BODY 3058e4b17023SJohn Marino@tindex TRY_BLOCK 3059e4b17023SJohn Marino@findex TRY_STMTS 3060e4b17023SJohn Marino@findex TRY_HANDLERS 3061e4b17023SJohn Marino@findex HANDLER_PARMS 3062e4b17023SJohn Marino@findex HANDLER_BODY 3063e4b17023SJohn Marino@findex USING_STMT 3064e4b17023SJohn Marino@tindex WHILE_STMT 3065e4b17023SJohn Marino@findex WHILE_BODY 3066e4b17023SJohn Marino@findex WHILE_COND 3067e4b17023SJohn Marino 3068e4b17023SJohn MarinoA function that has a definition in the current translation unit will 3069e4b17023SJohn Marinohave a non-@code{NULL} @code{DECL_INITIAL}. However, back ends should not make 3070e4b17023SJohn Marinouse of the particular value given by @code{DECL_INITIAL}. 3071e4b17023SJohn Marino 3072e4b17023SJohn MarinoThe @code{DECL_SAVED_TREE} macro will give the complete body of the 3073e4b17023SJohn Marinofunction. 3074e4b17023SJohn Marino 3075e4b17023SJohn Marino@subsubsection Statements 3076e4b17023SJohn Marino 3077e4b17023SJohn MarinoThere are tree nodes corresponding to all of the source-level 3078e4b17023SJohn Marinostatement constructs, used within the C and C++ frontends. These are 3079e4b17023SJohn Marinoenumerated here, together with a list of the various macros that can 3080e4b17023SJohn Marinobe used to obtain information about them. There are a few macros that 3081e4b17023SJohn Marinocan be used with all statements: 3082e4b17023SJohn Marino 3083e4b17023SJohn Marino@ftable @code 3084e4b17023SJohn Marino@item STMT_IS_FULL_EXPR_P 3085e4b17023SJohn MarinoIn C++, statements normally constitute ``full expressions''; temporaries 3086e4b17023SJohn Marinocreated during a statement are destroyed when the statement is complete. 3087e4b17023SJohn MarinoHowever, G++ sometimes represents expressions by statements; these 3088e4b17023SJohn Marinostatements will not have @code{STMT_IS_FULL_EXPR_P} set. Temporaries 3089e4b17023SJohn Marinocreated during such statements should be destroyed when the innermost 3090e4b17023SJohn Marinoenclosing statement with @code{STMT_IS_FULL_EXPR_P} set is exited. 3091e4b17023SJohn Marino 3092e4b17023SJohn Marino@end ftable 3093e4b17023SJohn Marino 3094e4b17023SJohn MarinoHere is the list of the various statement nodes, and the macros used to 3095e4b17023SJohn Marinoaccess them. This documentation describes the use of these nodes in 3096e4b17023SJohn Marinonon-template functions (including instantiations of template functions). 3097e4b17023SJohn MarinoIn template functions, the same nodes are used, but sometimes in 3098e4b17023SJohn Marinoslightly different ways. 3099e4b17023SJohn Marino 3100e4b17023SJohn MarinoMany of the statements have substatements. For example, a @code{while} 3101e4b17023SJohn Marinoloop will have a body, which is itself a statement. If the substatement 3102e4b17023SJohn Marinois @code{NULL_TREE}, it is considered equivalent to a statement 3103e4b17023SJohn Marinoconsisting of a single @code{;}, i.e., an expression statement in which 3104e4b17023SJohn Marinothe expression has been omitted. A substatement may in fact be a list 3105e4b17023SJohn Marinoof statements, connected via their @code{TREE_CHAIN}s. So, you should 3106e4b17023SJohn Marinoalways process the statement tree by looping over substatements, like 3107e4b17023SJohn Marinothis: 3108e4b17023SJohn Marino@smallexample 3109e4b17023SJohn Marinovoid process_stmt (stmt) 3110e4b17023SJohn Marino tree stmt; 3111e4b17023SJohn Marino@{ 3112e4b17023SJohn Marino while (stmt) 3113e4b17023SJohn Marino @{ 3114e4b17023SJohn Marino switch (TREE_CODE (stmt)) 3115e4b17023SJohn Marino @{ 3116e4b17023SJohn Marino case IF_STMT: 3117e4b17023SJohn Marino process_stmt (THEN_CLAUSE (stmt)); 3118e4b17023SJohn Marino /* @r{More processing here.} */ 3119e4b17023SJohn Marino break; 3120e4b17023SJohn Marino 3121e4b17023SJohn Marino @dots{} 3122e4b17023SJohn Marino @} 3123e4b17023SJohn Marino 3124e4b17023SJohn Marino stmt = TREE_CHAIN (stmt); 3125e4b17023SJohn Marino @} 3126e4b17023SJohn Marino@} 3127e4b17023SJohn Marino@end smallexample 3128e4b17023SJohn MarinoIn other words, while the @code{then} clause of an @code{if} statement 3129e4b17023SJohn Marinoin C++ can be only one statement (although that one statement may be a 3130e4b17023SJohn Marinocompound statement), the intermediate representation will sometimes use 3131e4b17023SJohn Marinoseveral statements chained together. 3132e4b17023SJohn Marino 3133e4b17023SJohn Marino@table @code 3134e4b17023SJohn Marino@item BREAK_STMT 3135e4b17023SJohn Marino 3136e4b17023SJohn MarinoUsed to represent a @code{break} statement. There are no additional 3137e4b17023SJohn Marinofields. 3138e4b17023SJohn Marino 3139e4b17023SJohn Marino@item CLEANUP_STMT 3140e4b17023SJohn Marino 3141e4b17023SJohn MarinoUsed to represent an action that should take place upon exit from the 3142e4b17023SJohn Marinoenclosing scope. Typically, these actions are calls to destructors for 3143e4b17023SJohn Marinolocal objects, but back ends cannot rely on this fact. If these nodes 3144e4b17023SJohn Marinoare in fact representing such destructors, @code{CLEANUP_DECL} will be 3145e4b17023SJohn Marinothe @code{VAR_DECL} destroyed. Otherwise, @code{CLEANUP_DECL} will be 3146e4b17023SJohn Marino@code{NULL_TREE}. In any case, the @code{CLEANUP_EXPR} is the 3147e4b17023SJohn Marinoexpression to execute. The cleanups executed on exit from a scope 3148e4b17023SJohn Marinoshould be run in the reverse order of the order in which the associated 3149e4b17023SJohn Marino@code{CLEANUP_STMT}s were encountered. 3150e4b17023SJohn Marino 3151e4b17023SJohn Marino@item CONTINUE_STMT 3152e4b17023SJohn Marino 3153e4b17023SJohn MarinoUsed to represent a @code{continue} statement. There are no additional 3154e4b17023SJohn Marinofields. 3155e4b17023SJohn Marino 3156e4b17023SJohn Marino@item CTOR_STMT 3157e4b17023SJohn Marino 3158e4b17023SJohn MarinoUsed to mark the beginning (if @code{CTOR_BEGIN_P} holds) or end (if 3159e4b17023SJohn Marino@code{CTOR_END_P} holds of the main body of a constructor. See also 3160e4b17023SJohn Marino@code{SUBOBJECT} for more information on how to use these nodes. 3161e4b17023SJohn Marino 3162e4b17023SJohn Marino@item DO_STMT 3163e4b17023SJohn Marino 3164e4b17023SJohn MarinoUsed to represent a @code{do} loop. The body of the loop is given by 3165e4b17023SJohn Marino@code{DO_BODY} while the termination condition for the loop is given by 3166e4b17023SJohn Marino@code{DO_COND}. The condition for a @code{do}-statement is always an 3167e4b17023SJohn Marinoexpression. 3168e4b17023SJohn Marino 3169e4b17023SJohn Marino@item EMPTY_CLASS_EXPR 3170e4b17023SJohn Marino 3171e4b17023SJohn MarinoUsed to represent a temporary object of a class with no data whose 3172e4b17023SJohn Marinoaddress is never taken. (All such objects are interchangeable.) The 3173e4b17023SJohn Marino@code{TREE_TYPE} represents the type of the object. 3174e4b17023SJohn Marino 3175e4b17023SJohn Marino@item EXPR_STMT 3176e4b17023SJohn Marino 3177e4b17023SJohn MarinoUsed to represent an expression statement. Use @code{EXPR_STMT_EXPR} to 3178e4b17023SJohn Marinoobtain the expression. 3179e4b17023SJohn Marino 3180e4b17023SJohn Marino@item FOR_STMT 3181e4b17023SJohn Marino 3182e4b17023SJohn MarinoUsed to represent a @code{for} statement. The @code{FOR_INIT_STMT} is 3183e4b17023SJohn Marinothe initialization statement for the loop. The @code{FOR_COND} is the 3184e4b17023SJohn Marinotermination condition. The @code{FOR_EXPR} is the expression executed 3185e4b17023SJohn Marinoright before the @code{FOR_COND} on each loop iteration; often, this 3186e4b17023SJohn Marinoexpression increments a counter. The body of the loop is given by 3187e4b17023SJohn Marino@code{FOR_BODY}. Note that @code{FOR_INIT_STMT} and @code{FOR_BODY} 3188e4b17023SJohn Marinoreturn statements, while @code{FOR_COND} and @code{FOR_EXPR} return 3189e4b17023SJohn Marinoexpressions. 3190e4b17023SJohn Marino 3191e4b17023SJohn Marino@item HANDLER 3192e4b17023SJohn Marino 3193e4b17023SJohn MarinoUsed to represent a C++ @code{catch} block. The @code{HANDLER_TYPE} 3194e4b17023SJohn Marinois the type of exception that will be caught by this handler; it is 3195e4b17023SJohn Marinoequal (by pointer equality) to @code{NULL} if this handler is for all 3196e4b17023SJohn Marinotypes. @code{HANDLER_PARMS} is the @code{DECL_STMT} for the catch 3197e4b17023SJohn Marinoparameter, and @code{HANDLER_BODY} is the code for the block itself. 3198e4b17023SJohn Marino 3199e4b17023SJohn Marino@item IF_STMT 3200e4b17023SJohn Marino 3201e4b17023SJohn MarinoUsed to represent an @code{if} statement. The @code{IF_COND} is the 3202e4b17023SJohn Marinoexpression. 3203e4b17023SJohn Marino 3204e4b17023SJohn MarinoIf the condition is a @code{TREE_LIST}, then the @code{TREE_PURPOSE} is 3205e4b17023SJohn Marinoa statement (usually a @code{DECL_STMT}). Each time the condition is 3206e4b17023SJohn Marinoevaluated, the statement should be executed. Then, the 3207e4b17023SJohn Marino@code{TREE_VALUE} should be used as the conditional expression itself. 3208e4b17023SJohn MarinoThis representation is used to handle C++ code like this: 3209e4b17023SJohn Marino 3210e4b17023SJohn MarinoC++ distinguishes between this and @code{COND_EXPR} for handling templates. 3211e4b17023SJohn Marino 3212e4b17023SJohn Marino@smallexample 3213e4b17023SJohn Marinoif (int i = 7) @dots{} 3214e4b17023SJohn Marino@end smallexample 3215e4b17023SJohn Marino 3216e4b17023SJohn Marinowhere there is a new local variable (or variables) declared within the 3217e4b17023SJohn Marinocondition. 3218e4b17023SJohn Marino 3219e4b17023SJohn MarinoThe @code{THEN_CLAUSE} represents the statement given by the @code{then} 3220e4b17023SJohn Marinocondition, while the @code{ELSE_CLAUSE} represents the statement given 3221e4b17023SJohn Marinoby the @code{else} condition. 3222e4b17023SJohn Marino 3223e4b17023SJohn Marino@item SUBOBJECT 3224e4b17023SJohn Marino 3225e4b17023SJohn MarinoIn a constructor, these nodes are used to mark the point at which a 3226e4b17023SJohn Marinosubobject of @code{this} is fully constructed. If, after this point, an 3227e4b17023SJohn Marinoexception is thrown before a @code{CTOR_STMT} with @code{CTOR_END_P} set 3228e4b17023SJohn Marinois encountered, the @code{SUBOBJECT_CLEANUP} must be executed. The 3229e4b17023SJohn Marinocleanups must be executed in the reverse order in which they appear. 3230e4b17023SJohn Marino 3231e4b17023SJohn Marino@item SWITCH_STMT 3232e4b17023SJohn Marino 3233e4b17023SJohn MarinoUsed to represent a @code{switch} statement. The @code{SWITCH_STMT_COND} 3234e4b17023SJohn Marinois the expression on which the switch is occurring. See the documentation 3235e4b17023SJohn Marinofor an @code{IF_STMT} for more information on the representation used 3236e4b17023SJohn Marinofor the condition. The @code{SWITCH_STMT_BODY} is the body of the switch 3237e4b17023SJohn Marinostatement. The @code{SWITCH_STMT_TYPE} is the original type of switch 3238e4b17023SJohn Marinoexpression as given in the source, before any compiler conversions. 3239e4b17023SJohn Marino 3240e4b17023SJohn Marino@item TRY_BLOCK 3241e4b17023SJohn MarinoUsed to represent a @code{try} block. The body of the try block is 3242e4b17023SJohn Marinogiven by @code{TRY_STMTS}. Each of the catch blocks is a @code{HANDLER} 3243e4b17023SJohn Marinonode. The first handler is given by @code{TRY_HANDLERS}. Subsequent 3244e4b17023SJohn Marinohandlers are obtained by following the @code{TREE_CHAIN} link from one 3245e4b17023SJohn Marinohandler to the next. The body of the handler is given by 3246e4b17023SJohn Marino@code{HANDLER_BODY}. 3247e4b17023SJohn Marino 3248e4b17023SJohn MarinoIf @code{CLEANUP_P} holds of the @code{TRY_BLOCK}, then the 3249e4b17023SJohn Marino@code{TRY_HANDLERS} will not be a @code{HANDLER} node. Instead, it will 3250e4b17023SJohn Marinobe an expression that should be executed if an exception is thrown in 3251e4b17023SJohn Marinothe try block. It must rethrow the exception after executing that code. 3252e4b17023SJohn MarinoAnd, if an exception is thrown while the expression is executing, 3253e4b17023SJohn Marino@code{terminate} must be called. 3254e4b17023SJohn Marino 3255e4b17023SJohn Marino@item USING_STMT 3256e4b17023SJohn MarinoUsed to represent a @code{using} directive. The namespace is given by 3257e4b17023SJohn Marino@code{USING_STMT_NAMESPACE}, which will be a NAMESPACE_DECL@. This node 3258e4b17023SJohn Marinois needed inside template functions, to implement using directives 3259e4b17023SJohn Marinoduring instantiation. 3260e4b17023SJohn Marino 3261e4b17023SJohn Marino@item WHILE_STMT 3262e4b17023SJohn Marino 3263e4b17023SJohn MarinoUsed to represent a @code{while} loop. The @code{WHILE_COND} is the 3264e4b17023SJohn Marinotermination condition for the loop. See the documentation for an 3265e4b17023SJohn Marino@code{IF_STMT} for more information on the representation used for the 3266e4b17023SJohn Marinocondition. 3267e4b17023SJohn Marino 3268e4b17023SJohn MarinoThe @code{WHILE_BODY} is the body of the loop. 3269e4b17023SJohn Marino 3270e4b17023SJohn Marino@end table 3271e4b17023SJohn Marino 3272e4b17023SJohn Marino@node C++ Expressions 3273e4b17023SJohn Marino@subsection C++ Expressions 3274e4b17023SJohn Marino 3275e4b17023SJohn MarinoThis section describes expressions specific to the C and C++ front 3276e4b17023SJohn Marinoends. 3277e4b17023SJohn Marino 3278e4b17023SJohn Marino@table @code 3279e4b17023SJohn Marino@item TYPEID_EXPR 3280e4b17023SJohn Marino 3281e4b17023SJohn MarinoUsed to represent a @code{typeid} expression. 3282e4b17023SJohn Marino 3283e4b17023SJohn Marino@item NEW_EXPR 3284e4b17023SJohn Marino@itemx VEC_NEW_EXPR 3285e4b17023SJohn Marino 3286e4b17023SJohn MarinoUsed to represent a call to @code{new} and @code{new[]} respectively. 3287e4b17023SJohn Marino 3288e4b17023SJohn Marino@item DELETE_EXPR 3289e4b17023SJohn Marino@itemx VEC_DELETE_EXPR 3290e4b17023SJohn Marino 3291e4b17023SJohn MarinoUsed to represent a call to @code{delete} and @code{delete[]} respectively. 3292e4b17023SJohn Marino 3293e4b17023SJohn Marino@item MEMBER_REF 3294e4b17023SJohn Marino 3295e4b17023SJohn MarinoRepresents a reference to a member of a class. 3296e4b17023SJohn Marino 3297e4b17023SJohn Marino@item THROW_EXPR 3298e4b17023SJohn Marino 3299e4b17023SJohn MarinoRepresents an instance of @code{throw} in the program. Operand 0, 3300e4b17023SJohn Marinowhich is the expression to throw, may be @code{NULL_TREE}. 3301e4b17023SJohn Marino 3302e4b17023SJohn Marino 3303e4b17023SJohn Marino@item AGGR_INIT_EXPR 3304e4b17023SJohn MarinoAn @code{AGGR_INIT_EXPR} represents the initialization as the return 3305e4b17023SJohn Marinovalue of a function call, or as the result of a constructor. An 3306e4b17023SJohn Marino@code{AGGR_INIT_EXPR} will only appear as a full-expression, or as the 3307e4b17023SJohn Marinosecond operand of a @code{TARGET_EXPR}. @code{AGGR_INIT_EXPR}s have 3308e4b17023SJohn Marinoa representation similar to that of @code{CALL_EXPR}s. You can use 3309e4b17023SJohn Marinothe @code{AGGR_INIT_EXPR_FN} and @code{AGGR_INIT_EXPR_ARG} macros to access 3310e4b17023SJohn Marinothe function to call and the arguments to pass. 3311e4b17023SJohn Marino 3312e4b17023SJohn MarinoIf @code{AGGR_INIT_VIA_CTOR_P} holds of the @code{AGGR_INIT_EXPR}, then 3313e4b17023SJohn Marinothe initialization is via a constructor call. The address of the 3314e4b17023SJohn Marino@code{AGGR_INIT_EXPR_SLOT} operand, which is always a @code{VAR_DECL}, 3315e4b17023SJohn Marinois taken, and this value replaces the first argument in the argument 3316e4b17023SJohn Marinolist. 3317e4b17023SJohn Marino 3318e4b17023SJohn MarinoIn either case, the expression is void. 3319e4b17023SJohn Marino 3320e4b17023SJohn Marino 3321e4b17023SJohn Marino@end table 3322e4b17023SJohn Marino 3323e4b17023SJohn Marino 3324e4b17023SJohn Marino@node Java Trees 3325e4b17023SJohn Marino@section Java Trees 3326