]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
gccrs: foreverstack: Add `to_rib` method
authorArthur Cohen <arthur.cohen@embecosm.com>
Fri, 25 Aug 2023 12:19:31 +0000 (14:19 +0200)
committerArthur Cohen <arthur.cohen@embecosm.com>
Tue, 30 Jan 2024 11:36:43 +0000 (12:36 +0100)
gcc/rust/ChangeLog:

* resolve/rust-forever-stack.h: New method.
* resolve/rust-forever-stack.hxx: Likewise.

gcc/rust/resolve/rust-forever-stack.h
gcc/rust/resolve/rust-forever-stack.hxx

index 37277ddb3ada39f9953c677177afc0fa71e51b0b..a540e682e5b09e56e9f7597191a95f259f74bcd6 100644 (file)
@@ -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
index 4e06da235bfaaf5e22f7e14636b2a38ec9d4421f..65796172b08a54e904926faddb924b28679c209d 100644 (file)
@@ -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,