From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 7905) id 05FBA3858407; Tue, 30 Jan 2024 11:57:26 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 05FBA3858407 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1706615847; bh=WS4nKxJGTQuKeFUX+FwICTngmsKj27AQ2gln9A2c6oA=; h=From:To:Subject:Date:From; b=fRqe51Rn1wA79iDuslIun8s+1YCvrJVWxBhLe6/5LcptwkGQFTU/+FH2fmmTy5cqi nC613Md1r5kX17E536HWAA/DgZc/x/cJzfbVIgO4OSEEalk9wS1PEBuSgOKi/wr6ID eFFlvMH1iLbvBPKiFZYbwq5E9sWeysfrWBI2RWY0= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Arthur Cohen To: gcc-cvs@gcc.gnu.org Subject: [gcc r14-8532] gccrs: forever-stack: Fix basic get logic X-Act-Checkin: gcc X-Git-Author: Arthur Cohen X-Git-Refname: refs/heads/trunk X-Git-Oldrev: f7d8356a6ea2952574487596e66185a96a7f5d58 X-Git-Newrev: 446ab9b265554b8e20ff386466f119fcf9e11093 Message-Id: <20240130115727.05FBA3858407@sourceware.org> Date: Tue, 30 Jan 2024 11:57:26 +0000 (GMT) List-Id: https://gcc.gnu.org/g:446ab9b265554b8e20ff386466f119fcf9e11093 commit r14-8532-g446ab9b265554b8e20ff386466f119fcf9e11093 Author: Arthur Cohen 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 resolve_path (const AST::SimplePath &path); + template tl::optional 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::const_iterator; + template + using SegIterator = typename std::vector::const_iterator; Node &find_closest_module (Node &starting_point); - tl::optional - find_starting_point (const std::vector &segments, - Node &starting_point); + template + tl::optional> + find_starting_point (const std::vector &segments, Node &starting_point); - tl::optional - resolve_segments (Node &starting_point, - const std::vector &segments, - SegIterator iterator); + template + tl::optional resolve_segments (Node &starting_point, + const std::vector &segments, + SegIterator 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::update_cursor (Node &new_cursor) } template -tl::optional -ForeverStack::get (const Identifier &name) -{ - return tl::nullopt; -} - -template <> inline tl::optional -ForeverStack::get (const Identifier &name) +ForeverStack::get (const Identifier &name) { tl::optional resolved_node = tl::nullopt; @@ -226,9 +219,9 @@ ForeverStack::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::find_closest_module (Node &starting_point) /* If a the given condition is met, emit an error about misused leading path * segments */ +template 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 -tl::optional::const_iterator> -ForeverStack::find_starting_point ( - const std::vector &segments, Node &starting_point) +template +tl::optional::const_iterator> +ForeverStack::find_starting_point (const std::vector &segments, + Node &starting_point) { auto iterator = segments.begin (); @@ -357,10 +351,11 @@ ForeverStack::find_starting_point ( } template +template tl::optional::Node &> ForeverStack::resolve_segments ( - Node &starting_point, const std::vector &segments, - std::vector::const_iterator iterator) + Node &starting_point, const std::vector &segments, + typename std::vector::const_iterator iterator) { auto *current_node = &starting_point; for (; !is_last (iterator, segments); iterator++) @@ -407,9 +402,14 @@ ForeverStack::resolve_segments ( } template +template tl::optional -ForeverStack::resolve_path (const AST::SimplePath &path) +ForeverStack::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 ();