aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorPhilip Herron <philip.herron@embecosm.com>2021-09-05 00:13:25 +0100
committerPhilip Herron <philip.herron@embecosm.com>2021-09-05 00:13:25 +0100
commit9c56ecf32c0daeb87ff61e33076a3b1c8c3fcb49 (patch)
treead2c7db6d69ba7a5a90355505ced574908348d2a /gcc
parent3438ea39e33880e582e8a11b558bfacb6fb280b0 (diff)
downloadgcc-9c56ecf32c0daeb87ff61e33076a3b1c8c3fcb49.zip
gcc-9c56ecf32c0daeb87ff61e33076a3b1c8c3fcb49.tar.gz
gcc-9c56ecf32c0daeb87ff61e33076a3b1c8c3fcb49.tar.bz2
Add helpers to as clause of QualifiedPaths to get the generic args
When we resolve a TypePath we expect this to resolve to a TyTy and to substitute arguments accordingly. Qualified paths contain a trait reference which can contain generic arguments, the problem here is that traits are not a TyTy type since traits define behaviour not types. In order to actually apply the substitutions in a future commit we must be able to access these arguments in a sensible way first.
Diffstat (limited to 'gcc')
-rw-r--r--gcc/rust/hir/tree/rust-hir-path.h21
1 files changed, 21 insertions, 0 deletions
diff --git a/gcc/rust/hir/tree/rust-hir-path.h b/gcc/rust/hir/tree/rust-hir-path.h
index 2a491be..13e246f 100644
--- a/gcc/rust/hir/tree/rust-hir-path.h
+++ b/gcc/rust/hir/tree/rust-hir-path.h
@@ -767,6 +767,27 @@ public:
rust_assert (has_as_clause ());
return trait;
}
+
+ bool trait_has_generic_args () const
+ {
+ rust_assert (has_as_clause ());
+ bool is_generic_seg = trait->get_final_segment ()->get_type ()
+ == TypePathSegment::SegmentType::GENERIC;
+ if (!is_generic_seg)
+ return false;
+
+ TypePathSegmentGeneric *seg = static_cast<TypePathSegmentGeneric *> (
+ trait->get_final_segment ().get ());
+ return seg->has_generic_args ();
+ }
+
+ GenericArgs &get_trait_generic_args ()
+ {
+ rust_assert (trait_has_generic_args ());
+ TypePathSegmentGeneric *seg = static_cast<TypePathSegmentGeneric *> (
+ trait->get_final_segment ().get ());
+ return seg->get_generic_args ();
+ }
};
/* HIR node representing a qualified path-in-expression pattern (path that