aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJakub Dupak <dev@jakubdupak.com>2023-12-11 23:11:34 +0100
committerArthur Cohen <arthur.cohen@embecosm.com>2024-01-30 12:36:50 +0100
commit75e6d0cf415c939b020cef2e2693b652848ae45d (patch)
tree99f173518d31d25225d2ee3e062a353493848b38
parent44c58e2972826bd795431a3dada784b65c4d6487 (diff)
downloadgcc-75e6d0cf415c939b020cef2e2693b652848ae45d.zip
gcc-75e6d0cf415c939b020cef2e2693b652848ae45d.tar.gz
gcc-75e6d0cf415c939b020cef2e2693b652848ae45d.tar.bz2
gccrs: TyTy: SubstitutionRef cast specialization
Allows skipping parent check when casting. gcc/rust/ChangeLog: * typecheck/rust-tyty.h (BaseType::is): Cast API. (SubstitutionRef>): Cast API. (BaseType::as): Cast API. (BaseType::try_as): Cast API. Signed-off-by: Jakub Dupak <dev@jakubdupak.com>
-rw-r--r--gcc/rust/typecheck/rust-tyty.h78
1 files changed, 78 insertions, 0 deletions
diff --git a/gcc/rust/typecheck/rust-tyty.h b/gcc/rust/typecheck/rust-tyty.h
index 6ce760d..2ed407e 100644
--- a/gcc/rust/typecheck/rust-tyty.h
+++ b/gcc/rust/typecheck/rust-tyty.h
@@ -1575,6 +1575,84 @@ BaseType::is<const CallableTypeInterface> () const
return this->is<CallableTypeInterface> ();
}
+template <>
+WARN_UNUSED_RESULT inline bool
+BaseType::is<SubstitutionRef> () const
+{
+ auto kind = this->get_kind ();
+ return kind == FNPTR || kind == FNDEF || kind == CLOSURE || kind == ADT
+ || kind == PROJECTION;
+}
+
+template <>
+WARN_UNUSED_RESULT inline bool
+BaseType::is<const SubstitutionRef> () const
+{
+ return this->is<SubstitutionRef> ();
+}
+
+template <>
+WARN_UNUSED_RESULT inline SubstitutionRef *
+BaseType::as<SubstitutionRef> ()
+{
+ auto kind = this->get_kind ();
+ switch (kind)
+ {
+ case FNDEF:
+ return static_cast<FnType *> (this);
+ case CLOSURE:
+ return static_cast<ClosureType *> (this);
+ case ADT:
+ return static_cast<ADTType *> (this);
+ case PROJECTION:
+ return static_cast<ProjectionType *> (this);
+ default:
+ rust_unreachable ();
+ }
+}
+
+template <>
+WARN_UNUSED_RESULT inline const SubstitutionRef *
+BaseType::as<const SubstitutionRef> () const
+{
+ auto kind = this->get_kind ();
+ switch (kind)
+ {
+ case FNDEF:
+ return static_cast<const FnType *> (this);
+ case CLOSURE:
+ return static_cast<const ClosureType *> (this);
+ case ADT:
+ return static_cast<const ADTType *> (this);
+ case PROJECTION:
+ return static_cast<const ProjectionType *> (this);
+ default:
+ rust_unreachable ();
+ }
+}
+
+template <>
+WARN_UNUSED_RESULT inline SubstitutionRef *
+BaseType::try_as<SubstitutionRef> ()
+{
+ if (this->is<SubstitutionRef> ())
+ {
+ return this->as<SubstitutionRef> ();
+ }
+ return nullptr;
+}
+
+template <>
+WARN_UNUSED_RESULT inline const SubstitutionRef *
+BaseType::try_as<const SubstitutionRef> () const
+{
+ if (this->is<const SubstitutionRef> ())
+ {
+ return this->as<const SubstitutionRef> ();
+ }
+ return nullptr;
+}
+
} // namespace TyTy
} // namespace Rust