1 @c Copyright (c) 1999, 2000, 2001, 2002, 2003 Free Software Foundation, Inc.
2 @c Free Software Foundation, Inc.
3 @c This is part of the GCC manual.
4 @c For copying conditions, see the file gcc.texi.
6 @c ---------------------------------------------------------------------
8 @c ---------------------------------------------------------------------
11 @chapter Trees: The intermediate representation used by the C and C++ front ends
13 @cindex C/C++ Internal Representation
15 This chapter documents the internal representation used by GCC to
16 represent C and C++ source programs. When presented with a C or C++
17 source program, GCC parses the program, performs semantic analysis
18 (including the generation of error messages), and then produces the
19 internal representation described here. This representation contains a
20 complete representation for the entire translation unit provided as
21 input to the front end. This representation is then typically processed
22 by a code-generator in order to produce machine code, but could also be
23 used in the creation of source browsers, intelligent editors, automatic
24 documentation generators, interpreters, and any other programs needing
25 the ability to process C or C++ code.
27 This chapter explains the internal representation. In particular, it
28 documents the internal representation for C and C++ source
29 constructs, and the macros, functions, and variables that can be used to
30 access these constructs. The C++ representation is largely a superset
31 of the representation used in the C front end. There is only one
32 construct used in C that does not appear in the C++ front end and that
33 is the GNU ``nested function'' extension. Many of the macros documented
34 here do not apply in C because the corresponding language constructs do
37 If you are developing a ``back end'', be it is a code-generator or some
38 other tool, that uses this representation, you may occasionally find
39 that you need to ask questions not easily answered by the functions and
40 macros available here. If that situation occurs, it is quite likely
41 that GCC already supports the functionality you desire, but that the
42 interface is simply not documented here. In that case, you should ask
43 the GCC maintainers (via mail to @email{gcc@@gcc.gnu.org}) about
44 documenting the functionality you require. Similarly, if you find
45 yourself writing functions that do not deal directly with your back end,
46 but instead might be useful to other people using the GCC front end, you
47 should submit your patches for inclusion in GCC@.
50 * Deficiencies:: Topics net yet covered in this document.
51 * Tree overview:: All about @code{tree}s.
52 * Types:: Fundamental and aggregate types.
53 * Scopes:: Namespaces and classes.
54 * Functions:: Overloading, function bodies, and linkage.
55 * Declarations:: Type declarations and variables.
56 * Attributes:: Declaration and type attributes.
57 * Expression trees:: From @code{typeid} to @code{throw}.
60 @c ---------------------------------------------------------------------
62 @c ---------------------------------------------------------------------
67 There are many places in which this document is incomplet and incorrekt.
68 It is, as of yet, only @emph{preliminary} documentation.
70 @c ---------------------------------------------------------------------
72 @c ---------------------------------------------------------------------
79 The central data structure used by the internal representation is the
80 @code{tree}. These nodes, while all of the C type @code{tree}, are of
81 many varieties. A @code{tree} is a pointer type, but the object to
82 which it points may be of a variety of types. From this point forward,
83 we will refer to trees in ordinary type, rather than in @code{this
84 font}, except when talking about the actual C type @code{tree}.
86 You can tell what kind of node a particular tree is by using the
87 @code{TREE_CODE} macro. Many, many macros take trees as input and
88 return trees as output. However, most macros require a certain kind of
89 tree node as input. In other words, there is a type-system for trees,
90 but it is not reflected in the C type-system.
92 For safety, it is useful to configure GCC with @option{--enable-checking}.
93 Although this results in a significant performance penalty (since all
94 tree types are checked at run-time), and is therefore inappropriate in a
95 release version, it is extremely helpful during the development process.
97 Many macros behave as predicates. Many, although not all, of these
98 predicates end in @samp{_P}. Do not rely on the result type of these
99 macros being of any particular type. You may, however, rely on the fact
100 that the type can be compared to @code{0}, so that statements like
102 if (TEST_P (t) && !TEST_P (y))
108 int i = (TEST_P (t) != 0);
111 are legal. Macros that return @code{int} values now may be changed to
112 return @code{tree} values, or other pointers in the future. Even those
113 that continue to return @code{int} may return multiple nonzero codes
114 where previously they returned only zero and one. Therefore, you should
120 as this code is not guaranteed to work correctly in the future.
122 You should not take the address of values returned by the macros or
123 functions described here. In particular, no guarantee is given that the
126 In general, the names of macros are all in uppercase, while the names of
127 functions are entirely in lowercase. There are rare exceptions to this
128 rule. You should assume that any macro or function whose name is made
129 up entirely of uppercase letters may evaluate its arguments more than
130 once. You may assume that a macro or function whose name is made up
131 entirely of lowercase letters will evaluate its arguments only once.
133 The @code{error_mark_node} is a special tree. Its tree code is
134 @code{ERROR_MARK}, but since there is only ever one node with that code,
135 the usual practice is to compare the tree against
136 @code{error_mark_node}. (This test is just a test for pointer
137 equality.) If an error has occurred during front-end processing the
138 flag @code{errorcount} will be set. If the front end has encountered
139 code it cannot handle, it will issue a message to the user and set
140 @code{sorrycount}. When these flags are set, any macro or function
141 which normally returns a tree of a particular kind may instead return
142 the @code{error_mark_node}. Thus, if you intend to do any processing of
143 erroneous code, you must be prepared to deal with the
144 @code{error_mark_node}.
146 Occasionally, a particular tree slot (like an operand to an expression,
147 or a particular field in a declaration) will be referred to as
148 ``reserved for the back end.'' These slots are used to store RTL when
149 the tree is converted to RTL for use by the GCC back end. However, if
150 that process is not taking place (e.g., if the front end is being hooked
151 up to an intelligent editor), then those slots may be used by the
152 back end presently in use.
154 If you encounter situations that do not match this documentation, such
155 as tree nodes of types not mentioned here, or macros documented to
156 return entities of a particular kind that instead return entities of
157 some different kind, you have found a bug, either in the front end or in
158 the documentation. Please report these bugs as you would any other
162 * Macros and Functions::Macros and functions that can be used with all trees.
163 * Identifiers:: The names of things.
164 * Containers:: Lists and vectors.
167 @c ---------------------------------------------------------------------
169 @c ---------------------------------------------------------------------
171 @node Macros and Functions
175 This section is not here yet.
177 @c ---------------------------------------------------------------------
179 @c ---------------------------------------------------------------------
182 @subsection Identifiers
185 @tindex IDENTIFIER_NODE
187 An @code{IDENTIFIER_NODE} represents a slightly more general concept
188 that the standard C or C++ concept of identifier. In particular, an
189 @code{IDENTIFIER_NODE} may contain a @samp{$}, or other extraordinary
192 There are never two distinct @code{IDENTIFIER_NODE}s representing the
193 same identifier. Therefore, you may use pointer equality to compare
194 @code{IDENTIFIER_NODE}s, rather than using a routine like @code{strcmp}.
196 You can use the following macros to access identifiers:
198 @item IDENTIFIER_POINTER
199 The string represented by the identifier, represented as a
200 @code{char*}. This string is always @code{NUL}-terminated, and contains
201 no embedded @code{NUL} characters.
203 @item IDENTIFIER_LENGTH
204 The length of the string returned by @code{IDENTIFIER_POINTER}, not
205 including the trailing @code{NUL}. This value of
206 @code{IDENTIFIER_LENGTH (x)} is always the same as @code{strlen
207 (IDENTIFIER_POINTER (x))}.
209 @item IDENTIFIER_OPNAME_P
210 This predicate holds if the identifier represents the name of an
211 overloaded operator. In this case, you should not depend on the
212 contents of either the @code{IDENTIFIER_POINTER} or the
213 @code{IDENTIFIER_LENGTH}.
215 @item IDENTIFIER_TYPENAME_P
216 This predicate holds if the identifier represents the name of a
217 user-defined conversion operator. In this case, the @code{TREE_TYPE} of
218 the @code{IDENTIFIER_NODE} holds the type to which the conversion
223 @c ---------------------------------------------------------------------
225 @c ---------------------------------------------------------------------
228 @subsection Containers
236 @findex TREE_VEC_LENGTH
239 Two common container data structures can be represented directly with
240 tree nodes. A @code{TREE_LIST} is a singly linked list containing two
241 trees per node. These are the @code{TREE_PURPOSE} and @code{TREE_VALUE}
242 of each node. (Often, the @code{TREE_PURPOSE} contains some kind of
243 tag, or additional information, while the @code{TREE_VALUE} contains the
244 majority of the payload. In other cases, the @code{TREE_PURPOSE} is
245 simply @code{NULL_TREE}, while in still others both the
246 @code{TREE_PURPOSE} and @code{TREE_VALUE} are of equal stature.) Given
247 one @code{TREE_LIST} node, the next node is found by following the
248 @code{TREE_CHAIN}. If the @code{TREE_CHAIN} is @code{NULL_TREE}, then
249 you have reached the end of the list.
251 A @code{TREE_VEC} is a simple vector. The @code{TREE_VEC_LENGTH} is an
252 integer (not a tree) giving the number of nodes in the vector. The
253 nodes themselves are accessed using the @code{TREE_VEC_ELT} macro, which
254 takes two arguments. The first is the @code{TREE_VEC} in question; the
255 second is an integer indicating which element in the vector is desired.
256 The elements are indexed from zero.
258 @c ---------------------------------------------------------------------
260 @c ---------------------------------------------------------------------
267 @cindex fundamental type
271 @tindex TYPE_MIN_VALUE
272 @tindex TYPE_MAX_VALUE
275 @tindex ENUMERAL_TYPE
278 @tindex REFERENCE_TYPE
279 @tindex FUNCTION_TYPE
286 @tindex TYPENAME_TYPE
288 @findex CP_TYPE_QUALS
289 @findex TYPE_UNQUALIFIED
290 @findex TYPE_QUAL_CONST
291 @findex TYPE_QUAL_VOLATILE
292 @findex TYPE_QUAL_RESTRICT
293 @findex TYPE_MAIN_VARIANT
294 @cindex qualified type
297 @findex TYPE_PRECISION
298 @findex TYPE_ARG_TYPES
299 @findex TYPE_METHOD_BASETYPE
300 @findex TYPE_PTRMEM_P
301 @findex TYPE_OFFSET_BASETYPE
305 @findex TYPENAME_TYPE_FULLNAME
307 @findex TYPE_PTROBV_P
309 All types have corresponding tree nodes. However, you should not assume
310 that there is exactly one tree node corresponding to each type. There
311 are often several nodes each of which correspond to the same type.
313 For the most part, different kinds of types have different tree codes.
314 (For example, pointer types use a @code{POINTER_TYPE} code while arrays
315 use an @code{ARRAY_TYPE} code.) However, pointers to member functions
316 use the @code{RECORD_TYPE} code. Therefore, when writing a
317 @code{switch} statement that depends on the code associated with a
318 particular type, you should take care to handle pointers to member
319 functions under the @code{RECORD_TYPE} case label.
321 In C++, an array type is not qualified; rather the type of the array
322 elements is qualified. This situation is reflected in the intermediate
323 representation. The macros described here will always examine the
324 qualification of the underlying element type when applied to an array
325 type. (If the element type is itself an array, then the recursion
326 continues until a non-array type is found, and the qualification of this
327 type is examined.) So, for example, @code{CP_TYPE_CONST_P} will hold of
328 the type @code{const int ()[7]}, denoting an array of seven @code{int}s.
330 The following functions and macros deal with cv-qualification of types:
333 This macro returns the set of type qualifiers applied to this type.
334 This value is @code{TYPE_UNQUALIFIED} if no qualifiers have been
335 applied. The @code{TYPE_QUAL_CONST} bit is set if the type is
336 @code{const}-qualified. The @code{TYPE_QUAL_VOLATILE} bit is set if the
337 type is @code{volatile}-qualified. The @code{TYPE_QUAL_RESTRICT} bit is
338 set if the type is @code{restrict}-qualified.
340 @item CP_TYPE_CONST_P
341 This macro holds if the type is @code{const}-qualified.
343 @item CP_TYPE_VOLATILE_P
344 This macro holds if the type is @code{volatile}-qualified.
346 @item CP_TYPE_RESTRICT_P
347 This macro holds if the type is @code{restrict}-qualified.
349 @item CP_TYPE_CONST_NON_VOLATILE_P
350 This predicate holds for a type that is @code{const}-qualified, but
351 @emph{not} @code{volatile}-qualified; other cv-qualifiers are ignored as
352 well: only the @code{const}-ness is tested.
354 @item TYPE_MAIN_VARIANT
355 This macro returns the unqualified version of a type. It may be applied
356 to an unqualified type, but it is not always the identity function in
360 A few other macros and functions are usable with all types:
363 The number of bits required to represent the type, represented as an
364 @code{INTEGER_CST}. For an incomplete type, @code{TYPE_SIZE} will be
368 The alignment of the type, in bits, represented as an @code{int}.
371 This macro returns a declaration (in the form of a @code{TYPE_DECL}) for
372 the type. (Note this macro does @emph{not} return a
373 @code{IDENTIFIER_NODE}, as you might expect, given its name!) You can
374 look at the @code{DECL_NAME} of the @code{TYPE_DECL} to obtain the
375 actual name of the type. The @code{TYPE_NAME} will be @code{NULL_TREE}
376 for a type that is not a built-in type, the result of a typedef, or a
379 @item CP_INTEGRAL_TYPE
380 This predicate holds if the type is an integral type. Notice that in
381 C++, enumerations are @emph{not} integral types.
383 @item ARITHMETIC_TYPE_P
384 This predicate holds if the type is an integral type (in the C++ sense)
385 or a floating point type.
388 This predicate holds for a class-type.
391 This predicate holds for a built-in type.
394 This predicate holds if the type is a pointer to data member.
397 This predicate holds if the type is a pointer type, and the pointee is
401 This predicate holds for a pointer to function type.
404 This predicate holds for a pointer to object type. Note however that it
405 does not hold for the generic pointer to object type @code{void *}. You
406 may use @code{TYPE_PTROBV_P} to test for a pointer to object type as
407 well as @code{void *}.
410 This predicate takes two types as input, and holds if they are the same
411 type. For example, if one type is a @code{typedef} for the other, or
412 both are @code{typedef}s for the same type. This predicate also holds if
413 the two trees given as input are simply copies of one another; i.e.,
414 there is no difference between them at the source level, but, for
415 whatever reason, a duplicate has been made in the representation. You
416 should never use @code{==} (pointer equality) to compare types; always
417 use @code{same_type_p} instead.
420 Detailed below are the various kinds of types, and the macros that can
421 be used to access them. Although other kinds of types are used
422 elsewhere in G++, the types described here are the only ones that you
423 will encounter while examining the intermediate representation.
427 Used to represent the @code{void} type.
430 Used to represent the various integral types, including @code{char},
431 @code{short}, @code{int}, @code{long}, and @code{long long}. This code
432 is not used for enumeration types, nor for the @code{bool} type. Note
433 that GCC's @code{CHAR_TYPE} node is @emph{not} used to represent
434 @code{char}. The @code{TYPE_PRECISION} is the number of bits used in
435 the representation, represented as an @code{unsigned int}. (Note that
436 in the general case this is not the same value as @code{TYPE_SIZE};
437 suppose that there were a 24-bit integer type, but that alignment
438 requirements for the ABI required 32-bit alignment. Then,
439 @code{TYPE_SIZE} would be an @code{INTEGER_CST} for 32, while
440 @code{TYPE_PRECISION} would be 24.) The integer type is unsigned if
441 @code{TREE_UNSIGNED} holds; otherwise, it is signed.
443 The @code{TYPE_MIN_VALUE} is an @code{INTEGER_CST} for the smallest
444 integer that may be represented by this type. Similarly, the
445 @code{TYPE_MAX_VALUE} is an @code{INTEGER_CST} for the largest integer
446 that may be represented by this type.
449 Used to represent the @code{float}, @code{double}, and @code{long
450 double} types. The number of bits in the floating-point representation
451 is given by @code{TYPE_PRECISION}, as in the @code{INTEGER_TYPE} case.
454 Used to represent GCC built-in @code{__complex__} data types. The
455 @code{TREE_TYPE} is the type of the real and imaginary parts.
458 Used to represent an enumeration type. The @code{TYPE_PRECISION} gives
459 (as an @code{int}), the number of bits used to represent the type. If
460 there are no negative enumeration constants, @code{TREE_UNSIGNED} will
461 hold. The minimum and maximum enumeration constants may be obtained
462 with @code{TYPE_MIN_VALUE} and @code{TYPE_MAX_VALUE}, respectively; each
463 of these macros returns an @code{INTEGER_CST}.
465 The actual enumeration constants themselves may be obtained by looking
466 at the @code{TYPE_VALUES}. This macro will return a @code{TREE_LIST},
467 containing the constants. The @code{TREE_PURPOSE} of each node will be
468 an @code{IDENTIFIER_NODE} giving the name of the constant; the
469 @code{TREE_VALUE} will be an @code{INTEGER_CST} giving the value
470 assigned to that constant. These constants will appear in the order in
471 which they were declared. The @code{TREE_TYPE} of each of these
472 constants will be the type of enumeration type itself.
475 Used to represent the @code{bool} type.
478 Used to represent pointer types, and pointer to data member types. The
479 @code{TREE_TYPE} gives the type to which this type points. If the type
480 is a pointer to data member type, then @code{TYPE_PTRMEM_P} will hold.
481 For a pointer to data member type of the form @samp{T X::*},
482 @code{TYPE_PTRMEM_CLASS_TYPE} will be the type @code{X}, while
483 @code{TYPE_PTRMEM_POINTED_TO_TYPE} will be the type @code{T}.
486 Used to represent reference types. The @code{TREE_TYPE} gives the type
487 to which this type refers.
490 Used to represent the type of non-member functions and of static member
491 functions. The @code{TREE_TYPE} gives the return type of the function.
492 The @code{TYPE_ARG_TYPES} are a @code{TREE_LIST} of the argument types.
493 The @code{TREE_VALUE} of each node in this list is the type of the
494 corresponding argument; the @code{TREE_PURPOSE} is an expression for the
495 default argument value, if any. If the last node in the list is
496 @code{void_list_node} (a @code{TREE_LIST} node whose @code{TREE_VALUE}
497 is the @code{void_type_node}), then functions of this type do not take
498 variable arguments. Otherwise, they do take a variable number of
501 Note that in C (but not in C++) a function declared like @code{void f()}
502 is an unprototyped function taking a variable number of arguments; the
503 @code{TYPE_ARG_TYPES} of such a function will be @code{NULL}.
506 Used to represent the type of a non-static member function. Like a
507 @code{FUNCTION_TYPE}, the return type is given by the @code{TREE_TYPE}.
508 The type of @code{*this}, i.e., the class of which functions of this
509 type are a member, is given by the @code{TYPE_METHOD_BASETYPE}. The
510 @code{TYPE_ARG_TYPES} is the parameter list, as for a
511 @code{FUNCTION_TYPE}, and includes the @code{this} argument.
514 Used to represent array types. The @code{TREE_TYPE} gives the type of
515 the elements in the array. If the array-bound is present in the type,
516 the @code{TYPE_DOMAIN} is an @code{INTEGER_TYPE} whose
517 @code{TYPE_MIN_VALUE} and @code{TYPE_MAX_VALUE} will be the lower and
518 upper bounds of the array, respectively. The @code{TYPE_MIN_VALUE} will
519 always be an @code{INTEGER_CST} for zero, while the
520 @code{TYPE_MAX_VALUE} will be one less than the number of elements in
521 the array, i.e., the highest value which may be used to index an element
525 Used to represent @code{struct} and @code{class} types, as well as
526 pointers to member functions and similar constructs in other languages.
527 @code{TYPE_FIELDS} contains the items contained in this type, each of
528 which can be a @code{FIELD_DECL}, @code{VAR_DECL}, @code{CONST_DECL}, or
529 @code{TYPE_DECL}. You may not make any assumptions about the ordering
530 of the fields in the type or whether one or more of them overlap. If
531 @code{TYPE_PTRMEMFUNC_P} holds, then this type is a pointer-to-member
532 type. In that case, the @code{TYPE_PTRMEMFUNC_FN_TYPE} is a
533 @code{POINTER_TYPE} pointing to a @code{METHOD_TYPE}. The
534 @code{METHOD_TYPE} is the type of a function pointed to by the
535 pointer-to-member function. If @code{TYPE_PTRMEMFUNC_P} does not hold,
536 this type is a class type. For more information, see @pxref{Classes}.
539 Used to represent @code{union} types. Similar to @code{RECORD_TYPE}
540 except that all @code{FIELD_DECL} nodes in @code{TYPE_FIELD} start at
543 @item QUAL_UNION_TYPE
544 Used to represent part of a variant record in Ada. Similar to
545 @code{UNION_TYPE} except that each @code{FIELD_DECL} has a
546 @code{DECL_QUALIFIER} field, which contains a boolean expression that
547 indicates whether the field is present in the object. The type will only
548 have one field, so each field's @code{DECL_QUALIFIER} is only evaluated
549 if none of the expressions in the previous fields in @code{TYPE_FIELDS}
550 are nonzero. Normally these expressions will reference a field in the
551 outer object using a @code{PLACEHOLDER_EXPR}.
554 This node is used to represent a type the knowledge of which is
555 insufficient for a sound processing.
558 This node is used to represent a pointer-to-data member. For a data
559 member @code{X::m} the @code{TYPE_OFFSET_BASETYPE} is @code{X} and the
560 @code{TREE_TYPE} is the type of @code{m}.
563 Used to represent a construct of the form @code{typename T::A}. The
564 @code{TYPE_CONTEXT} is @code{T}; the @code{TYPE_NAME} is an
565 @code{IDENTIFIER_NODE} for @code{A}. If the type is specified via a
566 template-id, then @code{TYPENAME_TYPE_FULLNAME} yields a
567 @code{TEMPLATE_ID_EXPR}. The @code{TREE_TYPE} is non-@code{NULL} if the
568 node is implicitly generated in support for the implicit typename
569 extension; in which case the @code{TREE_TYPE} is a type node for the
573 Used to represent the @code{__typeof__} extension. The
574 @code{TYPE_FIELDS} is the expression the type of which is being
578 There are variables whose values represent some of the basic types.
582 A node for @code{void}.
584 @item integer_type_node
585 A node for @code{int}.
587 @item unsigned_type_node.
588 A node for @code{unsigned int}.
590 @item char_type_node.
591 A node for @code{char}.
594 It may sometimes be useful to compare one of these variables with a type
595 in hand, using @code{same_type_p}.
597 @c ---------------------------------------------------------------------
599 @c ---------------------------------------------------------------------
603 @cindex namespace, class, scope
605 The root of the entire intermediate representation is the variable
606 @code{global_namespace}. This is the namespace specified with @code{::}
607 in C++ source code. All other namespaces, types, variables, functions,
608 and so forth can be found starting with this namespace.
610 Besides namespaces, the other high-level scoping construct in C++ is the
611 class. (Throughout this manual the term @dfn{class} is used to mean the
612 types referred to in the ANSI/ISO C++ Standard as classes; these include
613 types defined with the @code{class}, @code{struct}, and @code{union}
617 * Namespaces:: Member functions, types, etc.
618 * Classes:: Members, bases, friends, etc.
621 @c ---------------------------------------------------------------------
623 @c ---------------------------------------------------------------------
626 @subsection Namespaces
628 @tindex NAMESPACE_DECL
630 A namespace is represented by a @code{NAMESPACE_DECL} node.
632 However, except for the fact that it is distinguished as the root of the
633 representation, the global namespace is no different from any other
634 namespace. Thus, in what follows, we describe namespaces generally,
635 rather than the global namespace in particular.
637 The following macros and functions can be used on a @code{NAMESPACE_DECL}:
641 This macro is used to obtain the @code{IDENTIFIER_NODE} corresponding to
642 the unqualified name of the name of the namespace (@pxref{Identifiers}).
643 The name of the global namespace is @samp{::}, even though in C++ the
644 global namespace is unnamed. However, you should use comparison with
645 @code{global_namespace}, rather than @code{DECL_NAME} to determine
646 whether or not a namespace is the global one. An unnamed namespace
647 will have a @code{DECL_NAME} equal to @code{anonymous_namespace_name}.
648 Within a single translation unit, all unnamed namespaces will have the
652 This macro returns the enclosing namespace. The @code{DECL_CONTEXT} for
653 the @code{global_namespace} is @code{NULL_TREE}.
655 @item DECL_NAMESPACE_ALIAS
656 If this declaration is for a namespace alias, then
657 @code{DECL_NAMESPACE_ALIAS} is the namespace for which this one is an
660 Do not attempt to use @code{cp_namespace_decls} for a namespace which is
661 an alias. Instead, follow @code{DECL_NAMESPACE_ALIAS} links until you
662 reach an ordinary, non-alias, namespace, and call
663 @code{cp_namespace_decls} there.
665 @item DECL_NAMESPACE_STD_P
666 This predicate holds if the namespace is the special @code{::std}
669 @item cp_namespace_decls
670 This function will return the declarations contained in the namespace,
671 including types, overloaded functions, other namespaces, and so forth.
672 If there are no declarations, this function will return
673 @code{NULL_TREE}. The declarations are connected through their
674 @code{TREE_CHAIN} fields.
676 Although most entries on this list will be declarations,
677 @code{TREE_LIST} nodes may also appear. In this case, the
678 @code{TREE_VALUE} will be an @code{OVERLOAD}. The value of the
679 @code{TREE_PURPOSE} is unspecified; back ends should ignore this value.
680 As with the other kinds of declarations returned by
681 @code{cp_namespace_decls}, the @code{TREE_CHAIN} will point to the next
682 declaration in this list.
684 For more information on the kinds of declarations that can occur on this
685 list, @xref{Declarations}. Some declarations will not appear on this
686 list. In particular, no @code{FIELD_DECL}, @code{LABEL_DECL}, or
687 @code{PARM_DECL} nodes will appear here.
689 This function cannot be used with namespaces that have
690 @code{DECL_NAMESPACE_ALIAS} set.
694 @c ---------------------------------------------------------------------
696 @c ---------------------------------------------------------------------
703 @findex CLASSTYPE_DECLARED_CLASS
706 @findex TREE_VIA_PUBLIC
707 @findex TREE_VIA_PROTECTED
708 @findex TREE_VIA_PRIVATE
713 A class type is represented by either a @code{RECORD_TYPE} or a
714 @code{UNION_TYPE}. A class declared with the @code{union} tag is
715 represented by a @code{UNION_TYPE}, while classes declared with either
716 the @code{struct} or the @code{class} tag are represented by
717 @code{RECORD_TYPE}s. You can use the @code{CLASSTYPE_DECLARED_CLASS}
718 macro to discern whether or not a particular type is a @code{class} as
719 opposed to a @code{struct}. This macro will be true only for classes
720 declared with the @code{class} tag.
722 Almost all non-function members are available on the @code{TYPE_FIELDS}
723 list. Given one member, the next can be found by following the
724 @code{TREE_CHAIN}. You should not depend in any way on the order in
725 which fields appear on this list. All nodes on this list will be
726 @samp{DECL} nodes. A @code{FIELD_DECL} is used to represent a non-static
727 data member, a @code{VAR_DECL} is used to represent a static data
728 member, and a @code{TYPE_DECL} is used to represent a type. Note that
729 the @code{CONST_DECL} for an enumeration constant will appear on this
730 list, if the enumeration type was declared in the class. (Of course,
731 the @code{TYPE_DECL} for the enumeration type will appear here as well.)
732 There are no entries for base classes on this list. In particular,
733 there is no @code{FIELD_DECL} for the ``base-class portion'' of an
736 The @code{TYPE_VFIELD} is a compiler-generated field used to point to
737 virtual function tables. It may or may not appear on the
738 @code{TYPE_FIELDS} list. However, back ends should handle the
739 @code{TYPE_VFIELD} just like all the entries on the @code{TYPE_FIELDS}
742 The function members are available on the @code{TYPE_METHODS} list.
743 Again, subsequent members are found by following the @code{TREE_CHAIN}
744 field. If a function is overloaded, each of the overloaded functions
745 appears; no @code{OVERLOAD} nodes appear on the @code{TYPE_METHODS}
746 list. Implicitly declared functions (including default constructors,
747 copy constructors, assignment operators, and destructors) will appear on
750 Every class has an associated @dfn{binfo}, which can be obtained with
751 @code{TYPE_BINFO}. Binfos are used to represent base-classes. The
752 binfo given by @code{TYPE_BINFO} is the degenerate case, whereby every
753 class is considered to be its own base-class. The base classes for a
754 particular binfo can be obtained with @code{BINFO_BASETYPES}. These
755 base-classes are themselves binfos. The class type associated with a
756 binfo is given by @code{BINFO_TYPE}. It is always the case that
757 @code{BINFO_TYPE (TYPE_BINFO (x))} is the same type as @code{x}, up to
758 qualifiers. However, it is not always the case that @code{TYPE_BINFO
759 (BINFO_TYPE (y))} is always the same binfo as @code{y}. The reason is
760 that if @code{y} is a binfo representing a base-class @code{B} of a
761 derived class @code{D}, then @code{BINFO_TYPE (y)} will be @code{B},
762 and @code{TYPE_BINFO (BINFO_TYPE (y))} will be @code{B} as its own
763 base-class, rather than as a base-class of @code{D}.
765 The @code{BINFO_BASETYPES} is a @code{TREE_VEC} (@pxref{Containers}).
766 Base types appear in left-to-right order in this vector. You can tell
767 whether or @code{public}, @code{protected}, or @code{private}
768 inheritance was used by using the @code{TREE_VIA_PUBLIC},
769 @code{TREE_VIA_PROTECTED}, and @code{TREE_VIA_PRIVATE} macros. Each of
770 these macros takes a @code{BINFO} and is true if and only if the
771 indicated kind of inheritance was used. If @code{TREE_VIA_VIRTUAL}
772 holds of a binfo, then its @code{BINFO_TYPE} was inherited from
775 The following macros can be used on a tree node representing a class-type.
779 This predicate holds if the class is local class @emph{i.e.} declared
780 inside a function body.
782 @item TYPE_POLYMORPHIC_P
783 This predicate holds if the class has at least one virtual function
784 (declared or inherited).
786 @item TYPE_HAS_DEFAULT_CONSTRUCTOR
787 This predicate holds whenever its argument represents a class-type with
790 @item CLASSTYPE_HAS_MUTABLE
791 @itemx TYPE_HAS_MUTABLE_P
792 These predicates hold for a class-type having a mutable data member.
794 @item CLASSTYPE_NON_POD_P
795 This predicate holds only for class-types that are not PODs.
797 @item TYPE_HAS_NEW_OPERATOR
798 This predicate holds for a class-type that defines
801 @item TYPE_HAS_ARRAY_NEW_OPERATOR
802 This predicate holds for a class-type for which
803 @code{operator new[]} is defined.
805 @item TYPE_OVERLOADS_CALL_EXPR
806 This predicate holds for class-type for which the function call
807 @code{operator()} is overloaded.
809 @item TYPE_OVERLOADS_ARRAY_REF
810 This predicate holds for a class-type that overloads
813 @item TYPE_OVERLOADS_ARROW
814 This predicate holds for a class-type for which @code{operator->} is
819 @c ---------------------------------------------------------------------
821 @c ---------------------------------------------------------------------
824 @section Declarations
827 @cindex type declaration
834 @tindex NAMESPACE_DECL
836 @tindex TEMPLATE_DECL
843 @findex DECL_EXTERNAL
845 This section covers the various kinds of declarations that appear in the
846 internal representation, except for declarations of functions
847 (represented by @code{FUNCTION_DECL} nodes), which are described in
850 Some macros can be used with any kind of declaration. These include:
853 This macro returns an @code{IDENTIFIER_NODE} giving the name of the
857 This macro returns the type of the entity declared.
859 @item DECL_SOURCE_FILE
860 This macro returns the name of the file in which the entity was
861 declared, as a @code{char*}. For an entity declared implicitly by the
862 compiler (like @code{__builtin_memcpy}), this will be the string
865 @item DECL_SOURCE_LINE
866 This macro returns the line number at which the entity was declared, as
869 @item DECL_ARTIFICIAL
870 This predicate holds if the declaration was implicitly generated by the
871 compiler. For example, this predicate will hold of an implicitly
872 declared member function, or of the @code{TYPE_DECL} implicitly
873 generated for a class type. Recall that in C++ code like:
878 is roughly equivalent to C code like:
883 The implicitly generated @code{typedef} declaration is represented by a
884 @code{TYPE_DECL} for which @code{DECL_ARTIFICIAL} holds.
886 @item DECL_NAMESPACE_SCOPE_P
887 This predicate holds if the entity was declared at a namespace scope.
889 @item DECL_CLASS_SCOPE_P
890 This predicate holds if the entity was declared at a class scope.
892 @item DECL_FUNCTION_SCOPE_P
893 This predicate holds if the entity was declared inside a function
898 The various kinds of declarations include:
901 These nodes are used to represent labels in function bodies. For more
902 information, see @ref{Functions}. These nodes only appear in block
906 These nodes are used to represent enumeration constants. The value of
907 the constant is given by @code{DECL_INITIAL} which will be an
908 @code{INTEGER_CST} with the same type as the @code{TREE_TYPE} of the
909 @code{CONST_DECL}, i.e., an @code{ENUMERAL_TYPE}.
912 These nodes represent the value returned by a function. When a value is
913 assigned to a @code{RESULT_DECL}, that indicates that the value should
914 be returned, via bitwise copy, by the function. You can use
915 @code{DECL_SIZE} and @code{DECL_ALIGN} on a @code{RESULT_DECL}, just as
916 with a @code{VAR_DECL}.
919 These nodes represent @code{typedef} declarations. The @code{TREE_TYPE}
920 is the type declared to have the name given by @code{DECL_NAME}. In
921 some cases, there is no associated name.
924 These nodes represent variables with namespace or block scope, as well
925 as static data members. The @code{DECL_SIZE} and @code{DECL_ALIGN} are
926 analogous to @code{TYPE_SIZE} and @code{TYPE_ALIGN}. For a declaration,
927 you should always use the @code{DECL_SIZE} and @code{DECL_ALIGN} rather
928 than the @code{TYPE_SIZE} and @code{TYPE_ALIGN} given by the
929 @code{TREE_TYPE}, since special attributes may have been applied to the
930 variable to give it a particular size and alignment. You may use the
931 predicates @code{DECL_THIS_STATIC} or @code{DECL_THIS_EXTERN} to test
932 whether the storage class specifiers @code{static} or @code{extern} were
933 used to declare a variable.
935 If this variable is initialized (but does not require a constructor),
936 the @code{DECL_INITIAL} will be an expression for the initializer. The
937 initializer should be evaluated, and a bitwise copy into the variable
938 performed. If the @code{DECL_INITIAL} is the @code{error_mark_node},
939 there is an initializer, but it is given by an explicit statement later
940 in the code; no bitwise copy is required.
942 GCC provides an extension that allows either automatic variables, or
943 global variables, to be placed in particular registers. This extension
944 is being used for a particular @code{VAR_DECL} if @code{DECL_REGISTER}
945 holds for the @code{VAR_DECL}, and if @code{DECL_ASSEMBLER_NAME} is not
946 equal to @code{DECL_NAME}. In that case, @code{DECL_ASSEMBLER_NAME} is
947 the name of the register into which the variable will be placed.
950 Used to represent a parameter to a function. Treat these nodes
951 similarly to @code{VAR_DECL} nodes. These nodes only appear in the
952 @code{DECL_ARGUMENTS} for a @code{FUNCTION_DECL}.
954 The @code{DECL_ARG_TYPE} for a @code{PARM_DECL} is the type that will
955 actually be used when a value is passed to this function. It may be a
956 wider type than the @code{TREE_TYPE} of the parameter; for example, the
957 ordinary type might be @code{short} while the @code{DECL_ARG_TYPE} is
961 These nodes represent non-static data members. The @code{DECL_SIZE} and
962 @code{DECL_ALIGN} behave as for @code{VAR_DECL} nodes. The
963 @code{DECL_FIELD_BITPOS} gives the first bit used for this field, as an
964 @code{INTEGER_CST}. These values are indexed from zero, where zero
965 indicates the first bit in the object.
967 If @code{DECL_C_BIT_FIELD} holds, this field is a bit-field.
974 These nodes are used to represent class, function, and variable (static
975 data member) templates. The @code{DECL_TEMPLATE_SPECIALIZATIONS} are a
976 @code{TREE_LIST}. The @code{TREE_VALUE} of each node in the list is a
977 @code{TEMPLATE_DECL}s or @code{FUNCTION_DECL}s representing
978 specializations (including instantiations) of this template. Back ends
979 can safely ignore @code{TEMPLATE_DECL}s, but should examine
980 @code{FUNCTION_DECL} nodes on the specializations list just as they
981 would ordinary @code{FUNCTION_DECL} nodes.
983 For a class template, the @code{DECL_TEMPLATE_INSTANTIATIONS} list
984 contains the instantiations. The @code{TREE_VALUE} of each node is an
985 instantiation of the class. The @code{DECL_TEMPLATE_SPECIALIZATIONS}
986 contains partial specializations of the class.
990 Back ends can safely ignore these nodes.
994 @c ---------------------------------------------------------------------
996 @c ---------------------------------------------------------------------
1001 @tindex FUNCTION_DECL
1006 A function is represented by a @code{FUNCTION_DECL} node. A set of
1007 overloaded functions is sometimes represented by a @code{OVERLOAD} node.
1009 An @code{OVERLOAD} node is not a declaration, so none of the
1010 @samp{DECL_} macros should be used on an @code{OVERLOAD}. An
1011 @code{OVERLOAD} node is similar to a @code{TREE_LIST}. Use
1012 @code{OVL_CURRENT} to get the function associated with an
1013 @code{OVERLOAD} node; use @code{OVL_NEXT} to get the next
1014 @code{OVERLOAD} node in the list of overloaded functions. The macros
1015 @code{OVL_CURRENT} and @code{OVL_NEXT} are actually polymorphic; you can
1016 use them to work with @code{FUNCTION_DECL} nodes as well as with
1017 overloads. In the case of a @code{FUNCTION_DECL}, @code{OVL_CURRENT}
1018 will always return the function itself, and @code{OVL_NEXT} will always
1019 be @code{NULL_TREE}.
1021 To determine the scope of a function, you can use the
1022 @code{DECL_CONTEXT} macro. This macro will return the class
1023 (either a @code{RECORD_TYPE} or a @code{UNION_TYPE}) or namespace (a
1024 @code{NAMESPACE_DECL}) of which the function is a member. For a virtual
1025 function, this macro returns the class in which the function was
1026 actually defined, not the base class in which the virtual declaration
1029 If a friend function is defined in a class scope, the
1030 @code{DECL_FRIEND_CONTEXT} macro can be used to determine the class in
1031 which it was defined. For example, in
1033 class C @{ friend void f() @{@} @};
1036 the @code{DECL_CONTEXT} for @code{f} will be the
1037 @code{global_namespace}, but the @code{DECL_FRIEND_CONTEXT} will be the
1038 @code{RECORD_TYPE} for @code{C}.
1040 In C, the @code{DECL_CONTEXT} for a function maybe another function.
1041 This representation indicates that the GNU nested function extension
1042 is in use. For details on the semantics of nested functions, see the
1043 GCC Manual. The nested function can refer to local variables in its
1044 containing function. Such references are not explicitly marked in the
1045 tree structure; back ends must look at the @code{DECL_CONTEXT} for the
1046 referenced @code{VAR_DECL}. If the @code{DECL_CONTEXT} for the
1047 referenced @code{VAR_DECL} is not the same as the function currently
1048 being processed, and neither @code{DECL_EXTERNAL} nor
1049 @code{DECL_STATIC} hold, then the reference is to a local variable in
1050 a containing function, and the back end must take appropriate action.
1053 * Function Basics:: Function names, linkage, and so forth.
1054 * Function Bodies:: The statements that make up a function body.
1057 @c ---------------------------------------------------------------------
1059 @c ---------------------------------------------------------------------
1061 @node Function Basics
1062 @subsection Function Basics
1065 @cindex copy constructor
1066 @cindex assignment operator
1069 @findex DECL_ASSEMBLER_NAME
1071 @findex DECL_LINKONCE_P
1072 @findex DECL_FUNCTION_MEMBER_P
1073 @findex DECL_CONSTRUCTOR_P
1074 @findex DECL_DESTRUCTOR_P
1075 @findex DECL_OVERLOADED_OPERATOR_P
1076 @findex DECL_CONV_FN_P
1077 @findex DECL_ARTIFICIAL
1078 @findex DECL_GLOBAL_CTOR_P
1079 @findex DECL_GLOBAL_DTOR_P
1080 @findex GLOBAL_INIT_PRIORITY
1082 The following macros and functions can be used on a @code{FUNCTION_DECL}:
1085 This predicate holds for a function that is the program entry point
1089 This macro returns the unqualified name of the function, as an
1090 @code{IDENTIFIER_NODE}. For an instantiation of a function template,
1091 the @code{DECL_NAME} is the unqualified name of the template, not
1092 something like @code{f<int>}. The value of @code{DECL_NAME} is
1093 undefined when used on a constructor, destructor, overloaded operator,
1094 or type-conversion operator, or any function that is implicitly
1095 generated by the compiler. See below for macros that can be used to
1096 distinguish these cases.
1098 @item DECL_ASSEMBLER_NAME
1099 This macro returns the mangled name of the function, also an
1100 @code{IDENTIFIER_NODE}. This name does not contain leading underscores
1101 on systems that prefix all identifiers with underscores. The mangled
1102 name is computed in the same way on all platforms; if special processing
1103 is required to deal with the object file format used on a particular
1104 platform, it is the responsibility of the back end to perform those
1105 modifications. (Of course, the back end should not modify
1106 @code{DECL_ASSEMBLER_NAME} itself.)
1109 This predicate holds if the function is undefined.
1112 This predicate holds if the function has external linkage.
1114 @item DECL_LOCAL_FUNCTION_P
1115 This predicate holds if the function was declared at block scope, even
1116 though it has a global scope.
1118 @item DECL_ANTICIPATED
1119 This predicate holds if the function is a built-in function but its
1120 prototype is not yet explicitly declared.
1122 @item DECL_EXTERN_C_FUNCTION_P
1123 This predicate holds if the function is declared as an
1124 `@code{extern "C"}' function.
1126 @item DECL_LINKONCE_P
1127 This macro holds if multiple copies of this function may be emitted in
1128 various translation units. It is the responsibility of the linker to
1129 merge the various copies. Template instantiations are the most common
1130 example of functions for which @code{DECL_LINKONCE_P} holds; G++
1131 instantiates needed templates in all translation units which require them,
1132 and then relies on the linker to remove duplicate instantiations.
1134 FIXME: This macro is not yet implemented.
1136 @item DECL_FUNCTION_MEMBER_P
1137 This macro holds if the function is a member of a class, rather than a
1138 member of a namespace.
1140 @item DECL_STATIC_FUNCTION_P
1141 This predicate holds if the function a static member function.
1143 @item DECL_NONSTATIC_MEMBER_FUNCTION_P
1144 This macro holds for a non-static member function.
1146 @item DECL_CONST_MEMFUNC_P
1147 This predicate holds for a @code{const}-member function.
1149 @item DECL_VOLATILE_MEMFUNC_P
1150 This predicate holds for a @code{volatile}-member function.
1152 @item DECL_CONSTRUCTOR_P
1153 This macro holds if the function is a constructor.
1155 @item DECL_NONCONVERTING_P
1156 This predicate holds if the constructor is a non-converting constructor.
1158 @item DECL_COMPLETE_CONSTRUCTOR_P
1159 This predicate holds for a function which is a constructor for an object
1162 @item DECL_BASE_CONSTRUCTOR_P
1163 This predicate holds for a function which is a constructor for a base
1166 @item DECL_COPY_CONSTRUCTOR_P
1167 This predicate holds for a function which is a copy-constructor.
1169 @item DECL_DESTRUCTOR_P
1170 This macro holds if the function is a destructor.
1172 @item DECL_COMPLETE_DESTRUCTOR_P
1173 This predicate holds if the function is the destructor for an object a
1176 @item DECL_OVERLOADED_OPERATOR_P
1177 This macro holds if the function is an overloaded operator.
1179 @item DECL_CONV_FN_P
1180 This macro holds if the function is a type-conversion operator.
1182 @item DECL_GLOBAL_CTOR_P
1183 This predicate holds if the function is a file-scope initialization
1186 @item DECL_GLOBAL_DTOR_P
1187 This predicate holds if the function is a file-scope finalization
1191 This predicate holds if the function is a thunk.
1193 These functions represent stub code that adjusts the @code{this} pointer
1194 and then jumps to another function. When the jumped-to function
1195 returns, control is transferred directly to the caller, without
1196 returning to the thunk. The first parameter to the thunk is always the
1197 @code{this} pointer; the thunk should add @code{THUNK_DELTA} to this
1198 value. (The @code{THUNK_DELTA} is an @code{int}, not an
1199 @code{INTEGER_CST}.)
1201 Then, if @code{THUNK_VCALL_OFFSET} (an @code{INTEGER_CST}) is nonzero
1202 the adjusted @code{this} pointer must be adjusted again. The complete
1203 calculation is given by the following pseudo-code:
1207 if (THUNK_VCALL_OFFSET)
1208 this += (*((ptrdiff_t **) this))[THUNK_VCALL_OFFSET]
1211 Finally, the thunk should jump to the location given
1212 by @code{DECL_INITIAL}; this will always be an expression for the
1213 address of a function.
1215 @item DECL_NON_THUNK_FUNCTION_P
1216 This predicate holds if the function is @emph{not} a thunk function.
1218 @item GLOBAL_INIT_PRIORITY
1219 If either @code{DECL_GLOBAL_CTOR_P} or @code{DECL_GLOBAL_DTOR_P} holds,
1220 then this gives the initialization priority for the function. The
1221 linker will arrange that all functions for which
1222 @code{DECL_GLOBAL_CTOR_P} holds are run in increasing order of priority
1223 before @code{main} is called. When the program exits, all functions for
1224 which @code{DECL_GLOBAL_DTOR_P} holds are run in the reverse order.
1226 @item DECL_ARTIFICIAL
1227 This macro holds if the function was implicitly generated by the
1228 compiler, rather than explicitly declared. In addition to implicitly
1229 generated class member functions, this macro holds for the special
1230 functions created to implement static initialization and destruction, to
1231 compute run-time type information, and so forth.
1233 @item DECL_ARGUMENTS
1234 This macro returns the @code{PARM_DECL} for the first argument to the
1235 function. Subsequent @code{PARM_DECL} nodes can be obtained by
1236 following the @code{TREE_CHAIN} links.
1239 This macro returns the @code{RESULT_DECL} for the function.
1242 This macro returns the @code{FUNCTION_TYPE} or @code{METHOD_TYPE} for
1245 @item TYPE_RAISES_EXCEPTIONS
1246 This macro returns the list of exceptions that a (member-)function can
1247 raise. The returned list, if non @code{NULL}, is comprised of nodes
1248 whose @code{TREE_VALUE} represents a type.
1250 @item TYPE_NOTHROW_P
1251 This predicate holds when the exception-specification of its arguments
1252 if of the form `@code{()}'.
1254 @item DECL_ARRAY_DELETE_OPERATOR_P
1255 This predicate holds if the function an overloaded
1256 @code{operator delete[]}.
1260 @c ---------------------------------------------------------------------
1262 @c ---------------------------------------------------------------------
1264 @node Function Bodies
1265 @subsection Function Bodies
1266 @cindex function body
1273 @findex ASM_CLOBBERS
1275 @tindex CLEANUP_STMT
1276 @findex CLEANUP_DECL
1277 @findex CLEANUP_EXPR
1278 @tindex COMPOUND_STMT
1279 @findex COMPOUND_BODY
1280 @tindex CONTINUE_STMT
1282 @findex DECL_STMT_DECL
1286 @tindex EMPTY_CLASS_EXPR
1288 @findex EXPR_STMT_EXPR
1290 @findex FOR_INIT_STMT
1295 @findex FILE_STMT_FILENAME
1297 @findex GOTO_DESTINATION
1305 @tindex LABEL_STMT_LABEL
1310 @findex SCOPE_BEGIN_P
1312 @findex SCOPE_NULLIFIED_P
1314 @findex SUBOBJECT_CLEANUP
1320 @findex TRY_HANDLERS
1321 @findex HANDLER_PARMS
1322 @findex HANDLER_BODY
1328 A function that has a definition in the current translation unit will
1329 have a non-@code{NULL} @code{DECL_INITIAL}. However, back ends should not make
1330 use of the particular value given by @code{DECL_INITIAL}.
1332 The @code{DECL_SAVED_TREE} macro will give the complete body of the
1333 function. This node will usually be a @code{COMPOUND_STMT} representing
1334 the outermost block of the function, but it may also be a
1335 @code{TRY_BLOCK}, a @code{RETURN_INIT}, or any other valid statement.
1337 @subsubsection Statements
1339 There are tree nodes corresponding to all of the source-level statement
1340 constructs. These are enumerated here, together with a list of the
1341 various macros that can be used to obtain information about them. There
1342 are a few macros that can be used with all statements:
1346 This macro returns the line number for the statement. If the statement
1347 spans multiple lines, this value will be the number of the first line on
1348 which the statement occurs. Although we mention @code{CASE_LABEL} below
1349 as if it were a statement, they do not allow the use of
1350 @code{STMT_LINENO}. There is no way to obtain the line number for a
1353 Statements do not contain information about
1354 the file from which they came; that information is implicit in the
1355 @code{FUNCTION_DECL} from which the statements originate.
1357 @item STMT_IS_FULL_EXPR_P
1358 In C++, statements normally constitute ``full expressions''; temporaries
1359 created during a statement are destroyed when the statement is complete.
1360 However, G++ sometimes represents expressions by statements; these
1361 statements will not have @code{STMT_IS_FULL_EXPR_P} set. Temporaries
1362 created during such statements should be destroyed when the innermost
1363 enclosing statement with @code{STMT_IS_FULL_EXPR_P} set is exited.
1367 Here is the list of the various statement nodes, and the macros used to
1368 access them. This documentation describes the use of these nodes in
1369 non-template functions (including instantiations of template functions).
1370 In template functions, the same nodes are used, but sometimes in
1371 slightly different ways.
1373 Many of the statements have substatements. For example, a @code{while}
1374 loop will have a body, which is itself a statement. If the substatement
1375 is @code{NULL_TREE}, it is considered equivalent to a statement
1376 consisting of a single @code{;}, i.e., an expression statement in which
1377 the expression has been omitted. A substatement may in fact be a list
1378 of statements, connected via their @code{TREE_CHAIN}s. So, you should
1379 always process the statement tree by looping over substatements, like
1382 void process_stmt (stmt)
1387 switch (TREE_CODE (stmt))
1390 process_stmt (THEN_CLAUSE (stmt));
1391 /* More processing here. */
1397 stmt = TREE_CHAIN (stmt);
1401 In other words, while the @code{then} clause of an @code{if} statement
1402 in C++ can be only one statement (although that one statement may be a
1403 compound statement), the intermediate representation will sometimes use
1404 several statements chained together.
1409 Used to represent an inline assembly statement. For an inline assembly
1414 The @code{ASM_STRING} macro will return a @code{STRING_CST} node for
1415 @code{"mov x, y"}. If the original statement made use of the
1416 extended-assembly syntax, then @code{ASM_OUTPUTS},
1417 @code{ASM_INPUTS}, and @code{ASM_CLOBBERS} will be the outputs, inputs,
1418 and clobbers for the statement, represented as @code{STRING_CST} nodes.
1419 The extended-assembly syntax looks like:
1421 asm ("fsinx %1,%0" : "=f" (result) : "f" (angle));
1423 The first string is the @code{ASM_STRING}, containing the instruction
1424 template. The next two strings are the output and inputs, respectively;
1425 this statement has no clobbers. As this example indicates, ``plain''
1426 assembly statements are merely a special case of extended assembly
1427 statements; they have no cv-qualifiers, outputs, inputs, or clobbers.
1428 All of the strings will be @code{NUL}-terminated, and will contain no
1429 embedded @code{NUL}-characters.
1431 If the assembly statement is declared @code{volatile}, or if the
1432 statement was not an extended assembly statement, and is therefore
1433 implicitly volatile, then the predicate @code{ASM_VOLATILE_P} will hold
1434 of the @code{ASM_STMT}.
1438 Used to represent a @code{break} statement. There are no additional
1443 Use to represent a @code{case} label, range of @code{case} labels, or a
1444 @code{default} label. If @code{CASE_LOW} is @code{NULL_TREE}, then this is a
1445 @code{default} label. Otherwise, if @code{CASE_HIGH} is @code{NULL_TREE}, then
1446 this is an ordinary @code{case} label. In this case, @code{CASE_LOW} is
1447 an expression giving the value of the label. Both @code{CASE_LOW} and
1448 @code{CASE_HIGH} are @code{INTEGER_CST} nodes. These values will have
1449 the same type as the condition expression in the switch statement.
1451 Otherwise, if both @code{CASE_LOW} and @code{CASE_HIGH} are defined, the
1452 statement is a range of case labels. Such statements originate with the
1453 extension that allows users to write things of the form:
1457 The first value will be @code{CASE_LOW}, while the second will be
1462 Used to represent an action that should take place upon exit from the
1463 enclosing scope. Typically, these actions are calls to destructors for
1464 local objects, but back ends cannot rely on this fact. If these nodes
1465 are in fact representing such destructors, @code{CLEANUP_DECL} will be
1466 the @code{VAR_DECL} destroyed. Otherwise, @code{CLEANUP_DECL} will be
1467 @code{NULL_TREE}. In any case, the @code{CLEANUP_EXPR} is the
1468 expression to execute. The cleanups executed on exit from a scope
1469 should be run in the reverse order of the order in which the associated
1470 @code{CLEANUP_STMT}s were encountered.
1474 Used to represent a brace-enclosed block. The first substatement is
1475 given by @code{COMPOUND_BODY}. Subsequent substatements are found by
1476 following the @code{TREE_CHAIN} link from one substatement to the next.
1477 The @code{COMPOUND_BODY} will be @code{NULL_TREE} if there are no
1482 Used to represent a @code{continue} statement. There are no additional
1487 Used to mark the beginning (if @code{CTOR_BEGIN_P} holds) or end (if
1488 @code{CTOR_END_P} holds of the main body of a constructor. See also
1489 @code{SUBOBJECT} for more information on how to use these nodes.
1493 Used to represent a local declaration. The @code{DECL_STMT_DECL} macro
1494 can be used to obtain the entity declared. This declaration may be a
1495 @code{LABEL_DECL}, indicating that the label declared is a local label.
1496 (As an extension, GCC allows the declaration of labels with scope.) In
1497 C, this declaration may be a @code{FUNCTION_DECL}, indicating the
1498 use of the GCC nested function extension. For more information,
1503 Used to represent a @code{do} loop. The body of the loop is given by
1504 @code{DO_BODY} while the termination condition for the loop is given by
1505 @code{DO_COND}. The condition for a @code{do}-statement is always an
1508 @item EMPTY_CLASS_EXPR
1510 Used to represent a temporary object of a class with no data whose
1511 address is never taken. (All such objects are interchangeable.) The
1512 @code{TREE_TYPE} represents the type of the object.
1516 Used to represent an expression statement. Use @code{EXPR_STMT_EXPR} to
1517 obtain the expression.
1521 Used to record a change in filename within the body of a function.
1522 Use @code{FILE_STMT_FILENAME} to obtain the new filename.
1526 Used to represent a @code{for} statement. The @code{FOR_INIT_STMT} is
1527 the initialization statement for the loop. The @code{FOR_COND} is the
1528 termination condition. The @code{FOR_EXPR} is the expression executed
1529 right before the @code{FOR_COND} on each loop iteration; often, this
1530 expression increments a counter. The body of the loop is given by
1531 @code{FOR_BODY}. Note that @code{FOR_INIT_STMT} and @code{FOR_BODY}
1532 return statements, while @code{FOR_COND} and @code{FOR_EXPR} return
1537 Used to represent a @code{goto} statement. The @code{GOTO_DESTINATION} will
1538 usually be a @code{LABEL_DECL}. However, if the ``computed goto'' extension
1539 has been used, the @code{GOTO_DESTINATION} will be an arbitrary expression
1540 indicating the destination. This expression will always have pointer type.
1541 Additionally the @code{GOTO_FAKE_P} flag is set whenever the goto statement
1542 does not come from source code, but it is generated implicitly by the compiler.
1543 This is used for branch prediction.
1547 Used to represent a C++ @code{catch} block. The @code{HANDLER_TYPE}
1548 is the type of exception that will be caught by this handler; it is
1549 equal (by pointer equality) to @code{NULL} if this handler is for all
1550 types. @code{HANDLER_PARMS} is the @code{DECL_STMT} for the catch
1551 parameter, and @code{HANDLER_BODY} is the @code{COMPOUND_STMT} for the
1556 Used to represent an @code{if} statement. The @code{IF_COND} is the
1559 If the condition is a @code{TREE_LIST}, then the @code{TREE_PURPOSE} is
1560 a statement (usually a @code{DECL_STMT}). Each time the condition is
1561 evaluated, the statement should be executed. Then, the
1562 @code{TREE_VALUE} should be used as the conditional expression itself.
1563 This representation is used to handle C++ code like this:
1566 if (int i = 7) @dots{}
1569 where there is a new local variable (or variables) declared within the
1572 The @code{THEN_CLAUSE} represents the statement given by the @code{then}
1573 condition, while the @code{ELSE_CLAUSE} represents the statement given
1574 by the @code{else} condition.
1578 Used to represent a label. The @code{LABEL_DECL} declared by this
1579 statement can be obtained with the @code{LABEL_STMT_LABEL} macro. The
1580 @code{IDENTIFIER_NODE} giving the name of the label can be obtained from
1581 the @code{LABEL_DECL} with @code{DECL_NAME}.
1585 If the function uses the G++ ``named return value'' extension, meaning
1586 that the function has been defined like:
1588 S f(int) return s @{@dots{}@}
1590 then there will be a @code{RETURN_INIT}. There is never a named
1591 returned value for a constructor. The first argument to the
1592 @code{RETURN_INIT} is the name of the object returned; the second
1593 argument is the initializer for the object. The object is initialized
1594 when the @code{RETURN_INIT} is encountered. The object referred to is
1595 the actual object returned; this extension is a manual way of doing the
1596 ``return-value optimization.'' Therefore, the object must actually be
1597 constructed in the place where the object will be returned.
1601 Used to represent a @code{return} statement. The @code{RETURN_EXPR} is
1602 the expression returned; it will be @code{NULL_TREE} if the statement
1610 A scope-statement represents the beginning or end of a scope. If
1611 @code{SCOPE_BEGIN_P} holds, this statement represents the beginning of a
1612 scope; if @code{SCOPE_END_P} holds this statement represents the end of
1613 a scope. On exit from a scope, all cleanups from @code{CLEANUP_STMT}s
1614 occurring in the scope must be run, in reverse order to the order in
1615 which they were encountered. If @code{SCOPE_NULLIFIED_P} or
1616 @code{SCOPE_NO_CLEANUPS_P} holds of the scope, back ends should behave
1617 as if the @code{SCOPE_STMT} were not present at all.
1621 In a constructor, these nodes are used to mark the point at which a
1622 subobject of @code{this} is fully constructed. If, after this point, an
1623 exception is thrown before a @code{CTOR_STMT} with @code{CTOR_END_P} set
1624 is encountered, the @code{SUBOBJECT_CLEANUP} must be executed. The
1625 cleanups must be executed in the reverse order in which they appear.
1629 Used to represent a @code{switch} statement. The @code{SWITCH_COND} is
1630 the expression on which the switch is occurring. See the documentation
1631 for an @code{IF_STMT} for more information on the representation used
1632 for the condition. The @code{SWITCH_BODY} is the body of the switch
1633 statement. The @code{SWITCH_TYPE} is the original type of switch
1634 expression as given in the source, before any compiler conversions.
1637 Used to represent a @code{try} block. The body of the try block is
1638 given by @code{TRY_STMTS}. Each of the catch blocks is a @code{HANDLER}
1639 node. The first handler is given by @code{TRY_HANDLERS}. Subsequent
1640 handlers are obtained by following the @code{TREE_CHAIN} link from one
1641 handler to the next. The body of the handler is given by
1642 @code{HANDLER_BODY}.
1644 If @code{CLEANUP_P} holds of the @code{TRY_BLOCK}, then the
1645 @code{TRY_HANDLERS} will not be a @code{HANDLER} node. Instead, it will
1646 be an expression that should be executed if an exception is thrown in
1647 the try block. It must rethrow the exception after executing that code.
1648 And, if an exception is thrown while the expression is executing,
1649 @code{terminate} must be called.
1652 Used to represent a @code{using} directive. The namespace is given by
1653 @code{USING_STMT_NAMESPACE}, which will be a NAMESPACE_DECL@. This node
1654 is needed inside template functions, to implement using directives
1655 during instantiation.
1659 Used to represent a @code{while} loop. The @code{WHILE_COND} is the
1660 termination condition for the loop. See the documentation for an
1661 @code{IF_STMT} for more information on the representation used for the
1664 The @code{WHILE_BODY} is the body of the loop.
1668 @c ---------------------------------------------------------------------
1670 @c ---------------------------------------------------------------------
1672 @section Attributes in trees
1675 Attributes, as specified using the @code{__attribute__} keyword, are
1676 represented internally as a @code{TREE_LIST}. The @code{TREE_PURPOSE}
1677 is the name of the attribute, as an @code{IDENTIFIER_NODE}. The
1678 @code{TREE_VALUE} is a @code{TREE_LIST} of the arguments of the
1679 attribute, if any, or @code{NULL_TREE} if there are no arguments; the
1680 arguments are stored as the @code{TREE_VALUE} of successive entries in
1681 the list, and may be identifiers or expressions. The @code{TREE_CHAIN}
1682 of the attribute is the next attribute in a list of attributes applying
1683 to the same declaration or type, or @code{NULL_TREE} if there are no
1684 further attributes in the list.
1686 Attributes may be attached to declarations and to types; these
1687 attributes may be accessed with the following macros. All attributes
1688 are stored in this way, and many also cause other changes to the
1689 declaration or type or to other internal compiler data structures.
1691 @deftypefn {Tree Macro} tree DECL_ATTRIBUTES (tree @var{decl})
1692 This macro returns the attributes on the declaration @var{decl}.
1695 @deftypefn {Tree Macro} tree TYPE_ATTRIBUTES (tree @var{type})
1696 This macro returns the attributes on the type @var{type}.
1699 @c ---------------------------------------------------------------------
1701 @c ---------------------------------------------------------------------
1703 @node Expression trees
1704 @section Expressions
1706 @findex TREE_OPERAND
1708 @findex TREE_INT_CST_HIGH
1709 @findex TREE_INT_CST_LOW
1710 @findex tree_int_cst_lt
1711 @findex tree_int_cst_equal
1716 @findex TREE_STRING_LENGTH
1717 @findex TREE_STRING_POINTER
1719 @findex PTRMEM_CST_CLASS
1720 @findex PTRMEM_CST_MEMBER
1724 @tindex BIT_NOT_EXPR
1725 @tindex TRUTH_NOT_EXPR
1727 @tindex INDIRECT_REF
1728 @tindex FIX_TRUNC_EXPR
1730 @tindex COMPLEX_EXPR
1732 @tindex REALPART_EXPR
1733 @tindex IMAGPART_EXPR
1735 @tindex CONVERT_EXPR
1739 @tindex BIT_IOR_EXPR
1740 @tindex BIT_XOR_EXPR
1741 @tindex BIT_AND_EXPR
1742 @tindex TRUTH_ANDIF_EXPR
1743 @tindex TRUTH_ORIF_EXPR
1744 @tindex TRUTH_AND_EXPR
1745 @tindex TRUTH_OR_EXPR
1746 @tindex TRUTH_XOR_EXPR
1750 @tindex TRUNC_DIV_EXPR
1751 @tindex TRUNC_MOD_EXPR
1761 @tindex COMPONENT_REF
1762 @tindex COMPOUND_EXPR
1766 @tindex COMPOUND_LITERAL_EXPR
1771 @tindex CLEANUP_POINT_EXPR
1776 The internal representation for expressions is for the most part quite
1777 straightforward. However, there are a few facts that one must bear in
1778 mind. In particular, the expression ``tree'' is actually a directed
1779 acyclic graph. (For example there may be many references to the integer
1780 constant zero throughout the source program; many of these will be
1781 represented by the same expression node.) You should not rely on
1782 certain kinds of node being shared, nor should rely on certain kinds of
1783 nodes being unshared.
1785 The following macros can be used with all expression nodes:
1789 Returns the type of the expression. This value may not be precisely the
1790 same type that would be given the expression in the original program.
1793 In what follows, some nodes that one might expect to always have type
1794 @code{bool} are documented to have either integral or boolean type. At
1795 some point in the future, the C front end may also make use of this same
1796 intermediate representation, and at this point these nodes will
1797 certainly have integral type. The previous sentence is not meant to
1798 imply that the C++ front end does not or will not give these nodes
1801 Below, we list the various kinds of expression nodes. Except where
1802 noted otherwise, the operands to an expression are accessed using the
1803 @code{TREE_OPERAND} macro. For example, to access the first operand to
1804 a binary plus expression @code{expr}, use:
1807 TREE_OPERAND (expr, 0)
1810 As this example indicates, the operands are zero-indexed.
1812 The table below begins with constants, moves on to unary expressions,
1813 then proceeds to binary expressions, and concludes with various other
1814 kinds of expressions:
1818 These nodes represent integer constants. Note that the type of these
1819 constants is obtained with @code{TREE_TYPE}; they are not always of type
1820 @code{int}. In particular, @code{char} constants are represented with
1821 @code{INTEGER_CST} nodes. The value of the integer constant @code{e} is
1823 ((TREE_INT_CST_HIGH (e) << HOST_BITS_PER_WIDE_INT)
1824 + TREE_INST_CST_LOW (e))
1827 HOST_BITS_PER_WIDE_INT is at least thirty-two on all platforms. Both
1828 @code{TREE_INT_CST_HIGH} and @code{TREE_INT_CST_LOW} return a
1829 @code{HOST_WIDE_INT}. The value of an @code{INTEGER_CST} is interpreted
1830 as a signed or unsigned quantity depending on the type of the constant.
1831 In general, the expression given above will overflow, so it should not
1832 be used to calculate the value of the constant.
1834 The variable @code{integer_zero_node} is an integer constant with value
1835 zero. Similarly, @code{integer_one_node} is an integer constant with
1836 value one. The @code{size_zero_node} and @code{size_one_node} variables
1837 are analogous, but have type @code{size_t} rather than @code{int}.
1839 The function @code{tree_int_cst_lt} is a predicate which holds if its
1840 first argument is less than its second. Both constants are assumed to
1841 have the same signedness (i.e., either both should be signed or both
1842 should be unsigned.) The full width of the constant is used when doing
1843 the comparison; the usual rules about promotions and conversions are
1844 ignored. Similarly, @code{tree_int_cst_equal} holds if the two
1845 constants are equal. The @code{tree_int_cst_sgn} function returns the
1846 sign of a constant. The value is @code{1}, @code{0}, or @code{-1}
1847 according on whether the constant is greater than, equal to, or less
1848 than zero. Again, the signedness of the constant's type is taken into
1849 account; an unsigned constant is never less than zero, no matter what
1854 FIXME: Talk about how to obtain representations of this constant, do
1855 comparisons, and so forth.
1858 These nodes are used to represent complex number constants, that is a
1859 @code{__complex__} whose parts are constant nodes. The
1860 @code{TREE_REALPART} and @code{TREE_IMAGPART} return the real and the
1861 imaginary parts respectively.
1864 These nodes are used to represent vector constants, whose parts are
1865 constant nodes. Each individual constant node is either an integer or a
1866 double constant node. The first operand is a @code{TREE_LIST} of the
1867 constant nodes and is accessed through @code{TREE_VECTOR_CST_ELTS}.
1870 These nodes represent string-constants. The @code{TREE_STRING_LENGTH}
1871 returns the length of the string, as an @code{int}. The
1872 @code{TREE_STRING_POINTER} is a @code{char*} containing the string
1873 itself. The string may not be @code{NUL}-terminated, and it may contain
1874 embedded @code{NUL} characters. Therefore, the
1875 @code{TREE_STRING_LENGTH} includes the trailing @code{NUL} if it is
1878 For wide string constants, the @code{TREE_STRING_LENGTH} is the number
1879 of bytes in the string, and the @code{TREE_STRING_POINTER}
1880 points to an array of the bytes of the string, as represented on the
1881 target system (that is, as integers in the target endianness). Wide and
1882 non-wide string constants are distinguished only by the @code{TREE_TYPE}
1883 of the @code{STRING_CST}.
1885 FIXME: The formats of string constants are not well-defined when the
1886 target system bytes are not the same width as host system bytes.
1889 These nodes are used to represent pointer-to-member constants. The
1890 @code{PTRMEM_CST_CLASS} is the class type (either a @code{RECORD_TYPE}
1891 or @code{UNION_TYPE} within which the pointer points), and the
1892 @code{PTRMEM_CST_MEMBER} is the declaration for the pointed to object.
1893 Note that the @code{DECL_CONTEXT} for the @code{PTRMEM_CST_MEMBER} is in
1894 general different from the @code{PTRMEM_CST_CLASS}. For example,
1897 struct B @{ int i; @};
1898 struct D : public B @{@};
1902 The @code{PTRMEM_CST_CLASS} for @code{&D::i} is @code{D}, even though
1903 the @code{DECL_CONTEXT} for the @code{PTRMEM_CST_MEMBER} is @code{B},
1904 since @code{B::i} is a member of @code{B}, not @code{D}.
1908 These nodes represent variables, including static data members. For
1909 more information, @pxref{Declarations}.
1912 These nodes represent unary negation of the single operand, for both
1913 integer and floating-point types. The type of negation can be
1914 determined by looking at the type of the expression.
1916 The behavior of this operation on signed arithmetic overflow is
1917 controlled by the @code{flag_wrapv} and @code{flag_trapv} variables.
1920 These nodes represent the absolute value of the single operand, for
1921 both integer and floating-point types. This is typically used to
1922 implement the @code{abs}, @code{labs} and @code{llabs} builtins for
1923 integer types, and the @code{fabs}, @code{fabsf} and @code{fabsl}
1924 builtins for floating point types. The type of abs operation can
1925 be determined by looking at the type of the expression.
1927 This node is not used for complex types. To represent the modulus
1928 or complex abs of a complex value, use the @code{BUILT_IN_CABS},
1929 @code{BUILT_IN_CABSF} or @code{BUILT_IN_CABSL} builtins, as used
1930 to implement the C99 @code{cabs}, @code{cabsf} and @code{cabsl}
1934 These nodes represent bitwise complement, and will always have integral
1935 type. The only operand is the value to be complemented.
1937 @item TRUTH_NOT_EXPR
1938 These nodes represent logical negation, and will always have integral
1939 (or boolean) type. The operand is the value being negated.
1941 @item PREDECREMENT_EXPR
1942 @itemx PREINCREMENT_EXPR
1943 @itemx POSTDECREMENT_EXPR
1944 @itemx POSTINCREMENT_EXPR
1945 These nodes represent increment and decrement expressions. The value of
1946 the single operand is computed, and the operand incremented or
1947 decremented. In the case of @code{PREDECREMENT_EXPR} and
1948 @code{PREINCREMENT_EXPR}, the value of the expression is the value
1949 resulting after the increment or decrement; in the case of
1950 @code{POSTDECREMENT_EXPR} and @code{POSTINCREMENT_EXPR} is the value
1951 before the increment or decrement occurs. The type of the operand, like
1952 that of the result, will be either integral, boolean, or floating-point.
1955 These nodes are used to represent the address of an object. (These
1956 expressions will always have pointer or reference type.) The operand may
1957 be another expression, or it may be a declaration.
1959 As an extension, GCC allows users to take the address of a label. In
1960 this case, the operand of the @code{ADDR_EXPR} will be a
1961 @code{LABEL_DECL}. The type of such an expression is @code{void*}.
1963 If the object addressed is not an lvalue, a temporary is created, and
1964 the address of the temporary is used.
1967 These nodes are used to represent the object pointed to by a pointer.
1968 The operand is the pointer being dereferenced; it will always have
1969 pointer or reference type.
1971 @item FIX_TRUNC_EXPR
1972 These nodes represent conversion of a floating-point value to an
1973 integer. The single operand will have a floating-point type, while the
1974 the complete expression will have an integral (or boolean) type. The
1975 operand is rounded towards zero.
1978 These nodes represent conversion of an integral (or boolean) value to a
1979 floating-point value. The single operand will have integral type, while
1980 the complete expression will have a floating-point type.
1982 FIXME: How is the operand supposed to be rounded? Is this dependent on
1986 These nodes are used to represent complex numbers constructed from two
1987 expressions of the same (integer or real) type. The first operand is the
1988 real part and the second operand is the imaginary part.
1991 These nodes represent the conjugate of their operand.
1994 @itemx IMAGPART_EXPR
1995 These nodes represent respectively the real and the imaginary parts
1996 of complex numbers (their sole argument).
1998 @item NON_LVALUE_EXPR
1999 These nodes indicate that their one and only operand is not an lvalue.
2000 A back end can treat these identically to the single operand.
2003 These nodes are used to represent conversions that do not require any
2004 code-generation. For example, conversion of a @code{char*} to an
2005 @code{int*} does not require any code be generated; such a conversion is
2006 represented by a @code{NOP_EXPR}. The single operand is the expression
2007 to be converted. The conversion from a pointer to a reference is also
2008 represented with a @code{NOP_EXPR}.
2011 These nodes are similar to @code{NOP_EXPR}s, but are used in those
2012 situations where code may need to be generated. For example, if an
2013 @code{int*} is converted to an @code{int} code may need to be generated
2014 on some platforms. These nodes are never used for C++-specific
2015 conversions, like conversions between pointers to different classes in
2016 an inheritance hierarchy. Any adjustments that need to be made in such
2017 cases are always indicated explicitly. Similarly, a user-defined
2018 conversion is never represented by a @code{CONVERT_EXPR}; instead, the
2019 function calls are made explicit.
2022 These nodes represent @code{throw} expressions. The single operand is
2023 an expression for the code that should be executed to throw the
2024 exception. However, there is one implicit action not represented in
2025 that expression; namely the call to @code{__throw}. This function takes
2026 no arguments. If @code{setjmp}/@code{longjmp} exceptions are used, the
2027 function @code{__sjthrow} is called instead. The normal GCC back end
2028 uses the function @code{emit_throw} to generate this code; you can
2029 examine this function to see what needs to be done.
2033 These nodes represent left and right shifts, respectively. The first
2034 operand is the value to shift; it will always be of integral type. The
2035 second operand is an expression for the number of bits by which to
2036 shift. Right shift should be treated as arithmetic, i.e., the
2037 high-order bits should be zero-filled when the expression has unsigned
2038 type and filled with the sign bit when the expression has signed type.
2039 Note that the result is undefined if the second operand is larger
2040 than the first operand's type size.
2046 These nodes represent bitwise inclusive or, bitwise exclusive or, and
2047 bitwise and, respectively. Both operands will always have integral
2050 @item TRUTH_ANDIF_EXPR
2051 @itemx TRUTH_ORIF_EXPR
2052 These nodes represent logical and and logical or, respectively. These
2053 operators are not strict; i.e., the second operand is evaluated only if
2054 the value of the expression is not determined by evaluation of the first
2055 operand. The type of the operands, and the result type, is always of
2056 boolean or integral type.
2058 @item TRUTH_AND_EXPR
2059 @itemx TRUTH_OR_EXPR
2060 @itemx TRUTH_XOR_EXPR
2061 These nodes represent logical and, logical or, and logical exclusive or.
2062 They are strict; both arguments are always evaluated. There are no
2063 corresponding operators in C or C++, but the front end will sometimes
2064 generate these expressions anyhow, if it can tell that strictness does
2070 @itemx TRUNC_DIV_EXPR
2071 @itemx TRUNC_MOD_EXPR
2073 These nodes represent various binary arithmetic operations.
2074 Respectively, these operations are addition, subtraction (of the second
2075 operand from the first), multiplication, integer division, integer
2076 remainder, and floating-point division. The operands to the first three
2077 of these may have either integral or floating type, but there will never
2078 be case in which one operand is of floating type and the other is of
2081 The result of a @code{TRUNC_DIV_EXPR} is always rounded towards zero.
2082 The @code{TRUNC_MOD_EXPR} of two operands @code{a} and @code{b} is
2083 always @code{a - (a/b)*b} where the division is as if computed by a
2084 @code{TRUNC_DIV_EXPR}.
2086 The behavior of these operations on signed arithmetic overflow is
2087 controlled by the @code{flag_wrapv} and @code{flag_trapv} variables.
2090 These nodes represent array accesses. The first operand is the array;
2091 the second is the index. To calculate the address of the memory
2092 accessed, you must scale the index by the size of the type of the array
2093 elements. The type of these expressions must be the type of a component of
2096 @item ARRAY_RANGE_REF
2097 These nodes represent access to a range (or ``slice'') of an array. The
2098 operands are the same as that for @code{ARRAY_REF} and have the same
2099 meanings. The type of these expressions must be an array whose component
2100 type is the same as that of the first operand. The range of that array
2101 type determines the amount of data these expressions access.
2103 @item EXACT_DIV_EXPR
2113 These nodes represent the less than, less than or equal to, greater
2114 than, greater than or equal to, equal, and not equal comparison
2115 operators. The first and second operand with either be both of integral
2116 type or both of floating type. The result type of these expressions
2117 will always be of integral or boolean type.
2120 These nodes represent assignment. The left-hand side is the first
2121 operand; the right-hand side is the second operand. The left-hand side
2122 will be a @code{VAR_DECL}, @code{INDIRECT_REF}, @code{COMPONENT_REF}, or
2125 These nodes are used to represent not only assignment with @samp{=} but
2126 also compound assignments (like @samp{+=}), by reduction to @samp{=}
2127 assignment. In other words, the representation for @samp{i += 3} looks
2128 just like that for @samp{i = i + 3}.
2131 These nodes are just like @code{MODIFY_EXPR}, but are used only when a
2132 variable is initialized, rather than assigned to subsequently.
2135 These nodes represent non-static data member accesses. The first
2136 operand is the object (rather than a pointer to it); the second operand
2137 is the @code{FIELD_DECL} for the data member.
2140 These nodes represent comma-expressions. The first operand is an
2141 expression whose value is computed and thrown away prior to the
2142 evaluation of the second operand. The value of the entire expression is
2143 the value of the second operand.
2146 These nodes represent @code{?:} expressions. The first operand
2147 is of boolean or integral type. If it evaluates to a nonzero value,
2148 the second operand should be evaluated, and returned as the value of the
2149 expression. Otherwise, the third operand is evaluated, and returned as
2150 the value of the expression.
2152 The second operand must have the same type as the entire expression,
2153 unless it unconditionally throws an exception or calls a noreturn
2154 function, in which case it should have void type. The same constraints
2155 apply to the third operand. This allows array bounds checks to be
2156 represented conveniently as @code{(i >= 0 && i < 10) ? i : abort()}.
2158 As a GNU extension, the C language front-ends allow the second
2159 operand of the @code{?:} operator may be omitted in the source.
2160 For example, @code{x ? : 3} is equivalent to @code{x ? x : 3},
2161 assuming that @code{x} is an expression without side-effects.
2162 In the tree representation, however, the second operand is always
2163 present, possibly protected by @code{SAVE_EXPR} if the first
2164 argument does cause side-effects.
2167 These nodes are used to represent calls to functions, including
2168 non-static member functions. The first operand is a pointer to the
2169 function to call; it is always an expression whose type is a
2170 @code{POINTER_TYPE}. The second argument is a @code{TREE_LIST}. The
2171 arguments to the call appear left-to-right in the list. The
2172 @code{TREE_VALUE} of each list node contains the expression
2173 corresponding to that argument. (The value of @code{TREE_PURPOSE} for
2174 these nodes is unspecified, and should be ignored.) For non-static
2175 member functions, there will be an operand corresponding to the
2176 @code{this} pointer. There will always be expressions corresponding to
2177 all of the arguments, even if the function is declared with default
2178 arguments and some arguments are not explicitly provided at the call
2182 These nodes are used to represent GCC's statement-expression extension.
2183 The statement-expression extension allows code like this:
2185 int f() @{ return (@{ int j; j = 3; j + 7; @}); @}
2187 In other words, an sequence of statements may occur where a single
2188 expression would normally appear. The @code{STMT_EXPR} node represents
2189 such an expression. The @code{STMT_EXPR_STMT} gives the statement
2190 contained in the expression; this is always a @code{COMPOUND_STMT}. The
2191 value of the expression is the value of the last sub-statement in the
2192 @code{COMPOUND_STMT}. More precisely, the value is the value computed
2193 by the last @code{EXPR_STMT} in the outermost scope of the
2194 @code{COMPOUND_STMT}. For example, in:
2198 the value is @code{3} while in:
2200 (@{ if (x) @{ 3; @} @})
2202 (represented by a nested @code{COMPOUND_STMT}), there is no value. If
2203 the @code{STMT_EXPR} does not yield a value, it's type will be
2207 These nodes represent local blocks. The first operand is a list of
2208 temporary variables, connected via their @code{TREE_CHAIN} field. These
2209 will never require cleanups. The scope of these variables is just the
2210 body of the @code{BIND_EXPR}. The body of the @code{BIND_EXPR} is the
2214 These nodes represent ``infinite'' loops. The @code{LOOP_EXPR_BODY}
2215 represents the body of the loop. It should be executed forever, unless
2216 an @code{EXIT_EXPR} is encountered.
2219 These nodes represent conditional exits from the nearest enclosing
2220 @code{LOOP_EXPR}. The single operand is the condition; if it is
2221 nonzero, then the loop should be exited. An @code{EXIT_EXPR} will only
2222 appear within a @code{LOOP_EXPR}.
2224 @item CLEANUP_POINT_EXPR
2225 These nodes represent full-expressions. The single operand is an
2226 expression to evaluate. Any destructor calls engendered by the creation
2227 of temporaries during the evaluation of that expression should be
2228 performed immediately after the expression is evaluated.
2231 These nodes represent the brace-enclosed initializers for a structure or
2232 array. The first operand is reserved for use by the back end. The
2233 second operand is a @code{TREE_LIST}. If the @code{TREE_TYPE} of the
2234 @code{CONSTRUCTOR} is a @code{RECORD_TYPE} or @code{UNION_TYPE}, then
2235 the @code{TREE_PURPOSE} of each node in the @code{TREE_LIST} will be a
2236 @code{FIELD_DECL} and the @code{TREE_VALUE} of each node will be the
2237 expression used to initialize that field.
2239 If the @code{TREE_TYPE} of the @code{CONSTRUCTOR} is an
2240 @code{ARRAY_TYPE}, then the @code{TREE_PURPOSE} of each element in the
2241 @code{TREE_LIST} will be an @code{INTEGER_CST}. This constant indicates
2242 which element of the array (indexed from zero) is being assigned to;
2243 again, the @code{TREE_VALUE} is the corresponding initializer. If the
2244 @code{TREE_PURPOSE} is @code{NULL_TREE}, then the initializer is for the
2245 next available array element.
2247 In the front end, you should not depend on the fields appearing in any
2248 particular order. However, in the middle end, fields must appear in
2249 declaration order. You should not assume that all fields will be
2250 represented. Unrepresented fields will be set to zero.
2252 @item COMPOUND_LITERAL_EXPR
2253 @findex COMPOUND_LITERAL_EXPR_DECL_STMT
2254 @findex COMPOUND_LITERAL_EXPR_DECL
2255 These nodes represent ISO C99 compound literals. The
2256 @code{COMPOUND_LITERAL_EXPR_DECL_STMT} is a @code{DECL_STMT}
2257 containing an anonymous @code{VAR_DECL} for
2258 the unnamed object represented by the compound literal; the
2259 @code{DECL_INITIAL} of that @code{VAR_DECL} is a @code{CONSTRUCTOR}
2260 representing the brace-enclosed list of initializers in the compound
2261 literal. That anonymous @code{VAR_DECL} can also be accessed directly
2262 by the @code{COMPOUND_LITERAL_EXPR_DECL} macro.
2266 A @code{SAVE_EXPR} represents an expression (possibly involving
2267 side-effects) that is used more than once. The side-effects should
2268 occur only the first time the expression is evaluated. Subsequent uses
2269 should just reuse the computed value. The first operand to the
2270 @code{SAVE_EXPR} is the expression to evaluate. The side-effects should
2271 be executed where the @code{SAVE_EXPR} is first encountered in a
2272 depth-first preorder traversal of the expression tree.
2275 A @code{TARGET_EXPR} represents a temporary object. The first operand
2276 is a @code{VAR_DECL} for the temporary variable. The second operand is
2277 the initializer for the temporary. The initializer is evaluated, and
2278 copied (bitwise) into the temporary.
2280 Often, a @code{TARGET_EXPR} occurs on the right-hand side of an
2281 assignment, or as the second operand to a comma-expression which is
2282 itself the right-hand side of an assignment, etc. In this case, we say
2283 that the @code{TARGET_EXPR} is ``normal''; otherwise, we say it is
2284 ``orphaned''. For a normal @code{TARGET_EXPR} the temporary variable
2285 should be treated as an alias for the left-hand side of the assignment,
2286 rather than as a new temporary variable.
2288 The third operand to the @code{TARGET_EXPR}, if present, is a
2289 cleanup-expression (i.e., destructor call) for the temporary. If this
2290 expression is orphaned, then this expression must be executed when the
2291 statement containing this expression is complete. These cleanups must
2292 always be executed in the order opposite to that in which they were
2293 encountered. Note that if a temporary is created on one branch of a
2294 conditional operator (i.e., in the second or third operand to a
2295 @code{COND_EXPR}), the cleanup must be run only if that branch is
2298 See @code{STMT_IS_FULL_EXPR_P} for more information about running these
2301 @item AGGR_INIT_EXPR
2302 An @code{AGGR_INIT_EXPR} represents the initialization as the return
2303 value of a function call, or as the result of a constructor. An
2304 @code{AGGR_INIT_EXPR} will only appear as the second operand of a
2305 @code{TARGET_EXPR}. The first operand to the @code{AGGR_INIT_EXPR} is
2306 the address of a function to call, just as in a @code{CALL_EXPR}. The
2307 second operand are the arguments to pass that function, as a
2308 @code{TREE_LIST}, again in a manner similar to that of a
2309 @code{CALL_EXPR}. The value of the expression is that returned by the
2312 If @code{AGGR_INIT_VIA_CTOR_P} holds of the @code{AGGR_INIT_EXPR}, then
2313 the initialization is via a constructor call. The address of the third
2314 operand of the @code{AGGR_INIT_EXPR}, which is always a @code{VAR_DECL},
2315 is taken, and this value replaces the first argument in the argument
2316 list. In this case, the value of the expression is the @code{VAR_DECL}
2317 given by the third operand to the @code{AGGR_INIT_EXPR}; constructors do
2321 A @code{VTABLE_REF} indicates that the interior expression computes
2322 a value that is a vtable entry. It is used with @option{-fvtable-gc}
2323 to track the reference through to front end to the middle end, at
2324 which point we transform this to a @code{REG_VTABLE_REF} note, which
2325 survives the balance of code generation.
2327 The first operand is the expression that computes the vtable reference.
2328 The second operand is the @code{VAR_DECL} of the vtable. The third
2329 operand is an @code{INTEGER_CST} of the byte offset into the vtable.
2332 This node is used to implement support for the C/C++ variable argument-list
2333 mechanism. It represents expressions like @code{va_arg (ap, type)}.
2334 Its @code{TREE_TYPE} yields the tree representation for @code{type} and
2335 its sole argument yields the representation for @code{ap}.