public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r14-8537] gccrs: foreverstack: Add `to_rib` method
@ 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:232f94af30dc99f7618c8d7c83c0224a5750f203

commit r14-8537-g232f94af30dc99f7618c8d7c83c0224a5750f203
Author: Arthur Cohen <arthur.cohen@embecosm.com>
Date:   Fri Aug 25 14:19:31 2023 +0200

    gccrs: foreverstack: Add `to_rib` method
    
    gcc/rust/ChangeLog:
    
            * resolve/rust-forever-stack.h: New method.
            * resolve/rust-forever-stack.hxx: Likewise.

Diff:
---
 gcc/rust/resolve/rust-forever-stack.h   |  2 ++
 gcc/rust/resolve/rust-forever-stack.hxx | 20 +++++++++++++++++++-
 2 files changed, 21 insertions(+), 1 deletion(-)

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<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 4e06da235bfa..65796172b08a 100644
--- a/gcc/rust/resolve/rust-forever-stack.hxx
+++ b/gcc/rust/resolve/rust-forever-stack.hxx
@@ -532,11 +532,29 @@ 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,

^ 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-8537] gccrs: foreverstack: Add `to_rib` method 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).