diff --git a/src/ast/type/type.cc b/src/ast/type/type.cc index 17ee534094..1814876efe 100644 --- a/src/ast/type/type.cc +++ b/src/ast/type/type.cc @@ -108,6 +108,61 @@ bool Type::is_integer_scalar_or_vector() { return is_unsigned_scalar_or_vector() || is_signed_scalar_or_vector(); } +const AliasType* Type::AsAlias() const { + assert(IsAlias()); + return static_cast(this); +} + +const ArrayType* Type::AsArray() const { + assert(IsArray()); + return static_cast(this); +} + +const BoolType* Type::AsBool() const { + assert(IsBool()); + return static_cast(this); +} + +const F32Type* Type::AsF32() const { + assert(IsF32()); + return static_cast(this); +} + +const I32Type* Type::AsI32() const { + assert(IsI32()); + return static_cast(this); +} + +const MatrixType* Type::AsMatrix() const { + assert(IsMatrix()); + return static_cast(this); +} + +const PointerType* Type::AsPointer() const { + assert(IsPointer()); + return static_cast(this); +} + +const StructType* Type::AsStruct() const { + assert(IsStruct()); + return static_cast(this); +} + +const U32Type* Type::AsU32() const { + assert(IsU32()); + return static_cast(this); +} + +const VectorType* Type::AsVector() const { + assert(IsVector()); + return static_cast(this); +} + +const VoidType* Type::AsVoid() const { + assert(IsVoid()); + return static_cast(this); +} + AliasType* Type::AsAlias() { assert(IsAlias()); return static_cast(this); diff --git a/src/ast/type/type.h b/src/ast/type/type.h index 4fa44ab1d9..4a76ccfa67 100644 --- a/src/ast/type/type.h +++ b/src/ast/type/type.h @@ -81,6 +81,29 @@ class Type { /// @returns true if this type is an integer scalar or vector bool is_integer_scalar_or_vector(); + /// @returns the type as an alias type + const AliasType* AsAlias() const; + /// @returns the type as an array type + const ArrayType* AsArray() const; + /// @returns the type as a bool type + const BoolType* AsBool() const; + /// @returns the type as a f32 type + const F32Type* AsF32() const; + /// @returns the type as an i32 type + const I32Type* AsI32() const; + /// @returns the type as a matrix type + const MatrixType* AsMatrix() const; + /// @returns the type as a pointer type + const PointerType* AsPointer() const; + /// @returns the type as a struct type + const StructType* AsStruct() const; + /// @returns the type as a u32 type + const U32Type* AsU32() const; + /// @returns the type as a vector type + const VectorType* AsVector() const; + /// @returns the type as a void type + const VoidType* AsVoid() const; + /// @returns the type as an alias type AliasType* AsAlias(); /// @returns the type as an array type