* cp-tree.h (EXPR_STMT_ASSIGNS_THIS): New macro.
(STMT_IS_FULL_EXPR_P): Likewise.
(STMT_LINENO_FOR_FN_P): Likewise.
(prep_stmt): New function.
(building_stmt_tree): Tweak for safety.
* pt.c (tsubst_expr): Use prep_stmt throughout.
(add_tree): Move it to semantics.c
* semantics.c (add_tree): Move it here.
(finish_expr_stmt_real): New function.
(finish_expr_stmt): Use it.
(finish_if_stmt_cond): Use FINISH_COND.
(finish_while_stmt_cond): Likewise.
(finish_for_cond): Likewise.
(finish_stmt_tree): Tweak line-number handling.
(prep_stmt): New function.
(expand_stmt): Use it.
From-SVN: r29249
1999-09-09 Mark Mitchell <mark@codesourcery.com>
+ * cp-tree.h (EXPR_STMT_ASSIGNS_THIS): New macro.
+ (STMT_IS_FULL_EXPR_P): Likewise.
+ (STMT_LINENO_FOR_FN_P): Likewise.
+ (prep_stmt): New function.
+ (building_stmt_tree): Tweak for safety.
+ * pt.c (tsubst_expr): Use prep_stmt throughout.
+ (add_tree): Move it to semantics.c
+ * semantics.c (add_tree): Move it here.
+ (finish_expr_stmt_real): New function.
+ (finish_expr_stmt): Use it.
+ (finish_if_stmt_cond): Use FINISH_COND.
+ (finish_while_stmt_cond): Likewise.
+ (finish_for_cond): Likewise.
+ (finish_stmt_tree): Tweak line-number handling.
+ (prep_stmt): New function.
+ (expand_stmt): Use it.
+
* cp-tree.h (begin_switch_stmt): Adjust prototype.
(finish_switch_cond): Likewise.
* parse.y (simple_stmt): Adjust accordingly.
/* Usage of TREE_LANG_FLAG_?:
0: BINFO_MARKED (BINFO nodes).
COMPOUND_STMT_NO_SCOPE (in COMPOUND_STMT).
+ EXPR_STMT_ASSIGNS_THIS (in EXPR_STMT).
NEW_EXPR_USE_GLOBAL (in NEW_EXPR).
DELETE_EXPR_USE_GLOBAL (in DELETE_EXPR).
LOOKUP_EXPR_GLOBAL (in LOOKUP_EXPR).
INHERITED_VALUE_BINDING_P (in CPLUS_BINDING)
BASELINK_P (in TREE_LIST)
ICS_ELLIPSIS_FLAG (in _CONV)
+ STMT_IS_FULL_EXPR_P (in _STMT)
2: IDENTIFIER_OPNAME_P.
BINFO_VBASE_MARKED.
BINFO_FIELDS_MARKED.
TYPE_VIRTUAL_P.
ICS_THIS_FLAG (in _CONV)
- BINDING_HAS_LEVEL_P (In CPLUS_BINDING)
+ STMT_LINENO_FOR_FN_P (in _STMT)
+ BINDING_HAS_LEVEL_P (in CPLUS_BINDING)
3: TYPE_USES_VIRTUAL_BASECLASSES (in a class TYPE).
BINFO_VTABLE_PATH_MARKED.
BINFO_PUSHDECLS_MARKED.
constructor call, rather than an ordinary function call. */
#define AGGR_INIT_VIA_CTOR_P(NODE) TREE_LANG_FLAG_0 (NODE)
+/* Nonzero if this statement contained the first assigned to `this' in
+ the current function. (Of course, one cannot assign to `this' in
+ ANSI/ISO C++, but we still support assignments to this with
+ -fthis-is-variable.) */
+#define EXPR_STMT_ASSIGNS_THIS(NODE) TREE_LANG_FLAG_0 ((NODE))
+
+/* Nonzero if this statement should be considered a full-expression. */
+#define STMT_IS_FULL_EXPR_P(NODE) TREE_LANG_FLAG_1 ((NODE))
+
/* The TYPE_MAIN_DECL for a class template type is a TYPE_DECL, not a
TEMPLATE_DECL. This macro determines whether or not a given class
type is really a template type, as opposed to an instantiation or
#define ASM_VOLATILE_P(NODE) \
(ASM_CV_QUAL ((NODE)) != NULL_TREE)
-/* The line-number at which a statement began. */
+/* The line-number at which a statement began. But if
+ STMT_LINENO_FOR_FN_P does holds, then this macro gives the
+ line number for the end of the current function instead. */
#define STMT_LINENO(NODE) \
(TREE_COMPLEXITY ((NODE)))
+/* If non-zero, the STMT_LINENO for NODE is the line at which the
+ function ended. */
+#define STMT_LINENO_FOR_FN_P(NODE) \
+ (TREE_LANG_FLAG_2 ((NODE)))
+
/* The parameters for a call-declarator. */
#define CALL_DECLARATOR_PARMS(NODE) \
(TREE_PURPOSE (TREE_OPERAND ((NODE), 1)))
extern void expand_body PROTO((tree));
extern void begin_stmt_tree PROTO((tree));
extern void finish_stmt_tree PROTO((tree));
+extern void prep_stmt PROTO((tree));
/* Non-zero if we are presently building a statement tree, rather
than expanding each statement as we encounter it. */
-#define building_stmt_tree() \
- (processing_template_decl || !expanding_p)
+#define building_stmt_tree() \
+ (current_function && (processing_template_decl || !expanding_p))
/* in spew.c */
extern void init_spew PROTO((void));
switch (TREE_CODE (t))
{
case RETURN_INIT:
+ prep_stmt (t);
finish_named_return_value
(TREE_OPERAND (t, 0),
tsubst_expr (TREE_OPERAND (t, 1), args, /*complain=*/1, in_decl));
break;
case CTOR_INITIALIZER:
+ prep_stmt (t);
current_member_init_list
= tsubst_expr_values (TREE_OPERAND (t, 0), args);
current_base_init_list
break;
case RETURN_STMT:
- lineno = STMT_LINENO (t);
+ prep_stmt (t);
finish_return_stmt (tsubst_expr (RETURN_EXPR (t),
args, complain, in_decl));
break;
case EXPR_STMT:
- lineno = STMT_LINENO (t);
+ prep_stmt (t);
+ /* If we're doing tsubst'ing, then we should not yet have done
+ semantic analysisy, so we should not know that this statement
+ assigns to the `this' pointer. */
+ my_friendly_assert (EXPR_STMT_ASSIGNS_THIS (t) == 0,
+ 19990831);
finish_expr_stmt (tsubst_expr (EXPR_STMT_EXPR (t),
args, complain, in_decl));
break;
tree decl;
tree init;
- lineno = STMT_LINENO (t);
+ prep_stmt (t);
decl = DECL_STMT_DECL (t);
if (TREE_CODE (decl) == LABEL_DECL)
finish_label_decl (DECL_NAME (decl));
case FOR_STMT:
{
tree tmp;
- lineno = STMT_LINENO (t);
+ prep_stmt (t);
stmt = begin_for_stmt ();
for (tmp = FOR_INIT_STMT (t); tmp; tmp = TREE_CHAIN (tmp))
case WHILE_STMT:
{
- lineno = STMT_LINENO (t);
+ prep_stmt (t);
stmt = begin_while_stmt ();
finish_while_stmt_cond (tsubst_expr (WHILE_COND (t),
args, complain, in_decl),
case DO_STMT:
{
- lineno = STMT_LINENO (t);
+ prep_stmt (t);
stmt = begin_do_stmt ();
tsubst_expr (DO_BODY (t), args, complain, in_decl);
finish_do_body (stmt);
{
tree tmp;
- lineno = STMT_LINENO (t);
+ prep_stmt (t);
stmt = begin_if_stmt ();
finish_if_stmt_cond (tsubst_expr (IF_COND (t),
args, complain, in_decl),
{
tree substmt;
- lineno = STMT_LINENO (t);
+ prep_stmt (t);
stmt = begin_compound_stmt (COMPOUND_STMT_NO_SCOPE (t));
for (substmt = COMPOUND_BODY (t);
substmt != NULL_TREE;
break;
case BREAK_STMT:
- lineno = STMT_LINENO (t);
+ prep_stmt (t);
finish_break_stmt ();
break;
case CONTINUE_STMT:
- lineno = STMT_LINENO (t);
+ prep_stmt (t);
finish_continue_stmt ();
break;
{
tree val;
- lineno = STMT_LINENO (t);
+ prep_stmt (t);
stmt = begin_switch_stmt ();
val = tsubst_expr (SWITCH_COND (t), args, complain, in_decl);
finish_switch_cond (val, stmt);
break;
case CASE_LABEL:
+ prep_stmt (t);
finish_case_label (tsubst_expr (CASE_LOW (t), args, complain, in_decl),
tsubst_expr (CASE_HIGH (t), args, complain, in_decl));
break;
break;
case GOTO_STMT:
- lineno = STMT_LINENO (t);
+ prep_stmt (t);
t = GOTO_DESTINATION (t);
if (TREE_CODE (t) != LABEL_DECL)
/* Computed goto's must be tsubst'd into. On the other hand,
break;
case ASM_STMT:
- lineno = STMT_LINENO (t);
+ prep_stmt (t);
finish_asm_stmt (ASM_CV_QUAL (t),
tsubst_expr (ASM_STRING (t), args, complain, in_decl),
tsubst_expr (ASM_OUTPUTS (t), args, complain, in_decl),
break;
case TRY_BLOCK:
- lineno = STMT_LINENO (t);
+ prep_stmt (t);
stmt = begin_try_block ();
tsubst_expr (TRY_STMTS (t), args, complain, in_decl);
finish_try_block (stmt);
break;
case HANDLER:
- lineno = STMT_LINENO (t);
+ prep_stmt (t);
stmt = begin_handler ();
if (HANDLER_PARMS (t))
expand_start_catch_block
break;
case TAG_DEFN:
- lineno = STMT_LINENO (t);
+ prep_stmt (t);
t = TREE_TYPE (t);
if (TREE_CODE (t) == ENUMERAL_TYPE)
tsubst (t, args, complain, NULL_TREE);
}
void
-add_tree (t)
- tree t;
-{
- last_tree = TREE_CHAIN (last_tree) = t;
-}
-
-
-void
begin_tree ()
{
if (current_function)
static void expand_stmts PROTO((tree));
static void do_pushlevel PROTO((void));
static tree do_poplevel PROTO((void));
+static void finish_expr_stmt_real PROTO((tree, int));
static tree expand_cond PROTO((tree));
/* When parsing a template, LAST_TREE contains the last statement
substmt = cond; \
} while (0)
-/* Finish an expression-statement, whose EXPRESSION is as indicated. */
+/* T is a statement. Add it to the statement-tree. */
-void
-finish_expr_stmt (expr)
+void
+add_tree (t)
+ tree t;
+{
+ /* Add T to the statement-tree. */
+ last_tree = TREE_CHAIN (last_tree) = t;
+
+ /* When we expand a statement-tree, we must know whether or not the
+ statements are full-expresions. We record that fact here. */
+ if (building_stmt_tree ())
+ STMT_IS_FULL_EXPR_P (last_tree) = stmts_are_full_exprs_p;
+}
+
+/* Finish an expression-statement, whose EXPRESSION is as indicated.
+ If ASSIGNED_THIS is non-zero, then this statement just assigned to
+ the `this' pointer. */
+
+static void
+finish_expr_stmt_real (expr, assigned_this)
tree expr;
+ int assigned_this;
{
if (expr != NULL_TREE)
{
}
}
+ /* If this statement assigned to the `this' pointer, record that
+ fact for finish_stmt. */
+ if (assigned_this)
+ current_function_just_assigned_this = 1;
+
finish_stmt ();
/* This was an expression-statement, so we save the type of the
last_expr_type = expr ? TREE_TYPE (expr) : NULL_TREE;
}
+/* Like finish_expr_stmt_real, but ASSIGNS_THIS is always zero. */
+
+void
+finish_expr_stmt (expr)
+ tree expr;
+{
+ finish_expr_stmt_real (expr, /*assigns_this=*/0);
+}
+
/* Begin an if-statement. Returns a newly created IF_STMT if
appropriate. */
tree if_stmt;
{
if (building_stmt_tree ())
- {
- if (last_tree != if_stmt)
- RECHAIN_STMTS_FROM_LAST (if_stmt, IF_COND (if_stmt));
- else
- IF_COND (if_stmt) = cond;
- }
+ FINISH_COND (cond, if_stmt, IF_COND (if_stmt));
else
{
emit_line_note (input_filename, lineno);
tree while_stmt;
{
if (building_stmt_tree ())
- {
- if (last_tree != while_stmt)
- RECHAIN_STMTS_FROM_LAST (while_stmt, WHILE_COND (while_stmt));
- else
- TREE_OPERAND (while_stmt, 0) = cond;
- }
+ FINISH_COND (cond, while_stmt, WHILE_COND (while_stmt));
else
{
emit_line_note (input_filename, lineno);
tree for_stmt;
{
if (building_stmt_tree ())
- {
- if (last_tree != for_stmt)
- RECHAIN_STMTS_FROM_LAST (for_stmt, FOR_COND (for_stmt));
- else
- FOR_COND (for_stmt) = cond;
- }
+ FINISH_COND (cond, for_stmt, FOR_COND (for_stmt));
else
{
emit_line_note (input_filename, lineno);
finish_stmt_tree (fn)
tree fn;
{
- DECL_SAVED_TREE (fn) = TREE_CHAIN (DECL_SAVED_TREE (fn));
+ tree stmt;
+
+ /* Remove the fake extra statement added in begin_stmt_tree. */
+ stmt = TREE_CHAIN (DECL_SAVED_TREE (fn));
+ DECL_SAVED_TREE (fn) = stmt;
+
+ /* The line-number recorded in the outermost statement in a function
+ is the line number of the end of the function. */
+ STMT_LINENO (stmt) = lineno;
+ STMT_LINENO_FOR_FN_P (stmt) = 1;
+}
+
+/* We're about to expand T, a statement. Set up appropriate context
+ for the substitution. */
+
+void
+prep_stmt (t)
+ tree t;
+{
+ if (!STMT_LINENO_FOR_FN_P (t))
+ lineno = STMT_LINENO (t);
+ stmts_are_full_exprs_p = STMT_IS_FULL_EXPR_P (t);
}
/* Some statements, like for-statements or if-statements, require a
expand_stmt (t)
tree t;
{
+ int saved_stmts_are_full_exprs_p;
+ tree rval;
+
if (t == NULL_TREE || t == error_mark_node)
return NULL_TREE;
+ /* Assume we'll have nothing to return. */
+ rval = NULL_TREE;
+
+ /* Set up context appropriately for handling this statement. */
+ saved_stmts_are_full_exprs_p = stmts_are_full_exprs_p;
+ prep_stmt (t);
+
switch (TREE_CODE (t))
{
case RETURN_STMT:
- lineno = STMT_LINENO (t);
finish_return_stmt (RETURN_EXPR (t));
break;
case EXPR_STMT:
- lineno = STMT_LINENO (t);
- finish_expr_stmt (EXPR_STMT_EXPR (t));
+ finish_expr_stmt_real (EXPR_STMT_EXPR (t),
+ EXPR_STMT_ASSIGNS_THIS (t));
break;
case DECL_STMT:
{
tree tmp;
- lineno = STMT_LINENO (t);
begin_for_stmt ();
for (tmp = FOR_INIT_STMT (t); tmp; tmp = TREE_CHAIN (tmp))
expand_stmt (tmp);
case WHILE_STMT:
{
- lineno = STMT_LINENO (t);
begin_while_stmt ();
finish_while_stmt_cond (expand_cond (WHILE_COND (t)), NULL_TREE);
expand_stmt (WHILE_BODY (t));
case DO_STMT:
{
- lineno = STMT_LINENO (t);
begin_do_stmt ();
expand_stmt (DO_BODY (t));
finish_do_body (NULL_TREE);
break;
case IF_STMT:
- lineno = STMT_LINENO (t);
begin_if_stmt ();
finish_if_stmt_cond (expand_cond (IF_COND (t)), NULL_TREE);
if (THEN_CLAUSE (t))
break;
case COMPOUND_STMT:
- lineno = STMT_LINENO (t);
begin_compound_stmt (COMPOUND_STMT_NO_SCOPE (t));
expand_stmts (COMPOUND_BODY (t));
- return finish_compound_stmt (COMPOUND_STMT_NO_SCOPE (t),
+ rval = finish_compound_stmt (COMPOUND_STMT_NO_SCOPE (t),
NULL_TREE);
+ break;
case BREAK_STMT:
- lineno = STMT_LINENO (t);
finish_break_stmt ();
break;
case CONTINUE_STMT:
- lineno = STMT_LINENO (t);
finish_continue_stmt ();
break;
{
tree cond;
- lineno = STMT_LINENO (t);
begin_switch_stmt ();
cond = expand_cond (SWITCH_COND (t));
finish_switch_cond (cond, NULL_TREE);
break;
case LABEL_STMT:
- lineno = STMT_LINENO (t);
finish_label_stmt (DECL_NAME (LABEL_STMT_LABEL (t)));
break;
case GOTO_STMT:
- lineno = STMT_LINENO (t);
if (TREE_CODE (GOTO_DESTINATION (t)) == LABEL_DECL)
finish_goto_stmt (DECL_NAME (GOTO_DESTINATION (t)));
else
break;
case ASM_STMT:
- lineno = STMT_LINENO (t);
finish_asm_stmt (ASM_CV_QUAL (t), ASM_STRING (t), ASM_OUTPUTS
(t), ASM_INPUTS (t), ASM_CLOBBERS (t));
break;
case TRY_BLOCK:
- lineno = STMT_LINENO (t);
if (CLEANUP_P (t))
{
expand_eh_region_start ();
break;
case HANDLER:
- lineno = STMT_LINENO (t);
begin_handler ();
if (HANDLER_PARMS (t))
expand_start_catch_block (DECL_STMT_DECL (HANDLER_PARMS (t)));
break;
case SUBOBJECT:
- lineno = STMT_LINENO (t);
finish_subobject (SUBOBJECT_CLEANUP (t));
break;
break;
}
- return NULL_TREE;
+ /* Restore saved state. */
+ stmts_are_full_exprs_p = saved_stmts_are_full_exprs_p;
+
+ return rval;
}
/* Generate RTL for FN. */