From d11ced47656740e6da662cc2af31783973533b0f 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)U32 with Castable Change-Id: I4999d45950fdffe4345cf0abae1b026244abba1d Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/34273 Reviewed-by: dan sinclair --- src/ast/type/access_control_type_test.cc | 2 +- src/ast/type/alias_type_test.cc | 2 +- src/ast/type/array_type_test.cc | 2 +- src/ast/type/bool_type_test.cc | 3 +- 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 +- .../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 | 6 ++- src/ast/type/struct_type_test.cc | 2 +- src/ast/type/type.cc | 20 ++------ src/ast/type/type.h | 7 --- src/ast/type/u32_type.cc | 4 -- src/ast/type/u32_type.h | 3 -- src/ast/type/u32_type_test.cc | 2 +- src/ast/type/vector_type_test.cc | 3 +- src/ast/type_manager_test.cc | 2 +- src/inspector/inspector.cc | 3 +- src/reader/spirv/parser_impl.cc | 10 ++-- .../spirv/parser_impl_convert_type_test.cc | 13 ++--- .../parser_impl_texture_sampler_types_test.cc | 11 +++- src/reader/wgsl/parser_impl_type_decl_test.cc | 4 +- .../bound_array_accessors_transform_test.cc | 50 +++++++++---------- src/type_determiner_test.cc | 14 +++--- src/validator/validator_impl.cc | 10 ++-- src/writer/hlsl/generator_impl.cc | 11 ++-- src/writer/msl/generator_impl.cc | 12 ++--- src/writer/spirv/builder.cc | 19 ++++--- src/writer/wgsl/generator_impl.cc | 3 +- 33 files changed, 124 insertions(+), 118 deletions(-) diff --git a/src/ast/type/access_control_type_test.cc b/src/ast/type/access_control_type_test.cc index e5fc40a49c..e02ee23765 100644 --- a/src/ast/type/access_control_type_test.cc +++ b/src/ast/type/access_control_type_test.cc @@ -63,7 +63,7 @@ TEST_F(AccessControlTypeTest, Is) { EXPECT_FALSE(ty->Is()); EXPECT_FALSE(ty->Is()); EXPECT_FALSE(ty->Is()); - EXPECT_FALSE(ty->IsU32()); + EXPECT_FALSE(ty->Is()); EXPECT_FALSE(ty->IsVector()); } diff --git a/src/ast/type/alias_type_test.cc b/src/ast/type/alias_type_test.cc index df38b69b64..46259a02dc 100644 --- a/src/ast/type/alias_type_test.cc +++ b/src/ast/type/alias_type_test.cc @@ -64,7 +64,7 @@ TEST_F(AliasTypeTest, Is) { EXPECT_FALSE(ty->Is()); EXPECT_FALSE(ty->Is()); EXPECT_FALSE(ty->Is()); - EXPECT_FALSE(ty->IsU32()); + EXPECT_FALSE(ty->Is()); EXPECT_FALSE(ty->IsVector()); } diff --git a/src/ast/type/array_type_test.cc b/src/ast/type/array_type_test.cc index ba1fdedd1f..b8119e80e4 100644 --- a/src/ast/type/array_type_test.cc +++ b/src/ast/type/array_type_test.cc @@ -70,7 +70,7 @@ TEST_F(ArrayTypeTest, Is) { EXPECT_FALSE(ty->Is()); EXPECT_FALSE(ty->Is()); EXPECT_FALSE(ty->Is()); - EXPECT_FALSE(ty->IsU32()); + EXPECT_FALSE(ty->Is()); EXPECT_FALSE(ty->IsVector()); } diff --git a/src/ast/type/bool_type_test.cc b/src/ast/type/bool_type_test.cc index e61aa8dc4b..4d8fa7e54b 100644 --- a/src/ast/type/bool_type_test.cc +++ b/src/ast/type/bool_type_test.cc @@ -23,6 +23,7 @@ #include "src/ast/type/pointer_type.h" #include "src/ast/type/struct_type.h" #include "src/ast/type/texture_type.h" +#include "src/ast/type/u32_type.h" namespace tint { namespace ast { @@ -45,7 +46,7 @@ TEST_F(BoolTypeTest, Is) { EXPECT_FALSE(ty->Is()); EXPECT_FALSE(ty->Is()); EXPECT_FALSE(ty->Is()); - EXPECT_FALSE(ty->IsU32()); + EXPECT_FALSE(ty->Is()); EXPECT_FALSE(ty->IsVector()); } diff --git a/src/ast/type/depth_texture_type_test.cc b/src/ast/type/depth_texture_type_test.cc index 5db5e882d6..53200aead7 100644 --- a/src/ast/type/depth_texture_type_test.cc +++ b/src/ast/type/depth_texture_type_test.cc @@ -24,6 +24,7 @@ #include "src/ast/type/matrix_type.h" #include "src/ast/type/pointer_type.h" #include "src/ast/type/struct_type.h" +#include "src/ast/type/u32_type.h" namespace tint { namespace ast { @@ -46,7 +47,7 @@ TEST_F(DepthTextureTypeTest, Is) { EXPECT_FALSE(ty->Is()); EXPECT_FALSE(ty->Is()); EXPECT_TRUE(ty->Is()); - EXPECT_FALSE(ty->IsU32()); + EXPECT_FALSE(ty->Is()); EXPECT_FALSE(ty->IsVector()); } diff --git a/src/ast/type/f32_type_test.cc b/src/ast/type/f32_type_test.cc index 058e2f297e..bd3446865f 100644 --- a/src/ast/type/f32_type_test.cc +++ b/src/ast/type/f32_type_test.cc @@ -23,6 +23,7 @@ #include "src/ast/type/pointer_type.h" #include "src/ast/type/struct_type.h" #include "src/ast/type/texture_type.h" +#include "src/ast/type/u32_type.h" namespace tint { namespace ast { @@ -45,7 +46,7 @@ TEST_F(F32TypeTest, Is) { EXPECT_FALSE(ty->Is()); EXPECT_FALSE(ty->Is()); EXPECT_FALSE(ty->Is()); - EXPECT_FALSE(ty->IsU32()); + EXPECT_FALSE(ty->Is()); EXPECT_FALSE(ty->IsVector()); } diff --git a/src/ast/type/i32_type_test.cc b/src/ast/type/i32_type_test.cc index ba980b5b35..093ed6a66c 100644 --- a/src/ast/type/i32_type_test.cc +++ b/src/ast/type/i32_type_test.cc @@ -23,6 +23,7 @@ #include "src/ast/type/pointer_type.h" #include "src/ast/type/struct_type.h" #include "src/ast/type/texture_type.h" +#include "src/ast/type/u32_type.h" namespace tint { namespace ast { @@ -45,7 +46,7 @@ TEST_F(I32TypeTest, Is) { EXPECT_FALSE(ty->Is()); EXPECT_FALSE(ty->Is()); EXPECT_FALSE(ty->Is()); - EXPECT_FALSE(ty->IsU32()); + EXPECT_FALSE(ty->Is()); EXPECT_FALSE(ty->IsVector()); } diff --git a/src/ast/type/matrix_type_test.cc b/src/ast/type/matrix_type_test.cc index 9557e7e8ff..6335674f9e 100644 --- a/src/ast/type/matrix_type_test.cc +++ b/src/ast/type/matrix_type_test.cc @@ -23,6 +23,7 @@ #include "src/ast/type/pointer_type.h" #include "src/ast/type/struct_type.h" #include "src/ast/type/texture_type.h" +#include "src/ast/type/u32_type.h" namespace tint { namespace ast { @@ -54,7 +55,7 @@ TEST_F(MatrixTypeTest, Is) { EXPECT_FALSE(ty->Is()); EXPECT_FALSE(ty->Is()); EXPECT_FALSE(ty->Is()); - EXPECT_FALSE(ty->IsU32()); + EXPECT_FALSE(ty->Is()); EXPECT_FALSE(ty->IsVector()); } diff --git a/src/ast/type/multisampled_texture_type_test.cc b/src/ast/type/multisampled_texture_type_test.cc index 9db6845d37..e08440d32d 100644 --- a/src/ast/type/multisampled_texture_type_test.cc +++ b/src/ast/type/multisampled_texture_type_test.cc @@ -23,6 +23,7 @@ #include "src/ast/type/matrix_type.h" #include "src/ast/type/pointer_type.h" #include "src/ast/type/struct_type.h" +#include "src/ast/type/u32_type.h" namespace tint { namespace ast { @@ -46,7 +47,7 @@ TEST_F(MultisampledTextureTypeTest, Is) { EXPECT_FALSE(ty->Is()); EXPECT_FALSE(ty->Is()); EXPECT_TRUE(ty->Is()); - EXPECT_FALSE(ty->IsU32()); + EXPECT_FALSE(ty->Is()); EXPECT_FALSE(ty->IsVector()); } diff --git a/src/ast/type/pointer_type_test.cc b/src/ast/type/pointer_type_test.cc index 0e440024ee..6af8570f60 100644 --- a/src/ast/type/pointer_type_test.cc +++ b/src/ast/type/pointer_type_test.cc @@ -23,6 +23,7 @@ #include "src/ast/type/matrix_type.h" #include "src/ast/type/struct_type.h" #include "src/ast/type/texture_type.h" +#include "src/ast/type/u32_type.h" namespace tint { namespace ast { @@ -53,7 +54,7 @@ TEST_F(PointerTypeTest, Is) { EXPECT_FALSE(ty->Is()); EXPECT_FALSE(ty->Is()); EXPECT_FALSE(ty->Is()); - EXPECT_FALSE(ty->IsU32()); + EXPECT_FALSE(ty->Is()); EXPECT_FALSE(ty->IsVector()); } diff --git a/src/ast/type/sampled_texture_type_test.cc b/src/ast/type/sampled_texture_type_test.cc index 525eb990b1..6c37a8122b 100644 --- a/src/ast/type/sampled_texture_type_test.cc +++ b/src/ast/type/sampled_texture_type_test.cc @@ -23,6 +23,7 @@ #include "src/ast/type/matrix_type.h" #include "src/ast/type/pointer_type.h" #include "src/ast/type/struct_type.h" +#include "src/ast/type/u32_type.h" namespace tint { namespace ast { @@ -46,7 +47,7 @@ TEST_F(SampledTextureTypeTest, Is) { EXPECT_FALSE(ty->Is()); EXPECT_FALSE(ty->Is()); EXPECT_TRUE(ty->Is()); - EXPECT_FALSE(ty->IsU32()); + EXPECT_FALSE(ty->Is()); EXPECT_FALSE(ty->IsVector()); } diff --git a/src/ast/type/sampler_type_test.cc b/src/ast/type/sampler_type_test.cc index 6a4c5f9fc3..9fd5ada417 100644 --- a/src/ast/type/sampler_type_test.cc +++ b/src/ast/type/sampler_type_test.cc @@ -24,6 +24,7 @@ #include "src/ast/type/pointer_type.h" #include "src/ast/type/struct_type.h" #include "src/ast/type/texture_type.h" +#include "src/ast/type/u32_type.h" namespace tint { namespace ast { @@ -57,7 +58,7 @@ TEST_F(SamplerTypeTest, Is) { EXPECT_TRUE(ty->Is()); EXPECT_FALSE(ty->Is()); EXPECT_FALSE(ty->Is()); - EXPECT_FALSE(ty->IsU32()); + EXPECT_FALSE(ty->Is()); EXPECT_FALSE(ty->IsVector()); } diff --git a/src/ast/type/storage_texture_type_test.cc b/src/ast/type/storage_texture_type_test.cc index c87c9ae046..961b1cb6ca 100644 --- a/src/ast/type/storage_texture_type_test.cc +++ b/src/ast/type/storage_texture_type_test.cc @@ -26,6 +26,7 @@ #include "src/ast/type/matrix_type.h" #include "src/ast/type/pointer_type.h" #include "src/ast/type/struct_type.h" +#include "src/ast/type/u32_type.h" #include "src/type_determiner.h" namespace tint { @@ -50,7 +51,7 @@ TEST_F(StorageTextureTypeTest, Is) { EXPECT_FALSE(ty->Is()); EXPECT_FALSE(ty->Is()); EXPECT_TRUE(ty->Is()); - EXPECT_FALSE(ty->IsU32()); + EXPECT_FALSE(ty->Is()); EXPECT_FALSE(ty->IsVector()); } @@ -111,7 +112,8 @@ TEST_F(StorageTextureTypeTest, U32Type) { ASSERT_TRUE(td.Determine()) << td.error(); ASSERT_TRUE(s->Is()); ASSERT_TRUE(s->As()->IsStorage()); - EXPECT_TRUE(s->As()->AsStorage()->type()->IsU32()); + EXPECT_TRUE( + s->As()->AsStorage()->type()->Is()); } TEST_F(StorageTextureTypeTest, I32Type) { diff --git a/src/ast/type/struct_type_test.cc b/src/ast/type/struct_type_test.cc index 244bedd90f..82227b1c3b 100644 --- a/src/ast/type/struct_type_test.cc +++ b/src/ast/type/struct_type_test.cc @@ -61,7 +61,7 @@ TEST_F(StructTypeTest, Is) { EXPECT_FALSE(ty->Is()); EXPECT_TRUE(ty->Is()); EXPECT_FALSE(ty->Is()); - EXPECT_FALSE(ty->IsU32()); + EXPECT_FALSE(ty->Is()); EXPECT_FALSE(ty->IsVector()); } diff --git a/src/ast/type/type.cc b/src/ast/type/type.cc index a2e6267f72..5204986f85 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::IsU32() const { - return false; -} - bool Type::IsVector() const { return false; } @@ -107,11 +103,11 @@ bool Type::is_float_scalar_or_vector() { } bool Type::is_integer_scalar() { - return IsU32() || Is(); + return Is() || Is(); } bool Type::is_unsigned_integer_vector() { - return IsVector() && AsVector()->type()->IsU32(); + return IsVector() && AsVector()->type()->Is(); } bool Type::is_signed_integer_vector() { @@ -119,7 +115,7 @@ bool Type::is_signed_integer_vector() { } bool Type::is_unsigned_scalar_or_vector() { - return IsU32() || (IsVector() && AsVector()->type()->IsU32()); + return Is() || (IsVector() && AsVector()->type()->Is()); } bool Type::is_signed_scalar_or_vector() { @@ -130,11 +126,6 @@ bool Type::is_integer_scalar_or_vector() { return is_unsigned_scalar_or_vector() || is_signed_scalar_or_vector(); } -const U32Type* Type::AsU32() const { - assert(IsU32()); - return static_cast(this); -} - const VectorType* Type::AsVector() const { assert(IsVector()); return static_cast(this); @@ -145,11 +136,6 @@ const VoidType* Type::AsVoid() const { return static_cast(this); } -U32Type* Type::AsU32() { - assert(IsU32()); - return static_cast(this); -} - VectorType* Type::AsVector() { assert(IsVector()); return static_cast(this); diff --git a/src/ast/type/type.h b/src/ast/type/type.h index 4061b76ff6..a78f916d40 100644 --- a/src/ast/type/type.h +++ b/src/ast/type/type.h @@ -23,7 +23,6 @@ namespace tint { namespace ast { namespace type { -class U32Type; class VectorType; class VoidType; @@ -37,8 +36,6 @@ class Type : public Castable { Type(Type&&); ~Type() override; - /// @returns true if the type is a u32 type - virtual bool IsU32() const; /// @returns true if the type is a vec type virtual bool IsVector() const; /// @returns true if the type is a void type @@ -98,15 +95,11 @@ 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 u32 type - const U32Type* AsU32() const; /// @returns the type as a vector type const VectorType* AsVector() const; /// @returns the type as a void type const VoidType* AsVoid() const; - /// @returns the type as a u32 type - U32Type* AsU32(); /// @returns the type as a vector type VectorType* AsVector(); /// @returns the type as a void type diff --git a/src/ast/type/u32_type.cc b/src/ast/type/u32_type.cc index a699eb37f0..baaffd2ddb 100644 --- a/src/ast/type/u32_type.cc +++ b/src/ast/type/u32_type.cc @@ -24,10 +24,6 @@ U32Type::~U32Type() = default; U32Type::U32Type(U32Type&&) = default; -bool U32Type::IsU32() const { - return true; -} - std::string U32Type::type_name() const { return "__u32"; } diff --git a/src/ast/type/u32_type.h b/src/ast/type/u32_type.h index 53ba6e3d25..35e4b912f9 100644 --- a/src/ast/type/u32_type.h +++ b/src/ast/type/u32_type.h @@ -32,9 +32,6 @@ class U32Type : public Castable { U32Type(U32Type&&); ~U32Type() override; - /// @returns true if the type is a u32 type - bool IsU32() const override; - /// @returns the name for th type std::string type_name() const override; diff --git a/src/ast/type/u32_type_test.cc b/src/ast/type/u32_type_test.cc index dd7096d1bc..5afb341b54 100644 --- a/src/ast/type/u32_type_test.cc +++ b/src/ast/type/u32_type_test.cc @@ -47,7 +47,7 @@ TEST_F(U32TypeTest, Is) { EXPECT_FALSE(ty->Is()); EXPECT_FALSE(ty->Is()); EXPECT_FALSE(ty->Is()); - EXPECT_TRUE(ty->IsU32()); + EXPECT_TRUE(ty->Is()); EXPECT_FALSE(ty->IsVector()); } diff --git a/src/ast/type/vector_type_test.cc b/src/ast/type/vector_type_test.cc index a6d2d2b9fa..8940ba9a89 100644 --- a/src/ast/type/vector_type_test.cc +++ b/src/ast/type/vector_type_test.cc @@ -24,6 +24,7 @@ #include "src/ast/type/pointer_type.h" #include "src/ast/type/struct_type.h" #include "src/ast/type/texture_type.h" +#include "src/ast/type/u32_type.h" namespace tint { namespace ast { @@ -54,7 +55,7 @@ TEST_F(VectorTypeTest, Is) { EXPECT_FALSE(ty->Is()); EXPECT_FALSE(ty->Is()); EXPECT_FALSE(ty->Is()); - EXPECT_FALSE(ty->IsU32()); + EXPECT_FALSE(ty->Is()); EXPECT_TRUE(ty->IsVector()); } diff --git a/src/ast/type_manager_test.cc b/src/ast/type_manager_test.cc index bc321c3762..3d844d10b9 100644 --- a/src/ast/type_manager_test.cc +++ b/src/ast/type_manager_test.cc @@ -50,7 +50,7 @@ TEST_F(TypeManagerTest, GetDifferentTypeReturnsDifferentPtr) { auto* t2 = tm.Get(std::make_unique()); ASSERT_NE(t2, nullptr); EXPECT_NE(t, t2); - EXPECT_TRUE(t2->IsU32()); + EXPECT_TRUE(t2->Is()); } TEST_F(TypeManagerTest, ResetClearsPreviousData) { diff --git a/src/inspector/inspector.cc b/src/inspector/inspector.cc index 94ba8bb0b4..b4da984c17 100644 --- a/src/inspector/inspector.cc +++ b/src/inspector/inspector.cc @@ -36,6 +36,7 @@ #include "src/ast/type/struct_type.h" #include "src/ast/type/texture_type.h" #include "src/ast/type/type.h" +#include "src/ast/type/u32_type.h" #include "src/ast/type/vector_type.h" #include "src/ast/uint_literal.h" @@ -396,7 +397,7 @@ std::vector Inspector::GetSampledTextureResourceBindingsImpl( if (base_type->Is()) { entry.sampled_kind = ResourceBinding::SampledKind::kFloat; - } else if (base_type->IsU32()) { + } else if (base_type->Is()) { entry.sampled_kind = ResourceBinding::SampledKind::kUInt; } else if (base_type->Is()) { entry.sampled_kind = ResourceBinding::SampledKind::kSInt; diff --git a/src/reader/spirv/parser_impl.cc b/src/reader/spirv/parser_impl.cc index 4f1cdf416a..56c2f531ef 100644 --- a/src/reader/spirv/parser_impl.cc +++ b/src/reader/spirv/parser_impl.cc @@ -979,7 +979,7 @@ bool ParserImpl::EmitScalarSpecConstants() { ast_expr = create(create( ast_type, static_cast(literal_value))); - } else if (ast_type->IsU32()) { + } else if (ast_type->Is()) { ast_expr = create(create( ast_type, static_cast(literal_value))); @@ -1263,7 +1263,7 @@ TypedExpression ParserImpl::MakeConstantExpression(uint32_t id) { // So canonicalization should map that way too. // Currently "null" is missing from the WGSL parser. // See https://bugs.chromium.org/p/tint/issues/detail?id=34 - if (ast_type->IsU32()) { + if (ast_type->Is()) { return {ast_type, create( create(ast_type, spirv_const->GetU32()))}; @@ -1339,7 +1339,7 @@ ast::Expression* ParserImpl::MakeNullValue(ast::type::Type* type) { return create( create(type, false)); } - if (type->IsU32()) { + if (type->Is()) { return create( create(type, 0u)); } @@ -1446,7 +1446,7 @@ ast::type::Type* ParserImpl::GetSignedIntMatchingShape(ast::type::Type* other) { Fail() << "no type provided"; } auto* i32 = ast_module_.create(); - if (other->Is() || other->IsU32() || + if (other->Is() || other->Is() || other->Is()) { return i32; } @@ -1465,7 +1465,7 @@ ast::type::Type* ParserImpl::GetUnsignedIntMatchingShape( return nullptr; } auto* u32 = ast_module_.create(); - if (other->Is() || other->IsU32() || + if (other->Is() || other->Is() || other->Is()) { return u32; } diff --git a/src/reader/spirv/parser_impl_convert_type_test.cc b/src/reader/spirv/parser_impl_convert_type_test.cc index 002b2c6cd8..4a5100f6fc 100644 --- a/src/reader/spirv/parser_impl_convert_type_test.cc +++ b/src/reader/spirv/parser_impl_convert_type_test.cc @@ -26,6 +26,7 @@ #include "src/ast/type/pointer_type.h" #include "src/ast/type/struct_type.h" #include "src/ast/type/type.h" +#include "src/ast/type/u32_type.h" #include "src/ast/type/vector_type.h" #include "src/reader/spirv/parser_impl.h" #include "src/reader/spirv/parser_impl_test_helper.h" @@ -117,7 +118,7 @@ TEST_F(SpvParserTest, ConvertType_U32) { EXPECT_TRUE(p->BuildInternalModule()); auto* type = p->ConvertType(3); - EXPECT_TRUE(type->IsU32()); + EXPECT_TRUE(type->Is()); EXPECT_TRUE(p->error().empty()); } @@ -225,17 +226,17 @@ TEST_F(SpvParserTest, ConvertType_VecOverU32) { auto* v2xu32 = p->ConvertType(20); EXPECT_TRUE(v2xu32->IsVector()); - EXPECT_TRUE(v2xu32->AsVector()->type()->IsU32()); + EXPECT_TRUE(v2xu32->AsVector()->type()->Is()); EXPECT_EQ(v2xu32->AsVector()->size(), 2u); auto* v3xu32 = p->ConvertType(30); EXPECT_TRUE(v3xu32->IsVector()); - EXPECT_TRUE(v3xu32->AsVector()->type()->IsU32()); + EXPECT_TRUE(v3xu32->AsVector()->type()->Is()); EXPECT_EQ(v3xu32->AsVector()->size(), 3u); auto* v4xu32 = p->ConvertType(40); EXPECT_TRUE(v4xu32->IsVector()); - EXPECT_TRUE(v4xu32->AsVector()->type()->IsU32()); + EXPECT_TRUE(v4xu32->AsVector()->type()->Is()); EXPECT_EQ(v4xu32->AsVector()->size(), 4u); EXPECT_TRUE(p->error().empty()); @@ -359,7 +360,7 @@ TEST_F(SpvParserTest, ConvertType_RuntimeArray) { EXPECT_FALSE(arr_type->has_array_stride()); auto* elem_type = arr_type->type(); ASSERT_NE(elem_type, nullptr); - EXPECT_TRUE(elem_type->IsU32()); + EXPECT_TRUE(elem_type->Is()); EXPECT_TRUE(p->error().empty()); } @@ -441,7 +442,7 @@ TEST_F(SpvParserTest, ConvertType_Array) { EXPECT_FALSE(arr_type->has_array_stride()); auto* elem_type = arr_type->type(); ASSERT_NE(elem_type, nullptr); - EXPECT_TRUE(elem_type->IsU32()); + EXPECT_TRUE(elem_type->Is()); EXPECT_TRUE(p->error().empty()); } diff --git a/src/reader/wgsl/parser_impl_texture_sampler_types_test.cc b/src/reader/wgsl/parser_impl_texture_sampler_types_test.cc index baa7d62301..d64c5a2e9c 100644 --- a/src/reader/wgsl/parser_impl_texture_sampler_types_test.cc +++ b/src/reader/wgsl/parser_impl_texture_sampler_types_test.cc @@ -18,6 +18,7 @@ #include "src/ast/type/multisampled_texture_type.h" #include "src/ast/type/sampled_texture_type.h" #include "src/ast/type/sampler_type.h" +#include "src/ast/type/u32_type.h" #include "src/reader/wgsl/parser_impl.h" #include "src/reader/wgsl/parser_impl_test_helper.h" @@ -113,7 +114,10 @@ TEST_F(ParserImplTest, TextureSamplerTypes_SampledTexture_U32_Old) { ASSERT_NE(t.value, nullptr); ASSERT_TRUE(t->Is()); ASSERT_TRUE(t->As()->IsSampled()); - ASSERT_TRUE(t->As()->AsSampled()->type()->IsU32()); + ASSERT_TRUE(t->As() + ->AsSampled() + ->type() + ->Is()); EXPECT_EQ(t->As()->dim(), ast::type::TextureDimension::k3d); } @@ -202,7 +206,10 @@ TEST_F(ParserImplTest, TextureSamplerTypes_SampledTexture_U32) { ASSERT_NE(t.value, nullptr); ASSERT_TRUE(t->Is()); ASSERT_TRUE(t->As()->IsSampled()); - ASSERT_TRUE(t->As()->AsSampled()->type()->IsU32()); + ASSERT_TRUE(t->As() + ->AsSampled() + ->type() + ->Is()); EXPECT_EQ(t->As()->dim(), ast::type::TextureDimension::k3d); } diff --git a/src/reader/wgsl/parser_impl_type_decl_test.cc b/src/reader/wgsl/parser_impl_type_decl_test.cc index cb58617e0c..cc27ef3368 100644 --- a/src/reader/wgsl/parser_impl_type_decl_test.cc +++ b/src/reader/wgsl/parser_impl_type_decl_test.cc @@ -129,7 +129,7 @@ TEST_F(ParserImplTest, TypeDecl_U32) { EXPECT_FALSE(t.errored); ASSERT_NE(t.value, nullptr) << p->error(); EXPECT_EQ(t.value, uint_type); - ASSERT_TRUE(t->IsU32()); + ASSERT_TRUE(t->Is()); } struct VecData { @@ -528,7 +528,7 @@ TEST_F(ParserImplTest, TypeDecl_Array_Runtime) { auto* a = t->As(); ASSERT_TRUE(a->IsRuntimeArray()); - ASSERT_TRUE(a->type()->IsU32()); + ASSERT_TRUE(a->type()->Is()); } TEST_F(ParserImplTest, TypeDecl_Array_BadType) { diff --git a/src/transform/bound_array_accessors_transform_test.cc b/src/transform/bound_array_accessors_transform_test.cc index 664a51942e..d9aa52209d 100644 --- a/src/transform/bound_array_accessors_transform_test.cc +++ b/src/transform/bound_array_accessors_transform_test.cc @@ -141,7 +141,7 @@ TEST_F(BoundArrayAccessorsTest, Ptrs_Clamp) { ASSERT_TRUE(idx->params()[0]->IsConstructor()); ASSERT_TRUE(idx->params()[0]->AsConstructor()->IsTypeConstructor()); auto* tc = idx->params()[0]->AsConstructor()->AsTypeConstructor(); - EXPECT_TRUE(tc->type()->IsU32()); + EXPECT_TRUE(tc->type()->Is()); ASSERT_EQ(tc->values().size(), 1u); ASSERT_EQ(tc->values()[0], access_idx); @@ -152,7 +152,7 @@ TEST_F(BoundArrayAccessorsTest, Ptrs_Clamp) { EXPECT_EQ(scalar->literal()->AsUint()->value(), 2u); ASSERT_NE(ptr->idx_expr()->result_type(), nullptr); - ASSERT_TRUE(ptr->idx_expr()->result_type()->IsU32()); + ASSERT_TRUE(ptr->idx_expr()->result_type()->Is()); } TEST_F(BoundArrayAccessorsTest, Array_Idx_Nested_Scalar) { @@ -204,7 +204,7 @@ TEST_F(BoundArrayAccessorsTest, Array_Idx_Nested_Scalar) { ASSERT_TRUE(idx->params()[0]->IsConstructor()); ASSERT_TRUE(idx->params()[0]->AsConstructor()->IsTypeConstructor()); auto* tc = idx->params()[0]->AsConstructor()->AsTypeConstructor(); - EXPECT_TRUE(tc->type()->IsU32()); + EXPECT_TRUE(tc->type()->Is()); ASSERT_EQ(tc->values().size(), 1u); auto* sub = tc->values()[0]; @@ -218,7 +218,7 @@ TEST_F(BoundArrayAccessorsTest, Array_Idx_Nested_Scalar) { ASSERT_TRUE(sub_idx->params()[0]->IsConstructor()); ASSERT_TRUE(sub_idx->params()[0]->AsConstructor()->IsTypeConstructor()); tc = sub_idx->params()[0]->AsConstructor()->AsTypeConstructor(); - EXPECT_TRUE(tc->type()->IsU32()); + EXPECT_TRUE(tc->type()->Is()); ASSERT_EQ(tc->values().size(), 1u); ASSERT_EQ(tc->values()[0], b_access_idx); @@ -235,7 +235,7 @@ TEST_F(BoundArrayAccessorsTest, Array_Idx_Nested_Scalar) { EXPECT_EQ(scalar->literal()->AsUint()->value(), 2u); ASSERT_NE(ptr->idx_expr()->result_type(), nullptr); - ASSERT_TRUE(ptr->idx_expr()->result_type()->IsU32()); + ASSERT_TRUE(ptr->idx_expr()->result_type()->Is()); } TEST_F(BoundArrayAccessorsTest, Array_Idx_Scalar) { @@ -274,7 +274,7 @@ TEST_F(BoundArrayAccessorsTest, Array_Idx_Scalar) { EXPECT_EQ(scalar->literal()->AsUint()->value(), 1u); ASSERT_NE(ptr->idx_expr()->result_type(), nullptr); - ASSERT_TRUE(ptr->idx_expr()->result_type()->IsU32()); + ASSERT_TRUE(ptr->idx_expr()->result_type()->Is()); } TEST_F(BoundArrayAccessorsTest, Array_Idx_Expr) { @@ -325,7 +325,7 @@ TEST_F(BoundArrayAccessorsTest, Array_Idx_Expr) { ASSERT_TRUE(idx->params()[0]->IsConstructor()); ASSERT_TRUE(idx->params()[0]->AsConstructor()->IsTypeConstructor()); auto* tc = idx->params()[0]->AsConstructor()->AsTypeConstructor(); - EXPECT_TRUE(tc->type()->IsU32()); + EXPECT_TRUE(tc->type()->Is()); ASSERT_EQ(tc->values().size(), 1u); ASSERT_EQ(tc->values()[0], access_idx); @@ -336,7 +336,7 @@ TEST_F(BoundArrayAccessorsTest, Array_Idx_Expr) { EXPECT_EQ(scalar->literal()->AsUint()->value(), 2u); ASSERT_NE(ptr->idx_expr()->result_type(), nullptr); - ASSERT_TRUE(ptr->idx_expr()->result_type()->IsU32()); + ASSERT_TRUE(ptr->idx_expr()->result_type()->Is()); } TEST_F(BoundArrayAccessorsTest, Array_Idx_Negative) { @@ -414,7 +414,7 @@ TEST_F(BoundArrayAccessorsTest, Array_Idx_OutOfBounds) { EXPECT_EQ(scalar->literal()->AsUint()->value(), 2u); ASSERT_NE(ptr->idx_expr()->result_type(), nullptr); - ASSERT_TRUE(ptr->idx_expr()->result_type()->IsU32()); + ASSERT_TRUE(ptr->idx_expr()->result_type()->Is()); } TEST_F(BoundArrayAccessorsTest, Vector_Idx_Scalar) { @@ -453,7 +453,7 @@ TEST_F(BoundArrayAccessorsTest, Vector_Idx_Scalar) { EXPECT_EQ(scalar->literal()->AsUint()->value(), 1u); ASSERT_NE(ptr->idx_expr()->result_type(), nullptr); - ASSERT_TRUE(ptr->idx_expr()->result_type()->IsU32()); + ASSERT_TRUE(ptr->idx_expr()->result_type()->Is()); } TEST_F(BoundArrayAccessorsTest, Vector_Idx_Expr) { @@ -503,7 +503,7 @@ TEST_F(BoundArrayAccessorsTest, Vector_Idx_Expr) { ASSERT_TRUE(idx->params()[0]->IsConstructor()); ASSERT_TRUE(idx->params()[0]->AsConstructor()->IsTypeConstructor()); auto* tc = idx->params()[0]->AsConstructor()->AsTypeConstructor(); - EXPECT_TRUE(tc->type()->IsU32()); + EXPECT_TRUE(tc->type()->Is()); ASSERT_EQ(tc->values().size(), 1u); ASSERT_EQ(tc->values()[0], access_idx); @@ -514,7 +514,7 @@ TEST_F(BoundArrayAccessorsTest, Vector_Idx_Expr) { EXPECT_EQ(scalar->literal()->AsUint()->value(), 2u); ASSERT_NE(ptr->idx_expr()->result_type(), nullptr); - ASSERT_TRUE(ptr->idx_expr()->result_type()->IsU32()); + ASSERT_TRUE(ptr->idx_expr()->result_type()->Is()); } TEST_F(BoundArrayAccessorsTest, Vector_Idx_Negative) { @@ -592,7 +592,7 @@ TEST_F(BoundArrayAccessorsTest, Vector_Idx_OutOfBounds) { EXPECT_EQ(scalar->literal()->AsUint()->value(), 2u); ASSERT_NE(ptr->idx_expr()->result_type(), nullptr); - ASSERT_TRUE(ptr->idx_expr()->result_type()->IsU32()); + ASSERT_TRUE(ptr->idx_expr()->result_type()->Is()); } TEST_F(BoundArrayAccessorsTest, Matrix_Idx_Scalar) { @@ -637,7 +637,7 @@ TEST_F(BoundArrayAccessorsTest, Matrix_Idx_Scalar) { EXPECT_EQ(scalar->literal()->AsUint()->value(), 2u); ASSERT_NE(ary->idx_expr()->result_type(), nullptr); - ASSERT_TRUE(ary->idx_expr()->result_type()->IsU32()); + ASSERT_TRUE(ary->idx_expr()->result_type()->Is()); ASSERT_TRUE(ptr->idx_expr()->IsConstructor()); ASSERT_TRUE(ptr->idx_expr()->AsConstructor()->IsScalarConstructor()); @@ -647,7 +647,7 @@ TEST_F(BoundArrayAccessorsTest, Matrix_Idx_Scalar) { EXPECT_EQ(scalar->literal()->AsUint()->value(), 1u); ASSERT_NE(ptr->idx_expr()->result_type(), nullptr); - ASSERT_TRUE(ptr->idx_expr()->result_type()->IsU32()); + ASSERT_TRUE(ptr->idx_expr()->result_type()->Is()); } TEST_F(BoundArrayAccessorsTest, Matrix_Idx_Expr_Column) { @@ -704,7 +704,7 @@ TEST_F(BoundArrayAccessorsTest, Matrix_Idx_Expr_Column) { ASSERT_TRUE(idx->params()[0]->IsConstructor()); ASSERT_TRUE(idx->params()[0]->AsConstructor()->IsTypeConstructor()); auto* tc = idx->params()[0]->AsConstructor()->AsTypeConstructor(); - EXPECT_TRUE(tc->type()->IsU32()); + EXPECT_TRUE(tc->type()->Is()); ASSERT_EQ(tc->values().size(), 1u); ASSERT_EQ(tc->values()[0], access_idx); @@ -715,7 +715,7 @@ TEST_F(BoundArrayAccessorsTest, Matrix_Idx_Expr_Column) { EXPECT_EQ(scalar->literal()->AsUint()->value(), 2u); ASSERT_NE(ary->idx_expr()->result_type(), nullptr); - ASSERT_TRUE(ary->idx_expr()->result_type()->IsU32()); + ASSERT_TRUE(ary->idx_expr()->result_type()->Is()); ASSERT_TRUE(ptr->idx_expr()->IsConstructor()); ASSERT_TRUE(ptr->idx_expr()->AsConstructor()->IsScalarConstructor()); @@ -725,7 +725,7 @@ TEST_F(BoundArrayAccessorsTest, Matrix_Idx_Expr_Column) { EXPECT_EQ(scalar->literal()->AsUint()->value(), 1u); ASSERT_NE(ptr->idx_expr()->result_type(), nullptr); - ASSERT_TRUE(ptr->idx_expr()->result_type()->IsU32()); + ASSERT_TRUE(ptr->idx_expr()->result_type()->Is()); } TEST_F(BoundArrayAccessorsTest, Matrix_Idx_Expr_Row) { @@ -790,7 +790,7 @@ TEST_F(BoundArrayAccessorsTest, Matrix_Idx_Expr_Row) { ASSERT_TRUE(idx->params()[0]->IsConstructor()); ASSERT_TRUE(idx->params()[0]->AsConstructor()->IsTypeConstructor()); auto* tc = idx->params()[0]->AsConstructor()->AsTypeConstructor(); - EXPECT_TRUE(tc->type()->IsU32()); + EXPECT_TRUE(tc->type()->Is()); ASSERT_EQ(tc->values().size(), 1u); ASSERT_EQ(tc->values()[0], access_idx); @@ -801,10 +801,10 @@ TEST_F(BoundArrayAccessorsTest, Matrix_Idx_Expr_Row) { EXPECT_EQ(scalar->literal()->AsUint()->value(), 1u); ASSERT_NE(ary->idx_expr()->result_type(), nullptr); - ASSERT_TRUE(ary->idx_expr()->result_type()->IsU32()); + ASSERT_TRUE(ary->idx_expr()->result_type()->Is()); ASSERT_NE(ptr->idx_expr()->result_type(), nullptr); - ASSERT_TRUE(ptr->idx_expr()->result_type()->IsU32()); + ASSERT_TRUE(ptr->idx_expr()->result_type()->Is()); } TEST_F(BoundArrayAccessorsTest, Matrix_Idx_Negative_Column) { @@ -957,7 +957,7 @@ TEST_F(BoundArrayAccessorsTest, Matrix_Idx_OutOfBounds_Column) { EXPECT_EQ(scalar->literal()->AsUint()->value(), 2u); ASSERT_NE(ary->idx_expr()->result_type(), nullptr); - ASSERT_TRUE(ary->idx_expr()->result_type()->IsU32()); + ASSERT_TRUE(ary->idx_expr()->result_type()->Is()); ASSERT_TRUE(ptr->idx_expr()->IsConstructor()); ASSERT_TRUE(ptr->idx_expr()->AsConstructor()->IsScalarConstructor()); @@ -967,7 +967,7 @@ TEST_F(BoundArrayAccessorsTest, Matrix_Idx_OutOfBounds_Column) { EXPECT_EQ(scalar->literal()->AsUint()->value(), 1u); ASSERT_NE(ptr->idx_expr()->result_type(), nullptr); - ASSERT_TRUE(ptr->idx_expr()->result_type()->IsU32()); + ASSERT_TRUE(ptr->idx_expr()->result_type()->Is()); } TEST_F(BoundArrayAccessorsTest, Matrix_Idx_OutOfBounds_Row) { @@ -1012,7 +1012,7 @@ TEST_F(BoundArrayAccessorsTest, Matrix_Idx_OutOfBounds_Row) { EXPECT_EQ(scalar->literal()->AsUint()->value(), 2u); ASSERT_NE(ary->idx_expr()->result_type(), nullptr); - ASSERT_TRUE(ary->idx_expr()->result_type()->IsU32()); + ASSERT_TRUE(ary->idx_expr()->result_type()->Is()); ASSERT_TRUE(ptr->idx_expr()->IsConstructor()); ASSERT_TRUE(ptr->idx_expr()->AsConstructor()->IsScalarConstructor()); @@ -1022,7 +1022,7 @@ TEST_F(BoundArrayAccessorsTest, Matrix_Idx_OutOfBounds_Row) { EXPECT_EQ(scalar->literal()->AsUint()->value(), 1u); ASSERT_NE(ptr->idx_expr()->result_type(), nullptr); - ASSERT_TRUE(ptr->idx_expr()->result_type()->IsU32()); + ASSERT_TRUE(ptr->idx_expr()->result_type()->Is()); } // TODO(dsinclair): Implement when constant_id exists diff --git a/src/type_determiner_test.cc b/src/type_determiner_test.cc index 3f3715e77c..dd3784d330 100644 --- a/src/type_determiner_test.cc +++ b/src/type_determiner_test.cc @@ -1756,7 +1756,7 @@ class Intrinsic_TextureOperation if (dim == ast::type::TextureDimension::k1d) { if (type->Is()) { return std::make_unique(); - } else if (type->IsU32()) { + } else if (type->Is()) { return std::make_unique(); } else { return std::make_unique(); @@ -1823,7 +1823,8 @@ TEST_P(Intrinsic_StorageTextureOperation, TextureLoadRo) { EXPECT_TRUE( expr.result_type()->AsVector()->type()->Is()); } else { - EXPECT_TRUE(expr.result_type()->AsVector()->type()->IsU32()); + EXPECT_TRUE( + expr.result_type()->AsVector()->type()->Is()); } EXPECT_EQ(expr.result_type()->AsVector()->size(), 4u); } @@ -1895,7 +1896,8 @@ TEST_P(Intrinsic_SampledTextureOperation, TextureLoadSampled) { EXPECT_TRUE( expr.result_type()->AsVector()->type()->Is()); } else { - EXPECT_TRUE(expr.result_type()->AsVector()->type()->IsU32()); + EXPECT_TRUE( + expr.result_type()->AsVector()->type()->Is()); } EXPECT_EQ(expr.result_type()->AsVector()->size(), 4u); } @@ -2479,7 +2481,7 @@ TEST_P(ImportData_SingleParam_FloatOrInt_Test, Uint_Scalar) { EXPECT_TRUE(td()->DetermineResultType(&call)) << td()->error(); ASSERT_NE(ident->result_type(), nullptr); - EXPECT_TRUE(ident->result_type()->IsU32()); + EXPECT_TRUE(ident->result_type()->Is()); } TEST_P(ImportData_SingleParam_FloatOrInt_Test, Uint_Vector) { @@ -3563,7 +3565,7 @@ TEST_P(ImportData_ThreeParam_FloatOrInt_Test, Uint_Scalar) { EXPECT_TRUE(td()->DetermineResultType(&call)) << td()->error(); ASSERT_NE(ident->result_type(), nullptr); - EXPECT_TRUE(ident->result_type()->IsU32()); + EXPECT_TRUE(ident->result_type()->Is()); } TEST_P(ImportData_ThreeParam_FloatOrInt_Test, Uint_Vector) { @@ -3922,7 +3924,7 @@ TEST_P(ImportData_FloatOrInt_TwoParamTest, Scalar_Unsigned) { EXPECT_TRUE(td()->DetermineResultType(&call)) << td()->error(); ASSERT_NE(ident->result_type(), nullptr); - EXPECT_TRUE(ident->result_type()->IsU32()); + EXPECT_TRUE(ident->result_type()->Is()); } TEST_P(ImportData_FloatOrInt_TwoParamTest, Scalar_Float) { diff --git a/src/validator/validator_impl.cc b/src/validator/validator_impl.cc index 73d896ff92..49bcb914ef 100644 --- a/src/validator/validator_impl.cc +++ b/src/validator/validator_impl.cc @@ -316,7 +316,8 @@ bool ValidatorImpl::ValidateSwitch(const ast::SwitchStatement* s) { } auto* cond_type = s->condition()->result_type()->UnwrapAll(); - if (!(cond_type->Is() || cond_type->IsU32())) { + if (!(cond_type->Is() || + cond_type->Is())) { add_error(s->condition()->source(), "v-0025", "switch statement selector expression must be of a " "scalar integer type"); @@ -342,12 +343,13 @@ bool ValidatorImpl::ValidateSwitch(const ast::SwitchStatement* s) { return false; } - auto v = static_cast(selector->type()->IsU32() + auto v = static_cast(selector->type()->Is() ? selector->AsUint()->value() : selector->AsSint()->value()); if (selector_set.count(v)) { - auto v_str = selector->type()->IsU32() ? selector->AsUint()->to_str() - : selector->AsSint()->to_str(); + auto v_str = selector->type()->Is() + ? selector->AsUint()->to_str() + : selector->AsSint()->to_str(); add_error(case_stmt->source(), "v-0027", "a literal value must not appear more than once in " "the case selectors for a switch statement: '" + diff --git a/src/writer/hlsl/generator_impl.cc b/src/writer/hlsl/generator_impl.cc index 340af43973..74c3781b40 100644 --- a/src/writer/hlsl/generator_impl.cc +++ b/src/writer/hlsl/generator_impl.cc @@ -49,6 +49,7 @@ #include "src/ast/type/sampler_type.h" #include "src/ast/type/struct_type.h" #include "src/ast/type/texture_type.h" +#include "src/ast/type/u32_type.h" #include "src/ast/type/vector_type.h" #include "src/ast/uint_literal.h" #include "src/ast/unary_op_expression.h" @@ -268,7 +269,8 @@ bool GeneratorImpl::EmitBitcast(std::ostream& pre, std::ostream& out, ast::BitcastExpression* expr) { if (!expr->type()->Is() && - !expr->type()->Is() && !expr->type()->IsU32()) { + !expr->type()->Is() && + !expr->type()->Is()) { error_ = "Unable to do bitcast to type " + expr->type()->type_name(); return false; } @@ -1552,7 +1554,7 @@ bool GeneratorImpl::EmitZeroValue(std::ostream& out, ast::type::Type* type) { out << "0.0f"; } else if (type->Is()) { out << "0"; - } else if (type->IsU32()) { + } else if (type->Is()) { out << "0u"; } else if (type->IsVector()) { return EmitZeroValue(out, type->AsVector()->type()); @@ -2123,7 +2125,7 @@ bool GeneratorImpl::EmitType(std::ostream& out, return false; } - } else if (type->IsU32()) { + } else if (type->Is()) { out << "uint"; } else if (type->IsVector()) { auto* vec = type->AsVector(); @@ -2133,7 +2135,8 @@ bool GeneratorImpl::EmitType(std::ostream& out, } else if (vec->type()->Is() && size >= 1 && size <= 4) { out << "int" << size; - } else if (vec->type()->IsU32() && size >= 1 && size <= 4) { + } else if (vec->type()->Is() && size >= 1 && + size <= 4) { out << "uint" << size; } else { out << "vector<"; diff --git a/src/writer/msl/generator_impl.cc b/src/writer/msl/generator_impl.cc index a021d79d24..b90d6104f6 100644 --- a/src/writer/msl/generator_impl.cc +++ b/src/writer/msl/generator_impl.cc @@ -201,7 +201,7 @@ uint32_t GeneratorImpl::calculate_alignment_size(ast::type::Type* type) { return 0; } if (type->Is() || type->Is() || - type->IsU32()) { + type->Is()) { return 4; } if (type->Is()) { @@ -796,7 +796,7 @@ std::string GeneratorImpl::generate_builtin_name( case ast::Intrinsic::kAbs: if (ident->result_type()->Is()) { out += "fabs"; - } else if (ident->result_type()->IsU32() || + } else if (ident->result_type()->Is() || ident->result_type()->Is()) { out += "abs"; } @@ -804,7 +804,7 @@ std::string GeneratorImpl::generate_builtin_name( case ast::Intrinsic::kMax: if (ident->result_type()->Is()) { out += "fmax"; - } else if (ident->result_type()->IsU32() || + } else if (ident->result_type()->Is() || ident->result_type()->Is()) { out += "max"; } @@ -812,7 +812,7 @@ std::string GeneratorImpl::generate_builtin_name( case ast::Intrinsic::kMin: if (ident->result_type()->Is()) { out += "fmin"; - } else if (ident->result_type()->IsU32() || + } else if (ident->result_type()->Is() || ident->result_type()->Is()) { out += "min"; } @@ -935,7 +935,7 @@ bool GeneratorImpl::EmitZeroValue(ast::type::Type* type) { out_ << "0.0f"; } else if (type->Is()) { out_ << "0"; - } else if (type->IsU32()) { + } else if (type->Is()) { out_ << "0u"; } else if (type->IsVector()) { return EmitZeroValue(type->AsVector()->type()); @@ -1909,7 +1909,7 @@ bool GeneratorImpl::EmitType(ast::type::Type* type, const std::string& name) { } out_ << ">"; - } else if (type->IsU32()) { + } else if (type->Is()) { out_ << "uint"; } else if (type->IsVector()) { auto* vec = type->AsVector(); diff --git a/src/writer/spirv/builder.cc b/src/writer/spirv/builder.cc index cda2161267..974b56dfdc 100644 --- a/src/writer/spirv/builder.cc +++ b/src/writer/spirv/builder.cc @@ -746,7 +746,7 @@ bool Builder::GenerateGlobalVariable(ast::Variable* var) { if (type->Is()) { ast::FloatLiteral l(type, 0.0f); init_id = GenerateLiteralIfNeeded(var, &l); - } else if (type->IsU32()) { + } else if (type->Is()) { ast::UintLiteral l(type, 0); init_id = GenerateLiteralIfNeeded(var, &l); } else if (type->Is()) { @@ -1403,7 +1403,8 @@ uint32_t Builder::GenerateCastOrCopyOrPassthrough(ast::type::Type* to_type, to_type->Is()) || (from_type->is_signed_integer_vector() && to_type->is_float_vector())) { op = spv::Op::OpConvertSToF; - } else if ((from_type->IsU32() && to_type->Is()) || + } else if ((from_type->Is() && + to_type->Is()) || (from_type->is_unsigned_integer_vector() && to_type->is_float_vector())) { op = spv::Op::OpConvertUToF; @@ -1412,21 +1413,25 @@ uint32_t Builder::GenerateCastOrCopyOrPassthrough(ast::type::Type* to_type, (from_type->is_float_vector() && to_type->is_signed_integer_vector())) { op = spv::Op::OpConvertFToS; - } else if ((from_type->Is() && to_type->IsU32()) || + } else if ((from_type->Is() && + to_type->Is()) || (from_type->is_float_vector() && to_type->is_unsigned_integer_vector())) { op = spv::Op::OpConvertFToU; } else if ((from_type->Is() && to_type->Is()) || - (from_type->IsU32() && to_type->IsU32()) || + (from_type->Is() && + to_type->Is()) || (from_type->Is() && to_type->Is()) || (from_type->Is() && to_type->Is()) || (from_type->IsVector() && (from_type == to_type))) { return val_id; - } else if ((from_type->Is() && to_type->IsU32()) || - (from_type->IsU32() && to_type->Is()) || + } else if ((from_type->Is() && + to_type->Is()) || + (from_type->Is() && + to_type->Is()) || (from_type->is_signed_integer_vector() && to_type->is_unsigned_integer_vector()) || (from_type->is_unsigned_integer_vector() && @@ -2447,7 +2452,7 @@ uint32_t Builder::GenerateTypeIfNeeded(ast::type::Type* type) { ast::AccessControl::kReadWrite, result)) { return 0; } - } else if (type->IsU32()) { + } else if (type->Is()) { push_type(spv::Op::OpTypeInt, {result, Operand::Int(32), Operand::Int(0)}); } else if (type->IsVector()) { if (!GenerateVectorType(type->AsVector(), result)) { diff --git a/src/writer/wgsl/generator_impl.cc b/src/writer/wgsl/generator_impl.cc index 27d84e7e23..53e2690cbc 100644 --- a/src/writer/wgsl/generator_impl.cc +++ b/src/writer/wgsl/generator_impl.cc @@ -64,6 +64,7 @@ #include "src/ast/type/sampler_type.h" #include "src/ast/type/storage_texture_type.h" #include "src/ast/type/struct_type.h" +#include "src/ast/type/u32_type.h" #include "src/ast/type/vector_type.h" #include "src/ast/type_constructor_expression.h" #include "src/ast/uint_literal.h" @@ -544,7 +545,7 @@ bool GeneratorImpl::EmitType(ast::type::Type* type) { out_ << ">"; } - } else if (type->IsU32()) { + } else if (type->Is()) { out_ << "u32"; } else if (type->IsVector()) { auto* vec = type->AsVector();