From: Arthur Cohen <[email protected]>
gcc/rust/ChangeLog:
* resolve/rust-forever-stack.h: Add new resolve_path function.
* resolve/rust-forever-stack.hxx: Implement it.
---
This change was merged into the gccrs repository and is posted here for
upstream visibility and potential drive-by review, as requested by GCC
release managers.
Each commit email contains a link to its details on github from where you can
find the Pull-Request and associated discussions.
Commit on github:
https://github.com/Rust-GCC/gccrs/commit/316b07d6e984af3c4fcf86f7accde20ec84cd52c
The commit has been mentioned in the following pull-request(s):
- https://github.com/Rust-GCC/gccrs/pull/4149
gcc/rust/resolve/rust-forever-stack.h | 18 ++++++++++++-
gcc/rust/resolve/rust-forever-stack.hxx | 35 ++++++++++++++++++++++++-
2 files changed, 51 insertions(+), 2 deletions(-)
diff --git a/gcc/rust/resolve/rust-forever-stack.h
b/gcc/rust/resolve/rust-forever-stack.h
index fb265582a..2a88df7b9 100644
--- a/gcc/rust/resolve/rust-forever-stack.h
+++ b/gcc/rust/resolve/rust-forever-stack.h
@@ -682,6 +682,11 @@ public:
const std::vector<S> &segments, ResolutionMode mode,
std::function<void (const S &, NodeId)> insert_segment_resolution,
std::vector<Error> &collect_errors);
+ template <typename S>
+ tl::optional<Rib::Definition> resolve_path (
+ const std::vector<S> &segments, ResolutionMode mode,
+ std::function<void (const S &, NodeId)> insert_segment_resolution,
+ std::vector<Error> &collect_errors, NodeId starting_point_id);
// FIXME: Documentation
tl::optional<Rib &> to_rib (NodeId rib_id);
@@ -743,9 +748,19 @@ private:
tl::optional<Node &> parent; // `None` only if the node is a root
};
- // private overload which allows specifying a starting point
+ /**
+ * Private overloads which allow specifying a starting point
+ */
+
tl::optional<Rib::Definition> get (Node &start, const Identifier &name);
+ template <typename S>
+ tl::optional<Rib::Definition> resolve_path (
+ const std::vector<S> &segments, ResolutionMode mode,
+ std::function<void (const S &, NodeId)> insert_segment_resolution,
+ std::vector<Error> &collect_errors,
+ std::reference_wrapper<Node> starting_point);
+
/* Should we keep going upon seeing a Rib? */
enum class KeepGoing
{
@@ -777,6 +792,7 @@ private:
* resolution
*/
Node lang_prelude;
+
/*
* The extern prelude, used for resolving external crates
*/
diff --git a/gcc/rust/resolve/rust-forever-stack.hxx
b/gcc/rust/resolve/rust-forever-stack.hxx
index cd13af015..bd35d6c4e 100644
--- a/gcc/rust/resolve/rust-forever-stack.hxx
+++ b/gcc/rust/resolve/rust-forever-stack.hxx
@@ -647,6 +647,25 @@ ForeverStack<N>::resolve_final_segment (Node &final_node,
std::string &seg_name,
return final_node.rib.get (seg_name);
}
+template <Namespace N>
+template <typename S>
+tl::optional<Rib::Definition>
+ForeverStack<N>::resolve_path (
+ const std::vector<S> &segments, ResolutionMode mode,
+ std::function<void (const S &, NodeId)> insert_segment_resolution,
+ std::vector<Error> &collect_errors, NodeId starting_point_id)
+{
+ auto starting_point = dfs_node (root, starting_point_id);
+
+ // We may have a prelude, but haven't visited it yet and thus it's not in our
+ // nodes
+ if (!starting_point)
+ return tl::nullopt;
+
+ return resolve_path (segments, mode, insert_segment_resolution,
+ collect_errors, *starting_point);
+}
+
template <Namespace N>
template <typename S>
tl::optional<Rib::Definition>
@@ -654,10 +673,24 @@ ForeverStack<N>::resolve_path (
const std::vector<S> &segments, ResolutionMode mode,
std::function<void (const S &, NodeId)> insert_segment_resolution,
std::vector<Error> &collect_errors)
+{
+ std::reference_wrapper<Node> starting_point = cursor ();
+
+ return resolve_path (segments, mode, insert_segment_resolution,
+ collect_errors, starting_point);
+}
+
+template <Namespace N>
+template <typename S>
+tl::optional<Rib::Definition>
+ForeverStack<N>::resolve_path (
+ const std::vector<S> &segments, ResolutionMode mode,
+ std::function<void (const S &, NodeId)> insert_segment_resolution,
+ std::vector<Error> &collect_errors,
+ std::reference_wrapper<Node> starting_point)
{
rust_assert (!segments.empty ());
- std::reference_wrapper<Node> starting_point = cursor ();
switch (mode)
{
case ResolutionMode::Normal:
--
2.52.0