From 30e9cfbf6a60b034a85077b4dd242a2760180188 Mon Sep 17 00:00:00 2001 From: CohenArthur Date: Tue, 18 May 2021 19:27:12 +0200 Subject: name-resolver: Add NodeId to CanonicalPath lookup and reverse mappings --- gcc/rust/resolve/rust-name-resolver.h | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'gcc') diff --git a/gcc/rust/resolve/rust-name-resolver.h b/gcc/rust/resolve/rust-name-resolver.h index 205c877..e45847e 100644 --- a/gcc/rust/resolve/rust-name-resolver.h +++ b/gcc/rust/resolve/rust-name-resolver.h @@ -114,6 +114,7 @@ public: } mappings[path] = id; + reverse_mappings.insert (std::pair (id, path)); decls_within_rib.insert (std::pair (id, locus)); references[id] = {}; } @@ -128,9 +129,21 @@ public: return true; } + bool lookup_canonical_path (const NodeId &id, CanonicalPath *ident) + { + auto it = reverse_mappings.find (id); + if (it == reverse_mappings.end ()) + return false; + + *ident = it->second; + return true; + } + void clear_name (const CanonicalPath &ident, NodeId id) { mappings.erase (ident); + reverse_mappings.erase (id); + for (auto &it : decls_within_rib) { if (it.first == id) @@ -194,6 +207,7 @@ private: CrateNum crate_num; NodeId node_id; std::map mappings; + std::map reverse_mappings; std::set > decls_within_rib; std::map > references; }; -- cgit v1.1