diff options
author | David Faust <david.faust@oracle.com> | 2021-12-13 13:20:02 -0800 |
---|---|---|
committer | David Faust <david.faust@oracle.com> | 2021-12-13 14:45:44 -0800 |
commit | 946069f506afba2ac03b00ad8244f1f42e0c03f1 (patch) | |
tree | 0abcb908640348e6128499e0ad99715c12258f93 /gcc | |
parent | e43a784dc89030941b0cc43309541970c59a723c (diff) | |
download | gcc-946069f506afba2ac03b00ad8244f1f42e0c03f1.zip gcc-946069f506afba2ac03b00ad8244f1f42e0c03f1.tar.gz gcc-946069f506afba2ac03b00ad8244f1f42e0c03f1.tar.bz2 |
Get rid of lambdas within AST::TupleStruct
These constructs make working with the IR needlessly complicated for
static analysis. Replace with simple for loops, and delete the old
TupleStruct::iterate () method.
Fixes: #715
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/rust/ast/rust-item.h | 9 | ||||
-rw-r--r-- | gcc/rust/hir/rust-ast-lower-item.h | 34 | ||||
-rw-r--r-- | gcc/rust/hir/rust-ast-lower-stmt.h | 34 | ||||
-rw-r--r-- | gcc/rust/resolve/rust-ast-resolve-item.h | 4 | ||||
-rw-r--r-- | gcc/rust/resolve/rust-ast-resolve-stmt.h | 4 |
5 files changed, 36 insertions, 49 deletions
diff --git a/gcc/rust/ast/rust-item.h b/gcc/rust/ast/rust-item.h index f952dcc..e319d74 100644 --- a/gcc/rust/ast/rust-item.h +++ b/gcc/rust/ast/rust-item.h @@ -2110,15 +2110,6 @@ public: std::vector<TupleField> &get_fields () { return fields; } const std::vector<TupleField> &get_fields () const { return fields; } - void iterate (std::function<bool (TupleField &)> 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 697e98a..d4c0306 100644 --- a/gcc/rust/hir/rust-ast-lower-item.h +++ b/gcc/rust/hir/rust-ast-lower-item.h @@ -154,24 +154,24 @@ public: HIR::Visibility vis = HIR::Visibility::create_public (); std::vector<HIR::TupleField> fields; - struct_decl.iterate ([&] (AST::TupleField &field) mutable -> bool { - 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)); + for (AST::TupleField &field : struct_decl.get_fields ()) + { + HIR::Visibility vis = HIR::Visibility::create_public (); + HIR::Type *type + = ASTLoweringType::translate (field.get_field_type ().get ()); - HIR::TupleField translated_field (mapping, - std::unique_ptr<HIR::Type> (type), vis, - field.get_locus (), - field.get_outer_attrs ()); - fields.push_back (std::move (translated_field)); - return true; - }); + 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::TupleField translated_field (mapping, + std::unique_ptr<HIR::Type> (type), + vis, field.get_locus (), + field.get_outer_attrs ()); + 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 eab0922..b617991 100644 --- a/gcc/rust/hir/rust-ast-lower-stmt.h +++ b/gcc/rust/hir/rust-ast-lower-stmt.h @@ -151,24 +151,24 @@ public: HIR::Visibility vis = HIR::Visibility::create_public (); std::vector<HIR::TupleField> fields; - struct_decl.iterate ([&] (AST::TupleField &field) mutable -> bool { - 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)); + for (AST::TupleField &field : struct_decl.get_fields ()) + { + HIR::Visibility vis = HIR::Visibility::create_public (); + HIR::Type *type + = ASTLoweringType::translate (field.get_field_type ().get ()); - HIR::TupleField translated_field (mapping, - std::unique_ptr<HIR::Type> (type), vis, - field.get_locus (), - field.get_outer_attrs ()); - fields.push_back (std::move (translated_field)); - return true; - }); + 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::TupleField translated_field (mapping, + std::unique_ptr<HIR::Type> (type), + vis, field.get_locus (), + field.get_outer_attrs ()); + 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 a4bf261..e697f1c 100644 --- a/gcc/rust/resolve/rust-ast-resolve-item.h +++ b/gcc/rust/resolve/rust-ast-resolve-item.h @@ -245,11 +245,9 @@ public: if (struct_decl.has_where_clause ()) ResolveWhereClause::Resolve (struct_decl.get_where_clause ()); - struct_decl.iterate ([&] (AST::TupleField &field) mutable -> bool { + for (AST::TupleField &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 98fcaf2..a404365 100644 --- a/gcc/rust/resolve/rust-ast-resolve-stmt.h +++ b/gcc/rust/resolve/rust-ast-resolve-stmt.h @@ -115,11 +115,9 @@ public: } } - struct_decl.iterate ([&] (AST::TupleField &field) mutable -> bool { + for (AST::TupleField &field : struct_decl.get_fields ()) ResolveType::go (field.get_field_type ().get (), struct_decl.get_node_id ()); - return true; - }); resolver->get_type_scope ().pop (); } |