public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Thomas Schwinge <tschwinge@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org
Subject: [gcc/devel/rust/master] mappings: Add module->children mappings
Date: Wed,  8 Jun 2022 12:46:36 +0000 (GMT)	[thread overview]
Message-ID: <20220608124636.3ABF33895FF8@sourceware.org> (raw)

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


                 reply	other threads:[~2022-06-08 12:46 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220608124636.3ABF33895FF8@sourceware.org \
    --to=tschwinge@gcc.gnu.org \
    --cc=gcc-cvs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).