tint/type: Remove Source from Struct & StructMember

type::Struct is the base class of sem::Struct.

type::Struct does not have a Declaration() member, so it does not make sense for it to have a Source.

Given that sem::Struct has a Declaration() method, use this to obtain the source.

Same logic applies to StructMember.

Change-Id: I693f659c35216ebe5eac5ea2a5b6457773077ddc
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/129480
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: Dan Sinclair <dsinclair@chromium.org>
Kokoro: Ben Clayton <bclayton@google.com>
This commit is contained in:
Ben Clayton 2023-04-27 19:29:45 +00:00 committed by Dawn LUCI CQ
parent bc9e422728
commit bc6720b9f6
12 changed files with 60 additions and 92 deletions

View File

@ -45,7 +45,6 @@ type::Struct* BuildStruct(ProgramBuilder& b,
offset = utils::RoundUp(align, offset); offset = utils::RoundUp(align, offset);
max_align = std::max(max_align, align); max_align = std::max(max_align, align);
members.Push(b.create<type::StructMember>( members.Push(b.create<type::StructMember>(
/* source */ Source{},
/* name */ b.Sym(m.name), /* name */ b.Sym(m.name),
/* type */ m.type, /* type */ m.type,
/* index */ static_cast<uint32_t>(members.Length()), /* index */ static_cast<uint32_t>(members.Length()),
@ -58,7 +57,6 @@ type::Struct* BuildStruct(ProgramBuilder& b,
uint32_t size_without_padding = offset; uint32_t size_without_padding = offset;
uint32_t size_with_padding = utils::RoundUp(max_align, offset); uint32_t size_with_padding = utils::RoundUp(max_align, offset);
return b.create<type::Struct>( return b.create<type::Struct>(
/* source */ Source{},
/* name */ b.Sym(name), /* name */ b.Sym(name),
/* members */ std::move(members), /* members */ std::move(members),
/* align */ max_align, /* align */ max_align,

View File

@ -150,12 +150,11 @@ TEST_F(ResolverInferredTypeTest, InferStruct_Pass) {
auto* member = Member("x", ty.i32()); auto* member = Member("x", ty.i32());
auto* str = Structure("S", utils::Vector{member}); auto* str = Structure("S", utils::Vector{member});
auto* expected_type = auto* expected_type = create<sem::Struct>(
create<sem::Struct>(str, str->source, str->name->symbol, str, str->name->symbol,
utils::Vector{create<sem::StructMember>( utils::Vector{create<sem::StructMember>(member, member->name->symbol, create<type::I32>(),
member, member->source, member->name->symbol, create<type::I32>(), 0u, 0u, 0u, 4u, type::StructMemberAttributes{})},
0u, 0u, 0u, 4u, type::StructMemberAttributes{})}, 0u, 4u, 4u);
0u, 4u, 4u);
auto* ctor_expr = Call(ty.Of(str)); auto* ctor_expr = Call(ty.Of(str));

View File

@ -4189,9 +4189,9 @@ sem::Struct* Resolver::Structure(const ast::Struct* str) {
} }
auto* sem_member = builder_->create<sem::StructMember>( auto* sem_member = builder_->create<sem::StructMember>(
member, member->source, member->name->symbol, type, member, member->name->symbol, type, static_cast<uint32_t>(sem_members.Length()),
static_cast<uint32_t>(sem_members.Length()), static_cast<uint32_t>(offset), static_cast<uint32_t>(offset), static_cast<uint32_t>(align),
static_cast<uint32_t>(align), static_cast<uint32_t>(size), attributes); static_cast<uint32_t>(size), attributes);
builder_->Sem().Add(member, sem_member); builder_->Sem().Add(member, sem_member);
sem_members.Push(sem_member); sem_members.Push(sem_member);
@ -4214,14 +4214,13 @@ sem::Struct* Resolver::Structure(const ast::Struct* str) {
} }
auto* out = builder_->create<sem::Struct>( auto* out = builder_->create<sem::Struct>(
str, str->source, str->name->symbol, std::move(sem_members), str, str->name->symbol, std::move(sem_members), static_cast<uint32_t>(struct_align),
static_cast<uint32_t>(struct_align), static_cast<uint32_t>(struct_size), static_cast<uint32_t>(struct_size), static_cast<uint32_t>(size_no_padding));
static_cast<uint32_t>(size_no_padding));
for (size_t i = 0; i < sem_members.Length(); i++) { for (size_t i = 0; i < sem_members.Length(); i++) {
auto* mem_type = sem_members[i]->Type(); auto* mem_type = sem_members[i]->Type();
if (mem_type->Is<type::Atomic>()) { if (mem_type->Is<type::Atomic>()) {
atomic_composite_info_.Add(out, &sem_members[i]->Source()); atomic_composite_info_.Add(out, &sem_members[i]->Declaration()->source);
break; break;
} else { } else {
if (auto found = atomic_composite_info_.Get(mem_type)) { if (auto found = atomic_composite_info_.Get(mem_type)) {
@ -4566,7 +4565,7 @@ bool Resolver::ApplyAddressSpaceUsageToType(builtin::AddressSpace address_space,
utils::StringStream err; utils::StringStream err;
err << "while analyzing structure member " << sem_.TypeNameOf(str) << "." err << "while analyzing structure member " << sem_.TypeNameOf(str) << "."
<< member->Name().Name(); << member->Name().Name();
AddNote(err.str(), member->Source()); AddNote(err.str(), member->Declaration()->source);
return false; return false;
} }
} }

View File

@ -445,7 +445,7 @@ bool Validator::AddressSpaceLayout(const type::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(), str->Source()); AddNote("see layout of struct:\n" + str->Layout(), str->Declaration()->source);
note_usage(); note_usage();
return false; return false;
} }
@ -461,13 +461,13 @@ bool Validator::AddressSpaceLayout(const type::Type* store_ty,
"' is currently at offset " + std::to_string(m->Offset()) + "' is currently at offset " + std::to_string(m->Offset()) +
". Consider setting @align(" + std::to_string(required_align) + ". Consider setting @align(" + std::to_string(required_align) +
") on this member", ") on this member",
m->Source()); m->Declaration()->source);
AddNote("see layout of struct:\n" + str->Layout(), str->Source()); AddNote("see layout of struct:\n" + str->Layout(), 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(), AddNote("and layout of struct member:\n" + member_str->Layout(),
member_str->Source()); member_str->Declaration()->source);
} }
note_usage(); note_usage();
@ -483,19 +483,19 @@ bool Validator::AddressSpaceLayout(const type::Type* store_ty,
!enabled_extensions_.Contains( !enabled_extensions_.Contains(
builtin::Extension::kChromiumInternalRelaxedUniformLayout)) { builtin::Extension::kChromiumInternalRelaxedUniformLayout)) {
AddError( AddError(
"uniform storage requires that the number of bytes between the " "uniform storage requires that the number of bytes between the start of "
"start of the previous member of type struct and the current " "the previous member of type struct and the current member be a multiple "
"member be a multiple of 16 bytes, but there are currently " + "of 16 bytes, but there are currently " +
std::to_string(prev_to_curr_offset) + " bytes between '" + std::to_string(prev_to_curr_offset) + " bytes between '" +
member_name_of(prev_member) + "' and '" + member_name_of(m) + member_name_of(prev_member) + "' and '" + member_name_of(m) +
"'. Consider setting @align(16) on this member", "'. Consider setting @align(16) on this member",
m->Source()); m->Declaration()->source);
AddNote("see layout of struct:\n" + str->Layout(), str->Source()); AddNote("see layout of struct:\n" + str->Layout(), 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" + prev_member_str->Layout(), AddNote("and layout of previous member struct:\n" + prev_member_str->Layout(),
prev_member_str->Source()); prev_member_str->Declaration()->source);
note_usage(); note_usage();
return false; return false;
} }
@ -1213,8 +1213,8 @@ bool Validator::EntryPoint(const sem::Function* func, ast::PipelineStage stage)
if (auto* str = ty->As<sem::Struct>()) { if (auto* str = ty->As<sem::Struct>()) {
for (auto* member : str->Members()) { for (auto* member : str->Members()) {
if (!validate_entry_point_attributes_inner( if (!validate_entry_point_attributes_inner(
member->Declaration()->attributes, member->Type(), member->Source(), member->Declaration()->attributes, member->Type(),
param_or_ret, member->Declaration()->source, param_or_ret,
/*is_struct_member*/ true, member->Attributes().location)) { /*is_struct_member*/ true, member->Attributes().location)) {
AddNote("while analyzing entry point '" + decl->name->symbol.Name() + "'", AddNote("while analyzing entry point '" + decl->name->symbol.Name() + "'",
decl->source); decl->source);
@ -2066,7 +2066,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().IsEmpty()) { if (str->Members().IsEmpty()) {
AddError("structures must have at least one member", str->Source()); AddError("structures must have at least one member", str->Declaration()->source);
return false; return false;
} }
@ -2076,7 +2076,7 @@ bool Validator::Structure(const sem::Struct* str, ast::PipelineStage stage) cons
if (r->Count()->Is<type::RuntimeArrayCount>()) { if (r->Count()->Is<type::RuntimeArrayCount>()) {
if (member != str->Members().Back()) { if (member != str->Members().Back()) {
AddError("runtime arrays may only appear as the last member of a struct", AddError("runtime arrays may only appear as the last member of a struct",
member->Source()); member->Declaration()->source);
return false; return false;
} }
} }
@ -2088,7 +2088,7 @@ bool Validator::Structure(const sem::Struct* str, ast::PipelineStage stage) cons
} else if (!IsFixedFootprint(member->Type())) { } else if (!IsFixedFootprint(member->Type())) {
AddError( AddError(
"a struct that contains a runtime array cannot be nested inside another struct", "a struct that contains a runtime array cannot be nested inside another struct",
member->Source()); member->Declaration()->source);
return false; return false;
} }
@ -2107,7 +2107,8 @@ bool Validator::Structure(const sem::Struct* str, ast::PipelineStage stage) cons
has_location = true; has_location = true;
TINT_ASSERT(Resolver, member->Attributes().location.has_value()); TINT_ASSERT(Resolver, member->Attributes().location.has_value());
if (!LocationAttribute(location, member->Attributes().location.value(), if (!LocationAttribute(location, member->Attributes().location.value(),
member->Type(), locations, stage, member->Source())) { member->Type(), locations, stage,
member->Declaration()->source)) {
return false; return false;
} }
return true; return true;

View File

@ -22,20 +22,18 @@ TINT_INSTANTIATE_TYPEINFO(tint::sem::StructMember);
namespace tint::sem { namespace tint::sem {
Struct::Struct(const ast::Struct* declaration, Struct::Struct(const ast::Struct* declaration,
tint::Source source,
Symbol name, Symbol name,
utils::VectorRef<const StructMember*> members, utils::VectorRef<const StructMember*> members,
uint32_t align, uint32_t align,
uint32_t size, uint32_t size,
uint32_t size_no_padding) uint32_t size_no_padding)
: Base(source, name, members, align, size, size_no_padding), declaration_(declaration) { : Base(name, members, align, size, size_no_padding), declaration_(declaration) {
TINT_ASSERT(Semantic, declaration != nullptr); TINT_ASSERT(Semantic, declaration != nullptr);
} }
Struct::~Struct() = default; Struct::~Struct() = default;
StructMember::StructMember(const ast::StructMember* declaration, StructMember::StructMember(const ast::StructMember* declaration,
tint::Source source,
Symbol name, Symbol name,
const type::Type* type, const type::Type* type,
uint32_t index, uint32_t index,
@ -43,7 +41,7 @@ StructMember::StructMember(const ast::StructMember* declaration,
uint32_t align, uint32_t align,
uint32_t size, uint32_t size,
const type::StructMemberAttributes& attributes) const type::StructMemberAttributes& attributes)
: Base(source, name, type, index, offset, align, size, attributes), declaration_(declaration) { : Base(name, type, index, offset, align, size, attributes), declaration_(declaration) {
TINT_ASSERT(Semantic, declaration != nullptr); TINT_ASSERT(Semantic, declaration != nullptr);
} }

View File

@ -43,14 +43,12 @@ class Struct final : public utils::Castable<Struct, type::Struct> {
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
/// @param size the byte size of the structure /// @param size the byte size of the structure
/// @param size_no_padding size of the members without the end of structure alignment padding /// @param size_no_padding size of the members without the end of structure alignment padding
Struct(const ast::Struct* declaration, Struct(const ast::Struct* declaration,
tint::Source source,
Symbol name, Symbol name,
utils::VectorRef<const StructMember*> members, utils::VectorRef<const StructMember*> members,
uint32_t align, uint32_t align,
@ -78,7 +76,6 @@ class StructMember final : public utils::Castable<StructMember, type::StructMemb
public: public:
/// Constructor /// Constructor
/// @param declaration the AST declaration node /// @param declaration the AST declaration node
/// @param source the source of the struct member
/// @param name the name of the structure member /// @param name the name of the structure member
/// @param type the type of the member /// @param type the type of the member
/// @param index the index of the member in the structure /// @param index the index of the member in the structure
@ -87,7 +84,6 @@ class StructMember final : public utils::Castable<StructMember, type::StructMemb
/// @param size the byte size of the member /// @param size the byte size of the member
/// @param attributes the optional attributes /// @param attributes the optional attributes
StructMember(const ast::StructMember* declaration, StructMember(const ast::StructMember* declaration,
tint::Source source,
Symbol name, Symbol name,
const type::Type* type, const type::Type* type,
uint32_t index, uint32_t index,

View File

@ -26,8 +26,8 @@ TEST_F(SemStructTest, Creation) {
auto name = Sym("S"); auto name = Sym("S");
auto* impl = create<ast::Struct>(Ident(name), utils::Empty, utils::Empty); auto* impl = create<ast::Struct>(Ident(name), utils::Empty, utils::Empty);
auto* ptr = impl; auto* ptr = impl;
auto* s = create<sem::Struct>(impl, impl->source, impl->name->symbol, utils::Empty, auto* s = create<sem::Struct>(impl, impl->name->symbol, utils::Empty, 4u /* align */,
4u /* align */, 8u /* size */, 16u /* size_no_padding */); 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,11 +36,11 @@ TEST_F(SemStructTest, Creation) {
TEST_F(SemStructTest, Equals) { TEST_F(SemStructTest, Equals) {
auto* a_impl = create<ast::Struct>(Ident("a"), utils::Empty, utils::Empty); auto* a_impl = create<ast::Struct>(Ident("a"), utils::Empty, utils::Empty);
auto* a = create<sem::Struct>(a_impl, a_impl->source, a_impl->name->symbol, utils::Empty, auto* a = create<sem::Struct>(a_impl, a_impl->name->symbol, utils::Empty, 4u /* align */,
4u /* align */, 4u /* size */, 4u /* size_no_padding */); 4u /* size */, 4u /* size_no_padding */);
auto* b_impl = create<ast::Struct>(Ident("b"), utils::Empty, utils::Empty); auto* b_impl = create<ast::Struct>(Ident("b"), utils::Empty, utils::Empty);
auto* b = create<sem::Struct>(b_impl, b_impl->source, b_impl->name->symbol, utils::Empty, auto* b = create<sem::Struct>(b_impl, b_impl->name->symbol, utils::Empty, 4u /* align */,
4u /* align */, 4u /* size */, 4u /* size_no_padding */); 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));
@ -50,8 +50,8 @@ TEST_F(SemStructTest, Equals) {
TEST_F(SemStructTest, FriendlyName) { TEST_F(SemStructTest, FriendlyName) {
auto name = Sym("my_struct"); auto name = Sym("my_struct");
auto* impl = create<ast::Struct>(Ident(name), utils::Empty, utils::Empty); auto* impl = create<ast::Struct>(Ident(name), utils::Empty, utils::Empty);
auto* s = create<sem::Struct>(impl, impl->source, impl->name->symbol, utils::Empty, auto* s = create<sem::Struct>(impl, impl->name->symbol, utils::Empty, 4u /* align */,
4u /* align */, 4u /* size */, 4u /* size_no_padding */); 4u /* size */, 4u /* size_no_padding */);
EXPECT_EQ(s->FriendlyName(), "my_struct"); EXPECT_EQ(s->FriendlyName(), "my_struct");
} }

View File

@ -120,8 +120,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->source, decl->name->symbol, utils::Empty, return b.create<sem::Struct>(decl, decl->name->symbol, utils::Empty, 4u /* align */,
4u /* align */, 4u /* size */, 4u /* size_no_padding */); 4u /* size */, 4u /* size_no_padding */);
}); });
ast::CheckIdentifier(str, "S"); ast::CheckIdentifier(str, "S");

View File

@ -52,14 +52,12 @@ type::Flags FlagsFrom(utils::VectorRef<const StructMember*> members) {
} // namespace } // namespace
Struct::Struct(tint::Source source, Struct::Struct(Symbol name,
Symbol name,
utils::VectorRef<const StructMember*> members, utils::VectorRef<const StructMember*> members,
uint32_t align, uint32_t align,
uint32_t size, uint32_t size,
uint32_t size_no_padding) uint32_t size_no_padding)
: Base(utils::Hash(utils::TypeInfo::Of<Struct>().full_hashcode, name), FlagsFrom(members)), : Base(utils::Hash(utils::TypeInfo::Of<Struct>().full_hashcode, name), FlagsFrom(members)),
source_(source),
name_(name), name_(name),
members_(std::move(members)), members_(std::move(members)),
align_(align), align_(align),
@ -169,19 +167,17 @@ Struct* Struct::Clone(CloneContext& ctx) const {
for (const auto& mem : members_) { for (const auto& mem : members_) {
members.Push(mem->Clone(ctx)); members.Push(mem->Clone(ctx));
} }
return ctx.dst.mgr->Get<Struct>(source_, sym, members, align_, size_, size_no_padding_); return ctx.dst.mgr->Get<Struct>(sym, members, align_, size_, size_no_padding_);
} }
StructMember::StructMember(tint::Source source, StructMember::StructMember(Symbol name,
Symbol name,
const type::Type* type, const type::Type* type,
uint32_t index, uint32_t index,
uint32_t offset, uint32_t offset,
uint32_t align, uint32_t align,
uint32_t size, uint32_t size,
const StructMemberAttributes& attributes) const StructMemberAttributes& attributes)
: source_(source), : name_(name),
name_(name),
type_(type), type_(type),
index_(index), index_(index),
offset_(offset), offset_(offset),
@ -194,8 +190,7 @@ StructMember::~StructMember() = default;
StructMember* StructMember::Clone(CloneContext& ctx) const { StructMember* StructMember::Clone(CloneContext& ctx) const {
auto sym = ctx.dst.st->Register(name_.Name()); auto sym = ctx.dst.st->Register(name_.Name());
auto* ty = type_->Clone(ctx); auto* ty = type_->Clone(ctx);
return ctx.dst.mgr->Get<StructMember>(source_, sym, ty, index_, offset_, align_, size_, return ctx.dst.mgr->Get<StructMember>(sym, ty, index_, offset_, align_, size_, attributes_);
attributes_);
} }
} // namespace tint::type } // namespace tint::type

View File

@ -49,15 +49,13 @@ enum class PipelineStageUsage {
class Struct : public utils::Castable<Struct, Type> { class Struct : public utils::Castable<Struct, Type> {
public: public:
/// Constructor /// Constructor
/// @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
/// @param size the byte size of the structure /// @param size the byte size of the structure
/// @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(tint::Source source, Struct(Symbol name,
Symbol name,
utils::VectorRef<const StructMember*> members, utils::VectorRef<const StructMember*> members,
uint32_t align, uint32_t align,
uint32_t size, uint32_t size,
@ -70,9 +68,6 @@ class Struct : public utils::Castable<Struct, Type> {
/// @returns true if the this type is equal to @p other /// @returns true if the this type is equal to @p other
bool Equals(const UniqueNode& other) const override; bool Equals(const UniqueNode& other) const override;
/// @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_; }
@ -153,7 +148,6 @@ class Struct : public utils::Castable<Struct, Type> {
Struct* Clone(CloneContext& ctx) const override; Struct* Clone(CloneContext& ctx) const override;
private: private:
const tint::Source source_;
const Symbol name_; const Symbol name_;
const utils::Vector<const StructMember*, 4> members_; const utils::Vector<const StructMember*, 4> members_;
const uint32_t align_; const uint32_t align_;
@ -180,7 +174,6 @@ struct StructMemberAttributes {
class StructMember : public utils::Castable<StructMember, Node> { class StructMember : public utils::Castable<StructMember, Node> {
public: public:
/// Constructor /// Constructor
/// @param source the source of the struct member
/// @param name the name of the structure member /// @param name the name of the structure member
/// @param type the type of the member /// @param type the type of the member
/// @param index the index of the member in the structure /// @param index the index of the member in the structure
@ -188,8 +181,7 @@ class StructMember : public utils::Castable<StructMember, Node> {
/// @param align the byte alignment of the member /// @param align the byte alignment of the member
/// @param size the byte size of the member /// @param size the byte size of the member
/// @param attributes the optional attributes /// @param attributes the optional attributes
StructMember(tint::Source source, StructMember(Symbol name,
Symbol name,
const type::Type* type, const type::Type* type,
uint32_t index, uint32_t index,
uint32_t offset, uint32_t offset,
@ -200,9 +192,6 @@ class StructMember : public utils::Castable<StructMember, Node> {
/// Destructor /// Destructor
~StructMember() override; ~StructMember() override;
/// @returns the source the struct member
const tint::Source& Source() const { return source_; }
/// @returns the name of the structure member /// @returns the name of the structure member
Symbol Name() const { return name_; } Symbol Name() const { return name_; }
@ -236,7 +225,6 @@ class StructMember : public utils::Castable<StructMember, Node> {
StructMember* Clone(CloneContext& ctx) const; StructMember* Clone(CloneContext& ctx) const;
private: private:
const tint::Source source_;
const Symbol name_; const Symbol name_;
const type::Struct* struct_; const type::Struct* struct_;
const type::Type* type_; const type::Type* type_;

View File

@ -24,7 +24,7 @@ using TypeStructTest = TestHelper;
TEST_F(TypeStructTest, Creation) { TEST_F(TypeStructTest, Creation) {
auto name = Sym("S"); auto name = Sym("S");
auto* s = create<Struct>(Source{}, name, utils::Empty, 4u /* align */, 8u /* size */, auto* s = create<Struct>(name, utils::Empty, 4u /* align */, 8u /* size */,
16u /* size_no_padding */); 16u /* size_no_padding */);
EXPECT_EQ(s->Align(), 4u); EXPECT_EQ(s->Align(), 4u);
EXPECT_EQ(s->Size(), 8u); EXPECT_EQ(s->Size(), 8u);
@ -32,9 +32,9 @@ TEST_F(TypeStructTest, Creation) {
} }
TEST_F(TypeStructTest, Equals) { TEST_F(TypeStructTest, Equals) {
auto* a = create<Struct>(Source{}, Sym("a"), utils::Empty, 4u /* align */, 4u /* size */, auto* a = create<Struct>(Sym("a"), utils::Empty, 4u /* align */, 4u /* size */,
4u /* size_no_padding */); 4u /* size_no_padding */);
auto* b = create<Struct>(Source{}, Sym("b"), utils::Empty, 4u /* align */, 4u /* size */, auto* b = create<Struct>(Sym("b"), utils::Empty, 4u /* align */, 4u /* size */,
4u /* size_no_padding */); 4u /* size_no_padding */);
EXPECT_TRUE(a->Equals(*a)); EXPECT_TRUE(a->Equals(*a));
@ -44,8 +44,8 @@ TEST_F(TypeStructTest, Equals) {
TEST_F(TypeStructTest, FriendlyName) { TEST_F(TypeStructTest, FriendlyName) {
auto name = Sym("my_struct"); auto name = Sym("my_struct");
auto* s = create<Struct>(Source{}, name, utils::Empty, 4u /* align */, 4u /* size */, auto* s =
4u /* size_no_padding */); create<Struct>(name, utils::Empty, 4u /* align */, 4u /* size */, 4u /* size_no_padding */);
EXPECT_EQ(s->FriendlyName(), "my_struct"); EXPECT_EQ(s->FriendlyName(), "my_struct");
} }
@ -209,10 +209,10 @@ TEST_F(TypeStructTest, Clone) {
attrs_location_2.location = 2; attrs_location_2.location = 2;
auto* s = create<Struct>( auto* s = create<Struct>(
Source{}, Sym("my_struct"), Sym("my_struct"),
utils::Vector{create<StructMember>(Source{}, Sym("b"), create<Vector>(create<F32>(), 3u), utils::Vector{create<StructMember>(Sym("b"), create<Vector>(create<F32>(), 3u), 0u, 0u, 16u,
0u, 0u, 16u, 12u, attrs_location_2), 12u, attrs_location_2),
create<StructMember>(Source{}, Sym("a"), create<I32>(), 1u, 16u, 4u, 4u, create<StructMember>(Sym("a"), create<I32>(), 1u, 16u, 4u, 4u,
type::StructMemberAttributes{})}, type::StructMemberAttributes{})},
4u /* align */, 8u /* size */, 16u /* size_no_padding */); 4u /* align */, 8u /* size */, 16u /* size_no_padding */);

View File

@ -45,11 +45,9 @@ struct TypeTest : public TestHelper {
const Matrix* mat4x3_af = create<Matrix>(vec3_af, 4u); const Matrix* mat4x3_af = create<Matrix>(vec3_af, 4u);
const Reference* ref_u32 = const Reference* ref_u32 =
create<Reference>(u32, builtin::AddressSpace::kPrivate, builtin::Access::kReadWrite); create<Reference>(u32, builtin::AddressSpace::kPrivate, builtin::Access::kReadWrite);
const Struct* str_f32 = create<Struct>(Source{}, const Struct* str_f32 = create<Struct>(Sym("str_f32"),
Sym("str_f32"),
utils::Vector{ utils::Vector{
create<StructMember>( create<StructMember>(
/* source */ Source{},
/* name */ Sym("x"), /* name */ Sym("x"),
/* type */ f32, /* type */ f32,
/* index */ 0u, /* index */ 0u,
@ -61,11 +59,9 @@ struct TypeTest : public TestHelper {
/* align*/ 4u, /* align*/ 4u,
/* size*/ 4u, /* size*/ 4u,
/* size_no_padding*/ 4u); /* size_no_padding*/ 4u);
const Struct* str_f16 = create<Struct>(Source{}, const Struct* str_f16 = create<Struct>(Sym("str_f16"),
Sym("str_f16"),
utils::Vector{ utils::Vector{
create<StructMember>( create<StructMember>(
/* source */ Source{},
/* name */ Sym("x"), /* name */ Sym("x"),
/* type */ f16, /* type */ f16,
/* index */ 0u, /* index */ 0u,
@ -77,11 +73,9 @@ struct TypeTest : public TestHelper {
/* align*/ 4u, /* align*/ 4u,
/* size*/ 4u, /* size*/ 4u,
/* size_no_padding*/ 4u); /* size_no_padding*/ 4u);
Struct* str_af = create<Struct>(Source{}, Struct* str_af = create<Struct>(Sym("str_af"),
Sym("str_af"),
utils::Vector{ utils::Vector{
create<StructMember>( create<StructMember>(
/* source */ Source{},
/* name */ Sym("x"), /* name */ Sym("x"),
/* type */ af, /* type */ af,
/* index */ 0u, /* index */ 0u,