public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc/devel/rust/master] ast: Resolver: Refactor ResolveRelativeTypePath in its own source file
@ 2022-06-08 12:41 Thomas Schwinge
0 siblings, 0 replies; only message in thread
From: Thomas Schwinge @ 2022-06-08 12:41 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:98e1de2d8fdc0f39af161284d2cc74755aa1d260
commit 98e1de2d8fdc0f39af161284d2cc74755aa1d260
Author: Arthur Cohen <arthur.cohen@embecosm.com>
Date: Fri Apr 29 09:29:21 2022 +0200
ast: Resolver: Refactor ResolveRelativeTypePath in its own source file
Diff:
---
gcc/rust/resolve/rust-ast-resolve-type.cc | 47 ++++++++++++++++++++++++++
gcc/rust/resolve/rust-ast-resolve-type.h | 55 +++----------------------------
2 files changed, 52 insertions(+), 50 deletions(-)
diff --git a/gcc/rust/resolve/rust-ast-resolve-type.cc b/gcc/rust/resolve/rust-ast-resolve-type.cc
index 29b5edf94f6..141788019ee 100644
--- a/gcc/rust/resolve/rust-ast-resolve-type.cc
+++ b/gcc/rust/resolve/rust-ast-resolve-type.cc
@@ -248,5 +248,52 @@ ResolveType::visit (AST::SliceType &type)
type.get_elem_type ()->accept_vis (*this);
}
+ResolveRelativeTypePath::ResolveRelativeTypePath (CanonicalPath qualified_path)
+ : ResolveTypeToCanonicalPath (true, true)
+{
+ result = qualified_path;
+}
+
+bool
+ResolveRelativeTypePath::go (AST::QualifiedPathInType &path)
+{
+ // resolve the type and trait path
+ auto &qualified_path = path.get_qualified_path_type ();
+ CanonicalPath result = CanonicalPath::create_empty ();
+ if (!resolve_qual_seg (qualified_path, result))
+ return false;
+
+ // resolve the associated impl if available but it can also be from a trait
+ // and this is allowed to fail
+ auto resolver = Resolver::get ();
+ NodeId projection_resolved_id = UNKNOWN_NODEID;
+ if (resolver->get_name_scope ().lookup (result, &projection_resolved_id))
+ {
+ // mark the resolution for this
+ resolver->insert_resolved_name (qualified_path.get_node_id (),
+ projection_resolved_id);
+ }
+
+ // qualified types are similar to other paths in that we cannot guarantee
+ // that we can resolve the path at name resolution. We must look up
+ // associated types and type information to figure this out properly
+
+ ResolveRelativeTypePath o (result);
+ std::unique_ptr<AST::TypePathSegment> &associated
+ = path.get_associated_segment ();
+
+ associated->accept_vis (o);
+ if (o.failure_flag)
+ return false;
+
+ for (auto &seg : path.get_segments ())
+ {
+ seg->accept_vis (o);
+ if (o.failure_flag)
+ return false;
+ }
+
+ return true;
+}
} // 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 72846336d23..933413537b6 100644
--- a/gcc/rust/resolve/rust-ast-resolve-type.h
+++ b/gcc/rust/resolve/rust-ast-resolve-type.h
@@ -190,54 +190,10 @@ class ResolveRelativeTypePath : public ResolveTypeToCanonicalPath
using ResolveTypeToCanonicalPath::visit;
public:
- static bool go (AST::QualifiedPathInType &path, NodeId parent,
- bool canonicalize_type_with_generics)
- {
- // resolve the type and trait path
- auto &qualified_path = path.get_qualified_path_type ();
- CanonicalPath result = CanonicalPath::create_empty ();
- if (!resolve_qual_seg (qualified_path, result))
- return false;
-
- // resolve the associated impl if available but it can also be from a trait
- // and this is allowed to fail
- auto resolver = Resolver::get ();
- NodeId projection_resolved_id = UNKNOWN_NODEID;
- if (resolver->get_name_scope ().lookup (result, &projection_resolved_id))
- {
- // mark the resolution for this
- resolver->insert_resolved_name (qualified_path.get_node_id (),
- projection_resolved_id);
- }
-
- // qualified types are similar to other paths in that we cannot guarantee
- // that we can resolve the path at name resolution. We must look up
- // associated types and type information to figure this out properly
-
- ResolveRelativeTypePath o (result);
- std::unique_ptr<AST::TypePathSegment> &associated
- = path.get_associated_segment ();
-
- associated->accept_vis (o);
- if (o.failure_flag)
- return false;
-
- for (auto &seg : path.get_segments ())
- {
- seg->accept_vis (o);
- if (o.failure_flag)
- return false;
- }
-
- return true;
- }
+ static bool go (AST::QualifiedPathInType &path);
private:
- ResolveRelativeTypePath (CanonicalPath qualified_path)
- : ResolveTypeToCanonicalPath (true, true)
- {
- result = qualified_path;
- }
+ ResolveRelativeTypePath (CanonicalPath qualified_path);
static bool resolve_qual_seg (AST::QualifiedPathType &seg,
CanonicalPath &result);
@@ -375,8 +331,7 @@ public:
void visit (AST::QualifiedPathInType &path) override
{
- ok = ResolveRelativeTypePath::go (path, parent,
- canonicalize_type_with_generics);
+ ok = ResolveRelativeTypePath::go (path);
}
void visit (AST::ArrayType &type) override;
@@ -431,7 +386,7 @@ public:
ok = resolved_node != UNKNOWN_NODEID;
}
- void visit (AST::Lifetime &bound) override { ok = true; }
+ void visit (AST::Lifetime &) override { ok = true; }
private:
ResolveTypeBound (NodeId parent, bool canonicalize_type_with_generics)
@@ -459,7 +414,7 @@ public:
return resolver.resolved_node;
};
- void visit (AST::LifetimeParam ¶m) override
+ void visit (AST::LifetimeParam &) override
{
// For now do not do anything and accept everything.
ok = true;
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2022-06-08 12:41 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-08 12:41 [gcc/devel/rust/master] ast: Resolver: Refactor ResolveRelativeTypePath in its own source file 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).