From a08f265625e525fa937dd6bc59f37da122df9f82 Mon Sep 17 00:00:00 2001 From: Arthur Cohen Date: Tue, 11 Oct 2022 11:38:55 +0200 Subject: gccrs: mappings: Add MacroInvocation -> MacroRulesDef mappings gcc/rust/ChangeLog: * util/rust-hir-map.h: Add new mappings. * util/rust-hir-map.cc (Mappings::insert_macro_invocation): Add insertion function into mappings. (Mappings::lookup_macro_invocation): Add lookup function for mappings. --- gcc/rust/util/rust-hir-map.cc | 22 ++++++++++++++++++++++ gcc/rust/util/rust-hir-map.h | 6 ++++++ 2 files changed, 28 insertions(+) (limited to 'gcc') diff --git a/gcc/rust/util/rust-hir-map.cc b/gcc/rust/util/rust-hir-map.cc index 8043448..7ea782ed 100644 --- a/gcc/rust/util/rust-hir-map.cc +++ b/gcc/rust/util/rust-hir-map.cc @@ -867,6 +867,28 @@ Mappings::lookup_macro_def (NodeId id, AST::MacroRulesDefinition **def) } void +Mappings::insert_macro_invocation (AST::MacroInvocation &invoc, + AST::MacroRulesDefinition *def) +{ + auto it = macroInvocations.find (invoc.get_macro_node_id ()); + rust_assert (it == macroInvocations.end ()); + + macroInvocations[invoc.get_macro_node_id ()] = def; +} + +bool +Mappings::lookup_macro_invocation (AST::MacroInvocation &invoc, + AST::MacroRulesDefinition **def) +{ + auto it = macroInvocations.find (invoc.get_macro_node_id ()); + if (it == macroInvocations.end ()) + return false; + + *def = it->second; + return true; +} + +void Mappings::insert_visibility (NodeId id, Privacy::ModuleVisibility visibility) { visibility_map.insert ({id, visibility}); diff --git a/gcc/rust/util/rust-hir-map.h b/gcc/rust/util/rust-hir-map.h index 474bd5f..addd9ef 100644 --- a/gcc/rust/util/rust-hir-map.h +++ b/gcc/rust/util/rust-hir-map.h @@ -269,6 +269,11 @@ public: bool lookup_macro_def (NodeId id, AST::MacroRulesDefinition **def); + void insert_macro_invocation (AST::MacroInvocation &invoc, + AST::MacroRulesDefinition *def); + bool lookup_macro_invocation (AST::MacroInvocation &invoc, + AST::MacroRulesDefinition **def); + void insert_visibility (NodeId id, Privacy::ModuleVisibility visibility); bool lookup_visibility (NodeId id, Privacy::ModuleVisibility &def); @@ -334,6 +339,7 @@ private: // macros std::map macroMappings; + std::map macroInvocations; // crate names std::map crate_names; -- cgit v1.1