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 <bclayton@google.com>
This commit is contained in:
dan sinclair 2021-01-11 16:24:32 +00:00 committed by dan sinclair
parent 1d967e3228
commit e76a86a22c
12 changed files with 27 additions and 26 deletions

View File

@ -103,12 +103,12 @@ bool Module::IsValid() const {
return false;
}
if (auto* str = alias->type()->As<type::Struct>()) {
if (str->name().empty()) {
if (!str->symbol().IsValid()) {
return false;
}
}
} else if (auto* str = ty->As<type::Struct>()) {
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<type::Struct>()) {
out << str->name() << " ";
out << str->symbol().to_str() << " ";
str->impl()->to_str(out, indent);
}
}

View File

@ -40,8 +40,6 @@ class Struct : public Castable<Struct, Type> {
/// @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(); }

View File

@ -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) {

View File

@ -357,7 +357,8 @@ Expect<bool> ParserImpl::expect_global_decl() {
return Failure::kErrored;
auto* type = module_.unique_type(std::move(str.value));
register_constructed(type->As<ast::type::Struct>()->name(), type);
register_constructed(
module_.SymbolToName(type->As<ast::type::Struct>()->symbol()), type);
module_.AddConstructedType(type);
return true;
}

View File

@ -107,11 +107,11 @@ type B = A;)");
ASSERT_EQ(m.constructed_types().size(), 2u);
ASSERT_TRUE(m.constructed_types()[0]->Is<ast::type::Struct>());
auto* str = m.constructed_types()[0]->As<ast::type::Struct>();
EXPECT_EQ(str->name(), "A");
EXPECT_EQ(str->symbol(), p->get_module().RegisterSymbol("A"));
ASSERT_TRUE(m.constructed_types()[1]->Is<ast::type::Alias>());
auto* alias = m.constructed_types()[1]->As<ast::type::Alias>();
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<ast::type::Struct>());
auto* str = t->As<ast::type::Struct>();
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<ast::type::Struct>());
auto* str = t->As<ast::type::Struct>();
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<ast::type::Struct>());
auto* str = t->As<ast::type::Struct>();
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());
}

View File

@ -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");

View File

@ -60,7 +60,7 @@ TEST_F(ParserImplTest, TypeDecl_ParsesStruct_Ident) {
auto* s = alias->type()->As<ast::type::Struct>();
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) {

View File

@ -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;
}
}

View File

@ -249,7 +249,7 @@ bool GeneratorImpl::EmitConstructedType(std::ostream& out,
}
out << " " << namer_->NameFor(alias->symbol()) << ";" << std::endl;
} else if (auto* str = ty->As<ast::type::Struct>()) {
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<ast::type::Struct>()) {
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<ast::type::Struct>()) {
out << str->name();
out << namer_->NameFor(str->symbol());
} else if (auto* tex = type->As<ast::type::Texture>()) {
if (tex->Is<ast::type::StorageTexture>()) {
out << "RW";

View File

@ -1852,7 +1852,7 @@ bool GeneratorImpl::EmitType(ast::type::Type* type, const Symbol& symbol) {
} else if (auto* str = type->As<ast::type::Struct>()) {
// 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<ast::type::Texture>()) {
if (tex->Is<ast::type::DepthTexture>()) {
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;

View File

@ -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()))});

View File

@ -458,7 +458,7 @@ bool GeneratorImpl::EmitType(ast::type::Type* type) {
} else if (auto* str = type->As<ast::type::Struct>()) {
// 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<ast::type::Texture>()) {
out_ << "texture_";
if (texture->Is<ast::type::DepthTexture>()) {
@ -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()) {