Remove regardless.

This CL removes the regardless statement and turns `regardless` into a
reserved word.

Change-Id: I50c521111b90dbadddaeb36674e8c40205186076
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/19361
Reviewed-by: Ryan Harrison <rharrison@chromium.org>
This commit is contained in:
dan sinclair 2020-04-14 14:46:51 +00:00 committed by dan sinclair
parent 2a3e79cf8c
commit efb5d4e10f
19 changed files with 4 additions and 539 deletions

View File

@ -94,8 +94,6 @@ source_set("libtint") {
"src/ast/nop_statement.h", "src/ast/nop_statement.h",
"src/ast/pipeline_stage.cc", "src/ast/pipeline_stage.cc",
"src/ast/pipeline_stage.h", "src/ast/pipeline_stage.h",
"src/ast/regardless_statement.cc",
"src/ast/regardless_statement.h",
"src/ast/return_statement.cc", "src/ast/return_statement.cc",
"src/ast/return_statement.h", "src/ast/return_statement.h",
"src/ast/scalar_constructor_expression.cc", "src/ast/scalar_constructor_expression.cc",

View File

@ -107,8 +107,6 @@ set(TINT_LIB_SRCS
ast/nop_statement.h ast/nop_statement.h
ast/pipeline_stage.cc ast/pipeline_stage.cc
ast/pipeline_stage.h ast/pipeline_stage.h
ast/regardless_statement.cc
ast/regardless_statement.h
ast/return_statement.cc ast/return_statement.cc
ast/return_statement.h ast/return_statement.h
ast/scalar_constructor_expression.cc ast/scalar_constructor_expression.cc
@ -282,7 +280,6 @@ set(TINT_TEST_SRCS
ast/member_accessor_expression_test.cc ast/member_accessor_expression_test.cc
ast/module_test.cc ast/module_test.cc
ast/nop_statement_test.cc ast/nop_statement_test.cc
ast/regardless_statement_test.cc
ast/binary_expression_test.cc ast/binary_expression_test.cc
ast/return_statement_test.cc ast/return_statement_test.cc
ast/scalar_constructor_expression_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_postfix_expression_test.cc
reader/wgsl/parser_impl_premerge_stmt_test.cc reader/wgsl/parser_impl_premerge_stmt_test.cc
reader/wgsl/parser_impl_primary_expression_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_relational_expression_test.cc
reader/wgsl/parser_impl_shift_expression_test.cc reader/wgsl/parser_impl_shift_expression_test.cc
reader/wgsl/parser_impl_statement_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_loop_test.cc
writer/wgsl/generator_impl_member_accessor_test.cc writer/wgsl/generator_impl_member_accessor_test.cc
writer/wgsl/generator_impl_nop_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_relational_test.cc
writer/wgsl/generator_impl_return_test.cc writer/wgsl/generator_impl_return_test.cc
writer/wgsl/generator_impl_switch_test.cc writer/wgsl/generator_impl_switch_test.cc

View File

@ -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<Expression> condition,
StatementList body)
: Statement(), condition_(std::move(condition)), body_(std::move(body)) {}
RegardlessStatement::RegardlessStatement(const Source& source,
std::unique_ptr<Expression> 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

View File

@ -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 <memory>
#include <utility>
#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<Expression> 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<Expression> condition,
StatementList body);
/// Move constructor
RegardlessStatement(RegardlessStatement&&);
~RegardlessStatement() override;
/// Sets the condition expression
/// @param condition the condition expression
void set_condition(std::unique_ptr<Expression> 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<Expression> condition_;
StatementList body_;
};
} // namespace ast
} // namespace tint
#endif // SRC_AST_REGARDLESS_STATEMENT_H_

View File

