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

Change-Id: I8d9b916f5977121380325d373c4e2f805b691fae
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/34264
Reviewed-by: dan sinclair <dsinclair@chromium.org>
This commit is contained in:
Ben Clayton
2020-11-30 23:30:58 +00:00
parent 67864267c2
commit af37c4ae83
34 changed files with 118 additions and 125 deletions

View File

@@ -50,7 +50,7 @@ TEST_F(AccessControlTypeTest, Is) {
Type* ty = &at;
EXPECT_TRUE(ty->Is<AccessControlType>());
EXPECT_FALSE(ty->Is<AliasType>());
EXPECT_FALSE(ty->IsArray());
EXPECT_FALSE(ty->Is<ArrayType>());
EXPECT_FALSE(ty->IsBool());
EXPECT_FALSE(ty->IsF32());
EXPECT_FALSE(ty->IsI32());

View File

@@ -51,7 +51,7 @@ TEST_F(AliasTypeTest, Is) {
Type* ty = &at;
EXPECT_FALSE(ty->Is<AccessControlType>());
EXPECT_TRUE(ty->Is<AliasType>());
EXPECT_FALSE(ty->IsArray());
EXPECT_FALSE(ty->Is<ArrayType>());
EXPECT_FALSE(ty->IsBool());
EXPECT_FALSE(ty->IsF32());
EXPECT_FALSE(ty->IsI32());

View File

@@ -32,10 +32,6 @@ ArrayType::ArrayType(ArrayType&&) = default;
ArrayType::~ArrayType() = default;
bool ArrayType::IsArray() const {
return true;
}
uint64_t ArrayType::MinBufferBindingSize(MemoryLayout mem_layout) const {
if (!has_array_stride()) {
// Arrays in buffers are required to have a stride.

View File

@@ -41,8 +41,6 @@ class ArrayType : public Castable<ArrayType, Type> {
ArrayType(ArrayType&&);
~ArrayType() override;
/// @returns true if the type is an array type
bool IsArray() const override;
/// @returns true if this is a runtime array.
/// i.e. the size is determined at runtime
bool IsRuntimeArray() const { return size_ == 0; }

View File

@@ -35,7 +35,7 @@ TEST_F(ArrayTypeTest, CreateSizedArray) {
ArrayType arr{&u32, 3};
EXPECT_EQ(arr.type(), &u32);
EXPECT_EQ(arr.size(), 3u);
EXPECT_TRUE(arr.IsArray());
EXPECT_TRUE(arr.Is<ArrayType>());
EXPECT_FALSE(arr.IsRuntimeArray());
}
@@ -44,7 +44,7 @@ TEST_F(ArrayTypeTest, CreateRuntimeArray) {
ArrayType arr{&u32};
EXPECT_EQ(arr.type(), &u32);
EXPECT_EQ(arr.size(), 0u);
EXPECT_TRUE(arr.IsArray());
EXPECT_TRUE(arr.Is<ArrayType>());
EXPECT_TRUE(arr.IsRuntimeArray());
}
@@ -55,7 +55,7 @@ TEST_F(ArrayTypeTest, Is) {
Type* ty = &arr;
EXPECT_FALSE(ty->Is<AccessControlType>());
EXPECT_FALSE(ty->Is<AliasType>());
EXPECT_TRUE(ty->IsArray());
EXPECT_TRUE(ty->Is<ArrayType>());
EXPECT_FALSE(ty->IsBool());
EXPECT_FALSE(ty->IsF32());
EXPECT_FALSE(ty->IsI32());

View File

@@ -16,6 +16,7 @@
#include "src/ast/test_helper.h"
#include "src/ast/type/access_control_type.h"
#include "src/ast/type/array_type.h"
namespace tint {
namespace ast {
@@ -29,7 +30,7 @@ TEST_F(BoolTypeTest, Is) {
Type* ty = &b;
EXPECT_FALSE(ty->Is<AccessControlType>());
EXPECT_FALSE(ty->Is<AliasType>());
EXPECT_FALSE(ty->IsArray());
EXPECT_FALSE(ty->Is<ArrayType>());
EXPECT_TRUE(ty->IsBool());
EXPECT_FALSE(ty->IsF32());
EXPECT_FALSE(ty->IsI32());

View File

@@ -17,6 +17,7 @@
#include "src/ast/test_helper.h"
#include "src/ast/type/access_control_type.h"
#include "src/ast/type/array_type.h"
namespace tint {
namespace ast {
@@ -30,7 +31,7 @@ TEST_F(DepthTextureTypeTest, Is) {
Type* ty = &d;
EXPECT_FALSE(ty->Is<AccessControlType>());
EXPECT_FALSE(ty->Is<AliasType>());
EXPECT_FALSE(ty->IsArray());
EXPECT_FALSE(ty->Is<ArrayType>());
EXPECT_FALSE(ty->IsBool());
EXPECT_FALSE(ty->IsF32());
EXPECT_FALSE(ty->IsI32());

View File

@@ -16,6 +16,7 @@
#include "src/ast/test_helper.h"
#include "src/ast/type/access_control_type.h"
#include "src/ast/type/array_type.h"
namespace tint {
namespace ast {
@@ -29,7 +30,7 @@ TEST_F(F32TypeTest, Is) {
Type* ty = &f;
EXPECT_FALSE(ty->Is<AccessControlType>());
EXPECT_FALSE(ty->Is<AliasType>());
EXPECT_FALSE(ty->IsArray());
EXPECT_FALSE(ty->Is<ArrayType>());
EXPECT_FALSE(ty->IsBool());
EXPECT_TRUE(ty->IsF32());
EXPECT_FALSE(ty->IsI32());

View File

@@ -16,6 +16,7 @@
#include "src/ast/test_helper.h"
#include "src/ast/type/access_control_type.h"
#include "src/ast/type/array_type.h"
namespace tint {
namespace ast {
@@ -29,7 +30,7 @@ TEST_F(I32TypeTest, Is) {
Type* ty = &i;
EXPECT_FALSE(ty->Is<AccessControlType>());
EXPECT_FALSE(ty->Is<AliasType>());
EXPECT_FALSE(ty->IsArray());
EXPECT_FALSE(ty->Is<ArrayType>());
EXPECT_FALSE(ty->IsBool());
EXPECT_FALSE(ty->IsF32());
EXPECT_TRUE(ty->IsI32());

View File

@@ -16,6 +16,7 @@
#include "src/ast/test_helper.h"
#include "src/ast/type/access_control_type.h"
#include "src/ast/type/array_type.h"
#include "src/ast/type/i32_type.h"
namespace tint {
@@ -39,7 +40,7 @@ TEST_F(MatrixTypeTest, Is) {
Type* ty = &m;
EXPECT_FALSE(ty->Is<AccessControlType>());
EXPECT_FALSE(ty->Is<AliasType>());
EXPECT_FALSE(ty->IsArray());
EXPECT_FALSE(ty->Is<ArrayType>());
EXPECT_FALSE(ty->IsBool());
EXPECT_FALSE(ty->IsF32());
EXPECT_FALSE(ty->IsI32());

View File

@@ -16,6 +16,7 @@
#include "src/ast/test_helper.h"
#include "src/ast/type/access_control_type.h"
#include "src/ast/type/array_type.h"
#include "src/ast/type/f32_type.h"
namespace tint {
@@ -31,7 +32,7 @@ TEST_F(MultisampledTextureTypeTest, Is) {
Type* ty = &s;
EXPECT_FALSE(ty->Is<AccessControlType>());
EXPECT_FALSE(ty->Is<AliasType>());
EXPECT_FALSE(ty->IsArray());
EXPECT_FALSE(ty->Is<ArrayType>());
EXPECT_FALSE(ty->IsBool());
EXPECT_FALSE(ty->IsF32());
EXPECT_FALSE(ty->IsI32());

View File

@@ -16,6 +16,7 @@
#include "src/ast/test_helper.h"
#include "src/ast/type/access_control_type.h"
#include "src/ast/type/array_type.h"
#include "src/ast/type/i32_type.h"
namespace tint {
@@ -38,7 +39,7 @@ TEST_F(PointerTypeTest, Is) {
Type* ty = &p;
EXPECT_FALSE(ty->Is<AccessControlType>());
EXPECT_FALSE(ty->Is<AliasType>());
EXPECT_FALSE(ty->IsArray());
EXPECT_FALSE(ty->Is<ArrayType>());
EXPECT_FALSE(ty->IsBool());
EXPECT_FALSE(ty->IsF32());
EXPECT_FALSE(ty->IsI32());

View File

@@ -16,6 +16,7 @@
#include "src/ast/test_helper.h"
#include "src/ast/type/access_control_type.h"
#include "src/ast/type/array_type.h"
#include "src/ast/type/f32_type.h"
namespace tint {
@@ -31,7 +32,7 @@ TEST_F(SampledTextureTypeTest, Is) {
Type* ty = &s;
EXPECT_FALSE(ty->Is<AccessControlType>());
EXPECT_FALSE(ty->Is<AliasType>());
EXPECT_FALSE(ty->IsArray());
EXPECT_FALSE(ty->Is<ArrayType>());
EXPECT_FALSE(ty->IsBool());
EXPECT_FALSE(ty->IsF32());
EXPECT_FALSE(ty->IsI32());

View File

@@ -16,6 +16,7 @@
#include "src/ast/test_helper.h"
#include "src/ast/type/access_control_type.h"
#include "src/ast/type/array_type.h"
namespace tint {
namespace ast {
@@ -40,7 +41,7 @@ TEST_F(SamplerTypeTest, Is) {
Type* ty = &s;
EXPECT_FALSE(ty->Is<AccessControlType>());
EXPECT_FALSE(ty->Is<AliasType>());
EXPECT_FALSE(ty->IsArray());
EXPECT_FALSE(ty->Is<ArrayType>());
EXPECT_FALSE(ty->IsBool());
EXPECT_FALSE(ty->IsF32());
EXPECT_FALSE(ty->IsI32());

View File

@@ -19,6 +19,7 @@
#include "src/ast/identifier_expression.h"
#include "src/ast/test_helper.h"
#include "src/ast/type/access_control_type.h"
#include "src/ast/type/array_type.h"
#include "src/type_determiner.h"
namespace tint {
@@ -34,7 +35,7 @@ TEST_F(StorageTextureTypeTest, Is) {
Type* ty = &s;
EXPECT_FALSE(ty->Is<AccessControlType>());
EXPECT_FALSE(ty->Is<AliasType>());
EXPECT_FALSE(ty->IsArray());
EXPECT_FALSE(ty->Is<ArrayType>());
EXPECT_FALSE(ty->IsBool());
EXPECT_FALSE(ty->IsF32());
EXPECT_FALSE(ty->IsI32());

View File

@@ -47,7 +47,7 @@ TEST_F(StructTypeTest, Is) {
Type* ty = &s;
EXPECT_FALSE(ty->Is<AccessControlType>());
EXPECT_FALSE(ty->Is<AliasType>());
EXPECT_FALSE(ty->IsArray());
EXPECT_FALSE(ty->Is<ArrayType>());
EXPECT_FALSE(ty->IsBool());
EXPECT_FALSE(ty->IsF32());
EXPECT_FALSE(ty->IsI32());

View File

@@ -66,10 +66,6 @@ Type* Type::UnwrapAll() {
return UnwrapIfNeeded()->UnwrapPtrIfNeeded()->UnwrapIfNeeded();
}
bool Type::IsArray() const {
return false;
}
bool Type::IsBool() const {
return false;
}
@@ -166,11 +162,6 @@ bool Type::is_integer_scalar_or_vector() {
return is_unsigned_scalar_or_vector() || is_signed_scalar_or_vector();
}
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);
@@ -226,11 +217,6 @@ const VoidType* Type::AsVoid() const {
return static_cast<const VoidType*>(this);
}
ArrayType* Type::AsArray() {
assert(IsArray());
return static_cast<ArrayType*>(this);
}
BoolType* Type::AsBool() {
assert(IsBool());
return static_cast<BoolType*>(this);

View File

@@ -23,7 +23,6 @@ namespace tint {
namespace ast {
namespace type {
class ArrayType;
class BoolType;
class F32Type;
class I32Type;
@@ -46,8 +45,6 @@ class Type : public Castable<Type> {
Type(Type&&);
~Type() override;
/// @returns true if the type is an array type
virtual bool IsArray() const;
/// @returns true if the type is a bool type
virtual bool IsBool() const;
/// @returns true if the type is an f32 type
@@ -125,8 +122,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 array type
const ArrayType* AsArray() const;
/// @returns the type as a bool type
const BoolType* AsBool() const;
/// @returns the type as a f32 type
@@ -150,8 +145,6 @@ class Type : public Castable<Type> {
/// @returns the type as a void type
const VoidType* AsVoid() const;
/// @returns the type as an array type
ArrayType* AsArray();
/// @returns the type as a bool type
BoolType* AsBool();
/// @returns the type as a f32 type

View File

@@ -16,6 +16,7 @@
#include "src/ast/test_helper.h"
#include "src/ast/type/access_control_type.h"
#include "src/ast/type/array_type.h"
namespace tint {
namespace ast {
@@ -29,7 +30,7 @@ TEST_F(U32TypeTest, Is) {
Type* ty = &u;
EXPECT_FALSE(ty->Is<AccessControlType>());
EXPECT_FALSE(ty->Is<AliasType>());
EXPECT_FALSE(ty->IsArray());
EXPECT_FALSE(ty->Is<ArrayType>());
EXPECT_FALSE(ty->IsBool());
EXPECT_FALSE(ty->IsF32());
EXPECT_FALSE(ty->IsI32());

View File

@@ -16,6 +16,7 @@
#include "src/ast/test_helper.h"
#include "src/ast/type/access_control_type.h"
#include "src/ast/type/array_type.h"
#include "src/ast/type/i32_type.h"
namespace tint {
@@ -38,7 +39,7 @@ TEST_F(VectorTypeTest, Is) {
Type* ty = &v;
EXPECT_FALSE(ty->Is<AccessControlType>());
EXPECT_FALSE(ty->Is<AliasType>());
EXPECT_FALSE(ty->IsArray());
EXPECT_FALSE(ty->Is<ArrayType>());
EXPECT_FALSE(ty->IsBool());
EXPECT_FALSE(ty->IsF32());
EXPECT_FALSE(ty->IsI32());