From f3639b787f208238f2cecdc3231ecf9dd0eb64b8 Mon Sep 17 00:00:00 2001 From: Ben Clayton Date: Mon, 30 Nov 2020 23:30:58 +0000 Subject: [PATCH] Replace Type::(Is|As)Bool with Castable Change-Id: I60ed33bd9a54b14bb9b35f3cd999a2604c2c4450 Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/34265 Reviewed-by: dan sinclair --- src/ast/type/access_control_type_test.cc | 3 ++- src/ast/type/alias_type_test.cc | 3 ++- src/ast/type/array_type_test.cc | 3 ++- src/ast/type/bool_type.cc | 4 ---- src/ast/type/bool_type.h | 3 --- src/ast/type/bool_type_test.cc | 2 +- src/ast/type/depth_texture_type_test.cc | 3 ++- src/ast/type/f32_type_test.cc | 3 ++- src/ast/type/i32_type_test.cc | 3 ++- src/ast/type/matrix_type_test.cc | 3 ++- src/ast/type/multisampled_texture_type_test.cc | 3 ++- src/ast/type/pointer_type_test.cc | 3 ++- src/ast/type/sampled_texture_type_test.cc | 3 ++- src/ast/type/sampler_type_test.cc | 3 ++- src/ast/type/storage_texture_type_test.cc | 3 ++- src/ast/type/struct_type_test.cc | 3 ++- src/ast/type/type.cc | 16 +--------------- src/ast/type/type.h | 7 ------- src/ast/type/u32_type_test.cc | 3 ++- src/ast/type/vector_type_test.cc | 3 ++- src/reader/spirv/function.cc | 2 +- src/reader/spirv/parser_impl.cc | 4 ++-- .../spirv/parser_impl_convert_type_test.cc | 3 ++- src/reader/wgsl/parser_impl_type_decl_test.cc | 2 +- src/type_determiner_test.cc | 17 ++++++++++------- src/writer/hlsl/generator_impl.cc | 5 +++-- src/writer/msl/generator_impl.cc | 6 +++--- src/writer/spirv/builder.cc | 8 +++++--- src/writer/wgsl/generator_impl.cc | 3 ++- 29 files changed, 61 insertions(+), 66 deletions(-) diff --git a/src/ast/type/access_control_type_test.cc b/src/ast/type/access_control_type_test.cc index 652e3b8afe..b07d2a2369 100644 --- a/src/ast/type/access_control_type_test.cc +++ b/src/ast/type/access_control_type_test.cc @@ -24,6 +24,7 @@ #include "src/ast/struct_member_offset_decoration.h" #include "src/ast/test_helper.h" #include "src/ast/type/array_type.h" +#include "src/ast/type/bool_type.h" #include "src/ast/type/i32_type.h" #include "src/ast/type/pointer_type.h" #include "src/ast/type/struct_type.h" @@ -51,7 +52,7 @@ TEST_F(AccessControlTypeTest, Is) { EXPECT_TRUE(ty->Is()); EXPECT_FALSE(ty->Is()); EXPECT_FALSE(ty->Is()); - EXPECT_FALSE(ty->IsBool()); + EXPECT_FALSE(ty->Is()); EXPECT_FALSE(ty->IsF32()); EXPECT_FALSE(ty->IsI32()); EXPECT_FALSE(ty->IsMatrix()); diff --git a/src/ast/type/alias_type_test.cc b/src/ast/type/alias_type_test.cc index 67e7473fc7..22b81a7a10 100644 --- a/src/ast/type/alias_type_test.cc +++ b/src/ast/type/alias_type_test.cc @@ -25,6 +25,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/bool_type.h" #include "src/ast/type/i32_type.h" #include "src/ast/type/pointer_type.h" #include "src/ast/type/struct_type.h" @@ -52,7 +53,7 @@ TEST_F(AliasTypeTest, Is) { EXPECT_FALSE(ty->Is()); EXPECT_TRUE(ty->Is()); EXPECT_FALSE(ty->Is()); - EXPECT_FALSE(ty->IsBool()); + EXPECT_FALSE(ty->Is()); EXPECT_FALSE(ty->IsF32()); EXPECT_FALSE(ty->IsI32()); EXPECT_FALSE(ty->IsMatrix()); diff --git a/src/ast/type/array_type_test.cc b/src/ast/type/array_type_test.cc index 84cb3bdc23..40ec166fc2 100644 --- a/src/ast/type/array_type_test.cc +++ b/src/ast/type/array_type_test.cc @@ -20,6 +20,7 @@ #include "src/ast/stride_decoration.h" #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/i32_type.h" #include "src/ast/type/u32_type.h" @@ -56,7 +57,7 @@ TEST_F(ArrayTypeTest, Is) { EXPECT_FALSE(ty->Is()); EXPECT_FALSE(ty->Is()); EXPECT_TRUE(ty->Is()); - EXPECT_FALSE(ty->IsBool()); + EXPECT_FALSE(ty->Is()); EXPECT_FALSE(ty->IsF32()); EXPECT_FALSE(ty->IsI32()); EXPECT_FALSE(ty->IsMatrix()); diff --git a/src/ast/type/bool_type.cc b/src/ast/type/bool_type.cc index e8f0af337e..7accedfac1 100644 --- a/src/ast/type/bool_type.cc +++ b/src/ast/type/bool_type.cc @@ -24,10 +24,6 @@ BoolType::BoolType(BoolType&&) = default; BoolType::~BoolType() = default; -bool BoolType::IsBool() const { - return true; -} - std::string BoolType::type_name() const { return "__bool"; } diff --git a/src/ast/type/bool_type.h b/src/ast/type/bool_type.h index abd6e73b55..5e7ccf6f14 100644 --- a/src/ast/type/bool_type.h +++ b/src/ast/type/bool_type.h @@ -32,9 +32,6 @@ class BoolType : public Castable { BoolType(BoolType&&); ~BoolType() override; - /// @returns true if the type is a bool type - bool IsBool() const override; - /// @returns the name for this type std::string type_name() const override; }; diff --git a/src/ast/type/bool_type_test.cc b/src/ast/type/bool_type_test.cc index 2b674b286f..6b7c5233ba 100644 --- a/src/ast/type/bool_type_test.cc +++ b/src/ast/type/bool_type_test.cc @@ -31,7 +31,7 @@ TEST_F(BoolTypeTest, Is) { EXPECT_FALSE(ty->Is()); EXPECT_FALSE(ty->Is()); EXPECT_FALSE(ty->Is()); - EXPECT_TRUE(ty->IsBool()); + EXPECT_TRUE(ty->Is()); EXPECT_FALSE(ty->IsF32()); EXPECT_FALSE(ty->IsI32()); EXPECT_FALSE(ty->IsMatrix()); diff --git a/src/ast/type/depth_texture_type_test.cc b/src/ast/type/depth_texture_type_test.cc index 0d19918675..1f5ea21f76 100644 --- a/src/ast/type/depth_texture_type_test.cc +++ b/src/ast/type/depth_texture_type_test.cc @@ -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" namespace tint { namespace ast { @@ -32,7 +33,7 @@ TEST_F(DepthTextureTypeTest, Is) { EXPECT_FALSE(ty->Is()); EXPECT_FALSE(ty->Is()); EXPECT_FALSE(ty->Is()); - EXPECT_FALSE(ty->IsBool()); + EXPECT_FALSE(ty->Is()); EXPECT_FALSE(ty->IsF32()); EXPECT_FALSE(ty->IsI32()); EXPECT_FALSE(ty->IsMatrix()); diff --git a/src/ast/type/f32_type_test.cc b/src/ast/type/f32_type_test.cc index f48c0705d7..01327c4916 100644 --- a/src/ast/type/f32_type_test.cc +++ b/src/ast/type/f32_type_test.cc @@ -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/bool_type.h" namespace tint { namespace ast { @@ -31,7 +32,7 @@ TEST_F(F32TypeTest, Is) { EXPECT_FALSE(ty->Is()); EXPECT_FALSE(ty->Is()); EXPECT_FALSE(ty->Is()); - EXPECT_FALSE(ty->IsBool()); + EXPECT_FALSE(ty->Is()); EXPECT_TRUE(ty->IsF32()); EXPECT_FALSE(ty->IsI32()); EXPECT_FALSE(ty->IsMatrix()); diff --git a/src/ast/type/i32_type_test.cc b/src/ast/type/i32_type_test.cc index 7e7b08612e..3deed3bb7e 100644 --- a/src/ast/type/i32_type_test.cc +++ b/src/ast/type/i32_type_test.cc @@ -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/bool_type.h" namespace tint { namespace ast { @@ -31,7 +32,7 @@ TEST_F(I32TypeTest, Is) { EXPECT_FALSE(ty->Is()); EXPECT_FALSE(ty->Is()); EXPECT_FALSE(ty->Is()); - EXPECT_FALSE(ty->IsBool()); + EXPECT_FALSE(ty->Is()); EXPECT_FALSE(ty->IsF32()); EXPECT_TRUE(ty->IsI32()); EXPECT_FALSE(ty->IsMatrix()); diff --git a/src/ast/type/matrix_type_test.cc b/src/ast/type/matrix_type_test.cc index bc2791e2b9..395e4df1dd 100644 --- a/src/ast/type/matrix_type_test.cc +++ b/src/ast/type/matrix_type_test.cc @@ -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/bool_type.h" #include "src/ast/type/i32_type.h" namespace tint { @@ -41,7 +42,7 @@ TEST_F(MatrixTypeTest, Is) { EXPECT_FALSE(ty->Is()); EXPECT_FALSE(ty->Is()); EXPECT_FALSE(ty->Is()); - EXPECT_FALSE(ty->IsBool()); + EXPECT_FALSE(ty->Is()); EXPECT_FALSE(ty->IsF32()); EXPECT_FALSE(ty->IsI32()); EXPECT_TRUE(ty->IsMatrix()); diff --git a/src/ast/type/multisampled_texture_type_test.cc b/src/ast/type/multisampled_texture_type_test.cc index f11e8cea16..75a15aa44c 100644 --- a/src/ast/type/multisampled_texture_type_test.cc +++ b/src/ast/type/multisampled_texture_type_test.cc @@ -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/bool_type.h" #include "src/ast/type/f32_type.h" namespace tint { @@ -33,7 +34,7 @@ TEST_F(MultisampledTextureTypeTest, Is) { EXPECT_FALSE(ty->Is()); EXPECT_FALSE(ty->Is()); EXPECT_FALSE(ty->Is()); - EXPECT_FALSE(ty->IsBool()); + EXPECT_FALSE(ty->Is()); EXPECT_FALSE(ty->IsF32()); EXPECT_FALSE(ty->IsI32()); EXPECT_FALSE(ty->IsMatrix()); diff --git a/src/ast/type/pointer_type_test.cc b/src/ast/type/pointer_type_test.cc index 8aeb8cd531..1d93fc24eb 100644 --- a/src/ast/type/pointer_type_test.cc +++ b/src/ast/type/pointer_type_test.cc @@ -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/bool_type.h" #include "src/ast/type/i32_type.h" namespace tint { @@ -40,7 +41,7 @@ TEST_F(PointerTypeTest, Is) { EXPECT_FALSE(ty->Is()); EXPECT_FALSE(ty->Is()); EXPECT_FALSE(ty->Is()); - EXPECT_FALSE(ty->IsBool()); + EXPECT_FALSE(ty->Is()); EXPECT_FALSE(ty->IsF32()); EXPECT_FALSE(ty->IsI32()); EXPECT_FALSE(ty->IsMatrix()); diff --git a/src/ast/type/sampled_texture_type_test.cc b/src/ast/type/sampled_texture_type_test.cc index dd08506359..bc90dcf1e5 100644 --- a/src/ast/type/sampled_texture_type_test.cc +++ b/src/ast/type/sampled_texture_type_test.cc @@ -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/bool_type.h" #include "src/ast/type/f32_type.h" namespace tint { @@ -33,7 +34,7 @@ TEST_F(SampledTextureTypeTest, Is) { EXPECT_FALSE(ty->Is()); EXPECT_FALSE(ty->Is()); EXPECT_FALSE(ty->Is()); - EXPECT_FALSE(ty->IsBool()); + EXPECT_FALSE(ty->Is()); EXPECT_FALSE(ty->IsF32()); EXPECT_FALSE(ty->IsI32()); EXPECT_FALSE(ty->IsMatrix()); diff --git a/src/ast/type/sampler_type_test.cc b/src/ast/type/sampler_type_test.cc index db1111551f..1363f091e8 100644 --- a/src/ast/type/sampler_type_test.cc +++ b/src/ast/type/sampler_type_test.cc @@ -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/bool_type.h" namespace tint { namespace ast { @@ -42,7 +43,7 @@ TEST_F(SamplerTypeTest, Is) { EXPECT_FALSE(ty->Is()); EXPECT_FALSE(ty->Is()); EXPECT_FALSE(ty->Is()); - EXPECT_FALSE(ty->IsBool()); + EXPECT_FALSE(ty->Is()); EXPECT_FALSE(ty->IsF32()); EXPECT_FALSE(ty->IsI32()); EXPECT_FALSE(ty->IsMatrix()); diff --git a/src/ast/type/storage_texture_type_test.cc b/src/ast/type/storage_texture_type_test.cc index 47afe0d29b..c35e5d0b4c 100644 --- a/src/ast/type/storage_texture_type_test.cc +++ b/src/ast/type/storage_texture_type_test.cc @@ -20,6 +20,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/bool_type.h" #include "src/type_determiner.h" namespace tint { @@ -36,7 +37,7 @@ TEST_F(StorageTextureTypeTest, Is) { EXPECT_FALSE(ty->Is()); EXPECT_FALSE(ty->Is()); EXPECT_FALSE(ty->Is()); - EXPECT_FALSE(ty->IsBool()); + EXPECT_FALSE(ty->Is()); EXPECT_FALSE(ty->IsF32()); EXPECT_FALSE(ty->IsI32()); EXPECT_FALSE(ty->IsMatrix()); diff --git a/src/ast/type/struct_type_test.cc b/src/ast/type/struct_type_test.cc index 3c1ba83994..cee3f5b814 100644 --- a/src/ast/type/struct_type_test.cc +++ b/src/ast/type/struct_type_test.cc @@ -23,6 +23,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/bool_type.h" #include "src/ast/type/i32_type.h" #include "src/ast/type/u32_type.h" #include "src/ast/type/vector_type.h" @@ -48,7 +49,7 @@ TEST_F(StructTypeTest, Is) { EXPECT_FALSE(ty->Is()); EXPECT_FALSE(ty->Is()); EXPECT_FALSE(ty->Is()); - EXPECT_FALSE(ty->IsBool()); + EXPECT_FALSE(ty->Is()); EXPECT_FALSE(ty->IsF32()); EXPECT_FALSE(ty->IsI32()); EXPECT_FALSE(ty->IsMatrix()); diff --git a/src/ast/type/type.cc b/src/ast/type/type.cc index 45dcc0fcd4..8339977c35 100644 --- a/src/ast/type/type.cc +++ b/src/ast/type/type.cc @@ -66,10 +66,6 @@ Type* Type::UnwrapAll() { return UnwrapIfNeeded()->UnwrapPtrIfNeeded()->UnwrapIfNeeded(); } -bool Type::IsBool() const { - return false; -} - bool Type::IsF32() const { return false; } @@ -119,7 +115,7 @@ uint64_t Type::BaseAlignment(MemoryLayout) const { } bool Type::is_scalar() { - return is_float_scalar() || is_integer_scalar() || IsBool(); + return is_float_scalar() || is_integer_scalar() || Is(); } bool Type::is_float_scalar() { @@ -162,11 +158,6 @@ bool Type::is_integer_scalar_or_vector() { return is_unsigned_scalar_or_vector() || is_signed_scalar_or_vector(); } -const BoolType* Type::AsBool() const { - assert(IsBool()); - return static_cast(this); -} - const F32Type* Type::AsF32() const { assert(IsF32()); return static_cast(this); @@ -217,11 +208,6 @@ const VoidType* Type::AsVoid() const { return static_cast(this); } -BoolType* Type::AsBool() { - assert(IsBool()); - return static_cast(this); -} - F32Type* Type::AsF32() { assert(IsF32()); return static_cast(this); diff --git a/src/ast/type/type.h b/src/ast/type/type.h index 7993f4233c..907d7a33fd 100644 --- a/src/ast/type/type.h +++ b/src/ast/type/type.h @@ -23,7 +23,6 @@ namespace tint { namespace ast { namespace type { -class BoolType; class F32Type; class I32Type; class MatrixType; @@ -45,8 +44,6 @@ class Type : public Castable { Type(Type&&); ~Type() override; - /// @returns true if the type is a bool type - virtual bool IsBool() const; /// @returns true if the type is an f32 type virtual bool IsF32() const; /// @returns true if the type is an i32 type @@ -122,8 +119,6 @@ class Type : public Castable { /// @returns true if this type is an integer scalar or vector bool is_integer_scalar_or_vector(); - /// @returns the type as a bool type - const BoolType* AsBool() const; /// @returns the type as a f32 type const F32Type* AsF32() const; /// @returns the type as an i32 type @@ -145,8 +140,6 @@ class Type : public Castable { /// @returns the type as a void type const VoidType* AsVoid() const; - /// @returns the type as a bool type - BoolType* AsBool(); /// @returns the type as a f32 type F32Type* AsF32(); /// @returns the type as an i32 type diff --git a/src/ast/type/u32_type_test.cc b/src/ast/type/u32_type_test.cc index d764f38ce0..20d92da628 100644 --- a/src/ast/type/u32_type_test.cc +++ b/src/ast/type/u32_type_test.cc @@ -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/bool_type.h" namespace tint { namespace ast { @@ -31,7 +32,7 @@ TEST_F(U32TypeTest, Is) { EXPECT_FALSE(ty->Is()); EXPECT_FALSE(ty->Is()); EXPECT_FALSE(ty->Is()); - EXPECT_FALSE(ty->IsBool()); + EXPECT_FALSE(ty->Is()); EXPECT_FALSE(ty->IsF32()); EXPECT_FALSE(ty->IsI32()); EXPECT_FALSE(ty->IsMatrix()); diff --git a/src/ast/type/vector_type_test.cc b/src/ast/type/vector_type_test.cc index cbbdd7309e..a849f5e2e2 100644 --- a/src/ast/type/vector_type_test.cc +++ b/src/ast/type/vector_type_test.cc @@ -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/bool_type.h" #include "src/ast/type/i32_type.h" namespace tint { @@ -40,7 +41,7 @@ TEST_F(VectorTypeTest, Is) { EXPECT_FALSE(ty->Is()); EXPECT_FALSE(ty->Is()); EXPECT_FALSE(ty->Is()); - EXPECT_FALSE(ty->IsBool()); + EXPECT_FALSE(ty->Is()); EXPECT_FALSE(ty->IsF32()); EXPECT_FALSE(ty->IsI32()); EXPECT_FALSE(ty->IsMatrix()); diff --git a/src/reader/spirv/function.cc b/src/reader/spirv/function.cc index 027cacc30e..ad29bfc2af 100644 --- a/src/reader/spirv/function.cc +++ b/src/reader/spirv/function.cc @@ -3597,7 +3597,7 @@ TypedExpression FunctionEmitter::MakeSimpleSelect( // a VariablePointers* capability, which is not allowed in by WebGPU. auto* op_ty = operand1.type; if (op_ty->IsVector() || op_ty->is_float_scalar() || - op_ty->is_integer_scalar() || op_ty->IsBool()) { + op_ty->is_integer_scalar() || op_ty->Is()) { ast::ExpressionList params; params.push_back(operand1.expr); params.push_back(operand2.expr); diff --git a/src/reader/spirv/parser_impl.cc b/src/reader/spirv/parser_impl.cc index 3fe9599c4d..096289f3d1 100644 --- a/src/reader/spirv/parser_impl.cc +++ b/src/reader/spirv/parser_impl.cc @@ -1277,7 +1277,7 @@ TypedExpression ParserImpl::MakeConstantExpression(uint32_t id) { create( create(ast_type, spirv_const->GetFloat()))}; } - if (ast_type->IsBool()) { + if (ast_type->Is()) { const bool value = spirv_const->AsNullConstant() ? false : spirv_const->AsBoolConstant()->value(); @@ -1334,7 +1334,7 @@ ast::Expression* ParserImpl::MakeNullValue(ast::type::Type* type) { auto* original_type = type; type = type->UnwrapIfNeeded(); - if (type->IsBool()) { + if (type->Is()) { return create( create(type, false)); } diff --git a/src/reader/spirv/parser_impl_convert_type_test.cc b/src/reader/spirv/parser_impl_convert_type_test.cc index 3239b0a798..11f2d09d2c 100644 --- a/src/reader/spirv/parser_impl_convert_type_test.cc +++ b/src/reader/spirv/parser_impl_convert_type_test.cc @@ -19,6 +19,7 @@ #include "gmock/gmock.h" #include "src/ast/struct.h" #include "src/ast/type/array_type.h" +#include "src/ast/type/bool_type.h" #include "src/ast/type/matrix_type.h" #include "src/ast/type/pointer_type.h" #include "src/ast/type/struct_type.h" @@ -96,7 +97,7 @@ TEST_F(SpvParserTest, ConvertType_Bool) { EXPECT_TRUE(p->BuildInternalModule()); auto* type = p->ConvertType(100); - EXPECT_TRUE(type->IsBool()); + EXPECT_TRUE(type->Is()); EXPECT_TRUE(p->error().empty()); } diff --git a/src/reader/wgsl/parser_impl_type_decl_test.cc b/src/reader/wgsl/parser_impl_type_decl_test.cc index 96352ad5b0..83c31f1e82 100644 --- a/src/reader/wgsl/parser_impl_type_decl_test.cc +++ b/src/reader/wgsl/parser_impl_type_decl_test.cc @@ -87,7 +87,7 @@ TEST_F(ParserImplTest, TypeDecl_Bool) { EXPECT_FALSE(t.errored); ASSERT_NE(t.value, nullptr) << p->error(); EXPECT_EQ(t.value, bool_type); - ASSERT_TRUE(t->IsBool()); + ASSERT_TRUE(t->Is()); } TEST_F(ParserImplTest, TypeDecl_F32) { diff --git a/src/type_determiner_test.cc b/src/type_determiner_test.cc index 6503585e29..9c486eaaa6 100644 --- a/src/type_determiner_test.cc +++ b/src/type_determiner_test.cc @@ -1190,7 +1190,7 @@ TEST_P(Expr_Binary_LogicalTest, Scalar) { ASSERT_TRUE(td()->DetermineResultType(&expr)) << td()->error(); ASSERT_NE(expr.result_type(), nullptr); - EXPECT_TRUE(expr.result_type()->IsBool()); + EXPECT_TRUE(expr.result_type()->Is()); } TEST_P(Expr_Binary_LogicalTest, Vector) { @@ -1211,7 +1211,8 @@ TEST_P(Expr_Binary_LogicalTest, Vector) { ASSERT_TRUE(td()->DetermineResultType(&expr)) << td()->error(); ASSERT_NE(expr.result_type(), nullptr); ASSERT_TRUE(expr.result_type()->IsVector()); - EXPECT_TRUE(expr.result_type()->AsVector()->type()->IsBool()); + EXPECT_TRUE( + expr.result_type()->AsVector()->type()->Is()); EXPECT_EQ(expr.result_type()->AsVector()->size(), 3u); } INSTANTIATE_TEST_SUITE_P(TypeDeterminerTest, @@ -1236,7 +1237,7 @@ TEST_P(Expr_Binary_CompareTest, Scalar) { ASSERT_TRUE(td()->DetermineResultType(&expr)) << td()->error(); ASSERT_NE(expr.result_type(), nullptr); - EXPECT_TRUE(expr.result_type()->IsBool()); + EXPECT_TRUE(expr.result_type()->Is()); } TEST_P(Expr_Binary_CompareTest, Vector) { @@ -1257,7 +1258,8 @@ TEST_P(Expr_Binary_CompareTest, Vector) { ASSERT_TRUE(td()->DetermineResultType(&expr)) << td()->error(); ASSERT_NE(expr.result_type(), nullptr); ASSERT_TRUE(expr.result_type()->IsVector()); - EXPECT_TRUE(expr.result_type()->AsVector()->type()->IsBool()); + EXPECT_TRUE( + expr.result_type()->AsVector()->type()->Is()); EXPECT_EQ(expr.result_type()->AsVector()->size(), 3u); } INSTANTIATE_TEST_SUITE_P(TypeDeterminerTest, @@ -1616,7 +1618,7 @@ TEST_P(Intrinsic, Test) { EXPECT_TRUE(td()->DetermineResultType(&expr)); ASSERT_NE(expr.result_type(), nullptr); - EXPECT_TRUE(expr.result_type()->IsBool()); + EXPECT_TRUE(expr.result_type()->Is()); } INSTANTIATE_TEST_SUITE_P(TypeDeterminerTest, Intrinsic, @@ -1644,7 +1646,8 @@ TEST_P(Intrinsic_FloatMethod, Vector) { ASSERT_NE(expr.result_type(), nullptr); ASSERT_TRUE(expr.result_type()->IsVector()); - EXPECT_TRUE(expr.result_type()->AsVector()->type()->IsBool()); + EXPECT_TRUE( + expr.result_type()->AsVector()->type()->Is()); EXPECT_EQ(expr.result_type()->AsVector()->size(), 3u); } @@ -1666,7 +1669,7 @@ TEST_P(Intrinsic_FloatMethod, Scalar) { EXPECT_TRUE(td()->Determine()); EXPECT_TRUE(td()->DetermineResultType(&expr)); ASSERT_NE(expr.result_type(), nullptr); - EXPECT_TRUE(expr.result_type()->IsBool()); + EXPECT_TRUE(expr.result_type()->Is()); } TEST_P(Intrinsic_FloatMethod, MissingParam) { diff --git a/src/writer/hlsl/generator_impl.cc b/src/writer/hlsl/generator_impl.cc index a4d75645d2..e39d5eeae6 100644 --- a/src/writer/hlsl/generator_impl.cc +++ b/src/writer/hlsl/generator_impl.cc @@ -41,6 +41,7 @@ #include "src/ast/type/access_control_type.h" #include "src/ast/type/alias_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/matrix_type.h" @@ -1542,7 +1543,7 @@ bool GeneratorImpl::EmitLiteral(std::ostream& out, ast::Literal* lit) { } bool GeneratorImpl::EmitZeroValue(std::ostream& out, ast::type::Type* type) { - if (type->IsBool()) { + if (type->Is()) { out << "false"; } else if (type->IsF32()) { out << "0.0f"; @@ -2057,7 +2058,7 @@ bool GeneratorImpl::EmitType(std::ostream& out, for (uint32_t size : sizes) { out << "[" << size << "]"; } - } else if (type->IsBool()) { + } else if (type->Is()) { out << "bool"; } else if (type->IsF32()) { out << "float"; diff --git a/src/writer/msl/generator_impl.cc b/src/writer/msl/generator_impl.cc index 1e98cc1522..0d8830e4a9 100644 --- a/src/writer/msl/generator_impl.cc +++ b/src/writer/msl/generator_impl.cc @@ -194,7 +194,7 @@ uint32_t GeneratorImpl::calculate_alignment_size(ast::type::Type* type) { uint32_t type_size = calculate_alignment_size(ary->type()); return ary->size() * type_size; } - if (type->IsBool()) { + if (type->Is()) { return 1; } if (type->IsPointer()) { @@ -928,7 +928,7 @@ bool GeneratorImpl::EmitTypeConstructor(ast::TypeConstructorExpression* expr) { } bool GeneratorImpl::EmitZeroValue(ast::type::Type* type) { - if (type->IsBool()) { + if (type->Is()) { out_ << "false"; } else if (type->IsF32()) { out_ << "0.0f"; @@ -1812,7 +1812,7 @@ bool GeneratorImpl::EmitType(ast::type::Type* type, const std::string& name) { for (uint32_t size : sizes) { out_ << "[" << size << "]"; } - } else if (type->IsBool()) { + } else if (type->Is()) { out_ << "bool"; } else if (type->IsF32()) { out_ << "float"; diff --git a/src/writer/spirv/builder.cc b/src/writer/spirv/builder.cc index 68b3e3771f..c640f84c83 100644 --- a/src/writer/spirv/builder.cc +++ b/src/writer/spirv/builder.cc @@ -52,6 +52,7 @@ #include "src/ast/switch_statement.h" #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/depth_texture_type.h" #include "src/ast/type/f32_type.h" #include "src/ast/type/i32_type.h" @@ -750,7 +751,7 @@ bool Builder::GenerateGlobalVariable(ast::Variable* var) { } else if (type->IsI32()) { ast::SintLiteral l(type, 0); init_id = GenerateLiteralIfNeeded(var, &l); - } else if (type->IsBool()) { + } else if (type->Is()) { ast::BoolLiteral l(type, false); init_id = GenerateLiteralIfNeeded(var, &l); } else { @@ -1407,7 +1408,8 @@ uint32_t Builder::GenerateCastOrCopyOrPassthrough(ast::type::Type* to_type, (from_type->is_float_vector() && to_type->is_unsigned_integer_vector())) { op = spv::Op::OpConvertFToU; - } else if ((from_type->IsBool() && to_type->IsBool()) || + } else if ((from_type->Is() && + to_type->Is()) || (from_type->IsU32() && to_type->IsU32()) || (from_type->IsI32() && to_type->IsI32()) || (from_type->IsF32() && to_type->IsF32()) || @@ -2414,7 +2416,7 @@ uint32_t Builder::GenerateTypeIfNeeded(ast::type::Type* type) { if (!GenerateArrayType(type->As(), result)) { return 0; } - } else if (type->IsBool()) { + } else if (type->Is()) { push_type(spv::Op::OpTypeBool, {result}); } else if (type->IsF32()) { push_type(spv::Op::OpTypeFloat, {result, Operand::Int(32)}); diff --git a/src/writer/wgsl/generator_impl.cc b/src/writer/wgsl/generator_impl.cc index f2d16deb3f..00aaa68f1f 100644 --- a/src/writer/wgsl/generator_impl.cc +++ b/src/writer/wgsl/generator_impl.cc @@ -53,6 +53,7 @@ #include "src/ast/switch_statement.h" #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/depth_texture_type.h" #include "src/ast/type/matrix_type.h" #include "src/ast/type/multisampled_texture_type.h" @@ -430,7 +431,7 @@ bool GeneratorImpl::EmitType(ast::type::Type* type) { out_ << ", " << ary->size(); out_ << ">"; - } else if (type->IsBool()) { + } else if (type->Is()) { out_ << "bool"; } else if (type->IsF32()) { out_ << "f32";