From: Arthur Cohen Date: Thu, 21 Sep 2023 13:55:03 +0000 (+0200) Subject: gccrs: forever stack: Fix resolve_path signature X-Git-Tag: basepoints/gcc-15~1605 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=5fd3de11508e7205e39b5fe00d8b4fd4789aeb86;p=thirdparty%2Fgcc.git 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. --- 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 57a38078f144..2245ba31772f 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 &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 &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 349d0971f616..ec469a9b3fa0 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 tl::optional resolve_path (const P &path); + template + tl::optional resolve_path (const std::vector &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 211979fa9b95..8f0ab66b18b7 100644 --- a/gcc/rust/resolve/rust-forever-stack.hxx +++ b/gcc/rust/resolve/rust-forever-stack.hxx @@ -429,24 +429,25 @@ ForeverStack::resolve_segments ( } template -template +template tl::optional -ForeverStack::resolve_path (const P &path) +ForeverStack::resolve_path (const std::vector &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::const_iterator iterator) { + typename std::vector::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 ()); }); }