From: Arthur Cohen Date: Fri, 25 Aug 2023 12:19:31 +0000 (+0200) Subject: gccrs: foreverstack: Add `to_rib` method X-Git-Tag: basepoints/gcc-15~1602 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=232f94af30dc99f7618c8d7c83c0224a5750f203;p=thirdparty%2Fgcc.git gccrs: foreverstack: Add `to_rib` method gcc/rust/ChangeLog: * resolve/rust-forever-stack.h: New method. * resolve/rust-forever-stack.hxx: Likewise. --- diff --git a/gcc/rust/resolve/rust-forever-stack.h b/gcc/rust/resolve/rust-forever-stack.h index 37277ddb3ada..a540e682e5b0 100644 --- a/gcc/rust/resolve/rust-forever-stack.h +++ b/gcc/rust/resolve/rust-forever-stack.h @@ -585,6 +585,8 @@ private: // FIXME: Documentation tl::optional> dfs (Node &starting_point, NodeId to_find); + // FIXME: Documentation + tl::optional dfs_rib (Node &starting_point, NodeId to_find); }; } // namespace Resolver2_0 diff --git a/gcc/rust/resolve/rust-forever-stack.hxx b/gcc/rust/resolve/rust-forever-stack.hxx index 4e06da235bfa..65796172b08a 100644 --- a/gcc/rust/resolve/rust-forever-stack.hxx +++ b/gcc/rust/resolve/rust-forever-stack.hxx @@ -532,11 +532,29 @@ ForeverStack::to_canonical_path (NodeId id) template tl::optional -ForeverStack::to_rib (NodeId rib_id) +ForeverStack::dfs_rib (ForeverStack::Node &starting_point, NodeId to_find) { + if (starting_point.id == to_find) + return starting_point.rib; + + for (auto &child : starting_point.children) + { + auto candidate = dfs_rib (child.second, to_find); + + if (candidate.has_value ()) + return candidate; + } + return tl::nullopt; } +template +tl::optional +ForeverStack::to_rib (NodeId rib_id) +{ + return dfs_rib (root, rib_id); +} + template void ForeverStack::stream_rib (std::stringstream &stream, const Rib &rib,