diff options
author | Arthur Cohen <arthur.cohen@embecosm.com> | 2022-05-12 15:27:26 +0200 |
---|---|---|
committer | Arthur Cohen <arthur.cohen@embecosm.com> | 2022-05-12 17:10:06 +0200 |
commit | d374eb47de109af21faa0cfe9fd76a353d9bd06f (patch) | |
tree | 3d03ed31d6a7313a5a91ba5d4078f311513c920b | |
parent | 172624a7f9ce1ba16a89c7ee64861cb5447b7561 (diff) | |
download | gcc-d374eb47de109af21faa0cfe9fd76a353d9bd06f.zip gcc-d374eb47de109af21faa0cfe9fd76a353d9bd06f.tar.gz gcc-d374eb47de109af21faa0cfe9fd76a353d9bd06f.tar.bz2 |
resolver: TopLevel: Build tree of child modules
-rw-r--r-- | gcc/rust/resolve/rust-ast-resolve-base.h | 6 | ||||
-rw-r--r-- | gcc/rust/resolve/rust-ast-resolve-item.cc | 5 | ||||
-rw-r--r-- | gcc/rust/resolve/rust-ast-resolve-toplevel.h | 14 | ||||
-rw-r--r-- | 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 17d05c3..9c1f0a1 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 93eca1b..38e7713 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 7aba67f..7cfaa72 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 6da5609..945ff28 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 ()) |