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

Change-Id: I833c92be270236fefd1e77a7a145dede757e93e9
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/34262
Reviewed-by: dan sinclair <dsinclair@chromium.org>
This commit is contained in:
Ben Clayton 2020-11-30 23:30:58 +00:00
parent 69aabb51a9
commit a8d87788da
26 changed files with 248 additions and 246 deletions

View File

@ -23,17 +23,13 @@ namespace type {
AccessControlType::AccessControlType(AccessControl access, Type* subtype) AccessControlType::AccessControlType(AccessControl access, Type* subtype)
: access_(access), subtype_(subtype) { : access_(access), subtype_(subtype) {
assert(subtype_); assert(subtype_);
assert(!subtype_->IsAccessControl()); assert(!subtype_->Is<AccessControlType>());
} }
AccessControlType::AccessControlType(AccessControlType&&) = default; AccessControlType::AccessControlType(AccessControlType&&) = default;
AccessControlType::~AccessControlType() = default; AccessControlType::~AccessControlType() = default;
bool AccessControlType::IsAccessControl() const {
return true;
}
std::string AccessControlType::type_name() const { std::string AccessControlType::type_name() const {
std::string name = "__access_control_"; std::string name = "__access_control_";
switch (access_) { switch (access_) {

View File

@ -35,9 +35,6 @@ class AccessControlType : public Castable<AccessControlType, Type> {
AccessControlType(AccessControlType&&); AccessControlType(AccessControlType&&);
~AccessControlType() override; ~AccessControlType() override;
/// @returns true if the type is an access control type
bool IsAccessControl() const override;
/// @returns true if the access control is read only /// @returns true if the access control is read only
bool IsReadOnly() const { return access_ == AccessControl::kReadOnly; } bool IsReadOnly() const { return access_ == AccessControl::kReadOnly; }
/// @returns true if the access control is write only /// @returns true if the access control is write only

View File

@ -47,7 +47,7 @@ TEST_F(AccessControlTypeTest, Is) {
I32Type i32; I32Type i32;
AccessControlType at{AccessControl::kReadOnly, &i32}; AccessControlType at{AccessControl::kReadOnly, &i32};
EXPECT_TRUE(at.IsAccessControl()); EXPECT_TRUE(at.Is<AccessControlType>());
EXPECT_FALSE(at.IsAlias()); EXPECT_FALSE(at.IsAlias());
EXPECT_FALSE(at.IsArray()); EXPECT_FALSE(at.IsArray());
EXPECT_FALSE(at.IsBool()); EXPECT_FALSE(at.IsBool());

View File

@ -48,19 +48,20 @@ TEST_F(AliasTypeTest, Is) {
I32Type i32; I32Type i32;
AliasType at{"a", &i32}; AliasType at{"a", &i32};
EXPECT_FALSE(at.IsAccessControl()); Type* ty = &at;
EXPECT_TRUE(at.IsAlias()); EXPECT_FALSE(ty->Is<AccessControlType>());
EXPECT_FALSE(at.IsArray()); EXPECT_TRUE(ty->IsAlias());
EXPECT_FALSE(at.IsBool()); EXPECT_FALSE(ty->IsArray());
EXPECT_FALSE(at.IsF32()); EXPECT_FALSE(ty->IsBool());
EXPECT_FALSE(at.IsI32()); EXPECT_FALSE(ty->IsF32());
EXPECT_FALSE(at.IsMatrix()); EXPECT_FALSE(ty->IsI32());
EXPECT_FALSE(at.IsPointer()); EXPECT_FALSE(ty->IsMatrix());
EXPECT_FALSE(at.IsSampler()); EXPECT_FALSE(ty->IsPointer());
EXPECT_FALSE(at.IsStruct()); EXPECT_FALSE(ty->IsSampler());
EXPECT_FALSE(at.IsTexture()); EXPECT_FALSE(ty->IsStruct());
EXPECT_FALSE(at.IsU32()); EXPECT_FALSE(ty->IsTexture());
EXPECT_FALSE(at.IsVector()); EXPECT_FALSE(ty->IsU32());
EXPECT_FALSE(ty->IsVector());
} }
TEST_F(AliasTypeTest, TypeName) { TEST_F(AliasTypeTest, TypeName) {

View File

@ -19,6 +19,7 @@
#include "src/ast/stride_decoration.h" #include "src/ast/stride_decoration.h"
#include "src/ast/test_helper.h" #include "src/ast/test_helper.h"
#include "src/ast/type/access_control_type.h"
#include "src/ast/type/i32_type.h" #include "src/ast/type/i32_type.h"
#include "src/ast/type/u32_type.h" #include "src/ast/type/u32_type.h"
@ -51,19 +52,20 @@ TEST_F(ArrayTypeTest, Is) {
I32Type i32; I32Type i32;
ArrayType arr{&i32, 3}; ArrayType arr{&i32, 3};
EXPECT_FALSE(arr.IsAccessControl()); Type* ty = &arr;
EXPECT_FALSE(arr.IsAlias()); EXPECT_FALSE(ty->Is<AccessControlType>());
EXPECT_TRUE(arr.IsArray()); EXPECT_FALSE(ty->IsAlias());
EXPECT_FALSE(arr.IsBool()); EXPECT_TRUE(ty->IsArray());
EXPECT_FALSE(arr.IsF32()); EXPECT_FALSE(ty->IsBool());
EXPECT_FALSE(arr.IsI32()); EXPECT_FALSE(ty->IsF32());
EXPECT_FALSE(arr.IsMatrix()); EXPECT_FALSE(ty->IsI32());
EXPECT_FALSE(arr.IsPointer()); EXPECT_FALSE(ty->IsMatrix());
EXPECT_FALSE(arr.IsSampler()); EXPECT_FALSE(ty->IsPointer());
EXPECT_FALSE(arr.IsStruct()); EXPECT_FALSE(ty->IsSampler());
EXPECT_FALSE(arr.IsTexture()); EXPECT_FALSE(ty->IsStruct());
EXPECT_FALSE(arr.IsU32()); EXPECT_FALSE(ty->IsTexture());
EXPECT_FALSE(arr.IsVector()); EXPECT_FALSE(ty->IsU32());
EXPECT_FALSE(ty->IsVector());
} }
TEST_F(ArrayTypeTest, TypeName) { TEST_F(ArrayTypeTest, TypeName) {

View File

@ -15,6 +15,7 @@
#include "src/ast/type/bool_type.h" #include "src/ast/type/bool_type.h"
#include "src/ast/test_helper.h" #include "src/ast/test_helper.h"
#include "src/ast/type/access_control_type.h"
namespace tint { namespace tint {
namespace ast { namespace ast {
@ -25,19 +26,20 @@ using BoolTypeTest = TestHelper;
TEST_F(BoolTypeTest, Is) { TEST_F(BoolTypeTest, Is) {
BoolType b; BoolType b;
EXPECT_FALSE(b.IsAccessControl()); Type* ty = &b;
EXPECT_FALSE(b.IsAlias()); EXPECT_FALSE(ty->Is<AccessControlType>());
EXPECT_FALSE(b.IsArray()); EXPECT_FALSE(ty->IsAlias());
EXPECT_TRUE(b.IsBool()); EXPECT_FALSE(ty->IsArray());
EXPECT_FALSE(b.IsF32()); EXPECT_TRUE(ty->IsBool());
EXPECT_FALSE(b.IsI32()); EXPECT_FALSE(ty->IsF32());
EXPECT_FALSE(b.IsMatrix()); EXPECT_FALSE(ty->IsI32());
EXPECT_FALSE(b.IsPointer()); EXPECT_FALSE(ty->IsMatrix());
EXPECT_FALSE(b.IsSampler()); EXPECT_FALSE(ty->IsPointer());
EXPECT_FALSE(b.IsStruct()); EXPECT_FALSE(ty->IsSampler());
EXPECT_FALSE(b.IsTexture()); EXPECT_FALSE(ty->IsStruct());
EXPECT_FALSE(b.IsU32()); EXPECT_FALSE(ty->IsTexture());
EXPECT_FALSE(b.IsVector()); EXPECT_FALSE(ty->IsU32());
EXPECT_FALSE(ty->IsVector());
} }
TEST_F(BoolTypeTest, TypeName) { TEST_F(BoolTypeTest, TypeName) {

View File

@ -16,6 +16,8 @@
#include "src/ast/test_helper.h" #include "src/ast/test_helper.h"
#include "src/ast/type/access_control_type.h"
namespace tint { namespace tint {
namespace ast { namespace ast {
namespace type { namespace type {
@ -25,19 +27,20 @@ using DepthTextureTypeTest = TestHelper;
TEST_F(DepthTextureTypeTest, Is) { TEST_F(DepthTextureTypeTest, Is) {
DepthTextureType d(TextureDimension::kCube); DepthTextureType d(TextureDimension::kCube);
EXPECT_FALSE(d.IsAccessControl()); Type* ty = &d;
EXPECT_FALSE(d.IsAlias()); EXPECT_FALSE(ty->Is<AccessControlType>());
EXPECT_FALSE(d.IsArray()); EXPECT_FALSE(ty->IsAlias());
EXPECT_FALSE(d.IsBool()); EXPECT_FALSE(ty->IsArray());
EXPECT_FALSE(d.IsF32()); EXPECT_FALSE(ty->IsBool());
EXPECT_FALSE(d.IsI32()); EXPECT_FALSE(ty->IsF32());
EXPECT_FALSE(d.IsMatrix()); EXPECT_FALSE(ty->IsI32());
EXPECT_FALSE(d.IsPointer()); EXPECT_FALSE(ty->IsMatrix());
EXPECT_FALSE(d.IsSampler()); EXPECT_FALSE(ty->IsPointer());
EXPECT_FALSE(d.IsStruct()); EXPECT_FALSE(ty->IsSampler());
EXPECT_TRUE(d.IsTexture()); EXPECT_FALSE(ty->IsStruct());
EXPECT_FALSE(d.IsU32()); EXPECT_TRUE(ty->IsTexture());
EXPECT_FALSE(d.IsVector()); EXPECT_FALSE(ty->IsU32());
EXPECT_FALSE(ty->IsVector());
} }
TEST_F(DepthTextureTypeTest, IsTextureType) { TEST_F(DepthTextureTypeTest, IsTextureType) {

View File

@ -15,6 +15,7 @@
#include "src/ast/type/f32_type.h" #include "src/ast/type/f32_type.h"
#include "src/ast/test_helper.h" #include "src/ast/test_helper.h"
#include "src/ast/type/access_control_type.h"
namespace tint { namespace tint {
namespace ast { namespace ast {
@ -25,19 +26,20 @@ using F32TypeTest = TestHelper;
TEST_F(F32TypeTest, Is) { TEST_F(F32TypeTest, Is) {
F32Type f; F32Type f;
EXPECT_FALSE(f.IsAccessControl()); Type* ty = &f;
EXPECT_FALSE(f.IsAlias()); EXPECT_FALSE(ty->Is<AccessControlType>());
EXPECT_FALSE(f.IsArray()); EXPECT_FALSE(ty->IsAlias());
EXPECT_FALSE(f.IsBool()); EXPECT_FALSE(ty->IsArray());
EXPECT_TRUE(f.IsF32()); EXPECT_FALSE(ty->IsBool());
EXPECT_FALSE(f.IsI32()); EXPECT_TRUE(ty->IsF32());
EXPECT_FALSE(f.IsMatrix()); EXPECT_FALSE(ty->IsI32());
EXPECT_FALSE(f.IsPointer()); EXPECT_FALSE(ty->IsMatrix());
EXPECT_FALSE(f.IsSampler()); EXPECT_FALSE(ty->IsPointer());
EXPECT_FALSE(f.IsStruct()); EXPECT_FALSE(ty->IsSampler());
EXPECT_FALSE(f.IsTexture()); EXPECT_FALSE(ty->IsStruct());
EXPECT_FALSE(f.IsU32()); EXPECT_FALSE(ty->IsTexture());
EXPECT_FALSE(f.IsVector()); EXPECT_FALSE(ty->IsU32());
EXPECT_FALSE(ty->IsVector());
} }
TEST_F(F32TypeTest, TypeName) { TEST_F(F32TypeTest, TypeName) {

View File

@ -15,6 +15,7 @@
#include "src/ast/type/i32_type.h" #include "src/ast/type/i32_type.h"
#include "src/ast/test_helper.h" #include "src/ast/test_helper.h"
#include "src/ast/type/access_control_type.h"
namespace tint { namespace tint {
namespace ast { namespace ast {
@ -25,19 +26,20 @@ using I32TypeTest = TestHelper;
TEST_F(I32TypeTest, Is) { TEST_F(I32TypeTest, Is) {
I32Type i; I32Type i;
EXPECT_FALSE(i.IsAccessControl()); Type* ty = &i;
EXPECT_FALSE(i.IsAlias()); EXPECT_FALSE(ty->Is<AccessControlType>());
EXPECT_FALSE(i.IsArray()); EXPECT_FALSE(ty->IsAlias());
EXPECT_FALSE(i.IsBool()); EXPECT_FALSE(ty->IsArray());
EXPECT_FALSE(i.IsF32()); EXPECT_FALSE(ty->IsBool());
EXPECT_TRUE(i.IsI32()); EXPECT_FALSE(ty->IsF32());
EXPECT_FALSE(i.IsMatrix()); EXPECT_TRUE(ty->IsI32());
EXPECT_FALSE(i.IsPointer()); EXPECT_FALSE(ty->IsMatrix());
EXPECT_FALSE(i.IsSampler()); EXPECT_FALSE(ty->IsPointer());
EXPECT_FALSE(i.IsStruct()); EXPECT_FALSE(ty->IsSampler());
EXPECT_FALSE(i.IsTexture()); EXPECT_FALSE(ty->IsStruct());
EXPECT_FALSE(i.IsU32()); EXPECT_FALSE(ty->IsTexture());
EXPECT_FALSE(i.IsVector()); EXPECT_FALSE(ty->IsU32());
EXPECT_FALSE(ty->IsVector());
} }
TEST_F(I32TypeTest, TypeName) { TEST_F(I32TypeTest, TypeName) {

View File

@ -15,6 +15,7 @@
#include "src/ast/type/matrix_type.h" #include "src/ast/type/matrix_type.h"
#include "src/ast/test_helper.h" #include "src/ast/test_helper.h"
#include "src/ast/type/access_control_type.h"
#include "src/ast/type/i32_type.h" #include "src/ast/type/i32_type.h"
namespace tint { namespace tint {
@ -35,19 +36,20 @@ TEST_F(MatrixTypeTest, Creation) {
TEST_F(MatrixTypeTest, Is) { TEST_F(MatrixTypeTest, Is) {
I32Type i32; I32Type i32;
MatrixType m{&i32, 2, 3}; MatrixType m{&i32, 2, 3};
EXPECT_FALSE(m.IsAccessControl()); Type* ty = &m;
EXPECT_FALSE(m.IsAlias()); EXPECT_FALSE(ty->Is<AccessControlType>());
EXPECT_FALSE(m.IsArray()); EXPECT_FALSE(ty->IsAlias());
EXPECT_FALSE(m.IsBool()); EXPECT_FALSE(ty->IsArray());
EXPECT_FALSE(m.IsF32()); EXPECT_FALSE(ty->IsBool());
EXPECT_FALSE(m.IsI32()); EXPECT_FALSE(ty->IsF32());
EXPECT_TRUE(m.IsMatrix()); EXPECT_FALSE(ty->IsI32());
EXPECT_FALSE(m.IsPointer()); EXPECT_TRUE(ty->IsMatrix());
EXPECT_FALSE(m.IsSampler()); EXPECT_FALSE(ty->IsPointer());
EXPECT_FALSE(m.IsStruct()); EXPECT_FALSE(ty->IsSampler());
EXPECT_FALSE(m.IsTexture()); EXPECT_FALSE(ty->IsStruct());
EXPECT_FALSE(m.IsU32()); EXPECT_FALSE(ty->IsTexture());
EXPECT_FALSE(m.IsVector()); EXPECT_FALSE(ty->IsU32());
EXPECT_FALSE(ty->IsVector());
} }
TEST_F(MatrixTypeTest, TypeName) { TEST_F(MatrixTypeTest, TypeName) {

View File

@ -15,6 +15,7 @@
#include "src/ast/type/multisampled_texture_type.h" #include "src/ast/type/multisampled_texture_type.h"
#include "src/ast/test_helper.h" #include "src/ast/test_helper.h"
#include "src/ast/type/access_control_type.h"
#include "src/ast/type/f32_type.h" #include "src/ast/type/f32_type.h"
namespace tint { namespace tint {
@ -27,19 +28,20 @@ using MultisampledTextureTypeTest = TestHelper;
TEST_F(MultisampledTextureTypeTest, Is) { TEST_F(MultisampledTextureTypeTest, Is) {
F32Type f32; F32Type f32;
MultisampledTextureType s(TextureDimension::kCube, &f32); MultisampledTextureType s(TextureDimension::kCube, &f32);
EXPECT_FALSE(s.IsAccessControl()); Type* ty = &s;
EXPECT_FALSE(s.IsAlias()); EXPECT_FALSE(ty->Is<AccessControlType>());
EXPECT_FALSE(s.IsArray()); EXPECT_FALSE(ty->IsAlias());
EXPECT_FALSE(s.IsBool()); EXPECT_FALSE(ty->IsArray());
EXPECT_FALSE(s.IsF32()); EXPECT_FALSE(ty->IsBool());
EXPECT_FALSE(s.IsI32()); EXPECT_FALSE(ty->IsF32());
EXPECT_FALSE(s.IsMatrix()); EXPECT_FALSE(ty->IsI32());
EXPECT_FALSE(s.IsPointer()); EXPECT_FALSE(ty->IsMatrix());
EXPECT_FALSE(s.IsSampler()); EXPECT_FALSE(ty->IsPointer());
EXPECT_FALSE(s.IsStruct()); EXPECT_FALSE(ty->IsSampler());
EXPECT_TRUE(s.IsTexture()); EXPECT_FALSE(ty->IsStruct());
EXPECT_FALSE(s.IsU32()); EXPECT_TRUE(ty->IsTexture());
EXPECT_FALSE(s.IsVector()); EXPECT_FALSE(ty->IsU32());
EXPECT_FALSE(ty->IsVector());
} }
TEST_F(MultisampledTextureTypeTest, IsTextureType) { TEST_F(MultisampledTextureTypeTest, IsTextureType) {

View File

@ -15,6 +15,7 @@
#include "src/ast/type/pointer_type.h" #include "src/ast/type/pointer_type.h"
#include "src/ast/test_helper.h" #include "src/ast/test_helper.h"
#include "src/ast/type/access_control_type.h"
#include "src/ast/type/i32_type.h" #include "src/ast/type/i32_type.h"
namespace tint { namespace tint {
@ -34,19 +35,20 @@ TEST_F(PointerTypeTest, Creation) {
TEST_F(PointerTypeTest, Is) { TEST_F(PointerTypeTest, Is) {
I32Type i32; I32Type i32;
PointerType p{&i32, StorageClass::kFunction}; PointerType p{&i32, StorageClass::kFunction};
EXPECT_FALSE(p.IsAccessControl()); Type* ty = &p;
EXPECT_FALSE(p.IsAlias()); EXPECT_FALSE(ty->Is<AccessControlType>());
EXPECT_FALSE(p.IsArray()); EXPECT_FALSE(ty->IsAlias());
EXPECT_FALSE(p.IsBool()); EXPECT_FALSE(ty->IsArray());
EXPECT_FALSE(p.IsF32()); EXPECT_FALSE(ty->IsBool());
EXPECT_FALSE(p.IsI32()); EXPECT_FALSE(ty->IsF32());
EXPECT_FALSE(p.IsMatrix()); EXPECT_FALSE(ty->IsI32());
EXPECT_TRUE(p.IsPointer()); EXPECT_FALSE(ty->IsMatrix());
EXPECT_FALSE(p.IsSampler()); EXPECT_TRUE(ty->IsPointer());
EXPECT_FALSE(p.IsStruct()); EXPECT_FALSE(ty->IsSampler());
EXPECT_FALSE(p.IsTexture()); EXPECT_FALSE(ty->IsStruct());
EXPECT_FALSE(p.IsU32()); EXPECT_FALSE(ty->IsTexture());
EXPECT_FALSE(p.IsVector()); EXPECT_FALSE(ty->IsU32());
EXPECT_FALSE(ty->IsVector());
} }
TEST_F(PointerTypeTest, TypeName) { TEST_F(PointerTypeTest, TypeName) {

View File

@ -15,6 +15,7 @@
#include "src/ast/type/sampled_texture_type.h" #include "src/ast/type/sampled_texture_type.h"
#include "src/ast/test_helper.h" #include "src/ast/test_helper.h"
#include "src/ast/type/access_control_type.h"
#include "src/ast/type/f32_type.h" #include "src/ast/type/f32_type.h"
namespace tint { namespace tint {
@ -27,19 +28,20 @@ using SampledTextureTypeTest = TestHelper;
TEST_F(SampledTextureTypeTest, Is) { TEST_F(SampledTextureTypeTest, Is) {
F32Type f32; F32Type f32;
SampledTextureType s(TextureDimension::kCube, &f32); SampledTextureType s(TextureDimension::kCube, &f32);
EXPECT_FALSE(s.IsAccessControl()); Type* ty = &s;
EXPECT_FALSE(s.IsAlias()); EXPECT_FALSE(ty->Is<AccessControlType>());
EXPECT_FALSE(s.IsArray()); EXPECT_FALSE(ty->IsAlias());
EXPECT_FALSE(s.IsBool()); EXPECT_FALSE(ty->IsArray());
EXPECT_FALSE(s.IsF32()); EXPECT_FALSE(ty->IsBool());
EXPECT_FALSE(s.IsI32()); EXPECT_FALSE(ty->IsF32());
EXPECT_FALSE(s.IsMatrix()); EXPECT_FALSE(ty->IsI32());
EXPECT_FALSE(s.IsPointer()); EXPECT_FALSE(ty->IsMatrix());
EXPECT_FALSE(s.IsSampler()); EXPECT_FALSE(ty->IsPointer());
EXPECT_FALSE(s.IsStruct()); EXPECT_FALSE(ty->IsSampler());
EXPECT_TRUE(s.IsTexture()); EXPECT_FALSE(ty->IsStruct());
EXPECT_FALSE(s.IsU32()); EXPECT_TRUE(ty->IsTexture());
EXPECT_FALSE(s.IsVector()); EXPECT_FALSE(ty->IsU32());
EXPECT_FALSE(ty->IsVector());
} }
TEST_F(SampledTextureTypeTest, IsTextureType) { TEST_F(SampledTextureTypeTest, IsTextureType) {

View File

@ -15,6 +15,7 @@
#include "src/ast/type/sampler_type.h" #include "src/ast/type/sampler_type.h"
#include "src/ast/test_helper.h" #include "src/ast/test_helper.h"
#include "src/ast/type/access_control_type.h"
namespace tint { namespace tint {
namespace ast { namespace ast {
@ -36,19 +37,20 @@ TEST_F(SamplerTypeTest, Creation_ComparisonSampler) {
TEST_F(SamplerTypeTest, Is) { TEST_F(SamplerTypeTest, Is) {
SamplerType s{SamplerKind::kSampler}; SamplerType s{SamplerKind::kSampler};
EXPECT_FALSE(s.IsAccessControl()); Type* ty = &s;
EXPECT_FALSE(s.IsAlias()); EXPECT_FALSE(ty->Is<AccessControlType>());
EXPECT_FALSE(s.IsArray()); EXPECT_FALSE(ty->IsAlias());
EXPECT_FALSE(s.IsBool()); EXPECT_FALSE(ty->IsArray());
EXPECT_FALSE(s.IsF32()); EXPECT_FALSE(ty->IsBool());
EXPECT_FALSE(s.IsI32()); EXPECT_FALSE(ty->IsF32());
EXPECT_FALSE(s.IsMatrix()); EXPECT_FALSE(ty->IsI32());
EXPECT_FALSE(s.IsPointer()); EXPECT_FALSE(ty->IsMatrix());
EXPECT_TRUE(s.IsSampler()); EXPECT_FALSE(ty->IsPointer());
EXPECT_FALSE(s.IsStruct()); EXPECT_TRUE(ty->IsSampler());
EXPECT_FALSE(s.IsTexture()); EXPECT_FALSE(ty->IsStruct());
EXPECT_FALSE(s.IsU32()); EXPECT_FALSE(ty->IsTexture());
EXPECT_FALSE(s.IsVector()); EXPECT_FALSE(ty->IsU32());
EXPECT_FALSE(ty->IsVector());
} }
TEST_F(SamplerTypeTest, TypeName_Sampler) { TEST_F(SamplerTypeTest, TypeName_Sampler) {

View File

@ -18,6 +18,7 @@
#include "src/ast/identifier_expression.h" #include "src/ast/identifier_expression.h"
#include "src/ast/test_helper.h" #include "src/ast/test_helper.h"
#include "src/ast/type/access_control_type.h"
#include "src/type_determiner.h" #include "src/type_determiner.h"
namespace tint { namespace tint {
@ -30,19 +31,20 @@ using StorageTextureTypeTest = TestHelper;
TEST_F(StorageTextureTypeTest, Is) { TEST_F(StorageTextureTypeTest, Is) {
StorageTextureType s(TextureDimension::k2dArray, AccessControl::kReadOnly, StorageTextureType s(TextureDimension::k2dArray, AccessControl::kReadOnly,
ImageFormat::kRgba32Float); ImageFormat::kRgba32Float);
EXPECT_FALSE(s.IsAccessControl()); Type* ty = &s;
EXPECT_FALSE(s.IsAlias()); EXPECT_FALSE(ty->Is<AccessControlType>());
EXPECT_FALSE(s.IsArray()); EXPECT_FALSE(ty->IsAlias());
EXPECT_FALSE(s.IsBool()); EXPECT_FALSE(ty->IsArray());
EXPECT_FALSE(s.IsF32()); EXPECT_FALSE(ty->IsBool());
EXPECT_FALSE(s.IsI32()); EXPECT_FALSE(ty->IsF32());
EXPECT_FALSE(s.IsMatrix()); EXPECT_FALSE(ty->IsI32());
EXPECT_FALSE(s.IsPointer()); EXPECT_FALSE(ty->IsMatrix());
EXPECT_FALSE(s.IsSampler()); EXPECT_FALSE(ty->IsPointer());
EXPECT_FALSE(s.IsStruct()); EXPECT_FALSE(ty->IsSampler());
EXPECT_TRUE(s.IsTexture()); EXPECT_FALSE(ty->IsStruct());
EXPECT_FALSE(s.IsU32()); EXPECT_TRUE(ty->IsTexture());
EXPECT_FALSE(s.IsVector()); EXPECT_FALSE(ty->IsU32());
EXPECT_FALSE(ty->IsVector());
} }
TEST_F(StorageTextureTypeTest, IsTextureType) { TEST_F(StorageTextureTypeTest, IsTextureType) {

View File

@ -21,6 +21,7 @@
#include "src/ast/struct_member_decoration.h" #include "src/ast/struct_member_decoration.h"
#include "src/ast/struct_member_offset_decoration.h" #include "src/ast/struct_member_offset_decoration.h"
#include "src/ast/test_helper.h" #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/array_type.h"
#include "src/ast/type/i32_type.h" #include "src/ast/type/i32_type.h"
#include "src/ast/type/u32_type.h" #include "src/ast/type/u32_type.h"
@ -43,19 +44,20 @@ TEST_F(StructTypeTest, Creation) {
TEST_F(StructTypeTest, Is) { TEST_F(StructTypeTest, Is) {
auto* impl = create<Struct>(); auto* impl = create<Struct>();
StructType s{"S", impl}; StructType s{"S", impl};
EXPECT_FALSE(s.IsAccessControl()); Type* ty = &s;
EXPECT_FALSE(s.IsAlias()); EXPECT_FALSE(ty->Is<AccessControlType>());
EXPECT_FALSE(s.IsArray()); EXPECT_FALSE(ty->IsAlias());
EXPECT_FALSE(s.IsBool()); EXPECT_FALSE(ty->IsArray());
EXPECT_FALSE(s.IsF32()); EXPECT_FALSE(ty->IsBool());
EXPECT_FALSE(s.IsI32()); EXPECT_FALSE(ty->IsF32());
EXPECT_FALSE(s.IsMatrix()); EXPECT_FALSE(ty->IsI32());
EXPECT_FALSE(s.IsPointer()); EXPECT_FALSE(ty->IsMatrix());
EXPECT_FALSE(s.IsSampler()); EXPECT_FALSE(ty->IsPointer());
EXPECT_TRUE(s.IsStruct()); EXPECT_FALSE(ty->IsSampler());
EXPECT_FALSE(s.IsTexture()); EXPECT_TRUE(ty->IsStruct());
EXPECT_FALSE(s.IsU32()); EXPECT_FALSE(ty->IsTexture());
EXPECT_FALSE(s.IsVector()); EXPECT_FALSE(ty->IsU32());
EXPECT_FALSE(ty->IsVector());
} }
TEST_F(StructTypeTest, TypeName) { TEST_F(StructTypeTest, TypeName) {

View File

@ -37,7 +37,7 @@ namespace type {
Type::Type() = default; Type::Type() = default;
Type:: Type(Type&&) = default; Type::Type(Type&&) = default;
Type::~Type() = default; Type::~Type() = default;
@ -52,9 +52,9 @@ Type* Type::UnwrapIfNeeded() {
auto* where = this; auto* where = this;
while (true) { while (true) {
if (where->IsAlias()) { if (where->IsAlias()) {
where = where->AsAlias()->type(); where = where->AsAlias()->type();
} else if (where->IsAccessControl()) { } else if (where->Is<AccessControlType>()) {
where = where->AsAccessControl()->type(); where = where->As<AccessControlType>()->type();
} else { } else {
break; break;
} }
@ -66,10 +66,6 @@ Type* Type::UnwrapAll() {
return UnwrapIfNeeded()->UnwrapPtrIfNeeded()->UnwrapIfNeeded(); return UnwrapIfNeeded()->UnwrapPtrIfNeeded()->UnwrapIfNeeded();
} }
bool Type::IsAccessControl() const {
return false;
}
bool Type::IsAlias() const { bool Type::IsAlias() const {
return false; return false;
} }
@ -174,11 +170,6 @@ bool Type::is_integer_scalar_or_vector() {
return is_unsigned_scalar_or_vector() || is_signed_scalar_or_vector(); return is_unsigned_scalar_or_vector() || is_signed_scalar_or_vector();
} }
const AccessControlType* Type::AsAccessControl() const {
assert(IsAccessControl());
return static_cast<const AccessControlType*>(this);
}
const AliasType* Type::AsAlias() const { const AliasType* Type::AsAlias() const {
assert(IsAlias()); assert(IsAlias());
return static_cast<const AliasType*>(this); return static_cast<const AliasType*>(this);
@ -244,11 +235,6 @@ const VoidType* Type::AsVoid() const {
return static_cast<const VoidType*>(this); return static_cast<const VoidType*>(this);
} }
AccessControlType* Type::AsAccessControl() {
assert(IsAccessControl());
return static_cast<AccessControlType*>(this);
}
AliasType* Type::AsAlias() { AliasType* Type::AsAlias() {
assert(IsAlias()); assert(IsAlias());
return static_cast<AliasType*>(this); return static_cast<AliasType*>(this);

View File

@ -23,7 +23,6 @@ namespace tint {
namespace ast { namespace ast {
namespace type { namespace type {
class AccessControlType;
class AliasType; class AliasType;
class ArrayType; class ArrayType;
class BoolType; class BoolType;
@ -48,8 +47,6 @@ class Type : public Castable<Type> {
Type(Type&&); Type(Type&&);
~Type() override; ~Type() override;
/// @returns true if the type is an access control type
virtual bool IsAccessControl() const;
/// @returns true if the type is an alias type /// @returns true if the type is an alias type
virtual bool IsAlias() const; virtual bool IsAlias() const;
/// @returns true if the type is an array type /// @returns true if the type is an array type
@ -131,8 +128,6 @@ class Type : public Castable<Type> {
/// @returns true if this type is an integer scalar or vector /// @returns true if this type is an integer scalar or vector
bool is_integer_scalar_or_vector(); bool is_integer_scalar_or_vector();
/// @returns the type as an access control type
const AccessControlType* AsAccessControl() const;
/// @returns the type as an alias type /// @returns the type as an alias type
const AliasType* AsAlias() const; const AliasType* AsAlias() const;
/// @returns the type as an array type /// @returns the type as an array type
@ -160,8 +155,6 @@ class Type : public Castable<Type> {
/// @returns the type as a void type /// @returns the type as a void type
const VoidType* AsVoid() const; const VoidType* AsVoid() const;
/// @returns the type as an access control type
AccessControlType* AsAccessControl();
/// @returns the type as an alias type /// @returns the type as an alias type
AliasType* AsAlias(); AliasType* AsAlias();
/// @returns the type as an array type /// @returns the type as an array type

View File

@ -15,6 +15,7 @@
#include "src/ast/type/u32_type.h" #include "src/ast/type/u32_type.h"
#include "src/ast/test_helper.h" #include "src/ast/test_helper.h"
#include "src/ast/type/access_control_type.h"
namespace tint { namespace tint {
namespace ast { namespace ast {
@ -25,19 +26,20 @@ using U32TypeTest = TestHelper;
TEST_F(U32TypeTest, Is) { TEST_F(U32TypeTest, Is) {
U32Type u; U32Type u;
EXPECT_FALSE(u.IsAccessControl()); Type* ty = &u;
EXPECT_FALSE(u.IsAlias()); EXPECT_FALSE(ty->Is<AccessControlType>());
EXPECT_FALSE(u.IsArray()); EXPECT_FALSE(ty->IsAlias());
EXPECT_FALSE(u.IsBool()); EXPECT_FALSE(ty->IsArray());
EXPECT_FALSE(u.IsF32()); EXPECT_FALSE(ty->IsBool());
EXPECT_FALSE(u.IsI32()); EXPECT_FALSE(ty->IsF32());
EXPECT_FALSE(u.IsMatrix()); EXPECT_FALSE(ty->IsI32());
EXPECT_FALSE(u.IsPointer()); EXPECT_FALSE(ty->IsMatrix());
EXPECT_FALSE(u.IsSampler()); EXPECT_FALSE(ty->IsPointer());
EXPECT_FALSE(u.IsStruct()); EXPECT_FALSE(ty->IsSampler());
EXPECT_FALSE(u.IsTexture()); EXPECT_FALSE(ty->IsStruct());
EXPECT_TRUE(u.IsU32()); EXPECT_FALSE(ty->IsTexture());
EXPECT_FALSE(u.IsVector()); EXPECT_TRUE(ty->IsU32());
EXPECT_FALSE(ty->IsVector());
} }
TEST_F(U32TypeTest, TypeName) { TEST_F(U32TypeTest, TypeName) {

View File

@ -15,6 +15,7 @@
#include "src/ast/type/vector_type.h" #include "src/ast/type/vector_type.h"
#include "src/ast/test_helper.h" #include "src/ast/test_helper.h"
#include "src/ast/type/access_control_type.h"
#include "src/ast/type/i32_type.h" #include "src/ast/type/i32_type.h"
namespace tint { namespace tint {
@ -34,19 +35,20 @@ TEST_F(VectorTypeTest, Creation) {
TEST_F(VectorTypeTest, Is) { TEST_F(VectorTypeTest, Is) {
I32Type i32; I32Type i32;
VectorType v{&i32, 4}; VectorType v{&i32, 4};
EXPECT_FALSE(v.IsAccessControl()); Type* ty = &v;
EXPECT_FALSE(v.IsAlias()); EXPECT_FALSE(ty->Is<AccessControlType>());
EXPECT_FALSE(v.IsArray()); EXPECT_FALSE(ty->IsAlias());
EXPECT_FALSE(v.IsBool()); EXPECT_FALSE(ty->IsArray());
EXPECT_FALSE(v.IsF32()); EXPECT_FALSE(ty->IsBool());
EXPECT_FALSE(v.IsI32()); EXPECT_FALSE(ty->IsF32());
EXPECT_FALSE(v.IsMatrix()); EXPECT_FALSE(ty->IsI32());
EXPECT_FALSE(v.IsPointer()); EXPECT_FALSE(ty->IsMatrix());
EXPECT_FALSE(v.IsSampler()); EXPECT_FALSE(ty->IsPointer());
EXPECT_FALSE(v.IsStruct()); EXPECT_FALSE(ty->IsSampler());
EXPECT_FALSE(v.IsTexture()); EXPECT_FALSE(ty->IsStruct());
EXPECT_FALSE(v.IsU32()); EXPECT_FALSE(ty->IsTexture());
EXPECT_TRUE(v.IsVector()); EXPECT_FALSE(ty->IsU32());
EXPECT_TRUE(ty->IsVector());
} }
TEST_F(VectorTypeTest, TypeName) { TEST_F(VectorTypeTest, TypeName) {

View File

@ -181,7 +181,7 @@ std::vector<ResourceBinding> Inspector::GetUniformBufferResourceBindings(
ast::Variable* var = nullptr; ast::Variable* var = nullptr;
ast::Function::BindingInfo binding_info; ast::Function::BindingInfo binding_info;
std::tie(var, binding_info) = ruv; std::tie(var, binding_info) = ruv;
if (!var->type()->IsAccessControl()) { if (!var->type()->Is<ast::type::AccessControlType>()) {
continue; continue;
} }
auto* unwrapped_type = var->type()->UnwrapIfNeeded(); auto* unwrapped_type = var->type()->UnwrapIfNeeded();
@ -303,11 +303,11 @@ std::vector<ResourceBinding> Inspector::GetStorageBufferResourceBindingsImpl(
ast::Variable* var = nullptr; ast::Variable* var = nullptr;
ast::Function::BindingInfo binding_info; ast::Function::BindingInfo binding_info;
std::tie(var, binding_info) = rsv; std::tie(var, binding_info) = rsv;
if (!var->type()->IsAccessControl()) { if (!var->type()->Is<ast::type::AccessControlType>()) {
continue; continue;
} }
auto* ac_type = var->type()->AsAccessControl(); auto* ac_type = var->type()->As<ast::type::AccessControlType>();
if (read_only != ac_type->IsReadOnly()) { if (read_only != ac_type->IsReadOnly()) {
continue; continue;
} }

View File

@ -103,8 +103,8 @@ TEST_F(ParserImplTest, VariableIdentDecl_ParsesWithAccessDeco_Read) {
ASSERT_FALSE(decl.errored); ASSERT_FALSE(decl.errored);
ASSERT_EQ(decl->name, "my_var"); ASSERT_EQ(decl->name, "my_var");
ASSERT_NE(decl->type, nullptr); ASSERT_NE(decl->type, nullptr);
ASSERT_TRUE(decl->type->IsAccessControl()); ASSERT_TRUE(decl->type->Is<ast::type::AccessControlType>());
EXPECT_TRUE(decl->type->AsAccessControl()->IsReadOnly()); EXPECT_TRUE(decl->type->As<ast::type::AccessControlType>()->IsReadOnly());
} }
TEST_F(ParserImplTest, VariableIdentDecl_ParsesWithAccessDeco_ReadWrite) { TEST_F(ParserImplTest, VariableIdentDecl_ParsesWithAccessDeco_ReadWrite) {
@ -129,8 +129,8 @@ TEST_F(ParserImplTest, VariableIdentDecl_ParsesWithAccessDeco_ReadWrite) {
ASSERT_FALSE(decl.errored); ASSERT_FALSE(decl.errored);
ASSERT_EQ(decl->name, "my_var"); ASSERT_EQ(decl->name, "my_var");
ASSERT_NE(decl->type, nullptr); ASSERT_NE(decl->type, nullptr);
ASSERT_TRUE(decl->type->IsAccessControl()); ASSERT_TRUE(decl->type->Is<ast::type::AccessControlType>());
EXPECT_TRUE(decl->type->AsAccessControl()->IsReadWrite()); EXPECT_TRUE(decl->type->As<ast::type::AccessControlType>()->IsReadWrite());
} }
TEST_F(ParserImplTest, VariableIdentDecl_MultipleAccessDecoFail) { TEST_F(ParserImplTest, VariableIdentDecl_MultipleAccessDecoFail) {

View File

@ -1328,11 +1328,11 @@ bool GeneratorImpl::EmitEntryPointData(
} }
emitted_globals.insert(var->name()); emitted_globals.insert(var->name());
if (!var->type()->IsAccessControl()) { if (!var->type()->Is<ast::type::AccessControlType>()) {
error_ = "access control type required for storage buffer"; error_ = "access control type required for storage buffer";
return false; return false;
} }
auto* ac = var->type()->AsAccessControl(); auto* ac = var->type()->As<ast::type::AccessControlType>();
if (ac->IsReadWrite()) { if (ac->IsReadWrite()) {
out << "RW"; out << "RW";

View File

@ -1282,11 +1282,11 @@ bool GeneratorImpl::EmitFunctionInternal(ast::Function* func,
} }
first = false; first = false;
if (!var->type()->IsAccessControl()) { if (!var->type()->Is<ast::type::AccessControlType>()) {
error_ = "invalid type for storage buffer, expected access control"; error_ = "invalid type for storage buffer, expected access control";
return false; return false;
} }
auto* ac = var->type()->AsAccessControl(); auto* ac = var->type()->As<ast::type::AccessControlType>();
if (ac->IsReadOnly()) { if (ac->IsReadOnly()) {
out_ << "const "; out_ << "const ";
} }
@ -1443,11 +1443,11 @@ bool GeneratorImpl::EmitEntryPointFunction(ast::Function* func) {
auto* binding = data.second.binding; auto* binding = data.second.binding;
// auto* set = data.second.set; // auto* set = data.second.set;
if (!var->type()->IsAccessControl()) { if (!var->type()->Is<ast::type::AccessControlType>()) {
error_ = "invalid type for storage buffer, expected access control"; error_ = "invalid type for storage buffer, expected access control";
return false; return false;
} }
auto* ac = var->type()->AsAccessControl(); auto* ac = var->type()->As<ast::type::AccessControlType>();
if (ac->IsReadOnly()) { if (ac->IsReadOnly()) {
out_ << "const "; out_ << "const ";
} }

View File

@ -2399,8 +2399,8 @@ uint32_t Builder::GenerateTypeIfNeeded(ast::type::Type* type) {
auto result = result_op(); auto result = result_op();
auto id = result.to_i(); auto id = result.to_i();
if (type->IsAccessControl()) { if (type->Is<ast::type::AccessControlType>()) {
auto* ac = type->AsAccessControl(); auto* ac = type->As<ast::type::AccessControlType>();
auto* subtype = ac->type()->UnwrapIfNeeded(); auto* subtype = ac->type()->UnwrapIfNeeded();
if (!subtype->IsStruct()) { if (!subtype->IsStruct()) {
error_ = "Access control attached to non-struct type."; error_ = "Access control attached to non-struct type.";

View File

@ -394,8 +394,8 @@ bool GeneratorImpl::EmitImageFormat(const ast::type::ImageFormat fmt) {
} }
bool GeneratorImpl::EmitType(ast::type::Type* type) { bool GeneratorImpl::EmitType(ast::type::Type* type) {
if (type->IsAccessControl()) { if (type->Is<ast::type::AccessControlType>()) {
auto* ac = type->AsAccessControl(); auto* ac = type->As<ast::type::AccessControlType>();
out_ << "[[access("; out_ << "[[access(";
if (ac->IsReadOnly()) { if (ac->IsReadOnly()) {