]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
gccrs: forever stack: Fix resolve_path signature
authorArthur Cohen <arthur.cohen@embecosm.com>
Thu, 21 Sep 2023 13:55:03 +0000 (15:55 +0200)
committerArthur Cohen <arthur.cohen@embecosm.com>
Tue, 30 Jan 2024 11:36:43 +0000 (12:36 +0100)
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.

gcc/rust/resolve/rust-early-name-resolver-2.0.cc
gcc/rust/resolve/rust-forever-stack.h
gcc/rust/resolve/rust-forever-stack.hxx

index 57a38078f144ce2527ce87740243929914f407e6..2245ba31772f79b8d018c806056c4a9fe6527a14 100644 (file)
@@ -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
index 349d0971f6166b76051e0257da885fc86ea42ad1..ec469a9b3fa0850ff853ad2665dea4716a84e862 100644 (file)
@@ -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 ();
 
index 211979fa9b95ed430bd449d31d765356f2717f90..8f0ab66b18b7010b25c98fa375d732cfc06dbb71 100644 (file)
@@ -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 ());
     });
 }