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

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

View File

@@ -25,6 +25,7 @@
#include "src/ast/test_helper.h"
#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/ast/type/pointer_type.h"
#include "src/ast/type/struct_type.h"
@@ -53,7 +54,7 @@ TEST_F(AccessControlTypeTest, Is) {
EXPECT_FALSE(ty->Is<AliasType>());
EXPECT_FALSE(ty->Is<ArrayType>());
EXPECT_FALSE(ty->Is<BoolType>());
EXPECT_FALSE(ty->IsF32());
EXPECT_FALSE(ty->Is<F32Type>());
EXPECT_FALSE(ty->IsI32());
EXPECT_FALSE(ty->IsMatrix());
EXPECT_FALSE(ty->IsPointer());

View File

@@ -26,6 +26,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/f32_type.h"
#include "src/ast/type/i32_type.h"
#include "src/ast/type/pointer_type.h"
#include "src/ast/type/struct_type.h"
@@ -54,7 +55,7 @@ TEST_F(AliasTypeTest, Is) {
EXPECT_TRUE(ty->Is<AliasType>());
EXPECT_FALSE(ty->Is<ArrayType>());
EXPECT_FALSE(ty->Is<BoolType>());
EXPECT_FALSE(ty->IsF32());
EXPECT_FALSE(ty->Is<F32Type>());
EXPECT_FALSE(ty->IsI32());
EXPECT_FALSE(ty->IsMatrix());
EXPECT_FALSE(ty->IsPointer());

View File

@@ -21,6 +21,7 @@
#include "src/ast/test_helper.h"
#include "src/ast/type/access_control_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/ast/type/u32_type.h"
@@ -58,7 +59,7 @@ TEST_F(ArrayTypeTest, Is) {
EXPECT_FALSE(ty->Is<AliasType>());
EXPECT_TRUE(ty->Is<ArrayType>());
EXPECT_FALSE(ty->Is<BoolType>());
EXPECT_FALSE(ty->IsF32());
EXPECT_FALSE(ty->Is<F32Type>());
EXPECT_FALSE(ty->IsI32());
EXPECT_FALSE(ty->IsMatrix());
EXPECT_FALSE(ty->IsPointer());

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"
#include "src/ast/type/f32_type.h"
namespace tint {
namespace ast {
@@ -32,7 +33,7 @@ TEST_F(BoolTypeTest, Is) {
EXPECT_FALSE(ty->Is<AliasType>());
EXPECT_FALSE(ty->Is<ArrayType>());
EXPECT_TRUE(ty->Is<BoolType>());
EXPECT_FALSE(ty->IsF32());
EXPECT_FALSE(ty->Is<F32Type>());
EXPECT_FALSE(ty->IsI32());
EXPECT_FALSE(ty->IsMatrix());
EXPECT_FALSE(ty->IsPointer());

View File

@@ -19,6 +19,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/f32_type.h"
namespace tint {
namespace ast {
@@ -34,7 +35,7 @@ TEST_F(DepthTextureTypeTest, Is) {
EXPECT_FALSE(ty->Is<AliasType>());
EXPECT_FALSE(ty->Is<ArrayType>());
EXPECT_FALSE(ty->Is<BoolType>());
EXPECT_FALSE(ty->IsF32());
EXPECT_FALSE(ty->Is<F32Type>());
EXPECT_FALSE(ty->IsI32());
EXPECT_FALSE(ty->IsMatrix());
EXPECT_FALSE(ty->IsPointer());

View File

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

View File

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

View File

@@ -33,7 +33,7 @@ TEST_F(F32TypeTest, Is) {
EXPECT_FALSE(ty->Is<AliasType>());
EXPECT_FALSE(ty->Is<ArrayType>());
EXPECT_FALSE(ty->Is<BoolType>());
EXPECT_TRUE(ty->IsF32());
EXPECT_TRUE(ty->Is<F32Type>());
EXPECT_FALSE(ty->IsI32());
EXPECT_FALSE(ty->IsMatrix());
EXPECT_FALSE(ty->IsPointer());

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/f32_type.h"
namespace tint {
namespace ast {
@@ -33,7 +34,7 @@ TEST_F(I32TypeTest, Is) {
EXPECT_FALSE(ty->Is<AliasType>());
EXPECT_FALSE(ty->Is<ArrayType>());
EXPECT_FALSE(ty->Is<BoolType>());
EXPECT_FALSE(ty->IsF32());
EXPECT_FALSE(ty->Is<F32Type>());
EXPECT_TRUE(ty->IsI32());
EXPECT_FALSE(ty->IsMatrix());
EXPECT_FALSE(ty->IsPointer());

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/f32_type.h"
#include "src/ast/type/i32_type.h"
namespace tint {
@@ -43,7 +44,7 @@ TEST_F(MatrixTypeTest, Is) {
EXPECT_FALSE(ty->Is<AliasType>());
EXPECT_FALSE(ty->Is<ArrayType>());
EXPECT_FALSE(ty->Is<BoolType>());
EXPECT_FALSE(ty->IsF32());
EXPECT_FALSE(ty->Is<F32Type>());
EXPECT_FALSE(ty->IsI32());
EXPECT_TRUE(ty->IsMatrix());
EXPECT_FALSE(ty->IsPointer());

View File

@@ -35,7 +35,7 @@ TEST_F(MultisampledTextureTypeTest, Is) {
EXPECT_FALSE(ty->Is<AliasType>());
EXPECT_FALSE(ty->Is<ArrayType>());
EXPECT_FALSE(ty->Is<BoolType>());
EXPECT_FALSE(ty->IsF32());
EXPECT_FALSE(ty->Is<F32Type>());
EXPECT_FALSE(ty->IsI32());
EXPECT_FALSE(ty->IsMatrix());
EXPECT_FALSE(ty->IsPointer());

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/f32_type.h"
#include "src/ast/type/i32_type.h"
namespace tint {
@@ -42,7 +43,7 @@ TEST_F(PointerTypeTest, Is) {
EXPECT_FALSE(ty->Is<AliasType>());
EXPECT_FALSE(ty->Is<ArrayType>());
EXPECT_FALSE(ty->Is<BoolType>());
EXPECT_FALSE(ty->IsF32());
EXPECT_FALSE(ty->Is<F32Type>());
EXPECT_FALSE(ty->IsI32());
EXPECT_FALSE(ty->IsMatrix());
EXPECT_TRUE(ty->IsPointer());

View File

@@ -35,7 +35,7 @@ TEST_F(SampledTextureTypeTest, Is) {
EXPECT_FALSE(ty->Is<AliasType>());
EXPECT_FALSE(ty->Is<ArrayType>());
EXPECT_FALSE(ty->Is<BoolType>());
EXPECT_FALSE(ty->IsF32());
EXPECT_FALSE(ty->Is<F32Type>());
EXPECT_FALSE(ty->IsI32());
EXPECT_FALSE(ty->IsMatrix());
EXPECT_FALSE(ty->IsPointer());

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/f32_type.h"
namespace tint {
namespace ast {
@@ -44,7 +45,7 @@ TEST_F(SamplerTypeTest, Is) {
EXPECT_FALSE(ty->Is<AliasType>());
EXPECT_FALSE(ty->Is<ArrayType>());
EXPECT_FALSE(ty->Is<BoolType>());
EXPECT_FALSE(ty->IsF32());
EXPECT_FALSE(ty->Is<F32Type>());
EXPECT_FALSE(ty->IsI32());
EXPECT_FALSE(ty->IsMatrix());
EXPECT_FALSE(ty->IsPointer());

View File

@@ -21,6 +21,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/f32_type.h"
#include "src/type_determiner.h"
namespace tint {
@@ -38,7 +39,7 @@ TEST_F(StorageTextureTypeTest, Is) {
EXPECT_FALSE(ty->Is<AliasType>());
EXPECT_FALSE(ty->Is<ArrayType>());
EXPECT_FALSE(ty->Is<BoolType>());
EXPECT_FALSE(ty->IsF32());
EXPECT_FALSE(ty->Is<F32Type>());
EXPECT_FALSE(ty->IsI32());
EXPECT_FALSE(ty->IsMatrix());
EXPECT_FALSE(ty->IsPointer());
@@ -92,7 +93,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()->IsF32());
EXPECT_TRUE(s->AsTexture()->AsStorage()->type()->Is<ast::type::F32Type>());
}
TEST_F(StorageTextureTypeTest, U32Type) {

View File

@@ -24,6 +24,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/f32_type.h"
#include "src/ast/type/i32_type.h"
#include "src/ast/type/u32_type.h"
#include "src/ast/type/vector_type.h"
@@ -50,7 +51,7 @@ TEST_F(StructTypeTest, Is) {
EXPECT_FALSE(ty->Is<AliasType>());
EXPECT_FALSE(ty->Is<ArrayType>());
EXPECT_FALSE(ty->Is<BoolType>());
EXPECT_FALSE(ty->IsF32());
EXPECT_FALSE(ty->Is<F32Type>());
EXPECT_FALSE(ty->IsI32());
EXPECT_FALSE(ty->IsMatrix());
EXPECT_FALSE(ty->IsPointer());

View File

@@ -66,10 +66,6 @@ Type* Type::UnwrapAll() {
return UnwrapIfNeeded()->UnwrapPtrIfNeeded()->UnwrapIfNeeded();
}
bool Type::IsF32() const {
return false;
}
bool Type::IsI32() const {
return false;
}
@@ -119,7 +115,7 @@ bool Type::is_scalar() {
}
bool Type::is_float_scalar() {
return IsF32();
return Is<F32Type>();
}
bool Type::is_float_matrix() {
@@ -158,11 +154,6 @@ bool Type::is_integer_scalar_or_vector() {
return is_unsigned_scalar_or_vector() || is_signed_scalar_or_vector();
}
const F32Type* Type::AsF32() const {
assert(IsF32());
return static_cast<const F32Type*>(this);
}
const I32Type* Type::AsI32() const {
assert(IsI32());
return static_cast<const I32Type*>(this);
@@ -208,11 +199,6 @@ const VoidType* Type::AsVoid() const {
return static_cast<const VoidType*>(this);
}
F32Type* Type::AsF32() {
assert(IsF32());
return static_cast<F32Type*>(this);
}
I32Type* Type::AsI32() {
assert(IsI32());
return static_cast<I32Type*>(this);

View File

@@ -23,7 +23,6 @@ namespace tint {
namespace ast {
namespace type {
class F32Type;
class I32Type;
class MatrixType;
class PointerType;
@@ -44,8 +43,6 @@ class Type : public Castable<Type> {
Type(Type&&);
~Type() override;
/// @returns true if the type is an f32 type
virtual bool IsF32() const;
/// @returns true if the type is an i32 type
virtual bool IsI32() const;
/// @returns true if the type is a matrix type
@@ -119,8 +116,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 f32 type
const F32Type* AsF32() const;
/// @returns the type as an i32 type
const I32Type* AsI32() const;
/// @returns the type as a matrix type
@@ -140,8 +135,6 @@ class Type : public Castable<Type> {
/// @returns the type as a void type
const VoidType* AsVoid() const;
/// @returns the type as a f32 type
F32Type* AsF32();
/// @returns the type as an i32 type
I32Type* AsI32();
/// @returns the type as a matrix type

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/f32_type.h"
namespace tint {
namespace ast {
@@ -33,7 +34,7 @@ TEST_F(U32TypeTest, Is) {
EXPECT_FALSE(ty->Is<AliasType>());
EXPECT_FALSE(ty->Is<ArrayType>());
EXPECT_FALSE(ty->Is<BoolType>());
EXPECT_FALSE(ty->IsF32());
EXPECT_FALSE(ty->Is<F32Type>());
EXPECT_FALSE(ty->IsI32());
EXPECT_FALSE(ty->IsMatrix());
EXPECT_FALSE(ty->IsPointer());

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/f32_type.h"
#include "src/ast/type/i32_type.h"
namespace tint {
@@ -42,7 +43,7 @@ TEST_F(VectorTypeTest, Is) {
EXPECT_FALSE(ty->Is<AliasType>());
EXPECT_FALSE(ty->Is<ArrayType>());
EXPECT_FALSE(ty->Is<BoolType>());
EXPECT_FALSE(ty->IsF32());
EXPECT_FALSE(ty->Is<F32Type>());
EXPECT_FALSE(ty->IsI32());
EXPECT_FALSE(ty->IsMatrix());
EXPECT_FALSE(ty->IsPointer());