aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Faust <david.faust@oracle.com>2021-12-13 13:43:28 -0800
committerDavid Faust <david.faust@oracle.com>2021-12-13 14:45:44 -0800
commit8c3ad67d19b7e74b1c89a6ad42f2bb0c5fb172e0 (patch)
treed015715eac87015e6bf8dd02a51a1fbc3bbcdb01
parent946069f506afba2ac03b00ad8244f1f42e0c03f1 (diff)
downloadgcc-8c3ad67d19b7e74b1c89a6ad42f2bb0c5fb172e0.zip
gcc-8c3ad67d19b7e74b1c89a6ad42f2bb0c5fb172e0.tar.gz
gcc-8c3ad67d19b7e74b1c89a6ad42f2bb0c5fb172e0.tar.bz2
Get rid of lambdas within AST::StructStruct
These constructs make working with the IR needlessly complicated for static analysis. Replace with simple for loops, and delete the old StructStruct::iterate () method. Fixes: #714
-rw-r--r--gcc/rust/ast/rust-item.h9
-rw-r--r--gcc/rust/hir/rust-ast-lower-item.h36
-rw-r--r--gcc/rust/hir/rust-ast-lower-stmt.h36
-rw-r--r--gcc/rust/resolve/rust-ast-resolve-item.h4
-rw-r--r--gcc/rust/resolve/rust-ast-resolve-stmt.h4
5 files changed, 38 insertions, 51 deletions
diff --git a/gcc/rust/ast/rust-item.h b/gcc/rust/ast/rust-item.h
index e319d74..16a9108 100644
--- a/gcc/rust/ast/rust-item.h
+++ b/gcc/rust/ast/rust-item.h
@@ -1975,15 +1975,6 @@ public:
std::vector<StructField> &get_fields () { return fields; }
const std::vector<StructField> &get_fields () const { return fields; }
- void iterate (std::function<bool (StructField &)> cb)
- {
- for (auto &field : fields)
- {
- if (!cb (field))
- return;
- }
- }
-
protected:
/* Use covariance to implement clone function as returning this object
* rather than base */
diff --git a/gcc/rust/hir/rust-ast-lower-item.h b/gcc/rust/hir/rust-ast-lower-item.h
index d4c0306..2a8c9bb 100644
--- a/gcc/rust/hir/rust-ast-lower-item.h
+++ b/gcc/rust/hir/rust-ast-lower-item.h
@@ -215,28 +215,28 @@ public:
bool is_unit = struct_decl.is_unit_struct ();
std::vector<HIR::StructField> fields;
- struct_decl.iterate ([&] (AST::StructField &field) mutable -> bool {
- HIR::Visibility vis = HIR::Visibility::create_public ();
- HIR::Type *type
- = ASTLoweringType::translate (field.get_field_type ().get ());
+ for (AST::StructField &field : struct_decl.get_fields ())
+ {
+ HIR::Visibility vis = HIR::Visibility::create_public ();
+ HIR::Type *type
+ = ASTLoweringType::translate (field.get_field_type ().get ());
- auto crate_num = mappings->get_current_crate ();
- Analysis::NodeMapping mapping (crate_num, field.get_node_id (),
- mappings->get_next_hir_id (crate_num),
- mappings->get_next_localdef_id (
- crate_num));
+ auto crate_num = mappings->get_current_crate ();
+ Analysis::NodeMapping mapping (crate_num, field.get_node_id (),
+ mappings->get_next_hir_id (crate_num),
+ mappings->get_next_localdef_id (
+ crate_num));
- HIR::StructField translated_field (mapping, field.get_field_name (),
- std::unique_ptr<HIR::Type> (type), vis,
- field.get_locus (),
- field.get_outer_attrs ());
+ HIR::StructField translated_field (mapping, field.get_field_name (),
+ std::unique_ptr<HIR::Type> (type),
+ vis, field.get_locus (),
+ field.get_outer_attrs ());
- if (struct_field_name_exists (fields, translated_field))
- return false;
+ if (struct_field_name_exists (fields, translated_field))
+ break;
- fields.push_back (std::move (translated_field));
- return true;
- });
+ fields.push_back (std::move (translated_field));
+ }
auto crate_num = mappings->get_current_crate ();
Analysis::NodeMapping mapping (crate_num, struct_decl.get_node_id (),
diff --git a/gcc/rust/hir/rust-ast-lower-stmt.h b/gcc/rust/hir/rust-ast-lower-stmt.h
index b617991..237c635 100644
--- a/gcc/rust/hir/rust-ast-lower-stmt.h
+++ b/gcc/rust/hir/rust-ast-lower-stmt.h
@@ -203,28 +203,28 @@ public:
bool is_unit = struct_decl.is_unit_struct ();
std::vector<HIR::StructField> fields;
- struct_decl.iterate ([&] (AST::StructField &field) mutable -> bool {
- HIR::Visibility vis = HIR::Visibility::create_public ();
- HIR::Type *type
- = ASTLoweringType::translate (field.get_field_type ().get ());
+ for (AST::StructField &field : struct_decl.get_fields ())
+ {
+ HIR::Visibility vis = HIR::Visibility::create_public ();
+ HIR::Type *type
+ = ASTLoweringType::translate (field.get_field_type ().get ());
- auto crate_num = mappings->get_current_crate ();
- Analysis::NodeMapping mapping (crate_num, field.get_node_id (),
- mappings->get_next_hir_id (crate_num),
- mappings->get_next_localdef_id (
- crate_num));
+ auto crate_num = mappings->get_current_crate ();
+ Analysis::NodeMapping mapping (crate_num, field.get_node_id (),
+ mappings->get_next_hir_id (crate_num),
+ mappings->get_next_localdef_id (
+ crate_num));
- HIR::StructField translated_field (mapping, field.get_field_name (),
- std::unique_ptr<HIR::Type> (type), vis,
- field.get_locus (),
- field.get_outer_attrs ());
+ HIR::StructField translated_field (mapping, field.get_field_name (),
+ std::unique_ptr<HIR::Type> (type),
+ vis, field.get_locus (),
+ field.get_outer_attrs ());
- if (struct_field_name_exists (fields, translated_field))
- return false;
+ if (struct_field_name_exists (fields, translated_field))
+ break;
- fields.push_back (std::move (translated_field));
- return true;
- });
+ fields.push_back (std::move (translated_field));
+ }
auto crate_num = mappings->get_current_crate ();
Analysis::NodeMapping mapping (crate_num, struct_decl.get_node_id (),
diff --git a/gcc/rust/resolve/rust-ast-resolve-item.h b/gcc/rust/resolve/rust-ast-resolve-item.h
index e697f1c..e8e6b8d 100644
--- a/gcc/rust/resolve/rust-ast-resolve-item.h
+++ b/gcc/rust/resolve/rust-ast-resolve-item.h
@@ -308,11 +308,9 @@ public:
if (struct_decl.has_where_clause ())
ResolveWhereClause::Resolve (struct_decl.get_where_clause ());
- struct_decl.iterate ([&] (AST::StructField &field) mutable -> bool {
+ for (AST::StructField &field : struct_decl.get_fields ())
ResolveType::go (field.get_field_type ().get (),
struct_decl.get_node_id ());
- return true;
- });
resolver->get_type_scope ().pop ();
}
diff --git a/gcc/rust/resolve/rust-ast-resolve-stmt.h b/gcc/rust/resolve/rust-ast-resolve-stmt.h
index a404365..16f5b9a 100644
--- a/gcc/rust/resolve/rust-ast-resolve-stmt.h
+++ b/gcc/rust/resolve/rust-ast-resolve-stmt.h
@@ -237,11 +237,9 @@ public:
}
}
- struct_decl.iterate ([&] (AST::StructField &field) mutable -> bool {
+ for (AST::StructField &field : struct_decl.get_fields ())
ResolveType::go (field.get_field_type ().get (),
struct_decl.get_node_id ());
- return true;
- });
resolver->get_type_scope ().pop ();
}