diff options
author | Philip Herron <philip.herron@embecosm.com> | 2021-08-31 12:22:18 +0100 |
---|---|---|
committer | Philip Herron <philip.herron@embecosm.com> | 2021-08-31 12:22:18 +0100 |
commit | 2ab6f9ee9f294bcd38378905d94fe7b280524414 (patch) | |
tree | b0047c7b6d3a1717d3f592ab5ed13447dab04e57 /gcc/rust/resolve/rust-ast-resolve.cc | |
parent | 0e3030707bfcd196fd678a25bf28fbdb925914c4 (diff) | |
download | gcc-2ab6f9ee9f294bcd38378905d94fe7b280524414.zip gcc-2ab6f9ee9f294bcd38378905d94fe7b280524414.tar.gz gcc-2ab6f9ee9f294bcd38378905d94fe7b280524414.tar.bz2 |
Add name resolution for QualifiedPathInType
Qualified path types allow for TypePaths qualified with a paticular
associated impl and type;
Diffstat (limited to 'gcc/rust/resolve/rust-ast-resolve.cc')
-rw-r--r-- | gcc/rust/resolve/rust-ast-resolve.cc | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/gcc/rust/resolve/rust-ast-resolve.cc b/gcc/rust/resolve/rust-ast-resolve.cc index 9d79b36..1f90181 100644 --- a/gcc/rust/resolve/rust-ast-resolve.cc +++ b/gcc/rust/resolve/rust-ast-resolve.cc @@ -744,5 +744,49 @@ ResolveItem::resolve_extern_item (AST::ExternalItem *item) ResolveExternItem::go (item); } +// qualified path in type + +bool +ResolveRelativeTypePath::resolve_qual_seg (AST::QualifiedPathType &seg, + CanonicalPath &result) +{ + if (seg.is_error ()) + { + rust_error_at (seg.get_locus (), "segment has error: %s", + seg.as_string ().c_str ()); + return false; + } + + bool canonicalize_type_with_generics = true; + NodeId type_resolved_node + = ResolveType::go (seg.get_type ().get (), seg.get_node_id (), + canonicalize_type_with_generics); + if (type_resolved_node == UNKNOWN_NODEID) + return false; + + CanonicalPath impl_type_seg + = ResolveTypeToCanonicalPath::resolve (*seg.get_type ().get ()); + if (!seg.has_as_clause ()) + { + result = result.append (impl_type_seg); + return true; + } + + NodeId trait_resolved_node + = ResolveType::go (&seg.get_as_type_path (), seg.get_node_id (), + canonicalize_type_with_generics); + + if (trait_resolved_node == UNKNOWN_NODEID) + return false; + + CanonicalPath trait_type_seg + = ResolveTypeToCanonicalPath::resolve (seg.get_as_type_path ()); + CanonicalPath projection + = TraitImplProjection::resolve (seg.get_node_id (), trait_type_seg, + impl_type_seg); + result = result.append (projection); + return true; +} + } // namespace Resolver } // namespace Rust |