@ -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 <sstream>
#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<IdentifierExpression>("ident");
StatementList stmts;
stmts.push_back(std::make_unique<KillStatement>());
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<IdentifierExpression>("ident");
StatementList stmts;
stmts.push_back(std::make_unique<KillStatement>());
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<IdentifierExpression>("ident");
StatementList stmts;
stmts.push_back(std::make_unique<KillStatement>());
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<KillStatement>());
RegardlessStatement r;
r.set_body(std::move(stmts));
EXPECT_FALSE(r.IsValid());
}
TEST_F(RegardlessStatementTest, IsValid_InvalidCondition) {
auto ident = std::make_unique<IdentifierExpression>("");
StatementList stmts;
stmts.push_back(std::make_unique<KillStatement>());
RegardlessStatement r(std::move(ident), std::move(stmts));
EXPECT_FALSE(r.IsValid());
}
TEST_F(RegardlessStatementTest, IsValid_NullBodyStatement) {
auto ident = std::make_unique<IdentifierExpression>("ident");
StatementList stmts;
stmts.push_back(std::make_unique<KillStatement>());
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<IdentifierExpression>("ident");
StatementList stmts;
stmts.push_back(std::make_unique<KillStatement>());
stmts.push_back(std::make_unique<IfStatement>());
RegardlessStatement r(std::move(ident), std::move(stmts));
EXPECT_FALSE(r.IsValid());
}
TEST_F(RegardlessStatementTest, ToStr) {
auto ident = std::make_unique<IdentifierExpression>("ident");
StatementList stmts;
stmts.push_back(std::make_unique<KillStatement>());
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

View File

@ -26,7 +26,6 @@
#include "src/ast/kill_statement.h" #include "src/ast/kill_statement.h"
#include "src/ast/loop_statement.h" #include "src/ast/loop_statement.h"
#include "src/ast/nop_statement.h" #include "src/ast/nop_statement.h"
#include "src/ast/regardless_statement.h"
#include "src/ast/return_statement.h" #include "src/ast/return_statement.h"
#include "src/ast/switch_statement.h" #include "src/ast/switch_statement.h"
#include "src/ast/unless_statement.h" #include "src/ast/unless_statement.h"
@ -83,10 +82,6 @@ bool Statement::IsNop() const {
return false; return false;
} }
bool Statement::IsRegardless() const {
return false;
}
bool Statement::IsReturn() const { bool Statement::IsReturn() const {
return false; return false;
} }
@ -153,11 +148,6 @@ NopStatement* Statement::AsNop() {
return static_cast<NopStatement*>(this); return static_cast<NopStatement*>(this);
} }
RegardlessStatement* Statement::AsRegardless() {
assert(IsRegardless());
return static_cast<RegardlessStatement*>(this);
}
ReturnStatement* Statement::AsReturn() { ReturnStatement* Statement::AsReturn() {
assert(IsReturn()); assert(IsReturn());
return static_cast<ReturnStatement*>(this); return static_cast<ReturnStatement*>(this);

View File

@ -33,7 +33,6 @@ class IfStatement;
class KillStatement; class KillStatement;
class LoopStatement; class LoopStatement;
class NopStatement; class NopStatement;
class RegardlessStatement;
class ReturnStatement; class ReturnStatement;
class SwitchStatement; class SwitchStatement;
class UnlessStatement; class UnlessStatement;
@ -64,8 +63,6 @@ class Statement : public Node {
virtual bool IsLoop() const; virtual bool IsLoop() const;
/// @returns true if this is a nop statement /// @returns true if this is a nop statement
virtual bool IsNop() const; virtual bool IsNop() const;
/// @returns true if this is an regardless statement
virtual bool IsRegardless() const;
/// @returns true if this is a return statement /// @returns true if this is a return statement
virtual bool IsReturn() const; virtual bool IsReturn() const;
/// @returns true if this is a switch statement /// @returns true if this is a switch statement
@ -95,8 +92,6 @@ class Statement : public Node {
LoopStatement* AsLoop(); LoopStatement* AsLoop();
/// @returns the statement as a nop statement /// @returns the statement as a nop statement
NopStatement* AsNop(); NopStatement* AsNop();
/// @returns the statement as an regardless statement
RegardlessStatement* AsRegardless();
/// @returns the statement as a return statement /// @returns the statement as a return statement
ReturnStatement* AsReturn(); ReturnStatement* AsReturn();
/// @returns the statement as a switch statement /// @returns the statement as a switch statement

View File

@ -606,8 +606,6 @@ Token Lexer::check_keyword(const Source& source, const std::string& str) {
return {Token::Type::kPtr, source, "ptr"}; return {Token::Type::kPtr, source, "ptr"};
if (str == "push_constant") if (str == "push_constant")
return {Token::Type::kPushConstant, source, "push_constant"}; return {Token::Type::kPushConstant, source, "push_constant"};
if (str == "regardless")
return {Token::Type::kRegardless, source, "regardless"};
if (str == "return") if (str == "return")
return {Token::Type::kReturn, source, "return"}; return {Token::Type::kReturn, source, "return"};
if (str == "set") if (str == "set")
@ -683,7 +681,8 @@ Token Lexer::check_reserved(const Source& source, const std::string& str) {
return {Token::Type::kReservedKeyword, source, "u16"}; return {Token::Type::kReservedKeyword, source, "u16"};
if (str == "u64") if (str == "u64")
return {Token::Type::kReservedKeyword, source, "u64"}; return {Token::Type::kReservedKeyword, source, "u64"};
if (str == "regardless")
return {Token::Type::kReservedKeyword, source, "regardless"};
return {}; return {};
} }

View File

@ -478,7 +478,6 @@ INSTANTIATE_TEST_SUITE_P(
TokenData{"private", Token::Type::kPrivate}, TokenData{"private", Token::Type::kPrivate},
TokenData{"ptr", Token::Type::kPtr}, TokenData{"ptr", Token::Type::kPtr},
TokenData{"push_constant", Token::Type::kPushConstant}, TokenData{"push_constant", Token::Type::kPushConstant},
TokenData{"regardless", Token::Type::kRegardless},
TokenData{"return", Token::Type::kReturn}, TokenData{"return", Token::Type::kReturn},
TokenData{"set", Token::Type::kSet}, TokenData{"set", Token::Type::kSet},
TokenData{"storage_buffer", Token::Type::kStorageBuffer}, TokenData{"storage_buffer", Token::Type::kStorageBuffer},
@ -525,7 +524,8 @@ INSTANTIATE_TEST_SUITE_P(LexerTest,
"typedef", "typedef",
"u8", "u8",
"u16", "u16",
"u64")); "u64",
"regardless"));
} // namespace } // namespace
} // namespace wgsl } // namespace wgsl

