aboutsummaryrefslogtreecommitdiff
path: root/gcc/rust/util/rust-hir-map.h
diff options
context:
space:
mode:
authorArthur Cohen <arthur.cohen@embecosm.com>2025-02-24 13:09:17 +0100
committerCohenArthur <arthur.cohen@embecosm.com>2025-03-06 15:44:14 +0000
commitf88af6176e24e62670f33f3d119db02850c11af2 (patch)
tree510f16e233618fa414528254692bf3f04b5048ab /gcc/rust/util/rust-hir-map.h
parent912ebb6b74936e6e69bba116af7e45caab3c414c (diff)
downloadgcc-f88af6176e24e62670f33f3d119db02850c11af2.zip
gcc-f88af6176e24e62670f33f3d119db02850c11af2.tar.gz
gcc-f88af6176e24e62670f33f3d119db02850c11af2.tar.bz2
expansion: Correctly expand $crate metavar
gcc/rust/ChangeLog: * expand/rust-macro-expand.cc: Use new SubstituteCtx API. * expand/rust-macro-expand.h: Likewise. * expand/rust-macro-substitute-ctx.cc: Implement proper expansion of $crate. * expand/rust-macro-substitute-ctx.h: Adapt APIs to take macro definition when substituting. * util/rust-hir-map.cc (Mappings::insert_macro_def): Store crate information when inserting macro definition in mappings. (Mappings::lookup_macro_def_crate): New. * util/rust-hir-map.h: Adapt mappings to store crate in which macros were defined. gcc/testsuite/ChangeLog: * rust/execute/crate-metavar1.rs: New test. * rust/compile/crate-metavar1.rs: New test.
Diffstat (limited to 'gcc/rust/util/rust-hir-map.h')
-rw-r--r--gcc/rust/util/rust-hir-map.h4
1 files changed, 3 insertions, 1 deletions
diff --git a/gcc/rust/util/rust-hir-map.h b/gcc/rust/util/rust-hir-map.h
index 6f21f38..9fcb3c6 100644
--- a/gcc/rust/util/rust-hir-map.h
+++ b/gcc/rust/util/rust-hir-map.h
@@ -269,6 +269,7 @@ public:
void insert_macro_def (AST::MacroRulesDefinition *macro);
tl::optional<AST::MacroRulesDefinition *> lookup_macro_def (NodeId id);
+ tl::optional<CrateNum> lookup_macro_def_crate (NodeId id);
void insert_macro_invocation (AST::MacroInvocation &invoc,
AST::MacroRulesDefinition *def);
@@ -402,7 +403,8 @@ private:
std::map<CrateNum, std::set<HirId>> hirNodesWithinCrate;
// MBE macros
- std::map<NodeId, AST::MacroRulesDefinition *> macroMappings;
+ std::map<NodeId, std::pair<AST::MacroRulesDefinition *, CrateNum>>
+ macroMappings;
std::map<NodeId, AST::MacroRulesDefinition *> macroInvocations;
std::vector<NodeId> exportedMacros;