diff --git a/BUILD.gn b/BUILD.gn index 28606b16cb..162f7a1ecb 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -278,8 +278,6 @@ source_set("libtint_core_src") { "src/ast/sint_literal.h", "src/ast/statement.cc", "src/ast/statement.h", - "src/ast/statement_condition.cc", - "src/ast/statement_condition.h", "src/ast/storage_class.cc", "src/ast/storage_class.h", "src/ast/struct.cc", diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 7f2f27435b..e848119a90 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -115,8 +115,6 @@ set(TINT_LIB_SRCS ast/sint_literal.h ast/statement.cc ast/statement.h - ast/statement_condition.cc - ast/statement_condition.h ast/storage_class.cc ast/storage_class.h ast/struct_decoration.cc diff --git a/src/ast/break_statement.cc b/src/ast/break_statement.cc index a1dda434c1..db543d39de 100644 --- a/src/ast/break_statement.cc +++ b/src/ast/break_statement.cc @@ -21,19 +21,6 @@ BreakStatement::BreakStatement() : Statement() {} BreakStatement::BreakStatement(const Source& source) : Statement(source) {} -BreakStatement::BreakStatement(StatementCondition condition, - std::unique_ptr conditional) - : Statement(), - condition_(condition), - conditional_(std::move(conditional)) {} - -BreakStatement::BreakStatement(const Source& source, - StatementCondition condition, - std::unique_ptr conditional) - : Statement(source), - condition_(condition), - conditional_(std::move(conditional)) {} - BreakStatement::BreakStatement(BreakStatement&&) = default; BreakStatement::~BreakStatement() = default; @@ -43,26 +30,12 @@ bool BreakStatement::IsBreak() const { } bool BreakStatement::IsValid() const { - if (condition_ == StatementCondition::kNone) - return conditional_ == nullptr; - - return conditional_ != nullptr && conditional_->IsValid(); + return true; } void BreakStatement::to_str(std::ostream& out, size_t indent) const { make_indent(out, indent); - out << "Break{"; - - if (condition_ != StatementCondition::kNone) { - out << std::endl; - - make_indent(out, indent + 2); - out << condition_ << std::endl; - conditional_->to_str(out, indent + 2); - - make_indent(out, indent); - } - out << "}" << std::endl; + out << "Break{}" << std::endl; } } // namespace ast diff --git a/src/ast/break_statement.h b/src/ast/break_statement.h index 4a720de96a..f29d5fcdda 100644 --- a/src/ast/break_statement.h +++ b/src/ast/break_statement.h @@ -15,12 +15,7 @@ #ifndef SRC_AST_BREAK_STATEMENT_H_ #define SRC_AST_BREAK_STATEMENT_H_ -#include -#include - -#include "src/ast/expression.h" #include "src/ast/statement.h" -#include "src/ast/statement_condition.h" namespace tint { namespace ast { @@ -33,36 +28,10 @@ class BreakStatement : public Statement { /// Constructor /// @param source the break statement source explicit BreakStatement(const Source& source); - /// Constructor - /// @param condition the condition type - /// @param conditional the condition expression - BreakStatement(StatementCondition condition, - std::unique_ptr conditional); - /// Constructor - /// @param source the break statement source - /// @param condition the condition type - /// @param conditional the condition expression - BreakStatement(const Source& source, - StatementCondition condition, - std::unique_ptr conditional); /// Move constructor BreakStatement(BreakStatement&&); ~BreakStatement() override; - /// Sets the condition type - /// @param condition the condition type - void set_condition(StatementCondition condition) { condition_ = condition; } - /// @returns the condition type - StatementCondition condition() const { return condition_; } - - /// Sets the conditional expression - /// @param conditional the conditional expression - void set_conditional(std::unique_ptr conditional) { - conditional_ = std::move(conditional); - } - /// @returns the conditional expression - Expression* conditional() const { return conditional_.get(); } - /// @returns true if this is an break statement bool IsBreak() const override; @@ -76,9 +45,6 @@ class BreakStatement : public Statement { private: BreakStatement(const BreakStatement&) = delete; - - StatementCondition condition_ = StatementCondition::kNone; - std::unique_ptr conditional_; }; } // namespace ast diff --git a/src/ast/break_statement_test.cc b/src/ast/break_statement_test.cc index 49df1ba0cc..4e39386a86 100644 --- a/src/ast/break_statement_test.cc +++ b/src/ast/break_statement_test.cc @@ -15,8 +15,6 @@ #include "src/ast/break_statement.h" #include "gtest/gtest.h" -#include "src/ast/identifier_expression.h" -#include "src/ast/statement_condition.h" namespace tint { namespace ast { @@ -24,21 +22,6 @@ namespace { using BreakStatementTest = testing::Test; -TEST_F(BreakStatementTest, Creation) { - BreakStatement stmt; - EXPECT_EQ(stmt.condition(), StatementCondition::kNone); - EXPECT_EQ(stmt.conditional(), nullptr); -} - -TEST_F(BreakStatementTest, CreationWithConditional) { - auto expr = std::make_unique("expr"); - auto* expr_ptr = expr.get(); - - BreakStatement stmt(StatementCondition::kIf, std::move(expr)); - EXPECT_EQ(stmt.condition(), StatementCondition::kIf); - EXPECT_EQ(stmt.conditional(), expr_ptr); -} - TEST_F(BreakStatementTest, Creation_WithSource) { BreakStatement stmt(Source{20, 2}); auto src = stmt.source(); @@ -46,51 +29,17 @@ TEST_F(BreakStatementTest, Creation_WithSource) { EXPECT_EQ(src.column, 2u); } -TEST_F(BreakStatementTest, Creation_WithSourceAndCondition) { - auto expr = std::make_unique("expr"); - - BreakStatement stmt(Source{20, 2}, StatementCondition::kUnless, - std::move(expr)); - auto src = stmt.source(); - EXPECT_EQ(src.line, 20u); - EXPECT_EQ(src.column, 2u); -} - TEST_F(BreakStatementTest, IsBreak) { BreakStatement stmt; EXPECT_TRUE(stmt.IsBreak()); } -TEST_F(BreakStatementTest, IsValid_WithoutCondition) { +TEST_F(BreakStatementTest, IsValid) { BreakStatement stmt; EXPECT_TRUE(stmt.IsValid()); } -TEST_F(BreakStatementTest, IsValid_WithCondition) { - auto expr = std::make_unique("expr"); - BreakStatement stmt(StatementCondition::kIf, std::move(expr)); - EXPECT_TRUE(stmt.IsValid()); -} - -TEST_F(BreakStatementTest, IsValid_WithConditionAndConditionNone) { - auto expr = std::make_unique("expr"); - BreakStatement stmt(StatementCondition::kNone, std::move(expr)); - EXPECT_FALSE(stmt.IsValid()); -} - -TEST_F(BreakStatementTest, IsValid_WithCondition_MissingConditional) { - BreakStatement stmt; - stmt.set_condition(StatementCondition::kIf); - EXPECT_FALSE(stmt.IsValid()); -} - -TEST_F(BreakStatementTest, IsValid_InvalidConditional) { - auto expr = std::make_unique(""); - BreakStatement stmt(StatementCondition::kIf, std::move(expr)); - EXPECT_FALSE(stmt.IsValid()); -} - -TEST_F(BreakStatementTest, ToStr_WithoutCondition) { +TEST_F(BreakStatementTest, ToStr) { BreakStatement stmt; std::ostringstream out; stmt.to_str(out, 2); @@ -98,18 +47,6 @@ TEST_F(BreakStatementTest, ToStr_WithoutCondition) { )"); } -TEST_F(BreakStatementTest, ToStr_WithCondition) { - auto expr = std::make_unique("expr"); - BreakStatement stmt(StatementCondition::kUnless, std::move(expr)); - std::ostringstream out; - stmt.to_str(out, 2); - EXPECT_EQ(out.str(), R"( Break{ - unless - Identifier{expr} - } -)"); -} - } // namespace } // namespace ast } // namespace tint diff --git a/src/ast/continue_statement.cc b/src/ast/continue_statement.cc index 6ef2f81dcd..efc17d9132 100644 --- a/src/ast/continue_statement.cc +++ b/src/ast/continue_statement.cc @@ -22,19 +22,6 @@ ContinueStatement::ContinueStatement() : Statement() {} ContinueStatement::ContinueStatement(const Source& source) : Statement(source) {} -ContinueStatement::ContinueStatement(StatementCondition condition, - std::unique_ptr conditional) - : Statement(), - condition_(condition), - conditional_(std::move(conditional)) {} - -ContinueStatement::ContinueStatement(const Source& source, - StatementCondition condition, - std::unique_ptr conditional) - : Statement(source), - condition_(condition), - conditional_(std::move(conditional)) {} - ContinueStatement::ContinueStatement(ContinueStatement&&) = default; ContinueStatement::~ContinueStatement() = default; @@ -44,26 +31,12 @@ bool ContinueStatement::IsContinue() const { } bool ContinueStatement::IsValid() const { - if (condition_ == StatementCondition::kNone) - return conditional_ == nullptr; - - return conditional_ && conditional_->IsValid(); + return true; } void ContinueStatement::to_str(std::ostream& out, size_t indent) const { make_indent(out, indent); - out << "Continue{"; - - if (condition_ != StatementCondition::kNone) { - out << std::endl; - - make_indent(out, indent + 2); - out << condition_ << std::endl; - conditional_->to_str(out, indent + 2); - - make_indent(out, indent); - } - out << "}" << std::endl; + out << "Continue{}" << std::endl; } } // namespace ast diff --git a/src/ast/continue_statement.h b/src/ast/continue_statement.h index f06df2fcdc..866917bb40 100644 --- a/src/ast/continue_statement.h +++ b/src/ast/continue_statement.h @@ -18,9 +18,7 @@ #include #include -#include "src/ast/expression.h" #include "src/ast/statement.h" -#include "src/ast/statement_condition.h" namespace tint { namespace ast { @@ -33,36 +31,10 @@ class ContinueStatement : public Statement { /// Constructor /// @param source the continue statement source explicit ContinueStatement(const Source& source); - /// Constructor - /// @param condition the condition type - /// @param conditional the condition expression - ContinueStatement(StatementCondition condition, - std::unique_ptr conditional); - /// Constructor - /// @param source the continue statement source - /// @param condition the condition type - /// @param conditional the condition expression - ContinueStatement(const Source& source, - StatementCondition condition, - std::unique_ptr conditional); /// Move constructor ContinueStatement(ContinueStatement&&); ~ContinueStatement() override; - /// Sets the condition type - /// @param condition the condition type - void set_condition(StatementCondition condition) { condition_ = condition; } - /// @returns the condition type - StatementCondition condition() const { return condition_; } - - /// Sets the conditional expression - /// @param conditional the conditional expression - void set_conditional(std::unique_ptr conditional) { - conditional_ = std::move(conditional); - } - /// @returns the conditional expression - Expression* conditional() const { return conditional_.get(); } - /// @returns true if this is an continue statement bool IsContinue() const override; @@ -76,9 +48,6 @@ class ContinueStatement : public Statement { private: ContinueStatement(const ContinueStatement&) = delete; - - StatementCondition condition_ = StatementCondition::kNone; - std::unique_ptr conditional_; }; } // namespace ast diff --git a/src/ast/continue_statement_test.cc b/src/ast/continue_statement_test.cc index 10026bd0ad..4ba18e9848 100644 --- a/src/ast/continue_statement_test.cc +++ b/src/ast/continue_statement_test.cc @@ -15,8 +15,6 @@ #include "src/ast/continue_statement.h" #include "gtest/gtest.h" -#include "src/ast/identifier_expression.h" -#include "src/ast/statement_condition.h" namespace tint { namespace ast { @@ -24,21 +22,6 @@ namespace { using ContinueStatementTest = testing::Test; -TEST_F(ContinueStatementTest, Creation) { - ContinueStatement stmt; - EXPECT_EQ(stmt.condition(), StatementCondition::kNone); - EXPECT_EQ(stmt.conditional(), nullptr); -} - -TEST_F(ContinueStatementTest, CreationWithConditional) { - auto expr = std::make_unique("expr"); - auto* expr_ptr = expr.get(); - - ContinueStatement stmt(StatementCondition::kIf, std::move(expr)); - EXPECT_EQ(stmt.condition(), StatementCondition::kIf); - EXPECT_EQ(stmt.conditional(), expr_ptr); -} - TEST_F(ContinueStatementTest, Creation_WithSource) { ContinueStatement stmt(Source{20, 2}); auto src = stmt.source(); @@ -46,51 +29,17 @@ TEST_F(ContinueStatementTest, Creation_WithSource) { EXPECT_EQ(src.column, 2u); } -TEST_F(ContinueStatementTest, Creation_WithSourceAndCondition) { - auto expr = std::make_unique("expr"); - - ContinueStatement stmt(Source{20, 2}, StatementCondition::kUnless, - std::move(expr)); - auto src = stmt.source(); - EXPECT_EQ(src.line, 20u); - EXPECT_EQ(src.column, 2u); -} - TEST_F(ContinueStatementTest, IsContinue) { ContinueStatement stmt; EXPECT_TRUE(stmt.IsContinue()); } -TEST_F(ContinueStatementTest, IsValid_WithoutCondition) { +TEST_F(ContinueStatementTest, IsValid) { ContinueStatement stmt; EXPECT_TRUE(stmt.IsValid()); } -TEST_F(ContinueStatementTest, IsValid_WithCondition) { - auto expr = std::make_unique("expr"); - ContinueStatement stmt(StatementCondition::kIf, std::move(expr)); - EXPECT_TRUE(stmt.IsValid()); -} - -TEST_F(ContinueStatementTest, IsValid_InvalidConditional) { - auto expr = std::make_unique(""); - ContinueStatement stmt(StatementCondition::kIf, std::move(expr)); - EXPECT_FALSE(stmt.IsValid()); -} - -TEST_F(ContinueStatementTest, IsValid_NoneConditionWithConditional) { - auto expr = std::make_unique("expr"); - ContinueStatement stmt(StatementCondition::kNone, std::move(expr)); - EXPECT_FALSE(stmt.IsValid()); -} - -TEST_F(ContinueStatementTest, IsValid_WithCondition_MissingConditional) { - ContinueStatement stmt; - stmt.set_condition(StatementCondition::kIf); - EXPECT_FALSE(stmt.IsValid()); -} - -TEST_F(ContinueStatementTest, ToStr_WithoutCondition) { +TEST_F(ContinueStatementTest, ToStr) { ContinueStatement stmt; std::ostringstream out; stmt.to_str(out, 2); @@ -98,18 +47,6 @@ TEST_F(ContinueStatementTest, ToStr_WithoutCondition) { )"); } -TEST_F(ContinueStatementTest, ToStr_WithCondition) { - auto expr = std::make_unique("expr"); - ContinueStatement stmt(StatementCondition::kUnless, std::move(expr)); - std::ostringstream out; - stmt.to_str(out, 2); - EXPECT_EQ(out.str(), R"( Continue{ - unless - Identifier{expr} - } -)"); -} - } // namespace } // namespace ast } // namespace tint diff --git a/src/ast/fallthrough_statement.h b/src/ast/fallthrough_statement.h index a165b3abf5..7579e499e9 100644 --- a/src/ast/fallthrough_statement.h +++ b/src/ast/fallthrough_statement.h @@ -15,9 +15,7 @@ #ifndef SRC_AST_FALLTHROUGH_STATEMENT_H_ #define SRC_AST_FALLTHROUGH_STATEMENT_H_ -#include "src/ast/expression.h" #include "src/ast/statement.h" -#include "src/ast/statement_condition.h" namespace tint { namespace ast { diff --git a/src/ast/statement_condition.cc b/src/ast/statement_condition.cc deleted file mode 100644 index dc2136fef4..0000000000 --- a/src/ast/statement_condition.cc +++ /dev/null @@ -1,37 +0,0 @@ -// Copyright 2020 The Tint Authors. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#include "src/ast/statement_condition.h" - -namespace tint { -namespace ast { - -std::ostream& operator<<(std::ostream& out, StatementCondition condition) { - switch (condition) { - case StatementCondition::kNone: - out << "none"; - break; - case StatementCondition::kIf: - out << "if"; - break; - case StatementCondition::kUnless: - out << "unless"; - break; - } - - return out; -} - -} // namespace ast -} // namespace tint diff --git a/src/ast/statement_condition.h b/src/ast/statement_condition.h deleted file mode 100644 index fa4149ef3a..0000000000 --- a/src/ast/statement_condition.h +++ /dev/null @@ -1,31 +0,0 @@ -// Copyright 2020 The Tint Authors. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#ifndef SRC_AST_STATEMENT_CONDITION_H_ -#define SRC_AST_STATEMENT_CONDITION_H_ - -#include - -namespace tint { -namespace ast { - -/// Type of condition attached to a statement -enum class StatementCondition { kNone = 0, kIf, kUnless }; - -std::ostream& operator<<(std::ostream& out, StatementCondition condition); - -} // namespace ast -} // namespace tint - -#endif // SRC_AST_STATEMENT_CONDITION_H_ diff --git a/src/ast/switch_statement.h b/src/ast/switch_statement.h index 29078cc675..ba3f2686e8 100644 --- a/src/ast/switch_statement.h +++ b/src/ast/switch_statement.h @@ -22,7 +22,6 @@ #include "src/ast/expression.h" #include "src/ast/literal.h" #include "src/ast/statement.h" -#include "src/ast/statement_condition.h" namespace tint { namespace ast { diff --git a/src/reader/wgsl/parser_impl.cc b/src/reader/wgsl/parser_impl.cc index 89edc77e65..eebea01f30 100644 --- a/src/reader/wgsl/parser_impl.cc +++ b/src/reader/wgsl/parser_impl.cc @@ -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 ParserImpl::loop_stmt() { } // break_stmt -// : BREAK ({IF | UNLESS} paren_rhs_stmt)? +// : BREAK std::unique_ptr 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 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(source, condition, - std::move(conditional)); + return std::make_unique(t.source()); } // continue_stmt -// : CONTINUE ({IF | UNLESS} paren_rhs_stmt)? +// : CONTINUE std::unique_ptr 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 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(source, condition, - std::move(conditional)); + return std::make_unique(t.source()); } // continuing_stmt diff --git a/src/reader/wgsl/parser_impl_break_stmt_test.cc b/src/reader/wgsl/parser_impl_break_stmt_test.cc index 45ff183e59..4eba1591b5 100644 --- a/src/reader/wgsl/parser_impl_break_stmt_test.cc +++ b/src/reader/wgsl/parser_impl_break_stmt_test.cc @@ -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 diff --git a/src/reader/wgsl/parser_impl_continue_stmt_test.cc b/src/reader/wgsl/parser_impl_continue_stmt_test.cc index 9a7b6fa85f..8207e5763e 100644 --- a/src/reader/wgsl/parser_impl_continue_stmt_test.cc +++ b/src/reader/wgsl/parser_impl_continue_stmt_test.cc @@ -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 diff --git a/src/reader/wgsl/parser_impl_statement_test.cc b/src/reader/wgsl/parser_impl_statement_test.cc index 1deaa12125..5fc9339d33 100644 --- a/src/reader/wgsl/parser_impl_statement_test.cc +++ b/src/reader/wgsl/parser_impl_statement_test.cc @@ -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) { diff --git a/src/type_determiner.cc b/src/type_determiner.cc index beddba4283..8604d7b172 100644 --- a/src/type_determiner.cc +++ b/src/type_determiner.cc @@ -159,16 +159,14 @@ bool TypeDeterminer::DetermineResultType(ast::Statement* stmt) { return DetermineResultType(a->lhs()) && DetermineResultType(a->rhs()); } if (stmt->IsBreak()) { - auto* b = stmt->AsBreak(); - return DetermineResultType(b->conditional()); + return true; } if (stmt->IsCase()) { auto* c = stmt->AsCase(); return DetermineStatements(c->body()); } if (stmt->IsContinue()) { - auto* c = stmt->AsContinue(); - return DetermineResultType(c->conditional()); + return true; } if (stmt->IsElse()) { auto* e = stmt->AsElse(); diff --git a/src/type_determiner_test.cc b/src/type_determiner_test.cc index 0b746a9cd9..40090f5f36 100644 --- a/src/type_determiner_test.cc +++ b/src/type_determiner_test.cc @@ -129,26 +129,6 @@ TEST_F(TypeDeterminerTest, Stmt_Assign) { EXPECT_TRUE(rhs_ptr->result_type()->IsF32()); } -TEST_F(TypeDeterminerTest, Stmt_Break) { - ast::type::I32Type i32; - - auto cond = std::make_unique( - std::make_unique(&i32, 2)); - auto* cond_ptr = cond.get(); - - ast::BreakStatement brk(ast::StatementCondition::kIf, std::move(cond)); - - EXPECT_TRUE(td()->DetermineResultType(&brk)); - ASSERT_NE(cond_ptr->result_type(), nullptr); - EXPECT_TRUE(cond_ptr->result_type()->IsI32()); -} - -TEST_F(TypeDeterminerTest, Stmt_Break_WithoutCondition) { - ast::type::I32Type i32; - ast::BreakStatement brk; - EXPECT_TRUE(td()->DetermineResultType(&brk)); -} - TEST_F(TypeDeterminerTest, Stmt_Case) { ast::type::I32Type i32; ast::type::F32Type f32; @@ -176,26 +156,6 @@ TEST_F(TypeDeterminerTest, Stmt_Case) { EXPECT_TRUE(rhs_ptr->result_type()->IsF32()); } -TEST_F(TypeDeterminerTest, Stmt_Continue) { - ast::type::I32Type i32; - - auto cond = std::make_unique( - std::make_unique(&i32, 2)); - auto* cond_ptr = cond.get(); - - ast::ContinueStatement stmt(ast::StatementCondition::kIf, std::move(cond)); - - EXPECT_TRUE(td()->DetermineResultType(&stmt)); - ASSERT_NE(cond_ptr->result_type(), nullptr); - EXPECT_TRUE(cond_ptr->result_type()->IsI32()); -} - -TEST_F(TypeDeterminerTest, Stmt_Continue_WithoutStatement) { - ast::type::I32Type i32; - ast::ContinueStatement stmt; - EXPECT_TRUE(td()->DetermineResultType(&stmt)); -} - TEST_F(TypeDeterminerTest, Stmt_Else) { ast::type::I32Type i32; ast::type::F32Type f32; diff --git a/src/writer/spirv/builder_if_test.cc b/src/writer/spirv/builder_if_test.cc index 7818e5db95..ceaff32a22 100644 --- a/src/writer/spirv/builder_if_test.cc +++ b/src/writer/spirv/builder_if_test.cc @@ -26,7 +26,6 @@ #include "src/ast/return_statement.h" #include "src/ast/scalar_constructor_expression.h" #include "src/ast/sint_literal.h" -#include "src/ast/statement_condition.h" #include "src/ast/type/bool_type.h" #include "src/ast/type/i32_type.h" #include "src/context.h" @@ -488,67 +487,6 @@ OpBranch %1 )"); } -// This is blocked on implementing conditional break -TEST_F(BuilderTest, DISABLED_If_WithConditionalBreak) { - ast::type::BoolType bool_type; - // loop { - // if (true) { - // break if (false); - // } - // } - auto cond_true = std::make_unique( - std::make_unique(&bool_type, true)); - auto cond_false = std::make_unique( - std::make_unique(&bool_type, false)); - - ast::StatementList if_body; - if_body.push_back(std::make_unique( - ast::StatementCondition::kIf, std::move(cond_false))); - - auto if_stmt = std::make_unique(std::move(cond_true), - std::move(if_body)); - - ast::StatementList loop_body; - loop_body.push_back(std::move(if_stmt)); - - ast::LoopStatement expr(std::move(loop_body), {}); - - Context ctx; - ast::Module mod; - TypeDeterminer td(&ctx, &mod); - - ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error(); - - Builder b(&mod); - b.push_function(Function{}); - - EXPECT_TRUE(b.GenerateLoopStatement(&expr)) << b.error(); - EXPECT_EQ(DumpInstructions(b.types()), R"(%5 = OpTypeBool -%6 = OpConstantTrue %5 -%7 = OpConstantFalse %5 -)"); - EXPECT_EQ(DumpInstructions(b.functions()[0].instructions()), - R"(OpBranch %1 -%1 = OpLabel -OpLoopMerge %2 %3 None -OpBranch %4 -%4 = OpLabel -OpSelectionMerge %8 None -OpBranchConditional %6 %9 %8 -%9 = OpLabel -OpBranchConditional %7 %2 %8 -%8 = OpLabel -OpBranch %3 -%3 = OpLabel -OpBranch %1 -%2 = OpLabel -)"); -} - -TEST_F(BuilderTest, DISABLED_If_WithElseConditionalBreak) { - FAIL(); -} - TEST_F(BuilderTest, If_WithContinue) { ast::type::BoolType bool_type; // loop { @@ -601,10 +539,6 @@ OpBranch %1 )"); } -TEST_F(BuilderTest, DISABLED_If_WithConditionalContinue) { - FAIL(); -} - TEST_F(BuilderTest, If_WithElseContinue) { ast::type::BoolType bool_type; // loop { @@ -666,10 +600,6 @@ OpBranch %1 )"); } -TEST_F(BuilderTest, DISABLED_If_WithElseConditionalContinue) { - FAIL(); -} - TEST_F(BuilderTest, If_WithReturn) { ast::type::BoolType bool_type; // if (true) { diff --git a/src/writer/spirv/builder_loop_test.cc b/src/writer/spirv/builder_loop_test.cc index d5bfe5b156..107147024c 100644 --- a/src/writer/spirv/builder_loop_test.cc +++ b/src/writer/spirv/builder_loop_test.cc @@ -202,8 +202,6 @@ OpBranch %1 )"); } -TEST_F(BuilderTest, DISABLED_Loop_WithConditionalContinue) {} - TEST_F(BuilderTest, Loop_WithBreak) { // loop { // break; @@ -236,8 +234,6 @@ OpBranch %1 )"); } -TEST_F(BuilderTest, DISABLED_Loop_WithConditionalBreak) {} - } // namespace } // namespace spirv } // namespace writer diff --git a/src/writer/spirv/builder_switch_test.cc b/src/writer/spirv/builder_switch_test.cc index 3637a923f4..d320235b8a 100644 --- a/src/writer/spirv/builder_switch_test.cc +++ b/src/writer/spirv/builder_switch_test.cc @@ -472,16 +472,6 @@ TEST_F(BuilderTest, Switch_CaseFallthroughLastStatement) { EXPECT_EQ(b.error(), "fallthrough of last case statement is disallowed"); } -// TODO(dsinclair): Implement when parsing is handled for multi-value -// case labels. -TEST_F(BuilderTest, DISABLED_Switch_CaseWithMulitpleLabels) { - // switch (a) { - // case 1, 2, 3: - // v = 1; - // } - FAIL(); -} - TEST_F(BuilderTest, Switch_WithNestedBreak) { ast::type::I32Type i32; ast::type::BoolType bool_type; diff --git a/src/writer/wgsl/generator_impl.cc b/src/writer/wgsl/generator_impl.cc index f27f518135..2316d17d7d 100644 --- a/src/writer/wgsl/generator_impl.cc +++ b/src/writer/wgsl/generator_impl.cc @@ -691,28 +691,9 @@ bool GeneratorImpl::EmitAssign(ast::AssignmentStatement* stmt) { return true; } -bool GeneratorImpl::EmitBreak(ast::BreakStatement* stmt) { +bool GeneratorImpl::EmitBreak(ast::BreakStatement*) { make_indent(); - - out_ << "break"; - - if (stmt->condition() != ast::StatementCondition::kNone) { - out_ << " "; - if (stmt->condition() == ast::StatementCondition::kIf) { - out_ << "if"; - } else { - out_ << "unless"; - } - - out_ << " ("; - if (!EmitExpression(stmt->conditional())) { - return false; - } - out_ << ")"; - } - - out_ << ";" << std::endl; - + out_ << "break;" << std::endl; return true; } @@ -742,28 +723,9 @@ bool GeneratorImpl::EmitCase(ast::CaseStatement* stmt) { return EmitStatementBlockAndNewline(stmt->body()); } -bool GeneratorImpl::EmitContinue(ast::ContinueStatement* stmt) { +bool GeneratorImpl::EmitContinue(ast::ContinueStatement*) { make_indent(); - - out_ << "continue"; - - if (stmt->condition() != ast::StatementCondition::kNone) { - out_ << " "; - if (stmt->condition() == ast::StatementCondition::kIf) { - out_ << "if"; - } else { - out_ << "unless"; - } - - out_ << " ("; - if (!EmitExpression(stmt->conditional())) { - return false; - } - out_ << ")"; - } - - out_ << ";" << std::endl; - + out_ << "continue;" << std::endl; return true; } diff --git a/src/writer/wgsl/generator_impl_break_test.cc b/src/writer/wgsl/generator_impl_break_test.cc index 556dcfe7d6..7bcc8e8773 100644 --- a/src/writer/wgsl/generator_impl_break_test.cc +++ b/src/writer/wgsl/generator_impl_break_test.cc @@ -17,7 +17,6 @@ #include "gtest/gtest.h" #include "src/ast/break_statement.h" -#include "src/ast/identifier_expression.h" #include "src/writer/wgsl/generator_impl.h" namespace tint { @@ -37,28 +36,6 @@ TEST_F(GeneratorImplTest, Emit_Break) { EXPECT_EQ(g.result(), " break;\n"); } -TEST_F(GeneratorImplTest, Emit_BreakWithIf) { - auto expr = std::make_unique("expr"); - ast::BreakStatement b(ast::StatementCondition::kIf, std::move(expr)); - - GeneratorImpl g; - g.increment_indent(); - - ASSERT_TRUE(g.EmitStatement(&b)) << g.error(); - EXPECT_EQ(g.result(), " break if (expr);\n"); -} - -TEST_F(GeneratorImplTest, Emit_BreakWithUnless) { - auto expr = std::make_unique("expr"); - ast::BreakStatement b(ast::StatementCondition::kUnless, std::move(expr)); - - GeneratorImpl g; - g.increment_indent(); - - ASSERT_TRUE(g.EmitStatement(&b)) << g.error(); - EXPECT_EQ(g.result(), " break unless (expr);\n"); -} - } // namespace } // namespace wgsl } // namespace writer diff --git a/src/writer/wgsl/generator_impl_continue_test.cc b/src/writer/wgsl/generator_impl_continue_test.cc index cb5b81b42b..ffd5b93287 100644 --- a/src/writer/wgsl/generator_impl_continue_test.cc +++ b/src/writer/wgsl/generator_impl_continue_test.cc @@ -17,7 +17,6 @@ #include "gtest/gtest.h" #include "src/ast/continue_statement.h" -#include "src/ast/identifier_expression.h" #include "src/writer/wgsl/generator_impl.h" namespace tint { @@ -37,28 +36,6 @@ TEST_F(GeneratorImplTest, Emit_Continue) { EXPECT_EQ(g.result(), " continue;\n"); } -TEST_F(GeneratorImplTest, Emit_ContinueWithIf) { - auto expr = std::make_unique("expr"); - ast::ContinueStatement c(ast::StatementCondition::kIf, std::move(expr)); - - GeneratorImpl g; - g.increment_indent(); - - ASSERT_TRUE(g.EmitStatement(&c)) << g.error(); - EXPECT_EQ(g.result(), " continue if (expr);\n"); -} - -TEST_F(GeneratorImplTest, Emit_ContinueWithUnless) { - auto expr = std::make_unique("expr"); - ast::ContinueStatement c(ast::StatementCondition::kUnless, std::move(expr)); - - GeneratorImpl g; - g.increment_indent(); - - ASSERT_TRUE(g.EmitStatement(&c)) << g.error(); - EXPECT_EQ(g.result(), " continue unless (expr);\n"); -} - } // namespace } // namespace wgsl } // namespace writer