Add Source to sem::Struct
This CL adds a Source to the sem::Struct. The uses of struct->Declaration()->source now use the source stored directly on the struct. Bug: tint:1718 Change-Id: I860c67764f85d98b3f655247e18f93fa0fef9436 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/112447 Reviewed-by: Ben Clayton <bclayton@google.com> Kokoro: Kokoro <noreply+kokoro@google.com> Commit-Queue: Dan Sinclair <dsinclair@chromium.org>
This commit is contained in:
parent
8954189545
commit
f745e4e2bf
|
@ -151,7 +151,7 @@ TEST_F(ResolverInferredTypeTest, InferStruct_Pass) {
|
||||||
auto* str = Structure("S", utils::Vector{member});
|
auto* str = Structure("S", utils::Vector{member});
|
||||||
|
|
||||||
auto* expected_type =
|
auto* expected_type =
|
||||||
create<sem::Struct>(str, str->name,
|
create<sem::Struct>(str, str->source, str->name,
|
||||||
sem::StructMemberList{create<sem::StructMember>(
|
sem::StructMemberList{create<sem::StructMember>(
|
||||||
member, member->source, member->symbol, create<sem::I32>(), 0u, 0u,
|
member, member->source, member->symbol, create<sem::I32>(), 0u, 0u,
|
||||||
0u, 4u, std::nullopt)},
|
0u, 4u, std::nullopt)},
|
||||||
|
|
|
@ -823,6 +823,7 @@ sem::Struct* build_struct(ProgramBuilder& b,
|
||||||
uint32_t size_with_padding = utils::RoundUp(max_align, offset);
|
uint32_t size_with_padding = utils::RoundUp(max_align, offset);
|
||||||
return b.create<sem::Struct>(
|
return b.create<sem::Struct>(
|
||||||
/* declaration */ nullptr,
|
/* declaration */ nullptr,
|
||||||
|
/* source */ Source{},
|
||||||
/* name */ b.Sym(name),
|
/* name */ b.Sym(name),
|
||||||
/* members */ members,
|
/* members */ members,
|
||||||
/* align */ max_align,
|
/* align */ max_align,
|
||||||
|
|
|
@ -3299,7 +3299,7 @@ sem::Struct* Resolver::Structure(const ast::Struct* str) {
|
||||||
}
|
}
|
||||||
|
|
||||||
auto* out = builder_->create<sem::Struct>(
|
auto* out = builder_->create<sem::Struct>(
|
||||||
str, str->name, sem_members, static_cast<uint32_t>(struct_align),
|
str, str->source, str->name, sem_members, static_cast<uint32_t>(struct_align),
|
||||||
static_cast<uint32_t>(struct_size), static_cast<uint32_t>(size_no_padding));
|
static_cast<uint32_t>(struct_size), static_cast<uint32_t>(size_no_padding));
|
||||||
|
|
||||||
for (size_t i = 0; i < sem_members.size(); i++) {
|
for (size_t i = 0; i < sem_members.size(); i++) {
|
||||||
|
|
|
@ -446,8 +446,7 @@ bool Validator::AddressSpaceLayout(const sem::Type* store_ty,
|
||||||
|
|
||||||
// Recurse into the member type.
|
// Recurse into the member type.
|
||||||
if (!AddressSpaceLayout(m->Type(), address_space, m->Declaration()->type->source)) {
|
if (!AddressSpaceLayout(m->Type(), address_space, m->Declaration()->type->source)) {
|
||||||
AddNote("see layout of struct:\n" + str->Layout(symbols_),
|
AddNote("see layout of struct:\n" + str->Layout(symbols_), str->Source());
|
||||||
str->Declaration()->source);
|
|
||||||
note_usage();
|
note_usage();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -463,12 +462,11 @@ bool Validator::AddressSpaceLayout(const sem::Type* store_ty,
|
||||||
std::to_string(required_align) + ") on this member",
|
std::to_string(required_align) + ") on this member",
|
||||||
m->Source());
|
m->Source());
|
||||||
|
|
||||||
AddNote("see layout of struct:\n" + str->Layout(symbols_),
|
AddNote("see layout of struct:\n" + str->Layout(symbols_), str->Source());
|
||||||
str->Declaration()->source);
|
|
||||||
|
|
||||||
if (auto* member_str = m->Type()->As<sem::Struct>()) {
|
if (auto* member_str = m->Type()->As<sem::Struct>()) {
|
||||||
AddNote("and layout of struct member:\n" + member_str->Layout(symbols_),
|
AddNote("and layout of struct member:\n" + member_str->Layout(symbols_),
|
||||||
member_str->Declaration()->source);
|
member_str->Source());
|
||||||
}
|
}
|
||||||
|
|
||||||
note_usage();
|
note_usage();
|
||||||
|
@ -490,13 +488,12 @@ bool Validator::AddressSpaceLayout(const sem::Type* store_ty,
|
||||||
"'. Consider setting @align(16) on this member",
|
"'. Consider setting @align(16) on this member",
|
||||||
m->Source());
|
m->Source());
|
||||||
|
|
||||||
AddNote("see layout of struct:\n" + str->Layout(symbols_),
|
AddNote("see layout of struct:\n" + str->Layout(symbols_), str->Source());
|
||||||
str->Declaration()->source);
|
|
||||||
|
|
||||||
auto* prev_member_str = prev_member->Type()->As<sem::Struct>();
|
auto* prev_member_str = prev_member->Type()->As<sem::Struct>();
|
||||||
AddNote("and layout of previous member struct:\n" +
|
AddNote("and layout of previous member struct:\n" +
|
||||||
prev_member_str->Layout(symbols_),
|
prev_member_str->Layout(symbols_),
|
||||||
prev_member_str->Declaration()->source);
|
prev_member_str->Source());
|
||||||
note_usage();
|
note_usage();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -2017,7 +2014,7 @@ bool Validator::Alias(const ast::Alias*) const {
|
||||||
|
|
||||||
bool Validator::Structure(const sem::Struct* str, ast::PipelineStage stage) const {
|
bool Validator::Structure(const sem::Struct* str, ast::PipelineStage stage) const {
|
||||||
if (str->Members().empty()) {
|
if (str->Members().empty()) {
|
||||||
AddError("structures must have at least one member", str->Declaration()->source);
|
AddError("structures must have at least one member", str->Source());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -52,6 +52,7 @@ TypeFlags FlagsFrom(const StructMemberList& members) {
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
Struct::Struct(const ast::Struct* declaration,
|
Struct::Struct(const ast::Struct* declaration,
|
||||||
|
tint::Source source,
|
||||||
Symbol name,
|
Symbol name,
|
||||||
StructMemberList members,
|
StructMemberList members,
|
||||||
uint32_t align,
|
uint32_t align,
|
||||||
|
@ -59,6 +60,7 @@ Struct::Struct(const ast::Struct* declaration,
|
||||||
uint32_t size_no_padding)
|
uint32_t size_no_padding)
|
||||||
: Base(FlagsFrom(members)),
|
: Base(FlagsFrom(members)),
|
||||||
declaration_(declaration),
|
declaration_(declaration),
|
||||||
|
source_(source),
|
||||||
name_(name),
|
name_(name),
|
||||||
members_(std::move(members)),
|
members_(std::move(members)),
|
||||||
align_(align),
|
align_(align),
|
||||||
|
|
|
@ -57,6 +57,7 @@ class Struct final : public Castable<Struct, Type> {
|
||||||
public:
|
public:
|
||||||
/// Constructor
|
/// Constructor
|
||||||
/// @param declaration the AST structure declaration
|
/// @param declaration the AST structure declaration
|
||||||
|
/// @param source the source of the structure
|
||||||
/// @param name the name of the structure
|
/// @param name the name of the structure
|
||||||
/// @param members the structure members
|
/// @param members the structure members
|
||||||
/// @param align the byte alignment of the structure
|
/// @param align the byte alignment of the structure
|
||||||
|
@ -64,6 +65,7 @@ class Struct final : public Castable<Struct, Type> {
|
||||||
/// @param size_no_padding size of the members without the end of structure
|
/// @param size_no_padding size of the members without the end of structure
|
||||||
/// alignment padding
|
/// alignment padding
|
||||||
Struct(const ast::Struct* declaration,
|
Struct(const ast::Struct* declaration,
|
||||||
|
tint::Source source,
|
||||||
Symbol name,
|
Symbol name,
|
||||||
StructMemberList members,
|
StructMemberList members,
|
||||||
uint32_t align,
|
uint32_t align,
|
||||||
|
@ -83,6 +85,9 @@ class Struct final : public Castable<Struct, Type> {
|
||||||
/// @returns the struct
|
/// @returns the struct
|
||||||
const ast::Struct* Declaration() const { return declaration_; }
|
const ast::Struct* Declaration() const { return declaration_; }
|
||||||
|
|
||||||
|
/// @returns the source of the structure
|
||||||
|
tint::Source Source() const { return source_; }
|
||||||
|
|
||||||
/// @returns the name of the structure
|
/// @returns the name of the structure
|
||||||
Symbol Name() const { return name_; }
|
Symbol Name() const { return name_; }
|
||||||
|
|
||||||
|
@ -162,6 +167,7 @@ class Struct final : public Castable<Struct, Type> {
|
||||||
|
|
||||||
private:
|
private:
|
||||||
ast::Struct const* const declaration_;
|
ast::Struct const* const declaration_;
|
||||||
|
const tint::Source source_;
|
||||||
const Symbol name_;
|
const Symbol name_;
|
||||||
const StructMemberList members_;
|
const StructMemberList members_;
|
||||||
const uint32_t align_;
|
const uint32_t align_;
|
||||||
|
|
|
@ -26,8 +26,8 @@ TEST_F(StructTest, Creation) {
|
||||||
auto name = Sym("S");
|
auto name = Sym("S");
|
||||||
auto* impl = create<ast::Struct>(name, utils::Empty, utils::Empty);
|
auto* impl = create<ast::Struct>(name, utils::Empty, utils::Empty);
|
||||||
auto* ptr = impl;
|
auto* ptr = impl;
|
||||||
auto* s = create<sem::Struct>(impl, impl->name, StructMemberList{}, 4u /* align */,
|
auto* s = create<sem::Struct>(impl, impl->source, impl->name, StructMemberList{},
|
||||||
8u /* size */, 16u /* size_no_padding */);
|
4u /* align */, 8u /* size */, 16u /* size_no_padding */);
|
||||||
EXPECT_EQ(s->Declaration(), ptr);
|
EXPECT_EQ(s->Declaration(), ptr);
|
||||||
EXPECT_EQ(s->Align(), 4u);
|
EXPECT_EQ(s->Align(), 4u);
|
||||||
EXPECT_EQ(s->Size(), 8u);
|
EXPECT_EQ(s->Size(), 8u);
|
||||||
|
@ -36,22 +36,22 @@ TEST_F(StructTest, Creation) {
|
||||||
|
|
||||||
TEST_F(StructTest, Hash) {
|
TEST_F(StructTest, Hash) {
|
||||||
auto* a_impl = create<ast::Struct>(Sym("a"), utils::Empty, utils::Empty);
|
auto* a_impl = create<ast::Struct>(Sym("a"), utils::Empty, utils::Empty);
|
||||||
auto* a = create<sem::Struct>(a_impl, a_impl->name, StructMemberList{}, 4u /* align */,
|
auto* a = create<sem::Struct>(a_impl, a_impl->source, a_impl->name, StructMemberList{},
|
||||||
4u /* size */, 4u /* size_no_padding */);
|
4u /* align */, 4u /* size */, 4u /* size_no_padding */);
|
||||||
auto* b_impl = create<ast::Struct>(Sym("b"), utils::Empty, utils::Empty);
|
auto* b_impl = create<ast::Struct>(Sym("b"), utils::Empty, utils::Empty);
|
||||||
auto* b = create<sem::Struct>(b_impl, b_impl->name, StructMemberList{}, 4u /* align */,
|
auto* b = create<sem::Struct>(b_impl, b_impl->source, b_impl->name, StructMemberList{},
|
||||||
4u /* size */, 4u /* size_no_padding */);
|
4u /* align */, 4u /* size */, 4u /* size_no_padding */);
|
||||||
|
|
||||||
EXPECT_NE(a->Hash(), b->Hash());
|
EXPECT_NE(a->Hash(), b->Hash());
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(StructTest, Equals) {
|
TEST_F(StructTest, Equals) {
|
||||||
auto* a_impl = create<ast::Struct>(Sym("a"), utils::Empty, utils::Empty);
|
auto* a_impl = create<ast::Struct>(Sym("a"), utils::Empty, utils::Empty);
|
||||||
auto* a = create<sem::Struct>(a_impl, a_impl->name, StructMemberList{}, 4u /* align */,
|
auto* a = create<sem::Struct>(a_impl, a_impl->source, a_impl->name, StructMemberList{},
|
||||||
4u /* size */, 4u /* size_no_padding */);
|
4u /* align */, 4u /* size */, 4u /* size_no_padding */);
|
||||||
auto* b_impl = create<ast::Struct>(Sym("b"), utils::Empty, utils::Empty);
|
auto* b_impl = create<ast::Struct>(Sym("b"), utils::Empty, utils::Empty);
|
||||||
auto* b = create<sem::Struct>(b_impl, b_impl->name, StructMemberList{}, 4u /* align */,
|
auto* b = create<sem::Struct>(b_impl, b_impl->source, b_impl->name, StructMemberList{},
|
||||||
4u /* size */, 4u /* size_no_padding */);
|
4u /* align */, 4u /* size */, 4u /* size_no_padding */);
|
||||||
|
|
||||||
EXPECT_TRUE(a->Equals(*a));
|
EXPECT_TRUE(a->Equals(*a));
|
||||||
EXPECT_FALSE(a->Equals(*b));
|
EXPECT_FALSE(a->Equals(*b));
|
||||||
|
@ -61,8 +61,8 @@ TEST_F(StructTest, Equals) {
|
||||||
TEST_F(StructTest, FriendlyName) {
|
TEST_F(StructTest, FriendlyName) {
|
||||||
auto name = Sym("my_struct");
|
auto name = Sym("my_struct");
|
||||||
auto* impl = create<ast::Struct>(name, utils::Empty, utils::Empty);
|
auto* impl = create<ast::Struct>(name, utils::Empty, utils::Empty);
|
||||||
auto* s = create<sem::Struct>(impl, impl->name, StructMemberList{}, 4u /* align */,
|
auto* s = create<sem::Struct>(impl, impl->source, impl->name, StructMemberList{},
|
||||||
4u /* size */, 4u /* size_no_padding */);
|
4u /* align */, 4u /* size */, 4u /* size_no_padding */);
|
||||||
EXPECT_EQ(s->FriendlyName(Symbols()), "my_struct");
|
EXPECT_EQ(s->FriendlyName(Symbols()), "my_struct");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -45,6 +45,7 @@ struct TypeTest : public TestHelper {
|
||||||
const sem::Reference* ref_u32 =
|
const sem::Reference* ref_u32 =
|
||||||
create<Reference>(u32, ast::AddressSpace::kPrivate, ast::Access::kReadWrite);
|
create<Reference>(u32, ast::AddressSpace::kPrivate, ast::Access::kReadWrite);
|
||||||
const sem::Struct* str_f32 = create<Struct>(nullptr,
|
const sem::Struct* str_f32 = create<Struct>(nullptr,
|
||||||
|
Source{},
|
||||||
Sym("str_f32"),
|
Sym("str_f32"),
|
||||||
StructMemberList{
|
StructMemberList{
|
||||||
create<StructMember>(
|
create<StructMember>(
|
||||||
|
@ -62,6 +63,7 @@ struct TypeTest : public TestHelper {
|
||||||
/* size*/ 4u,
|
/* size*/ 4u,
|
||||||
/* size_no_padding*/ 4u);
|
/* size_no_padding*/ 4u);
|
||||||
const sem::Struct* str_f16 = create<Struct>(nullptr,
|
const sem::Struct* str_f16 = create<Struct>(nullptr,
|
||||||
|
Source{},
|
||||||
Sym("str_f16"),
|
Sym("str_f16"),
|
||||||
StructMemberList{
|
StructMemberList{
|
||||||
create<StructMember>(
|
create<StructMember>(
|
||||||
|
@ -79,6 +81,7 @@ struct TypeTest : public TestHelper {
|
||||||
/* size*/ 4u,
|
/* size*/ 4u,
|
||||||
/* size_no_padding*/ 4u);
|
/* size_no_padding*/ 4u);
|
||||||
sem::Struct* str_af = create<Struct>(nullptr,
|
sem::Struct* str_af = create<Struct>(nullptr,
|
||||||
|
Source{},
|
||||||
Sym("str_af"),
|
Sym("str_af"),
|
||||||
StructMemberList{
|
StructMemberList{
|
||||||
create<StructMember>(
|
create<StructMember>(
|
||||||
|
|
|
@ -122,8 +122,8 @@ TEST_F(CreateASTTypeForTest, AliasedArrayWithComplexOverrideLength) {
|
||||||
TEST_F(CreateASTTypeForTest, Struct) {
|
TEST_F(CreateASTTypeForTest, Struct) {
|
||||||
auto* str = create([](ProgramBuilder& b) {
|
auto* str = create([](ProgramBuilder& b) {
|
||||||
auto* decl = b.Structure("S", {});
|
auto* decl = b.Structure("S", {});
|
||||||
return b.create<sem::Struct>(decl, decl->name, sem::StructMemberList{}, 4u /* align */,
|
return b.create<sem::Struct>(decl, decl->source, decl->name, sem::StructMemberList{},
|
||||||
4u /* size */, 4u /* size_no_padding */);
|
4u /* align */, 4u /* size */, 4u /* size_no_padding */);
|
||||||
});
|
});
|
||||||
ASSERT_TRUE(str->Is<ast::TypeName>());
|
ASSERT_TRUE(str->Is<ast::TypeName>());
|
||||||
EXPECT_EQ(ast_type_builder.Symbols().NameFor(str->As<ast::TypeName>()->name), "S");
|
EXPECT_EQ(ast_type_builder.Symbols().NameFor(str->As<ast::TypeName>()->name), "S");
|
||||||
|
|
Loading…
Reference in New Issue