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 | |
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')
-rw-r--r-- | gcc/rust/util/rust-hir-map.cc | 19 | ||||
-rw-r--r-- | gcc/rust/util/rust-hir-map.h | 27 |
2 files changed, 35 insertions, 11 deletions
diff --git a/gcc/rust/util/rust-hir-map.cc b/gcc/rust/util/rust-hir-map.cc index 891618e..0dcbd4f 100644 --- a/gcc/rust/util/rust-hir-map.cc +++ b/gcc/rust/util/rust-hir-map.cc @@ -524,5 +524,24 @@ Mappings::resolve_nodeid_to_stmt (CrateNum crate, NodeId id, HIR::Stmt **stmt) return resolved_stmt != nullptr; } +void +Mappings::iterate_impl_items ( + std::function<bool (HirId, HIR::InherentImplItem *, HIR::InherentImpl *)> cb) +{ + for (auto it = hirImplItemMappings.begin (); it != hirImplItemMappings.end (); + it++) + { + for (auto iy = it->second.begin (); iy != it->second.end (); iy++) + { + auto id = iy->first; + auto impl_item = iy->second.second; + auto impl = lookup_associated_impl ( + impl_item->get_impl_mappings ().get_hirid ()); + if (!cb (id, impl_item, impl)) + return; + } + } +} + } // namespace Analysis } // namespace Rust 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; |