aboutsummaryrefslogtreecommitdiff
path: root/gcc/rust
diff options
context:
space:
mode:
authorPierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>2024-05-04 03:21:27 +0200
committerArthur Cohen <arthur.cohen@embecosm.com>2025-03-17 16:35:26 +0100
commit1d7d56aab77fa53e3cba8a885208a07772d91a76 (patch)
tree3f30d7d20875a3da3bd52a732ed8bdfaefa4de04 /gcc/rust
parente4778eceb42e914e4d202f851cd71f426f19ef7e (diff)
downloadgcc-1d7d56aab77fa53e3cba8a885208a07772d91a76.zip
gcc-1d7d56aab77fa53e3cba8a885208a07772d91a76.tar.gz
gcc-1d7d56aab77fa53e3cba8a885208a07772d91a76.tar.bz2
gccrs: Change lookup_macro_invocation's return type
Wrap the function's return type within an optional and remove the out reference argument. gcc/rust/ChangeLog: * expand/rust-macro-expand.cc (MacroExpander::expand_invoc): Adapt the function call to match its new prototype. * resolve/rust-early-name-resolver-2.0.cc (Early::insert_once): Likewise. (Early::visit): Likewise. * resolve/rust-early-name-resolver.cc (EarlyNameResolver::visit): Likewise. * util/rust-hir-map.cc (Mappings::lookup_macro_invocation): Change the function's return type. * util/rust-hir-map.h: Update the function's prototype. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Diffstat (limited to 'gcc/rust')
-rw-r--r--gcc/rust/expand/rust-macro-expand.cc18
-rw-r--r--gcc/rust/resolve/rust-early-name-resolver-2.0.cc8
-rw-r--r--gcc/rust/resolve/rust-early-name-resolver.cc3
-rw-r--r--gcc/rust/util/rust-hir-map.cc10
-rw-r--r--gcc/rust/util/rust-hir-map.h4
5 files changed, 18 insertions, 25 deletions
diff --git a/gcc/rust/expand/rust-macro-expand.cc b/gcc/rust/expand/rust-macro-expand.cc
index 86c6695..e2ef404 100644
--- a/gcc/rust/expand/rust-macro-expand.cc
+++ b/gcc/rust/expand/rust-macro-expand.cc
@@ -272,25 +272,25 @@ MacroExpander::expand_invoc (AST::MacroInvocation &invoc, bool has_semicolon)
invoc_data.set_expander (this);
// lookup the rules
- AST::MacroRulesDefinition *rules_def = nullptr;
- bool ok = mappings.lookup_macro_invocation (invoc, &rules_def);
+ auto rules_def = mappings.lookup_macro_invocation (invoc);
// If there's no rule associated with the invocation, we can simply return
// early. The early name resolver will have already emitted an error.
- if (!ok)
+ if (!rules_def)
return;
+ auto rdef = rules_def.value ();
+
// We store the last expanded invocation and macro definition for error
// reporting in case the recursion limit is reached
last_invoc = *invoc.clone_macro_invocation_impl ();
- last_def = *rules_def;
+ last_def = *rdef;
- if (rules_def->is_builtin ())
- fragment
- = rules_def->get_builtin_transcriber () (invoc.get_locus (), invoc_data)
- .value_or (AST::Fragment::create_empty ());
+ if (rdef->is_builtin ())
+ fragment = rdef->get_builtin_transcriber () (invoc.get_locus (), invoc_data)
+ .value_or (AST::Fragment::create_empty ());
else
- fragment = expand_decl_macro (invoc.get_locus (), invoc_data, *rules_def,
+ fragment = expand_decl_macro (invoc.get_locus (), invoc_data, *rdef,
has_semicolon);
set_expanded_fragment (std::move (fragment));
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 c051393..1b21e11 100644
--- a/gcc/rust/resolve/rust-early-name-resolver-2.0.cc
+++ b/gcc/rust/resolve/rust-early-name-resolver-2.0.cc
@@ -32,10 +32,7 @@ Early::insert_once (AST::MacroInvocation &invocation, NodeId resolved)
// TODO: Should we use `ctx.mark_resolved()`?
auto definition = ctx.mappings.lookup_macro_def (resolved);
- AST::MacroRulesDefinition *existing;
- auto exists = ctx.mappings.lookup_macro_invocation (invocation, &existing);
-
- if (!exists)
+ if (!ctx.mappings.lookup_macro_invocation (invocation))
ctx.mappings.insert_macro_invocation (invocation, definition.value ());
}
@@ -176,8 +173,7 @@ Early::visit (AST::MacroInvocation &invoc)
if (!rules_def)
return;
- AST::MacroRulesDefinition *tmp_def = nullptr;
- if (mappings.lookup_macro_invocation (invoc, &tmp_def))
+ if (mappings.lookup_macro_invocation (invoc))
return;
mappings.insert_macro_invocation (invoc, rules_def.value ());
diff --git a/gcc/rust/resolve/rust-early-name-resolver.cc b/gcc/rust/resolve/rust-early-name-resolver.cc
index 604b05d..ce427dd 100644
--- a/gcc/rust/resolve/rust-early-name-resolver.cc
+++ b/gcc/rust/resolve/rust-early-name-resolver.cc
@@ -503,8 +503,7 @@ EarlyNameResolver::visit (AST::MacroInvocation &invoc)
* we could be inserting the same macro def over and over again until we
* implement some optimizations */
// FIXME: ARTHUR: Remove that lookup and add proper optimizations instead
- AST::MacroRulesDefinition *tmp_def = nullptr;
- if (mappings.lookup_macro_invocation (invoc, &tmp_def))
+ if (mappings.lookup_macro_invocation (invoc))
return;
mappings.insert_macro_invocation (invoc, *rules_def);
diff --git a/gcc/rust/util/rust-hir-map.cc b/gcc/rust/util/rust-hir-map.cc
index f6df55f..3b72119 100644
--- a/gcc/rust/util/rust-hir-map.cc
+++ b/gcc/rust/util/rust-hir-map.cc
@@ -897,16 +897,14 @@ Mappings::insert_macro_invocation (AST::MacroInvocation &invoc,
macroInvocations[invoc.get_macro_node_id ()] = def;
}
-bool
-Mappings::lookup_macro_invocation (AST::MacroInvocation &invoc,
- AST::MacroRulesDefinition **def)
+tl::optional<AST::MacroRulesDefinition *>
+Mappings::lookup_macro_invocation (AST::MacroInvocation &invoc)
{
auto it = macroInvocations.find (invoc.get_macro_node_id ());
if (it == macroInvocations.end ())
- return false;
+ return tl::nullopt;
- *def = it->second;
- return true;
+ return it->second;
}
void
diff --git a/gcc/rust/util/rust-hir-map.h b/gcc/rust/util/rust-hir-map.h
index 3747804..d80a15e 100644
--- a/gcc/rust/util/rust-hir-map.h
+++ b/gcc/rust/util/rust-hir-map.h
@@ -282,8 +282,8 @@ public:
void insert_macro_invocation (AST::MacroInvocation &invoc,
AST::MacroRulesDefinition *def);
- bool lookup_macro_invocation (AST::MacroInvocation &invoc,
- AST::MacroRulesDefinition **def);
+ tl::optional<AST::MacroRulesDefinition *>
+ lookup_macro_invocation (AST::MacroInvocation &invoc);
void insert_exported_macro (AST::MacroRulesDefinition &def);
std::vector<NodeId> &get_exported_macros ();