aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArthur Cohen <arthur.cohen@embecosm.com>2023-09-21 15:55:03 +0200
committerArthur Cohen <arthur.cohen@embecosm.com>2024-01-30 12:36:43 +0100
commit5fd3de11508e7205e39b5fe00d8b4fd4789aeb86 (patch)
treea85608b1ce57b106ad848e6d3fce37275139bdcc
parenteec00ae27522438d6021c01501489cada87812dc (diff)
downloadgcc-5fd3de11508e7205e39b5fe00d8b4fd4789aeb86.zip
gcc-5fd3de11508e7205e39b5fe00d8b4fd4789aeb86.tar.gz
gcc-5fd3de11508e7205e39b5fe00d8b4fd4789aeb86.tar.bz2
gccrs: forever stack: Fix resolve_path signature
gcc/rust/ChangeLog: * resolve/rust-forever-stack.h: Fix `ForeverStack::resolve_path` signature. * resolve/rust-forever-stack.hxx: Likewise. * resolve/rust-early-name-resolver-2.0.cc (Early::visit): Use new API. (Early::visit_attributes): Likewise.
-rw-r--r--gcc/rust/resolve/rust-early-name-resolver-2.0.cc8
-rw-r--r--gcc/rust/resolve/rust-forever-stack.h5
-rw-r--r--gcc/rust/resolve/rust-forever-stack.hxx17
3 files changed, 18 insertions, 12 deletions
diff --git a/gcc/rust/resolve/rust-early-name-resolver-2.0.cc b/gcc/rust/resolve/rust-early-name-resolver-2.0.cc
index 57a3807..2245ba3 100644
--- a/gcc/rust/resolve/rust-early-name-resolver-2.0.cc
+++ b/gcc/rust/resolve/rust-early-name-resolver-2.0.cc
@@ -131,7 +131,7 @@ Early::visit (AST::MacroInvocation &invoc)
// we won't have changed `definition` from `nullopt` if there are more
// than one segments in our path
if (!definition.has_value ())
- definition = ctx.macros.resolve_path (path);
+ definition = ctx.macros.resolve_path (path.get_segments ());
// if the definition still does not have a value, then it's an error
if (!definition.has_value ())
@@ -188,7 +188,8 @@ Early::visit_attributes (std::vector<AST::Attribute> &attrs)
auto traits = attr.get_traits_to_derive ();
for (auto &trait : traits)
{
- auto definition = ctx.macros.resolve_path (trait.get ());
+ auto definition
+ = ctx.macros.resolve_path (trait.get ().get_segments ());
if (!definition.has_value ())
{
// FIXME: Change to proper error message
@@ -210,7 +211,8 @@ Early::visit_attributes (std::vector<AST::Attribute> &attrs)
->lookup_builtin (name)
.is_error ()) // Do not resolve builtins
{
- auto definition = ctx.macros.resolve_path (attr.get_path ());
+ auto definition
+ = ctx.macros.resolve_path (attr.get_path ().get_segments ());
if (!definition.has_value ())
{
// FIXME: Change to proper error message
diff --git a/gcc/rust/resolve/rust-forever-stack.h b/gcc/rust/resolve/rust-forever-stack.h
index 349d097..ec469a9 100644
--- a/gcc/rust/resolve/rust-forever-stack.h
+++ b/gcc/rust/resolve/rust-forever-stack.h
@@ -470,10 +470,13 @@ public:
/**
* Resolve a path to its definition in the current `ForeverStack`
*
+ * // TODO: Add documentation for `segments`
+ *
* @return a valid option with the NodeId if the path is present in the
* current map, an empty one otherwise.
*/
- template <typename P> tl::optional<NodeId> resolve_path (const P &path);
+ template <typename S>
+ tl::optional<NodeId> resolve_path (const std::vector<S> &segments);
std::string as_debug_string ();
diff --git a/gcc/rust/resolve/rust-forever-stack.hxx b/gcc/rust/resolve/rust-forever-stack.hxx
index 211979f..8f0ab66 100644
--- a/gcc/rust/resolve/rust-forever-stack.hxx
+++ b/gcc/rust/resolve/rust-forever-stack.hxx
@@ -429,24 +429,25 @@ ForeverStack<N>::resolve_segments (
}
template <Namespace N>
-template <typename P>
+template <typename S>
tl::optional<NodeId>
-ForeverStack<N>::resolve_path (const P &path)
+ForeverStack<N>::resolve_path (const std::vector<S> &segments)
{
+ // TODO: What to do if segments.empty() ?
+
// if there's only one segment, we just use `get`
- if (path.get_segments ().size () == 1)
- return get (path.get_final_segment ().as_string ());
+ if (segments.size () == 1)
+ return get (segments.back ().as_string ());
auto starting_point = cursor ();
- auto &segments = path.get_segments ();
return find_starting_point (segments, starting_point)
.and_then ([this, &segments, &starting_point] (
- std::vector<AST::SimplePathSegment>::const_iterator iterator) {
+ typename std::vector<S>::const_iterator iterator) {
return resolve_segments (starting_point, segments, iterator);
})
- .and_then ([&path] (Node final_node) {
- return final_node.rib.get (path.get_final_segment ().as_string ());
+ .and_then ([&segments] (Node final_node) {
+ return final_node.rib.get (segments.back ().as_string ());
});
}