Skip to content

Commit aa7435e

Browse files
committed
forever-stack: Add extra path resolution from a known NodeId.
gcc/rust/ChangeLog: * resolve/rust-forever-stack.h: Add new resolve_path function. * resolve/rust-forever-stack.hxx: Implement it.
1 parent f60bddd commit aa7435e

File tree

2 files changed

+51
-2
lines changed

2 files changed

+51
-2
lines changed

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

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -682,6 +682,11 @@ template <Namespace N> class ForeverStack
682682
const std::vector<S> &segments, ResolutionMode mode,
683683
std::function<void (const S &, NodeId)> insert_segment_resolution,
684684
std::vector<Error> &collect_errors);
685+
template <typename S>
686+
tl::optional<Rib::Definition> resolve_path (
687+
const std::vector<S> &segments, ResolutionMode mode,
688+
std::function<void (const S &, NodeId)> insert_segment_resolution,
689+
std::vector<Error> &collect_errors, NodeId starting_point_id);
685690

686691
// FIXME: Documentation
687692
tl::optional<Rib &> to_rib (NodeId rib_id);
@@ -743,9 +748,19 @@ template <Namespace N> class ForeverStack
743748
tl::optional<Node &> parent; // `None` only if the node is a root
744749
};
745750

746-
// private overload which allows specifying a starting point
751+
/**
752+
* Private overloads which allow specifying a starting point
753+
*/
754+
747755
tl::optional<Rib::Definition> get (Node &start, const Identifier &name);
748756

757+
template <typename S>
758+
tl::optional<Rib::Definition> resolve_path (
759+
const std::vector<S> &segments, ResolutionMode mode,
760+
std::function<void (const S &, NodeId)> insert_segment_resolution,
761+
std::vector<Error> &collect_errors,
762+
std::reference_wrapper<Node> starting_point);
763+
749764
/* Should we keep going upon seeing a Rib? */
750765
enum class KeepGoing
751766
{
@@ -777,6 +792,7 @@ template <Namespace N> class ForeverStack
777792
* resolution
778793
*/
779794
Node lang_prelude;
795+
780796
/*
781797
* The extern prelude, used for resolving external crates
782798
*/

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

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -647,17 +647,50 @@ ForeverStack<N>::resolve_final_segment (Node &final_node, std::string &seg_name,
647647
return final_node.rib.get (seg_name);
648648
}
649649

650+
template <Namespace N>
651+
template <typename S>
652+
tl::optional<Rib::Definition>
653+
ForeverStack<N>::resolve_path (
654+
const std::vector<S> &segments, ResolutionMode mode,
655+
std::function<void (const S &, NodeId)> insert_segment_resolution,
656+
std::vector<Error> &collect_errors, NodeId starting_point_id)
657+
{
658+
auto starting_point = dfs_node (root, starting_point_id);
659+
660+
// We may have a prelude, but haven't visited it yet and thus it's not in our
661+
// nodes
662+
if (!starting_point)
663+
return tl::nullopt;
664+
665+
return resolve_path (segments, mode, insert_segment_resolution,
666+
collect_errors, *starting_point);
667+
}
668+
650669
template <Namespace N>
651670
template <typename S>
652671
tl::optional<Rib::Definition>
653672
ForeverStack<N>::resolve_path (
654673
const std::vector<S> &segments, ResolutionMode mode,
655674
std::function<void (const S &, NodeId)> insert_segment_resolution,
656675
std::vector<Error> &collect_errors)
676+
{
677+
std::reference_wrapper<Node> starting_point = cursor ();
678+
679+
return resolve_path (segments, mode, insert_segment_resolution,
680+
collect_errors, starting_point);
681+
}
682+
683+
template <Namespace N>
684+
template <typename S>
685+
tl::optional<Rib::Definition>
686+
ForeverStack<N>::resolve_path (
687+
const std::vector<S> &segments, ResolutionMode mode,
688+
std::function<void (const S &, NodeId)> insert_segment_resolution,
689+
std::vector<Error> &collect_errors,
690+
std::reference_wrapper<Node> starting_point)
657691
{
658692
rust_assert (!segments.empty ());
659693

660-
std::reference_wrapper<Node> starting_point = cursor ();
661694
switch (mode)
662695
{
663696
case ResolutionMode::Normal:

0 commit comments

Comments
 (0)