diff options
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; |