View File

@ -1449,7 +1449,6 @@ ast::StatementList ParserImpl::statements() {
// | RETURN logical_or_expression SEMICOLON // | RETURN logical_or_expression SEMICOLON
// | if_stmt // | if_stmt
// | unless_stmt // | unless_stmt
// | regardless_stmt
// | switch_stmt // | switch_stmt
// | loop_stmt // | loop_stmt
// | variable_stmt SEMICOLON // | variable_stmt SEMICOLON
@ -1498,12 +1497,6 @@ std::unique_ptr<ast::Statement> ParserImpl::statement() {
if (unless != nullptr) if (unless != nullptr)
return unless; return unless;
auto regardless = regardless_stmt();
if (has_error())
return nullptr;
if (regardless != nullptr)
return regardless;
auto sw = switch_stmt(); auto sw = switch_stmt();
if (has_error()) if (has_error())
return nullptr; return nullptr;
@ -1880,32 +1873,6 @@ std::unique_ptr<ast::UnlessStatement> ParserImpl::unless_stmt() {
std::move(body)); std::move(body));
} }
// regardless_stmt
// : REGARDLESS paren_rhs_stmt body_stmt
std::unique_ptr<ast::RegardlessStatement> 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<ast::RegardlessStatement>(
source, std::move(condition), std::move(body));
}
// switch_stmt // switch_stmt
// : SWITCH paren_rhs_stmt BRACKET_LEFT switch_body+ BRACKET_RIGHT // : SWITCH paren_rhs_stmt BRACKET_LEFT switch_body+ BRACKET_RIGHT
std::unique_ptr<ast::SwitchStatement> ParserImpl::switch_stmt() { std::unique_ptr<ast::SwitchStatement> ParserImpl::switch_stmt() {

View File

@ -33,7 +33,6 @@
#include "src/ast/loop_statement.h" #include "src/ast/loop_statement.h"
#include "src/ast/module.h" #include "src/ast/module.h"
#include "src/ast/pipeline_stage.h" #include "src/ast/pipeline_stage.h"
#include "src/ast/regardless_statement.h"
#include "src/ast/statement.h" #include "src/ast/statement.h"
#include "src/ast/storage_class.h" #include "src/ast/storage_class.h"
#include "src/ast/struct.h" #include "src/ast/struct.h"
@ -215,9 +214,6 @@ class ParserImpl {
/// Parses a `unless_stmt` grammar element /// Parses a `unless_stmt` grammar element
/// @returns the parsed element or nullptr /// @returns the parsed element or nullptr
std::unique_ptr<ast::UnlessStatement> unless_stmt(); std::unique_ptr<ast::UnlessStatement> unless_stmt();
/// Parses a `regardless_stmt` grammar element
/// @returns the parsed element or nullptr
std::unique_ptr<ast::RegardlessStatement> regardless_stmt();
/// Parses a `switch_stmt` grammar element /// Parses a `switch_stmt` grammar element
/// @returns the parsed statement or nullptr /// @returns the parsed statement or nullptr
std::unique_ptr<ast::SwitchStatement> switch_stmt(); std::unique_ptr<ast::SwitchStatement> switch_stmt();

View File

@ -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

View File

@ -109,22 +109,6 @@ TEST_F(ParserImplTest, Statement_Unless_Invalid) {
EXPECT_EQ(p->error(), "1:9: unable to parse expression"); 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) { TEST_F(ParserImplTest, Statement_Variable) {
auto p = parser("var a : i32 = 1;"); auto p = parser("var a : i32 = 1;");
auto e = p->statement(); auto e = p->statement();

View File

@ -569,8 +569,6 @@ class Token {
bool IsPtr() const { return type_ == Type::kPtr; } bool IsPtr() const { return type_ == Type::kPtr; }
/// @returns true if token is a 'push_constant' /// @returns true if token is a 'push_constant'
bool IsPushConstant() const { return type_ == Type::kPushConstant; } 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' /// @returns true if token is a 'return'
bool IsReturn() const { return type_ == Type::kReturn; } bool IsReturn() const { return type_ == Type::kReturn; }
/// @returns true if token is a 'set' /// @returns true if token is a 'set'

View File

@ -30,7 +30,6 @@
#include "src/ast/if_statement.h" #include "src/ast/if_statement.h"
#include "src/ast/loop_statement.h" #include "src/ast/loop_statement.h"
#include "src/ast/member_accessor_expression.h" #include "src/ast/member_accessor_expression.h"
#include "src/ast/regardless_statement.h"
#include "src/ast/return_statement.h" #include "src/ast/return_statement.h"
#include "src/ast/scalar_constructor_expression.h" #include "src/ast/scalar_constructor_expression.h"
#include "src/ast/switch_statement.h" #include "src/ast/switch_statement.h"
@ -183,11 +182,6 @@ bool TypeDeterminer::DetermineResultType(ast::Statement* stmt) {
if (stmt->IsNop()) { if (stmt->IsNop()) {
return true; return true;
} }
if (stmt->IsRegardless()) {
auto* r = stmt->AsRegardless();
return DetermineResultType(r->condition()) &&
DetermineStatements(r->body());
}
if (stmt->IsReturn()) { if (stmt->IsReturn()) {
auto* r = stmt->AsReturn(); auto* r = stmt->AsReturn();
return DetermineResultType(r->value()); return DetermineResultType(r->value());

View File

@ -35,7 +35,6 @@
#include "src/ast/int_literal.h" #include "src/ast/int_literal.h"
#include "src/ast/loop_statement.h" #include "src/ast/loop_statement.h"
#include "src/ast/member_accessor_expression.h" #include "src/ast/member_accessor_expression.h"
#include "src/ast/regardless_statement.h"
#include "src/ast/return_statement.h" #include "src/ast/return_statement.h"
#include "src/ast/scalar_constructor_expression.h" #include "src/ast/scalar_constructor_expression.h"
#include "src/ast/struct.h" #include "src/ast/struct.h"
@ -310,36 +309,6 @@ TEST_F(TypeDeterminerTest, Stmt_Loop) {
EXPECT_TRUE(continuing_rhs_ptr->result_type()->IsF32()); 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<ast::ScalarConstructorExpression>(
std::make_unique<ast::IntLiteral>(&i32, 2));
auto lhs_ptr = lhs.get();
auto rhs = std::make_unique<ast::ScalarConstructorExpression>(
std::make_unique<ast::FloatLiteral>(&f32, 2.3f));
auto rhs_ptr = rhs.get();
ast::StatementList body;
body.push_back(std::make_unique<ast::AssignmentStatement>(std::move(lhs),
std::move(rhs)));
ast::RegardlessStatement regardless(
std::make_unique<ast::ScalarConstructorExpression>(
std::make_unique<ast::IntLiteral>(&i32, 3)),
std::move(body));
EXPECT_TRUE(td()->DetermineResultType(&regardless));
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) { TEST_F(TypeDeterminerTest, Stmt_Return) {
ast::type::I32Type i32; ast::type::I32Type i32;

View File

@ -39,7 +39,6 @@
#include "src/ast/location_decoration.h" #include "src/ast/location_decoration.h"
#include "src/ast/loop_statement.h" #include "src/ast/loop_statement.h"
#include "src/ast/member_accessor_expression.h" #include "src/ast/member_accessor_expression.h"
#include "src/ast/regardless_statement.h"
#include "src/ast/return_statement.h" #include "src/ast/return_statement.h"
#include "src/ast/scalar_constructor_expression.h" #include "src/ast/scalar_constructor_expression.h"
#include "src/ast/set_decoration.h" #include "src/ast/set_decoration.h"
@ -742,9 +741,6 @@ bool GeneratorImpl::EmitStatement(ast::Statement* stmt) {
if (stmt->IsNop()) { if (stmt->IsNop()) {
return EmitNop(stmt->AsNop()); return EmitNop(stmt->AsNop());
} }
if (stmt->IsRegardless()) {
return EmitRegardless(stmt->AsRegardless());
}
if (stmt->IsReturn()) { if (stmt->IsReturn()) {
return EmitReturn(stmt->AsReturn()); return EmitReturn(stmt->AsReturn());
} }
@ -932,18 +928,6 @@ bool GeneratorImpl::EmitNop(ast::NopStatement*) {
return true; 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) { bool GeneratorImpl::EmitReturn(ast::ReturnStatement* stmt) {
make_indent(); make_indent();

View File

@ -166,10 +166,6 @@ class GeneratorImpl {
/// @param stmt the nop statement /// @param stmt the nop statement
/// @returns true if the statement was successfully emitted /// @returns true if the statement was successfully emitted
bool EmitNop(ast::NopStatement* stmt); 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 /// Handles return statements
/// @param stmt the statement to emit /// @param stmt the statement to emit
/// @returns true if the statement was successfully emitted /// @returns true if the statement was successfully emitted

View File

@ -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 <memory>
#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<ast::IdentifierExpression>("cond");
ast::StatementList body;
body.push_back(std::make_unique<ast::NopStatement>());
body.push_back(std::make_unique<ast::KillStatement>());
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