public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc/devel/rust/master] refactor qualified type path resolution from the ResolveRelativeTypePathClass
@ 2022-06-29 10:27 Thomas Schwinge
0 siblings, 0 replies; only message in thread
From: Thomas Schwinge @ 2022-06-29 10:27 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:eb88a919f5395e9000126a8c78c97591711383a4
commit eb88a919f5395e9000126a8c78c97591711383a4
Author: Philip Herron <philip.herron@embecosm.com>
Date: Tue Jun 28 13:13:15 2022 +0100
refactor qualified type path resolution from the ResolveRelativeTypePathClass
Diff:
---
gcc/rust/resolve/rust-ast-resolve-type.cc | 73 ++++++++++++++++++++++++++++---
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 c5fe325c67f..902f034781e 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 8f52c3ed08d..8bbb587cb6f 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;
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2022-06-29 10:27 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-29 10:27 [gcc/devel/rust/master] refactor qualified type path resolution from the ResolveRelativeTypePathClass Thomas Schwinge
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).