public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r14-8532] gccrs: forever-stack: Fix basic get logic
@ 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:446ab9b265554b8e20ff386466f119fcf9e11093
commit r14-8532-g446ab9b265554b8e20ff386466f119fcf9e11093
Author: Arthur Cohen <arthur.cohen@embecosm.com>
Date: Mon Aug 21 15:52:06 2023 +0200
gccrs: forever-stack: Fix basic get logic
gcc/rust/ChangeLog:
* resolve/rust-forever-stack.h: Improve resolve_path API.
* resolve/rust-forever-stack.hxx: Likewise and fix implementation.
Diff:
---
gcc/rust/resolve/rust-forever-stack.h | 19 +++++++++--------
gcc/rust/resolve/rust-forever-stack.hxx | 38 ++++++++++++++++-----------------
2 files changed, 29 insertions(+), 28 deletions(-)
diff --git a/gcc/rust/resolve/rust-forever-stack.h b/gcc/rust/resolve/rust-forever-stack.h
index 7ee084919870..349d0971f616 100644
--- a/gcc/rust/resolve/rust-forever-stack.h
+++ b/gcc/rust/resolve/rust-forever-stack.h
@@ -473,7 +473,7 @@ public:
* @return a valid option with the NodeId if the path is present in the
* current map, an empty one otherwise.
*/
- tl::optional<NodeId> resolve_path (const AST::SimplePath &path);
+ template <typename P> tl::optional<NodeId> resolve_path (const P &path);
std::string as_debug_string ();
@@ -550,18 +550,19 @@ private:
/* Helper types and functions for `resolve_path` */
- using SegIterator = std::vector<AST::SimplePathSegment>::const_iterator;
+ template <typename S>
+ using SegIterator = typename std::vector<S>::const_iterator;
Node &find_closest_module (Node &starting_point);
- tl::optional<SegIterator>
- find_starting_point (const std::vector<AST::SimplePathSegment> &segments,
- Node &starting_point);
+ template <typename S>
+ tl::optional<SegIterator<S>>
+ find_starting_point (const std::vector<S> &segments, Node &starting_point);
- tl::optional<Node &>
- resolve_segments (Node &starting_point,
- const std::vector<AST::SimplePathSegment> &segments,
- SegIterator iterator);
+ template <typename S>
+ tl::optional<Node &> resolve_segments (Node &starting_point,
+ const std::vector<S> &segments,
+ SegIterator<S> iterator);
};
} // namespace Resolver2_0
diff --git a/gcc/rust/resolve/rust-forever-stack.hxx b/gcc/rust/resolve/rust-forever-stack.hxx
index 5acdf06c770c..806745eb9081 100644
--- a/gcc/rust/resolve/rust-forever-stack.hxx
+++ b/gcc/rust/resolve/rust-forever-stack.hxx
@@ -208,15 +208,8 @@ ForeverStack<N>::update_cursor (Node &new_cursor)
}
template <Namespace N>
-tl::optional<NodeId>
-ForeverStack<N>::get (const Identifier &name)
-{
- return tl::nullopt;
-}
-
-template <>
inline tl::optional<NodeId>
-ForeverStack<Namespace::Macros>::get (const Identifier &name)
+ForeverStack<N>::get (const Identifier &name)
{
tl::optional<NodeId> resolved_node = tl::nullopt;
@@ -226,9 +219,9 @@ ForeverStack<Namespace::Macros>::get (const Identifier &name)
return candidate.map_or (
[&resolved_node] (NodeId found) {
- // macro resolving does not need to care about various ribs - they are
- // available from all contexts if defined in the current scope, or an
- // outermore one. so if we do have a candidate, we can return it
+ // for most namespaces, we do not need to care about various ribs - they
+ // are available from all contexts if defined in the current scope, or
+ // an outermore one. so if we do have a candidate, we can return it
// directly and stop iterating
resolved_node = found;
@@ -278,9 +271,9 @@ ForeverStack<N>::find_closest_module (Node &starting_point)
/* If a the given condition is met, emit an error about misused leading path
* segments */
+template <typename S>
static inline bool
-check_leading_kw_at_start (const AST::SimplePathSegment &segment,
- bool condition)
+check_leading_kw_at_start (const S &segment, bool condition)
{
if (condition)
rust_error_at (
@@ -297,9 +290,10 @@ check_leading_kw_at_start (const AST::SimplePathSegment &segment,
// `super` segment, we go back to the cursor's parent until we reach the
// correct one or the root.
template <Namespace N>
-tl::optional<std::vector<AST::SimplePathSegment>::const_iterator>
-ForeverStack<N>::find_starting_point (
- const std::vector<AST::SimplePathSegment> &segments, Node &starting_point)
+template <typename S>
+tl::optional<typename std::vector<S>::const_iterator>
+ForeverStack<N>::find_starting_point (const std::vector<S> &segments,
+ Node &starting_point)
{
auto iterator = segments.begin ();
@@ -357,10 +351,11 @@ ForeverStack<N>::find_starting_point (
}
template <Namespace N>
+template <typename S>
tl::optional<typename ForeverStack<N>::Node &>
ForeverStack<N>::resolve_segments (
- Node &starting_point, const std::vector<AST::SimplePathSegment> &segments,
- std::vector<AST::SimplePathSegment>::const_iterator iterator)
+ Node &starting_point, const std::vector<S> &segments,
+ typename std::vector<S>::const_iterator iterator)
{
auto *current_node = &starting_point;
for (; !is_last (iterator, segments); iterator++)
@@ -407,9 +402,14 @@ ForeverStack<N>::resolve_segments (
}
template <Namespace N>
+template <typename P>
tl::optional<NodeId>
-ForeverStack<N>::resolve_path (const AST::SimplePath &path)
+ForeverStack<N>::resolve_path (const P &path)
{
+ // if there's only one segment, we just use `get`
+ if (path.get_segments ().size () == 1)
+ return get (path.get_final_segment ().as_string ());
+
auto starting_point = cursor ();
auto &segments = path.get_segments ();
^ 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-8532] gccrs: forever-stack: Fix basic get logic 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).