aboutsummaryrefslogtreecommitdiff
path: root/gcc/rust/resolve/rust-forever-stack.hxx
diff options
context:
space:
mode:
authorArthur Cohen <arthur.cohen@embecosm.com>2023-08-21 16:05:22 +0200
committerArthur Cohen <arthur.cohen@embecosm.com>2024-01-30 12:36:42 +0100
commiteec00ae27522438d6021c01501489cada87812dc (patch)
treecf7443b926fa7fea43dc1ab3d5b2f4d1cc638881 /gcc/rust/resolve/rust-forever-stack.hxx
parent446ab9b265554b8e20ff386466f119fcf9e11093 (diff)
downloadgcc-eec00ae27522438d6021c01501489cada87812dc.zip
gcc-eec00ae27522438d6021c01501489cada87812dc.tar.gz
gcc-eec00ae27522438d6021c01501489cada87812dc.tar.bz2
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.
Diffstat (limited to 'gcc/rust/resolve/rust-forever-stack.hxx')
-rw-r--r--gcc/rust/resolve/rust-forever-stack.hxx29
1 files changed, 28 insertions, 1 deletions
diff --git a/gcc/rust/resolve/rust-forever-stack.hxx b/gcc/rust/resolve/rust-forever-stack.hxx
index 806745e..211979f 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