[wgsl-parser] Consume empty struct closing brace.
This CL updates the WGSL parser to consume the closing } of an empty struct. Bug: tint:218 Change-Id: I0b17d2178b1b4b7f44fcf007da867db07dc2a6ae Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/27600 Reviewed-by: Sarah Mashayekhi <sarahmashay@google.com> Commit-Queue: dan sinclair <dsinclair@chromium.org>
This commit is contained in:
parent
5f915f1f92
commit
46252ec3ba
|
@ -1021,12 +1021,6 @@ std::unique_ptr<ast::type::StructType> ParserImpl::struct_decl() {
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
t = peek();
|
||||
if (!t.IsBraceLeft()) {
|
||||
set_error(t, "missing { for struct declaration");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
auto body = struct_body_decl();
|
||||
if (has_error()) {
|
||||
return nullptr;
|
||||
|
@ -1075,14 +1069,17 @@ ast::StructDecoration ParserImpl::struct_decoration(Token t) {
|
|||
// : BRACKET_LEFT struct_member* BRACKET_RIGHT
|
||||
ast::StructMemberList ParserImpl::struct_body_decl() {
|
||||
auto t = peek();
|
||||
if (!t.IsBraceLeft())
|
||||
if (!t.IsBraceLeft()) {
|
||||
set_error(t, "missing { for struct declaration");
|
||||
return {};
|
||||
|
||||
}
|
||||
next(); // Consume the peek
|
||||
|
||||
t = peek();
|
||||
if (t.IsBraceRight())
|
||||
if (t.IsBraceRight()) {
|
||||
next(); // Consume the peek
|
||||
return {};
|
||||
}
|
||||
|
||||
ast::StructMemberList members;
|
||||
for (;;) {
|
||||
|
|
|
@ -109,6 +109,24 @@ TEST_F(ParserImplTest, TypeDecl_Struct_WithStride) {
|
|||
EXPECT_EQ(arr->array_stride(), 4u);
|
||||
}
|
||||
|
||||
// This was failing due to not finding the missing ;. https://crbug.com/tint/218
|
||||
TEST_F(ParserImplTest, TypeDecl_Struct_Empty) {
|
||||
auto* p = parser("type str = struct {};");
|
||||
p->global_decl();
|
||||
ASSERT_FALSE(p->has_error()) << p->error();
|
||||
|
||||
auto module = p->module();
|
||||
ASSERT_EQ(module.alias_types().size(), 1u);
|
||||
|
||||
auto* t = module.alias_types()[0];
|
||||
ASSERT_NE(t, nullptr);
|
||||
EXPECT_EQ(t->name(), "str");
|
||||
|
||||
ASSERT_TRUE(t->type()->IsStruct());
|
||||
auto* s = t->type()->AsStruct();
|
||||
EXPECT_EQ(s->impl()->members().size(), 0u);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
} // namespace wgsl
|
||||
} // namespace reader
|
||||
|
|
Loading…
Reference in New Issue