[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>
diff --git a/src/reader/wgsl/parser_impl.cc b/src/reader/wgsl/parser_impl.cc
index b61d721..2a9b4c9 100644
--- a/src/reader/wgsl/parser_impl.cc
+++ b/src/reader/wgsl/parser_impl.cc
@@ -1351,7 +1351,7 @@
// 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 @@
// 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 @@
if (stmt == nullptr)
break;
- ret.push_back(std::move(stmt));
+ ret->append(std::move(stmt));
}
return ret;
@@ -1857,8 +1857,8 @@
// :
// | 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 @@
return {};
}
- ret.push_back(std::make_unique<ast::FallthroughStatement>(source));
+ ret->append(std::make_unique<ast::FallthroughStatement>(source));
break;
}
@@ -1881,7 +1881,7 @@
if (stmt == nullptr)
break;
- ret.push_back(std::move(stmt));
+ ret->append(std::move(stmt));
}
return ret;
@@ -1980,10 +1980,11 @@
// 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();