summaryrefslogtreecommitdiff
path: root/gcc/cp/semantics.c
diff options
context:
space:
mode:
authorbstarynk <bstarynk@138bc75d-0d04-0410-961f-82ee72b054a4>2011-01-14 10:15:29 +0000
committerbstarynk <bstarynk@138bc75d-0d04-0410-961f-82ee72b054a4>2011-01-14 10:15:29 +0000
commit9e7c3bcdba010a8a46d9a51d221e02222a6efc89 (patch)
treedff0563158f6cfb5a3169eea0cbb70bec200b8f0 /gcc/cp/semantics.c
parent7493a7e159c3886ea2effc5f1c5dd52adf1aac64 (diff)
downloadgcc-9e7c3bcdba010a8a46d9a51d221e02222a6efc89.tar.gz
2011-01-14 Basile Starynkevitch <basile@starynkevitch.net>
MELT branch merged with trunk rev 168776 git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/branches/melt-branch@168777 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/cp/semantics.c')
-rw-r--r--gcc/cp/semantics.c54
1 files changed, 44 insertions, 10 deletions
diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c
index aeb10fec8ac..b9775f4b909 100644
--- a/gcc/cp/semantics.c
+++ b/gcc/cp/semantics.c
@@ -827,21 +827,44 @@ finish_return_stmt (tree expr)
return r;
}
-/* Begin a for-statement. Returns a new FOR_STMT if appropriate. */
+/* Begin the scope of a for-statement or a range-for-statement.
+ Both the returned trees are to be used in a call to
+ begin_for_stmt or begin_range_for_stmt. */
tree
-begin_for_stmt (void)
+begin_for_scope (tree *init)
+{
+ tree scope = NULL_TREE;
+ if (flag_new_for_scope > 0)
+ scope = do_pushlevel (sk_for);
+
+ if (processing_template_decl)
+ *init = push_stmt_list ();
+ else
+ *init = NULL_TREE;
+
+ return scope;
+}
+
+/* Begin a for-statement. Returns a new FOR_STMT.
+ SCOPE and INIT should be the return of begin_for_scope,
+ or both NULL_TREE */
+
+tree
+begin_for_stmt (tree scope, tree init)
{
tree r;
r = build_stmt (input_location, FOR_STMT, NULL_TREE, NULL_TREE,
NULL_TREE, NULL_TREE);
- if (flag_new_for_scope > 0)
- TREE_CHAIN (r) = do_pushlevel (sk_for);
-
- if (processing_template_decl)
- FOR_INIT_STMT (r) = push_stmt_list ();
+ if (scope == NULL_TREE)
+ {
+ gcc_assert (!init);
+ scope = begin_for_scope (&init);
+ }
+ FOR_INIT_STMT (r) = init;
+ TREE_CHAIN (r) = scope;
return r;
}
@@ -925,18 +948,29 @@ finish_for_stmt (tree for_stmt)
}
/* Begin a range-for-statement. Returns a new RANGE_FOR_STMT.
+ SCOPE and INIT should be the return of begin_for_scope,
+ or both NULL_TREE .
To finish it call finish_for_stmt(). */
tree
-begin_range_for_stmt (void)
+begin_range_for_stmt (tree scope, tree init)
{
tree r;
r = build_stmt (input_location, RANGE_FOR_STMT,
NULL_TREE, NULL_TREE, NULL_TREE);
- if (flag_new_for_scope > 0)
- TREE_CHAIN (r) = do_pushlevel (sk_for);
+ if (scope == NULL_TREE)
+ {
+ gcc_assert (!init);
+ scope = begin_for_scope (&init);
+ }
+
+ /* RANGE_FOR_STMTs do not use nor save the init tree, so we
+ pop it now. */
+ if (init)
+ pop_stmt_list (init);
+ TREE_CHAIN (r) = scope;
return r;
}