public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc/devel/rust/master] Get rid of lambda within AST::TypePath and provide a method to return a reference
@ 2022-06-08 11:45 Thomas Schwinge
  0 siblings, 0 replies; only message in thread
From: Thomas Schwinge @ 2022-06-08 11:45 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:66832f312a7db436110a3b08ff51eac349d5fdbf

commit 66832f312a7db436110a3b08ff51eac349d5fdbf
Author: Kadoi Takemaru <diohabara@gmail.com>
Date:   Sun Oct 31 22:22:21 2021 +0900

    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>

Diff:
---
 gcc/rust/ast/rust-path.h           | 18 ------------------
 gcc/rust/hir/rust-ast-lower-type.h | 26 ++++++++++++--------------
 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 cc2721d1393..4c437cc3646 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 f44825c2e63..c6679321e7f 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 3aa27b62ef2..5f269b14ff6 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));


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2022-06-08 11:45 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-08 11:45 [gcc/devel/rust/master] Get rid of lambda within AST::TypePath and provide a method to return a reference Thomas Schwinge

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).