diff options
author | Kadoi Takemaru <diohabara@gmail.com> | 2021-10-31 22:22:21 +0900 |
---|---|---|
committer | Kadoi Takemaru <diohabara@gmail.com> | 2021-11-01 20:05:18 +0900 |
commit | 66832f312a7db436110a3b08ff51eac349d5fdbf (patch) | |
tree | 56a34e691457a303c5b987b8d8996e16268d8228 /gcc | |
parent | ca0b06f86fd44bd6067563dcbf4a2c021f2a79a5 (diff) | |
download | gcc-66832f312a7db436110a3b08ff51eac349d5fdbf.zip gcc-66832f312a7db436110a3b08ff51eac349d5fdbf.tar.gz gcc-66832f312a7db436110a3b08ff51eac349d5fdbf.tar.bz2 |
Get rid of lambda within AST::TypePath and provide a method to return a reference
Remove lambda expressions within AST::TypePath and use get_segments() to
iterate over AST::TypePathSegment
Fixes #718
Signed-off-by: Kadoi Takemaru <diohabara@gmail.com>
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/rust/ast/rust-path.h | 18 | ||||
-rw-r--r-- | gcc/rust/hir/rust-ast-lower-type.h | 26 | ||||
-rw-r--r-- | gcc/rust/hir/rust-ast-lower.cc | 26 |
3 files changed, 24 insertions, 46 deletions
diff --git a/gcc/rust/ast/rust-path.h b/gcc/rust/ast/rust-path.h index cc2721d..4c437cc 100644 --- a/gcc/rust/ast/rust-path.h +++ b/gcc/rust/ast/rust-path.h @@ -754,15 +754,6 @@ public: } size_t get_num_segments () const { return segments.size (); } - - void iterate_segments (std::function<bool (TypePathSegment *)> cb) - { - for (auto it = segments.begin (); it != segments.end (); it++) - { - if (!cb ((*it).get ())) - return; - } - } }; struct QualifiedPathType @@ -1029,15 +1020,6 @@ public: } Location get_locus () const override final { return locus; } - - void iterate_segments (std::function<bool (TypePathSegment *)> cb) - { - for (auto it = segments.begin (); it != segments.end (); it++) - { - if (!cb ((*it).get ())) - return; - } - } }; } // namespace AST } // namespace Rust diff --git a/gcc/rust/hir/rust-ast-lower-type.h b/gcc/rust/hir/rust-ast-lower-type.h index f44825c..c667932 100644 --- a/gcc/rust/hir/rust-ast-lower-type.h +++ b/gcc/rust/hir/rust-ast-lower-type.h @@ -62,20 +62,18 @@ public: { std::vector<std::unique_ptr<HIR::TypePathSegment>> translated_segments; - path.iterate_segments ([&] (AST::TypePathSegment *seg) mutable -> bool { - translated_segment = nullptr; - seg->accept_vis (*this); - if (translated_segment == nullptr) - { - rust_fatal_error (seg->get_locus (), - "failed to translate AST TypePathSegment"); - return false; - } - - translated_segments.push_back ( - std::unique_ptr<HIR::TypePathSegment> (translated_segment)); - return true; - }); + for (auto &seg : path.get_segments ()) + { + translated_segment = nullptr; + seg->accept_vis (*this); + if (translated_segment == nullptr) + { + rust_fatal_error (seg->get_locus (), + "failed to translate AST TypePathSegment"); + } + translated_segments.push_back ( + std::unique_ptr<HIR::TypePathSegment> (translated_segment)); + } auto crate_num = mappings->get_current_crate (); auto hirid = mappings->get_next_hir_id (crate_num); diff --git a/gcc/rust/hir/rust-ast-lower.cc b/gcc/rust/hir/rust-ast-lower.cc index 3aa27b6..5f269b1 100644 --- a/gcc/rust/hir/rust-ast-lower.cc +++ b/gcc/rust/hir/rust-ast-lower.cc @@ -490,20 +490,18 @@ ASTLowerQualifiedPathInType::visit (AST::QualifiedPathInType &path) std::unique_ptr<HIR::TypePathSegment> associated_segment (translated_segment); std::vector<std::unique_ptr<HIR::TypePathSegment> > translated_segments; - path.iterate_segments ([&] (AST::TypePathSegment *seg) mutable -> bool { - translated_segment = nullptr; - seg->accept_vis (*this); - if (translated_segment == nullptr) - { - rust_fatal_error (seg->get_locus (), - "failed to translate AST TypePathSegment"); - return false; - } - - translated_segments.push_back ( - std::unique_ptr<HIR::TypePathSegment> (translated_segment)); - return true; - }); + for (auto &seg : path.get_segments ()) + { + translated_segment = nullptr; + seg->accept_vis (*this); + if (translated_segment == nullptr) + { + rust_fatal_error (seg->get_locus (), + "failed to translte AST TypePathSegment"); + } + translated_segments.push_back ( + std::unique_ptr<HIR::TypePathSegment> (translated_segment)); + } Analysis::NodeMapping mapping (crate_num, path.get_node_id (), hirid, mappings->get_next_localdef_id (crate_num)); |