[wgsl-reader] Update to create BlockStatements
This CL updates the WGSL Reader to create BlockStatements instead of StatementLists. Bug: tint:135 Change-Id: Ifda394023553a625dad67be7d4e0dc815292282a Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/25724 Reviewed-by: Sarah Mashayekhi <sarahmashay@google.com>
This commit is contained in:
parent
37c0970d51
commit
f751501c35
|
@ -1351,7 +1351,7 @@ ast::PipelineStage ParserImpl::pipeline_stage() {
|
|||
|
||||
// body_stmt
|
||||
// : BRACKET_LEFT statements BRACKET_RIGHT
|
||||
ast::StatementList ParserImpl::body_stmt() {
|
||||
std::unique_ptr<ast::BlockStatement> ParserImpl::body_stmt() {
|
||||
auto t = peek();
|
||||
if (!t.IsBraceLeft())
|
||||
return {};
|
||||
|
@ -1400,8 +1400,8 @@ std::unique_ptr<ast::Expression> ParserImpl::paren_rhs_stmt() {
|
|||
|
||||
// statements
|
||||
// : statement*
|
||||
ast::StatementList ParserImpl::statements() {
|
||||
ast::StatementList ret;
|
||||
std::unique_ptr<ast::BlockStatement> ParserImpl::statements() {
|
||||
auto ret = std::make_unique<ast::BlockStatement>();
|
||||
|
||||
for (;;) {
|
||||
auto stmt = statement();
|
||||
|
@ -1410,7 +1410,7 @@ ast::StatementList ParserImpl::statements() {
|
|||
if (stmt == nullptr)
|
||||
break;
|
||||
|
||||
ret.push_back(std::move(stmt));
|
||||
ret->append(std::move(stmt));
|
||||
}
|
||||
|
||||
return ret;
|
||||
|
@ -1857,8 +1857,8 @@ ast::CaseSelectorList ParserImpl::case_selectors() {
|
|||
// :
|
||||
// | statement case_body
|
||||
// | FALLTHROUGH SEMICOLON
|
||||
ast::StatementList ParserImpl::case_body() {
|
||||
ast::StatementList ret;
|
||||
std::unique_ptr<ast::BlockStatement> ParserImpl::case_body() {
|
||||
auto ret = std::make_unique<ast::BlockStatement>();
|
||||
for (;;) {
|
||||
auto t = peek();
|
||||
if (t.IsFallthrough()) {
|
||||
|
@ -1871,7 +1871,7 @@ ast::StatementList ParserImpl::case_body() {
|
|||
return {};
|
||||
}
|
||||
|
||||
ret.push_back(std::make_unique<ast::FallthroughStatement>(source));
|
||||
ret->append(std::make_unique<ast::FallthroughStatement>(source));
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -1881,7 +1881,7 @@ ast::StatementList ParserImpl::case_body() {
|
|||
if (stmt == nullptr)
|
||||
break;
|
||||
|
||||
ret.push_back(std::move(stmt));
|
||||
ret->append(std::move(stmt));
|
||||
}
|
||||
|
||||
return ret;
|
||||
|
@ -1980,10 +1980,11 @@ std::unique_ptr<ast::ContinueStatement> ParserImpl::continue_stmt() {
|
|||
|
||||
// continuing_stmt
|
||||
// : CONTINUING body_stmt
|
||||
ast::StatementList ParserImpl::continuing_stmt() {
|
||||
std::unique_ptr<ast::BlockStatement> ParserImpl::continuing_stmt() {
|
||||
auto t = peek();
|
||||
if (!t.IsContinuing())
|
||||
return {};
|
||||
if (!t.IsContinuing()) {
|
||||
return std::make_unique<ast::BlockStatement>();
|
||||
}
|
||||
|
||||
next(); // Consume the peek
|
||||
return body_stmt();
|
||||
|
|
|
@ -177,13 +177,13 @@ class ParserImpl {
|
|||
ast::PipelineStage pipeline_stage();
|
||||
/// Parses a `body_stmt` grammar element
|
||||
/// @returns the parsed statements
|
||||
ast::StatementList body_stmt();
|
||||
std::unique_ptr<ast::BlockStatement> body_stmt();
|
||||
/// Parses a `paren_rhs_stmt` grammar element
|
||||
/// @returns the parsed element or nullptr
|
||||
std::unique_ptr<ast::Expression> paren_rhs_stmt();
|
||||
/// Parses a `statements` grammar element
|
||||
/// @returns the statements parsed
|
||||
ast::StatementList statements();
|
||||
std::unique_ptr<ast::BlockStatement> statements();
|
||||
/// Parses a `statement` grammar element
|
||||
/// @returns the parsed statement or nullptr
|
||||
std::unique_ptr<ast::Statement> statement();
|
||||
|
@ -219,7 +219,7 @@ class ParserImpl {
|
|||
ast::CaseSelectorList case_selectors();
|
||||
/// Parses a `case_body` grammar element
|
||||
/// @returns the parsed statements
|
||||
ast::StatementList case_body();
|
||||
std::unique_ptr<ast::BlockStatement> case_body();
|
||||
/// Parses a `func_call_stmt` grammar element
|
||||
/// @returns the parsed function call or nullptr
|
||||
std::unique_ptr<ast::CallStatement> func_call_stmt();
|
||||
|
@ -228,7 +228,7 @@ class ParserImpl {
|
|||
std::unique_ptr<ast::LoopStatement> loop_stmt();
|
||||
/// Parses a `continuing_stmt` grammar element
|
||||
/// @returns the parsed statements
|
||||
ast::StatementList continuing_stmt();
|
||||
std::unique_ptr<ast::BlockStatement> continuing_stmt();
|
||||
/// Parses a `const_literal` grammar element
|
||||
/// @returns the const literal parsed or nullptr if none found
|
||||
std::unique_ptr<ast::Literal> const_literal();
|
||||
|
|
|
@ -28,16 +28,16 @@ TEST_F(ParserImplTest, BodyStmt) {
|
|||
})");
|
||||
auto e = p->body_stmt();
|
||||
ASSERT_FALSE(p->has_error()) << p->error();
|
||||
ASSERT_EQ(e.size(), 2u);
|
||||
EXPECT_TRUE(e[0]->IsDiscard());
|
||||
EXPECT_TRUE(e[1]->IsReturn());
|
||||
ASSERT_EQ(e->size(), 2u);
|
||||
EXPECT_TRUE(e->get(0)->IsDiscard());
|
||||
EXPECT_TRUE(e->get(1)->IsReturn());
|
||||
}
|
||||
|
||||
TEST_F(ParserImplTest, BodyStmt_Empty) {
|
||||
auto* p = parser("{}");
|
||||
auto e = p->body_stmt();
|
||||
ASSERT_FALSE(p->has_error()) << p->error();
|
||||
EXPECT_EQ(e.size(), 0u);
|
||||
EXPECT_EQ(e->size(), 0u);
|
||||
}
|
||||
|
||||
TEST_F(ParserImplTest, BodyStmt_InvalidStmt) {
|
||||
|
|
|
@ -25,7 +25,7 @@ TEST_F(ParserImplTest, CaseBody_Empty) {
|
|||
auto* p = parser("");
|
||||
auto e = p->case_body();
|
||||
ASSERT_FALSE(p->has_error()) << p->error();
|
||||
EXPECT_EQ(e.size(), 0u);
|
||||
EXPECT_EQ(e->size(), 0u);
|
||||
}
|
||||
|
||||
TEST_F(ParserImplTest, CaseBody_Statements) {
|
||||
|
@ -35,32 +35,31 @@ TEST_F(ParserImplTest, CaseBody_Statements) {
|
|||
|
||||
auto e = p->case_body();
|
||||
ASSERT_FALSE(p->has_error()) << p->error();
|
||||
ASSERT_EQ(e.size(), 2u);
|
||||
EXPECT_TRUE(e[0]->IsVariableDecl());
|
||||
EXPECT_TRUE(e[1]->IsAssign());
|
||||
ASSERT_EQ(e->size(), 2u);
|
||||
EXPECT_TRUE(e->get(0)->IsVariableDecl());
|
||||
EXPECT_TRUE(e->get(1)->IsAssign());
|
||||
}
|
||||
|
||||
TEST_F(ParserImplTest, CaseBody_InvalidStatement) {
|
||||
auto* p = parser("a =");
|
||||
auto e = p->case_body();
|
||||
ASSERT_TRUE(p->has_error());
|
||||
EXPECT_EQ(e.size(), 0u);
|
||||
EXPECT_EQ(p->error(), "1:4: unable to parse right side of assignment");
|
||||
EXPECT_EQ(e, nullptr);
|
||||
}
|
||||
|
||||
TEST_F(ParserImplTest, CaseBody_Fallthrough) {
|
||||
auto* p = parser("fallthrough;");
|
||||
auto e = p->case_body();
|
||||
ASSERT_FALSE(p->has_error()) << p->error();
|
||||
ASSERT_EQ(e.size(), 1u);
|
||||
EXPECT_TRUE(e[0]->IsFallthrough());
|
||||
ASSERT_EQ(e->size(), 1u);
|
||||
EXPECT_TRUE(e->get(0)->IsFallthrough());
|
||||
}
|
||||
|
||||
TEST_F(ParserImplTest, CaseBody_Fallthrough_MissingSemicolon) {
|
||||
auto* p = parser("fallthrough");
|
||||
auto e = p->case_body();
|
||||
ASSERT_TRUE(p->has_error());
|
||||
EXPECT_EQ(e.size(), 0u);
|
||||
EXPECT_EQ(e, nullptr);
|
||||
EXPECT_EQ(p->error(), "1:12: missing ;");
|
||||
}
|
||||
|
||||
|
|
|
@ -25,15 +25,15 @@ TEST_F(ParserImplTest, ContinuingStmt) {
|
|||
auto* p = parser("continuing { discard; }");
|
||||
auto e = p->continuing_stmt();
|
||||
ASSERT_FALSE(p->has_error()) << p->error();
|
||||
ASSERT_EQ(e.size(), 1u);
|
||||
ASSERT_TRUE(e[0]->IsDiscard());
|
||||
ASSERT_EQ(e->size(), 1u);
|
||||
ASSERT_TRUE(e->get(0)->IsDiscard());
|
||||
}
|
||||
|
||||
TEST_F(ParserImplTest, ContinuingStmt_InvalidBody) {
|
||||
auto* p = parser("continuing { discard }");
|
||||
auto e = p->continuing_stmt();
|
||||
ASSERT_TRUE(p->has_error());
|
||||
ASSERT_EQ(e.size(), 0u);
|
||||
ASSERT_EQ(e, nullptr);
|
||||
EXPECT_EQ(p->error(), "1:22: missing ;");
|
||||
}
|
||||
|
||||
|
|
|
@ -26,16 +26,16 @@ TEST_F(ParserImplTest, Statements) {
|
|||
auto* p = parser("discard; return;");
|
||||
auto e = p->statements();
|
||||
ASSERT_FALSE(p->has_error()) << p->error();
|
||||
ASSERT_EQ(e.size(), 2u);
|
||||
EXPECT_TRUE(e[0]->IsDiscard());
|
||||
EXPECT_TRUE(e[1]->IsReturn());
|
||||
ASSERT_EQ(e->size(), 2u);
|
||||
EXPECT_TRUE(e->get(0)->IsDiscard());
|
||||
EXPECT_TRUE(e->get(1)->IsReturn());
|
||||
}
|
||||
|
||||
TEST_F(ParserImplTest, Statements_Empty) {
|
||||
auto* p = parser("");
|
||||
auto e = p->statements();
|
||||
ASSERT_FALSE(p->has_error()) << p->error();
|
||||
ASSERT_EQ(e.size(), 0u);
|
||||
ASSERT_EQ(e->size(), 0u);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
|
Loading…
Reference in New Issue