public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc/devel/rust/master] mappings: Add module->children mappings
@ 2022-06-08 12:46 Thomas Schwinge
0 siblings, 0 replies; only message in thread
From: Thomas Schwinge @ 2022-06-08 12:46 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:56b4aa48df965191558e58dede5631e10faab2d5
commit 56b4aa48df965191558e58dede5631e10faab2d5
Author: Arthur Cohen <arthur.cohen@embecosm.com>
Date: Thu May 12 12:10:31 2022 +0200
mappings: Add module->children mappings
Diff:
---
gcc/rust/util/rust-hir-map.cc | 20 ++++++++++++++++++++
gcc/rust/util/rust-hir-map.h | 9 +++++++++
2 files changed, 29 insertions(+)
diff --git a/gcc/rust/util/rust-hir-map.cc b/gcc/rust/util/rust-hir-map.cc
index 66d3e415471..a287589e1dc 100644
--- a/gcc/rust/util/rust-hir-map.cc
+++ b/gcc/rust/util/rust-hir-map.cc
@@ -848,5 +848,25 @@ Mappings::lookup_visibility (DefId id, Privacy::ModuleVisibility *def)
return true;
}
+void
+Mappings::insert_module_child (NodeId module, NodeId child)
+{
+ auto it = module_child_map.find (module);
+ if (it == module_child_map.end ())
+ module_child_map.insert ({module, {child}});
+ else
+ it->second.emplace_back (child);
+}
+
+Optional<std::vector<NodeId> &>
+Mappings::lookup_module_children (NodeId module)
+{
+ auto it = module_child_map.find (module);
+ if (it == module_child_map.end ())
+ return Optional<std::vector<NodeId> &>::none ();
+
+ return Optional<std::vector<NodeId> &>::some (it->second);
+}
+
} // namespace Analysis
} // namespace Rust
diff --git a/gcc/rust/util/rust-hir-map.h b/gcc/rust/util/rust-hir-map.h
index 0bb870b4910..88cb6823fba 100644
--- a/gcc/rust/util/rust-hir-map.h
+++ b/gcc/rust/util/rust-hir-map.h
@@ -19,6 +19,7 @@
#ifndef RUST_HIR_MAP_H
#define RUST_HIR_MAP_H
+#include "rust-optional.h"
#include "rust-system.h"
#include "rust-location.h"
#include "rust-mapping-common.h"
@@ -321,6 +322,9 @@ public:
void insert_visibility (DefId id, Privacy::ModuleVisibility visibility);
bool lookup_visibility (DefId id, Privacy::ModuleVisibility *def);
+ void insert_module_child (NodeId module, NodeId child);
+ Optional<std::vector<NodeId> &> lookup_module_children (NodeId module);
+
private:
Mappings ();
@@ -386,6 +390,11 @@ private:
// Low level visibility map for each DefId
std::map<DefId, Privacy::ModuleVisibility> visibility_map;
+
+ // Module tree maps
+
+ // Maps each module's node id to a list of its children
+ std::map<NodeId, std::vector<NodeId>> module_child_map;
};
} // namespace Analysis
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2022-06-08 12:46 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-08 12:46 [gcc/devel/rust/master] mappings: Add module->children mappings Thomas Schwinge
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).