diff options
author | Arthur Cohen <arthur.cohen@embecosm.com> | 2023-08-25 14:19:31 +0200 |
---|---|---|
committer | Arthur Cohen <arthur.cohen@embecosm.com> | 2024-01-30 12:36:43 +0100 |
commit | 232f94af30dc99f7618c8d7c83c0224a5750f203 (patch) | |
tree | 2c4af7e940635fc160424ac7771a8ea330228266 | |
parent | 12b2dcb088104c0682f501d0c87ba0b640bbb86b (diff) | |
download | gcc-232f94af30dc99f7618c8d7c83c0224a5750f203.zip gcc-232f94af30dc99f7618c8d7c83c0224a5750f203.tar.gz gcc-232f94af30dc99f7618c8d7c83c0224a5750f203.tar.bz2 |
gccrs: foreverstack: Add `to_rib` method
gcc/rust/ChangeLog:
* resolve/rust-forever-stack.h: New method.
* resolve/rust-forever-stack.hxx: Likewise.
-rw-r--r-- | gcc/rust/resolve/rust-forever-stack.h | 2 | ||||
-rw-r--r-- | gcc/rust/resolve/rust-forever-stack.hxx | 20 |
2 files changed, 21 insertions, 1 deletions
diff --git a/gcc/rust/resolve/rust-forever-stack.h b/gcc/rust/resolve/rust-forever-stack.h index 37277dd..a540e68 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<std::pair<Node &, std::string>> dfs (Node &starting_point, NodeId to_find); + // FIXME: Documentation + tl::optional<Rib &> 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 4e06da235..6579617 100644 --- a/gcc/rust/resolve/rust-forever-stack.hxx +++ b/gcc/rust/resolve/rust-forever-stack.hxx @@ -532,12 +532,30 @@ ForeverStack<N>::to_canonical_path (NodeId id) template <Namespace N> tl::optional<Rib &> -ForeverStack<N>::to_rib (NodeId rib_id) +ForeverStack<N>::dfs_rib (ForeverStack<N>::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 <Namespace N> +tl::optional<Rib &> +ForeverStack<N>::to_rib (NodeId rib_id) +{ + return dfs_rib (root, rib_id); +} + +template <Namespace N> void ForeverStack<N>::stream_rib (std::stringstream &stream, const Rib &rib, const std::string &next, |