mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-12-21 02:39:11 +00:00
Remove BlockStatement::insert()
Bug: tint:396 Bug: tint:390 Change-Id: I719b84804164fa801ded505ed56717948f06c7a7 Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/35502 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
db5ce658b5
commit
d408f2465a
@@ -1418,7 +1418,12 @@ Expect<ast::Builtin> ParserImpl::expect_builtin() {
|
||||
// body_stmt
|
||||
// : BRACKET_LEFT statements BRACKET_RIGHT
|
||||
Expect<ast::BlockStatement*> ParserImpl::expect_body_stmt() {
|
||||
return expect_brace_block("", [&] { return expect_statements(); });
|
||||
return expect_brace_block("", [&]() -> Expect<ast::BlockStatement*> {
|
||||
auto stmts = expect_statements();
|
||||
if (stmts.errored)
|
||||
return Failure::kErrored;
|
||||
return create<ast::BlockStatement>(Source{}, stmts.value);
|
||||
});
|
||||
}
|
||||
|
||||
// paren_rhs_stmt
|
||||
@@ -1437,7 +1442,7 @@ Expect<ast::Expression*> ParserImpl::expect_paren_rhs_stmt() {
|
||||
|
||||
// statements
|
||||
// : statement*
|
||||
Expect<ast::BlockStatement*> ParserImpl::expect_statements() {
|
||||
Expect<ast::StatementList> ParserImpl::expect_statements() {
|
||||
bool errored = false;
|
||||
ast::StatementList stmts;
|
||||
|
||||
@@ -1455,7 +1460,7 @@ Expect<ast::BlockStatement*> ParserImpl::expect_statements() {
|
||||
if (errored)
|
||||
return Failure::kErrored;
|
||||
|
||||
return create<ast::BlockStatement>(Source{}, stmts);
|
||||
return stmts;
|
||||
}
|
||||
|
||||
// statement
|
||||
@@ -1859,15 +1864,16 @@ Maybe<ast::LoopStatement*> ParserImpl::loop_stmt() {
|
||||
return Failure::kNoMatch;
|
||||
|
||||
return expect_brace_block("loop", [&]() -> Maybe<ast::LoopStatement*> {
|
||||
auto body = expect_statements();
|
||||
if (body.errored)
|
||||
auto stmts = expect_statements();
|
||||
if (stmts.errored)
|
||||
return Failure::kErrored;
|
||||
|
||||
auto continuing = continuing_stmt();
|
||||
if (continuing.errored)
|
||||
return Failure::kErrored;
|
||||
|
||||
return create<ast::LoopStatement>(source, body.value, continuing.value);
|
||||
auto* body = create<ast::BlockStatement>(source, stmts.value);
|
||||
return create<ast::LoopStatement>(source, body, continuing.value);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1958,9 +1964,9 @@ Maybe<ast::Statement*> ParserImpl::for_stmt() {
|
||||
if (header.errored)
|
||||
return Failure::kErrored;
|
||||
|
||||
auto body =
|
||||
auto stmts =
|
||||
expect_brace_block("for loop", [&] { return expect_statements(); });
|
||||
if (body.errored)
|
||||
if (stmts.errored)
|
||||
return Failure::kErrored;
|
||||
|
||||
// The for statement is a syntactic sugar on top of the loop statement.
|
||||
@@ -1980,7 +1986,7 @@ Maybe<ast::Statement*> ParserImpl::for_stmt() {
|
||||
auto* break_if_not_condition =
|
||||
create<ast::IfStatement>(not_condition->source(), not_condition,
|
||||
break_body, ast::ElseStatementList{});
|
||||
body->insert(0, break_if_not_condition);
|
||||
stmts.value.insert(stmts.value.begin(), break_if_not_condition);
|
||||
}
|
||||
|
||||
ast::BlockStatement* continuing_body = nullptr;
|
||||
@@ -1991,7 +1997,8 @@ Maybe<ast::Statement*> ParserImpl::for_stmt() {
|
||||
});
|
||||
}
|
||||
|
||||
auto* loop = create<ast::LoopStatement>(source, body.value, continuing_body);
|
||||
auto* body = create<ast::BlockStatement>(source, stmts.value);
|
||||
auto* loop = create<ast::LoopStatement>(source, body, continuing_body);
|
||||
|
||||
if (header->initializer != nullptr) {
|
||||
return create<ast::BlockStatement>(source, ast::StatementList{
|
||||
|
||||
@@ -468,7 +468,7 @@ class ParserImpl {
|
||||
Expect<ast::Expression*> expect_paren_rhs_stmt();
|
||||
/// Parses a `statements` grammar element
|
||||
/// @returns the statements parsed
|
||||
Expect<ast::BlockStatement*> expect_statements();
|
||||
Expect<ast::StatementList> expect_statements();
|
||||
/// Parses a `statement` grammar element
|
||||
/// @returns the parsed statement or nullptr
|
||||
Maybe<ast::Statement*> statement();
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
#include <string>
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
#include "src/ast/block_statement.h"
|
||||
#include "src/reader/wgsl/parser_impl.h"
|
||||
#include "src/reader/wgsl/parser_impl_test_helper.h"
|
||||
|
||||
@@ -30,15 +31,15 @@ class ForStmtTest : public ParserImplTest {
|
||||
auto e_loop = p_loop->expect_statements();
|
||||
EXPECT_FALSE(e_loop.errored);
|
||||
EXPECT_FALSE(p_loop->has_error()) << p_loop->error();
|
||||
ASSERT_NE(e_loop.value, nullptr);
|
||||
|
||||
auto p_for = parser(for_str);
|
||||
auto e_for = p_for->expect_statements();
|
||||
EXPECT_FALSE(e_for.errored);
|
||||
EXPECT_FALSE(p_for->has_error()) << p_for->error();
|
||||
ASSERT_NE(e_for.value, nullptr);
|
||||
|
||||
EXPECT_EQ(e_loop->str(), e_for->str());
|
||||
std::string loop = ast::BlockStatement({}, e_loop.value).str();
|
||||
std::string for_ = ast::BlockStatement({}, e_for.value).str();
|
||||
EXPECT_EQ(loop, for_);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -29,8 +29,8 @@ TEST_F(ParserImplTest, Statements) {
|
||||
EXPECT_FALSE(e.errored);
|
||||
EXPECT_FALSE(p->has_error()) << p->error();
|
||||
ASSERT_EQ(e->size(), 2u);
|
||||
EXPECT_TRUE(e->get(0)->Is<ast::DiscardStatement>());
|
||||
EXPECT_TRUE(e->get(1)->Is<ast::ReturnStatement>());
|
||||
EXPECT_TRUE(e.value[0]->Is<ast::DiscardStatement>());
|
||||
EXPECT_TRUE(e.value[1]->Is<ast::ReturnStatement>());
|
||||
}
|
||||
|
||||
TEST_F(ParserImplTest, Statements_Empty) {
|
||||
|
||||
Reference in New Issue
Block a user