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

Change-Id: Iaa43e607199e25308ecb121c61bb7a37abff197c
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/34270
Reviewed-by: dan sinclair <dsinclair@chromium.org>
This commit is contained in:
Ben Clayton
2020-11-30 23:30:58 +00:00
parent c52f4214ad
commit 351128a41e
28 changed files with 36 additions and 63 deletions

View File

@@ -281,8 +281,8 @@ Function::ReferencedSamplerVariablesImpl(type::SamplerKind kind) const {
for (auto* var : referenced_module_variables()) {
auto* unwrapped_type = var->type()->UnwrapIfNeeded();
if (!var->IsDecorated() || !unwrapped_type->IsSampler() ||
unwrapped_type->AsSampler()->kind() != kind) {
if (!var->IsDecorated() || !unwrapped_type->Is<ast::type::SamplerType>() ||
unwrapped_type->As<ast::type::SamplerType>()->kind() != kind) {
continue;
}

View File

@@ -59,7 +59,7 @@ TEST_F(AccessControlTypeTest, Is) {
EXPECT_FALSE(ty->Is<I32Type>());
EXPECT_FALSE(ty->Is<MatrixType>());
EXPECT_FALSE(ty->Is<PointerType>());
EXPECT_FALSE(ty->IsSampler());
EXPECT_FALSE(ty->Is<SamplerType>());
EXPECT_FALSE(ty->IsStruct());
EXPECT_FALSE(ty->IsTexture());
EXPECT_FALSE(ty->IsU32());

View File

@@ -60,7 +60,7 @@ TEST_F(AliasTypeTest, Is) {
EXPECT_FALSE(ty->Is<I32Type>());
EXPECT_FALSE(ty->Is<MatrixType>());
EXPECT_FALSE(ty->Is<PointerType>());
EXPECT_FALSE(ty->IsSampler());
EXPECT_FALSE(ty->Is<SamplerType>());
EXPECT_FALSE(ty->IsStruct());
EXPECT_FALSE(ty->IsTexture());
EXPECT_FALSE(ty->IsU32());

View File

@@ -65,7 +65,7 @@ TEST_F(ArrayTypeTest, Is) {
EXPECT_FALSE(ty->Is<I32Type>());
EXPECT_FALSE(ty->Is<MatrixType>());
EXPECT_FALSE(ty->Is<PointerType>());
EXPECT_FALSE(ty->IsSampler());
EXPECT_FALSE(ty->Is<SamplerType>());
EXPECT_FALSE(ty->IsStruct());
EXPECT_FALSE(ty->IsTexture());
EXPECT_FALSE(ty->IsU32());

View File

@@ -40,7 +40,7 @@ TEST_F(BoolTypeTest, Is) {
EXPECT_FALSE(ty->Is<I32Type>());
EXPECT_FALSE(ty->Is<MatrixType>());
EXPECT_FALSE(ty->Is<PointerType>());
EXPECT_FALSE(ty->IsSampler());
EXPECT_FALSE(ty->Is<SamplerType>());
EXPECT_FALSE(ty->IsStruct());
EXPECT_FALSE(ty->IsTexture());
EXPECT_FALSE(ty->IsU32());

View File

@@ -42,7 +42,7 @@ TEST_F(DepthTextureTypeTest, Is) {
EXPECT_FALSE(ty->Is<I32Type>());
EXPECT_FALSE(ty->Is<MatrixType>());
EXPECT_FALSE(ty->Is<PointerType>());
EXPECT_FALSE(ty->IsSampler());
EXPECT_FALSE(ty->Is<SamplerType>());
EXPECT_FALSE(ty->IsStruct());
EXPECT_TRUE(ty->IsTexture());
EXPECT_FALSE(ty->IsU32());

View File

@@ -40,7 +40,7 @@ TEST_F(F32TypeTest, Is) {
EXPECT_FALSE(ty->Is<I32Type>());
EXPECT_FALSE(ty->Is<MatrixType>());
EXPECT_FALSE(ty->Is<PointerType>());
EXPECT_FALSE(ty->IsSampler());
EXPECT_FALSE(ty->Is<SamplerType>());
EXPECT_FALSE(ty->IsStruct());
EXPECT_FALSE(ty->IsTexture());
EXPECT_FALSE(ty->IsU32());

View File

@@ -40,7 +40,7 @@ TEST_F(I32TypeTest, Is) {
EXPECT_TRUE(ty->Is<I32Type>());
EXPECT_FALSE(ty->Is<MatrixType>());
EXPECT_FALSE(ty->Is<PointerType>());
EXPECT_FALSE(ty->IsSampler());
EXPECT_FALSE(ty->Is<SamplerType>());
EXPECT_FALSE(ty->IsStruct());
EXPECT_FALSE(ty->IsTexture());
EXPECT_FALSE(ty->IsU32());

View File

@@ -49,7 +49,7 @@ TEST_F(MatrixTypeTest, Is) {
EXPECT_FALSE(ty->Is<I32Type>());
EXPECT_TRUE(ty->Is<MatrixType>());
EXPECT_FALSE(ty->Is<PointerType>());
EXPECT_FALSE(ty->IsSampler());
EXPECT_FALSE(ty->Is<SamplerType>());
EXPECT_FALSE(ty->IsStruct());
EXPECT_FALSE(ty->IsTexture());
EXPECT_FALSE(ty->IsU32());

View File

@@ -42,7 +42,7 @@ TEST_F(MultisampledTextureTypeTest, Is) {
EXPECT_FALSE(ty->Is<I32Type>());
EXPECT_FALSE(ty->Is<MatrixType>());
EXPECT_FALSE(ty->Is<PointerType>());
EXPECT_FALSE(ty->IsSampler());
EXPECT_FALSE(ty->Is<SamplerType>());
EXPECT_FALSE(ty->IsStruct());
EXPECT_TRUE(ty->IsTexture());
EXPECT_FALSE(ty->IsU32());

View File

@@ -48,7 +48,7 @@ TEST_F(PointerTypeTest, Is) {
EXPECT_FALSE(ty->Is<I32Type>());
EXPECT_FALSE(ty->Is<MatrixType>());
EXPECT_TRUE(ty->Is<PointerType>());
EXPECT_FALSE(ty->IsSampler());
EXPECT_FALSE(ty->Is<SamplerType>());
EXPECT_FALSE(ty->IsStruct());
EXPECT_FALSE(ty->IsTexture());
EXPECT_FALSE(ty->IsU32());

View File

@@ -42,7 +42,7 @@ TEST_F(SampledTextureTypeTest, Is) {
EXPECT_FALSE(ty->Is<I32Type>());
EXPECT_FALSE(ty->Is<MatrixType>());
EXPECT_FALSE(ty->Is<PointerType>());
EXPECT_FALSE(ty->IsSampler());
EXPECT_FALSE(ty->Is<SamplerType>());
EXPECT_FALSE(ty->IsStruct());
EXPECT_TRUE(ty->IsTexture());
EXPECT_FALSE(ty->IsU32());

View File

@@ -36,10 +36,6 @@ SamplerType::SamplerType(SamplerType&&) = default;
SamplerType::~SamplerType() = default;
bool SamplerType::IsSampler() const {
return true;
}
std::string SamplerType::type_name() const {
return std::string("__sampler_") +
(kind_ == SamplerKind::kSampler ? "sampler" : "comparison");

View File

@@ -43,9 +43,6 @@ class SamplerType : public Castable<SamplerType, Type> {
SamplerType(SamplerType&&);
~SamplerType() override;
/// @returns true if the type is a sampler type
bool IsSampler() const override;
/// @returns the sampler type
SamplerKind kind() const { return kind_; }

View File

@@ -52,7 +52,7 @@ TEST_F(SamplerTypeTest, Is) {
EXPECT_FALSE(ty->Is<I32Type>());
EXPECT_FALSE(ty->Is<MatrixType>());
EXPECT_FALSE(ty->Is<PointerType>());
EXPECT_TRUE(ty->IsSampler());
EXPECT_TRUE(ty->Is<SamplerType>());
EXPECT_FALSE(ty->IsStruct());
EXPECT_FALSE(ty->IsTexture());
EXPECT_FALSE(ty->IsU32());

View File

@@ -46,7 +46,7 @@ TEST_F(StorageTextureTypeTest, Is) {
EXPECT_FALSE(ty->Is<I32Type>());
EXPECT_FALSE(ty->Is<MatrixType>());
EXPECT_FALSE(ty->Is<PointerType>());
EXPECT_FALSE(ty->IsSampler());
EXPECT_FALSE(ty->Is<SamplerType>());
EXPECT_FALSE(ty->IsStruct());
EXPECT_TRUE(ty->IsTexture());
EXPECT_FALSE(ty->IsU32());

View File

@@ -57,7 +57,7 @@ TEST_F(StructTypeTest, Is) {
EXPECT_FALSE(ty->Is<I32Type>());
EXPECT_FALSE(ty->Is<MatrixType>());
EXPECT_FALSE(ty->Is<PointerType>());
EXPECT_FALSE(ty->IsSampler());
EXPECT_FALSE(ty->Is<SamplerType>());
EXPECT_TRUE(ty->IsStruct());
EXPECT_FALSE(ty->IsTexture());
EXPECT_FALSE(ty->IsU32());

View File

@@ -66,10 +66,6 @@ Type* Type::UnwrapAll() {
return UnwrapIfNeeded()->UnwrapPtrIfNeeded()->UnwrapIfNeeded();
}
bool Type::IsSampler() const {
return false;
}
bool Type::IsStruct() const {
return false;
}
@@ -142,11 +138,6 @@ bool Type::is_integer_scalar_or_vector() {
return is_unsigned_scalar_or_vector() || is_signed_scalar_or_vector();
}
const SamplerType* Type::AsSampler() const {
assert(IsSampler());
return static_cast<const SamplerType*>(this);
}
const StructType* Type::AsStruct() const {
assert(IsStruct());
return static_cast<const StructType*>(this);
@@ -172,11 +163,6 @@ const VoidType* Type::AsVoid() const {
return static_cast<const VoidType*>(this);
}
SamplerType* Type::AsSampler() {
assert(IsSampler());
return static_cast<SamplerType*>(this);
}
StructType* Type::AsStruct() {
assert(IsStruct());
return static_cast<StructType*>(this);

View File

@@ -23,7 +23,6 @@ namespace tint {
namespace ast {
namespace type {
class SamplerType;
class StructType;
class TextureType;
class U32Type;
@@ -40,8 +39,6 @@ class Type : public Castable<Type> {
Type(Type&&);
~Type() override;
/// @returns true if the type is a sampler
virtual bool IsSampler() const;
/// @returns true if the type is a struct type
virtual bool IsStruct() const;
/// @returns true if the type is a texture type
@@ -107,8 +104,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 sampler type
const SamplerType* AsSampler() const;
/// @returns the type as a struct type
const StructType* AsStruct() const;
/// @returns the type as a texture type
@@ -120,8 +115,6 @@ class Type : public Castable<Type> {
/// @returns the type as a void type
const VoidType* AsVoid() const;
/// @returns the type as a sampler type
SamplerType* AsSampler();
/// @returns the type as a struct type
StructType* AsStruct();
/// @returns the type as a texture type

View File

@@ -22,6 +22,7 @@
#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/sampler_type.h"
namespace tint {
namespace ast {
@@ -41,7 +42,7 @@ TEST_F(U32TypeTest, Is) {
EXPECT_FALSE(ty->Is<I32Type>());
EXPECT_FALSE(ty->Is<MatrixType>());
EXPECT_FALSE(ty->Is<PointerType>());
EXPECT_FALSE(ty->IsSampler());
EXPECT_FALSE(ty->Is<SamplerType>());
EXPECT_FALSE(ty->IsStruct());
EXPECT_FALSE(ty->IsTexture());
EXPECT_TRUE(ty->IsU32());

View File

@@ -49,7 +49,7 @@ TEST_F(VectorTypeTest, Is) {
EXPECT_FALSE(ty->Is<I32Type>());
EXPECT_FALSE(ty->Is<MatrixType>());
EXPECT_FALSE(ty->Is<PointerType>());
EXPECT_FALSE(ty->IsSampler());
EXPECT_FALSE(ty->Is<SamplerType>());
EXPECT_FALSE(ty->IsStruct());
EXPECT_FALSE(ty->IsTexture());
EXPECT_FALSE(ty->IsU32());