gccint: Statements for C++
1
1 11.10.5 Statements for C++
1 --------------------------
1
1 A function that has a definition in the current translation unit will
1 have a non-'NULL' 'DECL_INITIAL'. However, back ends should not make
1 use of the particular value given by 'DECL_INITIAL'.
1
1 The 'DECL_SAVED_TREE' macro will give the complete body of the
1 function.
1
1 11.10.5.1 Statements
1 ....................
1
1 There are tree nodes corresponding to all of the source-level statement
1 constructs, used within the C and C++ frontends. These are enumerated
1 here, together with a list of the various macros that can be used to
1 obtain information about them. There are a few macros that can be used
1 with all statements:
1
1 'STMT_IS_FULL_EXPR_P'
1 In C++, statements normally constitute "full expressions";
1 temporaries created during a statement are destroyed when the
1 statement is complete. However, G++ sometimes represents
1 expressions by statements; these statements will not have
1 'STMT_IS_FULL_EXPR_P' set. Temporaries created during such
1 statements should be destroyed when the innermost enclosing
1 statement with 'STMT_IS_FULL_EXPR_P' set is exited.
1
1 Here is the list of the various statement nodes, and the macros used to
1 access them. This documentation describes the use of these nodes in
1 non-template functions (including instantiations of template functions).
1 In template functions, the same nodes are used, but sometimes in
1 slightly different ways.
1
1 Many of the statements have substatements. For example, a 'while' loop
1 will have a body, which is itself a statement. If the substatement is
1 'NULL_TREE', it is considered equivalent to a statement consisting of a
1 single ';', i.e., an expression statement in which the expression has
1 been omitted. A substatement may in fact be a list of statements,
1 connected via their 'TREE_CHAIN's. So, you should always process the
1 statement tree by looping over substatements, like this:
1 void process_stmt (stmt)
1 tree stmt;
1 {
1 while (stmt)
1 {
1 switch (TREE_CODE (stmt))
1 {
1 case IF_STMT:
1 process_stmt (THEN_CLAUSE (stmt));
1 /* More processing here. */
1 break;
1
1 ...
1 }
1
1 stmt = TREE_CHAIN (stmt);
1 }
1 }
1 In other words, while the 'then' clause of an 'if' statement in C++ can
1 be only one statement (although that one statement may be a compound
1 statement), the intermediate representation will sometimes use several
1 statements chained together.
1
1 'BREAK_STMT'
1
1 Used to represent a 'break' statement. There are no additional
1 fields.
1
1 'CLEANUP_STMT'
1
1 Used to represent an action that should take place upon exit from
1 the enclosing scope. Typically, these actions are calls to
1 destructors for local objects, but back ends cannot rely on this
1 fact. If these nodes are in fact representing such destructors,
1 'CLEANUP_DECL' will be the 'VAR_DECL' destroyed. Otherwise,
1 'CLEANUP_DECL' will be 'NULL_TREE'. In any case, the
1 'CLEANUP_EXPR' is the expression to execute. The cleanups executed
1 on exit from a scope should be run in the reverse order of the
1 order in which the associated 'CLEANUP_STMT's were encountered.
1
1 'CONTINUE_STMT'
1
1 Used to represent a 'continue' statement. There are no additional
1 fields.
1
1 'CTOR_STMT'
1
1 Used to mark the beginning (if 'CTOR_BEGIN_P' holds) or end (if
1 'CTOR_END_P' holds of the main body of a constructor. See also
1 'SUBOBJECT' for more information on how to use these nodes.
1
1 'DO_STMT'
1
1 Used to represent a 'do' loop. The body of the loop is given by
1 'DO_BODY' while the termination condition for the loop is given by
1 'DO_COND'. The condition for a 'do'-statement is always an
1 expression.
1
1 'EMPTY_CLASS_EXPR'
1
1 Used to represent a temporary object of a class with no data whose
1 address is never taken. (All such objects are interchangeable.)
1 The 'TREE_TYPE' represents the type of the object.
1
1 'EXPR_STMT'
1
1 Used to represent an expression statement. Use 'EXPR_STMT_EXPR' to
1 obtain the expression.
1
1 'FOR_STMT'
1
1 Used to represent a 'for' statement. The 'FOR_INIT_STMT' is the
1 initialization statement for the loop. The 'FOR_COND' is the
1 termination condition. The 'FOR_EXPR' is the expression executed
1 right before the 'FOR_COND' on each loop iteration; often, this
1 expression increments a counter. The body of the loop is given by
1 'FOR_BODY'. Note that 'FOR_INIT_STMT' and 'FOR_BODY' return
1 statements, while 'FOR_COND' and 'FOR_EXPR' return expressions.
1
1 'HANDLER'
1
1 Used to represent a C++ 'catch' block. The 'HANDLER_TYPE' is the
1 type of exception that will be caught by this handler; it is equal
1 (by pointer equality) to 'NULL' if this handler is for all types.
1 'HANDLER_PARMS' is the 'DECL_STMT' for the catch parameter, and
1 'HANDLER_BODY' is the code for the block itself.
1
1 'IF_STMT'
1
1 Used to represent an 'if' statement. The 'IF_COND' is the
1 expression.
1
1 If the condition is a 'TREE_LIST', then the 'TREE_PURPOSE' is a
1 statement (usually a 'DECL_STMT'). Each time the condition is
1 evaluated, the statement should be executed. Then, the
1 'TREE_VALUE' should be used as the conditional expression itself.
1 This representation is used to handle C++ code like this:
1
1 C++ distinguishes between this and 'COND_EXPR' for handling
1 templates.
1
1 if (int i = 7) ...
1
1 where there is a new local variable (or variables) declared within
1 the condition.
1
1 The 'THEN_CLAUSE' represents the statement given by the 'then'
1 condition, while the 'ELSE_CLAUSE' represents the statement given
1 by the 'else' condition.
1
1 'SUBOBJECT'
1
1 In a constructor, these nodes are used to mark the point at which a
1 subobject of 'this' is fully constructed. If, after this point, an
1 exception is thrown before a 'CTOR_STMT' with 'CTOR_END_P' set is
1 encountered, the 'SUBOBJECT_CLEANUP' must be executed. The
1 cleanups must be executed in the reverse order in which they
1 appear.
1
1 'SWITCH_STMT'
1
1 Used to represent a 'switch' statement. The 'SWITCH_STMT_COND' is
1 the expression on which the switch is occurring. See the
1 documentation for an 'IF_STMT' for more information on the
1 representation used for the condition. The 'SWITCH_STMT_BODY' is
1 the body of the switch statement. The 'SWITCH_STMT_TYPE' is the
1 original type of switch expression as given in the source, before
1 any compiler conversions.
1
1 'TRY_BLOCK'
1 Used to represent a 'try' block. The body of the try block is
1 given by 'TRY_STMTS'. Each of the catch blocks is a 'HANDLER'
1 node. The first handler is given by 'TRY_HANDLERS'. Subsequent
1 handlers are obtained by following the 'TREE_CHAIN' link from one
1 handler to the next. The body of the handler is given by
1 'HANDLER_BODY'.
1
1 If 'CLEANUP_P' holds of the 'TRY_BLOCK', then the 'TRY_HANDLERS'
1 will not be a 'HANDLER' node. Instead, it will be an expression
1 that should be executed if an exception is thrown in the try block.
1 It must rethrow the exception after executing that code. And, if
1 an exception is thrown while the expression is executing,
1 'terminate' must be called.
1
1 'USING_STMT'
1 Used to represent a 'using' directive. The namespace is given by
1 'USING_STMT_NAMESPACE', which will be a NAMESPACE_DECL. This node
1 is needed inside template functions, to implement using directives
1 during instantiation.
1
1 'WHILE_STMT'
1
1 Used to represent a 'while' loop. The 'WHILE_COND' is the
1 termination condition for the loop. See the documentation for an
1 'IF_STMT' for more information on the representation used for the
1 condition.
1
1 The 'WHILE_BODY' is the body of the loop.
1