Assing const As.* functions to type class
Change-Id: I99c588b53f28da119611ef0a5b27820cdaa57fc2
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/20262
Reviewed-by: David Neto <dneto@google.com>
diff --git a/src/ast/type/type.cc b/src/ast/type/type.cc
index 17ee534..1814876 100644
--- a/src/ast/type/type.cc
+++ b/src/ast/type/type.cc
@@ -108,6 +108,61 @@
return is_unsigned_scalar_or_vector() || is_signed_scalar_or_vector();
}
+const AliasType* Type::AsAlias() const {
+ assert(IsAlias());
+ return static_cast<const AliasType*>(this);
+}
+
+const ArrayType* Type::AsArray() const {
+ assert(IsArray());
+ return static_cast<const ArrayType*>(this);
+}
+
+const BoolType* Type::AsBool() const {
+ assert(IsBool());
+ return static_cast<const BoolType*>(this);
+}
+
+const F32Type* Type::AsF32() const {
+ assert(IsF32());
+ return static_cast<const F32Type*>(this);
+}
+
+const I32Type* Type::AsI32() const {
+ assert(IsI32());
+ return static_cast<const I32Type*>(this);
+}
+
+const MatrixType* Type::AsMatrix() const {
+ assert(IsMatrix());
+ return static_cast<const MatrixType*>(this);
+}
+
+const PointerType* Type::AsPointer() const {
+ assert(IsPointer());
+ return static_cast<const PointerType*>(this);
+}
+
+const StructType* Type::AsStruct() const {
+ assert(IsStruct());
+ return static_cast<const StructType*>(this);
+}
+
+const U32Type* Type::AsU32() const {
+ assert(IsU32());
+ return static_cast<const U32Type*>(this);
+}
+
+const VectorType* Type::AsVector() const {
+ assert(IsVector());
+ return static_cast<const VectorType*>(this);
+}
+
+const VoidType* Type::AsVoid() const {
+ assert(IsVoid());
+ return static_cast<const VoidType*>(this);
+}
+
AliasType* Type::AsAlias() {
assert(IsAlias());
return static_cast<AliasType*>(this);
diff --git a/src/ast/type/type.h b/src/ast/type/type.h
index 4fa44ab..4a76ccf 100644
--- a/src/ast/type/type.h
+++ b/src/ast/type/type.h
@@ -82,6 +82,29 @@
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
ArrayType* AsArray();