mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-12-16 08:27:05 +00:00
Replace Type::(Is|As)Pointer with Castable
Change-Id: Ic1b82f1ddc61355021a80d8e72f645f830363c62 Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/34269 Reviewed-by: dan sinclair <dsinclair@chromium.org>
This commit is contained in:
@@ -58,7 +58,7 @@ TEST_F(AccessControlTypeTest, Is) {
|
||||
EXPECT_FALSE(ty->Is<F32Type>());
|
||||
EXPECT_FALSE(ty->Is<I32Type>());
|
||||
EXPECT_FALSE(ty->Is<MatrixType>());
|
||||
EXPECT_FALSE(ty->IsPointer());
|
||||
EXPECT_FALSE(ty->Is<PointerType>());
|
||||
EXPECT_FALSE(ty->IsSampler());
|
||||
EXPECT_FALSE(ty->IsStruct());
|
||||
EXPECT_FALSE(ty->IsTexture());
|
||||
|
||||
@@ -59,7 +59,7 @@ TEST_F(AliasTypeTest, Is) {
|
||||
EXPECT_FALSE(ty->Is<F32Type>());
|
||||
EXPECT_FALSE(ty->Is<I32Type>());
|
||||
EXPECT_FALSE(ty->Is<MatrixType>());
|
||||
EXPECT_FALSE(ty->IsPointer());
|
||||
EXPECT_FALSE(ty->Is<PointerType>());
|
||||
EXPECT_FALSE(ty->IsSampler());
|
||||
EXPECT_FALSE(ty->IsStruct());
|
||||
EXPECT_FALSE(ty->IsTexture());
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
#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/u32_type.h"
|
||||
|
||||
namespace tint {
|
||||
@@ -63,7 +64,7 @@ TEST_F(ArrayTypeTest, Is) {
|
||||
EXPECT_FALSE(ty->Is<F32Type>());
|
||||
EXPECT_FALSE(ty->Is<I32Type>());
|
||||
EXPECT_FALSE(ty->Is<MatrixType>());
|
||||
EXPECT_FALSE(ty->IsPointer());
|
||||
EXPECT_FALSE(ty->Is<PointerType>());
|
||||
EXPECT_FALSE(ty->IsSampler());
|
||||
EXPECT_FALSE(ty->IsStruct());
|
||||
EXPECT_FALSE(ty->IsTexture());
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
#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"
|
||||
|
||||
namespace tint {
|
||||
namespace ast {
|
||||
@@ -38,7 +39,7 @@ TEST_F(BoolTypeTest, Is) {
|
||||
EXPECT_FALSE(ty->Is<F32Type>());
|
||||
EXPECT_FALSE(ty->Is<I32Type>());
|
||||
EXPECT_FALSE(ty->Is<MatrixType>());
|
||||
EXPECT_FALSE(ty->IsPointer());
|
||||
EXPECT_FALSE(ty->Is<PointerType>());
|
||||
EXPECT_FALSE(ty->IsSampler());
|
||||
EXPECT_FALSE(ty->IsStruct());
|
||||
EXPECT_FALSE(ty->IsTexture());
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
#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"
|
||||
|
||||
namespace tint {
|
||||
namespace ast {
|
||||
@@ -40,7 +41,7 @@ TEST_F(DepthTextureTypeTest, Is) {
|
||||
EXPECT_FALSE(ty->Is<F32Type>());
|
||||
EXPECT_FALSE(ty->Is<I32Type>());
|
||||
EXPECT_FALSE(ty->Is<MatrixType>());
|
||||
EXPECT_FALSE(ty->IsPointer());
|
||||
EXPECT_FALSE(ty->Is<PointerType>());
|
||||
EXPECT_FALSE(ty->IsSampler());
|
||||
EXPECT_FALSE(ty->IsStruct());
|
||||
EXPECT_TRUE(ty->IsTexture());
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
#include "src/ast/type/bool_type.h"
|
||||
#include "src/ast/type/i32_type.h"
|
||||
#include "src/ast/type/matrix_type.h"
|
||||
#include "src/ast/type/pointer_type.h"
|
||||
|
||||
namespace tint {
|
||||
namespace ast {
|
||||
@@ -38,7 +39,7 @@ TEST_F(F32TypeTest, Is) {
|
||||
EXPECT_TRUE(ty->Is<F32Type>());
|
||||
EXPECT_FALSE(ty->Is<I32Type>());
|
||||
EXPECT_FALSE(ty->Is<MatrixType>());
|
||||
EXPECT_FALSE(ty->IsPointer());
|
||||
EXPECT_FALSE(ty->Is<PointerType>());
|
||||
EXPECT_FALSE(ty->IsSampler());
|
||||
EXPECT_FALSE(ty->IsStruct());
|
||||
EXPECT_FALSE(ty->IsTexture());
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
#include "src/ast/type/bool_type.h"
|
||||
#include "src/ast/type/f32_type.h"
|
||||
#include "src/ast/type/matrix_type.h"
|
||||
#include "src/ast/type/pointer_type.h"
|
||||
|
||||
namespace tint {
|
||||
namespace ast {
|
||||
@@ -38,7 +39,7 @@ TEST_F(I32TypeTest, Is) {
|
||||
EXPECT_FALSE(ty->Is<F32Type>());
|
||||
EXPECT_TRUE(ty->Is<I32Type>());
|
||||
EXPECT_FALSE(ty->Is<MatrixType>());
|
||||
EXPECT_FALSE(ty->IsPointer());
|
||||
EXPECT_FALSE(ty->Is<PointerType>());
|
||||
EXPECT_FALSE(ty->IsSampler());
|
||||
EXPECT_FALSE(ty->IsStruct());
|
||||
EXPECT_FALSE(ty->IsTexture());
|
||||
|
||||
@@ -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/pointer_type.h"
|
||||
|
||||
namespace tint {
|
||||
namespace ast {
|
||||
@@ -47,7 +48,7 @@ TEST_F(MatrixTypeTest, Is) {
|
||||
EXPECT_FALSE(ty->Is<F32Type>());
|
||||
EXPECT_FALSE(ty->Is<I32Type>());
|
||||
EXPECT_TRUE(ty->Is<MatrixType>());
|
||||
EXPECT_FALSE(ty->IsPointer());
|
||||
EXPECT_FALSE(ty->Is<PointerType>());
|
||||
EXPECT_FALSE(ty->IsSampler());
|
||||
EXPECT_FALSE(ty->IsStruct());
|
||||
EXPECT_FALSE(ty->IsTexture());
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
#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"
|
||||
|
||||
namespace tint {
|
||||
namespace ast {
|
||||
@@ -40,7 +41,7 @@ TEST_F(MultisampledTextureTypeTest, Is) {
|
||||
EXPECT_FALSE(ty->Is<F32Type>());
|
||||
EXPECT_FALSE(ty->Is<I32Type>());
|
||||
EXPECT_FALSE(ty->Is<MatrixType>());
|
||||
EXPECT_FALSE(ty->IsPointer());
|
||||
EXPECT_FALSE(ty->Is<PointerType>());
|
||||
EXPECT_FALSE(ty->IsSampler());
|
||||
EXPECT_FALSE(ty->IsStruct());
|
||||
EXPECT_TRUE(ty->IsTexture());
|
||||
|
||||
@@ -21,10 +21,6 @@ namespace type {
|
||||
PointerType::PointerType(Type* subtype, StorageClass storage_class)
|
||||
: subtype_(subtype), storage_class_(storage_class) {}
|
||||
|
||||
bool PointerType::IsPointer() const {
|
||||
return true;
|
||||
}
|
||||
|
||||
std::string PointerType::type_name() const {
|
||||
std::ostringstream out;
|
||||
out << "__ptr_" << storage_class_ << subtype_->type_name();
|
||||
|
||||
@@ -36,9 +36,6 @@ class PointerType : public Castable<PointerType, Type> {
|
||||
PointerType(PointerType&&);
|
||||
~PointerType() override;
|
||||
|
||||
/// @returns true if the type is a pointer type
|
||||
bool IsPointer() const override;
|
||||
|
||||
/// @returns the pointee type
|
||||
Type* type() const { return subtype_; }
|
||||
/// @returns the storage class of the pointer
|
||||
|
||||
@@ -47,7 +47,7 @@ TEST_F(PointerTypeTest, Is) {
|
||||
EXPECT_FALSE(ty->Is<F32Type>());
|
||||
EXPECT_FALSE(ty->Is<I32Type>());
|
||||
EXPECT_FALSE(ty->Is<MatrixType>());
|
||||
EXPECT_TRUE(ty->IsPointer());
|
||||
EXPECT_TRUE(ty->Is<PointerType>());
|
||||
EXPECT_FALSE(ty->IsSampler());
|
||||
EXPECT_FALSE(ty->IsStruct());
|
||||
EXPECT_FALSE(ty->IsTexture());
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
#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"
|
||||
|
||||
namespace tint {
|
||||
namespace ast {
|
||||
@@ -40,7 +41,7 @@ TEST_F(SampledTextureTypeTest, Is) {
|
||||
EXPECT_FALSE(ty->Is<F32Type>());
|
||||
EXPECT_FALSE(ty->Is<I32Type>());
|
||||
EXPECT_FALSE(ty->Is<MatrixType>());
|
||||
EXPECT_FALSE(ty->IsPointer());
|
||||
EXPECT_FALSE(ty->Is<PointerType>());
|
||||
EXPECT_FALSE(ty->IsSampler());
|
||||
EXPECT_FALSE(ty->IsStruct());
|
||||
EXPECT_TRUE(ty->IsTexture());
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
#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"
|
||||
|
||||
namespace tint {
|
||||
namespace ast {
|
||||
@@ -50,7 +51,7 @@ TEST_F(SamplerTypeTest, Is) {
|
||||
EXPECT_FALSE(ty->Is<F32Type>());
|
||||
EXPECT_FALSE(ty->Is<I32Type>());
|
||||
EXPECT_FALSE(ty->Is<MatrixType>());
|
||||
EXPECT_FALSE(ty->IsPointer());
|
||||
EXPECT_FALSE(ty->Is<PointerType>());
|
||||
EXPECT_TRUE(ty->IsSampler());
|
||||
EXPECT_FALSE(ty->IsStruct());
|
||||
EXPECT_FALSE(ty->IsTexture());
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
#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/type_determiner.h"
|
||||
|
||||
namespace tint {
|
||||
@@ -44,7 +45,7 @@ TEST_F(StorageTextureTypeTest, Is) {
|
||||
EXPECT_FALSE(ty->Is<F32Type>());
|
||||
EXPECT_FALSE(ty->Is<I32Type>());
|
||||
EXPECT_FALSE(ty->Is<MatrixType>());
|
||||
EXPECT_FALSE(ty->IsPointer());
|
||||
EXPECT_FALSE(ty->Is<PointerType>());
|
||||
EXPECT_FALSE(ty->IsSampler());
|
||||
EXPECT_FALSE(ty->IsStruct());
|
||||
EXPECT_TRUE(ty->IsTexture());
|
||||
|
||||
@@ -27,6 +27,7 @@
|
||||
#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/u32_type.h"
|
||||
#include "src/ast/type/vector_type.h"
|
||||
|
||||
@@ -55,7 +56,7 @@ TEST_F(StructTypeTest, Is) {
|
||||
EXPECT_FALSE(ty->Is<F32Type>());
|
||||
EXPECT_FALSE(ty->Is<I32Type>());
|
||||
EXPECT_FALSE(ty->Is<MatrixType>());
|
||||
EXPECT_FALSE(ty->IsPointer());
|
||||
EXPECT_FALSE(ty->Is<PointerType>());
|
||||
EXPECT_FALSE(ty->IsSampler());
|
||||
EXPECT_TRUE(ty->IsStruct());
|
||||
EXPECT_FALSE(ty->IsTexture());
|
||||
|
||||
@@ -42,8 +42,8 @@ Type::Type(Type&&) = default;
|
||||
Type::~Type() = default;
|
||||
|
||||
Type* Type::UnwrapPtrIfNeeded() {
|
||||
if (IsPointer()) {
|
||||
return AsPointer()->type();
|
||||
if (Is<PointerType>()) {
|
||||
return As<PointerType>()->type();
|
||||
}
|
||||
return this;
|
||||
}
|
||||
@@ -66,10 +66,6 @@ Type* Type::UnwrapAll() {
|
||||
return UnwrapIfNeeded()->UnwrapPtrIfNeeded()->UnwrapIfNeeded();
|
||||
}
|
||||
|
||||
bool Type::IsPointer() const {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool Type::IsSampler() const {
|
||||
return false;
|
||||
}
|
||||
@@ -146,11 +142,6 @@ bool Type::is_integer_scalar_or_vector() {
|
||||
return is_unsigned_scalar_or_vector() || is_signed_scalar_or_vector();
|
||||
}
|
||||
|
||||
const PointerType* Type::AsPointer() const {
|
||||
assert(IsPointer());
|
||||
return static_cast<const PointerType*>(this);
|
||||
}
|
||||
|
||||
const SamplerType* Type::AsSampler() const {
|
||||
assert(IsSampler());
|
||||
return static_cast<const SamplerType*>(this);
|
||||
@@ -181,11 +172,6 @@ const VoidType* Type::AsVoid() const {
|
||||
return static_cast<const VoidType*>(this);
|
||||
}
|
||||
|
||||
PointerType* Type::AsPointer() {
|
||||
assert(IsPointer());
|
||||
return static_cast<PointerType*>(this);
|
||||
}
|
||||
|
||||
SamplerType* Type::AsSampler() {
|
||||
assert(IsSampler());
|
||||
return static_cast<SamplerType*>(this);
|
||||
|
||||
@@ -23,7 +23,6 @@ namespace tint {
|
||||
namespace ast {
|
||||
namespace type {
|
||||
|
||||
class PointerType;
|
||||
class SamplerType;
|
||||
class StructType;
|
||||
class TextureType;
|
||||
@@ -41,8 +40,6 @@ class Type : public Castable<Type> {
|
||||
Type(Type&&);
|
||||
~Type() override;
|
||||
|
||||
/// @returns true if the type is a ptr type
|
||||
virtual bool IsPointer() const;
|
||||
/// @returns true if the type is a sampler
|
||||
virtual bool IsSampler() const;
|
||||
/// @returns true if the type is a struct type
|
||||
@@ -110,8 +107,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 pointer type
|
||||
const PointerType* AsPointer() const;
|
||||
/// @returns the type as a sampler type
|
||||
const SamplerType* AsSampler() const;
|
||||
/// @returns the type as a struct type
|
||||
@@ -125,8 +120,6 @@ class Type : public Castable<Type> {
|
||||
/// @returns the type as a void type
|
||||
const VoidType* AsVoid() const;
|
||||
|
||||
/// @returns the type as a pointer type
|
||||
PointerType* AsPointer();
|
||||
/// @returns the type as a sampler type
|
||||
SamplerType* AsSampler();
|
||||
/// @returns the type as a struct type
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
#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"
|
||||
|
||||
namespace tint {
|
||||
namespace ast {
|
||||
@@ -39,7 +40,7 @@ TEST_F(U32TypeTest, Is) {
|
||||
EXPECT_FALSE(ty->Is<F32Type>());
|
||||
EXPECT_FALSE(ty->Is<I32Type>());
|
||||
EXPECT_FALSE(ty->Is<MatrixType>());
|
||||
EXPECT_FALSE(ty->IsPointer());
|
||||
EXPECT_FALSE(ty->Is<PointerType>());
|
||||
EXPECT_FALSE(ty->IsSampler());
|
||||
EXPECT_FALSE(ty->IsStruct());
|
||||
EXPECT_FALSE(ty->IsTexture());
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
#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"
|
||||
|
||||
namespace tint {
|
||||
namespace ast {
|
||||
@@ -47,7 +48,7 @@ TEST_F(VectorTypeTest, Is) {
|
||||
EXPECT_FALSE(ty->Is<F32Type>());
|
||||
EXPECT_FALSE(ty->Is<I32Type>());
|
||||
EXPECT_FALSE(ty->Is<MatrixType>());
|
||||
EXPECT_FALSE(ty->IsPointer());
|
||||
EXPECT_FALSE(ty->Is<PointerType>());
|
||||
EXPECT_FALSE(ty->IsSampler());
|
||||
EXPECT_FALSE(ty->IsStruct());
|
||||
EXPECT_FALSE(ty->IsTexture());
|
||||
|
||||
Reference in New Issue
Block a user