[COMMITTED,010/101] gccrs: forever stack: Fix resolve_path signature

Message ID 20240130121026.807464-13-arthur.cohen@embecosm.com
State Committed
Commit 5fd3de11508e7205e39b5fe00d8b4fd4789aeb86
Headers
Series [COMMITTED,001/101] gccrs: Add visibility to trait item |

Commit Message

Arthur Cohen Jan. 30, 2024, 12:06 p.m. UTC
  From: Arthur Cohen <arthur.cohen@embecosm.com>

gcc/rust/ChangeLog:

	* resolve/rust-forever-stack.h: Fix `ForeverStack::resolve_path`
	signature.
	* resolve/rust-forever-stack.hxx: Likewise.
	* resolve/rust-early-name-resolver-2.0.cc (Early::visit): Use new API.
	(Early::visit_attributes): Likewise.
---
 .../resolve/rust-early-name-resolver-2.0.cc     |  8 +++++---
 gcc/rust/resolve/rust-forever-stack.h           |  5 ++++-
 gcc/rust/resolve/rust-forever-stack.hxx         | 17 +++++++++--------
 3 files changed, 18 insertions(+), 12 deletions(-)
  

Patch

diff --git a/gcc/rust/resolve/rust-early-name-resolver-2.0.cc b/gcc/rust/resolve/rust-early-name-resolver-2.0.cc
index 57a38078f14..2245ba31772 100644
--- a/gcc/rust/resolve/rust-early-name-resolver-2.0.cc
+++ b/gcc/rust/resolve/rust-early-name-resolver-2.0.cc
@@ -131,7 +131,7 @@  Early::visit (AST::MacroInvocation &invoc)
   // we won't have changed `definition` from `nullopt` if there are more
   // than one segments in our path
   if (!definition.has_value ())
-    definition = ctx.macros.resolve_path (path);
+    definition = ctx.macros.resolve_path (path.get_segments ());
 
   // if the definition still does not have a value, then it's an error
   if (!definition.has_value ())
@@ -188,7 +188,8 @@  Early::visit_attributes (std::vector<AST::Attribute> &attrs)
 	  auto traits = attr.get_traits_to_derive ();
 	  for (auto &trait : traits)
 	    {
-	      auto definition = ctx.macros.resolve_path (trait.get ());
+	      auto definition
+		= ctx.macros.resolve_path (trait.get ().get_segments ());
 	      if (!definition.has_value ())
 		{
 		  // FIXME: Change to proper error message
@@ -210,7 +211,8 @@  Early::visit_attributes (std::vector<AST::Attribute> &attrs)
 		 ->lookup_builtin (name)
 		 .is_error ()) // Do not resolve builtins
 	{
-	  auto definition = ctx.macros.resolve_path (attr.get_path ());
+	  auto definition
+	    = ctx.macros.resolve_path (attr.get_path ().get_segments ());
 	  if (!definition.has_value ())
 	    {
 	      // FIXME: Change to proper error message
diff --git a/gcc/rust/resolve/rust-forever-stack.h b/gcc/rust/resolve/rust-forever-stack.h
index 349d0971f61..ec469a9b3fa 100644
--- a/gcc/rust/resolve/rust-forever-stack.h
+++ b/gcc/rust/resolve/rust-forever-stack.h
@@ -470,10 +470,13 @@  public:
   /**
    * Resolve a path to its definition in the current `ForeverStack`
    *
+   * // TODO: Add documentation for `segments`
+   *
    * @return a valid option with the NodeId if the path is present in the
    *         current map, an empty one otherwise.
    */
-  template <typename P> tl::optional<NodeId> resolve_path (const P &path);
+  template <typename S>
+  tl::optional<NodeId> resolve_path (const std::vector<S> &segments);
 
   std::string as_debug_string ();
 
diff --git a/gcc/rust/resolve/rust-forever-stack.hxx b/gcc/rust/resolve/rust-forever-stack.hxx
index 211979fa9b9..8f0ab66b18b 100644
--- a/gcc/rust/resolve/rust-forever-stack.hxx
+++ b/gcc/rust/resolve/rust-forever-stack.hxx
@@ -429,24 +429,25 @@  ForeverStack<N>::resolve_segments (
 }
 
 template <Namespace N>
-template <typename P>
+template <typename S>
 tl::optional<NodeId>
-ForeverStack<N>::resolve_path (const P &path)
+ForeverStack<N>::resolve_path (const std::vector<S> &segments)
 {
+  // TODO: What to do if segments.empty() ?
+
   // if there's only one segment, we just use `get`
-  if (path.get_segments ().size () == 1)
-    return get (path.get_final_segment ().as_string ());
+  if (segments.size () == 1)
+    return get (segments.back ().as_string ());
 
   auto starting_point = cursor ();
-  auto &segments = path.get_segments ();
 
   return find_starting_point (segments, starting_point)
     .and_then ([this, &segments, &starting_point] (
-		 std::vector<AST::SimplePathSegment>::const_iterator iterator) {
+		 typename std::vector<S>::const_iterator iterator) {
       return resolve_segments (starting_point, segments, iterator);
     })
-    .and_then ([&path] (Node final_node) {
-      return final_node.rib.get (path.get_final_segment ().as_string ());
+    .and_then ([&segments] (Node final_node) {
+      return final_node.rib.get (segments.back ().as_string ());
     });
 }