There are some places inside rust-gcc.cc which are candidates
to use range for instead of iterators directly. This changes
the locations I saw and makes the code slightly more readable.
gcc/rust/ChangeLog:
PR rust/119341
* rust-gcc.cc (function_type): Use range fors.
(function_type_variadic): Likewise.
(fill_in_fields): Likewise.
(statement_list): Likewise.
(block): Likewise.
(block_add_statements): Likewise.
(function_set_parameters): Likewise.
(write_global_definitions): Likewise.
Signed-off-by: Andrew Pinski <[email protected]>
---
gcc/rust/rust-gcc.cc | 56 +++++++++++++++++---------------------------
1 file changed, 21 insertions(+), 35 deletions(-)
diff --git a/gcc/rust/rust-gcc.cc b/gcc/rust/rust-gcc.cc
index f8b29bc6cf1..8a740f72513 100644
--- a/gcc/rust/rust-gcc.cc
+++ b/gcc/rust/rust-gcc.cc
@@ -478,10 +478,9 @@ function_type (const typed_identifier &receiver,
pp = &TREE_CHAIN (*pp);
}
- for (std::vector<typed_identifier>::const_iterator p = parameters.begin ();
- p != parameters.end (); ++p)
+ for (const auto &p : parameters)
{
- tree t = p->type;
+ tree t = p.type;
if (error_operand_p (t))
return error_mark_node;
*pp = tree_cons (NULL_TREE, t, NULL_TREE);
@@ -527,10 +526,9 @@ function_type_variadic (const typed_identifier &receiver,
if (receiver.type != NULL_TREE)
args[offs++] = receiver.type;
- for (std::vector<typed_identifier>::const_iterator p = parameters.begin ();
- p != parameters.end (); ++p)
+ for (const auto &p : parameters)
{
- tree t = p->type;
+ tree t = p.type;
if (error_operand_p (t))
return error_mark_node;
args[offs++] = t;
@@ -608,14 +606,13 @@ fill_in_fields (tree fill, const
std::vector<typed_identifier> &fields)
{
tree field_trees = NULL_TREE;
tree *pp = &field_trees;
- for (std::vector<typed_identifier>::const_iterator p = fields.begin ();
- p != fields.end (); ++p)
+ for (const auto &p : fields)
{
- tree name_tree = get_identifier_from_string (p->name);
- tree type_tree = p->type;
+ tree name_tree = get_identifier_from_string (p.name);
+ tree type_tree = p.type;
if (error_operand_p (type_tree))
return error_mark_node;
- tree field = build_decl (p->location, FIELD_DECL, name_tree, type_tree);
+ tree field = build_decl (p.location, FIELD_DECL, name_tree, type_tree);
DECL_CONTEXT (field) = fill;
*pp = field;
pp = &DECL_CHAIN (field);
@@ -1721,10 +1718,8 @@ tree
statement_list (const std::vector<tree> &statements)
{
tree stmt_list = NULL_TREE;
- for (std::vector<tree>::const_iterator p = statements.begin ();
- p != statements.end (); ++p)
+ for (tree t : statements)
{
- tree t = (*p);
if (error_operand_p (t))
return error_mark_node;
append_to_statement_list (t, &stmt_list);
@@ -1778,10 +1773,9 @@ block (tree fndecl, tree enclosing, const
std::vector<Bvariable *> &vars,
}
tree *pp = &BLOCK_VARS (block_tree);
- for (std::vector<Bvariable *>::const_iterator pv = vars.begin ();
- pv != vars.end (); ++pv)
+ for (Bvariable *bv : vars)
{
- *pp = (*pv)->get_decl ();
+ *pp = bv->get_decl ();
if (!error_operand_p (*pp))
pp = &DECL_CHAIN (*pp);
}
@@ -1801,10 +1795,8 @@ void
block_add_statements (tree bind_tree, const std::vector<tree> &statements)
{
tree stmt_list = NULL_TREE;
- for (std::vector<tree>::const_iterator p = statements.begin ();
- p != statements.end (); ++p)
+ for (tree s : statements)
{
- tree s = (*p);
if (!error_operand_p (s))
append_to_statement_list (s, &stmt_list);
}
@@ -2248,10 +2240,9 @@ function_set_parameters (tree function,
tree params = NULL_TREE;
tree *pp = ¶ms;
- for (std::vector<Bvariable *>::const_iterator pv = param_vars.begin ();
- pv != param_vars.end (); ++pv)
+ for (Bvariable *bv : param_vars)
{
- *pp = (*pv)->get_decl ();
+ *pp = bv->get_decl ();
gcc_assert (!error_operand_p (*pp));
pp = &DECL_CHAIN (*pp);
}
@@ -2277,10 +2268,9 @@ write_global_definitions (const std::vector<tree>
&type_decls,
// Convert all non-erroneous declarations into Gimple form.
size_t i = 0;
- for (std::vector<Bvariable *>::const_iterator p = variable_decls.begin ();
- p != variable_decls.end (); ++p)
+ for (Bvariable *bv : variable_decls)
{
- tree v = (*p)->get_decl ();
+ tree v = bv->get_decl ();
if (error_operand_p (v))
continue;
defs[i] = v;
@@ -2288,8 +2278,7 @@ write_global_definitions (const std::vector<tree>
&type_decls,
++i;
}
- for (std::vector<tree>::const_iterator p = type_decls.begin ();
- p != type_decls.end (); ++p)
+ for (tree type_tree : type_decls)
{
tree type_tree = (*p);
if (type_tree != error_mark_node && IS_TYPE_OR_DECL_P (type_tree))
@@ -2300,20 +2289,17 @@ write_global_definitions (const std::vector<tree>
&type_decls,
++i;
}
}
- for (std::vector<tree>::const_iterator p = constant_decls.begin ();
- p != constant_decls.end (); ++p)
+ for (tree t : constant_decls)
{
- if ((*p) != error_mark_node)
+ if (t != error_mark_node)
{
- defs[i] = (*p);
+ defs[i] = t;
rust_preserve_from_gc (defs[i]);
++i;
}
}
- for (std::vector<tree>::const_iterator p = function_decls.begin ();
- p != function_decls.end (); ++p)
+ for (tree decl : function_decls)
{
- tree decl = (*p);
if (decl != error_mark_node)
{
rust_preserve_from_gc (decl);
--
2.43.0