Skip to content

Commit

Permalink
foreverstack: Add to_rib method
Browse files Browse the repository at this point in the history
gcc/rust/ChangeLog:

	* resolve/rust-forever-stack.h: New method.
	* resolve/rust-forever-stack.hxx: Likewise.
  • Loading branch information
CohenArthur committed Nov 15, 2023
1 parent 99039e9 commit a371e31
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
2 changes: 2 additions & 0 deletions gcc/rust/resolve/rust-forever-stack.h
Original file line number Diff line number Diff line change
Expand Up @@ -585,6 +585,8 @@ template <Namespace N> class ForeverStack
// 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
Expand Down
20 changes: 19 additions & 1 deletion gcc/rust/resolve/rust-forever-stack.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit a371e31

Please sign in to comment.