Access struct member name through sem.

This CL changes the uses of Declaration()->symbol for struct members in
the sem to access the `Name` directly.

Bug: tint:1718
Change-Id: I3050147b97bea66d6c283e176a7152f36eb2b25f
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/112444
Commit-Queue: Dan Sinclair <dsinclair@chromium.org>
Reviewed-by: Ben Clayton <bclayton@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
This commit is contained in:
dan sinclair 2022-12-01 14:52:33 +00:00 committed by Dawn LUCI CQ
parent d5d207ba9f
commit c5b1b5c77a
9 changed files with 18 additions and 21 deletions

View File

@ -648,9 +648,9 @@ void Inspector::AddEntryPointInOutVariables(std::string name,
if (auto* struct_ty = unwrapped_type->As<sem::Struct>()) { if (auto* struct_ty = unwrapped_type->As<sem::Struct>()) {
// Recurse into members. // Recurse into members.
for (auto* member : struct_ty->Members()) { for (auto* member : struct_ty->Members()) {
AddEntryPointInOutVariables( AddEntryPointInOutVariables(name + "." + program_->Symbols().NameFor(member->Name()),
name + "." + program_->Symbols().NameFor(member->Declaration()->symbol), member->Type(), member->Declaration()->attributes,
member->Type(), member->Declaration()->attributes, member->Location(), variables); member->Location(), variables);
} }
return; return;
} }

View File

@ -3620,7 +3620,7 @@ bool Resolver::ApplyAddressSpaceUsageToType(ast::AddressSpace address_space,
decl->type->source)) { decl->type->source)) {
std::stringstream err; std::stringstream err;
err << "while analyzing structure member " << sem_.TypeNameOf(str) << "." err << "while analyzing structure member " << sem_.TypeNameOf(str) << "."
<< builder_->Symbols().NameFor(decl->symbol); << builder_->Symbols().NameFor(member->Name());
AddNote(err.str(), decl->source); AddNote(err.str(), decl->source);
return false; return false;
} }

View File

@ -413,7 +413,7 @@ bool Validator::AddressSpaceLayout(const sem::Type* store_ty,
}; };
auto member_name_of = [this](const sem::StructMember* sm) { auto member_name_of = [this](const sem::StructMember* sm) {
return symbols_.NameFor(sm->Declaration()->symbol); return symbols_.NameFor(sm->Name());
}; };
// Only validate the [type + address space] once // Only validate the [type + address space] once

View File

