public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r14-8563] gccrs: early: Resolve paths properly
@ 2024-01-30 12:00 Arthur Cohen
0 siblings, 0 replies; only message in thread
From: Arthur Cohen @ 2024-01-30 12:00 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:53d979f361f214ead438c62d74a9adb2c4383651
commit r14-8563-g53d979f361f214ead438c62d74a9adb2c4383651
Author: Arthur Cohen <arthur.cohen@embecosm.com>
Date: Mon Aug 21 16:52:48 2023 +0200
gccrs: early: Resolve paths properly
gcc/rust/ChangeLog:
* resolve/rust-early-name-resolver-2.0.cc
(Early::insert_once): New function.
(Early::visit): Likewise.
* resolve/rust-early-name-resolver-2.0.h: Likewise.
Diff:
---
gcc/rust/resolve/rust-early-name-resolver-2.0.cc | 30 ++++++++++++++++++++++++
gcc/rust/resolve/rust-early-name-resolver-2.0.h | 10 ++++++++
2 files changed, 40 insertions(+)
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 2245ba31772f..48bb4c68d268 100644
--- a/gcc/rust/resolve/rust-early-name-resolver-2.0.cc
+++ b/gcc/rust/resolve/rust-early-name-resolver-2.0.cc
@@ -26,6 +26,33 @@ namespace Resolver2_0 {
Early::Early (NameResolutionContext &ctx) : DefaultResolver (ctx) {}
+void
+Early::insert_once (AST::MacroInvocation &invocation, NodeId resolved)
+{
+ // TODO: Should we use `ctx.mark_resolved()`?
+ AST::MacroRulesDefinition *definition;
+ auto ok = ctx.mappings.lookup_macro_def (resolved, &definition);
+
+ rust_assert (ok);
+
+ AST::MacroRulesDefinition *existing;
+ auto exists = ctx.mappings.lookup_macro_invocation (invocation, &existing);
+
+ if (!exists)
+ ctx.mappings.insert_macro_invocation (invocation, definition);
+}
+
+void
+Early::insert_once (AST::MacroRulesDefinition &def)
+{
+ // TODO: Should we use `ctx.mark_resolved()`?
+ AST::MacroRulesDefinition *definition;
+ auto exists = ctx.mappings.lookup_macro_def (def.get_node_id (), &definition);
+
+ if (!exists)
+ ctx.mappings.insert_macro_def (&def);
+}
+
void
Early::go (AST::Crate &crate)
{
@@ -89,6 +116,7 @@ Early::visit (AST::MacroRulesDefinition &def)
DefaultResolver::visit (def);
textual_scope.insert (def.get_rule_name ().as_string (), def.get_node_id ());
+ insert_once (def);
}
void
@@ -141,6 +169,8 @@ Early::visit (AST::MacroInvocation &invoc)
return;
}
+ insert_once (invoc, *definition);
+
// now do we need to keep mappings or something? or insert "uses" into our
// ForeverStack? can we do that? are mappings simpler?
auto mappings = Analysis::Mappings::get ();
diff --git a/gcc/rust/resolve/rust-early-name-resolver-2.0.h b/gcc/rust/resolve/rust-early-name-resolver-2.0.h
index dc2731964735..46c4b936866e 100644
--- a/gcc/rust/resolve/rust-early-name-resolver-2.0.h
+++ b/gcc/rust/resolve/rust-early-name-resolver-2.0.h
@@ -60,6 +60,16 @@ public:
private:
void visit_attributes (std::vector<AST::Attribute> &attrs);
+ /**
+ * Insert a resolved macro invocation into the mappings once, meaning that we
+ * can call this function each time the early name resolution pass is underway
+ * and it will not trigger assertions for already resolved invocations.
+ */
+ // TODO: Rename
+ void insert_once (AST::MacroInvocation &invocation, NodeId resolved);
+ // TODO: Rename
+ void insert_once (AST::MacroRulesDefinition &definition);
+
/**
* Macros can either be resolved through textual scoping or regular path
* scoping - which this class represents. Textual scoping works similarly to a
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2024-01-30 12:00 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-01-30 12:00 [gcc r14-8563] gccrs: early: Resolve paths properly 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).