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

Change-Id: Id130581f72e762bd398a4c1c509cdbe21739e750
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/34267
Reviewed-by: dan sinclair <dsinclair@chromium.org>
This commit is contained in:
Ben Clayton
2020-11-30 23:30:58 +00:00
parent 75f39be976
commit 9857f81e94
35 changed files with 114 additions and 120 deletions

View File

@@ -38,7 +38,7 @@ TEST_F(ExpressionTest, set_result_type) {
Expr e;
e.set_result_type(&i32);
ASSERT_NE(e.result_type(), nullptr);
EXPECT_TRUE(e.result_type()->IsI32());
EXPECT_TRUE(e.result_type()->Is<ast::type::I32Type>());
}
TEST_F(ExpressionTest, set_result_type_alias) {
@@ -49,7 +49,7 @@ TEST_F(ExpressionTest, set_result_type_alias) {
Expr e;
e.set_result_type(&b);
ASSERT_NE(e.result_type(), nullptr);
EXPECT_TRUE(e.result_type()->IsI32());
EXPECT_TRUE(e.result_type()->Is<ast::type::I32Type>());
}
} // namespace

View File

@@ -55,7 +55,7 @@ TEST_F(AccessControlTypeTest, Is) {
EXPECT_FALSE(ty->Is<ArrayType>());
EXPECT_FALSE(ty->Is<BoolType>());
EXPECT_FALSE(ty->Is<F32Type>());
EXPECT_FALSE(ty->IsI32());
EXPECT_FALSE(ty->Is<I32Type>());
EXPECT_FALSE(ty->IsMatrix());
EXPECT_FALSE(ty->IsPointer());
EXPECT_FALSE(ty->IsSampler());

View File

@@ -56,7 +56,7 @@ TEST_F(AliasTypeTest, Is) {
EXPECT_FALSE(ty->Is<ArrayType>());
EXPECT_FALSE(ty->Is<BoolType>());
EXPECT_FALSE(ty->Is<F32Type>());
EXPECT_FALSE(ty->IsI32());
EXPECT_FALSE(ty->Is<I32Type>());
EXPECT_FALSE(ty->IsMatrix());
EXPECT_FALSE(ty->IsPointer());
EXPECT_FALSE(ty->IsSampler());

View File

@@ -60,7 +60,7 @@ TEST_F(ArrayTypeTest, Is) {
EXPECT_TRUE(ty->Is<ArrayType>());
EXPECT_FALSE(ty->Is<BoolType>());
EXPECT_FALSE(ty->Is<F32Type>());
EXPECT_FALSE(ty->IsI32());
EXPECT_FALSE(ty->Is<I32Type>());
EXPECT_FALSE(ty->IsMatrix());
EXPECT_FALSE(ty->IsPointer());
EXPECT_FALSE(ty->IsSampler());

View File

@@ -18,6 +18,7 @@
#include "src/ast/type/access_control_type.h"
#include "src/ast/type/array_type.h"
#include "src/ast/type/f32_type.h"
#include "src/ast/type/i32_type.h"
namespace tint {
namespace ast {
@@ -34,7 +35,7 @@ TEST_F(BoolTypeTest, Is) {
EXPECT_FALSE(ty->Is<ArrayType>());
EXPECT_TRUE(ty->Is<BoolType>());
EXPECT_FALSE(ty->Is<F32Type>());
EXPECT_FALSE(ty->IsI32());
EXPECT_FALSE(ty->Is<I32Type>());
EXPECT_FALSE(ty->IsMatrix());
EXPECT_FALSE(ty->IsPointer());
EXPECT_FALSE(ty->IsSampler());

View File

@@ -20,6 +20,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/i32_type.h"
namespace tint {
namespace ast {
@@ -36,7 +37,7 @@ TEST_F(DepthTextureTypeTest, Is) {
EXPECT_FALSE(ty->Is<ArrayType>());
EXPECT_FALSE(ty->Is<BoolType>());
EXPECT_FALSE(ty->Is<F32Type>());
EXPECT_FALSE(ty->IsI32());
EXPECT_FALSE(ty->Is<I32Type>());
EXPECT_FALSE(ty->IsMatrix());
EXPECT_FALSE(ty->IsPointer());
EXPECT_FALSE(ty->IsSampler());

View File

@@ -18,6 +18,7 @@
#include "src/ast/type/access_control_type.h"
#include "src/ast/type/array_type.h"
#include "src/ast/type/bool_type.h"
#include "src/ast/type/i32_type.h"
namespace tint {
namespace ast {
@@ -34,7 +35,7 @@ TEST_F(F32TypeTest, Is) {
EXPECT_FALSE(ty->Is<ArrayType>());
EXPECT_FALSE(ty->Is<BoolType>());
EXPECT_TRUE(ty->Is<F32Type>());
EXPECT_FALSE(ty->IsI32());
EXPECT_FALSE(ty->Is<I32Type>());
EXPECT_FALSE(ty->IsMatrix());
EXPECT_FALSE(ty->IsPointer());
EXPECT_FALSE(ty->IsSampler());

View File

@@ -24,10 +24,6 @@ I32Type::I32Type(I32Type&&) = default;
I32Type::~I32Type() = default;
bool I32Type::IsI32() const {
return true;
}
std::string I32Type::type_name() const {
return "__i32";
}

View File

@@ -32,9 +32,6 @@ class I32Type : public Castable<I32Type, Type> {
I32Type(I32Type&&);
~I32Type() override;
/// @returns true if the type is an i32 type
bool IsI32() const override;
/// @returns the name for this type
std::string type_name() const override;

View File

@@ -35,7 +35,7 @@ TEST_F(I32TypeTest, Is) {
EXPECT_FALSE(ty->Is<ArrayType>());
EXPECT_FALSE(ty->Is<BoolType>());
EXPECT_FALSE(ty->Is<F32Type>());
EXPECT_TRUE(ty->IsI32());
EXPECT_TRUE(ty->Is<I32Type>());
EXPECT_FALSE(ty->IsMatrix());
EXPECT_FALSE(ty->IsPointer());
EXPECT_FALSE(ty->IsSampler());

View File

@@ -45,7 +45,7 @@ TEST_F(MatrixTypeTest, Is) {
EXPECT_FALSE(ty->Is<ArrayType>());
EXPECT_FALSE(ty->Is<BoolType>());
EXPECT_FALSE(ty->Is<F32Type>());
EXPECT_FALSE(ty->IsI32());
EXPECT_FALSE(ty->Is<I32Type>());
EXPECT_TRUE(ty->IsMatrix());
EXPECT_FALSE(ty->IsPointer());
EXPECT_FALSE(ty->IsSampler());

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/i32_type.h"
namespace tint {
namespace ast {
@@ -36,7 +37,7 @@ TEST_F(MultisampledTextureTypeTest, Is) {
EXPECT_FALSE(ty->Is<ArrayType>());
EXPECT_FALSE(ty->Is<BoolType>());
EXPECT_FALSE(ty->Is<F32Type>());
EXPECT_FALSE(ty->IsI32());
EXPECT_FALSE(ty->Is<I32Type>());
EXPECT_FALSE(ty->IsMatrix());
EXPECT_FALSE(ty->IsPointer());
EXPECT_FALSE(ty->IsSampler());

View File

@@ -44,7 +44,7 @@ TEST_F(PointerTypeTest, Is) {
EXPECT_FALSE(ty->Is<ArrayType>());
EXPECT_FALSE(ty->Is<BoolType>());
EXPECT_FALSE(ty->Is<F32Type>());
EXPECT_FALSE(ty->IsI32());
EXPECT_FALSE(ty->Is<I32Type>());
EXPECT_FALSE(ty->IsMatrix());
EXPECT_TRUE(ty->IsPointer());
EXPECT_FALSE(ty->IsSampler());

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/i32_type.h"
namespace tint {
namespace ast {
@@ -36,7 +37,7 @@ TEST_F(SampledTextureTypeTest, Is) {
EXPECT_FALSE(ty->Is<ArrayType>());
EXPECT_FALSE(ty->Is<BoolType>());
EXPECT_FALSE(ty->Is<F32Type>());
EXPECT_FALSE(ty->IsI32());
EXPECT_FALSE(ty->Is<I32Type>());
EXPECT_FALSE(ty->IsMatrix());
EXPECT_FALSE(ty->IsPointer());
EXPECT_FALSE(ty->IsSampler());

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/i32_type.h"
namespace tint {
namespace ast {
@@ -46,7 +47,7 @@ TEST_F(SamplerTypeTest, Is) {
EXPECT_FALSE(ty->Is<ArrayType>());
EXPECT_FALSE(ty->Is<BoolType>());
EXPECT_FALSE(ty->Is<F32Type>());
EXPECT_FALSE(ty->IsI32());
EXPECT_FALSE(ty->Is<I32Type>());
EXPECT_FALSE(ty->IsMatrix());
EXPECT_FALSE(ty->IsPointer());
EXPECT_TRUE(ty->IsSampler());

View File

@@ -22,6 +22,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/i32_type.h"
#include "src/type_determiner.h"
namespace tint {
@@ -40,7 +41,7 @@ TEST_F(StorageTextureTypeTest, Is) {
EXPECT_FALSE(ty->Is<ArrayType>());
EXPECT_FALSE(ty->Is<BoolType>());
EXPECT_FALSE(ty->Is<F32Type>());
EXPECT_FALSE(ty->IsI32());
EXPECT_FALSE(ty->Is<I32Type>());
EXPECT_FALSE(ty->IsMatrix());
EXPECT_FALSE(ty->IsPointer());
EXPECT_FALSE(ty->IsSampler());
@@ -93,7 +94,7 @@ TEST_F(StorageTextureTypeTest, F32Type) {
ASSERT_TRUE(td.Determine()) << td.error();
ASSERT_TRUE(s->IsTexture());
ASSERT_TRUE(s->AsTexture()->IsStorage());
EXPECT_TRUE(s->AsTexture()->AsStorage()->type()->Is<ast::type::F32Type>());
EXPECT_TRUE(s->AsTexture()->AsStorage()->type()->Is<F32Type>());
}
TEST_F(StorageTextureTypeTest, U32Type) {
@@ -121,7 +122,7 @@ TEST_F(StorageTextureTypeTest, I32Type) {
ASSERT_TRUE(td.Determine()) << td.error();
ASSERT_TRUE(s->IsTexture());
ASSERT_TRUE(s->AsTexture()->IsStorage());
EXPECT_TRUE(s->AsTexture()->AsStorage()->type()->IsI32());
EXPECT_TRUE(s->AsTexture()->AsStorage()->type()->Is<I32Type>());
}
TEST_F(StorageTextureTypeTest, MinBufferBindingSize) {

View File

@@ -52,7 +52,7 @@ TEST_F(StructTypeTest, Is) {
EXPECT_FALSE(ty->Is<ArrayType>());
EXPECT_FALSE(ty->Is<BoolType>());
EXPECT_FALSE(ty->Is<F32Type>());
EXPECT_FALSE(ty->IsI32());
EXPECT_FALSE(ty->Is<I32Type>());
EXPECT_FALSE(ty->IsMatrix());
EXPECT_FALSE(ty->IsPointer());
EXPECT_FALSE(ty->IsSampler());

View File

@@ -66,10 +66,6 @@ Type* Type::UnwrapAll() {
return UnwrapIfNeeded()->UnwrapPtrIfNeeded()->UnwrapIfNeeded();
}
bool Type::IsI32() const {
return false;
}
bool Type::IsMatrix() const {
return false;
}
@@ -131,7 +127,7 @@ bool Type::is_float_scalar_or_vector() {
}
bool Type::is_integer_scalar() {
return IsU32() || IsI32();
return IsU32() || Is<I32Type>();
}
bool Type::is_unsigned_integer_vector() {
@@ -139,7 +135,7 @@ bool Type::is_unsigned_integer_vector() {
}
bool Type::is_signed_integer_vector() {
return IsVector() && AsVector()->type()->IsI32();
return IsVector() && AsVector()->type()->Is<I32Type>();
}
bool Type::is_unsigned_scalar_or_vector() {
@@ -147,18 +143,13 @@ bool Type::is_unsigned_scalar_or_vector() {
}
bool Type::is_signed_scalar_or_vector() {
return IsI32() || (IsVector() && AsVector()->type()->IsI32());
return Is<I32Type>() || (IsVector() && AsVector()->type()->Is<I32Type>());
}
bool Type::is_integer_scalar_or_vector() {
return is_unsigned_scalar_or_vector() || is_signed_scalar_or_vector();
}
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);
@@ -199,11 +190,6 @@ const VoidType* Type::AsVoid() const {
return static_cast<const VoidType*>(this);
}
I32Type* Type::AsI32() {
assert(IsI32());
return static_cast<I32Type*>(this);
}
MatrixType* Type::AsMatrix() {
assert(IsMatrix());
return static_cast<MatrixType*>(this);

View File

@@ -23,7 +23,6 @@ namespace tint {
namespace ast {
namespace type {
class I32Type;
class MatrixType;
class PointerType;
class SamplerType;
@@ -43,8 +42,6 @@ class Type : public Castable<Type> {
Type(Type&&);
~Type() override;
/// @returns true if the type is an i32 type
virtual bool IsI32() const;
/// @returns true if the type is a matrix type
virtual bool IsMatrix() const;
/// @returns true if the type is a ptr type
@@ -116,8 +113,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 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
@@ -135,8 +130,6 @@ class Type : public Castable<Type> {
/// @returns the type as a void type
const VoidType* AsVoid() const;
/// @returns the type as an i32 type
I32Type* AsI32();
/// @returns the type as a matrix type
MatrixType* AsMatrix();
/// @returns the type as a pointer type

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/i32_type.h"
namespace tint {
namespace ast {
@@ -35,7 +36,7 @@ TEST_F(U32TypeTest, Is) {
EXPECT_FALSE(ty->Is<ArrayType>());
EXPECT_FALSE(ty->Is<BoolType>());
EXPECT_FALSE(ty->Is<F32Type>());
EXPECT_FALSE(ty->IsI32());
EXPECT_FALSE(ty->Is<I32Type>());
EXPECT_FALSE(ty->IsMatrix());
EXPECT_FALSE(ty->IsPointer());
EXPECT_FALSE(ty->IsSampler());

View File

@@ -44,7 +44,7 @@ TEST_F(VectorTypeTest, Is) {
EXPECT_FALSE(ty->Is<ArrayType>());
EXPECT_FALSE(ty->Is<BoolType>());
EXPECT_FALSE(ty->Is<F32Type>());
EXPECT_FALSE(ty->IsI32());
EXPECT_FALSE(ty->Is<I32Type>());
EXPECT_FALSE(ty->IsMatrix());
EXPECT_FALSE(ty->IsPointer());
EXPECT_FALSE(ty->IsSampler());

View File

@@ -28,14 +28,14 @@ TEST_F(TypeManagerTest, GetUnregistered) {
ast::TypeManager tm;
auto* t = tm.Get(std::make_unique<ast::type::I32Type>());
ASSERT_NE(t, nullptr);
EXPECT_TRUE(t->IsI32());
EXPECT_TRUE(t->Is<ast::type::I32Type>());
}
TEST_F(TypeManagerTest, GetSameTypeReturnsSamePtr) {
ast::TypeManager tm;
auto* t = tm.Get(std::make_unique<ast::type::I32Type>());
ASSERT_NE(t, nullptr);
EXPECT_TRUE(t->IsI32());
EXPECT_TRUE(t->Is<ast::type::I32Type>());
auto* t2 = tm.Get(std::make_unique<ast::type::I32Type>());
EXPECT_EQ(t, t2);
@@ -45,7 +45,7 @@ TEST_F(TypeManagerTest, GetDifferentTypeReturnsDifferentPtr) {
ast::TypeManager tm;
auto* t = tm.Get(std::make_unique<ast::type::I32Type>());
ASSERT_NE(t, nullptr);
EXPECT_TRUE(t->IsI32());
EXPECT_TRUE(t->Is<ast::type::I32Type>());
auto* t2 = tm.Get(std::make_unique<ast::type::U32Type>());
ASSERT_NE(t2, nullptr);