From e76a86a22c109aafbca69a50f1bc8ab9e4bed35a Mon Sep 17 00:00:00 2001 From: dan sinclair Date: Mon, 11 Jan 2021 16:24:32 +0000 Subject: [PATCH] Remove StructType::name() This CL removes the name accessor from the StructType. All usages are updated to use the symbol. Change-Id: I65d793e9609a1663facce955bdb89e60f11f382a Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/36800 Reviewed-by: Ben Clayton --- src/ast/module.cc | 6 +++--- src/ast/type/struct_type.h | 2 -- src/reader/spirv/parser_impl_named_types_test.cc | 6 ++++-- src/reader/wgsl/parser_impl.cc | 3 ++- src/reader/wgsl/parser_impl_global_decl_test.cc | 10 +++++----- src/reader/wgsl/parser_impl_struct_decl_test.cc | 6 +++--- src/reader/wgsl/parser_impl_type_alias_test.cc | 2 +- src/validator/validator_impl.cc | 2 +- src/writer/hlsl/generator_impl.cc | 6 +++--- src/writer/msl/generator_impl.cc | 4 ++-- src/writer/spirv/builder.cc | 2 +- src/writer/wgsl/generator_impl.cc | 4 ++-- 12 files changed, 27 insertions(+), 26 deletions(-) diff --git a/src/ast/module.cc b/src/ast/module.cc index c180639f64..ac337d0860 100644 --- a/src/ast/module.cc +++ b/src/ast/module.cc @@ -103,12 +103,12 @@ bool Module::IsValid() const { return false; } if (auto* str = alias->type()->As()) { - if (str->name().empty()) { + if (!str->symbol().IsValid()) { return false; } } } else if (auto* str = ty->As()) { - if (str->name().empty()) { + if (!str->symbol().IsValid()) { return false; } } else { @@ -139,7 +139,7 @@ std::string Module::to_str() const { str->impl()->to_str(out, indent); } } else if (auto* str = ty->As()) { - out << str->name() << " "; + out << str->symbol().to_str() << " "; str->impl()->to_str(out, indent); } } diff --git a/src/ast/type/struct_type.h b/src/ast/type/struct_type.h index d1a939c4ac..2d90a7a853 100644 --- a/src/ast/type/struct_type.h +++ b/src/ast/type/struct_type.h @@ -40,8 +40,6 @@ class Struct : public Castable { /// @returns the struct symbol const Symbol& symbol() const { return symbol_; } - /// @returns the struct name - const std::string& name() const { return name_; } /// @returns true if the struct has a block decoration bool IsBlockDecorated() const { return struct_->IsBlockDecorated(); } diff --git a/src/reader/spirv/parser_impl_named_types_test.cc b/src/reader/spirv/parser_impl_named_types_test.cc index be6ff493a9..26a3e3cb35 100644 --- a/src/reader/spirv/parser_impl_named_types_test.cc +++ b/src/reader/spirv/parser_impl_named_types_test.cc @@ -40,7 +40,8 @@ TEST_F(SpvParserTest, NamedTypes_AnonStruct) { %s = OpTypeStruct %uint %uint )")); EXPECT_TRUE(p->BuildAndParseInternalModule()); - EXPECT_THAT(p->module().to_str(), HasSubstr("S Struct")); + EXPECT_THAT(Demangler().Demangle(p->get_module(), p->get_module().to_str()), + HasSubstr("S Struct")); } TEST_F(SpvParserTest, NamedTypes_NamedStruct) { @@ -50,7 +51,8 @@ TEST_F(SpvParserTest, NamedTypes_NamedStruct) { %s = OpTypeStruct %uint %uint )")); EXPECT_TRUE(p->BuildAndParseInternalModule()); - EXPECT_THAT(p->module().to_str(), HasSubstr("mystruct Struct")); + EXPECT_THAT(Demangler().Demangle(p->get_module(), p->get_module().to_str()), + HasSubstr("mystruct Struct")); } TEST_F(SpvParserTest, NamedTypes_Dup_EmitBoth) { diff --git a/src/reader/wgsl/parser_impl.cc b/src/reader/wgsl/parser_impl.cc index 493ac840d1..d58b1537f8 100644 --- a/src/reader/wgsl/parser_impl.cc +++ b/src/reader/wgsl/parser_impl.cc @@ -357,7 +357,8 @@ Expect ParserImpl::expect_global_decl() { return Failure::kErrored; auto* type = module_.unique_type(std::move(str.value)); - register_constructed(type->As()->name(), type); + register_constructed( + module_.SymbolToName(type->As()->symbol()), type); module_.AddConstructedType(type); return true; } diff --git a/src/reader/wgsl/parser_impl_global_decl_test.cc b/src/reader/wgsl/parser_impl_global_decl_test.cc index 6256f02a4e..0aee4bff65 100644 --- a/src/reader/wgsl/parser_impl_global_decl_test.cc +++ b/src/reader/wgsl/parser_impl_global_decl_test.cc @@ -107,11 +107,11 @@ type B = A;)"); ASSERT_EQ(m.constructed_types().size(), 2u); ASSERT_TRUE(m.constructed_types()[0]->Is()); auto* str = m.constructed_types()[0]->As(); - EXPECT_EQ(str->name(), "A"); + EXPECT_EQ(str->symbol(), p->get_module().RegisterSymbol("A")); ASSERT_TRUE(m.constructed_types()[1]->Is()); auto* alias = m.constructed_types()[1]->As(); - EXPECT_EQ(m.SymbolToName(alias->symbol()), "B"); + EXPECT_EQ(alias->symbol(), p->get_module().RegisterSymbol("B")); EXPECT_EQ(alias->type(), str); } @@ -169,7 +169,7 @@ TEST_F(ParserImplTest, GlobalDecl_ParsesStruct) { ASSERT_TRUE(t->Is()); auto* str = t->As(); - EXPECT_EQ(str->name(), "A"); + EXPECT_EQ(str->symbol(), p->get_module().RegisterSymbol("A")); EXPECT_EQ(str->impl()->members().size(), 2u); } @@ -188,7 +188,7 @@ TEST_F(ParserImplTest, GlobalDecl_Struct_WithStride) { ASSERT_TRUE(t->Is()); auto* str = t->As(); - EXPECT_EQ(str->name(), "A"); + EXPECT_EQ(str->symbol(), p->get_module().RegisterSymbol("A")); EXPECT_EQ(str->impl()->members().size(), 1u); EXPECT_FALSE(str->IsBlockDecorated()); @@ -212,7 +212,7 @@ TEST_F(ParserImplTest, GlobalDecl_Struct_WithDecoration) { ASSERT_TRUE(t->Is()); auto* str = t->As(); - EXPECT_EQ(str->name(), "A"); + EXPECT_EQ(str->symbol(), p->get_module().RegisterSymbol("A")); EXPECT_EQ(str->impl()->members().size(), 1u); EXPECT_TRUE(str->IsBlockDecorated()); } diff --git a/src/reader/wgsl/parser_impl_struct_decl_test.cc b/src/reader/wgsl/parser_impl_struct_decl_test.cc index e1557a78f1..f176bb3a21 100644 --- a/src/reader/wgsl/parser_impl_struct_decl_test.cc +++ b/src/reader/wgsl/parser_impl_struct_decl_test.cc @@ -39,7 +39,7 @@ struct S { EXPECT_FALSE(s.errored); EXPECT_TRUE(s.matched); ASSERT_NE(s.value, nullptr); - ASSERT_EQ(s->name(), "S"); + ASSERT_EQ(s->symbol(), p->get_module().RegisterSymbol("S")); ASSERT_EQ(s->impl()->members().size(), 2u); EXPECT_EQ(s->impl()->members()[0]->name(), "a"); EXPECT_EQ(s->impl()->members()[1]->name(), "b"); @@ -61,7 +61,7 @@ TEST_F(ParserImplTest, StructDecl_ParsesWithDecoration) { EXPECT_FALSE(s.errored); EXPECT_TRUE(s.matched); ASSERT_NE(s.value, nullptr); - ASSERT_EQ(s->name(), "B"); + ASSERT_EQ(s->symbol(), p->get_module().RegisterSymbol("B")); ASSERT_EQ(s->impl()->members().size(), 2u); EXPECT_EQ(s->impl()->members()[0]->name(), "a"); EXPECT_EQ(s->impl()->members()[1]->name(), "b"); @@ -86,7 +86,7 @@ TEST_F(ParserImplTest, StructDecl_ParsesWithMultipleDecoration) { EXPECT_FALSE(s.errored); EXPECT_TRUE(s.matched); ASSERT_NE(s.value, nullptr); - ASSERT_EQ(s->name(), "S"); + ASSERT_EQ(s->symbol(), p->get_module().RegisterSymbol("S")); ASSERT_EQ(s->impl()->members().size(), 2u); EXPECT_EQ(s->impl()->members()[0]->name(), "a"); EXPECT_EQ(s->impl()->members()[1]->name(), "b"); diff --git a/src/reader/wgsl/parser_impl_type_alias_test.cc b/src/reader/wgsl/parser_impl_type_alias_test.cc index fc9e0d1ca8..f7872cf520 100644 --- a/src/reader/wgsl/parser_impl_type_alias_test.cc +++ b/src/reader/wgsl/parser_impl_type_alias_test.cc @@ -60,7 +60,7 @@ TEST_F(ParserImplTest, TypeDecl_ParsesStruct_Ident) { auto* s = alias->type()->As(); EXPECT_EQ(s->symbol(), p->get_module().RegisterSymbol("B")); - EXPECT_EQ(s->name(), "B"); + EXPECT_EQ(s->symbol(), p->get_module().RegisterSymbol("B")); } TEST_F(ParserImplTest, TypeDecl_MissingIdent) { diff --git a/src/validator/validator_impl.cc b/src/validator/validator_impl.cc index ade7fca003..484b3e982f 100644 --- a/src/validator/validator_impl.cc +++ b/src/validator/validator_impl.cc @@ -96,7 +96,7 @@ bool ValidatorImpl::ValidateConstructedTypes( add_error(member->source(), "v-0031", "a struct containing a runtime-sized array " "must be in the 'storage' storage class: '" + - st->name() + "'"); + module_.SymbolToName(st->symbol()) + "'"); return false; } } diff --git a/src/writer/hlsl/generator_impl.cc b/src/writer/hlsl/generator_impl.cc index e7f957d4a8..4eaaf599a6 100644 --- a/src/writer/hlsl/generator_impl.cc +++ b/src/writer/hlsl/generator_impl.cc @@ -249,7 +249,7 @@ bool GeneratorImpl::EmitConstructedType(std::ostream& out, } out << " " << namer_->NameFor(alias->symbol()) << ";" << std::endl; } else if (auto* str = ty->As()) { - if (!EmitStructType(out, str, str->name())) { + if (!EmitStructType(out, str, namer_->NameFor(str->symbol()))) { return false; } } else { @@ -1353,7 +1353,7 @@ bool GeneratorImpl::EmitEntryPointData( auto* type = var->type()->UnwrapIfNeeded(); if (auto* strct = type->As()) { - out << "ConstantBuffer<" << strct->name() << "> " + out << "ConstantBuffer<" << namer_->NameFor(strct->symbol()) << "> " << namer_->NameFor(var->symbol()) << " : register(b" << binding->value() << ");" << std::endl; } else { @@ -2139,7 +2139,7 @@ bool GeneratorImpl::EmitType(std::ostream& out, } out << "State"; } else if (auto* str = type->As()) { - out << str->name(); + out << namer_->NameFor(str->symbol()); } else if (auto* tex = type->As()) { if (tex->Is()) { out << "RW"; diff --git a/src/writer/msl/generator_impl.cc b/src/writer/msl/generator_impl.cc index f9b425a025..31f0364ee9 100644 --- a/src/writer/msl/generator_impl.cc +++ b/src/writer/msl/generator_impl.cc @@ -1852,7 +1852,7 @@ bool GeneratorImpl::EmitType(ast::type::Type* type, const Symbol& symbol) { } else if (auto* str = type->As()) { // The struct type emits as just the name. The declaration would be emitted // as part of emitting the constructed types. - out_ << str->name(); + out_ << namer_->NameFor(str->symbol()); } else if (auto* tex = type->As()) { if (tex->Is()) { out_ << "depth"; @@ -1942,7 +1942,7 @@ bool GeneratorImpl::EmitStructType(const ast::type::Struct* str) { // TODO(dsinclair): Block decoration? // if (str->impl()->decoration() != ast::StructDecoration::kNone) { // } - out_ << "struct " << str->name() << " {" << std::endl; + out_ << "struct " << namer_->NameFor(str->symbol()) << " {" << std::endl; increment_indent(); uint32_t current_offset = 0; diff --git a/src/writer/spirv/builder.cc b/src/writer/spirv/builder.cc index 78f61589a9..b662656f49 100644 --- a/src/writer/spirv/builder.cc +++ b/src/writer/spirv/builder.cc @@ -2788,7 +2788,7 @@ bool Builder::GenerateStructType(ast::type::Struct* struct_type, auto struct_id = result.to_i(); auto* impl = struct_type->impl(); - if (!struct_type->name().empty()) { + if (struct_type->symbol().IsValid()) { push_debug(spv::Op::OpName, {Operand::Int(struct_id), Operand::String(namer_->NameFor(struct_type->symbol()))}); diff --git a/src/writer/wgsl/generator_impl.cc b/src/writer/wgsl/generator_impl.cc index c8f868fbcd..514ccc2107 100644 --- a/src/writer/wgsl/generator_impl.cc +++ b/src/writer/wgsl/generator_impl.cc @@ -458,7 +458,7 @@ bool GeneratorImpl::EmitType(ast::type::Type* type) { } else if (auto* str = type->As()) { // The struct, as a type, is just the name. We should have already emitted // the declaration through a call to |EmitStructType| earlier. - out_ << str->name(); + out_ << module_.SymbolToName(str->symbol()); } else if (auto* texture = type->As()) { out_ << "texture_"; if (texture->Is()) { @@ -554,7 +554,7 @@ bool GeneratorImpl::EmitStructType(const ast::type::Struct* str) { deco->to_str(out_, 0); out_ << "]]" << std::endl; } - out_ << "struct " << str->name() << " {" << std::endl; + out_ << "struct " << module_.SymbolToName(str->symbol()) << " {" << std::endl; increment_indent(); for (auto* mem : impl->members()) {