From a026c166f077027f9997282cf63b0c6d02948ce0 Mon Sep 17 00:00:00 2001 From: Philip Herron Date: Wed, 16 Feb 2022 17:53:55 +0000 Subject: Add mappings helpers for looking up macros definitions --- gcc/rust/util/rust-hir-map.cc | 20 ++++++++++++++++++++ gcc/rust/util/rust-hir-map.h | 7 +++++++ 2 files changed, 27 insertions(+) (limited to 'gcc') diff --git a/gcc/rust/util/rust-hir-map.cc b/gcc/rust/util/rust-hir-map.cc index 04db333..1348e29 100644 --- a/gcc/rust/util/rust-hir-map.cc +++ b/gcc/rust/util/rust-hir-map.cc @@ -738,5 +738,25 @@ Mappings::iterate_trait_items ( } } +void +Mappings::insert_macro_def (AST::MacroRulesDefinition *macro) +{ + auto it = macroMappings.find (macro->get_node_id ()); + rust_assert (it == macroMappings.end ()); + + macroMappings[macro->get_node_id ()] = macro; +} + +bool +Mappings::lookup_macro_def (NodeId id, AST::MacroRulesDefinition **def) +{ + auto it = macroMappings.find (id); + if (it == macroMappings.end ()) + return false; + + *def = it->second; + return true; +} + } // namespace Analysis } // namespace Rust diff --git a/gcc/rust/util/rust-hir-map.h b/gcc/rust/util/rust-hir-map.h index 8781629..799351b 100644 --- a/gcc/rust/util/rust-hir-map.h +++ b/gcc/rust/util/rust-hir-map.h @@ -559,6 +559,10 @@ public: return true; } + void insert_macro_def (AST::MacroRulesDefinition *macro); + + bool lookup_macro_def (NodeId id, AST::MacroRulesDefinition **def); + private: Mappings (); @@ -612,6 +616,9 @@ private: // all hirid nodes std::map> hirNodesWithinCrate; + // macros + std::map macroMappings; + // crate names std::map crate_names; }; -- cgit v1.1