From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1643) id 65A08380E180; Wed, 8 Jun 2022 12:46:46 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 65A08380E180 Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Thomas Schwinge To: gcc-cvs@gcc.gnu.org Subject: [gcc/devel/rust/master] resolver: TopLevel: Build tree of child modules X-Act-Checkin: gcc X-Git-Author: Arthur Cohen X-Git-Refname: refs/heads/devel/rust/master X-Git-Oldrev: 172624a7f9ce1ba16a89c7ee64861cb5447b7561 X-Git-Newrev: d374eb47de109af21faa0cfe9fd76a353d9bd06f Message-Id: <20220608124646.65A08380E180@sourceware.org> Date: Wed, 8 Jun 2022 12:46:46 +0000 (GMT) X-BeenThere: gcc-cvs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 08 Jun 2022 12:46:46 -0000 https://gcc.gnu.org/g:d374eb47de109af21faa0cfe9fd76a353d9bd06f commit d374eb47de109af21faa0cfe9fd76a353d9bd06f Author: Arthur Cohen 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 ())