]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
gccrs: foreverstack: Specialize `get` for Namespace::Labels
authorArthur Cohen <arthur.cohen@embecosm.com>
Mon, 21 Aug 2023 14:05:22 +0000 (16:05 +0200)
committerArthur Cohen <arthur.cohen@embecosm.com>
Tue, 30 Jan 2024 11:36:42 +0000 (12:36 +0100)
gcc/rust/ChangeLog:

* resolve/rust-forever-stack.hxx: Add specific behavior for
`ForeverStack::get` when dealing with labels.

gcc/rust/resolve/rust-forever-stack.hxx

index 806745eb9081e8d80f86c9459fe28b7fd9ba4f06..211979fa9b95ed430bd449d31d765356f2717f90 100644 (file)
@@ -208,7 +208,7 @@ ForeverStack<N>::update_cursor (Node &new_cursor)
 }
 
 template <Namespace N>
-inline tl::optional<NodeId>
+tl::optional<NodeId>
 ForeverStack<N>::get (const Identifier &name)
 {
   tl::optional<NodeId> resolved_node = tl::nullopt;
@@ -234,6 +234,33 @@ ForeverStack<N>::get (const Identifier &name)
   return resolved_node;
 }
 
+template <>
+tl::optional<NodeId> inline ForeverStack<Namespace::Labels>::get (
+  const Identifier &name)
+{
+  tl::optional<NodeId> resolved_node = tl::nullopt;
+
+  reverse_iter ([&resolved_node, &name] (Node &current) {
+    // looking up for labels cannot go through function ribs
+    // TODO: What other ribs?
+    if (current.rib.kind == Rib::Kind::Function)
+      return KeepGoing::No;
+
+    auto candidate = current.rib.get (name.as_string ());
+
+    // FIXME: Factor this in a function with the generic `get`
+    return candidate.map_or (
+      [&resolved_node] (NodeId found) {
+       resolved_node = found;
+
+       return KeepGoing::No;
+      },
+      KeepGoing::Yes);
+  });
+
+  return resolved_node;
+}
+
 /* Check if an iterator points to the last element */
 template <typename I, typename C>
 static bool