diff options
author | Philip Herron <philip.herron@embecosm.com> | 2021-04-10 15:26:31 +0100 |
---|---|---|
committer | Philip Herron <philip.herron@embecosm.com> | 2021-04-12 22:39:45 +0100 |
commit | 826ce3c92d69b2f2ff9d11ad39cd0843fcc21a05 (patch) | |
tree | 5e428fb5db30734fc1e453c60317e6e27aef1554 /gcc/rust/util/rust-hir-map.h | |
parent | 3fa740f4ff0475809edd45de9fb03b12e1f2a389 (diff) | |
download | gcc-826ce3c92d69b2f2ff9d11ad39cd0843fcc21a05.zip gcc-826ce3c92d69b2f2ff9d11ad39cd0843fcc21a05.tar.gz gcc-826ce3c92d69b2f2ff9d11ad39cd0843fcc21a05.tar.bz2 |
Add impl mappings to inherent impl items
When lowering impl blocks to HIR we keep track of all the inherent impl
items for lookup later but we also need to be able to reverse lookup impl
items back to their respective impl block.
Diffstat (limited to 'gcc/rust/util/rust-hir-map.h')
-rw-r--r-- | gcc/rust/util/rust-hir-map.h | 27 |
1 files changed, 16 insertions, 11 deletions
diff --git a/gcc/rust/util/rust-hir-map.h b/gcc/rust/util/rust-hir-map.h index 2e8a629..9777ee3 100644 --- a/gcc/rust/util/rust-hir-map.h +++ b/gcc/rust/util/rust-hir-map.h @@ -158,20 +158,24 @@ public: return hirNodesWithinCrate[crate]; } - void - iterate_impl_items (std::function<bool (HirId, HIR::InherentImplItem *)> cb) + void insert_impl_item_mapping (HirId impl_item_id, HIR::InherentImpl *impl) { - for (auto it = hirImplItemMappings.begin (); - it != hirImplItemMappings.end (); it++) - { - for (auto iy = it->second.begin (); iy != it->second.end (); iy++) - { - if (!cb (iy->first, iy->second.second)) - return; - } - } + rust_assert (hirImplItemsToImplMappings.find (impl_item_id) + == hirImplItemsToImplMappings.end ()); + hirImplItemsToImplMappings[impl_item_id] = impl; } + HIR::InherentImpl *lookup_associated_impl (HirId impl_item_id) + { + auto lookup = hirImplItemsToImplMappings.find (impl_item_id); + rust_assert (lookup != hirImplItemsToImplMappings.end ()); + return lookup->second; + } + + void iterate_impl_items ( + std::function<bool (HirId, HIR::InherentImplItem *, HIR::InherentImpl *)> + cb); + private: Mappings (); @@ -198,6 +202,7 @@ private: std::map<HirId, std::pair<HirId, HIR::InherentImplItem *> > > hirImplItemMappings; std::map<CrateNum, std::map<HirId, HIR::SelfParam *> > hirSelfParamMappings; + std::map<HirId, HIR::InherentImpl *> hirImplItemsToImplMappings; // location info std::map<CrateNum, std::map<NodeId, Location> > locations; |