@ -80,7 +80,7 @@ bool Struct::Equals(const sem::Type& other) const {
const StructMember* Struct::FindMember(Symbol name) const { const StructMember* Struct::FindMember(Symbol name) const {
for (auto* member : members_) { for (auto* member : members_) {
if (member->Declaration()->symbol == name) { if (member->Name() == name) {
return member; return member;
} }
} }
@ -102,9 +102,7 @@ std::string Struct::FriendlyName(const SymbolTable& symbols) const {
std::string Struct::Layout(const tint::SymbolTable& symbols) const { std::string Struct::Layout(const tint::SymbolTable& symbols) const {
std::stringstream ss; std::stringstream ss;
auto member_name_of = [&](const sem::StructMember* sm) { auto member_name_of = [&](const sem::StructMember* sm) { return symbols.NameFor(sm->Name()); };
return symbols.NameFor(sm->Declaration()->symbol);
};
if (Members().empty()) { if (Members().empty()) {
return {}; return {};

View File

@ -359,10 +359,10 @@ struct CanonicalizeEntryPointIO::State {
continue; continue;
} }
auto* member_ast = member->Declaration(); auto name = ctx.src->Symbols().NameFor(member->Name());
auto name = ctx.src->Symbols().NameFor(member_ast->symbol);
auto attributes = CloneShaderIOAttributes(member_ast->attributes, do_interpolate); auto attributes =
CloneShaderIOAttributes(member->Declaration()->attributes, do_interpolate);
auto* input_expr = auto* input_expr =
AddInput(name, member->Type(), member->Location(), std::move(attributes)); AddInput(name, member->Type(), member->Location(), std::move(attributes));
inner_struct_values.Push(input_expr); inner_struct_values.Push(input_expr);
@ -388,9 +388,9 @@ struct CanonicalizeEntryPointIO::State {
continue; continue;
} }
auto* member_ast = member->Declaration(); auto name = ctx.src->Symbols().NameFor(member->Name());
auto name = ctx.src->Symbols().NameFor(member_ast->symbol); auto attributes =
auto attributes = CloneShaderIOAttributes(member_ast->attributes, do_interpolate); CloneShaderIOAttributes(member->Declaration()->attributes, do_interpolate);
// Extract the original structure member. // Extract the original structure member.
AddOutput(name, member->Type(), member->Location(), std::move(attributes), AddOutput(name, member->Type(), member->Location(), std::move(attributes),

View File

@ -645,8 +645,8 @@ struct DecomposeMemoryAccess::State {
utils::Vector<const ast::Statement*, 8> stmts; utils::Vector<const ast::Statement*, 8> stmts;
for (auto* member : str->Members()) { for (auto* member : str->Members()) {
auto* offset = b.Add("offset", u32(member->Offset())); auto* offset = b.Add("offset", u32(member->Offset()));
auto* element = b.MemberAccessor( auto* element =
"value", ctx.Clone(member->Declaration()->symbol)); b.MemberAccessor("value", ctx.Clone(member->Name()));
Symbol store = Symbol store =
StoreFunc(buf_ty, member->Type()->UnwrapRef(), var_user); StoreFunc(buf_ty, member->Type()->UnwrapRef(), var_user);
auto* call = b.Call(store, "buffer", offset, element); auto* call = b.Call(store, "buffer", offset, element);

View File

@ -107,7 +107,7 @@ Transform::ApplyResult NumWorkgroupsFromUniform::Apply(const Program* src,
// Capture the symbols that would be used to access this member, which // Capture the symbols that would be used to access this member, which
// we will replace later. We currently have no way to get from the // we will replace later. We currently have no way to get from the
// parameter directly to the member accessor expressions that use it. // parameter directly to the member accessor expressions that use it.
to_replace.insert({param->Declaration()->symbol, member->Declaration()->symbol}); to_replace.insert({param->Declaration()->symbol, member->Name()});
// Remove the struct member. // Remove the struct member.
// The CanonicalizeEntryPointIO transform will have generated this // The CanonicalizeEntryPointIO transform will have generated this

View File

@ -57,7 +57,7 @@ struct PackedVec3::State {
// Apply the PackedVec3::Attribute to the member // Apply the PackedVec3::Attribute to the member
auto* member_decl = member->Declaration(); auto* member_decl = member->Declaration();
auto name = ctx.Clone(member_decl->symbol); auto name = ctx.Clone(member->Name());
auto* type = ctx.Clone(member_decl->type); auto* type = ctx.Clone(member_decl->type);
utils::Vector<const ast::Attribute*, 4> attrs{ utils::Vector<const ast::Attribute*, 4> attrs{
b.ASTNodes().Create<Attribute>(b.ID(), b.AllocateNodeID()), b.ASTNodes().Create<Attribute>(b.ID(), b.AllocateNodeID()),

View File

@ -131,8 +131,7 @@ Transform::ApplyResult TruncateInterstageVariables::Apply(const Program* src,
} }
truncated_members.Push(ctx.Clone(member->Declaration())); truncated_members.Push(ctx.Clone(member->Declaration()));
initializer_exprs.Push( initializer_exprs.Push(b.MemberAccessor("io", ctx.Clone(member->Name())));
b.MemberAccessor("io", ctx.Clone(member->Declaration()->symbol)));
} }
// Create the new shader io struct. // Create the new shader io struct.