diff options
author | Philip Herron <philip.herron@embecosm.com> | 2022-02-16 17:53:55 +0000 |
---|---|---|
committer | Philip Herron <philip.herron@embecosm.com> | 2022-02-17 13:28:24 +0000 |
commit | a026c166f077027f9997282cf63b0c6d02948ce0 (patch) | |
tree | db381fcf0a856f5aad3f91e44cfaecda12709f7b /gcc | |
parent | 864df7901cfb2581b226939bec85d75c2f301aa3 (diff) | |
download | gcc-a026c166f077027f9997282cf63b0c6d02948ce0.zip gcc-a026c166f077027f9997282cf63b0c6d02948ce0.tar.gz gcc-a026c166f077027f9997282cf63b0c6d02948ce0.tar.bz2 |
Add mappings helpers for looking up macros definitions
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/rust/util/rust-hir-map.cc | 20 | ||||
-rw-r--r-- | gcc/rust/util/rust-hir-map.h | 7 |
2 files changed, 27 insertions, 0 deletions
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<CrateNum, std::set<HirId>> hirNodesWithinCrate; + // macros + std::map<NodeId, AST::MacroRulesDefinition *> macroMappings; + // crate names std::map<CrateNum, std::string> crate_names; }; |