Remove StructMember::name().
This CL removes the name accessor from the struct member. Usages have been replaced with symbol usages. Change-Id: Idd9c5b34f0b5503ffee84e0c82d69aa65b1df7ea Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/36820 Reviewed-by: Ben Clayton <bclayton@google.com> Reviewed-by: Ryan Harrison <rharrison@chromium.org>
This commit is contained in:
parent
e76a86a22c
commit
eb737c25db
|
@ -34,9 +34,9 @@ Struct::Struct(Struct&&) = default;
|
||||||
|
|
||||||
Struct::~Struct() = default;
|
Struct::~Struct() = default;
|
||||||
|
|
||||||
StructMember* Struct::get_member(const std::string& name) const {
|
StructMember* Struct::get_member(const Symbol& symbol) const {
|
||||||
for (auto* mem : members_) {
|
for (auto* mem : members_) {
|
||||||
if (mem->name() == name) {
|
if (mem->symbol() == symbol) {
|
||||||
return mem;
|
return mem;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -47,10 +47,10 @@ class Struct : public Castable<Struct, Node> {
|
||||||
/// @returns the members
|
/// @returns the members
|
||||||
const StructMemberList& members() const { return members_; }
|
const StructMemberList& members() const { return members_; }
|
||||||
|
|
||||||
/// Returns the struct member with the given name or nullptr if non exists.
|
/// Returns the struct member with the given symbol or nullptr if non exists.
|
||||||
/// @param name the name of the member
|
/// @param symbol the symbol of the member
|
||||||
/// @returns the struct member or nullptr if not found
|
/// @returns the struct member or nullptr if not found
|
||||||
StructMember* get_member(const std::string& name) const;
|
StructMember* get_member(const Symbol& symbol) const;
|
||||||
|
|
||||||
/// @returns true if the struct is block decorated
|
/// @returns true if the struct is block decorated
|
||||||
bool IsBlockDecorated() const;
|
bool IsBlockDecorated() const;
|
||||||
|
|
|
@ -50,8 +50,6 @@ class StructMember : public Castable<StructMember, Node> {
|
||||||
|
|
||||||
/// @returns the symbol
|
/// @returns the symbol
|
||||||
const Symbol& symbol() const { return symbol_; }
|
const Symbol& symbol() const { return symbol_; }
|
||||||
/// @returns the name
|
|
||||||
const std::string& name() const { return name_; }
|
|
||||||
/// @returns the type
|
/// @returns the type
|
||||||
type::Type* type() const { return type_; }
|
type::Type* type() const { return type_; }
|
||||||
|
|
||||||
|
|
|
@ -30,7 +30,6 @@ using StructMemberTest = TestHelper;
|
||||||
TEST_F(StructMemberTest, Creation) {
|
TEST_F(StructMemberTest, Creation) {
|
||||||
auto* st = Member("a", ty.i32, {MemberOffset(4)});
|
auto* st = Member("a", ty.i32, {MemberOffset(4)});
|
||||||
EXPECT_EQ(st->symbol(), Symbol(1));
|
EXPECT_EQ(st->symbol(), Symbol(1));
|
||||||
EXPECT_EQ(st->name(), "a");
|
|
||||||
EXPECT_EQ(st->type(), ty.i32);
|
EXPECT_EQ(st->type(), ty.i32);
|
||||||
EXPECT_EQ(st->decorations().size(), 1u);
|
EXPECT_EQ(st->decorations().size(), 1u);
|
||||||
EXPECT_TRUE(st->decorations()[0]->Is<StructMemberOffsetDecoration>());
|
EXPECT_TRUE(st->decorations()[0]->Is<StructMemberOffsetDecoration>());
|
||||||
|
@ -45,7 +44,6 @@ TEST_F(StructMemberTest, CreationWithSource) {
|
||||||
Source{Source::Range{Source::Location{27, 4}, Source::Location{27, 8}}},
|
Source{Source::Range{Source::Location{27, 4}, Source::Location{27, 8}}},
|
||||||
"a", ty.i32);
|
"a", ty.i32);
|
||||||
EXPECT_EQ(st->symbol(), Symbol(1));
|
EXPECT_EQ(st->symbol(), Symbol(1));
|
||||||
EXPECT_EQ(st->name(), "a");
|
|
||||||
EXPECT_EQ(st->type(), ty.i32);
|
EXPECT_EQ(st->type(), ty.i32);
|
||||||
EXPECT_EQ(st->decorations().size(), 0u);
|
EXPECT_EQ(st->decorations().size(), 0u);
|
||||||
EXPECT_EQ(st->source().range.begin.line, 27u);
|
EXPECT_EQ(st->source().range.begin.line, 27u);
|
||||||
|
|
|
@ -34,7 +34,7 @@ TEST_F(ParserImplTest, StructBodyDecl_Parses) {
|
||||||
ASSERT_EQ(m.value.size(), 1u);
|
ASSERT_EQ(m.value.size(), 1u);
|
||||||
|
|
||||||
const auto* mem = m.value[0];
|
const auto* mem = m.value[0];
|
||||||
EXPECT_EQ(mem->name(), "a");
|
EXPECT_EQ(mem->symbol(), p->get_module().RegisterSymbol("a"));
|
||||||
EXPECT_EQ(mem->type(), i32);
|
EXPECT_EQ(mem->type(), i32);
|
||||||
EXPECT_EQ(mem->decorations().size(), 0u);
|
EXPECT_EQ(mem->decorations().size(), 0u);
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,8 +41,10 @@ struct S {
|
||||||
ASSERT_NE(s.value, nullptr);
|
ASSERT_NE(s.value, nullptr);
|
||||||
ASSERT_EQ(s->symbol(), p->get_module().RegisterSymbol("S"));
|
ASSERT_EQ(s->symbol(), p->get_module().RegisterSymbol("S"));
|
||||||
ASSERT_EQ(s->impl()->members().size(), 2u);
|
ASSERT_EQ(s->impl()->members().size(), 2u);
|
||||||
EXPECT_EQ(s->impl()->members()[0]->name(), "a");
|
EXPECT_EQ(s->impl()->members()[0]->symbol(),
|
||||||
EXPECT_EQ(s->impl()->members()[1]->name(), "b");
|
p->get_module().RegisterSymbol("a"));
|
||||||
|
EXPECT_EQ(s->impl()->members()[1]->symbol(),
|
||||||
|
p->get_module().RegisterSymbol("b"));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(ParserImplTest, StructDecl_ParsesWithDecoration) {
|
TEST_F(ParserImplTest, StructDecl_ParsesWithDecoration) {
|
||||||
|
@ -63,8 +65,10 @@ TEST_F(ParserImplTest, StructDecl_ParsesWithDecoration) {
|
||||||
ASSERT_NE(s.value, nullptr);
|
ASSERT_NE(s.value, nullptr);
|
||||||
ASSERT_EQ(s->symbol(), p->get_module().RegisterSymbol("B"));
|
ASSERT_EQ(s->symbol(), p->get_module().RegisterSymbol("B"));
|
||||||
ASSERT_EQ(s->impl()->members().size(), 2u);
|
ASSERT_EQ(s->impl()->members().size(), 2u);
|
||||||
EXPECT_EQ(s->impl()->members()[0]->name(), "a");
|
EXPECT_EQ(s->impl()->members()[0]->symbol(),
|
||||||
EXPECT_EQ(s->impl()->members()[1]->name(), "b");
|
p->get_module().RegisterSymbol("a"));
|
||||||
|
EXPECT_EQ(s->impl()->members()[1]->symbol(),
|
||||||
|
p->get_module().RegisterSymbol("b"));
|
||||||
ASSERT_EQ(s->impl()->decorations().size(), 1u);
|
ASSERT_EQ(s->impl()->decorations().size(), 1u);
|
||||||
EXPECT_TRUE(s->impl()->decorations()[0]->Is<ast::StructBlockDecoration>());
|
EXPECT_TRUE(s->impl()->decorations()[0]->Is<ast::StructBlockDecoration>());
|
||||||
}
|
}
|
||||||
|
@ -88,8 +92,10 @@ TEST_F(ParserImplTest, StructDecl_ParsesWithMultipleDecoration) {
|
||||||
ASSERT_NE(s.value, nullptr);
|
ASSERT_NE(s.value, nullptr);
|
||||||
ASSERT_EQ(s->symbol(), p->get_module().RegisterSymbol("S"));
|
ASSERT_EQ(s->symbol(), p->get_module().RegisterSymbol("S"));
|
||||||
ASSERT_EQ(s->impl()->members().size(), 2u);
|
ASSERT_EQ(s->impl()->members().size(), 2u);
|
||||||
EXPECT_EQ(s->impl()->members()[0]->name(), "a");
|
EXPECT_EQ(s->impl()->members()[0]->symbol(),
|
||||||
EXPECT_EQ(s->impl()->members()[1]->name(), "b");
|
p->get_module().RegisterSymbol("a"));
|
||||||
|
EXPECT_EQ(s->impl()->members()[1]->symbol(),
|
||||||
|
p->get_module().RegisterSymbol("b"));
|
||||||
ASSERT_EQ(s->impl()->decorations().size(), 2u);
|
ASSERT_EQ(s->impl()->decorations().size(), 2u);
|
||||||
EXPECT_TRUE(s->impl()->decorations()[0]->Is<ast::StructBlockDecoration>());
|
EXPECT_TRUE(s->impl()->decorations()[0]->Is<ast::StructBlockDecoration>());
|
||||||
EXPECT_TRUE(s->impl()->decorations()[1]->Is<ast::StructBlockDecoration>());
|
EXPECT_TRUE(s->impl()->decorations()[1]->Is<ast::StructBlockDecoration>());
|
||||||
|
|
|
@ -39,7 +39,7 @@ TEST_F(ParserImplTest, StructMember_Parses) {
|
||||||
ASSERT_FALSE(m.errored);
|
ASSERT_FALSE(m.errored);
|
||||||
ASSERT_NE(m.value, nullptr);
|
ASSERT_NE(m.value, nullptr);
|
||||||
|
|
||||||
EXPECT_EQ(m->name(), "a");
|
EXPECT_EQ(m->symbol(), p->get_module().RegisterSymbol("a"));
|
||||||
EXPECT_EQ(m->type(), i32);
|
EXPECT_EQ(m->type(), i32);
|
||||||
EXPECT_EQ(m->decorations().size(), 0u);
|
EXPECT_EQ(m->decorations().size(), 0u);
|
||||||
|
|
||||||
|
@ -65,7 +65,7 @@ TEST_F(ParserImplTest, StructMember_ParsesWithDecoration) {
|
||||||
ASSERT_FALSE(m.errored);
|
ASSERT_FALSE(m.errored);
|
||||||
ASSERT_NE(m.value, nullptr);
|
ASSERT_NE(m.value, nullptr);
|
||||||
|
|
||||||
EXPECT_EQ(m->name(), "a");
|
EXPECT_EQ(m->symbol(), p->get_module().RegisterSymbol("a"));
|
||||||
EXPECT_EQ(m->type(), i32);
|
EXPECT_EQ(m->type(), i32);
|
||||||
EXPECT_EQ(m->decorations().size(), 1u);
|
EXPECT_EQ(m->decorations().size(), 1u);
|
||||||
EXPECT_TRUE(m->decorations()[0]->Is<ast::StructMemberOffsetDecoration>());
|
EXPECT_TRUE(m->decorations()[0]->Is<ast::StructMemberOffsetDecoration>());
|
||||||
|
@ -96,7 +96,7 @@ TEST_F(ParserImplTest, StructMember_ParsesWithMultipleDecorations) {
|
||||||
ASSERT_FALSE(m.errored);
|
ASSERT_FALSE(m.errored);
|
||||||
ASSERT_NE(m.value, nullptr);
|
ASSERT_NE(m.value, nullptr);
|
||||||
|
|
||||||
EXPECT_EQ(m->name(), "a");
|
EXPECT_EQ(m->symbol(), p->get_module().RegisterSymbol("a"));
|
||||||
EXPECT_EQ(m->type(), i32);
|
EXPECT_EQ(m->type(), i32);
|
||||||
EXPECT_EQ(m->decorations().size(), 2u);
|
EXPECT_EQ(m->decorations().size(), 2u);
|
||||||
EXPECT_TRUE(m->decorations()[0]->Is<ast::StructMemberOffsetDecoration>());
|
EXPECT_TRUE(m->decorations()[0]->Is<ast::StructMemberOffsetDecoration>());
|
||||||
|
|
|
@ -1048,17 +1048,18 @@ bool TypeDeterminer::DetermineMemberAccessor(
|
||||||
ast::type::Type* ret = nullptr;
|
ast::type::Type* ret = nullptr;
|
||||||
if (auto* ty = data_type->As<ast::type::Struct>()) {
|
if (auto* ty = data_type->As<ast::type::Struct>()) {
|
||||||
auto* strct = ty->impl();
|
auto* strct = ty->impl();
|
||||||
auto name = expr->member()->name();
|
auto symbol = expr->member()->symbol();
|
||||||
|
|
||||||
for (auto* member : strct->members()) {
|
for (auto* member : strct->members()) {
|
||||||
if (member->name() == name) {
|
if (member->symbol() == symbol) {
|
||||||
ret = member->type();
|
ret = member->type();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ret == nullptr) {
|
if (ret == nullptr) {
|
||||||
set_error(expr->source(), "struct member " + name + " not found");
|
set_error(expr->source(),
|
||||||
|
"struct member " + mod_->SymbolToName(symbol) + " not found");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1067,7 +1068,9 @@ bool TypeDeterminer::DetermineMemberAccessor(
|
||||||
ret = mod_->create<ast::type::Pointer>(ret, ptr->storage_class());
|
ret = mod_->create<ast::type::Pointer>(ret, ptr->storage_class());
|
||||||
}
|
}
|
||||||
} else if (auto* vec = data_type->As<ast::type::Vector>()) {
|
} else if (auto* vec = data_type->As<ast::type::Vector>()) {
|
||||||
auto size = expr->member()->name().size();
|
// TODO(dsinclair): Swizzle, record into the identifier experesion
|
||||||
|
|
||||||
|
auto size = mod_->SymbolToName(expr->member()->symbol()).size();
|
||||||
if (size == 1) {
|
if (size == 1) {
|
||||||
// A single element swizzle is just the type of the vector.
|
// A single element swizzle is just the type of the vector.
|
||||||
ret = vec->type();
|
ret = vec->type();
|
||||||
|
|
|
@ -1749,7 +1749,7 @@ std::string GeneratorImpl::generate_storage_buffer_index_expression(
|
||||||
auto* res_type = mem->structure()->result_type()->UnwrapAll();
|
auto* res_type = mem->structure()->result_type()->UnwrapAll();
|
||||||
if (auto* str = res_type->As<ast::type::Struct>()) {
|
if (auto* str = res_type->As<ast::type::Struct>()) {
|
||||||
auto* str_type = str->impl();
|
auto* str_type = str->impl();
|
||||||
auto* str_member = str_type->get_member(mem->member()->name());
|
auto* str_member = str_type->get_member(mem->member()->symbol());
|
||||||
|
|
||||||
if (!str_member->has_offset_decoration()) {
|
if (!str_member->has_offset_decoration()) {
|
||||||
error_ = "missing offset decoration for struct member";
|
error_ = "missing offset decoration for struct member";
|
||||||
|
@ -1758,9 +1758,11 @@ std::string GeneratorImpl::generate_storage_buffer_index_expression(
|
||||||
out << str_member->offset();
|
out << str_member->offset();
|
||||||
|
|
||||||
} else if (res_type->Is<ast::type::Vector>()) {
|
} else if (res_type->Is<ast::type::Vector>()) {
|
||||||
|
// TODO(dsinclair): Swizzle stuff
|
||||||
|
//
|
||||||
// This must be a single element swizzle if we've got a vector at this
|
// This must be a single element swizzle if we've got a vector at this
|
||||||
// point.
|
// point.
|
||||||
if (mem->member()->name().size() != 1) {
|
if (module_->SymbolToName(mem->member()->symbol()).size() != 1) {
|
||||||
error_ =
|
error_ =
|
||||||
"Encountered multi-element swizzle when should have only one "
|
"Encountered multi-element swizzle when should have only one "
|
||||||
"level";
|
"level";
|
||||||
|
@ -1770,7 +1772,9 @@ std::string GeneratorImpl::generate_storage_buffer_index_expression(
|
||||||
// TODO(dsinclair): All our types are currently 4 bytes (f32, i32, u32)
|
// TODO(dsinclair): All our types are currently 4 bytes (f32, i32, u32)
|
||||||
// so this is assuming 4. This will need to be fixed when we get f16 or
|
// so this is assuming 4. This will need to be fixed when we get f16 or
|
||||||
// f64 types.
|
// f64 types.
|
||||||
out << "(4 * " << convert_swizzle_to_index(mem->member()->name())
|
out << "(4 * "
|
||||||
|
<< convert_swizzle_to_index(
|
||||||
|
module_->SymbolToName(mem->member()->symbol()))
|
||||||
<< ")";
|
<< ")";
|
||||||
} else {
|
} else {
|
||||||
error_ =
|
error_ =
|
||||||
|
|
|
@ -888,12 +888,12 @@ bool Builder::GenerateMemberAccessor(ast::MemberAccessorExpression* expr,
|
||||||
}
|
}
|
||||||
|
|
||||||
auto* strct = data_type->As<ast::type::Struct>()->impl();
|
auto* strct = data_type->As<ast::type::Struct>()->impl();
|
||||||
auto name = expr->member()->name();
|
auto symbol = expr->member()->symbol();
|
||||||
|
|
||||||
uint32_t i = 0;
|
uint32_t i = 0;
|
||||||
for (; i < strct->members().size(); ++i) {
|
for (; i < strct->members().size(); ++i) {
|
||||||
auto* member = strct->members()[i];
|
auto* member = strct->members()[i];
|
||||||
if (member->name() == name) {
|
if (member->symbol() == symbol) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -912,7 +912,8 @@ bool Builder::GenerateMemberAccessor(ast::MemberAccessorExpression* expr,
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto swiz = expr->member()->name();
|
// TODO(dsinclair): Swizzle stuff
|
||||||
|
auto swiz = mod_->SymbolToName(expr->member()->symbol());
|
||||||
// Single element swizzle is either an access chain or a composite extract
|
// Single element swizzle is either an access chain or a composite extract
|
||||||
if (swiz.size() == 1) {
|
if (swiz.size() == 1) {
|
||||||
auto val = IndexFromName(swiz[0]);
|
auto val = IndexFromName(swiz[0]);
|
||||||
|
@ -2832,8 +2833,9 @@ bool Builder::GenerateStructType(ast::type::Struct* struct_type,
|
||||||
uint32_t Builder::GenerateStructMember(uint32_t struct_id,
|
uint32_t Builder::GenerateStructMember(uint32_t struct_id,
|
||||||
uint32_t idx,
|
uint32_t idx,
|
||||||
ast::StructMember* member) {
|
ast::StructMember* member) {
|
||||||
push_debug(spv::Op::OpMemberName, {Operand::Int(struct_id), Operand::Int(idx),
|
push_debug(spv::Op::OpMemberName,
|
||||||
Operand::String(member->name())});
|
{Operand::Int(struct_id), Operand::Int(idx),
|
||||||
|
Operand::String(namer_->NameFor(member->symbol()))});
|
||||||
|
|
||||||
bool has_layout = false;
|
bool has_layout = false;
|
||||||
for (auto* deco : member->decorations()) {
|
for (auto* deco : member->decorations()) {
|
||||||
|
|
|
@ -567,7 +567,7 @@ bool GeneratorImpl::EmitStructType(const ast::type::Struct* str) {
|
||||||
out_ << "[[offset(" << offset->offset() << ")]]" << std::endl;
|
out_ << "[[offset(" << offset->offset() << ")]]" << std::endl;
|
||||||
}
|
}
|
||||||
make_indent();
|
make_indent();
|
||||||
out_ << mem->name() << " : ";
|
out_ << module_.SymbolToName(mem->symbol()) << " : ";
|
||||||
if (!EmitType(mem->type())) {
|
if (!EmitType(mem->type())) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue