diff options
Diffstat (limited to 'gcc/rust/resolve')
-rw-r--r-- | gcc/rust/resolve/rust-ast-resolve-base.cc | 8 | ||||
-rw-r--r-- | gcc/rust/resolve/rust-ast-resolve-base.h | 2 | ||||
-rw-r--r-- | gcc/rust/resolve/rust-ast-resolve-item.cc | 27 | ||||
-rw-r--r-- | gcc/rust/resolve/rust-ast-resolve-type.cc | 79 | ||||
-rw-r--r-- | gcc/rust/resolve/rust-ast-resolve-type.h | 31 | ||||
-rw-r--r-- | gcc/rust/resolve/rust-late-name-resolver-2.0.cc | 19 | ||||
-rw-r--r-- | gcc/rust/resolve/rust-late-name-resolver-2.0.h | 1 |
7 files changed, 52 insertions, 115 deletions
diff --git a/gcc/rust/resolve/rust-ast-resolve-base.cc b/gcc/rust/resolve/rust-ast-resolve-base.cc index 74b2756..9cc980a 100644 --- a/gcc/rust/resolve/rust-ast-resolve-base.cc +++ b/gcc/rust/resolve/rust-ast-resolve-base.cc @@ -72,14 +72,6 @@ ResolverBase::visit (AST::ConstGenericParam &) {} void -ResolverBase::visit (AST::RegularPath &) -{} - -void -ResolverBase::visit (AST::LangItemPath &) -{} - -void ResolverBase::visit (AST::PathInExpression &) {} diff --git a/gcc/rust/resolve/rust-ast-resolve-base.h b/gcc/rust/resolve/rust-ast-resolve-base.h index bc3e048..7f01d50 100644 --- a/gcc/rust/resolve/rust-ast-resolve-base.h +++ b/gcc/rust/resolve/rust-ast-resolve-base.h @@ -40,8 +40,6 @@ public: void visit (AST::Lifetime &); void visit (AST::LifetimeParam &); void visit (AST::ConstGenericParam &); - void visit (AST::RegularPath &); - void visit (AST::LangItemPath &); void visit (AST::PathInExpression &); void visit (AST::TypePathSegment &); void visit (AST::TypePathSegmentGeneric &); diff --git a/gcc/rust/resolve/rust-ast-resolve-item.cc b/gcc/rust/resolve/rust-ast-resolve-item.cc index 619efb0..ca09c2e 100644 --- a/gcc/rust/resolve/rust-ast-resolve-item.cc +++ b/gcc/rust/resolve/rust-ast-resolve-item.cc @@ -682,28 +682,15 @@ ResolveItem::visit (AST::TraitImpl &impl_block) // setup paths CanonicalPath canonical_trait_type = CanonicalPath::create_empty (); - if (impl_block.get_trait_path ().get_path_kind () - == AST::Path::Kind::LangItem) - { - auto &lang_item - = static_cast<AST::LangItemPath &> (impl_block.get_trait_path ()); - canonical_trait_type - = CanonicalPath::new_seg (lang_item.get_node_id (), - LangItem::ToString ( - lang_item.get_lang_item_kind ())); - } - else + ok = ResolveTypeToCanonicalPath::go (impl_block.get_trait_path (), + canonical_trait_type); + if (!ok) { - ok = ResolveTypeToCanonicalPath::go (impl_block.get_trait_path_type (), - canonical_trait_type); - if (!ok) - { - resolver->get_name_scope ().pop (); - resolver->get_type_scope ().pop (); - resolver->get_label_scope ().pop (); - return; - } + resolver->get_name_scope ().pop (); + resolver->get_type_scope ().pop (); + resolver->get_label_scope ().pop (); + return; } rust_debug ("AST::TraitImpl resolve trait type: {%s}", diff --git a/gcc/rust/resolve/rust-ast-resolve-type.cc b/gcc/rust/resolve/rust-ast-resolve-type.cc index a4878a2..6cd8571 100644 --- a/gcc/rust/resolve/rust-ast-resolve-type.cc +++ b/gcc/rust/resolve/rust-ast-resolve-type.cc @@ -20,6 +20,7 @@ #include "rust-ast-resolve-expr.h" #include "rust-canonical-path.h" #include "rust-type.h" +#include "rust-hir-map.h" namespace Rust { namespace Resolver { @@ -99,45 +100,57 @@ ResolveRelativeTypePath::go (AST::TypePath &path, NodeId &resolved_node_id) for (size_t i = 0; i < path.get_segments ().size (); i++) { auto &segment = path.get_segments ().at (i); - const AST::PathIdentSegment &ident_seg = segment->get_ident_segment (); bool is_first_segment = i == 0; - resolved_node_id = UNKNOWN_NODEID; + NodeId crate_scope_id = resolver->peek_crate_module_scope (); + auto ident_string = segment->is_lang_item () + ? LangItem::PrettyString (segment->get_lang_item ()) + : segment->get_ident_segment ().as_string (); - bool in_middle_of_path = i > 0; - if (in_middle_of_path && segment->is_lower_self_seg ()) - { - rust_error_at (segment->get_locus (), ErrorCode::E0433, - "failed to resolve: %<%s%> in paths can only be used " - "in start position", - segment->as_string ().c_str ()); - return false; - } + resolved_node_id = UNKNOWN_NODEID; - NodeId crate_scope_id = resolver->peek_crate_module_scope (); - if (segment->is_crate_path_seg ()) + if (segment->is_lang_item ()) { - // what is the current crate scope node id? - module_scope_id = crate_scope_id; - previous_resolved_node_id = module_scope_id; - resolver->insert_resolved_name (segment->get_node_id (), - module_scope_id); - - continue; + resolved_node_id = Analysis::Mappings::get ().get_lang_item_node ( + segment->get_lang_item ()); + previous_resolved_node_id = resolved_node_id; } - else if (segment->is_super_path_seg ()) + else { - if (module_scope_id == crate_scope_id) + bool in_middle_of_path = i > 0; + if (in_middle_of_path && segment->is_lower_self_seg ()) { - rust_error_at (segment->get_locus (), - "cannot use super at the crate scope"); + rust_error_at (segment->get_locus (), ErrorCode::E0433, + "failed to resolve: %qs in paths can only be used " + "in start position", + segment->as_string ().c_str ()); return false; } - module_scope_id = resolver->peek_parent_module_scope (); - previous_resolved_node_id = module_scope_id; - resolver->insert_resolved_name (segment->get_node_id (), - module_scope_id); - continue; + if (segment->is_crate_path_seg ()) + { + // what is the current crate scope node id? + module_scope_id = crate_scope_id; + previous_resolved_node_id = module_scope_id; + resolver->insert_resolved_name (segment->get_node_id (), + module_scope_id); + + continue; + } + else if (segment->is_super_path_seg ()) + { + if (module_scope_id == crate_scope_id) + { + rust_error_at (segment->get_locus (), + "cannot use super at the crate scope"); + return false; + } + + module_scope_id = resolver->peek_parent_module_scope (); + previous_resolved_node_id = module_scope_id; + resolver->insert_resolved_name (segment->get_node_id (), + module_scope_id); + continue; + } } switch (segment->get_type ()) @@ -177,8 +190,7 @@ ResolveRelativeTypePath::go (AST::TypePath &path, NodeId &resolved_node_id) // name scope first NodeId resolved_node = UNKNOWN_NODEID; const CanonicalPath path - = CanonicalPath::new_seg (segment->get_node_id (), - ident_seg.as_string ()); + = CanonicalPath::new_seg (segment->get_node_id (), ident_string); if (resolver->get_type_scope ().lookup (path, &resolved_node)) { resolver->insert_resolved_type (segment->get_node_id (), @@ -191,7 +203,7 @@ ResolveRelativeTypePath::go (AST::TypePath &path, NodeId &resolved_node_id) resolved_node); resolved_node_id = resolved_node; } - else if (segment->is_lower_self_seg ()) + else if (!segment->is_lang_item () && segment->is_lower_self_seg ()) { // what is the current crate scope node id? module_scope_id = crate_scope_id; @@ -207,8 +219,7 @@ ResolveRelativeTypePath::go (AST::TypePath &path, NodeId &resolved_node_id) && previous_resolved_node_id == module_scope_id) { tl::optional<CanonicalPath &> resolved_child - = mappings.lookup_module_child (module_scope_id, - ident_seg.as_string ()); + = mappings.lookup_module_child (module_scope_id, ident_string); if (resolved_child.has_value ()) { NodeId resolved_node = resolved_child->get_node_id (); diff --git a/gcc/rust/resolve/rust-ast-resolve-type.h b/gcc/rust/resolve/rust-ast-resolve-type.h index 3a7dbd6..5870aca 100644 --- a/gcc/rust/resolve/rust-ast-resolve-type.h +++ b/gcc/rust/resolve/rust-ast-resolve-type.h @@ -61,37 +61,6 @@ class ResolveType : public ResolverBase using Rust::Resolver::ResolverBase::visit; public: - static NodeId go (AST::TypePath &type_path) - { - return ResolveType::go ((AST::Type &) type_path); - } - - static NodeId go (AST::Path &type_path) - { - if (type_path.get_path_kind () == AST::Path::Kind::LangItem) - { - auto &type = static_cast<AST::LangItemPath &> (type_path); - - auto lang_item = Analysis::Mappings::get () - .lookup_lang_item_node (type.get_lang_item_kind ()) - .value (); - - auto resolver = Resolver::get (); - resolver->insert_resolved_type (type.get_node_id (), lang_item); - - return lang_item; - } - - rust_assert (type_path.get_path_kind () == AST::Path::Kind::Type); - - // We have to do this dance to first downcast to a typepath, and then upcast - // to a Type. The altnernative is to split `go` into `go` and `go_inner` or - // something, but eventually this will need to change as we'll need - // `ResolveType::` to resolve other kinds of `Path`s as well. - return ResolveType::go ( - (AST::Type &) static_cast<AST::TypePath &> (type_path)); - } - static NodeId go (AST::Type &type) { ResolveType resolver; diff --git a/gcc/rust/resolve/rust-late-name-resolver-2.0.cc b/gcc/rust/resolve/rust-late-name-resolver-2.0.cc index 974e1fa..60b8952 100644 --- a/gcc/rust/resolve/rust-late-name-resolver-2.0.cc +++ b/gcc/rust/resolve/rust-late-name-resolver-2.0.cc @@ -249,25 +249,6 @@ Late::visit (AST::PathInExpression &expr) } void -Late::visit (AST::LangItemPath &type) -{ - auto &mappings = Rust::Analysis::Mappings::get (); - auto lang_item = mappings.lookup_lang_item_node (type.get_lang_item_kind ()); - - if (!lang_item) - { - rust_fatal_error ( - type.get_locus (), "use of undeclared lang item %qs", - LangItem::ToString (type.get_lang_item_kind ()).c_str ()); - return; - } - - ctx.map_usage (Usage (type.get_node_id ()), Definition (lang_item.value ())); - - DefaultResolver::visit (type); -} - -void Late::visit (AST::TypePath &type) { // should we add type path resolution in `ForeverStack` directly? Since it's diff --git a/gcc/rust/resolve/rust-late-name-resolver-2.0.h b/gcc/rust/resolve/rust-late-name-resolver-2.0.h index 0db21f2..0efa693 100644 --- a/gcc/rust/resolve/rust-late-name-resolver-2.0.h +++ b/gcc/rust/resolve/rust-late-name-resolver-2.0.h @@ -46,7 +46,6 @@ public: // resolutions void visit (AST::IdentifierExpr &) override; void visit (AST::PathInExpression &) override; - void visit (AST::LangItemPath &) override; void visit (AST::TypePath &) override; void visit (AST::Trait &) override; void visit (AST::StructExprStruct &) override; |