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

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

View File

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

View File

@@ -24,7 +24,7 @@ using TypeStructTest = TestHelper;
TEST_F(TypeStructTest, Creation) {
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 */);
EXPECT_EQ(s->Align(), 4u);
EXPECT_EQ(s->Size(), 8u);
@@ -32,9 +32,9 @@ TEST_F(TypeStructTest, Creation) {
}
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 */);
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 */);
EXPECT_TRUE(a->Equals(*a));
@@ -44,8 +44,8 @@ TEST_F(TypeStructTest, Equals) {
TEST_F(TypeStructTest, FriendlyName) {
auto name = Sym("my_struct");
auto* s = create<Struct>(Source{}, name, utils::Empty, 4u /* align */, 4u /* size */,
4u /* size_no_padding */);
auto* s =
create<Struct>(name, utils::Empty, 4u /* align */, 4u /* size */, 4u /* size_no_padding */);
EXPECT_EQ(s->FriendlyName(), "my_struct");
}
@@ -209,10 +209,10 @@ TEST_F(TypeStructTest, Clone) {
attrs_location_2.location = 2;
auto* s = create<Struct>(
Source{}, Sym("my_struct"),
utils::Vector{create<StructMember>(Source{}, Sym("b"), create<Vector>(create<F32>(), 3u),
0u, 0u, 16u, 12u, attrs_location_2),
create<StructMember>(Source{}, Sym("a"), create<I32>(), 1u, 16u, 4u, 4u,
Sym("my_struct"),
utils::Vector{create<StructMember>(Sym("b"), create<Vector>(create<F32>(), 3u), 0u, 0u, 16u,
12u, attrs_location_2),
create<StructMember>(Sym("a"), create<I32>(), 1u, 16u, 4u, 4u,
type::StructMemberAttributes{})},
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 Reference* ref_u32 =
create<Reference>(u32, builtin::AddressSpace::kPrivate, builtin::Access::kReadWrite);
const Struct* str_f32 = create<Struct>(Source{},
Sym("str_f32"),
const Struct* str_f32 = create<Struct>(Sym("str_f32"),
utils::Vector{
create<StructMember>(
/* source */ Source{},
/* name */ Sym("x"),
/* type */ f32,
/* index */ 0u,
@@ -61,11 +59,9 @@ struct TypeTest : public TestHelper {
/* align*/ 4u,
/* size*/ 4u,
/* size_no_padding*/ 4u);
const Struct* str_f16 = create<Struct>(Source{},
Sym("str_f16"),
const Struct* str_f16 = create<Struct>(Sym("str_f16"),
utils::Vector{
create<StructMember>(
/* source */ Source{},
/* name */ Sym("x"),
/* type */ f16,
/* index */ 0u,
@@ -77,11 +73,9 @@ struct TypeTest : public TestHelper {
/* align*/ 4u,
/* size*/ 4u,
/* size_no_padding*/ 4u);
Struct* str_af = create<Struct>(Source{},
Sym("str_af"),
Struct* str_af = create<Struct>(Sym("str_af"),
utils::Vector{
create<StructMember>(
/* source */ Source{},
/* name */ Sym("x"),
/* type */ af,
/* index */ 0u,