diff options
Diffstat (limited to 'gcc/rust/resolve/rust-ast-resolve-toplevel.h')
-rw-r--r-- | gcc/rust/resolve/rust-ast-resolve-toplevel.h | 54 |
1 files changed, 35 insertions, 19 deletions
diff --git a/gcc/rust/resolve/rust-ast-resolve-toplevel.h b/gcc/rust/resolve/rust-ast-resolve-toplevel.h index afc0068..2550c39 100644 --- a/gcc/rust/resolve/rust-ast-resolve-toplevel.h +++ b/gcc/rust/resolve/rust-ast-resolve-toplevel.h @@ -32,17 +32,19 @@ class ResolveTopLevel : public ResolverBase using Rust::Resolver::ResolverBase::visit; public: - static void go (AST::Item *item) + static void go (AST::Item *item, + const CanonicalPath &prefix = CanonicalPath::create_empty ()) { - ResolveTopLevel resolver; + ResolveTopLevel resolver (prefix); item->accept_vis (resolver); }; void visit (AST::TypeAlias &alias) override { resolver->get_type_scope ().insert ( - alias.get_new_type_name (), alias.get_node_id (), alias.get_locus (), - false, [&] (std::string, NodeId, Location locus) -> void { + CanonicalPath (alias.get_new_type_name ()), alias.get_node_id (), + alias.get_locus (), false, + [&] (const CanonicalPath &, NodeId, Location locus) -> void { rust_error_at (alias.get_locus (), "redefined multiple times"); rust_error_at (locus, "was defined here"); }); @@ -51,9 +53,9 @@ public: void visit (AST::TupleStruct &struct_decl) override { resolver->get_type_scope ().insert ( - struct_decl.get_identifier (), struct_decl.get_node_id (), + CanonicalPath (struct_decl.get_identifier ()), struct_decl.get_node_id (), struct_decl.get_locus (), false, - [&] (std::string, NodeId, Location locus) -> void { + [&] (const CanonicalPath &, NodeId, Location locus) -> void { rust_error_at (struct_decl.get_locus (), "redefined multiple times"); rust_error_at (locus, "was defined here"); }); @@ -62,9 +64,9 @@ public: void visit (AST::StructStruct &struct_decl) override { resolver->get_type_scope ().insert ( - struct_decl.get_identifier (), struct_decl.get_node_id (), + CanonicalPath (struct_decl.get_identifier ()), struct_decl.get_node_id (), struct_decl.get_locus (), false, - [&] (std::string, NodeId, Location locus) -> void { + [&] (const CanonicalPath &, NodeId, Location locus) -> void { rust_error_at (struct_decl.get_locus (), "redefined multiple times"); rust_error_at (locus, "was defined here"); }); @@ -73,8 +75,9 @@ public: void visit (AST::StaticItem &var) override { resolver->get_name_scope ().insert ( - var.get_identifier (), var.get_node_id (), var.get_locus (), false, - [&] (std::string, NodeId, Location locus) -> void { + CanonicalPath (var.get_identifier ()), var.get_node_id (), + var.get_locus (), false, + [&] (const CanonicalPath &, NodeId, Location locus) -> void { rust_error_at (var.get_locus (), "redefined multiple times"); rust_error_at (locus, "was defined here"); }); @@ -86,10 +89,11 @@ public: void visit (AST::ConstantItem &constant) override { + auto path + = prefix.append (ResolveConstantItemToCanonicalPath::resolve (constant)); resolver->get_name_scope ().insert ( - constant.get_identifier (), constant.get_node_id (), - constant.get_locus (), false, - [&] (std::string, NodeId, Location locus) -> void { + path, constant.get_node_id (), constant.get_locus (), false, + [&] (const CanonicalPath &, NodeId, Location locus) -> void { rust_error_at (constant.get_locus (), "redefined multiple times"); rust_error_at (locus, "was defined here"); }); @@ -100,10 +104,11 @@ public: void visit (AST::Function &function) override { + auto path + = prefix.append (ResolveFunctionItemToCanonicalPath::resolve (function)); resolver->get_name_scope ().insert ( - function.get_function_name (), function.get_node_id (), - function.get_locus (), false, - [&] (std::string, NodeId, Location locus) -> void { + path, function.get_node_id (), function.get_locus (), false, + [&] (const CanonicalPath &, NodeId, Location locus) -> void { rust_error_at (function.get_locus (), "redefined multiple times"); rust_error_at (locus, "was defined here"); }); @@ -122,13 +127,24 @@ public: void visit (AST::InherentImpl &impl_block) override { + bool canonicalize_type_args = !impl_block.has_generics (); + bool type_resolve_generic_args = false; + CanonicalPath impl_type + = ResolveTypeToCanonicalPath::resolve (*impl_block.get_type ().get (), + canonicalize_type_args, + type_resolve_generic_args); + CanonicalPath impl_prefix = prefix.append (impl_type); + for (auto &impl_item : impl_block.get_impl_items ()) - ResolveToplevelImplItem::go (impl_item.get (), - impl_block.get_type ().get ()); + ResolveToplevelImplItem::go (impl_item.get (), impl_prefix); } private: - ResolveTopLevel () : ResolverBase (UNKNOWN_NODEID) {} + ResolveTopLevel (const CanonicalPath &prefix) + : ResolverBase (UNKNOWN_NODEID), prefix (prefix) + {} + + const CanonicalPath &prefix; }; } // namespace Resolver |