diff --git a/src/ast/module.cc b/src/ast/module.cc index 101d7461aa..aed71b272d 100644 --- a/src/ast/module.cc +++ b/src/ast/module.cc @@ -61,12 +61,12 @@ bool Module::IsValid() const { if (alias->type() == nullptr) { return false; } - if (alias->type()->IsStruct() && - alias->type()->AsStruct()->name().empty()) { + if (alias->type()->Is() && + alias->type()->As()->name().empty()) { return false; } - } else if (ty->IsStruct()) { - auto* str = ty->AsStruct(); + } else if (ty->Is()) { + auto* str = ty->As(); if (str->name().empty()) { return false; } @@ -94,11 +94,11 @@ std::string Module::to_str() const { if (ty->Is()) { auto* alias = ty->As(); out << alias->name() << " -> " << alias->type()->type_name() << std::endl; - if (alias->type()->IsStruct()) { - alias->type()->AsStruct()->impl()->to_str(out, indent); + if (alias->type()->Is()) { + alias->type()->As()->impl()->to_str(out, indent); } - } else if (ty->IsStruct()) { - auto* str = ty->AsStruct(); + } else if (ty->Is()) { + auto* str = ty->As(); out << str->name() << " "; str->impl()->to_str(out, indent); } diff --git a/src/ast/type/access_control_type_test.cc b/src/ast/type/access_control_type_test.cc index 2557a533bb..c7ea3a394e 100644 --- a/src/ast/type/access_control_type_test.cc +++ b/src/ast/type/access_control_type_test.cc @@ -60,7 +60,7 @@ TEST_F(AccessControlTypeTest, Is) { EXPECT_FALSE(ty->Is()); EXPECT_FALSE(ty->Is()); EXPECT_FALSE(ty->Is()); - EXPECT_FALSE(ty->IsStruct()); + EXPECT_FALSE(ty->Is()); EXPECT_FALSE(ty->IsTexture()); EXPECT_FALSE(ty->IsU32()); EXPECT_FALSE(ty->IsVector()); diff --git a/src/ast/type/alias_type_test.cc b/src/ast/type/alias_type_test.cc index 8be31d00a9..ce2f3c7a71 100644 --- a/src/ast/type/alias_type_test.cc +++ b/src/ast/type/alias_type_test.cc @@ -61,7 +61,7 @@ TEST_F(AliasTypeTest, Is) { EXPECT_FALSE(ty->Is()); EXPECT_FALSE(ty->Is()); EXPECT_FALSE(ty->Is()); - EXPECT_FALSE(ty->IsStruct()); + EXPECT_FALSE(ty->Is()); EXPECT_FALSE(ty->IsTexture()); EXPECT_FALSE(ty->IsU32()); EXPECT_FALSE(ty->IsVector()); diff --git a/src/ast/type/array_type_test.cc b/src/ast/type/array_type_test.cc index 8ade7c4366..4cd1567ce2 100644 --- a/src/ast/type/array_type_test.cc +++ b/src/ast/type/array_type_test.cc @@ -25,6 +25,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/struct_type.h" #include "src/ast/type/u32_type.h" namespace tint { @@ -66,7 +67,7 @@ TEST_F(ArrayTypeTest, Is) { EXPECT_FALSE(ty->Is()); EXPECT_FALSE(ty->Is()); EXPECT_FALSE(ty->Is()); - EXPECT_FALSE(ty->IsStruct()); + EXPECT_FALSE(ty->Is()); EXPECT_FALSE(ty->IsTexture()); EXPECT_FALSE(ty->IsU32()); EXPECT_FALSE(ty->IsVector()); diff --git a/src/ast/type/bool_type_test.cc b/src/ast/type/bool_type_test.cc index 9aa14a4277..dc34ebb07d 100644 --- a/src/ast/type/bool_type_test.cc +++ b/src/ast/type/bool_type_test.cc @@ -21,6 +21,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/struct_type.h" namespace tint { namespace ast { @@ -41,7 +42,7 @@ TEST_F(BoolTypeTest, Is) { EXPECT_FALSE(ty->Is()); EXPECT_FALSE(ty->Is()); EXPECT_FALSE(ty->Is()); - EXPECT_FALSE(ty->IsStruct()); + EXPECT_FALSE(ty->Is()); EXPECT_FALSE(ty->IsTexture()); EXPECT_FALSE(ty->IsU32()); 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 089c6962f7..7eb088488d 100644 --- a/src/ast/type/depth_texture_type_test.cc +++ b/src/ast/type/depth_texture_type_test.cc @@ -23,6 +23,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/struct_type.h" namespace tint { namespace ast { @@ -43,7 +44,7 @@ TEST_F(DepthTextureTypeTest, Is) { EXPECT_FALSE(ty->Is()); EXPECT_FALSE(ty->Is()); EXPECT_FALSE(ty->Is()); - EXPECT_FALSE(ty->IsStruct()); + EXPECT_FALSE(ty->Is()); EXPECT_TRUE(ty->IsTexture()); EXPECT_FALSE(ty->IsU32()); EXPECT_FALSE(ty->IsVector()); diff --git a/src/ast/type/f32_type_test.cc b/src/ast/type/f32_type_test.cc index 6918a1f347..f0138c5c2a 100644 --- a/src/ast/type/f32_type_test.cc +++ b/src/ast/type/f32_type_test.cc @@ -21,6 +21,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/struct_type.h" namespace tint { namespace ast { @@ -41,7 +42,7 @@ TEST_F(F32TypeTest, Is) { EXPECT_FALSE(ty->Is()); EXPECT_FALSE(ty->Is()); EXPECT_FALSE(ty->Is()); - EXPECT_FALSE(ty->IsStruct()); + EXPECT_FALSE(ty->Is()); EXPECT_FALSE(ty->IsTexture()); EXPECT_FALSE(ty->IsU32()); EXPECT_FALSE(ty->IsVector()); diff --git a/src/ast/type/i32_type_test.cc b/src/ast/type/i32_type_test.cc index d0fa3fe274..f3b65520c0 100644 --- a/src/ast/type/i32_type_test.cc +++ b/src/ast/type/i32_type_test.cc @@ -21,6 +21,7 @@ #include "src/ast/type/f32_type.h" #include "src/ast/type/matrix_type.h" #include "src/ast/type/pointer_type.h" +#include "src/ast/type/struct_type.h" namespace tint { namespace ast { @@ -41,7 +42,7 @@ TEST_F(I32TypeTest, Is) { EXPECT_FALSE(ty->Is()); EXPECT_FALSE(ty->Is()); EXPECT_FALSE(ty->Is()); - EXPECT_FALSE(ty->IsStruct()); + EXPECT_FALSE(ty->Is()); EXPECT_FALSE(ty->IsTexture()); EXPECT_FALSE(ty->IsU32()); EXPECT_FALSE(ty->IsVector()); diff --git a/src/ast/type/matrix_type_test.cc b/src/ast/type/matrix_type_test.cc index c1af49ffca..633ec29731 100644 --- a/src/ast/type/matrix_type_test.cc +++ b/src/ast/type/matrix_type_test.cc @@ -21,6 +21,7 @@ #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" namespace tint { namespace ast { @@ -50,7 +51,7 @@ TEST_F(MatrixTypeTest, Is) { EXPECT_TRUE(ty->Is()); EXPECT_FALSE(ty->Is()); EXPECT_FALSE(ty->Is()); - EXPECT_FALSE(ty->IsStruct()); + EXPECT_FALSE(ty->Is()); EXPECT_FALSE(ty->IsTexture()); EXPECT_FALSE(ty->IsU32()); 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 52fca6fe34..d3a410cc33 100644 --- a/src/ast/type/multisampled_texture_type_test.cc +++ b/src/ast/type/multisampled_texture_type_test.cc @@ -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/struct_type.h" namespace tint { namespace ast { @@ -43,7 +44,7 @@ TEST_F(MultisampledTextureTypeTest, Is) { EXPECT_FALSE(ty->Is()); EXPECT_FALSE(ty->Is()); EXPECT_FALSE(ty->Is()); - EXPECT_FALSE(ty->IsStruct()); + EXPECT_FALSE(ty->Is()); EXPECT_TRUE(ty->IsTexture()); EXPECT_FALSE(ty->IsU32()); EXPECT_FALSE(ty->IsVector()); diff --git a/src/ast/type/pointer_type_test.cc b/src/ast/type/pointer_type_test.cc index 3166db53ae..3ce88367b9 100644 --- a/src/ast/type/pointer_type_test.cc +++ b/src/ast/type/pointer_type_test.cc @@ -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/struct_type.h" namespace tint { namespace ast { @@ -49,7 +50,7 @@ TEST_F(PointerTypeTest, Is) { EXPECT_FALSE(ty->Is()); EXPECT_TRUE(ty->Is()); EXPECT_FALSE(ty->Is()); - EXPECT_FALSE(ty->IsStruct()); + EXPECT_FALSE(ty->Is()); EXPECT_FALSE(ty->IsTexture()); EXPECT_FALSE(ty->IsU32()); 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 47902294b9..162f70100c 100644 --- a/src/ast/type/sampled_texture_type_test.cc +++ b/src/ast/type/sampled_texture_type_test.cc @@ -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/struct_type.h" namespace tint { namespace ast { @@ -43,7 +44,7 @@ TEST_F(SampledTextureTypeTest, Is) { EXPECT_FALSE(ty->Is()); EXPECT_FALSE(ty->Is()); EXPECT_FALSE(ty->Is()); - EXPECT_FALSE(ty->IsStruct()); + EXPECT_FALSE(ty->Is()); EXPECT_TRUE(ty->IsTexture()); EXPECT_FALSE(ty->IsU32()); EXPECT_FALSE(ty->IsVector()); diff --git a/src/ast/type/sampler_type_test.cc b/src/ast/type/sampler_type_test.cc index 4bdc6e441f..7ab51d97f9 100644 --- a/src/ast/type/sampler_type_test.cc +++ b/src/ast/type/sampler_type_test.cc @@ -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/struct_type.h" namespace tint { namespace ast { @@ -53,7 +54,7 @@ TEST_F(SamplerTypeTest, Is) { EXPECT_FALSE(ty->Is()); EXPECT_FALSE(ty->Is()); EXPECT_TRUE(ty->Is()); - EXPECT_FALSE(ty->IsStruct()); + EXPECT_FALSE(ty->Is()); EXPECT_FALSE(ty->IsTexture()); EXPECT_FALSE(ty->IsU32()); 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 43a0d29d9f..c97c8ca2a2 100644 --- a/src/ast/type/storage_texture_type_test.cc +++ b/src/ast/type/storage_texture_type_test.cc @@ -25,6 +25,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/struct_type.h" #include "src/type_determiner.h" namespace tint { @@ -47,7 +48,7 @@ TEST_F(StorageTextureTypeTest, Is) { EXPECT_FALSE(ty->Is()); EXPECT_FALSE(ty->Is()); EXPECT_FALSE(ty->Is()); - EXPECT_FALSE(ty->IsStruct()); + EXPECT_FALSE(ty->Is()); EXPECT_TRUE(ty->IsTexture()); EXPECT_FALSE(ty->IsU32()); EXPECT_FALSE(ty->IsVector()); diff --git a/src/ast/type/struct_type.cc b/src/ast/type/struct_type.cc index c6db7a05ed..3b107e42f4 100644 --- a/src/ast/type/struct_type.cc +++ b/src/ast/type/struct_type.cc @@ -33,10 +33,6 @@ StructType::StructType(StructType&&) = default; StructType::~StructType() = default; -bool StructType::IsStruct() const { - return true; -} - std::string StructType::type_name() const { return "__struct_" + name_; } diff --git a/src/ast/type/struct_type.h b/src/ast/type/struct_type.h index 3ab448797d..18ed3ba5d0 100644 --- a/src/ast/type/struct_type.h +++ b/src/ast/type/struct_type.h @@ -42,9 +42,6 @@ class StructType : public Castable { /// @returns true if the struct has a block decoration bool IsBlockDecorated() const { return struct_->IsBlockDecorated(); } - /// @returns true if the type is a struct type - bool IsStruct() const override; - /// @returns the struct name Struct* impl() const { return struct_; } diff --git a/src/ast/type/struct_type_test.cc b/src/ast/type/struct_type_test.cc index c13caa219e..84e5447740 100644 --- a/src/ast/type/struct_type_test.cc +++ b/src/ast/type/struct_type_test.cc @@ -58,7 +58,7 @@ TEST_F(StructTypeTest, Is) { EXPECT_FALSE(ty->Is()); EXPECT_FALSE(ty->Is()); EXPECT_FALSE(ty->Is()); - EXPECT_TRUE(ty->IsStruct()); + EXPECT_TRUE(ty->Is()); EXPECT_FALSE(ty->IsTexture()); EXPECT_FALSE(ty->IsU32()); EXPECT_FALSE(ty->IsVector()); diff --git a/src/ast/type/type.cc b/src/ast/type/type.cc index 1e8ed5c9f7..0ac063f94f 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::IsStruct() const { - return false; -} - bool Type::IsTexture() const { return false; } @@ -138,11 +134,6 @@ bool Type::is_integer_scalar_or_vector() { return is_unsigned_scalar_or_vector() || is_signed_scalar_or_vector(); } -const StructType* Type::AsStruct() const { - assert(IsStruct()); - return static_cast(this); -} - const TextureType* Type::AsTexture() const { assert(IsTexture()); return static_cast(this); @@ -163,11 +154,6 @@ const VoidType* Type::AsVoid() const { return static_cast(this); } -StructType* Type::AsStruct() { - assert(IsStruct()); - return static_cast(this); -} - TextureType* Type::AsTexture() { assert(IsTexture()); return static_cast(this); diff --git a/src/ast/type/type.h b/src/ast/type/type.h index 805c058ffb..7f88819a9b 100644 --- a/src/ast/type/type.h +++ b/src/ast/type/type.h @@ -23,7 +23,6 @@ namespace tint { namespace ast { namespace type { -class StructType; class TextureType; class U32Type; class VectorType; @@ -39,8 +38,6 @@ class Type : public Castable { Type(Type&&); ~Type() override; - /// @returns true if the type is a struct type - virtual bool IsStruct() const; /// @returns true if the type is a texture type virtual bool IsTexture() const; /// @returns true if the type is a u32 type @@ -104,8 +101,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 struct type - const StructType* AsStruct() const; /// @returns the type as a texture type const TextureType* AsTexture() const; /// @returns the type as a u32 type @@ -115,8 +110,6 @@ class Type : public Castable { /// @returns the type as a void type const VoidType* AsVoid() const; - /// @returns the type as a struct type - StructType* AsStruct(); /// @returns the type as a texture type TextureType* AsTexture(); /// @returns the type as a u32 type diff --git a/src/ast/type/u32_type_test.cc b/src/ast/type/u32_type_test.cc index 77b2e40f60..d8e756f4af 100644 --- a/src/ast/type/u32_type_test.cc +++ b/src/ast/type/u32_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/sampler_type.h" +#include "src/ast/type/struct_type.h" namespace tint { namespace ast { @@ -43,7 +44,7 @@ TEST_F(U32TypeTest, Is) { EXPECT_FALSE(ty->Is()); EXPECT_FALSE(ty->Is()); EXPECT_FALSE(ty->Is()); - EXPECT_FALSE(ty->IsStruct()); + EXPECT_FALSE(ty->Is()); EXPECT_FALSE(ty->IsTexture()); EXPECT_TRUE(ty->IsU32()); EXPECT_FALSE(ty->IsVector()); diff --git a/src/ast/type/vector_type_test.cc b/src/ast/type/vector_type_test.cc index 94a8b3f0a6..6a67e9ab0b 100644 --- a/src/ast/type/vector_type_test.cc +++ b/src/ast/type/vector_type_test.cc @@ -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/struct_type.h" namespace tint { namespace ast { @@ -50,7 +51,7 @@ TEST_F(VectorTypeTest, Is) { EXPECT_FALSE(ty->Is()); EXPECT_FALSE(ty->Is()); EXPECT_FALSE(ty->Is()); - EXPECT_FALSE(ty->IsStruct()); + EXPECT_FALSE(ty->Is()); EXPECT_FALSE(ty->IsTexture()); EXPECT_FALSE(ty->IsU32()); EXPECT_TRUE(ty->IsVector()); diff --git a/src/inspector/inspector.cc b/src/inspector/inspector.cc index bf6c289205..c16c95248b 100644 --- a/src/inspector/inspector.cc +++ b/src/inspector/inspector.cc @@ -188,11 +188,11 @@ std::vector Inspector::GetUniformBufferResourceBindings( } auto* unwrapped_type = var->type()->UnwrapIfNeeded(); - if (!unwrapped_type->IsStruct()) { + if (!unwrapped_type->Is()) { continue; } - if (!unwrapped_type->AsStruct()->IsBlockDecorated()) { + if (!unwrapped_type->As()->IsBlockDecorated()) { continue; } @@ -314,7 +314,7 @@ std::vector Inspector::GetStorageBufferResourceBindingsImpl( continue; } - if (!var->type()->UnwrapIfNeeded()->IsStruct()) { + if (!var->type()->UnwrapIfNeeded()->Is()) { continue; } diff --git a/src/reader/spirv/parser_impl.cc b/src/reader/spirv/parser_impl.cc index 82ecf8ab70..4f1cdf416a 100644 --- a/src/reader/spirv/parser_impl.cc +++ b/src/reader/spirv/parser_impl.cc @@ -1381,8 +1381,8 @@ ast::Expression* ParserImpl::MakeNullValue(ast::type::Type* type) { return create(original_type, std::move(ast_components)); } - if (type->IsStruct()) { - auto* struct_ty = type->AsStruct(); + if (type->Is()) { + auto* struct_ty = type->As(); ast::ExpressionList ast_components; for (auto* member : struct_ty->impl()->members()) { ast_components.emplace_back(MakeNullValue(member->type())); diff --git a/src/reader/spirv/parser_impl_convert_type_test.cc b/src/reader/spirv/parser_impl_convert_type_test.cc index 05425d5540..002b2c6cd8 100644 --- a/src/reader/spirv/parser_impl_convert_type_test.cc +++ b/src/reader/spirv/parser_impl_convert_type_test.cc @@ -570,9 +570,9 @@ TEST_F(SpvParserTest, ConvertType_StructTwoMembers) { auto* type = p->ConvertType(10); ASSERT_NE(type, nullptr); - EXPECT_TRUE(type->IsStruct()); + EXPECT_TRUE(type->Is()); std::stringstream ss; - type->AsStruct()->impl()->to_str(ss, 0); + type->As()->impl()->to_str(ss, 0); EXPECT_THAT(ss.str(), Eq(R"(Struct{ StructMember{field0: __u32} StructMember{field1: __f32} @@ -591,9 +591,9 @@ TEST_F(SpvParserTest, ConvertType_StructWithBlockDecoration) { auto* type = p->ConvertType(10); ASSERT_NE(type, nullptr); - EXPECT_TRUE(type->IsStruct()); + EXPECT_TRUE(type->Is()); std::stringstream ss; - type->AsStruct()->impl()->to_str(ss, 0); + type->As()->impl()->to_str(ss, 0); EXPECT_THAT(ss.str(), Eq(R"(Struct{ [[block]] StructMember{field0: __u32} @@ -616,9 +616,9 @@ TEST_F(SpvParserTest, ConvertType_StructWithMemberDecorations) { auto* type = p->ConvertType(10); ASSERT_NE(type, nullptr); - EXPECT_TRUE(type->IsStruct()); + EXPECT_TRUE(type->Is()); std::stringstream ss; - type->AsStruct()->impl()->to_str(ss, 0); + type->As()->impl()->to_str(ss, 0); EXPECT_THAT(ss.str(), Eq(R"(Struct{ StructMember{[[ offset 0 ]] field0: __f32} StructMember{[[ offset 8 ]] field1: __vec_2__f32} diff --git a/src/reader/wgsl/parser_impl.cc b/src/reader/wgsl/parser_impl.cc index 019f442f33..11ef56a0f3 100644 --- a/src/reader/wgsl/parser_impl.cc +++ b/src/reader/wgsl/parser_impl.cc @@ -318,7 +318,7 @@ Expect ParserImpl::expect_global_decl() { return Failure::kErrored; auto* type = module_.unique_type(std::move(str.value)); - register_constructed(type->AsStruct()->name(), type); + register_constructed(type->As()->name(), type); module_.AddConstructedType(type); return true; } diff --git a/src/reader/wgsl/parser_impl.h b/src/reader/wgsl/parser_impl.h index e533847a06..1e32028f4e 100644 --- a/src/reader/wgsl/parser_impl.h +++ b/src/reader/wgsl/parser_impl.h @@ -46,6 +46,7 @@ #include "src/ast/type/storage_texture_type.h" #include "src/ast/type/texture_type.h" #include "src/ast/type/type.h" +#include "src/ast/type/struct_type.h" #include "src/ast/variable.h" #include "src/ast/variable_decoration.h" #include "src/context.h" diff --git a/src/reader/wgsl/parser_impl_global_decl_test.cc b/src/reader/wgsl/parser_impl_global_decl_test.cc index 01f3635836..230c755459 100644 --- a/src/reader/wgsl/parser_impl_global_decl_test.cc +++ b/src/reader/wgsl/parser_impl_global_decl_test.cc @@ -103,8 +103,8 @@ type B = A;)"); auto& m = p->get_module(); ASSERT_EQ(m.constructed_types().size(), 2u); - ASSERT_TRUE(m.constructed_types()[0]->IsStruct()); - auto* str = m.constructed_types()[0]->AsStruct(); + ASSERT_TRUE(m.constructed_types()[0]->Is()); + auto* str = m.constructed_types()[0]->As(); EXPECT_EQ(str->name(), "A"); ASSERT_TRUE(m.constructed_types()[1]->Is()); @@ -164,9 +164,9 @@ TEST_F(ParserImplTest, GlobalDecl_ParsesStruct) { auto* t = m.constructed_types()[0]; ASSERT_NE(t, nullptr); - ASSERT_TRUE(t->IsStruct()); + ASSERT_TRUE(t->Is()); - auto* str = t->AsStruct(); + auto* str = t->As(); EXPECT_EQ(str->name(), "A"); EXPECT_EQ(str->impl()->members().size(), 2u); } @@ -183,9 +183,9 @@ TEST_F(ParserImplTest, GlobalDecl_Struct_WithStride) { auto* t = m.constructed_types()[0]; ASSERT_NE(t, nullptr); - ASSERT_TRUE(t->IsStruct()); + ASSERT_TRUE(t->Is()); - auto* str = t->AsStruct(); + auto* str = t->As(); EXPECT_EQ(str->name(), "A"); EXPECT_EQ(str->impl()->members().size(), 1u); EXPECT_FALSE(str->IsBlockDecorated()); @@ -207,9 +207,9 @@ TEST_F(ParserImplTest, GlobalDecl_Struct_WithDecoration) { auto* t = m.constructed_types()[0]; ASSERT_NE(t, nullptr); - ASSERT_TRUE(t->IsStruct()); + ASSERT_TRUE(t->Is()); - auto* str = t->AsStruct(); + auto* str = t->As(); EXPECT_EQ(str->name(), "A"); EXPECT_EQ(str->impl()->members().size(), 1u); EXPECT_TRUE(str->IsBlockDecorated()); diff --git a/src/reader/wgsl/parser_impl_type_alias_test.cc b/src/reader/wgsl/parser_impl_type_alias_test.cc index 12b51386cd..eba08831de 100644 --- a/src/reader/wgsl/parser_impl_type_alias_test.cc +++ b/src/reader/wgsl/parser_impl_type_alias_test.cc @@ -56,9 +56,9 @@ TEST_F(ParserImplTest, TypeDecl_ParsesStruct_Ident) { ASSERT_TRUE(t->Is()); auto* alias = t->As(); EXPECT_EQ(alias->name(), "a"); - ASSERT_TRUE(alias->type()->IsStruct()); + ASSERT_TRUE(alias->type()->Is()); - auto* s = alias->type()->AsStruct(); + auto* s = alias->type()->As(); EXPECT_EQ(s->name(), "B"); } diff --git a/src/type_determiner.cc b/src/type_determiner.cc index fcfc44c265..a879a79c78 100644 --- a/src/type_determiner.cc +++ b/src/type_determiner.cc @@ -1028,8 +1028,8 @@ bool TypeDeterminer::DetermineMemberAccessor( auto* data_type = res->UnwrapPtrIfNeeded()->UnwrapIfNeeded(); ast::type::Type* ret = nullptr; - if (data_type->IsStruct()) { - auto* strct = data_type->AsStruct()->impl(); + if (data_type->Is()) { + auto* strct = data_type->As()->impl(); auto name = expr->member()->name(); for (auto* member : strct->members()) { diff --git a/src/validator/validator_impl.cc b/src/validator/validator_impl.cc index a9d1000d80..73d896ff92 100644 --- a/src/validator/validator_impl.cc +++ b/src/validator/validator_impl.cc @@ -83,8 +83,8 @@ bool ValidatorImpl::Validate(const ast::Module* module) { bool ValidatorImpl::ValidateConstructedTypes( const std::vector& constructed_types) { for (auto* const ct : constructed_types) { - if (ct->IsStruct()) { - auto* st = ct->AsStruct(); + if (ct->Is()) { + auto* st = ct->As(); for (auto* member : st->impl()->members()) { if (member->type()->UnwrapAll()->Is()) { auto* r = member->type()->UnwrapAll()->As(); diff --git a/src/writer/hlsl/generator_impl.cc b/src/writer/hlsl/generator_impl.cc index 525d8a133e..5056a8a811 100644 --- a/src/writer/hlsl/generator_impl.cc +++ b/src/writer/hlsl/generator_impl.cc @@ -218,8 +218,9 @@ bool GeneratorImpl::EmitConstructedType(std::ostream& out, auto* alias = ty->As(); // HLSL typedef is for intrinsic types only. For an alias'd struct, // generate a secondary struct with the new name. - if (alias->type()->IsStruct()) { - if (!EmitStructType(out, alias->type()->AsStruct(), alias->name())) { + if (alias->type()->Is()) { + if (!EmitStructType(out, alias->type()->As(), + alias->name())) { return false; } return true; @@ -229,8 +230,8 @@ bool GeneratorImpl::EmitConstructedType(std::ostream& out, return false; } out << " " << namer_.NameFor(alias->name()) << ";" << std::endl; - } else if (ty->IsStruct()) { - auto* str = ty->AsStruct(); + } else if (ty->Is()) { + auto* str = ty->As(); if (!EmitStructType(out, str, str->name())) { return false; } @@ -1289,8 +1290,8 @@ bool GeneratorImpl::EmitEntryPointData( emitted_globals.insert(var->name()); auto* type = var->type()->UnwrapIfNeeded(); - if (type->IsStruct()) { - auto* strct = type->AsStruct(); + if (type->Is()) { + auto* strct = type->As(); out << "ConstantBuffer<" << strct->name() << "> " << var->name() << " : register(b" << binding->value() << ");" << std::endl; @@ -1684,8 +1685,8 @@ std::string GeneratorImpl::generate_storage_buffer_index_expression( if (expr->IsMemberAccessor()) { auto* mem = expr->AsMemberAccessor(); auto* res_type = mem->structure()->result_type()->UnwrapAll(); - if (res_type->IsStruct()) { - auto* str_type = res_type->AsStruct()->impl(); + if (res_type->Is()) { + auto* str_type = res_type->As()->impl(); auto* str_member = str_type->get_member(mem->member()->name()); if (!str_member->has_offset_decoration()) { @@ -2086,8 +2087,8 @@ bool GeneratorImpl::EmitType(std::ostream& out, out << "Comparison"; } out << "State"; - } else if (type->IsStruct()) { - out << type->AsStruct()->name(); + } else if (type->Is()) { + out << type->As()->name(); } else if (type->IsTexture()) { auto* tex = type->AsTexture(); if (tex->IsStorage()) { diff --git a/src/writer/msl/generator_impl.cc b/src/writer/msl/generator_impl.cc index 695ccfdb80..46b6855e66 100644 --- a/src/writer/msl/generator_impl.cc +++ b/src/writer/msl/generator_impl.cc @@ -166,19 +166,19 @@ bool GeneratorImpl::Generate() { uint32_t GeneratorImpl::calculate_largest_alignment( ast::type::StructType* type) { - auto* stct = type->AsStruct()->impl(); + auto* stct = type->As()->impl(); uint32_t largest_alignment = 0; for (auto* mem : stct->members()) { auto align = calculate_alignment_size(mem->type()); if (align == 0) { return 0; } - if (!mem->type()->IsStruct()) { + if (!mem->type()->Is()) { largest_alignment = std::max(largest_alignment, align); } else { - largest_alignment = - std::max(largest_alignment, - calculate_largest_alignment(mem->type()->AsStruct())); + largest_alignment = std::max( + largest_alignment, calculate_largest_alignment( + mem->type()->As())); } } return largest_alignment; @@ -211,8 +211,8 @@ uint32_t GeneratorImpl::calculate_alignment_size(ast::type::Type* type) { uint32_t type_size = calculate_alignment_size(mat->type()); return mat->rows() * mat->columns() * type_size; } - if (type->IsStruct()) { - auto* stct = type->AsStruct()->impl(); + if (type->Is()) { + auto* stct = type->As()->impl(); uint32_t count = 0; uint32_t largest_alignment = 0; // Offset decorations in WGSL must be in increasing order. @@ -226,12 +226,12 @@ uint32_t GeneratorImpl::calculate_alignment_size(ast::type::Type* type) { if (align == 0) { return 0; } - if (!mem->type()->IsStruct()) { + if (!mem->type()->Is()) { largest_alignment = std::max(largest_alignment, align); } else { - largest_alignment = - std::max(largest_alignment, - calculate_largest_alignment(mem->type()->AsStruct())); + largest_alignment = std::max( + largest_alignment, calculate_largest_alignment( + mem->type()->As())); } // Round up to the alignment size @@ -264,8 +264,8 @@ bool GeneratorImpl::EmitConstructedType(const ast::type::Type* ty) { return false; } out_ << " " << namer_.NameFor(alias->name()) << ";" << std::endl; - } else if (ty->IsStruct()) { - if (!EmitStructType(ty->AsStruct())) { + } else if (ty->Is()) { + if (!EmitStructType(ty->As())) { return false; } } else { @@ -947,7 +947,7 @@ bool GeneratorImpl::EmitZeroValue(ast::type::Type* type) { return false; } out_ << "}"; - } else if (type->IsStruct()) { + } else if (type->Is()) { out_ << "{}"; } else { error_ = "Invalid type for zero emission: " + type->type_name(); @@ -1834,10 +1834,10 @@ bool GeneratorImpl::EmitType(ast::type::Type* type, const std::string& name) { out_ << "*"; } else if (type->Is()) { out_ << "sampler"; - } else if (type->IsStruct()) { + } else if (type->Is()) { // The struct type emits as just the name. The declaration would be emitted // as part of emitting the constructed types. - out_ << type->AsStruct()->name(); + out_ << type->As()->name(); } else if (type->IsTexture()) { auto* tex = type->AsTexture(); diff --git a/src/writer/spirv/builder.cc b/src/writer/spirv/builder.cc index 590f4677bc..54853a7472 100644 --- a/src/writer/spirv/builder.cc +++ b/src/writer/spirv/builder.cc @@ -853,7 +853,7 @@ bool Builder::GenerateMemberAccessor(ast::MemberAccessorExpression* expr, // If the data_type is a structure we're accessing a member, if it's a // vector we're accessing a swizzle. - if (data_type->IsStruct()) { + if (data_type->Is()) { if (!info->source_type->Is()) { error_ = "Attempting to access a struct member on a non-pointer. Something is " @@ -861,7 +861,7 @@ bool Builder::GenerateMemberAccessor(ast::MemberAccessorExpression* expr, return false; } - auto* strct = data_type->AsStruct()->impl(); + auto* strct = data_type->As()->impl(); auto name = expr->member()->name(); uint32_t i = 0; @@ -1208,8 +1208,12 @@ bool Builder::is_constructor_const(ast::Expression* expr, bool is_global_init) { subtype = subtype->As()->type()->UnwrapAll(); } else if (subtype->Is()) { subtype = subtype->As()->type()->UnwrapAll(); - } else if (subtype->IsStruct()) { - subtype = subtype->AsStruct()->impl()->members()[i]->type()->UnwrapAll(); + } else if (subtype->Is()) { + subtype = subtype->As() + ->impl() + ->members()[i] + ->type() + ->UnwrapAll(); } if (subtype != sc->result_type()->UnwrapAll()) { return false; @@ -1282,7 +1286,8 @@ uint32_t Builder::GenerateTypeConstructorExpression( // If the result is not a vector then we should have validated that the // value type is a correctly sized vector so we can just use it directly. if (result_type == value_type || result_type->Is() || - result_type->Is() || result_type->IsStruct()) { + result_type->Is() || + result_type->Is()) { out << "_" << id; ops.push_back(Operand::Int(id)); @@ -1823,14 +1828,14 @@ uint32_t Builder::GenerateIntrinsic(ast::IdentifierExpression* ident, params.push_back(Operand::Int(struct_id)); auto* type = accessor->structure()->result_type()->UnwrapAll(); - if (!type->IsStruct()) { + if (!type->Is()) { error_ = "invalid type (" + type->type_name() + ") for runtime array length"; return 0; } // Runtime array must be the last member in the structure - params.push_back( - Operand::Int(uint32_t(type->AsStruct()->impl()->members().size() - 1))); + params.push_back(Operand::Int(uint32_t( + type->As()->impl()->members().size() - 1))); push_function_inst(spv::Op::OpArrayLength, params); return result_id; @@ -2409,12 +2414,12 @@ uint32_t Builder::GenerateTypeIfNeeded(ast::type::Type* type) { if (type->Is()) { auto* ac = type->As(); auto* subtype = ac->type()->UnwrapIfNeeded(); - if (!subtype->IsStruct()) { + if (!subtype->Is()) { error_ = "Access control attached to non-struct type."; return 0; } - if (!GenerateStructType(subtype->AsStruct(), ac->access_control(), - result)) { + if (!GenerateStructType(subtype->As(), + ac->access_control(), result)) { return 0; } } else if (type->Is()) { @@ -2435,9 +2440,9 @@ uint32_t Builder::GenerateTypeIfNeeded(ast::type::Type* type) { if (!GeneratePointerType(type->As(), result)) { return 0; } - } else if (type->IsStruct()) { - if (!GenerateStructType(type->AsStruct(), ast::AccessControl::kReadWrite, - result)) { + } else if (type->Is()) { + if (!GenerateStructType(type->As(), + ast::AccessControl::kReadWrite, result)) { return 0; } } else if (type->IsU32()) { diff --git a/src/writer/spirv/builder.h b/src/writer/spirv/builder.h index a9d9962593..ffda68c030 100644 --- a/src/writer/spirv/builder.h +++ b/src/writer/spirv/builder.h @@ -28,10 +28,11 @@ #include "src/ast/module.h" #include "src/ast/struct_member.h" #include "src/ast/type/access_control_type.h" -#include "src/ast/type/pointer_type.h" #include "src/ast/type/array_type.h" #include "src/ast/type/matrix_type.h" +#include "src/ast/type/pointer_type.h" #include "src/ast/type/storage_texture_type.h" +#include "src/ast/type/struct_type.h" #include "src/ast/type_constructor_expression.h" #include "src/context.h" #include "src/scope_stack.h" diff --git a/src/writer/wgsl/generator_impl.cc b/src/writer/wgsl/generator_impl.cc index 52fa96177b..402ae87bc6 100644 --- a/src/writer/wgsl/generator_impl.cc +++ b/src/writer/wgsl/generator_impl.cc @@ -178,8 +178,8 @@ bool GeneratorImpl::EmitConstructedType(const ast::type::Type* ty) { return false; } out_ << ";" << std::endl; - } else if (ty->IsStruct()) { - if (!EmitStructType(ty->AsStruct())) { + } else if (ty->Is()) { + if (!EmitStructType(ty->As())) { return false; } } else { @@ -460,10 +460,10 @@ bool GeneratorImpl::EmitType(ast::type::Type* type) { if (sampler->IsComparison()) { out_ << "_comparison"; } - } else if (type->IsStruct()) { + } else if (type->Is()) { // The struct, as a type, is just the name. We should have already emitted // the declaration through a call to |EmitStructType| earlier. - out_ << type->AsStruct()->name(); + out_ << type->As()->name(); } else if (type->IsTexture()) { auto* texture = type->AsTexture();