From: Arthur Cohen Date: Mon, 21 Aug 2023 14:05:22 +0000 (+0200) Subject: gccrs: foreverstack: Specialize `get` for Namespace::Labels X-Git-Tag: basepoints/gcc-15~1606 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=eec00ae27522438d6021c01501489cada87812dc;p=thirdparty%2Fgcc.git 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 --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::update_cursor (Node &new_cursor) } template -inline tl::optional +tl::optional ForeverStack::get (const Identifier &name) { tl::optional resolved_node = tl::nullopt; @@ -234,6 +234,33 @@ ForeverStack::get (const Identifier &name) return resolved_node; } +template <> +tl::optional inline ForeverStack::get ( + const Identifier &name) +{ + tl::optional resolved_node = tl::nullopt; + + reverse_iter ([&resolved_node, &name] (Node ¤t) { + // 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 static bool