mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-12-16 08:27:05 +00:00
ast: Remove Struct constructors that don't take a Source
And swap the `decorations` and `members` parameters, as decorations come last for other constructors. Parsers need fixing up. Bug: tint:396 Bug: tint:390 Change-Id: Ie9b814c1de24b6c987f0fbb9e6f92da7c352caa2 Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/35163 Commit-Queue: Ben Clayton <bclayton@google.com> Reviewed-by: dan sinclair <dsinclair@chromium.org>
This commit is contained in:
committed by
Commit Bot service account
parent
4543d1a232
commit
bcf37549c8
@@ -23,23 +23,12 @@ TINT_INSTANTIATE_CLASS_ID(tint::ast::Struct);
|
||||
namespace tint {
|
||||
namespace ast {
|
||||
|
||||
Struct::Struct(StructMemberList members)
|
||||
: Base(), members_(std::move(members)) {}
|
||||
|
||||
Struct::Struct(StructDecorationList decorations, StructMemberList members)
|
||||
: Base(),
|
||||
decorations_(std::move(decorations)),
|
||||
members_(std::move(members)) {}
|
||||
|
||||
Struct::Struct(const Source& source, StructMemberList members)
|
||||
: Base(source), members_(std::move(members)) {}
|
||||
|
||||
Struct::Struct(const Source& source,
|
||||
StructDecorationList decorations,
|
||||
StructMemberList members)
|
||||
StructMemberList members,
|
||||
StructDecorationList decorations)
|
||||
: Base(source),
|
||||
decorations_(std::move(decorations)),
|
||||
members_(std::move(members)) {}
|
||||
members_(std::move(members)),
|
||||
decorations_(std::move(decorations)) {}
|
||||
|
||||
Struct::Struct(Struct&&) = default;
|
||||
|
||||
@@ -64,8 +53,8 @@ bool Struct::IsBlockDecorated() const {
|
||||
}
|
||||
|
||||
Struct* Struct::Clone(CloneContext* ctx) const {
|
||||
return ctx->mod->create<Struct>(
|
||||
ctx->Clone(source()), ctx->Clone(decorations_), ctx->Clone(members_));
|
||||
return ctx->mod->create<Struct>(ctx->Clone(source()), ctx->Clone(members_),
|
||||
ctx->Clone(decorations_));
|
||||
}
|
||||
|
||||
bool Struct::IsValid() const {
|
||||
|
||||
@@ -29,24 +29,13 @@ namespace ast {
|
||||
/// A struct statement.
|
||||
class Struct : public Castable<Struct, Node> {
|
||||
public:
|
||||
/// Create a new struct statement
|
||||
/// @param members The struct members
|
||||
explicit Struct(StructMemberList members);
|
||||
/// Create a new struct statement
|
||||
/// @param decorations The struct decorations
|
||||
/// @param members The struct members
|
||||
Struct(StructDecorationList decorations, StructMemberList members);
|
||||
/// Create a new struct statement
|
||||
/// @param source The input source for the import statement
|
||||
/// @param members The struct members
|
||||
Struct(const Source& source, StructMemberList members);
|
||||
/// Create a new struct statement
|
||||
/// @param source The input source for the import statement
|
||||
/// @param decorations The struct decorations
|
||||
/// @param members The struct members
|
||||
Struct(const Source& source,
|
||||
StructDecorationList decorations,
|
||||
StructMemberList members);
|
||||
StructMemberList members,
|
||||
StructDecorationList decorations);
|
||||
/// Move constructor
|
||||
Struct(Struct&&);
|
||||
|
||||
@@ -85,8 +74,8 @@ class Struct : public Castable<Struct, Node> {
|
||||
private:
|
||||
Struct(const Struct&) = delete;
|
||||
|
||||
StructDecorationList decorations_;
|
||||
StructMemberList members_;
|
||||
StructDecorationList decorations_;
|
||||
};
|
||||
|
||||
} // namespace ast
|
||||
|
||||
@@ -35,7 +35,7 @@ TEST_F(StructTest, Creation) {
|
||||
members.push_back(
|
||||
create<StructMember>(Source{}, "a", &i32, StructMemberDecorationList()));
|
||||
|
||||
Struct s{members};
|
||||
Struct s{Source{}, members, ast::StructDecorationList{}};
|
||||
EXPECT_EQ(s.members().size(), 1u);
|
||||
EXPECT_TRUE(s.decorations().empty());
|
||||
EXPECT_EQ(s.source().range.begin.line, 0u);
|
||||
@@ -54,7 +54,7 @@ TEST_F(StructTest, Creation_WithDecorations) {
|
||||
StructDecorationList decos;
|
||||
decos.push_back(create<StructBlockDecoration>(Source{}));
|
||||
|
||||
Struct s{decos, members};
|
||||
Struct s{Source{}, members, decos};
|
||||
EXPECT_EQ(s.members().size(), 1u);
|
||||
ASSERT_EQ(s.decorations().size(), 1u);
|
||||
EXPECT_TRUE(s.decorations()[0]->Is<StructBlockDecoration>());
|
||||
@@ -76,7 +76,7 @@ TEST_F(StructTest, CreationWithSourceAndDecorations) {
|
||||
|
||||
Struct s{
|
||||
Source{Source::Range{Source::Location{27, 4}, Source::Location{27, 8}}},
|
||||
decos, members};
|
||||
members, decos};
|
||||
EXPECT_EQ(s.members().size(), 1u);
|
||||
ASSERT_EQ(s.decorations().size(), 1u);
|
||||
EXPECT_TRUE(s.decorations()[0]->Is<StructBlockDecoration>());
|
||||
@@ -87,7 +87,7 @@ TEST_F(StructTest, CreationWithSourceAndDecorations) {
|
||||
}
|
||||
|
||||
TEST_F(StructTest, IsValid) {
|
||||
Struct s({});
|
||||
Struct s(Source{}, StructMemberList{}, StructDecorationList{});
|
||||
EXPECT_TRUE(s.IsValid());
|
||||
}
|
||||
|
||||
@@ -99,7 +99,7 @@ TEST_F(StructTest, IsValid_Null_StructMember) {
|
||||
create<StructMember>(Source{}, "a", &i32, StructMemberDecorationList()));
|
||||
members.push_back(nullptr);
|
||||
|
||||
Struct s{members};
|
||||
Struct s{Source{}, members, ast::StructDecorationList{}};
|
||||
EXPECT_FALSE(s.IsValid());
|
||||
}
|
||||
|
||||
@@ -110,7 +110,7 @@ TEST_F(StructTest, IsValid_Invalid_StructMember) {
|
||||
members.push_back(
|
||||
create<StructMember>(Source{}, "", &i32, StructMemberDecorationList()));
|
||||
|
||||
Struct s{members};
|
||||
Struct s{Source{}, members, ast::StructDecorationList{}};
|
||||
EXPECT_FALSE(s.IsValid());
|
||||
}
|
||||
|
||||
@@ -124,7 +124,7 @@ TEST_F(StructTest, ToStr) {
|
||||
StructDecorationList decos;
|
||||
decos.push_back(create<StructBlockDecoration>(Source{}));
|
||||
|
||||
Struct s{decos, members};
|
||||
Struct s{Source{}, members, decos};
|
||||
|
||||
std::ostringstream out;
|
||||
s.to_str(out, 2);
|
||||
|
||||
@@ -134,7 +134,7 @@ TEST_F(AccessControlTest, MinBufferBindingSizeStruct) {
|
||||
|
||||
StructDecorationList decos;
|
||||
|
||||
auto* str = create<ast::Struct>(decos, members);
|
||||
auto* str = create<ast::Struct>(Source{}, members, decos);
|
||||
Struct struct_type("struct_type", str);
|
||||
AccessControl at{ast::AccessControl::kReadOnly, &struct_type};
|
||||
EXPECT_EQ(16u, at.MinBufferBindingSize(MemoryLayout::kUniformBuffer));
|
||||
@@ -179,7 +179,7 @@ TEST_F(AccessControlTest, BaseAlignmentStruct) {
|
||||
}
|
||||
StructDecorationList decos;
|
||||
|
||||
auto* str = create<ast::Struct>(decos, members);
|
||||
auto* str = create<ast::Struct>(Source{}, members, decos);
|
||||
Struct struct_type("struct_type", str);
|
||||
AccessControl at{ast::AccessControl::kReadOnly, &struct_type};
|
||||
EXPECT_EQ(16u, at.BaseAlignment(MemoryLayout::kUniformBuffer));
|
||||
|
||||
@@ -207,7 +207,7 @@ TEST_F(AliasTest, MinBufferBindingSizeStruct) {
|
||||
}
|
||||
StructDecorationList decos;
|
||||
|
||||
auto* str = create<ast::Struct>(decos, members);
|
||||
auto* str = create<ast::Struct>(Source{}, members, decos);
|
||||
Struct struct_type("struct_type", str);
|
||||
Alias alias{mod.RegisterSymbol("alias"), "alias", &struct_type};
|
||||
EXPECT_EQ(16u, alias.MinBufferBindingSize(MemoryLayout::kUniformBuffer));
|
||||
@@ -256,7 +256,7 @@ TEST_F(AliasTest, BaseAlignmentStruct) {
|
||||
}
|
||||
StructDecorationList decos;
|
||||
|
||||
auto* str = create<ast::Struct>(decos, members);
|
||||
auto* str = create<ast::Struct>(Source{}, members, decos);
|
||||
Struct struct_type("struct_type", str);
|
||||
Alias alias{mod.RegisterSymbol("alias"), "alias", &struct_type};
|
||||
EXPECT_EQ(16u, alias.BaseAlignment(MemoryLayout::kUniformBuffer));
|
||||
|
||||
@@ -41,7 +41,8 @@ using StructTest = TestHelper;
|
||||
|
||||
TEST_F(StructTest, Creation) {
|
||||
StructMemberList members;
|
||||
auto* impl = create<ast::Struct>(members);
|
||||
auto* impl =
|
||||
create<ast::Struct>(Source{}, members, ast::StructDecorationList{});
|
||||
auto* ptr = impl;
|
||||
Struct s{"S", impl};
|
||||
EXPECT_EQ(s.impl(), ptr);
|
||||
@@ -49,7 +50,8 @@ TEST_F(StructTest, Creation) {
|
||||
|
||||
TEST_F(StructTest, Is) {
|
||||
StructMemberList members;
|
||||
auto* impl = create<ast::Struct>(members);
|
||||
auto* impl =
|
||||
create<ast::Struct>(Source{}, members, ast::StructDecorationList{});
|
||||
Struct s{"S", impl};
|
||||
Type* ty = &s;
|
||||
EXPECT_FALSE(ty->Is<AccessControl>());
|
||||
@@ -69,7 +71,8 @@ TEST_F(StructTest, Is) {
|
||||
|
||||
TEST_F(StructTest, TypeName) {
|
||||
StructMemberList members;
|
||||
auto* impl = create<ast::Struct>(members);
|
||||
auto* impl =
|
||||
create<ast::Struct>(Source{}, members, ast::StructDecorationList{});
|
||||
Struct s{"my_struct", impl};
|
||||
EXPECT_EQ(s.type_name(), "__struct_my_struct");
|
||||
}
|
||||
@@ -90,7 +93,7 @@ TEST_F(StructTest, MinBufferBindingSize) {
|
||||
}
|
||||
StructDecorationList decos;
|
||||
|
||||
auto* str = create<ast::Struct>(decos, members);
|
||||
auto* str = create<ast::Struct>(Source{}, members, decos);
|
||||
Struct struct_type("struct_type", str);
|
||||
EXPECT_EQ(16u,
|
||||
struct_type.MinBufferBindingSize(MemoryLayout::kUniformBuffer));
|
||||
@@ -120,7 +123,7 @@ TEST_F(StructTest, MinBufferBindingSizeArray) {
|
||||
}
|
||||
StructDecorationList decos;
|
||||
|
||||
auto* str = create<ast::Struct>(decos, members);
|
||||
auto* str = create<ast::Struct>(Source{}, members, decos);
|
||||
Struct struct_type("struct_type", str);
|
||||
EXPECT_EQ(32u,
|
||||
struct_type.MinBufferBindingSize(MemoryLayout::kUniformBuffer));
|
||||
@@ -151,7 +154,7 @@ TEST_F(StructTest, MinBufferBindingSizeRuntimeArray) {
|
||||
}
|
||||
StructDecorationList decos;
|
||||
|
||||
auto* str = create<ast::Struct>(decos, members);
|
||||
auto* str = create<ast::Struct>(Source{}, members, decos);
|
||||
Struct struct_type("struct_type", str);
|
||||
EXPECT_EQ(12u,
|
||||
struct_type.MinBufferBindingSize(MemoryLayout::kStorageBuffer));
|
||||
@@ -169,7 +172,7 @@ TEST_F(StructTest, MinBufferBindingSizeVec2) {
|
||||
}
|
||||
StructDecorationList decos;
|
||||
|
||||
auto* str = create<ast::Struct>(decos, members);
|
||||
auto* str = create<ast::Struct>(Source{}, members, decos);
|
||||
Struct struct_type("struct_type", str);
|
||||
EXPECT_EQ(16u,
|
||||
struct_type.MinBufferBindingSize(MemoryLayout::kUniformBuffer));
|
||||
@@ -188,7 +191,7 @@ TEST_F(StructTest, MinBufferBindingSizeVec3) {
|
||||
}
|
||||
StructDecorationList decos;
|
||||
|
||||
auto* str = create<ast::Struct>(decos, members);
|
||||
auto* str = create<ast::Struct>(Source{}, members, decos);
|
||||
Struct struct_type("struct_type", str);
|
||||
EXPECT_EQ(16u,
|
||||
struct_type.MinBufferBindingSize(MemoryLayout::kUniformBuffer));
|
||||
@@ -208,7 +211,7 @@ TEST_F(StructTest, MinBufferBindingSizeVec4) {
|
||||
}
|
||||
StructDecorationList decos;
|
||||
|
||||
auto* str = create<ast::Struct>(decos, members);
|
||||
auto* str = create<ast::Struct>(Source{}, members, decos);
|
||||
Struct struct_type("struct_type", str);
|
||||
EXPECT_EQ(16u,
|
||||
struct_type.MinBufferBindingSize(MemoryLayout::kUniformBuffer));
|
||||
@@ -232,7 +235,7 @@ TEST_F(StructTest, BaseAlignment) {
|
||||
}
|
||||
StructDecorationList decos;
|
||||
|
||||
auto* str = create<ast::Struct>(decos, members);
|
||||
auto* str = create<ast::Struct>(Source{}, members, decos);
|
||||
Struct struct_type("struct_type", str);
|
||||
EXPECT_EQ(16u, struct_type.BaseAlignment(MemoryLayout::kUniformBuffer));
|
||||
EXPECT_EQ(4u, struct_type.BaseAlignment(MemoryLayout::kStorageBuffer));
|
||||
@@ -261,7 +264,7 @@ TEST_F(StructTest, BaseAlignmentArray) {
|
||||
}
|
||||
StructDecorationList decos;
|
||||
|
||||
auto* str = create<ast::Struct>(decos, members);
|
||||
auto* str = create<ast::Struct>(Source{}, members, decos);
|
||||
Struct struct_type("struct_type", str);
|
||||
EXPECT_EQ(16u, struct_type.BaseAlignment(MemoryLayout::kUniformBuffer));
|
||||
EXPECT_EQ(4u, struct_type.BaseAlignment(MemoryLayout::kStorageBuffer));
|
||||
@@ -290,7 +293,7 @@ TEST_F(StructTest, BaseAlignmentRuntimeArray) {
|
||||
}
|
||||
StructDecorationList decos;
|
||||
|
||||
auto* str = create<ast::Struct>(decos, members);
|
||||
auto* str = create<ast::Struct>(Source{}, members, decos);
|
||||
Struct struct_type("struct_type", str);
|
||||
EXPECT_EQ(4u, struct_type.BaseAlignment(MemoryLayout::kStorageBuffer));
|
||||
}
|
||||
@@ -307,7 +310,7 @@ TEST_F(StructTest, BaseAlignmentVec2) {
|
||||
}
|
||||
StructDecorationList decos;
|
||||
|
||||
auto* str = create<ast::Struct>(decos, members);
|
||||
auto* str = create<ast::Struct>(Source{}, members, decos);
|
||||
Struct struct_type("struct_type", str);
|
||||
EXPECT_EQ(16u, struct_type.BaseAlignment(MemoryLayout::kUniformBuffer));
|
||||
EXPECT_EQ(8u, struct_type.BaseAlignment(MemoryLayout::kStorageBuffer));
|
||||
@@ -325,7 +328,7 @@ TEST_F(StructTest, BaseAlignmentVec3) {
|
||||
}
|
||||
StructDecorationList decos;
|
||||
|
||||
auto* str = create<ast::Struct>(decos, members);
|
||||
auto* str = create<ast::Struct>(Source{}, members, decos);
|
||||
Struct struct_type("struct_type", str);
|
||||
EXPECT_EQ(16u, struct_type.BaseAlignment(MemoryLayout::kUniformBuffer));
|
||||
EXPECT_EQ(16u, struct_type.BaseAlignment(MemoryLayout::kStorageBuffer));
|
||||
@@ -343,7 +346,7 @@ TEST_F(StructTest, BaseAlignmentVec4) {
|
||||
}
|
||||
StructDecorationList decos;
|
||||
|
||||
auto* str = create<ast::Struct>(decos, members);
|
||||
auto* str = create<ast::Struct>(Source{}, members, decos);
|
||||
Struct struct_type("struct_type", str);
|
||||
EXPECT_EQ(16u, struct_type.BaseAlignment(MemoryLayout::kUniformBuffer));
|
||||
EXPECT_EQ(16u, struct_type.BaseAlignment(MemoryLayout::kStorageBuffer));
|
||||
|
||||
Reference in New Issue
Block a user