aboutsummaryrefslogtreecommitdiff
path: root/gcc/rust/expand/rust-macro-expand.cc
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2022-10-14 14:41:18 +0000
committerGitHub <noreply@github.com>2022-10-14 14:41:18 +0000
commitfa0bd801922d095893c9318ad1d0c78141c05796 (patch)
tree347f4854ff4ba56be603bcbab3e7d19c3f64125a /gcc/rust/expand/rust-macro-expand.cc
parentc85492954ded963d937de1fa8731be0718d117eb (diff)
parent6dca194d4b556dfe27cb7865142ad595f3a96c95 (diff)
downloadgcc-fa0bd801922d095893c9318ad1d0c78141c05796.zip
gcc-fa0bd801922d095893c9318ad1d0c78141c05796.tar.gz
gcc-fa0bd801922d095893c9318ad1d0c78141c05796.tar.bz2
Merge #1580
1580: Add early name resolver r=CohenArthur a=CohenArthur This addresses our issue with name resolution (#1576) not acting on macros early enough but does not fix it yet. This name resolver performs the same macro name resolution as what was previously done by the AttrVisitor visitor and macro expander. It also resolves macro expressions in builtin-macros properly, as well as expanded AST nodes when necessary. Co-authored-by: Arthur Cohen <arthur.cohen@embecosm.com>
Diffstat (limited to 'gcc/rust/expand/rust-macro-expand.cc')
-rw-r--r--gcc/rust/expand/rust-macro-expand.cc30
1 files changed, 8 insertions, 22 deletions
diff --git a/gcc/rust/expand/rust-macro-expand.cc b/gcc/rust/expand/rust-macro-expand.cc
index e7a7b84..96b74da 100644
--- a/gcc/rust/expand/rust-macro-expand.cc
+++ b/gcc/rust/expand/rust-macro-expand.cc
@@ -23,6 +23,7 @@
#include "rust-diagnostics.h"
#include "rust-parse.h"
#include "rust-attribute-visitor.h"
+#include "rust-early-name-resolver.h"
namespace Rust {
AST::ASTFragment
@@ -138,32 +139,17 @@ MacroExpander::expand_invoc (AST::MacroInvocation &invoc, bool has_semicolon)
// - else is unreachable
// - derive container macro - unreachable
- // lookup the rules for this macro
- NodeId resolved_node = UNKNOWN_NODEID;
- NodeId source_node = UNKNOWN_NODEID;
- if (has_semicolon)
- source_node = invoc.get_macro_node_id ();
- else
- source_node = invoc.get_pattern_node_id ();
- auto seg
- = Resolver::CanonicalPath::new_seg (source_node,
- invoc_data.get_path ().as_string ());
-
- bool found = resolver->get_macro_scope ().lookup (seg, &resolved_node);
- if (!found)
- {
- rust_error_at (invoc.get_locus (), "unknown macro: [%s]",
- seg.get ().c_str ());
- return;
- }
+ auto fragment = AST::ASTFragment::create_error ();
+ invoc_data.set_expander (this);
// lookup the rules
AST::MacroRulesDefinition *rules_def = nullptr;
- bool ok = mappings->lookup_macro_def (resolved_node, &rules_def);
- rust_assert (ok);
+ bool ok = mappings->lookup_macro_invocation (invoc, &rules_def);
- auto fragment = AST::ASTFragment::create_error ();
- invoc_data.set_expander (this);
+ // 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)
+ return;
if (rules_def->is_builtin ())
fragment