Replace Type::(Is|As)Matrix with Castable

Change-Id: I861aed231604a8bfba1f4cf3659b4863556fc3c4
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/34268
Reviewed-by: dan sinclair <dsinclair@chromium.org>
This commit is contained in:
Ben Clayton
2020-11-30 23:30:58 +00:00
parent 9857f81e94
commit d8457c15f1
32 changed files with 144 additions and 140 deletions

View File

@@ -27,6 +27,7 @@
#include "src/ast/type/bool_type.h"
#include "src/ast/type/f32_type.h"
#include "src/ast/type/i32_type.h"
#include "src/ast/type/matrix_type.h"
#include "src/ast/type/pointer_type.h"
#include "src/ast/type/struct_type.h"
#include "src/ast/type/u32_type.h"
@@ -56,7 +57,7 @@ TEST_F(AccessControlTypeTest, Is) {
EXPECT_FALSE(ty->Is<BoolType>());
EXPECT_FALSE(ty->Is<F32Type>());
EXPECT_FALSE(ty->Is<I32Type>());
EXPECT_FALSE(ty->IsMatrix());
EXPECT_FALSE(ty->Is<MatrixType>());
EXPECT_FALSE(ty->IsPointer());
EXPECT_FALSE(ty->IsSampler());
EXPECT_FALSE(ty->IsStruct());

View File

@@ -28,6 +28,7 @@
#include "src/ast/type/bool_type.h"
#include "src/ast/type/f32_type.h"
#include "src/ast/type/i32_type.h"
#include "src/ast/type/matrix_type.h"
#include "src/ast/type/pointer_type.h"
#include "src/ast/type/struct_type.h"
#include "src/ast/type/u32_type.h"
@@ -57,7 +58,7 @@ TEST_F(AliasTypeTest, Is) {
EXPECT_FALSE(ty->Is<BoolType>());
EXPECT_FALSE(ty->Is<F32Type>());
EXPECT_FALSE(ty->Is<I32Type>());
EXPECT_FALSE(ty->IsMatrix());
EXPECT_FALSE(ty->Is<MatrixType>());
EXPECT_FALSE(ty->IsPointer());
EXPECT_FALSE(ty->IsSampler());
EXPECT_FALSE(ty->IsStruct());

View File

@@ -23,6 +23,7 @@
#include "src/ast/type/bool_type.h"
#include "src/ast/type/f32_type.h"
#include "src/ast/type/i32_type.h"
#include "src/ast/type/matrix_type.h"
#include "src/ast/type/u32_type.h"
namespace tint {
@@ -61,7 +62,7 @@ TEST_F(ArrayTypeTest, Is) {
EXPECT_FALSE(ty->Is<BoolType>());
EXPECT_FALSE(ty->Is<F32Type>());
EXPECT_FALSE(ty->Is<I32Type>());
EXPECT_FALSE(ty->IsMatrix());
EXPECT_FALSE(ty->Is<MatrixType>());
EXPECT_FALSE(ty->IsPointer());
EXPECT_FALSE(ty->IsSampler());
EXPECT_FALSE(ty->IsStruct());

View File

@@ -19,6 +19,7 @@
#include "src/ast/type/array_type.h"
#include "src/ast/type/f32_type.h"
#include "src/ast/type/i32_type.h"
#include "src/ast/type/matrix_type.h"
namespace tint {
namespace ast {
@@ -36,7 +37,7 @@ TEST_F(BoolTypeTest, Is) {
EXPECT_TRUE(ty->Is<BoolType>());
EXPECT_FALSE(ty->Is<F32Type>());
EXPECT_FALSE(ty->Is<I32Type>());
EXPECT_FALSE(ty->IsMatrix());
EXPECT_FALSE(ty->Is<MatrixType>());
EXPECT_FALSE(ty->IsPointer());
EXPECT_FALSE(ty->IsSampler());
EXPECT_FALSE(ty->IsStruct());

View File

@@ -21,6 +21,7 @@
#include "src/ast/type/bool_type.h"
#include "src/ast/type/f32_type.h"
#include "src/ast/type/i32_type.h"
#include "src/ast/type/matrix_type.h"
namespace tint {
namespace ast {
@@ -38,7 +39,7 @@ TEST_F(DepthTextureTypeTest, Is) {
EXPECT_FALSE(ty->Is<BoolType>());
EXPECT_FALSE(ty->Is<F32Type>());
EXPECT_FALSE(ty->Is<I32Type>());
EXPECT_FALSE(ty->IsMatrix());
EXPECT_FALSE(ty->Is<MatrixType>());
EXPECT_FALSE(ty->IsPointer());
EXPECT_FALSE(ty->IsSampler());
EXPECT_FALSE(ty->IsStruct());

View File

@@ -19,6 +19,7 @@
#include "src/ast/type/array_type.h"
#include "src/ast/type/bool_type.h"
#include "src/ast/type/i32_type.h"
#include "src/ast/type/matrix_type.h"
namespace tint {
namespace ast {
@@ -36,7 +37,7 @@ TEST_F(F32TypeTest, Is) {
EXPECT_FALSE(ty->Is<BoolType>());
EXPECT_TRUE(ty->Is<F32Type>());
EXPECT_FALSE(ty->Is<I32Type>());
EXPECT_FALSE(ty->IsMatrix());
EXPECT_FALSE(ty->Is<MatrixType>());
EXPECT_FALSE(ty->IsPointer());
EXPECT_FALSE(ty->IsSampler());
EXPECT_FALSE(ty->IsStruct());

View File

@@ -19,6 +19,7 @@
#include "src/ast/type/array_type.h"
#include "src/ast/type/bool_type.h"
#include "src/ast/type/f32_type.h"
#include "src/ast/type/matrix_type.h"
namespace tint {
namespace ast {
@@ -36,7 +37,7 @@ TEST_F(I32TypeTest, Is) {
EXPECT_FALSE(ty->Is<BoolType>());
EXPECT_FALSE(ty->Is<F32Type>());
EXPECT_TRUE(ty->Is<I32Type>());
EXPECT_FALSE(ty->IsMatrix());
EXPECT_FALSE(ty->Is<MatrixType>());
EXPECT_FALSE(ty->IsPointer());
EXPECT_FALSE(ty->IsSampler());
EXPECT_FALSE(ty->IsStruct());

View File

@@ -35,10 +35,6 @@ MatrixType::MatrixType(MatrixType&&) = default;
MatrixType::~MatrixType() = default;
bool MatrixType::IsMatrix() const {
return true;
}
std::string MatrixType::type_name() const {
return "__mat_" + std::to_string(rows_) + "_" + std::to_string(columns_) +
subtype_->type_name();

View File

@@ -35,9 +35,6 @@ class MatrixType : public Castable<MatrixType, Type> {
MatrixType(MatrixType&&);
~MatrixType() override;
/// @returns true if the type is a matrix type
bool IsMatrix() const override;
/// @returns the type of the matrix
Type* type() const { return subtype_; }
/// @returns the number of rows in the matrix

View File

@@ -46,7 +46,7 @@ TEST_F(MatrixTypeTest, Is) {
EXPECT_FALSE(ty->Is<BoolType>());
EXPECT_FALSE(ty->Is<F32Type>());
EXPECT_FALSE(ty->Is<I32Type>());
EXPECT_TRUE(ty->IsMatrix());
EXPECT_TRUE(ty->Is<MatrixType>());
EXPECT_FALSE(ty->IsPointer());
EXPECT_FALSE(ty->IsSampler());
EXPECT_FALSE(ty->IsStruct());

View File

@@ -20,6 +20,7 @@
#include "src/ast/type/bool_type.h"
#include "src/ast/type/f32_type.h"
#include "src/ast/type/i32_type.h"
#include "src/ast/type/matrix_type.h"
namespace tint {
namespace ast {
@@ -38,7 +39,7 @@ TEST_F(MultisampledTextureTypeTest, Is) {
EXPECT_FALSE(ty->Is<BoolType>());
EXPECT_FALSE(ty->Is<F32Type>());
EXPECT_FALSE(ty->Is<I32Type>());
EXPECT_FALSE(ty->IsMatrix());
EXPECT_FALSE(ty->Is<MatrixType>());
EXPECT_FALSE(ty->IsPointer());
EXPECT_FALSE(ty->IsSampler());
EXPECT_FALSE(ty->IsStruct());

View File

@@ -20,6 +20,7 @@
#include "src/ast/type/bool_type.h"
#include "src/ast/type/f32_type.h"
#include "src/ast/type/i32_type.h"
#include "src/ast/type/matrix_type.h"
namespace tint {
namespace ast {
@@ -45,7 +46,7 @@ TEST_F(PointerTypeTest, Is) {
EXPECT_FALSE(ty->Is<BoolType>());
EXPECT_FALSE(ty->Is<F32Type>());
EXPECT_FALSE(ty->Is<I32Type>());
EXPECT_FALSE(ty->IsMatrix());
EXPECT_FALSE(ty->Is<MatrixType>());
EXPECT_TRUE(ty->IsPointer());
EXPECT_FALSE(ty->IsSampler());
EXPECT_FALSE(ty->IsStruct());

View File

@@ -20,6 +20,7 @@
#include "src/ast/type/bool_type.h"
#include "src/ast/type/f32_type.h"
#include "src/ast/type/i32_type.h"
#include "src/ast/type/matrix_type.h"
namespace tint {
namespace ast {
@@ -38,7 +39,7 @@ TEST_F(SampledTextureTypeTest, Is) {
EXPECT_FALSE(ty->Is<BoolType>());
EXPECT_FALSE(ty->Is<F32Type>());
EXPECT_FALSE(ty->Is<I32Type>());
EXPECT_FALSE(ty->IsMatrix());
EXPECT_FALSE(ty->Is<MatrixType>());
EXPECT_FALSE(ty->IsPointer());
EXPECT_FALSE(ty->IsSampler());
EXPECT_FALSE(ty->IsStruct());

View File

@@ -20,6 +20,7 @@
#include "src/ast/type/bool_type.h"
#include "src/ast/type/f32_type.h"
#include "src/ast/type/i32_type.h"
#include "src/ast/type/matrix_type.h"
namespace tint {
namespace ast {
@@ -48,7 +49,7 @@ TEST_F(SamplerTypeTest, Is) {
EXPECT_FALSE(ty->Is<BoolType>());
EXPECT_FALSE(ty->Is<F32Type>());
EXPECT_FALSE(ty->Is<I32Type>());
EXPECT_FALSE(ty->IsMatrix());
EXPECT_FALSE(ty->Is<MatrixType>());
EXPECT_FALSE(ty->IsPointer());
EXPECT_TRUE(ty->IsSampler());
EXPECT_FALSE(ty->IsStruct());

View File

@@ -23,6 +23,7 @@
#include "src/ast/type/bool_type.h"
#include "src/ast/type/f32_type.h"
#include "src/ast/type/i32_type.h"
#include "src/ast/type/matrix_type.h"
#include "src/type_determiner.h"
namespace tint {
@@ -42,7 +43,7 @@ TEST_F(StorageTextureTypeTest, Is) {
EXPECT_FALSE(ty->Is<BoolType>());
EXPECT_FALSE(ty->Is<F32Type>());
EXPECT_FALSE(ty->Is<I32Type>());
EXPECT_FALSE(ty->IsMatrix());
EXPECT_FALSE(ty->Is<MatrixType>());
EXPECT_FALSE(ty->IsPointer());
EXPECT_FALSE(ty->IsSampler());
EXPECT_FALSE(ty->IsStruct());

View File

@@ -26,6 +26,7 @@
#include "src/ast/type/bool_type.h"
#include "src/ast/type/f32_type.h"
#include "src/ast/type/i32_type.h"
#include "src/ast/type/matrix_type.h"
#include "src/ast/type/u32_type.h"
#include "src/ast/type/vector_type.h"
@@ -53,7 +54,7 @@ TEST_F(StructTypeTest, Is) {
EXPECT_FALSE(ty->Is<BoolType>());
EXPECT_FALSE(ty->Is<F32Type>());
EXPECT_FALSE(ty->Is<I32Type>());
EXPECT_FALSE(ty->IsMatrix());
EXPECT_FALSE(ty->Is<MatrixType>());
EXPECT_FALSE(ty->IsPointer());
EXPECT_FALSE(ty->IsSampler());
EXPECT_TRUE(ty->IsStruct());

View File

@@ -66,10 +66,6 @@ Type* Type::UnwrapAll() {
return UnwrapIfNeeded()->UnwrapPtrIfNeeded()->UnwrapIfNeeded();
}
bool Type::IsMatrix() const {
return false;
}
bool Type::IsPointer() const {
return false;
}
@@ -115,7 +111,7 @@ bool Type::is_float_scalar() {
}
bool Type::is_float_matrix() {
return IsMatrix() && AsMatrix()->type()->is_float_scalar();
return Is<MatrixType>() && As<MatrixType>()->type()->is_float_scalar();
}
bool Type::is_float_vector() {
@@ -150,11 +146,6 @@ bool Type::is_integer_scalar_or_vector() {
return is_unsigned_scalar_or_vector() || is_signed_scalar_or_vector();
}
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);
@@ -190,11 +181,6 @@ const VoidType* Type::AsVoid() const {
return static_cast<const VoidType*>(this);
}
MatrixType* Type::AsMatrix() {
assert(IsMatrix());
return static_cast<MatrixType*>(this);
}
PointerType* Type::AsPointer() {
assert(IsPointer());
return static_cast<PointerType*>(this);

View File

@@ -23,7 +23,6 @@ namespace tint {
namespace ast {
namespace type {
class MatrixType;
class PointerType;
class SamplerType;
class StructType;
@@ -42,8 +41,6 @@ class Type : public Castable<Type> {
Type(Type&&);
~Type() override;
/// @returns true if the type is a matrix type
virtual bool IsMatrix() const;
/// @returns true if the type is a ptr type
virtual bool IsPointer() const;
/// @returns true if the type is a sampler
@@ -113,8 +110,6 @@ class Type : public Castable<Type> {
/// @returns true if this type is an integer scalar or vector
bool is_integer_scalar_or_vector();
/// @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 sampler type
@@ -130,8 +125,6 @@ class Type : public Castable<Type> {
/// @returns the type as a void type
const VoidType* AsVoid() const;
/// @returns the type as a matrix type
MatrixType* AsMatrix();
/// @returns the type as a pointer type
PointerType* AsPointer();
/// @returns the type as a sampler type

View File

@@ -20,6 +20,7 @@
#include "src/ast/type/bool_type.h"
#include "src/ast/type/f32_type.h"
#include "src/ast/type/i32_type.h"
#include "src/ast/type/matrix_type.h"
namespace tint {
namespace ast {
@@ -37,7 +38,7 @@ TEST_F(U32TypeTest, Is) {
EXPECT_FALSE(ty->Is<BoolType>());
EXPECT_FALSE(ty->Is<F32Type>());
EXPECT_FALSE(ty->Is<I32Type>());
EXPECT_FALSE(ty->IsMatrix());
EXPECT_FALSE(ty->Is<MatrixType>());
EXPECT_FALSE(ty->IsPointer());
EXPECT_FALSE(ty->IsSampler());
EXPECT_FALSE(ty->IsStruct());

View File

@@ -20,6 +20,7 @@
#include "src/ast/type/bool_type.h"
#include "src/ast/type/f32_type.h"
#include "src/ast/type/i32_type.h"
#include "src/ast/type/matrix_type.h"
namespace tint {
namespace ast {
@@ -45,7 +46,7 @@ TEST_F(VectorTypeTest, Is) {
EXPECT_FALSE(ty->Is<BoolType>());
EXPECT_FALSE(ty->Is<F32Type>());
EXPECT_FALSE(ty->Is<I32Type>());
EXPECT_FALSE(ty->IsMatrix());
EXPECT_FALSE(ty->Is<MatrixType>());
EXPECT_FALSE(ty->IsPointer());
EXPECT_FALSE(ty->IsSampler());
EXPECT_FALSE(ty->IsStruct());