public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r14-8533] gccrs: foreverstack: Specialize `get` for Namespace::Labels
@ 2024-01-30 11:57 Arthur Cohen
  0 siblings, 0 replies; only message in thread
From: Arthur Cohen @ 2024-01-30 11:57 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:eec00ae27522438d6021c01501489cada87812dc

commit r14-8533-geec00ae27522438d6021c01501489cada87812dc
Author: Arthur Cohen <arthur.cohen@embecosm.com>
Date:   Mon Aug 21 16:05:22 2023 +0200

    gccrs: foreverstack: Specialize `get` for Namespace::Labels
    
    gcc/rust/ChangeLog:
    
            * resolve/rust-forever-stack.hxx: Add specific behavior for
            `ForeverStack::get` when dealing with labels.

Diff:
---
 gcc/rust/resolve/rust-forever-stack.hxx | 29 ++++++++++++++++++++++++++++-
 1 file changed, 28 insertions(+), 1 deletion(-)

diff --git a/gcc/rust/resolve/rust-forever-stack.hxx b/gcc/rust/resolve/rust-forever-stack.hxx
index 806745eb9081..211979fa9b95 100644
--- a/gcc/rust/resolve/rust-forever-stack.hxx
+++ b/gcc/rust/resolve/rust-forever-stack.hxx
@@ -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

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

only message in thread, other threads:[~2024-01-30 11:57 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-01-30 11:57 [gcc r14-8533] gccrs: foreverstack: Specialize `get` for Namespace::Labels Arthur Cohen

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).