From 481ecff293dbda6502585687609f6d105cf17453 Mon Sep 17 00:00:00 2001 From: dan sinclair Date: Thu, 15 Oct 2020 17:54:13 +0000 Subject: [PATCH] [ast] Require StructType to have a name This CL moves the StructType name into the constructor of the struct type instead of receiving through an accessor. The |set_name| accessor is removed as it should not be needed anymore. All call sites have been updated. The vertex pulling transform was fixed to correctly register an alias for the structure being created so it will be emitted. Bug: tint:175 Change-Id: I8802931d9bdbc6c2f12982eea9032931939d195c Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/30280 Reviewed-by: Ryan Harrison Commit-Queue: dan sinclair --- src/ast/module.cc | 4 + src/ast/module_test.cc | 22 +++++ src/ast/type/struct_type.cc | 4 +- src/ast/type/struct_type.h | 6 +- src/ast/type/struct_type_test.cc | 7 +- src/reader/spirv/parser_impl.cc | 9 +- src/reader/wgsl/parser_impl.cc | 7 +- src/reader/wgsl/parser_impl.h | 3 +- .../wgsl/parser_impl_struct_decl_test.cc | 19 +++-- src/transform/vertex_pulling_transform.cc | 11 ++- .../vertex_pulling_transform_test.cc | 48 +++++++++-- src/type_determiner_test.cc | 10 +-- .../hlsl/generator_impl_alias_type_test.cc | 2 +- .../hlsl/generator_impl_function_test.cc | 9 +- .../generator_impl_member_accessor_test.cc | 84 +++++++------------ src/writer/hlsl/generator_impl_type_test.cc | 8 +- .../msl/generator_impl_alias_type_test.cc | 2 +- src/writer/msl/generator_impl_test.cc | 6 +- src/writer/msl/generator_impl_type_test.cc | 8 +- ...rator_impl_variable_decl_statement_test.cc | 2 +- .../spirv/builder_accessor_expression_test.cc | 32 +++---- src/writer/spirv/builder_assign_test.cc | 3 +- .../builder_constructor_expression_test.cc | 12 +-- src/writer/spirv/builder_intrinsic_test.cc | 9 +- src/writer/spirv/builder_type_test.cc | 31 +++---- .../wgsl/generator_impl_alias_type_test.cc | 2 +- src/writer/wgsl/generator_impl_type_test.cc | 4 +- 27 files changed, 190 insertions(+), 174 deletions(-) diff --git a/src/ast/module.cc b/src/ast/module.cc index b595aa7a7e..dfb2ab8450 100644 --- a/src/ast/module.cc +++ b/src/ast/module.cc @@ -56,6 +56,10 @@ bool Module::IsValid() const { if (alias == nullptr) { return false; } + if (alias->type()->IsStruct() && + alias->type()->AsStruct()->name().empty()) { + return false; + } } for (const auto& func : functions_) { if (func == nullptr || !func->IsValid()) { diff --git a/src/ast/module_test.cc b/src/ast/module_test.cc index 50c3982824..30db2df38d 100644 --- a/src/ast/module_test.cc +++ b/src/ast/module_test.cc @@ -19,7 +19,9 @@ #include "gmock/gmock.h" #include "src/ast/function.h" +#include "src/ast/type/alias_type.h" #include "src/ast/type/f32_type.h" +#include "src/ast/type/struct_type.h" #include "src/ast/variable.h" namespace tint { @@ -99,6 +101,26 @@ TEST_F(ModuleTest, IsValid_Null_Alias) { EXPECT_FALSE(m.IsValid()); } +TEST_F(ModuleTest, IsValid_Struct) { + type::F32Type f32; + type::StructType st("name", {}); + type::AliasType alias("name", &st); + + Module m; + m.AddAliasType(&alias); + EXPECT_TRUE(m.IsValid()); +} + +TEST_F(ModuleTest, IsValid_Struct_EmptyName) { + type::F32Type f32; + type::StructType st("", {}); + type::AliasType alias("name", &st); + + Module m; + m.AddAliasType(&alias); + EXPECT_FALSE(m.IsValid()); +} + TEST_F(ModuleTest, IsValid_Function) { type::F32Type f32; auto func = std::make_unique("main", VariableList(), &f32); diff --git a/src/ast/type/struct_type.cc b/src/ast/type/struct_type.cc index 414dc17021..8f0a017a8e 100644 --- a/src/ast/type/struct_type.cc +++ b/src/ast/type/struct_type.cc @@ -20,8 +20,8 @@ namespace tint { namespace ast { namespace type { -StructType::StructType(std::unique_ptr impl) - : struct_(std::move(impl)) {} +StructType::StructType(const std::string& name, std::unique_ptr impl) + : name_(name), struct_(std::move(impl)) {} StructType::StructType(StructType&&) = default; diff --git a/src/ast/type/struct_type.h b/src/ast/type/struct_type.h index 6a41e674e7..9621adb2ca 100644 --- a/src/ast/type/struct_type.h +++ b/src/ast/type/struct_type.h @@ -29,15 +29,13 @@ namespace type { class StructType : public Type { public: /// Constructor + /// @param name the name of the struct /// @param impl the struct data - explicit StructType(std::unique_ptr impl); + StructType(const std::string& name, std::unique_ptr impl); /// Move constructor StructType(StructType&&); ~StructType() override; - /// Sets the name of the struct - /// @param name the name to set - void set_name(const std::string& name) { name_ = name; } /// @returns the struct name const std::string& name() const { return name_; } diff --git a/src/ast/type/struct_type_test.cc b/src/ast/type/struct_type_test.cc index 317704738d..3b11b4aaff 100644 --- a/src/ast/type/struct_type_test.cc +++ b/src/ast/type/struct_type_test.cc @@ -29,13 +29,13 @@ using StructTypeTest = testing::Test; TEST_F(StructTypeTest, Creation) { auto impl = std::make_unique(); auto* ptr = impl.get(); - StructType s{std::move(impl)}; + StructType s{"S", std::move(impl)}; EXPECT_EQ(s.impl(), ptr); } TEST_F(StructTypeTest, Is) { auto impl = std::make_unique(); - StructType s{std::move(impl)}; + StructType s{"S", std::move(impl)}; EXPECT_FALSE(s.IsAlias()); EXPECT_FALSE(s.IsArray()); EXPECT_FALSE(s.IsBool()); @@ -52,8 +52,7 @@ TEST_F(StructTypeTest, Is) { TEST_F(StructTypeTest, TypeName) { auto impl = std::make_unique(); - StructType s{std::move(impl)}; - s.set_name("my_struct"); + StructType s{"my_struct", std::move(impl)}; EXPECT_EQ(s.type_name(), "__struct_my_struct"); } diff --git a/src/reader/spirv/parser_impl.cc b/src/reader/spirv/parser_impl.cc index 0861b2457d..a869be4852 100644 --- a/src/reader/spirv/parser_impl.cc +++ b/src/reader/spirv/parser_impl.cc @@ -864,12 +864,11 @@ ast::type::Type* ParserImpl::ConvertType( // Now make the struct. auto ast_struct = std::make_unique( std::move(ast_struct_decorations), std::move(ast_members)); - // The struct type will be assigned a name during EmitAliasTypes. - auto ast_struct_type = - std::make_unique(std::move(ast_struct)); - // Set the struct name before registering it. + namer_.SuggestSanitizedName(type_id, "S"); - ast_struct_type->set_name(namer_.GetName(type_id)); + auto ast_struct_type = std::make_unique( + namer_.GetName(type_id), std::move(ast_struct)); + auto* result = ctx_.type_mgr().Get(std::move(ast_struct_type)); return result; } diff --git a/src/reader/wgsl/parser_impl.cc b/src/reader/wgsl/parser_impl.cc index aa2de91da0..24ff9a83c4 100644 --- a/src/reader/wgsl/parser_impl.cc +++ b/src/reader/wgsl/parser_impl.cc @@ -1083,7 +1083,7 @@ ast::type::AliasType* ParserImpl::type_alias() { if (has_error()) return nullptr; if (type == nullptr) { - auto str = struct_decl(); + auto str = struct_decl(name); if (has_error()) return nullptr; if (str == nullptr) { @@ -1091,7 +1091,6 @@ ast::type::AliasType* ParserImpl::type_alias() { return nullptr; } - str->set_name(name); type = ctx_.type_mgr().Get(std::move(str)); } if (type == nullptr) { @@ -1479,7 +1478,8 @@ ast::StorageClass ParserImpl::storage_class() { // struct_decl // : struct_decoration_decl* STRUCT struct_body_decl -std::unique_ptr ParserImpl::struct_decl() { +std::unique_ptr ParserImpl::struct_decl( + const std::string& name) { auto t = peek(); auto source = t.source(); @@ -1506,6 +1506,7 @@ std::unique_ptr ParserImpl::struct_decl() { } return std::make_unique( + name, std::make_unique(source, std::move(decos), std::move(body))); } diff --git a/src/reader/wgsl/parser_impl.h b/src/reader/wgsl/parser_impl.h index a17042354a..c9207e5a28 100644 --- a/src/reader/wgsl/parser_impl.h +++ b/src/reader/wgsl/parser_impl.h @@ -156,8 +156,9 @@ class ParserImpl { /// @returns the storage class or StorageClass::kNone if none matched ast::StorageClass storage_class(); /// Parses a `struct_decl` grammar element + /// @param name the name of the struct /// @returns the struct type or nullptr on error - std::unique_ptr struct_decl(); + std::unique_ptr struct_decl(const std::string& name); /// Parses a `struct_decoration_decl` grammar element, appending newly /// parsed decorations to the end of |decos|. /// @param decos list to store the parsed decorations diff --git a/src/reader/wgsl/parser_impl_struct_decl_test.cc b/src/reader/wgsl/parser_impl_struct_decl_test.cc index 178b3a5ee2..08e069bf48 100644 --- a/src/reader/wgsl/parser_impl_struct_decl_test.cc +++ b/src/reader/wgsl/parser_impl_struct_decl_test.cc @@ -28,9 +28,10 @@ struct { a : i32; [[offset(4)]] b : f32; })"); - auto s = p->struct_decl(); + auto s = p->struct_decl("S"); ASSERT_FALSE(p->has_error()); ASSERT_NE(s, nullptr); + ASSERT_EQ(s->name(), "S"); ASSERT_EQ(s->impl()->members().size(), 2u); EXPECT_EQ(s->impl()->members()[0]->name(), "a"); EXPECT_EQ(s->impl()->members()[1]->name(), "b"); @@ -42,9 +43,10 @@ TEST_F(ParserImplTest, StructDecl_ParsesWithDecoration) { a : f32; b : f32; })"); - auto s = p->struct_decl(); + auto s = p->struct_decl("B"); ASSERT_FALSE(p->has_error()); ASSERT_NE(s, nullptr); + ASSERT_EQ(s->name(), "B"); ASSERT_EQ(s->impl()->members().size(), 2u); EXPECT_EQ(s->impl()->members()[0]->name(), "a"); EXPECT_EQ(s->impl()->members()[1]->name(), "b"); @@ -59,9 +61,10 @@ TEST_F(ParserImplTest, StructDecl_ParsesWithMultipleDecoration) { a : f32; b : f32; })"); - auto s = p->struct_decl(); + auto s = p->struct_decl("S"); ASSERT_FALSE(p->has_error()); ASSERT_NE(s, nullptr); + ASSERT_EQ(s->name(), "S"); ASSERT_EQ(s->impl()->members().size(), 2u); EXPECT_EQ(s->impl()->members()[0]->name(), "a"); EXPECT_EQ(s->impl()->members()[1]->name(), "b"); @@ -72,7 +75,7 @@ TEST_F(ParserImplTest, StructDecl_ParsesWithMultipleDecoration) { TEST_F(ParserImplTest, StructDecl_EmptyMembers) { auto* p = parser("struct {}"); - auto s = p->struct_decl(); + auto s = p->struct_decl("S"); ASSERT_FALSE(p->has_error()); ASSERT_NE(s, nullptr); ASSERT_EQ(s->impl()->members().size(), 0u); @@ -80,7 +83,7 @@ TEST_F(ParserImplTest, StructDecl_EmptyMembers) { TEST_F(ParserImplTest, StructDecl_MissingBracketLeft) { auto* p = parser("struct }"); - auto s = p->struct_decl(); + auto s = p->struct_decl("S"); ASSERT_TRUE(p->has_error()); ASSERT_EQ(s, nullptr); EXPECT_EQ(p->error(), "1:8: missing { for struct declaration"); @@ -88,7 +91,7 @@ TEST_F(ParserImplTest, StructDecl_MissingBracketLeft) { TEST_F(ParserImplTest, StructDecl_InvalidStructBody) { auto* p = parser("struct { a : B; }"); - auto s = p->struct_decl(); + auto s = p->struct_decl("S"); ASSERT_TRUE(p->has_error()); ASSERT_EQ(s, nullptr); EXPECT_EQ(p->error(), "1:14: unknown type alias 'B'"); @@ -96,7 +99,7 @@ TEST_F(ParserImplTest, StructDecl_InvalidStructBody) { TEST_F(ParserImplTest, StructDecl_InvalidStructDecorationDecl) { auto* p = parser("[[block struct { a : i32; }"); - auto s = p->struct_decl(); + auto s = p->struct_decl("S"); ASSERT_TRUE(p->has_error()); ASSERT_EQ(s, nullptr); EXPECT_EQ(p->error(), "1:9: missing ]] for struct decoration"); @@ -104,7 +107,7 @@ TEST_F(ParserImplTest, StructDecl_InvalidStructDecorationDecl) { TEST_F(ParserImplTest, StructDecl_MissingStruct) { auto* p = parser("[[block]] {}"); - auto s = p->struct_decl(); + auto s = p->struct_decl("S"); ASSERT_TRUE(p->has_error()); ASSERT_EQ(s, nullptr); EXPECT_EQ(p->error(), "1:11: missing struct declaration"); diff --git a/src/transform/vertex_pulling_transform.cc b/src/transform/vertex_pulling_transform.cc index 303a06253e..4de12c58c8 100644 --- a/src/transform/vertex_pulling_transform.cc +++ b/src/transform/vertex_pulling_transform.cc @@ -26,6 +26,7 @@ #include "src/ast/struct_decoration.h" #include "src/ast/struct_member.h" #include "src/ast/struct_member_offset_decoration.h" +#include "src/ast/type/alias_type.h" #include "src/ast/type/array_type.h" #include "src/ast/type/f32_type.h" #include "src/ast/type/i32_type.h" @@ -42,6 +43,7 @@ namespace { static const char kVertexBufferNamePrefix[] = "_tint_pulling_vertex_buffer_"; static const char kStructBufferName[] = "_tint_vertex_data"; +static const char kStructName[] = "TintVertexData"; static const char kPullingPosVarName[] = "_tint_pulling_pos"; static const char kDefaultVertexIndexName[] = "_tint_pulling_vertex_index"; static const char kDefaultInstanceIndexName[] = "_tint_pulling_instance_index"; @@ -235,14 +237,16 @@ void VertexPullingTransform::AddVertexStorageBuffers() { auto* struct_type = ctx_->type_mgr().Get(std::make_unique( + kStructName, std::make_unique(std::move(decos), std::move(members)))); + auto* alias = ctx_->type_mgr().Get( + std::make_unique(kStructName, struct_type)); for (uint32_t i = 0; i < vertex_state_->vertex_buffers.size(); ++i) { // The decorated variable with struct type auto var = std::make_unique( - std::make_unique(GetVertexBufferName(i), - ast::StorageClass::kStorageBuffer, - struct_type)); + std::make_unique( + GetVertexBufferName(i), ast::StorageClass::kStorageBuffer, alias)); // Add decorations ast::VariableDecorationList decorations; @@ -252,6 +256,7 @@ void VertexPullingTransform::AddVertexStorageBuffers() { mod_->AddGlobalVariable(std::move(var)); } + mod_->AddAliasType(alias->AsAlias()); } void VertexPullingTransform::AddVertexPullingPreamble( diff --git a/src/transform/vertex_pulling_transform_test.cc b/src/transform/vertex_pulling_transform_test.cc index 666416f930..cc44466d7b 100644 --- a/src/transform/vertex_pulling_transform_test.cc +++ b/src/transform/vertex_pulling_transform_test.cc @@ -156,7 +156,12 @@ TEST_F(VertexPullingTransformTest, OneAttribute) { } _tint_pulling_vertex_buffer_0 storage_buffer - __struct_ + __alias_TintVertexData__struct_TintVertexData + } + TintVertexData -> __struct_TintVertexData + Struct{ + [[block]] + StructMember{[[ offset 0 ]] _tint_vertex_data: __array__u32_stride_4} } Function main -> __void StageDecoration{vertex} @@ -237,7 +242,12 @@ TEST_F(VertexPullingTransformTest, OneInstancedAttribute) { } _tint_pulling_vertex_buffer_0 storage_buffer - __struct_ + __alias_TintVertexData__struct_TintVertexData + } + TintVertexData -> __struct_TintVertexData + Struct{ + [[block]] + StructMember{[[ offset 0 ]] _tint_vertex_data: __array__u32_stride_4} } Function main -> __void StageDecoration{vertex} @@ -318,7 +328,12 @@ TEST_F(VertexPullingTransformTest, OneAttributeDifferentOutputSet) { } _tint_pulling_vertex_buffer_0 storage_buffer - __struct_ + __alias_TintVertexData__struct_TintVertexData + } + TintVertexData -> __struct_TintVertexData + Struct{ + [[block]] + StructMember{[[ offset 0 ]] _tint_vertex_data: __array__u32_stride_4} } Function main -> __void StageDecoration{vertex} @@ -442,7 +457,7 @@ TEST_F(VertexPullingTransformTest, ExistingVertexIndexAndInstanceIndex) { } _tint_pulling_vertex_buffer_0 storage_buffer - __struct_ + __alias_TintVertexData__struct_TintVertexData } DecoratedVariable{ Decorations{ @@ -451,7 +466,12 @@ TEST_F(VertexPullingTransformTest, ExistingVertexIndexAndInstanceIndex) { } _tint_pulling_vertex_buffer_1 storage_buffer - __struct_ + __alias_TintVertexData__struct_TintVertexData + } + TintVertexData -> __struct_TintVertexData + Struct{ + [[block]] + StructMember{[[ offset 0 ]] _tint_vertex_data: __array__u32_stride_4} } Function main -> __void StageDecoration{vertex} @@ -570,7 +590,12 @@ TEST_F(VertexPullingTransformTest, TwoAttributesSameBuffer) { } _tint_pulling_vertex_buffer_0 storage_buffer - __struct_ + __alias_TintVertexData__struct_TintVertexData + } + TintVertexData -> __struct_TintVertexData + Struct{ + [[block]] + StructMember{[[ offset 0 ]] _tint_vertex_data: __array__u32_stride_4} } Function main -> __void StageDecoration{vertex} @@ -756,7 +781,7 @@ TEST_F(VertexPullingTransformTest, FloatVectorAttributes) { } _tint_pulling_vertex_buffer_0 storage_buffer - __struct_ + __alias_TintVertexData__struct_TintVertexData } DecoratedVariable{ Decorations{ @@ -765,7 +790,7 @@ TEST_F(VertexPullingTransformTest, FloatVectorAttributes) { } _tint_pulling_vertex_buffer_1 storage_buffer - __struct_ + __alias_TintVertexData__struct_TintVertexData } DecoratedVariable{ Decorations{ @@ -774,7 +799,12 @@ TEST_F(VertexPullingTransformTest, FloatVectorAttributes) { } _tint_pulling_vertex_buffer_2 storage_buffer - __struct_ + __alias_TintVertexData__struct_TintVertexData + } + TintVertexData -> __struct_TintVertexData + Struct{ + [[block]] + StructMember{[[ offset 0 ]] _tint_vertex_data: __array__u32_stride_4} } Function main -> __void StageDecoration{vertex} diff --git a/src/type_determiner_test.cc b/src/type_determiner_test.cc index df8b79c8bb..70876a9913 100644 --- a/src/type_determiner_test.cc +++ b/src/type_determiner_test.cc @@ -1037,7 +1037,7 @@ TEST_F(TypeDeterminerTest, Expr_MemberAccessor_Struct) { auto strct = std::make_unique(std::move(members)); - ast::type::StructType st(std::move(strct)); + ast::type::StructType st("S", std::move(strct)); auto var = std::make_unique("my_struct", ast::StorageClass::kNone, &st); @@ -1072,7 +1072,7 @@ TEST_F(TypeDeterminerTest, Expr_MemberAccessor_Struct_Alias) { auto strct = std::make_unique(std::move(members)); - auto st = std::make_unique(std::move(strct)); + auto st = std::make_unique("alias", std::move(strct)); ast::type::AliasType alias("alias", st.get()); auto var = std::make_unique("my_struct", @@ -1176,8 +1176,7 @@ TEST_F(TypeDeterminerTest, Expr_Accessor_MultiLevel) { std::make_unique("foo", &vec4, std::move(decos))); auto strctB = std::make_unique(std::move(b_members)); - ast::type::StructType stB(std::move(strctB)); - stB.set_name("B"); + ast::type::StructType stB("B", std::move(strctB)); ast::type::VectorType vecB(&stB, 3); @@ -1187,8 +1186,7 @@ TEST_F(TypeDeterminerTest, Expr_Accessor_MultiLevel) { auto strctA = std::make_unique(std::move(a_members)); - ast::type::StructType stA(std::move(strctA)); - stA.set_name("A"); + ast::type::StructType stA("A", std::move(strctA)); auto var = std::make_unique("c", ast::StorageClass::kNone, &stA); diff --git a/src/writer/hlsl/generator_impl_alias_type_test.cc b/src/writer/hlsl/generator_impl_alias_type_test.cc index 703ac3b12b..5dfa239509 100644 --- a/src/writer/hlsl/generator_impl_alias_type_test.cc +++ b/src/writer/hlsl/generator_impl_alias_type_test.cc @@ -63,7 +63,7 @@ TEST_F(HlslGeneratorImplTest_AliasType, EmitAliasType_Struct) { auto str = std::make_unique(); str->set_members(std::move(members)); - ast::type::StructType s(std::move(str)); + ast::type::StructType s("a", std::move(str)); ast::type::AliasType alias("a", &s); ast::Module m; diff --git a/src/writer/hlsl/generator_impl_function_test.cc b/src/writer/hlsl/generator_impl_function_test.cc index 86e392f054..ff1412af0a 100644 --- a/src/writer/hlsl/generator_impl_function_test.cc +++ b/src/writer/hlsl/generator_impl_function_test.cc @@ -309,8 +309,7 @@ TEST_F(HlslGeneratorImplTest_Function, auto str = std::make_unique(); str->set_members(std::move(members)); - ast::type::StructType s(std::move(str)); - s.set_name("Uniforms"); + ast::type::StructType s("Uniforms", std::move(str)); auto alias = std::make_unique("Uniforms", &s); auto coord_var = @@ -384,8 +383,7 @@ TEST_F(HlslGeneratorImplTest_Function, auto str = std::make_unique(); str->set_members(std::move(members)); - ast::type::StructType s(std::move(str)); - s.set_name("Data"); + ast::type::StructType s("Data", std::move(str)); auto coord_var = std::make_unique(std::make_unique( @@ -450,8 +448,7 @@ TEST_F(HlslGeneratorImplTest_Function, auto str = std::make_unique(); str->set_members(std::move(members)); - ast::type::StructType s(std::move(str)); - s.set_name("Data"); + ast::type::StructType s("Data", std::move(str)); auto coord_var = std::make_unique(std::make_unique( diff --git a/src/writer/hlsl/generator_impl_member_accessor_test.cc b/src/writer/hlsl/generator_impl_member_accessor_test.cc index a55bedd82b..5faa38d356 100644 --- a/src/writer/hlsl/generator_impl_member_accessor_test.cc +++ b/src/writer/hlsl/generator_impl_member_accessor_test.cc @@ -58,8 +58,7 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor, EmitExpression_MemberAccessor) { auto strct = std::make_unique(); strct->set_members(std::move(members)); - ast::type::StructType s(std::move(strct)); - s.set_name("Str"); + ast::type::StructType s("Str", std::move(strct)); auto str_var = std::make_unique( std::make_unique("str", ast::StorageClass::kPrivate, &s)); @@ -105,8 +104,7 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor, auto str = std::make_unique(); str->set_members(std::move(members)); - ast::type::StructType s(std::move(str)); - s.set_name("Data"); + ast::type::StructType s("Data", std::move(str)); auto coord_var = std::make_unique(std::make_unique( @@ -154,8 +152,7 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor, auto str = std::make_unique(); str->set_members(std::move(members)); - ast::type::StructType s(std::move(str)); - s.set_name("Data"); + ast::type::StructType s("Data", std::move(str)); auto coord_var = std::make_unique(std::make_unique( @@ -206,8 +203,7 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor, auto str = std::make_unique(); str->set_members(std::move(members)); - ast::type::StructType s(std::move(str)); - s.set_name("Data"); + ast::type::StructType s("Data", std::move(str)); auto b_var = std::make_unique("b", ast::StorageClass::kPrivate, &mat); @@ -270,8 +266,7 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor, auto str = std::make_unique(); str->set_members(std::move(members)); - ast::type::StructType s(std::move(str)); - s.set_name("Data"); + ast::type::StructType s("Data", std::move(str)); auto coord_var = std::make_unique(std::make_unique( @@ -330,8 +325,7 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor, auto str = std::make_unique(); str->set_members(std::move(members)); - ast::type::StructType s(std::move(str)); - s.set_name("Data"); + ast::type::StructType s("Data", std::move(str)); auto coord_var = std::make_unique(std::make_unique( @@ -386,8 +380,7 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor, auto str = std::make_unique(); str->set_members(std::move(members)); - ast::type::StructType s(std::move(str)); - s.set_name("Data"); + ast::type::StructType s("Data", std::move(str)); auto coord_var = std::make_unique(std::make_unique( @@ -434,8 +427,7 @@ TEST_F( auto str = std::make_unique(); str->set_members(std::move(members)); - ast::type::StructType s(std::move(str)); - s.set_name("Data"); + ast::type::StructType s("Data", std::move(str)); auto coord_var = std::make_unique(std::make_unique( @@ -486,8 +478,7 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor, auto str = std::make_unique(); str->set_members(std::move(members)); - ast::type::StructType s(std::move(str)); - s.set_name("Data"); + ast::type::StructType s("Data", std::move(str)); auto coord_var = std::make_unique(std::make_unique( @@ -539,8 +530,7 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor, auto str = std::make_unique(); str->set_members(std::move(members)); - ast::type::StructType s(std::move(str)); - s.set_name("Data"); + ast::type::StructType s("Data", std::move(str)); auto coord_var = std::make_unique(std::make_unique( @@ -589,8 +579,7 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor, auto str = std::make_unique(); str->set_members(std::move(members)); - ast::type::StructType s(std::move(str)); - s.set_name("Data"); + ast::type::StructType s("Data", std::move(str)); auto coord_var = std::make_unique(std::make_unique( @@ -650,8 +639,7 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor, auto str = std::make_unique(); str->set_members(std::move(members)); - ast::type::StructType s(std::move(str)); - s.set_name("Data"); + ast::type::StructType s("Data", std::move(str)); auto coord_var = std::make_unique(std::make_unique( @@ -702,8 +690,7 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor, auto str = std::make_unique(); str->set_members(std::move(members)); - ast::type::StructType s(std::move(str)); - s.set_name("Data"); + ast::type::StructType s("Data", std::move(str)); auto coord_var = std::make_unique(std::make_unique( @@ -759,8 +746,7 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor, auto str = std::make_unique(); str->set_members(std::move(members)); - ast::type::StructType s(std::move(str)); - s.set_name("Data"); + ast::type::StructType s("Data", std::move(str)); auto coord_var = std::make_unique(std::make_unique( @@ -815,8 +801,7 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor, auto str = std::make_unique(); str->set_members(std::move(members)); - ast::type::StructType s(std::move(str)); - s.set_name("Data"); + ast::type::StructType s("Data", std::move(str)); auto coord_var = std::make_unique(std::make_unique( @@ -867,8 +852,7 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor, auto str = std::make_unique(); str->set_members(std::move(members)); - ast::type::StructType s(std::move(str)); - s.set_name("Data"); + ast::type::StructType s("Data", std::move(str)); auto coord_var = std::make_unique(std::make_unique( @@ -940,8 +924,7 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor, auto data_str = std::make_unique(); data_str->set_members(std::move(members)); - ast::type::StructType data(std::move(data_str)); - data.set_name("Data"); + ast::type::StructType data("Data", std::move(data_str)); ast::type::ArrayType ary(&data, 4); ast::ArrayDecorationList decos; @@ -955,8 +938,7 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor, auto pre_str = std::make_unique(); pre_str->set_members(std::move(members)); - ast::type::StructType pre_struct(std::move(pre_str)); - pre_struct.set_name("Pre"); + ast::type::StructType pre_struct("Pre", std::move(pre_str)); auto coord_var = std::make_unique(std::make_unique( @@ -1015,8 +997,7 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor, auto data_str = std::make_unique(); data_str->set_members(std::move(members)); - ast::type::StructType data(std::move(data_str)); - data.set_name("Data"); + ast::type::StructType data("Data", std::move(data_str)); ast::type::ArrayType ary(&data, 4); ast::ArrayDecorationList decos; @@ -1030,8 +1011,7 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor, auto pre_str = std::make_unique(); pre_str->set_members(std::move(members)); - ast::type::StructType pre_struct(std::move(pre_str)); - pre_struct.set_name("Pre"); + ast::type::StructType pre_struct("Pre", std::move(pre_str)); auto coord_var = std::make_unique(std::make_unique( @@ -1093,8 +1073,7 @@ TEST_F( auto data_str = std::make_unique(); data_str->set_members(std::move(members)); - ast::type::StructType data(std::move(data_str)); - data.set_name("Data"); + ast::type::StructType data("Data", std::move(data_str)); ast::type::ArrayType ary(&data, 4); ast::ArrayDecorationList decos; @@ -1108,8 +1087,7 @@ TEST_F( auto pre_str = std::make_unique(); pre_str->set_members(std::move(members)); - ast::type::StructType pre_struct(std::move(pre_str)); - pre_struct.set_name("Pre"); + ast::type::StructType pre_struct("Pre", std::move(pre_str)); auto coord_var = std::make_unique(std::make_unique( @@ -1170,8 +1148,7 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor, auto data_str = std::make_unique(); data_str->set_members(std::move(members)); - ast::type::StructType data(std::move(data_str)); - data.set_name("Data"); + ast::type::StructType data("Data", std::move(data_str)); ast::type::ArrayType ary(&data, 4); ast::ArrayDecorationList decos; @@ -1185,8 +1162,7 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor, auto pre_str = std::make_unique(); pre_str->set_members(std::move(members)); - ast::type::StructType pre_struct(std::move(pre_str)); - pre_struct.set_name("Pre"); + ast::type::StructType pre_struct("Pre", std::move(pre_str)); auto coord_var = std::make_unique(std::make_unique( @@ -1248,8 +1224,7 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor, auto data_str = std::make_unique(); data_str->set_members(std::move(members)); - ast::type::StructType data(std::move(data_str)); - data.set_name("Data"); + ast::type::StructType data("Data", std::move(data_str)); ast::type::ArrayType ary(&data, 4); ast::ArrayDecorationList decos; @@ -1263,8 +1238,7 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor, auto pre_str = std::make_unique(); pre_str->set_members(std::move(members)); - ast::type::StructType pre_struct(std::move(pre_str)); - pre_struct.set_name("Pre"); + ast::type::StructType pre_struct("Pre", std::move(pre_str)); auto coord_var = std::make_unique(std::make_unique( @@ -1342,8 +1316,7 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor, auto data_str = std::make_unique(); data_str->set_members(std::move(members)); - ast::type::StructType data(std::move(data_str)); - data.set_name("Data"); + ast::type::StructType data("Data", std::move(data_str)); ast::type::ArrayType ary(&data, 4); ast::ArrayDecorationList decos; @@ -1357,8 +1330,7 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor, auto pre_str = std::make_unique(); pre_str->set_members(std::move(members)); - ast::type::StructType pre_struct(std::move(pre_str)); - pre_struct.set_name("Pre"); + ast::type::StructType pre_struct("Pre", std::move(pre_str)); auto coord_var = std::make_unique(std::make_unique( diff --git a/src/writer/hlsl/generator_impl_type_test.cc b/src/writer/hlsl/generator_impl_type_test.cc index 85bbda4320..e9e86a5d2d 100644 --- a/src/writer/hlsl/generator_impl_type_test.cc +++ b/src/writer/hlsl/generator_impl_type_test.cc @@ -179,7 +179,7 @@ TEST_F(HlslGeneratorImplTest_Type, EmitType_Struct) { auto str = std::make_unique(); str->set_members(std::move(members)); - ast::type::StructType s(std::move(str)); + ast::type::StructType s("S", std::move(str)); ASSERT_TRUE(gen().EmitType(out(), &s, "")) << gen().error(); EXPECT_EQ(result(), R"(struct { @@ -210,7 +210,7 @@ TEST_F(HlslGeneratorImplTest_Type, DISABLED_EmitType_Struct_InjectPadding) { auto str = std::make_unique(); str->set_members(std::move(members)); - ast::type::StructType s(std::move(str)); + ast::type::StructType s("S", std::move(str)); ASSERT_TRUE(gen().EmitType(out(), &s, "")) << gen().error(); EXPECT_EQ(result(), R"(struct { @@ -238,7 +238,7 @@ TEST_F(HlslGeneratorImplTest_Type, EmitType_Struct_NameCollision) { auto str = std::make_unique(); str->set_members(std::move(members)); - ast::type::StructType s(std::move(str)); + ast::type::StructType s("S", std::move(str)); ASSERT_TRUE(gen().EmitType(out(), &s, "")) << gen().error(); EXPECT_EQ(result(), R"(struct { @@ -267,7 +267,7 @@ TEST_F(HlslGeneratorImplTest_Type, DISABLED_EmitType_Struct_WithDecoration) { auto str = std::make_unique(std::move(decos), std::move(members)); - ast::type::StructType s(std::move(str)); + ast::type::StructType s("S", std::move(str)); ASSERT_TRUE(gen().EmitType(out(), &s, "")) << gen().error(); EXPECT_EQ(result(), R"(struct { diff --git a/src/writer/msl/generator_impl_alias_type_test.cc b/src/writer/msl/generator_impl_alias_type_test.cc index 52fce9b739..8b791df28c 100644 --- a/src/writer/msl/generator_impl_alias_type_test.cc +++ b/src/writer/msl/generator_impl_alias_type_test.cc @@ -68,7 +68,7 @@ TEST_F(MslGeneratorImplTest, EmitAliasType_Struct) { auto str = std::make_unique(); str->set_members(std::move(members)); - ast::type::StructType s(std::move(str)); + ast::type::StructType s("a", std::move(str)); ast::type::AliasType alias("a", &s); ast::Module m; diff --git a/src/writer/msl/generator_impl_test.cc b/src/writer/msl/generator_impl_test.cc index 9f29067706..cfbeef03e6 100644 --- a/src/writer/msl/generator_impl_test.cc +++ b/src/writer/msl/generator_impl_test.cc @@ -201,7 +201,7 @@ TEST_F(MslGeneratorImplTest, calculate_alignment_size_struct) { auto str = std::make_unique(); str->set_members(std::move(members)); - ast::type::StructType s(std::move(str)); + ast::type::StructType s("S", std::move(str)); ast::Module m; GeneratorImpl g(&m); @@ -231,7 +231,7 @@ TEST_F(MslGeneratorImplTest, calculate_alignment_size_struct_of_struct) { auto inner_str = std::make_unique(); inner_str->set_members(std::move(members)); - ast::type::StructType inner_s(std::move(inner_str)); + ast::type::StructType inner_s("Inner", std::move(inner_str)); decos.push_back(std::make_unique(0)); members.push_back( @@ -248,7 +248,7 @@ TEST_F(MslGeneratorImplTest, calculate_alignment_size_struct_of_struct) { auto outer_str = std::make_unique(); outer_str->set_members(std::move(members)); - ast::type::StructType outer_s(std::move(outer_str)); + ast::type::StructType outer_s("Outer", std::move(outer_str)); ast::Module m; GeneratorImpl g(&m); diff --git a/src/writer/msl/generator_impl_type_test.cc b/src/writer/msl/generator_impl_type_test.cc index 02a0581661..baa6fb3277 100644 --- a/src/writer/msl/generator_impl_type_test.cc +++ b/src/writer/msl/generator_impl_type_test.cc @@ -208,7 +208,7 @@ TEST_F(MslGeneratorImplTest, EmitType_Struct) { auto str = std::make_unique(); str->set_members(std::move(members)); - ast::type::StructType s(std::move(str)); + ast::type::StructType s("S", std::move(str)); ast::Module m; GeneratorImpl g(&m); @@ -241,7 +241,7 @@ TEST_F(MslGeneratorImplTest, EmitType_Struct_InjectPadding) { auto str = std::make_unique(); str->set_members(std::move(members)); - ast::type::StructType s(std::move(str)); + ast::type::StructType s("S", std::move(str)); ast::Module m; GeneratorImpl g(&m); @@ -271,7 +271,7 @@ TEST_F(MslGeneratorImplTest, EmitType_Struct_NameCollision) { auto str = std::make_unique(); str->set_members(std::move(members)); - ast::type::StructType s(std::move(str)); + ast::type::StructType s("S", std::move(str)); ast::Module m; GeneratorImpl g(&m); @@ -301,7 +301,7 @@ TEST_F(MslGeneratorImplTest, DISABLED_EmitType_Struct_WithDecoration) { auto str = std::make_unique(std::move(decos), std::move(members)); - ast::type::StructType s(std::move(str)); + ast::type::StructType s("S", std::move(str)); ast::Module m; GeneratorImpl g(&m); diff --git a/src/writer/msl/generator_impl_variable_decl_statement_test.cc b/src/writer/msl/generator_impl_variable_decl_statement_test.cc index cda99ae938..68606a7bfb 100644 --- a/src/writer/msl/generator_impl_variable_decl_statement_test.cc +++ b/src/writer/msl/generator_impl_variable_decl_statement_test.cc @@ -102,7 +102,7 @@ TEST_F(MslGeneratorImplTest, Emit_VariableDeclStatement_Struct) { auto str = std::make_unique(); str->set_members(std::move(members)); - ast::type::StructType s(std::move(str)); + ast::type::StructType s("S", std::move(str)); auto var = std::make_unique("a", ast::StorageClass::kNone, &s); diff --git a/src/writer/spirv/builder_accessor_expression_test.cc b/src/writer/spirv/builder_accessor_expression_test.cc index d88f8e7697..e1cf72de90 100644 --- a/src/writer/spirv/builder_accessor_expression_test.cc +++ b/src/writer/spirv/builder_accessor_expression_test.cc @@ -309,8 +309,7 @@ TEST_F(BuilderTest, MemberAccessor) { std::make_unique("b", &f32, std::move(decos))); auto s = std::make_unique(std::move(members)); - ast::type::StructType s_type(std::move(s)); - s_type.set_name("my_struct"); + ast::type::StructType s_type("my_struct", std::move(s)); ast::Variable var("ident", ast::StorageClass::kFunction, &s_type); @@ -366,15 +365,14 @@ TEST_F(BuilderTest, MemberAccessor_Nested) { std::make_unique("b", &f32, std::move(decos))); ast::type::StructType inner_struct( - std::make_unique(std::move(inner_members))); + "Inner", std::make_unique(std::move(inner_members))); ast::StructMemberList outer_members; outer_members.push_back(std::make_unique( "inner", &inner_struct, std::move(decos))); ast::type::StructType s_type( - std::make_unique(std::move(outer_members))); - s_type.set_name("my_struct"); + "my_struct", std::make_unique(std::move(outer_members))); ast::Variable var("ident", ast::StorageClass::kFunction, &s_type); @@ -434,7 +432,7 @@ TEST_F(BuilderTest, MemberAccessor_Nested_WithAlias) { std::make_unique("b", &f32, std::move(decos))); ast::type::StructType inner_struct( - std::make_unique(std::move(inner_members))); + "Inner", std::make_unique(std::move(inner_members))); ast::type::AliasType alias("Inner", &inner_struct); @@ -443,8 +441,7 @@ TEST_F(BuilderTest, MemberAccessor_Nested_WithAlias) { std::make_unique("inner", &alias, std::move(decos))); ast::type::StructType s_type( - std::make_unique(std::move(outer_members))); - s_type.set_name("my_struct"); + "Outer", std::make_unique(std::move(outer_members))); ast::Variable var("ident", ast::StorageClass::kFunction, &s_type); @@ -504,15 +501,14 @@ TEST_F(BuilderTest, MemberAccessor_Nested_Assignment_LHS) { std::make_unique("b", &f32, std::move(decos))); ast::type::StructType inner_struct( - std::make_unique(std::move(inner_members))); + "Inner", std::make_unique(std::move(inner_members))); ast::StructMemberList outer_members; outer_members.push_back(std::make_unique( "inner", &inner_struct, std::move(decos))); ast::type::StructType s_type( - std::make_unique(std::move(outer_members))); - s_type.set_name("my_struct"); + "my_struct", std::make_unique(std::move(outer_members))); ast::Variable var("ident", ast::StorageClass::kFunction, &s_type); @@ -579,15 +575,14 @@ TEST_F(BuilderTest, MemberAccessor_Nested_Assignment_RHS) { std::make_unique("b", &f32, std::move(decos))); ast::type::StructType inner_struct( - std::make_unique(std::move(inner_members))); + "Inner", std::make_unique(std::move(inner_members))); ast::StructMemberList outer_members; outer_members.push_back(std::make_unique( "inner", &inner_struct, std::move(decos))); ast::type::StructType s_type( - std::make_unique(std::move(outer_members))); - s_type.set_name("my_struct"); + "my_struct", std::make_unique(std::move(outer_members))); ast::Variable var("ident", ast::StorageClass::kFunction, &s_type); ast::Variable store("store", ast::StorageClass::kFunction, &f32); @@ -866,22 +861,19 @@ TEST_F(BuilderTest, Accessor_Mixed_ArrayAndMember) { members.push_back( std::make_unique("baz", &vec3, std::move(decos))); auto s = std::make_unique(std::move(members)); - ast::type::StructType c_type(std::move(s)); - c_type.set_name("C"); + ast::type::StructType c_type("C", std::move(s)); members.push_back( std::make_unique("bar", &c_type, std::move(decos))); s = std::make_unique(std::move(members)); - ast::type::StructType b_type(std::move(s)); - b_type.set_name("B"); + ast::type::StructType b_type("B", std::move(s)); ast::type::ArrayType b_ary_type(&b_type, 3); members.push_back(std::make_unique("foo", &b_ary_type, std::move(decos))); s = std::make_unique(std::move(members)); - ast::type::StructType a_type(std::move(s)); - a_type.set_name("A"); + ast::type::StructType a_type("A", std::move(s)); ast::type::ArrayType a_ary_type(&a_type, 2); diff --git a/src/writer/spirv/builder_assign_test.cc b/src/writer/spirv/builder_assign_test.cc index 2d532426e4..e7e04e41ae 100644 --- a/src/writer/spirv/builder_assign_test.cc +++ b/src/writer/spirv/builder_assign_test.cc @@ -241,8 +241,7 @@ TEST_F(BuilderTest, Assign_StructMember) { std::make_unique("b", &f32, std::move(decos))); auto s = std::make_unique(std::move(members)); - ast::type::StructType s_type(std::move(s)); - s_type.set_name("my_struct"); + ast::type::StructType s_type("my_struct", std::move(s)); ast::Variable v("ident", ast::StorageClass::kFunction, &s_type); diff --git a/src/writer/spirv/builder_constructor_expression_test.cc b/src/writer/spirv/builder_constructor_expression_test.cc index 62c1ab8841..cc3f99bda5 100644 --- a/src/writer/spirv/builder_constructor_expression_test.cc +++ b/src/writer/spirv/builder_constructor_expression_test.cc @@ -1791,8 +1791,7 @@ TEST_F(BuilderTest, Constructor_Type_Struct) { std::make_unique("b", &vec, std::move(decos))); auto s = std::make_unique(std::move(members)); - ast::type::StructType s_type(std::move(s)); - s_type.set_name("my_struct"); + ast::type::StructType s_type("my_struct", std::move(s)); ast::ExpressionList vec_vals; vec_vals.push_back(std::make_unique( @@ -2002,8 +2001,7 @@ TEST_F(BuilderTest, Constructor_Type_ZeroInit_Struct) { std::make_unique("a", &f32, std::move(decos))); auto s = std::make_unique(std::move(members)); - ast::type::StructType s_type(std::move(s)); - s_type.set_name("my_struct"); + ast::type::StructType s_type("my_struct", std::move(s)); ast::ExpressionList vals; ast::TypeConstructorExpression t(&s_type, std::move(vals)); @@ -2775,8 +2773,7 @@ TEST_F(BuilderTest, IsConstructorConst_Struct) { std::make_unique("b", &vec, std::move(decos))); auto s = std::make_unique(std::move(members)); - ast::type::StructType s_type(std::move(s)); - s_type.set_name("my_struct"); + ast::type::StructType s_type("my_struct", std::move(s)); ast::ExpressionList vec_vals; vec_vals.push_back(std::make_unique( @@ -2816,8 +2813,7 @@ TEST_F(BuilderTest, IsConstructorConst_Struct_WithIdentSubExpression) { std::make_unique("b", &vec, std::move(decos))); auto s = std::make_unique(std::move(members)); - ast::type::StructType s_type(std::move(s)); - s_type.set_name("my_struct"); + ast::type::StructType s_type("my_struct", std::move(s)); ast::ExpressionList vec_vals; vec_vals.push_back(std::make_unique( diff --git a/src/writer/spirv/builder_intrinsic_test.cc b/src/writer/spirv/builder_intrinsic_test.cc index f89c0e34d6..b9b7fabd93 100644 --- a/src/writer/spirv/builder_intrinsic_test.cc +++ b/src/writer/spirv/builder_intrinsic_test.cc @@ -2733,8 +2733,7 @@ TEST_F(BuilderTest, Call_ArrayLength) { std::make_unique("a", &ary, std::move(decos))); auto s = std::make_unique(std::move(members)); - ast::type::StructType s_type(std::move(s)); - s_type.set_name("my_struct"); + ast::type::StructType s_type("my_struct", std::move(s)); auto var = std::make_unique("b", ast::StorageClass::kPrivate, &s_type); @@ -2792,8 +2791,7 @@ TEST_F(BuilderTest, Call_ArrayLength_OtherMembersInStruct) { std::make_unique("a", &ary, std::move(decos))); auto s = std::make_unique(std::move(members)); - ast::type::StructType s_type(std::move(s)); - s_type.set_name("my_struct"); + ast::type::StructType s_type("my_struct", std::move(s)); auto var = std::make_unique("b", ast::StorageClass::kPrivate, &s_type); @@ -2853,8 +2851,7 @@ TEST_F(BuilderTest, DISABLED_Call_ArrayLength_Ptr) { std::make_unique("a", &ary, std::move(decos))); auto s = std::make_unique(std::move(members)); - ast::type::StructType s_type(std::move(s)); - s_type.set_name("my_struct"); + ast::type::StructType s_type("my_struct", std::move(s)); auto var = std::make_unique("b", ast::StorageClass::kPrivate, &s_type); diff --git a/src/writer/spirv/builder_type_test.cc b/src/writer/spirv/builder_type_test.cc index 7c2ef16c8f..892e812965 100644 --- a/src/writer/spirv/builder_type_test.cc +++ b/src/writer/spirv/builder_type_test.cc @@ -311,7 +311,7 @@ TEST_F(BuilderTest_Type, ReturnsGeneratedPtr) { TEST_F(BuilderTest_Type, GenerateStruct_Empty) { auto s = std::make_unique(); - ast::type::StructType s_type(std::move(s)); + ast::type::StructType s_type("S", std::move(s)); ast::Module mod; Builder b(&mod); @@ -320,7 +320,8 @@ TEST_F(BuilderTest_Type, GenerateStruct_Empty) { EXPECT_EQ(id, 1u); EXPECT_EQ(b.types().size(), 1u); - EXPECT_EQ(DumpInstructions(b.debug()), ""); + EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %1 "S" +)"); EXPECT_EQ(DumpInstructions(b.types()), R"(%1 = OpTypeStruct )"); } @@ -334,8 +335,7 @@ TEST_F(BuilderTest_Type, GenerateStruct) { std::make_unique("a", &f32, std::move(decos))); auto s = std::make_unique(std::move(members)); - ast::type::StructType s_type(std::move(s)); - s_type.set_name("my_struct"); + ast::type::StructType s_type("my_struct", std::move(s)); ast::Module mod; Builder b(&mod); @@ -364,8 +364,7 @@ TEST_F(BuilderTest_Type, GenerateStruct_Decorated) { auto s = std::make_unique(std::move(struct_decos), std::move(members)); - ast::type::StructType s_type(std::move(s)); - s_type.set_name("my_struct"); + ast::type::StructType s_type("my_struct", std::move(s)); ast::Module mod; Builder b(&mod); @@ -398,7 +397,7 @@ TEST_F(BuilderTest_Type, GenerateStruct_DecoratedMembers) { std::make_unique("b", &f32, std::move(b_decos))); auto s = std::make_unique(std::move(members)); - ast::type::StructType s_type(std::move(s)); + ast::type::StructType s_type("S", std::move(s)); ast::Module mod; Builder b(&mod); @@ -409,7 +408,8 @@ TEST_F(BuilderTest_Type, GenerateStruct_DecoratedMembers) { EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeFloat 32 %1 = OpTypeStruct %2 %2 )"); - EXPECT_EQ(DumpInstructions(b.debug()), R"(OpMemberName %1 0 "a" + EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %1 "S" +OpMemberName %1 0 "a" OpMemberName %1 1 "b" )"); EXPECT_EQ(DumpInstructions(b.annots()), R"(OpMemberDecorate %1 0 Offset 0 @@ -436,7 +436,7 @@ TEST_F(BuilderTest_Type, GenerateStruct_NonLayout_Matrix) { std::move(empty_c))); auto s = std::make_unique(std::move(members)); - ast::type::StructType s_type(std::move(s)); + ast::type::StructType s_type("S", std::move(s)); ast::Module mod; Builder b(&mod); @@ -453,7 +453,8 @@ TEST_F(BuilderTest_Type, GenerateStruct_NonLayout_Matrix) { %7 = OpTypeMatrix %8 4 %1 = OpTypeStruct %2 %5 %7 )"); - EXPECT_EQ(DumpInstructions(b.debug()), R"(OpMemberName %1 0 "a" + EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %1 "S" +OpMemberName %1 0 "a" OpMemberName %1 1 "b" OpMemberName %1 2 "c" )"); @@ -483,7 +484,7 @@ TEST_F(BuilderTest_Type, GenerateStruct_DecoratedMembers_LayoutMatrix) { std::move(c_decos))); auto s = std::make_unique(std::move(members)); - ast::type::StructType s_type(std::move(s)); + ast::type::StructType s_type("S", std::move(s)); ast::Module mod; Builder b(&mod); @@ -500,7 +501,8 @@ TEST_F(BuilderTest_Type, GenerateStruct_DecoratedMembers_LayoutMatrix) { %7 = OpTypeMatrix %8 4 %1 = OpTypeStruct %2 %5 %7 )"); - EXPECT_EQ(DumpInstructions(b.debug()), R"(OpMemberName %1 0 "a" + EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %1 "S" +OpMemberName %1 0 "a" OpMemberName %1 1 "b" OpMemberName %1 2 "c" )"); @@ -548,7 +550,7 @@ TEST_F(BuilderTest_Type, GenerateStruct_DecoratedMembers_LayoutArraysOfMatrix) { std::move(c_decos))); auto s = std::make_unique(std::move(members)); - ast::type::StructType s_type(std::move(s)); + ast::type::StructType s_type("S", std::move(s)); ast::Module mod; Builder b(&mod); @@ -565,7 +567,8 @@ TEST_F(BuilderTest_Type, GenerateStruct_DecoratedMembers_LayoutArraysOfMatrix) { %7 = OpTypeMatrix %8 4 %1 = OpTypeStruct %2 %5 %7 )"); - EXPECT_EQ(DumpInstructions(b.debug()), R"(OpMemberName %1 0 "a" + EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %1 "S" +OpMemberName %1 0 "a" OpMemberName %1 1 "b" OpMemberName %1 2 "c" )"); diff --git a/src/writer/wgsl/generator_impl_alias_type_test.cc b/src/writer/wgsl/generator_impl_alias_type_test.cc index 009b2363f9..777aec17af 100644 --- a/src/writer/wgsl/generator_impl_alias_type_test.cc +++ b/src/writer/wgsl/generator_impl_alias_type_test.cc @@ -55,7 +55,7 @@ TEST_F(WgslGeneratorImplTest, EmitAliasType_Struct) { auto str = std::make_unique(); str->set_members(std::move(members)); - ast::type::StructType s(std::move(str)); + ast::type::StructType s("a", std::move(str)); ast::type::AliasType alias("a", &s); GeneratorImpl g; diff --git a/src/writer/wgsl/generator_impl_type_test.cc b/src/writer/wgsl/generator_impl_type_test.cc index 456c478e84..816a041040 100644 --- a/src/writer/wgsl/generator_impl_type_test.cc +++ b/src/writer/wgsl/generator_impl_type_test.cc @@ -155,7 +155,7 @@ TEST_F(WgslGeneratorImplTest, EmitType_Struct) { auto str = std::make_unique(); str->set_members(std::move(members)); - ast::type::StructType s(std::move(str)); + ast::type::StructType s("S", std::move(str)); GeneratorImpl g; ASSERT_TRUE(g.EmitType(&s)) << g.error(); @@ -185,7 +185,7 @@ TEST_F(WgslGeneratorImplTest, EmitType_Struct_WithDecoration) { auto str = std::make_unique(std::move(decos), std::move(members)); - ast::type::StructType s(std::move(str)); + ast::type::StructType s("S", std::move(str)); GeneratorImpl g; ASSERT_TRUE(g.EmitType(&s)) << g.error();