diff --git a/BUILD.gn b/BUILD.gn index b3848d87a0..bbc32776dc 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -94,8 +94,6 @@ source_set("libtint") { "src/ast/nop_statement.h", "src/ast/pipeline_stage.cc", "src/ast/pipeline_stage.h", - "src/ast/regardless_statement.cc", - "src/ast/regardless_statement.h", "src/ast/return_statement.cc", "src/ast/return_statement.h", "src/ast/scalar_constructor_expression.cc", diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 0977215d87..084a38ba54 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -107,8 +107,6 @@ set(TINT_LIB_SRCS ast/nop_statement.h ast/pipeline_stage.cc ast/pipeline_stage.h - ast/regardless_statement.cc - ast/regardless_statement.h ast/return_statement.cc ast/return_statement.h ast/scalar_constructor_expression.cc @@ -282,7 +280,6 @@ set(TINT_TEST_SRCS ast/member_accessor_expression_test.cc ast/module_test.cc ast/nop_statement_test.cc - ast/regardless_statement_test.cc ast/binary_expression_test.cc ast/return_statement_test.cc ast/scalar_constructor_expression_test.cc @@ -390,7 +387,6 @@ if(${TINT_BUILD_WGSL_READER}) reader/wgsl/parser_impl_postfix_expression_test.cc reader/wgsl/parser_impl_premerge_stmt_test.cc reader/wgsl/parser_impl_primary_expression_test.cc - reader/wgsl/parser_impl_regardless_stmt_test.cc reader/wgsl/parser_impl_relational_expression_test.cc reader/wgsl/parser_impl_shift_expression_test.cc reader/wgsl/parser_impl_statement_test.cc @@ -467,7 +463,6 @@ if(${TINT_BUILD_WGSL_WRITER}) writer/wgsl/generator_impl_loop_test.cc writer/wgsl/generator_impl_member_accessor_test.cc writer/wgsl/generator_impl_nop_test.cc - writer/wgsl/generator_impl_regardless_test.cc writer/wgsl/generator_impl_relational_test.cc writer/wgsl/generator_impl_return_test.cc writer/wgsl/generator_impl_switch_test.cc diff --git a/src/ast/regardless_statement.cc b/src/ast/regardless_statement.cc deleted file mode 100644 index d01bc81d11..0000000000 --- a/src/ast/regardless_statement.cc +++ /dev/null @@ -1,72 +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/regardless_statement.h" - -namespace tint { -namespace ast { - -RegardlessStatement::RegardlessStatement() : Statement() {} - -RegardlessStatement::RegardlessStatement(std::unique_ptr condition, - StatementList body) - : Statement(), condition_(std::move(condition)), body_(std::move(body)) {} - -RegardlessStatement::RegardlessStatement(const Source& source, - std::unique_ptr condition, - StatementList body) - : Statement(source), - condition_(std::move(condition)), - body_(std::move(body)) {} - -RegardlessStatement::RegardlessStatement(RegardlessStatement&&) = default; -RegardlessStatement::~RegardlessStatement() = default; - -bool RegardlessStatement::IsRegardless() const { - return true; -} - -bool RegardlessStatement::IsValid() const { - if (condition_ == nullptr || !condition_->IsValid()) { - return false; - } - for (const auto& stmt : body_) { - if (stmt == nullptr || !stmt->IsValid()) { - return false; - } - } - - return true; -} - -void RegardlessStatement::to_str(std::ostream& out, size_t indent) const { - make_indent(out, indent); - out << "Regardless{" << std::endl; - - condition_->to_str(out, indent + 2); - make_indent(out, indent + 2); - out << "{" << std::endl; - - for (const auto& stmt : body_) - stmt->to_str(out, indent + 4); - - make_indent(out, indent + 2); - out << "}" << std::endl; - - make_indent(out, indent); - out << "}" << std::endl; -} - -} // namespace ast -} // namespace tint diff --git a/src/ast/regardless_statement.h b/src/ast/regardless_statement.h deleted file mode 100644 index 22cbd64f40..0000000000 --- a/src/ast/regardless_statement.h +++ /dev/null @@ -1,83 +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_REGARDLESS_STATEMENT_H_ -#define SRC_AST_REGARDLESS_STATEMENT_H_ - -#include -#include - -#include "src/ast/expression.h" -#include "src/ast/statement.h" - -namespace tint { -namespace ast { - -/// A regardless statement -class RegardlessStatement : public Statement { - public: - /// Constructor - RegardlessStatement(); - /// Constructor - /// @param condition the condition expression - /// @param body the body statements - RegardlessStatement(std::unique_ptr condition, - StatementList body); - /// Constructor - /// @param source the regardless statement source - /// @param condition the condition expression - /// @param body the body statements - RegardlessStatement(const Source& source, - std::unique_ptr condition, - StatementList body); - /// Move constructor - RegardlessStatement(RegardlessStatement&&); - ~RegardlessStatement() override; - - /// Sets the condition expression - /// @param condition the condition expression - void set_condition(std::unique_ptr condition) { - condition_ = std::move(condition); - } - /// @returns the condition statements - Expression* condition() const { return condition_.get(); } - - /// Sets the body statements - /// @param body the body statements - void set_body(StatementList body) { body_ = std::move(body); } - /// @returns the body statements - const StatementList& body() const { return body_; } - - /// @returns true if this is an regardless statement - bool IsRegardless() const override; - - /// @returns true if the node is valid - bool IsValid() const override; - - /// Writes a representation of the node to the output stream - /// @param out the stream to write to - /// @param indent number of spaces to indent the node when writing - void to_str(std::ostream& out, size_t indent) const override; - - private: - RegardlessStatement(const RegardlessStatement&) = delete; - - std::unique_ptr condition_; - StatementList body_; -}; - -} // namespace ast -} // namespace tint - -#endif // SRC_AST_REGARDLESS_STATEMENT_H_ diff --git a/src/ast/regardless_statement_test.cc b/src/ast/regardless_statement_test.cc deleted file mode 100644 index 955ae07f2e..0000000000 --- a/src/ast/regardless_statement_test.cc +++ /dev/null @@ -1,128 +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/regardless_statement.h" - -#include - -#include "gtest/gtest.h" -#include "src/ast/identifier_expression.h" -#include "src/ast/if_statement.h" -#include "src/ast/kill_statement.h" - -namespace tint { -namespace ast { -namespace { - -using RegardlessStatementTest = testing::Test; - -TEST_F(RegardlessStatementTest, Creation) { - auto ident = std::make_unique("ident"); - StatementList stmts; - stmts.push_back(std::make_unique()); - - auto ident_ptr = ident.get(); - auto kill_ptr = stmts[0].get(); - - RegardlessStatement r(std::move(ident), std::move(stmts)); - EXPECT_EQ(r.condition(), ident_ptr); - ASSERT_EQ(r.body().size(), 1); - EXPECT_EQ(r.body()[0].get(), kill_ptr); -} - -TEST_F(RegardlessStatementTest, Creation_WithSource) { - auto ident = std::make_unique("ident"); - StatementList stmts; - stmts.push_back(std::make_unique()); - - RegardlessStatement r(Source{20, 2}, std::move(ident), std::move(stmts)); - auto src = r.source(); - EXPECT_EQ(src.line, 20); - EXPECT_EQ(src.column, 2); -} - -TEST_F(RegardlessStatementTest, IsRegardless) { - RegardlessStatement r; - EXPECT_TRUE(r.IsRegardless()); -} - -TEST_F(RegardlessStatementTest, IsValid) { - auto ident = std::make_unique("ident"); - StatementList stmts; - stmts.push_back(std::make_unique()); - - RegardlessStatement r(std::move(ident), std::move(stmts)); - EXPECT_TRUE(r.IsValid()); -} - -TEST_F(RegardlessStatementTest, IsValid_NullCondition) { - StatementList stmts; - stmts.push_back(std::make_unique()); - - RegardlessStatement r; - r.set_body(std::move(stmts)); - EXPECT_FALSE(r.IsValid()); -} - -TEST_F(RegardlessStatementTest, IsValid_InvalidCondition) { - auto ident = std::make_unique(""); - StatementList stmts; - stmts.push_back(std::make_unique()); - - RegardlessStatement r(std::move(ident), std::move(stmts)); - EXPECT_FALSE(r.IsValid()); -} - -TEST_F(RegardlessStatementTest, IsValid_NullBodyStatement) { - auto ident = std::make_unique("ident"); - StatementList stmts; - stmts.push_back(std::make_unique()); - stmts.push_back(nullptr); - - RegardlessStatement r; - r.set_condition(std::move(ident)); - r.set_body(std::move(stmts)); - EXPECT_FALSE(r.IsValid()); -} - -TEST_F(RegardlessStatementTest, IsValid_InvalidBodyStatement) { - auto ident = std::make_unique("ident"); - StatementList stmts; - stmts.push_back(std::make_unique()); - stmts.push_back(std::make_unique()); - - RegardlessStatement r(std::move(ident), std::move(stmts)); - EXPECT_FALSE(r.IsValid()); -} - -TEST_F(RegardlessStatementTest, ToStr) { - auto ident = std::make_unique("ident"); - StatementList stmts; - stmts.push_back(std::make_unique()); - - RegardlessStatement r(std::move(ident), std::move(stmts)); - std::ostringstream out; - r.to_str(out, 2); - EXPECT_EQ(out.str(), R"( Regardless{ - Identifier{ident} - { - Kill{} - } - } -)"); -} - -} // namespace -} // namespace ast -} // namespace tint diff --git a/src/ast/statement.cc b/src/ast/statement.cc index f34be378ba..53f60366c1 100644 --- a/src/ast/statement.cc +++ b/src/ast/statement.cc @@ -26,7 +26,6 @@ #include "src/ast/kill_statement.h" #include "src/ast/loop_statement.h" #include "src/ast/nop_statement.h" -#include "src/ast/regardless_statement.h" #include "src/ast/return_statement.h" #include "src/ast/switch_statement.h" #include "src/ast/unless_statement.h" @@ -83,10 +82,6 @@ bool Statement::IsNop() const { return false; } -bool Statement::IsRegardless() const { - return false; -} - bool Statement::IsReturn() const { return false; } @@ -153,11 +148,6 @@ NopStatement* Statement::AsNop() { return static_cast(this); } -RegardlessStatement* Statement::AsRegardless() { - assert(IsRegardless()); - return static_cast(this); -} - ReturnStatement* Statement::AsReturn() { assert(IsReturn()); return static_cast(this); diff --git a/src/ast/statement.h b/src/ast/statement.h index dcd4c36055..e084b73d90 100644 --- a/src/ast/statement.h +++ b/src/ast/statement.h @@ -33,7 +33,6 @@ class IfStatement; class KillStatement; class LoopStatement; class NopStatement; -class RegardlessStatement; class ReturnStatement; class SwitchStatement; class UnlessStatement; @@ -64,8 +63,6 @@ class Statement : public Node { virtual bool IsLoop() const; /// @returns true if this is a nop statement virtual bool IsNop() const; - /// @returns true if this is an regardless statement - virtual bool IsRegardless() const; /// @returns true if this is a return statement virtual bool IsReturn() const; /// @returns true if this is a switch statement @@ -95,8 +92,6 @@ class Statement : public Node { LoopStatement* AsLoop(); /// @returns the statement as a nop statement NopStatement* AsNop(); - /// @returns the statement as an regardless statement - RegardlessStatement* AsRegardless(); /// @returns the statement as a return statement ReturnStatement* AsReturn(); /// @returns the statement as a switch statement diff --git a/src/reader/wgsl/lexer.cc b/src/reader/wgsl/lexer.cc index 1eec4e2dc7..3d4e989957 100644 --- a/src/reader/wgsl/lexer.cc +++ b/src/reader/wgsl/lexer.cc @@ -606,8 +606,6 @@ Token Lexer::check_keyword(const Source& source, const std::string& str) { return {Token::Type::kPtr, source, "ptr"}; if (str == "push_constant") return {Token::Type::kPushConstant, source, "push_constant"}; - if (str == "regardless") - return {Token::Type::kRegardless, source, "regardless"}; if (str == "return") return {Token::Type::kReturn, source, "return"}; if (str == "set") @@ -683,7 +681,8 @@ Token Lexer::check_reserved(const Source& source, const std::string& str) { return {Token::Type::kReservedKeyword, source, "u16"}; if (str == "u64") return {Token::Type::kReservedKeyword, source, "u64"}; - + if (str == "regardless") + return {Token::Type::kReservedKeyword, source, "regardless"}; return {}; } diff --git a/src/reader/wgsl/lexer_test.cc b/src/reader/wgsl/lexer_test.cc index f1535649ea..fb8b3cafd1 100644 --- a/src/reader/wgsl/lexer_test.cc +++ b/src/reader/wgsl/lexer_test.cc @@ -478,7 +478,6 @@ INSTANTIATE_TEST_SUITE_P( TokenData{"private", Token::Type::kPrivate}, TokenData{"ptr", Token::Type::kPtr}, TokenData{"push_constant", Token::Type::kPushConstant}, - TokenData{"regardless", Token::Type::kRegardless}, TokenData{"return", Token::Type::kReturn}, TokenData{"set", Token::Type::kSet}, TokenData{"storage_buffer", Token::Type::kStorageBuffer}, @@ -525,7 +524,8 @@ INSTANTIATE_TEST_SUITE_P(LexerTest, "typedef", "u8", "u16", - "u64")); + "u64", + "regardless")); } // namespace } // namespace wgsl diff --git a/src/reader/wgsl/parser_impl.cc b/src/reader/wgsl/parser_impl.cc index 5f86f568b8..d1a1148b35 100644 --- a/src/reader/wgsl/parser_impl.cc +++ b/src/reader/wgsl/parser_impl.cc @@ -1449,7 +1449,6 @@ ast::StatementList ParserImpl::statements() { // | RETURN logical_or_expression SEMICOLON // | if_stmt // | unless_stmt -// | regardless_stmt // | switch_stmt // | loop_stmt // | variable_stmt SEMICOLON @@ -1498,12 +1497,6 @@ std::unique_ptr ParserImpl::statement() { if (unless != nullptr) return unless; - auto regardless = regardless_stmt(); - if (has_error()) - return nullptr; - if (regardless != nullptr) - return regardless; - auto sw = switch_stmt(); if (has_error()) return nullptr; @@ -1880,32 +1873,6 @@ std::unique_ptr ParserImpl::unless_stmt() { std::move(body)); } -// regardless_stmt -// : REGARDLESS paren_rhs_stmt body_stmt -std::unique_ptr ParserImpl::regardless_stmt() { - auto t = peek(); - if (!t.IsRegardless()) - return nullptr; - - auto source = t.source(); - next(); // Consume the peek - - auto condition = paren_rhs_stmt(); - if (has_error()) - return nullptr; - if (condition == nullptr) { - set_error(peek(), "unable to parse regardless condition"); - return nullptr; - } - - auto body = body_stmt(); - if (has_error()) - return nullptr; - - return std::make_unique( - source, std::move(condition), std::move(body)); -} - // switch_stmt // : SWITCH paren_rhs_stmt BRACKET_LEFT switch_body+ BRACKET_RIGHT std::unique_ptr ParserImpl::switch_stmt() { diff --git a/src/reader/wgsl/parser_impl.h b/src/reader/wgsl/parser_impl.h index 6027d1ebe1..faf77810be 100644 --- a/src/reader/wgsl/parser_impl.h +++ b/src/reader/wgsl/parser_impl.h @@ -33,7 +33,6 @@ #include "src/ast/loop_statement.h" #include "src/ast/module.h" #include "src/ast/pipeline_stage.h" -#include "src/ast/regardless_statement.h" #include "src/ast/statement.h" #include "src/ast/storage_class.h" #include "src/ast/struct.h" @@ -215,9 +214,6 @@ class ParserImpl { /// Parses a `unless_stmt` grammar element /// @returns the parsed element or nullptr std::unique_ptr unless_stmt(); - /// Parses a `regardless_stmt` grammar element - /// @returns the parsed element or nullptr - std::unique_ptr regardless_stmt(); /// Parses a `switch_stmt` grammar element /// @returns the parsed statement or nullptr std::unique_ptr switch_stmt(); diff --git a/src/reader/wgsl/parser_impl_regardless_stmt_test.cc b/src/reader/wgsl/parser_impl_regardless_stmt_test.cc deleted file mode 100644 index 54933524e6..0000000000 --- a/src/reader/wgsl/parser_impl_regardless_stmt_test.cc +++ /dev/null @@ -1,63 +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 "gtest/gtest.h" -#include "src/reader/wgsl/parser_impl.h" -#include "src/reader/wgsl/parser_impl_test_helper.h" - -namespace tint { -namespace reader { -namespace wgsl { -namespace { - -TEST_F(ParserImplTest, RegardlessStmt) { - auto p = parser("regardless (a) { kill; }"); - auto e = p->regardless_stmt(); - ASSERT_FALSE(p->has_error()) << p->error(); - ASSERT_NE(e, nullptr); - ASSERT_TRUE(e->IsRegardless()); - ASSERT_NE(e->condition(), nullptr); - EXPECT_TRUE(e->condition()->IsIdentifier()); - ASSERT_EQ(e->body().size(), 1); - EXPECT_TRUE(e->body()[0]->IsKill()); -} - -TEST_F(ParserImplTest, RegardlessStmt_InvalidCondition) { - auto p = parser("regardless(if(a){}) {}"); - auto e = p->regardless_stmt(); - ASSERT_TRUE(p->has_error()); - ASSERT_EQ(e, nullptr); - EXPECT_EQ(p->error(), "1:12: unable to parse expression"); -} - -TEST_F(ParserImplTest, RegardlessStmt_EmptyCondition) { - auto p = parser("regardless() {}"); - auto e = p->regardless_stmt(); - ASSERT_TRUE(p->has_error()); - ASSERT_EQ(e, nullptr); - EXPECT_EQ(p->error(), "1:12: unable to parse expression"); -} - -TEST_F(ParserImplTest, RegardlessStmt_InvalidBody) { - auto p = parser("regardless(a + 2 - 5 == true) { kill }"); - auto e = p->regardless_stmt(); - ASSERT_TRUE(p->has_error()); - ASSERT_EQ(e, nullptr); - EXPECT_EQ(p->error(), "1:38: missing ;"); -} - -} // namespace -} // namespace wgsl -} // namespace reader -} // namespace tint diff --git a/src/reader/wgsl/parser_impl_statement_test.cc b/src/reader/wgsl/parser_impl_statement_test.cc index 25a1017058..29ad4f8970 100644 --- a/src/reader/wgsl/parser_impl_statement_test.cc +++ b/src/reader/wgsl/parser_impl_statement_test.cc @@ -109,22 +109,6 @@ TEST_F(ParserImplTest, Statement_Unless_Invalid) { EXPECT_EQ(p->error(), "1:9: unable to parse expression"); } -TEST_F(ParserImplTest, Statement_Regardless) { - auto p = parser("regardless (a) {}"); - auto e = p->statement(); - ASSERT_FALSE(p->has_error()) << p->error(); - ASSERT_NE(e, nullptr); - ASSERT_TRUE(e->IsRegardless()); -} - -TEST_F(ParserImplTest, Statement_Regardless_Invalid) { - auto p = parser("regardless () {}"); - auto e = p->statement(); - ASSERT_TRUE(p->has_error()); - ASSERT_EQ(e, nullptr); - EXPECT_EQ(p->error(), "1:13: unable to parse expression"); -} - TEST_F(ParserImplTest, Statement_Variable) { auto p = parser("var a : i32 = 1;"); auto e = p->statement(); diff --git a/src/reader/wgsl/token.h b/src/reader/wgsl/token.h index ad77a80aa7..234e5e24ee 100644 --- a/src/reader/wgsl/token.h +++ b/src/reader/wgsl/token.h @@ -569,8 +569,6 @@ class Token { bool IsPtr() const { return type_ == Type::kPtr; } /// @returns true if token is a 'push_constant' bool IsPushConstant() const { return type_ == Type::kPushConstant; } - /// @returns true if token is a 'regardless' - bool IsRegardless() const { return type_ == Type::kRegardless; } /// @returns true if token is a 'return' bool IsReturn() const { return type_ == Type::kReturn; } /// @returns true if token is a 'set' diff --git a/src/type_determiner.cc b/src/type_determiner.cc index 357d3e98c5..1be0c42aca 100644 --- a/src/type_determiner.cc +++ b/src/type_determiner.cc @@ -30,7 +30,6 @@ #include "src/ast/if_statement.h" #include "src/ast/loop_statement.h" #include "src/ast/member_accessor_expression.h" -#include "src/ast/regardless_statement.h" #include "src/ast/return_statement.h" #include "src/ast/scalar_constructor_expression.h" #include "src/ast/switch_statement.h" @@ -183,11 +182,6 @@ bool TypeDeterminer::DetermineResultType(ast::Statement* stmt) { if (stmt->IsNop()) { return true; } - if (stmt->IsRegardless()) { - auto* r = stmt->AsRegardless(); - return DetermineResultType(r->condition()) && - DetermineStatements(r->body()); - } if (stmt->IsReturn()) { auto* r = stmt->AsReturn(); return DetermineResultType(r->value()); diff --git a/src/type_determiner_test.cc b/src/type_determiner_test.cc index 98997fc235..875842ae0b 100644 --- a/src/type_determiner_test.cc +++ b/src/type_determiner_test.cc @@ -35,7 +35,6 @@ #include "src/ast/int_literal.h" #include "src/ast/loop_statement.h" #include "src/ast/member_accessor_expression.h" -#include "src/ast/regardless_statement.h" #include "src/ast/return_statement.h" #include "src/ast/scalar_constructor_expression.h" #include "src/ast/struct.h" @@ -310,36 +309,6 @@ TEST_F(TypeDeterminerTest, Stmt_Loop) { EXPECT_TRUE(continuing_rhs_ptr->result_type()->IsF32()); } -TEST_F(TypeDeterminerTest, Stmt_Regardless) { - ast::type::I32Type i32; - ast::type::F32Type f32; - - auto lhs = std::make_unique( - std::make_unique(&i32, 2)); - auto lhs_ptr = lhs.get(); - - auto rhs = std::make_unique( - std::make_unique(&f32, 2.3f)); - auto rhs_ptr = rhs.get(); - - ast::StatementList body; - body.push_back(std::make_unique(std::move(lhs), - std::move(rhs))); - - ast::RegardlessStatement regardless( - std::make_unique( - std::make_unique(&i32, 3)), - std::move(body)); - - EXPECT_TRUE(td()->DetermineResultType(®ardless)); - ASSERT_NE(regardless.condition()->result_type(), nullptr); - ASSERT_NE(lhs_ptr->result_type(), nullptr); - ASSERT_NE(rhs_ptr->result_type(), nullptr); - EXPECT_TRUE(regardless.condition()->result_type()->IsI32()); - EXPECT_TRUE(lhs_ptr->result_type()->IsI32()); - EXPECT_TRUE(rhs_ptr->result_type()->IsF32()); -} - TEST_F(TypeDeterminerTest, Stmt_Return) { ast::type::I32Type i32; diff --git a/src/writer/wgsl/generator_impl.cc b/src/writer/wgsl/generator_impl.cc index 9eb1b36c05..88e54c6006 100644 --- a/src/writer/wgsl/generator_impl.cc +++ b/src/writer/wgsl/generator_impl.cc @@ -39,7 +39,6 @@ #include "src/ast/location_decoration.h" #include "src/ast/loop_statement.h" #include "src/ast/member_accessor_expression.h" -#include "src/ast/regardless_statement.h" #include "src/ast/return_statement.h" #include "src/ast/scalar_constructor_expression.h" #include "src/ast/set_decoration.h" @@ -742,9 +741,6 @@ bool GeneratorImpl::EmitStatement(ast::Statement* stmt) { if (stmt->IsNop()) { return EmitNop(stmt->AsNop()); } - if (stmt->IsRegardless()) { - return EmitRegardless(stmt->AsRegardless()); - } if (stmt->IsReturn()) { return EmitReturn(stmt->AsReturn()); } @@ -932,18 +928,6 @@ bool GeneratorImpl::EmitNop(ast::NopStatement*) { return true; } -bool GeneratorImpl::EmitRegardless(ast::RegardlessStatement* stmt) { - make_indent(); - - out_ << "regardless ("; - if (!EmitExpression(stmt->condition())) { - return false; - } - out_ << ")"; - - return EmitStatementBlockAndNewline(stmt->body()); -} - bool GeneratorImpl::EmitReturn(ast::ReturnStatement* stmt) { make_indent(); diff --git a/src/writer/wgsl/generator_impl.h b/src/writer/wgsl/generator_impl.h index 532f154bc6..d4ee578e5d 100644 --- a/src/writer/wgsl/generator_impl.h +++ b/src/writer/wgsl/generator_impl.h @@ -166,10 +166,6 @@ class GeneratorImpl { /// @param stmt the nop statement /// @returns true if the statement was successfully emitted bool EmitNop(ast::NopStatement* stmt); - /// Handles regardless statements - /// @param stmt the statement to emit - /// @returns true if the statement was successfully emitted - bool EmitRegardless(ast::RegardlessStatement* stmt); /// Handles return statements /// @param stmt the statement to emit /// @returns true if the statement was successfully emitted diff --git a/src/writer/wgsl/generator_impl_regardless_test.cc b/src/writer/wgsl/generator_impl_regardless_test.cc deleted file mode 100644 index 3a62297bcc..0000000000 --- a/src/writer/wgsl/generator_impl_regardless_test.cc +++ /dev/null @@ -1,54 +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 - -#include "gtest/gtest.h" -#include "src/ast/identifier_expression.h" -#include "src/ast/kill_statement.h" -#include "src/ast/nop_statement.h" -#include "src/ast/regardless_statement.h" -#include "src/writer/wgsl/generator_impl.h" - -namespace tint { -namespace writer { -namespace wgsl { -namespace { - -using GeneratorImplTest = testing::Test; - -TEST_F(GeneratorImplTest, Emit_Regardless) { - auto cond = std::make_unique("cond"); - - ast::StatementList body; - body.push_back(std::make_unique()); - body.push_back(std::make_unique()); - - ast::RegardlessStatement r(std::move(cond), std::move(body)); - - GeneratorImpl g; - g.increment_indent(); - - ASSERT_TRUE(g.EmitStatement(&r)) << g.error(); - EXPECT_EQ(g.result(), R"( regardless (cond) { - nop; - kill; - } -)"); -} - -} // namespace -} // namespace wgsl -} // namespace writer -} // namespace tint