mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-12-21 18:59:21 +00:00
Remove conditional break/continue.
This CL removes the conditional forms of the break and continue statements as they are no longer in the WGSL spec. Change-Id: I46224d6cb5ce706cfc95d35ab0a4eea46abf62a9 Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/22580 Reviewed-by: Ryan Harrison <rharrison@chromium.org>
This commit is contained in:
@@ -41,7 +41,6 @@
|
||||
#include "src/ast/scalar_constructor_expression.h"
|
||||
#include "src/ast/set_decoration.h"
|
||||
#include "src/ast/sint_literal.h"
|
||||
#include "src/ast/statement_condition.h"
|
||||
#include "src/ast/struct_member_offset_decoration.h"
|
||||
#include "src/ast/switch_statement.h"
|
||||
#include "src/ast/type/alias_type.h"
|
||||
@@ -1943,73 +1942,25 @@ std::unique_ptr<ast::LoopStatement> ParserImpl::loop_stmt() {
|
||||
}
|
||||
|
||||
// break_stmt
|
||||
// : BREAK ({IF | UNLESS} paren_rhs_stmt)?
|
||||
// : BREAK
|
||||
std::unique_ptr<ast::BreakStatement> ParserImpl::break_stmt() {
|
||||
auto t = peek();
|
||||
if (!t.IsBreak())
|
||||
return nullptr;
|
||||
|
||||
auto source = t.source();
|
||||
next(); // Consume the peek
|
||||
|
||||
ast::StatementCondition condition = ast::StatementCondition::kNone;
|
||||
std::unique_ptr<ast::Expression> conditional = nullptr;
|
||||
|
||||
t = peek();
|
||||
if (t.IsIf() || t.IsUnless()) {
|
||||
next(); // Consume the peek
|
||||
|
||||
if (t.IsIf())
|
||||
condition = ast::StatementCondition::kIf;
|
||||
else
|
||||
condition = ast::StatementCondition::kUnless;
|
||||
|
||||
conditional = paren_rhs_stmt();
|
||||
if (has_error())
|
||||
return nullptr;
|
||||
if (conditional == nullptr) {
|
||||
set_error(peek(), "unable to parse conditional statement");
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
return std::make_unique<ast::BreakStatement>(source, condition,
|
||||
std::move(conditional));
|
||||
return std::make_unique<ast::BreakStatement>(t.source());
|
||||
}
|
||||
|
||||
// continue_stmt
|
||||
// : CONTINUE ({IF | UNLESS} paren_rhs_stmt)?
|
||||
// : CONTINUE
|
||||
std::unique_ptr<ast::ContinueStatement> ParserImpl::continue_stmt() {
|
||||
auto t = peek();
|
||||
if (!t.IsContinue())
|
||||
return nullptr;
|
||||
|
||||
auto source = t.source();
|
||||
next(); // Consume the peek
|
||||
|
||||
ast::StatementCondition condition = ast::StatementCondition::kNone;
|
||||
std::unique_ptr<ast::Expression> conditional = nullptr;
|
||||
|
||||
t = peek();
|
||||
if (t.IsIf() || t.IsUnless()) {
|
||||
next(); // Consume the peek
|
||||
|
||||
if (t.IsIf())
|
||||
condition = ast::StatementCondition::kIf;
|
||||
else
|
||||
condition = ast::StatementCondition::kUnless;
|
||||
|
||||
conditional = paren_rhs_stmt();
|
||||
if (has_error())
|
||||
return nullptr;
|
||||
if (conditional == nullptr) {
|
||||
set_error(peek(), "unable to parse conditional statement");
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
return std::make_unique<ast::ContinueStatement>(source, condition,
|
||||
std::move(conditional));
|
||||
return std::make_unique<ast::ContinueStatement>(t.source());
|
||||
}
|
||||
|
||||
// continuing_stmt
|
||||
|
||||
@@ -14,8 +14,6 @@
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
#include "src/ast/break_statement.h"
|
||||
#include "src/ast/return_statement.h"
|
||||
#include "src/ast/statement.h"
|
||||
#include "src/reader/wgsl/parser_impl.h"
|
||||
#include "src/reader/wgsl/parser_impl_test_helper.h"
|
||||
|
||||
@@ -30,46 +28,6 @@ TEST_F(ParserImplTest, BreakStmt) {
|
||||
ASSERT_FALSE(p->has_error()) << p->error();
|
||||
ASSERT_NE(e, nullptr);
|
||||
ASSERT_TRUE(e->IsBreak());
|
||||
EXPECT_EQ(e->condition(), ast::StatementCondition::kNone);
|
||||
EXPECT_EQ(e->conditional(), nullptr);
|
||||
}
|
||||
|
||||
TEST_F(ParserImplTest, BreakStmt_WithIf) {
|
||||
auto* p = parser("break if (a == b)");
|
||||
auto e = p->break_stmt();
|
||||
ASSERT_FALSE(p->has_error()) << p->error();
|
||||
ASSERT_NE(e, nullptr);
|
||||
ASSERT_TRUE(e->IsBreak());
|
||||
EXPECT_EQ(e->condition(), ast::StatementCondition::kIf);
|
||||
ASSERT_NE(e->conditional(), nullptr);
|
||||
EXPECT_TRUE(e->conditional()->IsBinary());
|
||||
}
|
||||
|
||||
TEST_F(ParserImplTest, BreakStmt_WithUnless) {
|
||||
auto* p = parser("break unless (a == b)");
|
||||
auto e = p->break_stmt();
|
||||
ASSERT_FALSE(p->has_error()) << p->error();
|
||||
ASSERT_NE(e, nullptr);
|
||||
ASSERT_TRUE(e->IsBreak());
|
||||
EXPECT_EQ(e->condition(), ast::StatementCondition::kUnless);
|
||||
ASSERT_NE(e->conditional(), nullptr);
|
||||
EXPECT_TRUE(e->conditional()->IsBinary());
|
||||
}
|
||||
|
||||
TEST_F(ParserImplTest, BreakStmt_InvalidRHS) {
|
||||
auto* p = parser("break if (a = b)");
|
||||
auto e = p->break_stmt();
|
||||
ASSERT_TRUE(p->has_error());
|
||||
ASSERT_EQ(e, nullptr);
|
||||
EXPECT_EQ(p->error(), "1:13: expected )");
|
||||
}
|
||||
|
||||
TEST_F(ParserImplTest, BreakStmt_MissingRHS) {
|
||||
auto* p = parser("break if");
|
||||
auto e = p->break_stmt();
|
||||
ASSERT_TRUE(p->has_error());
|
||||
ASSERT_EQ(e, nullptr);
|
||||
EXPECT_EQ(p->error(), "1:9: expected (");
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
@@ -14,8 +14,6 @@
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
#include "src/ast/continue_statement.h"
|
||||
#include "src/ast/return_statement.h"
|
||||
#include "src/ast/statement.h"
|
||||
#include "src/reader/wgsl/parser_impl.h"
|
||||
#include "src/reader/wgsl/parser_impl_test_helper.h"
|
||||
|
||||
@@ -30,46 +28,6 @@ TEST_F(ParserImplTest, ContinueStmt) {
|
||||
ASSERT_FALSE(p->has_error()) << p->error();
|
||||
ASSERT_NE(e, nullptr);
|
||||
ASSERT_TRUE(e->IsContinue());
|
||||
EXPECT_EQ(e->condition(), ast::StatementCondition::kNone);
|
||||
EXPECT_EQ(e->conditional(), nullptr);
|
||||
}
|
||||
|
||||
TEST_F(ParserImplTest, ContinueStmt_WithIf) {
|
||||
auto* p = parser("continue if (a == b)");
|
||||
auto e = p->continue_stmt();
|
||||
ASSERT_FALSE(p->has_error()) << p->error();
|
||||
ASSERT_NE(e, nullptr);
|
||||
ASSERT_TRUE(e->IsContinue());
|
||||
EXPECT_EQ(e->condition(), ast::StatementCondition::kIf);
|
||||
ASSERT_NE(e->conditional(), nullptr);
|
||||
EXPECT_TRUE(e->conditional()->IsBinary());
|
||||
}
|
||||
|
||||
TEST_F(ParserImplTest, ContinueStmt_WithUnless) {
|
||||
auto* p = parser("continue unless (a == b)");
|
||||
auto e = p->continue_stmt();
|
||||
ASSERT_FALSE(p->has_error()) << p->error();
|
||||
ASSERT_NE(e, nullptr);
|
||||
ASSERT_TRUE(e->IsContinue());
|
||||
EXPECT_EQ(e->condition(), ast::StatementCondition::kUnless);
|
||||
ASSERT_NE(e->conditional(), nullptr);
|
||||
EXPECT_TRUE(e->conditional()->IsBinary());
|
||||
}
|
||||
|
||||
TEST_F(ParserImplTest, ContinueStmt_InvalidRHS) {
|
||||
auto* p = parser("continue if (a = b)");
|
||||
auto e = p->continue_stmt();
|
||||
ASSERT_TRUE(p->has_error());
|
||||
ASSERT_EQ(e, nullptr);
|
||||
EXPECT_EQ(p->error(), "1:16: expected )");
|
||||
}
|
||||
|
||||
TEST_F(ParserImplTest, ContinueStmt_MissingRHS) {
|
||||
auto* p = parser("continue if");
|
||||
auto e = p->continue_stmt();
|
||||
ASSERT_TRUE(p->has_error());
|
||||
ASSERT_EQ(e, nullptr);
|
||||
EXPECT_EQ(p->error(), "1:12: expected (");
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
@@ -197,20 +197,12 @@ TEST_F(ParserImplTest, Statement_Break) {
|
||||
EXPECT_TRUE(e->IsBreak());
|
||||
}
|
||||
|
||||
TEST_F(ParserImplTest, Statement_Break_Invalid) {
|
||||
auto* p = parser("break if (a = b);");
|
||||
auto e = p->statement();
|
||||
ASSERT_TRUE(p->has_error());
|
||||
ASSERT_EQ(e, nullptr);
|
||||
EXPECT_EQ(p->error(), "1:13: expected )");
|
||||
}
|
||||
|
||||
TEST_F(ParserImplTest, Statement_Break_MissingSemicolon) {
|
||||
auto* p = parser("break if (a == b)");
|
||||
auto* p = parser("break");
|
||||
auto e = p->statement();
|
||||
ASSERT_TRUE(p->has_error());
|
||||
ASSERT_EQ(e, nullptr);
|
||||
EXPECT_EQ(p->error(), "1:18: missing ;");
|
||||
EXPECT_EQ(p->error(), "1:6: missing ;");
|
||||
}
|
||||
|
||||
TEST_F(ParserImplTest, Statement_Continue) {
|
||||
@@ -221,20 +213,12 @@ TEST_F(ParserImplTest, Statement_Continue) {
|
||||
EXPECT_TRUE(e->IsContinue());
|
||||
}
|
||||
|
||||
TEST_F(ParserImplTest, Statement_Continue_Invalid) {
|
||||
auto* p = parser("continue if (a = b);");
|
||||
auto e = p->statement();
|
||||
ASSERT_TRUE(p->has_error());
|
||||
ASSERT_EQ(e, nullptr);
|
||||
EXPECT_EQ(p->error(), "1:16: expected )");
|
||||
}
|
||||
|
||||
TEST_F(ParserImplTest, Statement_Continue_MissingSemicolon) {
|
||||
auto* p = parser("continue if (a == b)");
|
||||
auto* p = parser("continue");
|
||||
auto e = p->statement();
|
||||
ASSERT_TRUE(p->has_error());
|
||||
ASSERT_EQ(e, nullptr);
|
||||
EXPECT_EQ(p->error(), "1:21: missing ;");
|
||||
EXPECT_EQ(p->error(), "1:9: missing ;");
|
||||
}
|
||||
|
||||
TEST_F(ParserImplTest, Statement_Kill) {
|
||||
|
||||
Reference in New Issue
Block a user