diff options
author | Philip Herron <philip.herron@embecosm.com> | 2022-06-28 17:00:54 +0100 |
---|---|---|
committer | Philip Herron <philip.herron@embecosm.com> | 2022-06-28 17:00:54 +0100 |
commit | 5b8502d862f647edb1ab41467759177983b4ddfc (patch) | |
tree | 5265d279ba60160bb1609071c59920a36609d1fa /gcc | |
parent | 76aeea68f518dba8a29bd7ad82e049ad106fe8bd (diff) | |
download | gcc-5b8502d862f647edb1ab41467759177983b4ddfc.zip gcc-5b8502d862f647edb1ab41467759177983b4ddfc.tar.gz gcc-5b8502d862f647edb1ab41467759177983b4ddfc.tar.bz2 |
Remove default keyword flags in ResolveType interface
This patch also decouples handle the case where we need to resolve the full
canonical path of a TypeNoBounds such as:
struct Foo;
impl &Foo { .. }
And te canonical path for the impl block Self type is actually
&crate_name::Foo
This is used in name mangling right now.
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/rust/resolve/rust-ast-resolve-expr.cc | 2 | ||||
-rw-r--r-- | gcc/rust/resolve/rust-ast-resolve-item.cc | 91 | ||||
-rw-r--r-- | gcc/rust/resolve/rust-ast-resolve-path.cc | 6 | ||||
-rw-r--r-- | gcc/rust/resolve/rust-ast-resolve-stmt.h | 22 | ||||
-rw-r--r-- | gcc/rust/resolve/rust-ast-resolve-type.cc | 122 | ||||
-rw-r--r-- | gcc/rust/resolve/rust-ast-resolve-type.h | 79 |
6 files changed, 179 insertions, 143 deletions
diff --git a/gcc/rust/resolve/rust-ast-resolve-expr.cc b/gcc/rust/resolve/rust-ast-resolve-expr.cc index f0ad567..2087bad 100644 --- a/gcc/rust/resolve/rust-ast-resolve-expr.cc +++ b/gcc/rust/resolve/rust-ast-resolve-expr.cc @@ -167,7 +167,7 @@ ResolveExpr::visit (AST::NegationExpr &expr) void ResolveExpr::visit (AST::TypeCastExpr &expr) { - ResolveType::go (expr.get_type_to_cast_to ().get (), expr.get_node_id ()); + ResolveType::go (expr.get_type_to_cast_to ().get ()); ResolveExpr::go (expr.get_casted_expr ().get (), prefix, canonical_prefix); } diff --git a/gcc/rust/resolve/rust-ast-resolve-item.cc b/gcc/rust/resolve/rust-ast-resolve-item.cc index 5b30cdb..1ad91af 100644 --- a/gcc/rust/resolve/rust-ast-resolve-item.cc +++ b/gcc/rust/resolve/rust-ast-resolve-item.cc @@ -50,7 +50,7 @@ ResolveTraitItems::visit (AST::TraitItemType &type) type.get_node_id (), cpath); for (auto &bound : type.get_type_param_bounds ()) - ResolveTypeBound::go (bound.get (), type.get_node_id ()); + ResolveTypeBound::go (bound.get ()); } void @@ -79,13 +79,13 @@ ResolveTraitItems::visit (AST::TraitItemFunc &func) } if (function.has_return_type ()) - ResolveType::go (function.get_return_type ().get (), func.get_node_id ()); + ResolveType::go (function.get_return_type ().get ()); // we make a new scope so the names of parameters are resolved and shadowed // correctly for (auto ¶m : function.get_function_params ()) { - ResolveType::go (param.get_type ().get (), param.get_node_id ()); + ResolveType::go (param.get_type ().get ()); PatternDeclaration::go (param.get_pattern ().get ()); } @@ -128,7 +128,7 @@ ResolveTraitItems::visit (AST::TraitItemMethod &func) } if (function.has_return_type ()) - ResolveType::go (function.get_return_type ().get (), func.get_node_id ()); + ResolveType::go (function.get_return_type ().get ()); // self turns into (self: Self) as a function param AST::SelfParam &self_param = function.get_self_param (); @@ -144,14 +144,14 @@ ResolveTraitItems::visit (AST::TraitItemMethod &func) AST::TypePath self_type_path (std::move (segments), self_param.get_locus ()); - ResolveType::go (&self_type_path, self_param.get_node_id ()); + ResolveType::go (&self_type_path); PatternDeclaration::go (&self_pattern); // we make a new scope so the names of parameters are resolved and shadowed // correctly for (auto ¶m : function.get_function_params ()) { - ResolveType::go (param.get_type ().get (), param.get_node_id ()); + ResolveType::go (param.get_type ().get ()); PatternDeclaration::go (param.get_pattern ().get ()); } @@ -177,7 +177,7 @@ ResolveTraitItems::visit (AST::TraitItemConst &constant) mappings->insert_canonical_path (mappings->get_current_crate (), constant.get_node_id (), cpath); - ResolveType::go (constant.get_type ().get (), constant.get_node_id ()); + ResolveType::go (constant.get_type ().get ()); if (constant.has_expr ()) ResolveExpr::go (constant.get_expr ().get (), path, cpath); @@ -218,7 +218,7 @@ ResolveItem::visit (AST::TypeAlias &alias) if (alias.has_where_clause ()) ResolveWhereClause::Resolve (alias.get_where_clause ()); - ResolveType::go (alias.get_type_aliased ().get (), alias.get_node_id ()); + ResolveType::go (alias.get_type_aliased ().get ()); resolver->get_type_scope ().pop (); } @@ -291,8 +291,7 @@ ResolveItem::visit (AST::TupleStruct &struct_decl) resolve_visibility (field.get_visibility ()); - ResolveType::go (field.get_field_type ().get (), - struct_decl.get_node_id ()); + ResolveType::go (field.get_field_type ().get ()); } resolver->get_type_scope ().pop (); @@ -361,7 +360,7 @@ ResolveItem::visit (AST::EnumItemTuple &item) if (field.get_field_type ()->is_marked_for_strip ()) continue; - ResolveType::go (field.get_field_type ().get (), item.get_node_id ()); + ResolveType::go (field.get_field_type ().get ()); } } @@ -380,7 +379,7 @@ ResolveItem::visit (AST::EnumItemStruct &item) if (field.get_field_type ()->is_marked_for_strip ()) continue; - ResolveType::go (field.get_field_type ().get (), item.get_node_id ()); + ResolveType::go (field.get_field_type ().get ()); } } @@ -429,8 +428,7 @@ ResolveItem::visit (AST::StructStruct &struct_decl) resolve_visibility (field.get_visibility ()); - ResolveType::go (field.get_field_type ().get (), - struct_decl.get_node_id ()); + ResolveType::go (field.get_field_type ().get ()); } resolver->get_type_scope ().pop (); @@ -467,8 +465,7 @@ ResolveItem::visit (AST::Union &union_decl) if (field.get_field_type ()->is_marked_for_strip ()) continue; - ResolveType::go (field.get_field_type ().get (), - union_decl.get_node_id ()); + ResolveType::go (field.get_field_type ().get ()); } resolver->get_type_scope ().pop (); @@ -484,7 +481,7 @@ ResolveItem::visit (AST::StaticItem &var) mappings->insert_canonical_path (mappings->get_current_crate (), var.get_node_id (), cpath); - ResolveType::go (var.get_type ().get (), var.get_node_id ()); + ResolveType::go (var.get_type ().get ()); ResolveExpr::go (var.get_expr ().get (), path, cpath); } @@ -500,7 +497,7 @@ ResolveItem::visit (AST::ConstantItem &constant) resolve_visibility (constant.get_visibility ()); - ResolveType::go (constant.get_type ().get (), constant.get_node_id ()); + ResolveType::go (constant.get_type ().get ()); ResolveExpr::go (constant.get_expr ().get (), path, cpath); } @@ -536,14 +533,13 @@ ResolveItem::visit (AST::Function &function) ResolveWhereClause::Resolve (function.get_where_clause ()); if (function.has_return_type ()) - ResolveType::go (function.get_return_type ().get (), - function.get_node_id ()); + ResolveType::go (function.get_return_type ().get ()); // we make a new scope so the names of parameters are resolved and shadowed // correctly for (auto ¶m : function.get_function_params ()) { - ResolveType::go (param.get_type ().get (), param.get_node_id ()); + ResolveType::go (param.get_type ().get ()); PatternDeclaration::go (param.get_pattern ().get ()); // the mutability checker needs to verify for immutable decls the number @@ -584,20 +580,20 @@ ResolveItem::visit (AST::InherentImpl &impl_block) // FIXME this needs to be protected behind nominal type-checks see: // rustc --explain E0118 - CanonicalPath self_cpath = CanonicalPath::create_empty (); - bool canonicalize_type_with_generics = false; - NodeId resolved_node - = ResolveType::go (impl_block.get_type ().get (), - canonicalize_type_with_generics, &self_cpath); + NodeId resolved_node = ResolveType::go (impl_block.get_type ().get ()); if (resolved_node == UNKNOWN_NODEID) { resolver->get_type_scope ().pop (); resolver->get_name_scope ().pop (); return; } - rust_assert (!self_cpath.is_empty ()); // Setup paths + CanonicalPath self_cpath = CanonicalPath::create_empty (); + bool ok = ResolveTypeToCanonicalPath::go (impl_block.get_type ().get (), + self_cpath); + rust_assert (ok); + std::string raw_impl_type_path = impl_block.get_type ()->as_string (); CanonicalPath impl_type = CanonicalPath::new_seg (impl_block.get_type ()->get_node_id (), @@ -671,7 +667,7 @@ ResolveItem::visit (AST::Method &method) ResolveWhereClause::Resolve (method.get_where_clause ()); if (method.has_return_type ()) - ResolveType::go (method.get_return_type ().get (), method.get_node_id ()); + ResolveType::go (method.get_return_type ().get ()); // self turns into (self: Self) as a function param AST::SelfParam &self_param = method.get_self_param (); @@ -687,14 +683,14 @@ ResolveItem::visit (AST::Method &method) AST::TypePath self_type_path (std::move (segments), self_param.get_locus ()); - ResolveType::go (&self_type_path, self_param.get_node_id ()); + ResolveType::go (&self_type_path); PatternDeclaration::go (&self_pattern); // we make a new scope so the names of parameters are resolved and shadowed // correctly for (auto ¶m : method.get_function_params ()) { - ResolveType::go (param.get_type ().get (), param.get_node_id ()); + ResolveType::go (param.get_type ().get ()); PatternDeclaration::go (param.get_pattern ().get ()); } @@ -734,11 +730,8 @@ ResolveItem::visit (AST::TraitImpl &impl_block) if (impl_block.has_where_clause ()) ResolveWhereClause::Resolve (impl_block.get_where_clause ()); - CanonicalPath canonical_trait_type = CanonicalPath::create_empty (); - bool canonicalize_type_with_generics = false; - NodeId trait_resolved_node - = ResolveType::go (&impl_block.get_trait_path (), - canonicalize_type_with_generics, &canonical_trait_type); + // CanonicalPath canonical_trait_type = CanonicalPath::create_empty (); + NodeId trait_resolved_node = ResolveType::go (&impl_block.get_trait_path ()); if (trait_resolved_node == UNKNOWN_NODEID) { resolver->get_type_scope ().pop (); @@ -746,19 +739,28 @@ ResolveItem::visit (AST::TraitImpl &impl_block) return; } - CanonicalPath canonical_impl_type = CanonicalPath::create_empty (); - NodeId type_resolved_node - = ResolveType::go (impl_block.get_type ().get (), - canonicalize_type_with_generics, &canonical_impl_type); + // CanonicalPath canonical_impl_type = CanonicalPath::create_empty (); + NodeId type_resolved_node = ResolveType::go (impl_block.get_type ().get ()); if (type_resolved_node == UNKNOWN_NODEID) { resolver->get_type_scope ().pop (); resolver->get_name_scope ().pop (); return; } - rust_assert (!canonical_impl_type.is_empty ()); + bool ok; // setup paths + CanonicalPath canonical_trait_type = CanonicalPath::create_empty (); + ok = ResolveTypeToCanonicalPath::go (&impl_block.get_trait_path (), + canonical_trait_type); + rust_assert (ok); + + CanonicalPath canonical_impl_type = CanonicalPath::create_empty (); + ok = ResolveTypeToCanonicalPath::go (impl_block.get_type ().get (), + canonical_impl_type); + rust_assert (ok); + + // raw paths std::string raw_impl_type_path = impl_block.get_type ()->as_string (); CanonicalPath impl_type_seg = CanonicalPath::new_seg (impl_block.get_type ()->get_node_id (), @@ -846,7 +848,7 @@ ResolveItem::visit (AST::Trait &trait) { for (auto &bound : trait.get_type_param_bounds ()) { - ResolveTypeBound::go (bound.get (), trait.get_node_id ()); + ResolveTypeBound::go (bound.get ()); } } @@ -1096,14 +1098,13 @@ ResolveExternItem::visit (AST::ExternalFunctionItem &function) } if (function.has_return_type ()) - ResolveType::go (function.get_return_type ().get (), - function.get_node_id ()); + ResolveType::go (function.get_return_type ().get ()); // we make a new scope so the names of parameters are resolved and shadowed // correctly for (auto ¶m : function.get_function_params ()) { - ResolveType::go (param.get_type ().get (), param.get_node_id ()); + ResolveType::go (param.get_type ().get ()); } // done @@ -1117,7 +1118,7 @@ ResolveExternItem::visit (AST::ExternalStaticItem &item) { resolve_visibility (item.get_visibility ()); - ResolveType::go (item.get_type ().get (), item.get_node_id ()); + ResolveType::go (item.get_type ().get ()); } } // namespace Resolver diff --git a/gcc/rust/resolve/rust-ast-resolve-path.cc b/gcc/rust/resolve/rust-ast-resolve-path.cc index a6940d4..3c69b65 100644 --- a/gcc/rust/resolve/rust-ast-resolve-path.cc +++ b/gcc/rust/resolve/rust-ast-resolve-path.cc @@ -216,10 +216,8 @@ void ResolvePath::resolve_path (AST::QualifiedPathInExpression *expr) { AST::QualifiedPathType &root_segment = expr->get_qualified_path_type (); - ResolveType::go (&root_segment.get_as_type_path (), - root_segment.get_node_id ()); - ResolveType::go (root_segment.get_type ().get (), - root_segment.get_node_id ()); + ResolveType::go (&root_segment.get_as_type_path ()); + ResolveType::go (root_segment.get_type ().get ()); for (auto &segment : expr->get_segments ()) { diff --git a/gcc/rust/resolve/rust-ast-resolve-stmt.h b/gcc/rust/resolve/rust-ast-resolve-stmt.h index 1d2ecd3..202a280 100644 --- a/gcc/rust/resolve/rust-ast-resolve-stmt.h +++ b/gcc/rust/resolve/rust-ast-resolve-stmt.h @@ -71,7 +71,7 @@ public: rust_error_at (r, "redefined multiple times"); }); - ResolveType::go (constant.get_type ().get (), constant.get_node_id ()); + ResolveType::go (constant.get_type ().get ()); ResolveExpr::go (constant.get_expr ().get (), prefix, canonical_prefix); } @@ -85,7 +85,7 @@ public: PatternDeclaration::go (stmt.get_pattern ().get ()); if (stmt.has_type ()) - ResolveType::go (stmt.get_type ().get (), stmt.get_node_id ()); + ResolveType::go (stmt.get_type ().get ()); } void visit (AST::TupleStruct &struct_decl) override @@ -117,8 +117,7 @@ public: } for (AST::TupleField &field : struct_decl.get_fields ()) - ResolveType::go (field.get_field_type ().get (), - struct_decl.get_node_id ()); + ResolveType::go (field.get_field_type ().get ()); resolver->get_type_scope ().pop (); } @@ -199,7 +198,7 @@ public: if (field.get_field_type ()->is_marked_for_strip ()) continue; - ResolveType::go (field.get_field_type ().get (), item.get_node_id ()); + ResolveType::go (field.get_field_type ().get ()); } } @@ -225,7 +224,7 @@ public: if (field.get_field_type ()->is_marked_for_strip ()) continue; - ResolveType::go (field.get_field_type ().get (), item.get_node_id ()); + ResolveType::go (field.get_field_type ().get ()); } } @@ -282,8 +281,7 @@ public: if (field.get_field_type ()->is_marked_for_strip ()) continue; - ResolveType::go (field.get_field_type ().get (), - struct_decl.get_node_id ()); + ResolveType::go (field.get_field_type ().get ()); } resolver->get_type_scope ().pop (); @@ -322,8 +320,7 @@ public: if (field.get_field_type ()->is_marked_for_strip ()) continue; - ResolveType::go (field.get_field_type ().get (), - union_decl.get_node_id ()); + ResolveType::go (field.get_field_type ().get ()); } resolver->get_type_scope ().pop (); @@ -361,14 +358,13 @@ public: } if (function.has_return_type ()) - ResolveType::go (function.get_return_type ().get (), - function.get_node_id ()); + ResolveType::go (function.get_return_type ().get ()); // we make a new scope so the names of parameters are resolved and shadowed // correctly for (auto ¶m : function.get_function_params ()) { - ResolveType::go (param.get_type ().get (), param.get_node_id ()); + ResolveType::go (param.get_type ().get ()); PatternDeclaration::go (param.get_pattern ().get ()); } diff --git a/gcc/rust/resolve/rust-ast-resolve-type.cc b/gcc/rust/resolve/rust-ast-resolve-type.cc index 4260ec4..5d0ceb5 100644 --- a/gcc/rust/resolve/rust-ast-resolve-type.cc +++ b/gcc/rust/resolve/rust-ast-resolve-type.cc @@ -35,7 +35,7 @@ ResolveType::visit (AST::ArrayType &type) void ResolveType::visit (AST::TraitObjectTypeOneBound &type) { - ResolveTypeBound::go (&type.get_trait_bound (), type.get_node_id ()); + ResolveTypeBound::go (&type.get_trait_bound ()); } void @@ -44,40 +44,20 @@ ResolveType::visit (AST::TraitObjectType &type) for (auto &bound : type.get_type_param_bounds ()) { /* NodeId bound_resolved_id = */ - ResolveTypeBound::go (bound.get (), type.get_node_id ()); + ResolveTypeBound::go (bound.get ()); } } void ResolveType::visit (AST::ReferenceType &type) { - CanonicalPath path = CanonicalPath::create_empty (); - resolved_node = ResolveType::go (type.get_type_referenced ().get (), - canonicalize_type_with_generics, &path); - if (canonical_path != nullptr) - { - std::string ref_type_str = type.is_mut () ? "mut" : ""; - std::string ref_path = "&" + ref_type_str + " " + path.get (); - *canonical_path = canonical_path->append ( - CanonicalPath::new_seg (type.get_node_id (), ref_path)); - } + resolved_node = ResolveType::go (type.get_type_referenced ().get ()); } void ResolveType::visit (AST::RawPointerType &type) { - CanonicalPath path = CanonicalPath::create_empty (); - resolved_node = ResolveType::go (type.get_type_pointed_to ().get (), - canonicalize_type_with_generics, &path); - if (canonical_path != nullptr) - { - std::string ptr_type_str - = type.get_pointer_type () == AST::RawPointerType::CONST ? "const" - : "mut"; - std::string ptr_path = "*" + ptr_type_str + " " + path.get (); - *canonical_path = canonical_path->append ( - CanonicalPath::new_seg (type.get_node_id (), ptr_path)); - } + resolved_node = ResolveType::go (type.get_type_pointed_to ().get ()); } void @@ -95,15 +75,7 @@ ResolveType::visit (AST::NeverType &type) void ResolveType::visit (AST::SliceType &type) { - CanonicalPath path = CanonicalPath::create_empty (); - resolved_node = ResolveType::go (type.get_elem_type ().get (), - canonicalize_type_with_generics, &path); - if (canonical_path != nullptr) - { - std::string slice_path = "[" + path.get () + "]"; - *canonical_path = canonical_path->append ( - CanonicalPath::new_seg (type.get_node_id (), slice_path)); - } + resolved_node = ResolveType::go (type.get_elem_type ().get ()); } // resolve relative type-paths @@ -159,7 +131,7 @@ ResolveRelativeTypePath::go (AST::TypePath &path, NodeId &resolved_node_id) { for (auto > : s->get_generic_args ().get_type_args ()) { - ResolveType::go (gt.get (), UNKNOWN_NODEID); + ResolveType::go (gt.get ()); } } } @@ -317,15 +289,14 @@ ResolveRelativeQualTypePath::resolve_qual_seg (AST::QualifiedPathType &seg) } auto type = seg.get_type ().get (); - NodeId type_resolved_node = ResolveType::go (type, seg.get_node_id ()); + NodeId type_resolved_node = ResolveType::go (type); if (type_resolved_node == UNKNOWN_NODEID) return false; if (!seg.has_as_clause ()) return true; - NodeId trait_resolved_node - = ResolveType::go (&seg.get_as_type_path (), seg.get_node_id ()); + NodeId trait_resolved_node = ResolveType::go (&seg.get_as_type_path ()); if (trait_resolved_node == UNKNOWN_NODEID) return false; @@ -358,5 +329,82 @@ ResolveRelativeQualTypePath::visit (AST::TypePathSegment &seg) } } +// resolve to canonical path + +bool +ResolveTypeToCanonicalPath::go (AST::Type *type, CanonicalPath &result) +{ + ResolveTypeToCanonicalPath resolver; + type->accept_vis (resolver); + result = resolver.result; + return !resolver.result.is_empty (); +} + +void +ResolveTypeToCanonicalPath::visit (AST::TypePath &path) +{ + NodeId resolved_node = UNKNOWN_NODEID; + if (!resolver->lookup_resolved_name (path.get_node_id (), &resolved_node)) + { + resolver->lookup_resolved_type (path.get_node_id (), &resolved_node); + } + + if (resolved_node == UNKNOWN_NODEID) + return; + + const CanonicalPath *type_path = nullptr; + if (mappings->lookup_canonical_path (mappings->get_current_crate (), + resolved_node, &type_path)) + { + result = *type_path; + } +} + +void +ResolveTypeToCanonicalPath::visit (AST::ReferenceType &type) +{ + CanonicalPath path = CanonicalPath::create_empty (); + bool ok + = ResolveTypeToCanonicalPath::go (type.get_type_referenced ().get (), path); + if (ok) + { + std::string ref_type_str = type.is_mut () ? "mut" : ""; + std::string ref_path = "&" + ref_type_str + " " + path.get (); + result = CanonicalPath::new_seg (type.get_node_id (), ref_path); + } +} + +void +ResolveTypeToCanonicalPath::visit (AST::RawPointerType &type) +{ + CanonicalPath path = CanonicalPath::create_empty (); + bool ok + = ResolveTypeToCanonicalPath::go (type.get_type_pointed_to ().get (), path); + if (ok) + { + std::string ptr_type_str + = type.get_pointer_type () == AST::RawPointerType::CONST ? "const" + : "mut"; + std::string ptr_path = "*" + ptr_type_str + " " + path.get (); + result = CanonicalPath::new_seg (type.get_node_id (), ptr_path); + } +} + +void +ResolveTypeToCanonicalPath::visit (AST::SliceType &type) +{ + CanonicalPath path = CanonicalPath::create_empty (); + bool ok = ResolveTypeToCanonicalPath::go (type.get_elem_type ().get (), path); + if (ok) + { + std::string slice_path = "[" + path.get () + "]"; + result = CanonicalPath::new_seg (type.get_node_id (), slice_path); + } +} + +ResolveTypeToCanonicalPath::ResolveTypeToCanonicalPath () + : ResolverBase (), result (CanonicalPath::create_empty ()) +{} + } // namespace Resolver } // namespace Rust diff --git a/gcc/rust/resolve/rust-ast-resolve-type.h b/gcc/rust/resolve/rust-ast-resolve-type.h index 664e688..965df42 100644 --- a/gcc/rust/resolve/rust-ast-resolve-type.h +++ b/gcc/rust/resolve/rust-ast-resolve-type.h @@ -56,11 +56,9 @@ class ResolveType : public ResolverBase using Rust::Resolver::ResolverBase::visit; public: - static NodeId go (AST::Type *type, - bool canonicalize_type_with_generics = false, - CanonicalPath *canonical_path = nullptr) + static NodeId go (AST::Type *type) { - ResolveType resolver (canonicalize_type_with_generics, canonical_path); + ResolveType resolver; type->accept_vis (resolver); return resolver.resolved_node; } @@ -74,10 +72,10 @@ public: void visit (AST::BareFunctionType &fntype) override { for (auto ¶m : fntype.get_function_params ()) - ResolveType::go (param.get_type ().get (), fntype.get_node_id ()); + ResolveType::go (param.get_type ().get ()); if (fntype.has_return_type ()) - ResolveType::go (fntype.get_return_type ().get (), fntype.get_node_id ()); + ResolveType::go (fntype.get_return_type ().get ()); } void visit (AST::TupleType &tuple) override @@ -89,23 +87,12 @@ public: } for (auto &elem : tuple.get_elems ()) - ResolveType::go (elem.get (), tuple.get_node_id ()); + ResolveType::go (elem.get ()); } void visit (AST::TypePath &path) override { - if (ResolveRelativeTypePath::go (path, resolved_node)) - { - if (canonical_path == nullptr) - return; - - const CanonicalPath *type_path = nullptr; - if (mappings->lookup_canonical_path (mappings->get_current_crate (), - resolved_node, &type_path)) - { - *canonical_path = *type_path; - } - } + ResolveRelativeTypePath::go (path, resolved_node); } void visit (AST::QualifiedPathInType &path) override @@ -130,15 +117,7 @@ public: void visit (AST::SliceType &type) override; private: - ResolveType (bool canonicalize_type_with_generics, - CanonicalPath *canonical_path) - : ResolverBase (), - canonicalize_type_with_generics (canonicalize_type_with_generics), - canonical_path (canonical_path) - {} - - bool canonicalize_type_with_generics; - CanonicalPath *canonical_path; + ResolveType () : ResolverBase () {} }; class ResolveTypeBound : public ResolverBase @@ -146,27 +125,20 @@ class ResolveTypeBound : public ResolverBase using Rust::Resolver::ResolverBase::visit; public: - static NodeId go (AST::TypeParamBound *type, - bool canonicalize_type_with_generics = false) + static NodeId go (AST::TypeParamBound *type) { - ResolveTypeBound resolver (canonicalize_type_with_generics); + ResolveTypeBound resolver; type->accept_vis (resolver); return resolver.resolved_node; }; void visit (AST::TraitBound &bound) override { - resolved_node = ResolveType::go (&bound.get_type_path (), - canonicalize_type_with_generics); + resolved_node = ResolveType::go (&bound.get_type_path ()); } private: - ResolveTypeBound (bool canonicalize_type_with_generics) - : ResolverBase (), - canonicalize_type_with_generics (canonicalize_type_with_generics) - {} - - bool canonicalize_type_with_generics; + ResolveTypeBound () : ResolverBase () {} }; class ResolveGenericParam : public ResolverBase @@ -191,13 +163,13 @@ public: { // if it has a type lets resolve it if (param.has_type ()) - ResolveType::go (param.get_type ().get (), param.get_node_id ()); + ResolveType::go (param.get_type ().get ()); if (param.has_type_param_bounds ()) { for (auto &bound : param.get_type_param_bounds ()) { - ResolveTypeBound::go (bound.get (), param.get_node_id ()); + ResolveTypeBound::go (bound.get ()); } } @@ -233,12 +205,12 @@ public: void visit (AST::TypeBoundWhereClauseItem &item) override { - ResolveType::go (item.get_type ().get (), item.get_node_id ()); + ResolveType::go (item.get_type ().get ()); if (item.has_type_param_bounds ()) { for (auto &bound : item.get_type_param_bounds ()) { - ResolveTypeBound::go (bound.get (), item.get_node_id ()); + ResolveTypeBound::go (bound.get ()); } } } @@ -247,6 +219,27 @@ private: ResolveWhereClause () : ResolverBase () {} }; +class ResolveTypeToCanonicalPath : public ResolverBase +{ + using Rust::Resolver::ResolverBase::visit; + +public: + static bool go (AST::Type *type, CanonicalPath &result); + + void visit (AST::TypePath &path) override; + + void visit (AST::ReferenceType &type) override; + + void visit (AST::RawPointerType &type) override; + + void visit (AST::SliceType &type) override; + +private: + ResolveTypeToCanonicalPath (); + + CanonicalPath result; +}; + } // namespace Resolver } // namespace Rust |