public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc/devel/rust/master] resolver: TopLevel: Build tree of child modules
@ 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:d374eb47de109af21faa0cfe9fd76a353d9bd06f

commit d374eb47de109af21faa0cfe9fd76a353d9bd06f
Author: Arthur Cohen <arthur.cohen@embecosm.com>
Date:   Thu May 12 15:27:26 2022 +0200

    resolver: TopLevel: Build tree of child modules

Diff:
---
 gcc/rust/resolve/rust-ast-resolve-base.h     |  6 ++++--
 gcc/rust/resolve/rust-ast-resolve-item.cc    |  5 ++++-
 gcc/rust/resolve/rust-ast-resolve-toplevel.h | 14 ++++++++------
 gcc/rust/resolve/rust-ast-resolve.cc         |  2 +-
 4 files changed, 17 insertions(+), 10 deletions(-)

diff --git a/gcc/rust/resolve/rust-ast-resolve-base.h b/gcc/rust/resolve/rust-ast-resolve-base.h
index 17d05c38cf2..9c1f0a10ac8 100644
--- a/gcc/rust/resolve/rust-ast-resolve-base.h
+++ b/gcc/rust/resolve/rust-ast-resolve-base.h
@@ -199,9 +199,10 @@ public:
   void visit (AST::BareFunctionType &);
 
 protected:
-  ResolverBase (NodeId parent)
+  ResolverBase (NodeId parent, NodeId current_module = UNKNOWN_NODEID)
     : resolver (Resolver::get ()), mappings (Analysis::Mappings::get ()),
-      resolved_node (UNKNOWN_NODEID), parent (parent), locus (Location ())
+      resolved_node (UNKNOWN_NODEID), parent (parent),
+      current_module (current_module), locus (Location ())
   {}
 
   bool resolved () const { return resolved_node != UNKNOWN_NODEID; }
@@ -215,6 +216,7 @@ protected:
   Analysis::Mappings *mappings;
   NodeId resolved_node;
   NodeId parent;
+  NodeId current_module;
   Location locus;
 };
 
diff --git a/gcc/rust/resolve/rust-ast-resolve-item.cc b/gcc/rust/resolve/rust-ast-resolve-item.cc
index 93eca1b9df2..38e7713e45d 100644
--- a/gcc/rust/resolve/rust-ast-resolve-item.cc
+++ b/gcc/rust/resolve/rust-ast-resolve-item.cc
@@ -250,8 +250,11 @@ ResolveItem::visit (AST::Module &module)
   resolver->push_new_type_rib (resolver->get_type_scope ().peek ());
   resolver->push_new_label_rib (resolver->get_type_scope ().peek ());
 
+  // FIXME: Should we reinsert a child here? Any reason we ResolveTopLevel::go
+  // in ResolveTopLevel::visit (AST::Module) as well as here?
   for (auto &item : module.get_items ())
-    ResolveTopLevel::go (item.get (), CanonicalPath::create_empty (), cpath);
+    ResolveTopLevel::go (item.get (), CanonicalPath::create_empty (), cpath,
+			 module.get_node_id ());
 
   for (auto &item : module.get_items ())
     ResolveItem::go (item.get (), path, cpath);
diff --git a/gcc/rust/resolve/rust-ast-resolve-toplevel.h b/gcc/rust/resolve/rust-ast-resolve-toplevel.h
index 7aba67fe7e7..7cfaa72f5a5 100644
--- a/gcc/rust/resolve/rust-ast-resolve-toplevel.h
+++ b/gcc/rust/resolve/rust-ast-resolve-toplevel.h
@@ -34,12 +34,12 @@ class ResolveTopLevel : public ResolverBase
 
 public:
   static void go (AST::Item *item, const CanonicalPath &prefix,
-		  const CanonicalPath &canonical_prefix)
+		  const CanonicalPath &canonical_prefix, NodeId current_module)
   {
     if (item->is_marked_for_strip ())
       return;
 
-    ResolveTopLevel resolver (prefix, canonical_prefix);
+    ResolveTopLevel resolver (prefix, canonical_prefix, current_module);
     item->accept_vis (resolver);
   };
 
@@ -62,8 +62,10 @@ public:
 				     Definition{module.get_node_id (),
 						module.get_node_id ()});
 
+    mappings->insert_module_child (current_module, module.get_node_id ());
+
     for (auto &item : module.get_items ())
-      ResolveTopLevel::go (item.get (), path, cpath);
+      ResolveTopLevel::go (item.get (), path, cpath, module.get_node_id ());
 
     mappings->insert_canonical_path (mappings->get_current_crate (),
 				     module.get_node_id (), cpath);
@@ -123,7 +125,7 @@ public:
       });
 
     for (auto &variant : enum_decl.get_variants ())
-      ResolveTopLevel::go (variant.get (), path, cpath);
+      ResolveTopLevel::go (variant.get (), path, cpath, current_module);
 
     mappings->insert_canonical_path (mappings->get_current_crate (),
 				     enum_decl.get_node_id (), cpath);
@@ -403,8 +405,8 @@ public:
 
 private:
   ResolveTopLevel (const CanonicalPath &prefix,
-		   const CanonicalPath &canonical_prefix)
-    : ResolverBase (UNKNOWN_NODEID), prefix (prefix),
+		   const CanonicalPath &canonical_prefix, NodeId current_module)
+    : ResolverBase (UNKNOWN_NODEID, current_module), prefix (prefix),
       canonical_prefix (canonical_prefix)
   {}
 
diff --git a/gcc/rust/resolve/rust-ast-resolve.cc b/gcc/rust/resolve/rust-ast-resolve.cc
index 6da560946b2..945ff28c195 100644
--- a/gcc/rust/resolve/rust-ast-resolve.cc
+++ b/gcc/rust/resolve/rust-ast-resolve.cc
@@ -86,7 +86,7 @@ NameResolution::go (AST::Crate &crate)
   // a Self type Foo which is defined after the impl block for example.
   for (auto it = crate.items.begin (); it != crate.items.end (); it++)
     ResolveTopLevel::go (it->get (), CanonicalPath::create_empty (),
-			 crate_prefix);
+			 crate_prefix, scope_node_id);
 
   // FIXME remove this
   if (saw_errors ())


^ 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] resolver: TopLevel: Build tree of child modules 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).