diff options
author | Philip Herron <philip.herron@embecosm.com> | 2022-06-28 13:13:15 +0100 |
---|---|---|
committer | Philip Herron <philip.herron@embecosm.com> | 2022-06-28 13:13:15 +0100 |
commit | eb88a919f5395e9000126a8c78c97591711383a4 (patch) | |
tree | ea1659bc89f422da686c12a47b095dc821a85907 | |
parent | 964969d4c608b058f37fafaef5e7f0f9ab7aef83 (diff) | |
download | gcc-eb88a919f5395e9000126a8c78c97591711383a4.zip gcc-eb88a919f5395e9000126a8c78c97591711383a4.tar.gz gcc-eb88a919f5395e9000126a8c78c97591711383a4.tar.bz2 |
refactor qualified type path resolution from the ResolveRelativeTypePathClass
-rw-r--r-- | gcc/rust/resolve/rust-ast-resolve-type.cc | 73 | ||||
-rw-r--r-- | gcc/rust/resolve/rust-ast-resolve-type.h | 22 |
2 files changed, 87 insertions, 8 deletions
diff --git a/gcc/rust/resolve/rust-ast-resolve-type.cc b/gcc/rust/resolve/rust-ast-resolve-type.cc index c5fe325..902f034 100644 --- a/gcc/rust/resolve/rust-ast-resolve-type.cc +++ b/gcc/rust/resolve/rust-ast-resolve-type.cc @@ -219,11 +219,15 @@ ResolveType::visit (AST::RawPointerType &type) void ResolveType::visit (AST::InferredType &type) -{} +{ + // FIXME +} void ResolveType::visit (AST::NeverType &type) -{} +{ + // FIXME +} void ResolveType::visit (AST::SliceType &type) @@ -239,6 +243,8 @@ ResolveType::visit (AST::SliceType &type) } } +// resolve relative type-paths + ResolveRelativeTypePath::ResolveRelativeTypePath (CanonicalPath qualified_path) : ResolveTypeToCanonicalPath (true, true) { @@ -408,11 +414,18 @@ ResolveRelativeTypePath::go (AST::TypePath &path, NodeId &resolved_node_id) return true; } +// qualified type paths + +ResolveRelativeQualTypePath::ResolveRelativeQualTypePath ( + CanonicalPath qualified_path) + : result (qualified_path), failure_flag (false) +{} + bool -ResolveRelativeTypePath::go (AST::QualifiedPathInType &path) +ResolveRelativeQualTypePath::go (AST::QualifiedPathInType &path) { CanonicalPath result = CanonicalPath::create_empty (); - ResolveRelativeTypePath o (result); + ResolveRelativeQualTypePath o (result); // resolve the type and trait path auto &qualified_path = path.get_qualified_path_type (); @@ -441,8 +454,8 @@ ResolveRelativeTypePath::go (AST::QualifiedPathInType &path) } bool -ResolveRelativeTypePath::resolve_qual_seg (AST::QualifiedPathType &seg, - CanonicalPath &result) +ResolveRelativeQualTypePath::resolve_qual_seg (AST::QualifiedPathType &seg, + CanonicalPath &result) { if (seg.is_error ()) { @@ -487,5 +500,53 @@ ResolveRelativeTypePath::resolve_qual_seg (AST::QualifiedPathType &seg, return true; } +void +ResolveRelativeQualTypePath::visit (AST::TypePathSegmentGeneric &seg) +{ + if (seg.is_error ()) + { + failure_flag = true; + rust_error_at (seg.get_locus (), "segment has error: %s", + seg.as_string ().c_str ()); + return; + } + + if (!seg.has_generic_args ()) + { + auto ident_segment + = CanonicalPath::new_seg (seg.get_node_id (), + seg.get_ident_segment ().as_string ()); + result = result.append (ident_segment); + return; + } + + ResolveType::type_resolve_generic_args (seg.get_generic_args ()); + + std::string generics = ResolveTypeToCanonicalPath::canonicalize_generic_args ( + seg.get_generic_args ()); + auto generic_segment + = CanonicalPath::new_seg (seg.get_node_id (), + seg.get_ident_segment ().as_string () + + "::" + generics); + result = result.append (generic_segment); +} + +void +ResolveRelativeQualTypePath::visit (AST::TypePathSegment &seg) +{ + if (seg.is_error ()) + { + failure_flag = true; + rust_error_at (seg.get_locus (), "segment has error: %s", + seg.as_string ().c_str ()); + return; + } + + CanonicalPath ident_seg + = CanonicalPath::new_seg (seg.get_node_id (), + seg.get_ident_segment ().as_string ()); + result = result.append (ident_seg); +} + } // 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 8f52c3e..8bbb587 100644 --- a/gcc/rust/resolve/rust-ast-resolve-type.h +++ b/gcc/rust/resolve/rust-ast-resolve-type.h @@ -85,12 +85,30 @@ class ResolveRelativeTypePath : public ResolveTypeToCanonicalPath public: static bool go (AST::TypePath &path, NodeId &resolved_node_id); - static bool go (AST::QualifiedPathInType &path); private: ResolveRelativeTypePath (CanonicalPath qualified_path); +}; + +class ResolveRelativeQualTypePath : public ResolverBase +{ + using ResolverBase::visit; + +public: + static bool go (AST::QualifiedPathInType &path); + + void visit (AST::TypePathSegmentGeneric &seg) override; + void visit (AST::TypePathSegment &seg) override; + +protected: bool resolve_qual_seg (AST::QualifiedPathType &seg, CanonicalPath &result); + +private: + ResolveRelativeQualTypePath (CanonicalPath qualified_path); + + CanonicalPath result; + bool failure_flag; }; class ResolveType : public ResolverBase @@ -152,7 +170,7 @@ public: void visit (AST::QualifiedPathInType &path) override { - ResolveRelativeTypePath::go (path); + ResolveRelativeQualTypePath::go (path); } void visit (AST::ArrayType &type) override; |