aboutsummaryrefslogtreecommitdiff
path: root/gcc/cp/constexpr.c
diff options
context:
space:
mode:
authorJason Merrill <jason@redhat.com>2021-04-02 22:20:43 -0400
committerJason Merrill <jason@redhat.com>2021-05-28 09:33:11 -0400
commit0f54cc9c63842ddfa921530cb499743cafc9b177 (patch)
tree28795686ae6679df3a4961d97f4d71e8d87d3cd1 /gcc/cp/constexpr.c
parentf7a07f5a5d8065e7f11133dd1f4ad3510ab2195b (diff)
downloadgcc-0f54cc9c63842ddfa921530cb499743cafc9b177.zip
gcc-0f54cc9c63842ddfa921530cb499743cafc9b177.tar.gz
gcc-0f54cc9c63842ddfa921530cb499743cafc9b177.tar.bz2
tree-iterator: C++11 range-for and tree_stmt_iterator
Like my recent patch to add ovl_range and lkp_range in the C++ front end, this patch adds the tsi_range adaptor for using C++11 range-based 'for' with a STATEMENT_LIST, e.g. for (tree stmt : tsi_range (stmt_list)) { ... } This also involves adding some operators to tree_stmt_iterator that are needed for range-for iterators, and should also be useful in code that uses the iterators directly. The patch updates the suitable loops in the C++ front end, but does not touch any loops elsewhere in the compiler. gcc/ChangeLog: * tree-iterator.h (struct tree_stmt_iterator): Add operator++, operator--, operator*, operator==, and operator!=. (class tsi_range): New. gcc/cp/ChangeLog: * constexpr.c (build_data_member_initialization): Use tsi_range. (build_constexpr_constructor_member_initializers): Likewise. (constexpr_fn_retval, cxx_eval_statement_list): Likewise. (potential_constant_expression_1): Likewise. * coroutines.cc (await_statement_expander): Likewise. (await_statement_walker): Likewise. * module.cc (trees_out::core_vals): Likewise. * pt.c (tsubst_expr): Likewise. * semantics.c (set_cleanup_locs): Likewise.
Diffstat (limited to 'gcc/cp/constexpr.c')
-rw-r--r--gcc/cp/constexpr.c42
1 files changed, 14 insertions, 28 deletions
diff --git a/gcc/cp/constexpr.c b/gcc/cp/constexpr.c
index 9cb761d..297f207 100644
--- a/gcc/cp/constexpr.c
+++ b/gcc/cp/constexpr.c
@@ -330,12 +330,9 @@ build_data_member_initialization (tree t, vec<constructor_elt, va_gc> **vec)
return false;
if (TREE_CODE (t) == STATEMENT_LIST)
{
- tree_stmt_iterator i;
- for (i = tsi_start (t); !tsi_end_p (i); tsi_next (&i))
- {
- if (! build_data_member_initialization (tsi_stmt (i), vec))
- return false;
- }
+ for (tree stmt : tsi_range (t))
+ if (! build_data_member_initialization (stmt, vec))
+ return false;
return true;
}
if (TREE_CODE (t) == CLEANUP_STMT)
@@ -577,10 +574,9 @@ build_constexpr_constructor_member_initializers (tree type, tree body)
break;
case STATEMENT_LIST:
- for (tree_stmt_iterator i = tsi_start (body);
- !tsi_end_p (i); tsi_next (&i))
+ for (tree stmt : tsi_range (body))
{
- body = tsi_stmt (i);
+ body = stmt;
if (TREE_CODE (body) == BIND_EXPR)
break;
}
@@ -617,10 +613,9 @@ build_constexpr_constructor_member_initializers (tree type, tree body)
}
else if (TREE_CODE (body) == STATEMENT_LIST)
{
- tree_stmt_iterator i;
- for (i = tsi_start (body); !tsi_end_p (i); tsi_next (&i))
+ for (tree stmt : tsi_range (body))
{
- ok = build_data_member_initialization (tsi_stmt (i), &vec);
+ ok = build_data_member_initialization (stmt, &vec);
if (!ok)
break;
}
@@ -675,11 +670,10 @@ constexpr_fn_retval (tree body)
{
case STATEMENT_LIST:
{
- tree_stmt_iterator i;
tree expr = NULL_TREE;
- for (i = tsi_start (body); !tsi_end_p (i); tsi_next (&i))
+ for (tree stmt : tsi_range (body))
{
- tree s = constexpr_fn_retval (tsi_stmt (i));
+ tree s = constexpr_fn_retval (stmt);
if (s == error_mark_node)
return error_mark_node;
else if (s == NULL_TREE)
@@ -5772,7 +5766,6 @@ cxx_eval_statement_list (const constexpr_ctx *ctx, tree t,
bool *non_constant_p, bool *overflow_p,
tree *jump_target)
{
- tree_stmt_iterator i;
tree local_target;
/* In a statement-expression we want to return the last value.
For empty statement expression return void_node. */
@@ -5782,9 +5775,8 @@ cxx_eval_statement_list (const constexpr_ctx *ctx, tree t,
local_target = NULL_TREE;
jump_target = &local_target;
}
- for (i = tsi_start (t); !tsi_end_p (i); tsi_next (&i))
+ for (tree stmt : tsi_range (t))
{
- tree stmt = tsi_stmt (i);
/* We've found a continue, so skip everything until we reach
the label its jumping to. */
if (continues (jump_target))
@@ -8282,16 +8274,10 @@ potential_constant_expression_1 (tree t, bool want_rval, bool strict, bool now,
}
case STATEMENT_LIST:
- {
- tree_stmt_iterator i;
- for (i = tsi_start (t); !tsi_end_p (i); tsi_next (&i))
- {
- if (!RECUR (tsi_stmt (i), any))
- return false;
- }
- return true;
- }
- break;
+ for (tree stmt : tsi_range (t))
+ if (!RECUR (stmt, any))
+ return false;
+ return true;
case MODIFY_EXPR:
if (cxx_dialect < cxx14)