Remove unless_stmt
The `unless` statement was removed from the WGSL grammar so remove it from Tint. Change-Id: I31a185f5c5e3e88b667caea1c9a88aee80c0b810 Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/22581 Reviewed-by: Ryan Harrison <rharrison@chromium.org>
This commit is contained in:
parent
6bd7061a2e
commit
2b23e4bd70
5
BUILD.gn
5
BUILD.gn
|
@ -324,8 +324,6 @@ source_set("libtint_core_src") {
|
||||||
"src/ast/unary_op.h",
|
"src/ast/unary_op.h",
|
||||||
"src/ast/unary_op_expression.cc",
|
"src/ast/unary_op_expression.cc",
|
||||||
"src/ast/unary_op_expression.h",
|
"src/ast/unary_op_expression.h",
|
||||||
"src/ast/unless_statement.cc",
|
|
||||||
"src/ast/unless_statement.h",
|
|
||||||
"src/ast/variable.cc",
|
"src/ast/variable.cc",
|
||||||
"src/ast/variable.h",
|
"src/ast/variable.h",
|
||||||
"src/ast/variable_decl_statement.cc",
|
"src/ast/variable_decl_statement.cc",
|
||||||
|
@ -615,7 +613,6 @@ source_set("tint_unittests_core_src") {
|
||||||
"src/ast/type_constructor_expression_test.cc",
|
"src/ast/type_constructor_expression_test.cc",
|
||||||
"src/ast/uint_literal_test.cc",
|
"src/ast/uint_literal_test.cc",
|
||||||
"src/ast/unary_op_expression_test.cc",
|
"src/ast/unary_op_expression_test.cc",
|
||||||
"src/ast/unless_statement_test.cc",
|
|
||||||
"src/ast/variable_decl_statement_test.cc",
|
"src/ast/variable_decl_statement_test.cc",
|
||||||
"src/ast/variable_test.cc",
|
"src/ast/variable_test.cc",
|
||||||
"src/scope_stack_test.cc",
|
"src/scope_stack_test.cc",
|
||||||
|
@ -771,7 +768,6 @@ source_set("tint_unittests_wgsl_reader_src") {
|
||||||
"src/reader/wgsl/parser_impl_type_alias_test.cc",
|
"src/reader/wgsl/parser_impl_type_alias_test.cc",
|
||||||
"src/reader/wgsl/parser_impl_type_decl_test.cc",
|
"src/reader/wgsl/parser_impl_type_decl_test.cc",
|
||||||
"src/reader/wgsl/parser_impl_unary_expression_test.cc",
|
"src/reader/wgsl/parser_impl_unary_expression_test.cc",
|
||||||
"src/reader/wgsl/parser_impl_unless_stmt_test.cc",
|
|
||||||
"src/reader/wgsl/parser_impl_variable_decl_test.cc",
|
"src/reader/wgsl/parser_impl_variable_decl_test.cc",
|
||||||
"src/reader/wgsl/parser_impl_variable_decoration_list_test.cc",
|
"src/reader/wgsl/parser_impl_variable_decoration_list_test.cc",
|
||||||
"src/reader/wgsl/parser_impl_variable_decoration_test.cc",
|
"src/reader/wgsl/parser_impl_variable_decoration_test.cc",
|
||||||
|
@ -822,7 +818,6 @@ source_set("tint_unittests_wgsl_writer_src") {
|
||||||
"src/writer/wgsl/generator_impl_type_test.cc",
|
"src/writer/wgsl/generator_impl_type_test.cc",
|
||||||
"src/writer/wgsl/generator_impl_unary_method_test.cc",
|
"src/writer/wgsl/generator_impl_unary_method_test.cc",
|
||||||
"src/writer/wgsl/generator_impl_unary_op_test.cc",
|
"src/writer/wgsl/generator_impl_unary_op_test.cc",
|
||||||
"src/writer/wgsl/generator_impl_unless_test.cc",
|
|
||||||
"src/writer/wgsl/generator_impl_variable_decl_statement_test.cc",
|
"src/writer/wgsl/generator_impl_variable_decl_statement_test.cc",
|
||||||
"src/writer/wgsl/generator_impl_variable_test.cc",
|
"src/writer/wgsl/generator_impl_variable_test.cc",
|
||||||
]
|
]
|
||||||
|
|
|
@ -161,8 +161,6 @@ set(TINT_LIB_SRCS
|
||||||
ast/unary_op.h
|
ast/unary_op.h
|
||||||
ast/unary_op_expression.cc
|
ast/unary_op_expression.cc
|
||||||
ast/unary_op_expression.h
|
ast/unary_op_expression.h
|
||||||
ast/unless_statement.cc
|
|
||||||
ast/unless_statement.h
|
|
||||||
ast/variable.cc
|
ast/variable.cc
|
||||||
ast/variable.h
|
ast/variable.h
|
||||||
ast/variable_decoration.cc
|
ast/variable_decoration.cc
|
||||||
|
@ -295,7 +293,6 @@ set(TINT_TEST_SRCS
|
||||||
ast/type_constructor_expression_test.cc
|
ast/type_constructor_expression_test.cc
|
||||||
ast/uint_literal_test.cc
|
ast/uint_literal_test.cc
|
||||||
ast/unary_op_expression_test.cc
|
ast/unary_op_expression_test.cc
|
||||||
ast/unless_statement_test.cc
|
|
||||||
ast/variable_decl_statement_test.cc
|
ast/variable_decl_statement_test.cc
|
||||||
ast/variable_test.cc
|
ast/variable_test.cc
|
||||||
scope_stack_test.cc
|
scope_stack_test.cc
|
||||||
|
@ -400,7 +397,6 @@ if(${TINT_BUILD_WGSL_READER})
|
||||||
reader/wgsl/parser_impl_type_alias_test.cc
|
reader/wgsl/parser_impl_type_alias_test.cc
|
||||||
reader/wgsl/parser_impl_type_decl_test.cc
|
reader/wgsl/parser_impl_type_decl_test.cc
|
||||||
reader/wgsl/parser_impl_unary_expression_test.cc
|
reader/wgsl/parser_impl_unary_expression_test.cc
|
||||||
reader/wgsl/parser_impl_unless_stmt_test.cc
|
|
||||||
reader/wgsl/parser_impl_variable_decl_test.cc
|
reader/wgsl/parser_impl_variable_decl_test.cc
|
||||||
reader/wgsl/parser_impl_variable_decoration_list_test.cc
|
reader/wgsl/parser_impl_variable_decoration_list_test.cc
|
||||||
reader/wgsl/parser_impl_variable_decoration_test.cc
|
reader/wgsl/parser_impl_variable_decoration_test.cc
|
||||||
|
@ -469,7 +465,6 @@ if(${TINT_BUILD_WGSL_WRITER})
|
||||||
writer/wgsl/generator_impl_switch_test.cc
|
writer/wgsl/generator_impl_switch_test.cc
|
||||||
writer/wgsl/generator_impl_type_test.cc
|
writer/wgsl/generator_impl_type_test.cc
|
||||||
writer/wgsl/generator_impl_unary_op_test.cc
|
writer/wgsl/generator_impl_unary_op_test.cc
|
||||||
writer/wgsl/generator_impl_unless_test.cc
|
|
||||||
writer/wgsl/generator_impl_variable_decl_statement_test.cc
|
writer/wgsl/generator_impl_variable_decl_statement_test.cc
|
||||||
writer/wgsl/generator_impl_variable_test.cc
|
writer/wgsl/generator_impl_variable_test.cc
|
||||||
)
|
)
|
||||||
|
|
|
@ -27,7 +27,6 @@
|
||||||
#include "src/ast/loop_statement.h"
|
#include "src/ast/loop_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/variable_decl_statement.h"
|
#include "src/ast/variable_decl_statement.h"
|
||||||
|
|
||||||
namespace tint {
|
namespace tint {
|
||||||
|
@ -85,10 +84,6 @@ bool Statement::IsSwitch() const {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Statement::IsUnless() const {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Statement::IsVariableDecl() const {
|
bool Statement::IsVariableDecl() const {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -148,11 +143,6 @@ const SwitchStatement* Statement::AsSwitch() const {
|
||||||
return static_cast<const SwitchStatement*>(this);
|
return static_cast<const SwitchStatement*>(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
const UnlessStatement* Statement::AsUnless() const {
|
|
||||||
assert(IsUnless());
|
|
||||||
return static_cast<const UnlessStatement*>(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
const VariableDeclStatement* Statement::AsVariableDecl() const {
|
const VariableDeclStatement* Statement::AsVariableDecl() const {
|
||||||
assert(IsVariableDecl());
|
assert(IsVariableDecl());
|
||||||
return static_cast<const VariableDeclStatement*>(this);
|
return static_cast<const VariableDeclStatement*>(this);
|
||||||
|
@ -213,11 +203,6 @@ SwitchStatement* Statement::AsSwitch() {
|
||||||
return static_cast<SwitchStatement*>(this);
|
return static_cast<SwitchStatement*>(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
UnlessStatement* Statement::AsUnless() {
|
|
||||||
assert(IsUnless());
|
|
||||||
return static_cast<UnlessStatement*>(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
VariableDeclStatement* Statement::AsVariableDecl() {
|
VariableDeclStatement* Statement::AsVariableDecl() {
|
||||||
assert(IsVariableDecl());
|
assert(IsVariableDecl());
|
||||||
return static_cast<VariableDeclStatement*>(this);
|
return static_cast<VariableDeclStatement*>(this);
|
||||||
|
|
|
@ -34,7 +34,6 @@ class KillStatement;
|
||||||
class LoopStatement;
|
class LoopStatement;
|
||||||
class ReturnStatement;
|
class ReturnStatement;
|
||||||
class SwitchStatement;
|
class SwitchStatement;
|
||||||
class UnlessStatement;
|
|
||||||
class VariableDeclStatement;
|
class VariableDeclStatement;
|
||||||
|
|
||||||
/// Base statement class
|
/// Base statement class
|
||||||
|
@ -64,8 +63,6 @@ class Statement : public Node {
|
||||||
virtual bool IsReturn() const;
|
virtual bool IsReturn() const;
|
||||||
/// @returns true if this is a switch statement
|
/// @returns true if this is a switch statement
|
||||||
virtual bool IsSwitch() const;
|
virtual bool IsSwitch() const;
|
||||||
/// @returns true if this is an unless statement
|
|
||||||
virtual bool IsUnless() const;
|
|
||||||
/// @returns true if this is an variable statement
|
/// @returns true if this is an variable statement
|
||||||
virtual bool IsVariableDecl() const;
|
virtual bool IsVariableDecl() const;
|
||||||
|
|
||||||
|
@ -91,8 +88,6 @@ class Statement : public Node {
|
||||||
const ReturnStatement* AsReturn() const;
|
const ReturnStatement* AsReturn() const;
|
||||||
/// @returns the statement as a const switch statement
|
/// @returns the statement as a const switch statement
|
||||||
const SwitchStatement* AsSwitch() const;
|
const SwitchStatement* AsSwitch() const;
|
||||||
/// @returns the statement as a const unless statement
|
|
||||||
const UnlessStatement* AsUnless() const;
|
|
||||||
/// @returns the statement as a const variable statement
|
/// @returns the statement as a const variable statement
|
||||||
const VariableDeclStatement* AsVariableDecl() const;
|
const VariableDeclStatement* AsVariableDecl() const;
|
||||||
|
|
||||||
|
@ -118,8 +113,6 @@ class Statement : public Node {
|
||||||
ReturnStatement* AsReturn();
|
ReturnStatement* AsReturn();
|
||||||
/// @returns the statement as a switch statement
|
/// @returns the statement as a switch statement
|
||||||
SwitchStatement* AsSwitch();
|
SwitchStatement* AsSwitch();
|
||||||
/// @returns the statement as an unless statement
|
|
||||||
UnlessStatement* AsUnless();
|
|
||||||
/// @returns the statement as an variable statement
|
/// @returns the statement as an variable statement
|
||||||
VariableDeclStatement* AsVariableDecl();
|
VariableDeclStatement* AsVariableDecl();
|
||||||
|
|
||||||
|
|
|
@ -1,79 +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/unless_statement.h"
|
|
||||||
|
|
||||||
namespace tint {
|
|
||||||
namespace ast {
|
|
||||||
|
|
||||||
UnlessStatement::UnlessStatement() : Statement() {}
|
|
||||||
|
|
||||||
UnlessStatement::UnlessStatement(std::unique_ptr<Expression> condition,
|
|
||||||
StatementList body)
|
|
||||||
: Statement(), condition_(std::move(condition)), body_(std::move(body)) {}
|
|
||||||
|
|
||||||
UnlessStatement::UnlessStatement(const Source& source,
|
|
||||||
std::unique_ptr<Expression> condition,
|
|
||||||
StatementList body)
|
|
||||||
: Statement(source),
|
|
||||||
condition_(std::move(condition)),
|
|
||||||
body_(std::move(body)) {}
|
|
||||||
|
|
||||||
UnlessStatement::UnlessStatement(UnlessStatement&&) = default;
|
|
||||||
|
|
||||||
UnlessStatement::~UnlessStatement() = default;
|
|
||||||
|
|
||||||
bool UnlessStatement::IsUnless() const {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool UnlessStatement::IsValid() const {
|
|
||||||
if (condition_ == nullptr || !condition_->IsValid()) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
for (const auto& stmt : body_) {
|
|
||||||
if (stmt == nullptr || !stmt->IsValid()) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
void UnlessStatement::to_str(std::ostream& out, size_t indent) const {
|
|
||||||
make_indent(out, indent);
|
|
||||||
out << "Unless{" << std::endl;
|
|
||||||
|
|
||||||
make_indent(out, indent + 2);
|
|
||||||
out << "(" << std::endl;
|
|
||||||
|
|
||||||
condition_->to_str(out, indent + 4);
|
|
||||||
|
|
||||||
make_indent(out, indent + 2);
|
|
||||||
out << ")" << std::endl;
|
|
||||||
|
|
||||||
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
|
|
|
@ -1,82 +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_UNLESS_STATEMENT_H_
|
|
||||||
#define SRC_AST_UNLESS_STATEMENT_H_
|
|
||||||
|
|
||||||
#include <memory>
|
|
||||||
#include <utility>
|
|
||||||
|
|
||||||
#include "src/ast/expression.h"
|
|
||||||
#include "src/ast/statement.h"
|
|
||||||
|
|
||||||
namespace tint {
|
|
||||||
namespace ast {
|
|
||||||
|
|
||||||
/// A unless statement
|
|
||||||
class UnlessStatement : public Statement {
|
|
||||||
public:
|
|
||||||
/// Constructor
|
|
||||||
UnlessStatement();
|
|
||||||
/// Constructor
|
|
||||||
/// @param condition the condition expression
|
|
||||||
/// @param body the body statements
|
|
||||||
UnlessStatement(std::unique_ptr<Expression> condition, StatementList body);
|
|
||||||
/// Constructor
|
|
||||||
/// @param source the unless statement source
|
|
||||||
/// @param condition the condition expression
|
|
||||||
/// @param body the body statements
|
|
||||||
UnlessStatement(const Source& source,
|
|
||||||
std::unique_ptr<Expression> condition,
|
|
||||||
StatementList body);
|
|
||||||
/// Move constructor
|
|
||||||
UnlessStatement(UnlessStatement&&);
|
|
||||||
~UnlessStatement() 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 unless statement
|
|
||||||
bool IsUnless() 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:
|
|
||||||
UnlessStatement(const UnlessStatement&) = delete;
|
|
||||||
|
|
||||||
std::unique_ptr<Expression> condition_;
|
|
||||||
StatementList body_;
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace ast
|
|
||||||
} // namespace tint
|
|
||||||
|
|
||||||
#endif // SRC_AST_UNLESS_STATEMENT_H_
|
|
|
@ -1,126 +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/unless_statement.h"
|
|
||||||
|
|
||||||
#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 UnlessStatementTest = testing::Test;
|
|
||||||
|
|
||||||
TEST_F(UnlessStatementTest, Creation) {
|
|
||||||
auto ident = std::make_unique<IdentifierExpression>("ident");
|
|
||||||
StatementList body;
|
|
||||||
body.push_back(std::make_unique<KillStatement>());
|
|
||||||
|
|
||||||
auto* ident_ptr = ident.get();
|
|
||||||
auto* kill_ptr = body[0].get();
|
|
||||||
|
|
||||||
UnlessStatement u(std::move(ident), std::move(body));
|
|
||||||
EXPECT_EQ(u.condition(), ident_ptr);
|
|
||||||
ASSERT_EQ(u.body().size(), 1u);
|
|
||||||
EXPECT_EQ(u.body()[0].get(), kill_ptr);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(UnlessStatementTest, Creation_WithSource) {
|
|
||||||
auto ident = std::make_unique<IdentifierExpression>("ident");
|
|
||||||
StatementList body;
|
|
||||||
body.push_back(std::make_unique<KillStatement>());
|
|
||||||
|
|
||||||
UnlessStatement u(Source{20, 2}, std::move(ident), std::move(body));
|
|
||||||
auto src = u.source();
|
|
||||||
EXPECT_EQ(src.line, 20u);
|
|
||||||
EXPECT_EQ(src.column, 2u);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(UnlessStatementTest, IsUnless) {
|
|
||||||
UnlessStatement stmt;
|
|
||||||
EXPECT_TRUE(stmt.IsUnless());
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(UnlessStatementTest, IsValid) {
|
|
||||||
auto ident = std::make_unique<IdentifierExpression>("ident");
|
|
||||||
StatementList body;
|
|
||||||
body.push_back(std::make_unique<KillStatement>());
|
|
||||||
|
|
||||||
UnlessStatement u(std::move(ident), std::move(body));
|
|
||||||
EXPECT_TRUE(u.IsValid());
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(UnlessStatementTest, IsValid_NullCondition) {
|
|
||||||
StatementList body;
|
|
||||||
body.push_back(std::make_unique<KillStatement>());
|
|
||||||
|
|
||||||
UnlessStatement u;
|
|
||||||
u.set_body(std::move(body));
|
|
||||||
EXPECT_FALSE(u.IsValid());
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(UnlessStatementTest, IsValid_InvalidCondition) {
|
|
||||||
auto ident = std::make_unique<IdentifierExpression>("");
|
|
||||||
StatementList body;
|
|
||||||
body.push_back(std::make_unique<KillStatement>());
|
|
||||||
|
|
||||||
UnlessStatement u(std::move(ident), std::move(body));
|
|
||||||
EXPECT_FALSE(u.IsValid());
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(UnlessStatementTest, IsValid_NullBodyStatement) {
|
|
||||||
auto ident = std::make_unique<IdentifierExpression>("ident");
|
|
||||||
StatementList body;
|
|
||||||
body.push_back(std::make_unique<KillStatement>());
|
|
||||||
body.push_back(nullptr);
|
|
||||||
|
|
||||||
UnlessStatement u(std::move(ident), std::move(body));
|
|
||||||
EXPECT_FALSE(u.IsValid());
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(UnlessStatementTest, IsValid_InvalidBodyStatement) {
|
|
||||||
auto ident = std::make_unique<IdentifierExpression>("ident");
|
|
||||||
StatementList body;
|
|
||||||
body.push_back(std::make_unique<KillStatement>());
|
|
||||||
body.push_back(std::make_unique<IfStatement>());
|
|
||||||
|
|
||||||
UnlessStatement u(std::move(ident), std::move(body));
|
|
||||||
EXPECT_FALSE(u.IsValid());
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(UnlessStatementTest, ToStr) {
|
|
||||||
auto ident = std::make_unique<IdentifierExpression>("ident");
|
|
||||||
StatementList body;
|
|
||||||
body.push_back(std::make_unique<KillStatement>());
|
|
||||||
|
|
||||||
UnlessStatement u(std::move(ident), std::move(body));
|
|
||||||
std::ostringstream out;
|
|
||||||
u.to_str(out, 2);
|
|
||||||
EXPECT_EQ(out.str(), R"( Unless{
|
|
||||||
(
|
|
||||||
Identifier{ident}
|
|
||||||
)
|
|
||||||
{
|
|
||||||
Kill{}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
)");
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace
|
|
||||||
} // namespace ast
|
|
||||||
} // namespace tint
|
|
|
@ -576,8 +576,6 @@ Token Lexer::check_keyword(const Source& source, const std::string& str) {
|
||||||
return {Token::Type::kUniform, source, "uniform"};
|
return {Token::Type::kUniform, source, "uniform"};
|
||||||
if (str == "uniform_constant")
|
if (str == "uniform_constant")
|
||||||
return {Token::Type::kUniformConstant, source, "uniform_constant"};
|
return {Token::Type::kUniformConstant, source, "uniform_constant"};
|
||||||
if (str == "unless")
|
|
||||||
return {Token::Type::kUnless, source, "unless"};
|
|
||||||
if (str == "var")
|
if (str == "var")
|
||||||
return {Token::Type::kVar, source, "var"};
|
return {Token::Type::kVar, source, "var"};
|
||||||
if (str == "vec2")
|
if (str == "vec2")
|
||||||
|
@ -621,6 +619,8 @@ Token Lexer::check_reserved(const Source& source, const std::string& str) {
|
||||||
return {Token::Type::kReservedKeyword, source, "let"};
|
return {Token::Type::kReservedKeyword, source, "let"};
|
||||||
if (str == "premerge")
|
if (str == "premerge")
|
||||||
return {Token::Type::kReservedKeyword, source, "premerge"};
|
return {Token::Type::kReservedKeyword, source, "premerge"};
|
||||||
|
if (str == "regardless")
|
||||||
|
return {Token::Type::kReservedKeyword, source, "regardless"};
|
||||||
if (str == "typedef")
|
if (str == "typedef")
|
||||||
return {Token::Type::kReservedKeyword, source, "typedef"};
|
return {Token::Type::kReservedKeyword, source, "typedef"};
|
||||||
if (str == "u8")
|
if (str == "u8")
|
||||||
|
@ -629,8 +629,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")
|
if (str == "unless")
|
||||||
return {Token::Type::kReservedKeyword, source, "regardless"};
|
return {Token::Type::kReservedKeyword, source, "unless"};
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -463,7 +463,6 @@ INSTANTIATE_TEST_SUITE_P(
|
||||||
TokenData{"uniform", Token::Type::kUniform},
|
TokenData{"uniform", Token::Type::kUniform},
|
||||||
TokenData{"uniform_constant",
|
TokenData{"uniform_constant",
|
||||||
Token::Type::kUniformConstant},
|
Token::Type::kUniformConstant},
|
||||||
TokenData{"unless", Token::Type::kUnless},
|
|
||||||
TokenData{"var", Token::Type::kVar},
|
TokenData{"var", Token::Type::kVar},
|
||||||
TokenData{"vec2", Token::Type::kVec2},
|
TokenData{"vec2", Token::Type::kVec2},
|
||||||
TokenData{"vec3", Token::Type::kVec3},
|
TokenData{"vec3", Token::Type::kVec3},
|
||||||
|
@ -499,6 +498,7 @@ INSTANTIATE_TEST_SUITE_P(LexerTest,
|
||||||
"u8",
|
"u8",
|
||||||
"u16",
|
"u16",
|
||||||
"u64",
|
"u64",
|
||||||
|
"unless",
|
||||||
"regardless"));
|
"regardless"));
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
|
@ -1420,7 +1420,6 @@ ast::StatementList ParserImpl::statements() {
|
||||||
// : SEMICOLON
|
// : SEMICOLON
|
||||||
// | return_stmt SEMICOLON
|
// | return_stmt SEMICOLON
|
||||||
// | if_stmt
|
// | if_stmt
|
||||||
// | unless_stmt
|
|
||||||
// | switch_stmt
|
// | switch_stmt
|
||||||
// | loop_stmt
|
// | loop_stmt
|
||||||
// | variable_stmt SEMICOLON
|
// | variable_stmt SEMICOLON
|
||||||
|
@ -1453,12 +1452,6 @@ std::unique_ptr<ast::Statement> ParserImpl::statement() {
|
||||||
if (stmt_if != nullptr)
|
if (stmt_if != nullptr)
|
||||||
return stmt_if;
|
return stmt_if;
|
||||||
|
|
||||||
auto unless = unless_stmt();
|
|
||||||
if (has_error())
|
|
||||||
return nullptr;
|
|
||||||
if (unless != nullptr)
|
|
||||||
return unless;
|
|
||||||
|
|
||||||
auto sw = switch_stmt();
|
auto sw = switch_stmt();
|
||||||
if (has_error())
|
if (has_error())
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
@ -1728,32 +1721,6 @@ std::unique_ptr<ast::ElseStatement> ParserImpl::else_stmt() {
|
||||||
return std::make_unique<ast::ElseStatement>(source, std::move(body));
|
return std::make_unique<ast::ElseStatement>(source, std::move(body));
|
||||||
}
|
}
|
||||||
|
|
||||||
// unless_stmt
|
|
||||||
// : UNLESS paren_rhs_stmt body_stmt
|
|
||||||
std::unique_ptr<ast::UnlessStatement> ParserImpl::unless_stmt() {
|
|
||||||
auto t = peek();
|
|
||||||
if (!t.IsUnless())
|
|
||||||
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 unless condition");
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto body = body_stmt();
|
|
||||||
if (has_error())
|
|
||||||
return nullptr;
|
|
||||||
|
|
||||||
return std::make_unique<ast::UnlessStatement>(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() {
|
||||||
|
|
|
@ -40,7 +40,6 @@
|
||||||
#include "src/ast/struct_member.h"
|
#include "src/ast/struct_member.h"
|
||||||
#include "src/ast/struct_member_decoration.h"
|
#include "src/ast/struct_member_decoration.h"
|
||||||
#include "src/ast/type/type.h"
|
#include "src/ast/type/type.h"
|
||||||
#include "src/ast/unless_statement.h"
|
|
||||||
#include "src/ast/variable.h"
|
#include "src/ast/variable.h"
|
||||||
#include "src/ast/variable_decoration.h"
|
#include "src/ast/variable_decoration.h"
|
||||||
#include "src/context.h"
|
#include "src/context.h"
|
||||||
|
@ -208,9 +207,6 @@ class ParserImpl {
|
||||||
/// Parses a `else_stmt` grammar element
|
/// Parses a `else_stmt` grammar element
|
||||||
/// @returns the parsed statement or nullptr
|
/// @returns the parsed statement or nullptr
|
||||||
std::unique_ptr<ast::ElseStatement> else_stmt();
|
std::unique_ptr<ast::ElseStatement> else_stmt();
|
||||||
/// Parses a `unless_stmt` grammar element
|
|
||||||
/// @returns the parsed element or nullptr
|
|
||||||
std::unique_ptr<ast::UnlessStatement> unless_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();
|
||||||
|
|
|
@ -93,22 +93,6 @@ TEST_F(ParserImplTest, Statement_If_Invalid) {
|
||||||
EXPECT_EQ(p->error(), "1:10: missing }");
|
EXPECT_EQ(p->error(), "1:10: missing }");
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(ParserImplTest, Statement_Unless) {
|
|
||||||
auto* p = parser("unless (a) {}");
|
|
||||||
auto e = p->statement();
|
|
||||||
ASSERT_FALSE(p->has_error()) << p->error();
|
|
||||||
ASSERT_NE(e, nullptr);
|
|
||||||
ASSERT_TRUE(e->IsUnless());
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(ParserImplTest, Statement_Unless_Invalid) {
|
|
||||||
auto* p = parser("unless () {}");
|
|
||||||
auto e = p->statement();
|
|
||||||
ASSERT_TRUE(p->has_error());
|
|
||||||
ASSERT_EQ(e, nullptr);
|
|
||||||
EXPECT_EQ(p->error(), "1:9: 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();
|
||||||
|
|
|
@ -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, UnlessStmt) {
|
|
||||||
auto* p = parser("unless (a) { kill; }");
|
|
||||||
auto e = p->unless_stmt();
|
|
||||||
ASSERT_FALSE(p->has_error()) << p->error();
|
|
||||||
ASSERT_NE(e, nullptr);
|
|
||||||
ASSERT_TRUE(e->IsUnless());
|
|
||||||
ASSERT_NE(e->condition(), nullptr);
|
|
||||||
EXPECT_TRUE(e->condition()->IsIdentifier());
|
|
||||||
ASSERT_EQ(e->body().size(), 1u);
|
|
||||||
EXPECT_TRUE(e->body()[0]->IsKill());
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(ParserImplTest, UnlessStmt_InvalidCondition) {
|
|
||||||
auto* p = parser("unless(if(a){}) {}");
|
|
||||||
auto e = p->unless_stmt();
|
|
||||||
ASSERT_TRUE(p->has_error());
|
|
||||||
ASSERT_EQ(e, nullptr);
|
|
||||||
EXPECT_EQ(p->error(), "1:8: unable to parse expression");
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(ParserImplTest, UnlessStmt_EmptyCondition) {
|
|
||||||
auto* p = parser("unless() {}");
|
|
||||||
auto e = p->unless_stmt();
|
|
||||||
ASSERT_TRUE(p->has_error());
|
|
||||||
ASSERT_EQ(e, nullptr);
|
|
||||||
EXPECT_EQ(p->error(), "1:8: unable to parse expression");
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(ParserImplTest, UnlessStmt_InvalidBody) {
|
|
||||||
auto* p = parser("unless(a + 2 - 5 == true) { kill }");
|
|
||||||
auto e = p->unless_stmt();
|
|
||||||
ASSERT_TRUE(p->has_error());
|
|
||||||
ASSERT_EQ(e, nullptr);
|
|
||||||
EXPECT_EQ(p->error(), "1:34: missing ;");
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace
|
|
||||||
} // namespace wgsl
|
|
||||||
} // namespace reader
|
|
||||||
} // namespace tint
|
|
|
@ -189,14 +189,10 @@ std::string Token::TypeToName(Type type) {
|
||||||
return "offset";
|
return "offset";
|
||||||
case Token::Type::kOut:
|
case Token::Type::kOut:
|
||||||
return "out";
|
return "out";
|
||||||
case Token::Type::kPremerge:
|
|
||||||
return "premerge";
|
|
||||||
case Token::Type::kPrivate:
|
case Token::Type::kPrivate:
|
||||||
return "private";
|
return "private";
|
||||||
case Token::Type::kPtr:
|
case Token::Type::kPtr:
|
||||||
return "ptr";
|
return "ptr";
|
||||||
case Token::Type::kRegardless:
|
|
||||||
return "regardless";
|
|
||||||
case Token::Type::kReturn:
|
case Token::Type::kReturn:
|
||||||
return "return";
|
return "return";
|
||||||
case Token::Type::kSet:
|
case Token::Type::kSet:
|
||||||
|
@ -217,8 +213,6 @@ std::string Token::TypeToName(Type type) {
|
||||||
return "uniform";
|
return "uniform";
|
||||||
case Token::Type::kUniformConstant:
|
case Token::Type::kUniformConstant:
|
||||||
return "uniform_constant";
|
return "uniform_constant";
|
||||||
case Token::Type::kUnless:
|
|
||||||
return "unless";
|
|
||||||
case Token::Type::kVar:
|
case Token::Type::kVar:
|
||||||
return "var";
|
return "var";
|
||||||
case Token::Type::kVec2:
|
case Token::Type::kVec2:
|
||||||
|
|
|
@ -200,14 +200,10 @@ class Token {
|
||||||
kOffset,
|
kOffset,
|
||||||
/// A 'out'
|
/// A 'out'
|
||||||
kOut,
|
kOut,
|
||||||
/// A 'premerge'
|
|
||||||
kPremerge,
|
|
||||||
/// A 'private'
|
/// A 'private'
|
||||||
kPrivate,
|
kPrivate,
|
||||||
/// A 'ptr'
|
/// A 'ptr'
|
||||||
kPtr,
|
kPtr,
|
||||||
/// A 'regardless'
|
|
||||||
kRegardless,
|
|
||||||
/// A 'return'
|
/// A 'return'
|
||||||
kReturn,
|
kReturn,
|
||||||
/// A 'set'
|
/// A 'set'
|
||||||
|
@ -228,8 +224,6 @@ class Token {
|
||||||
kUniform,
|
kUniform,
|
||||||
/// A 'uniform_constant'
|
/// A 'uniform_constant'
|
||||||
kUniformConstant,
|
kUniformConstant,
|
||||||
/// A 'unless'
|
|
||||||
kUnless,
|
|
||||||
/// A 'var'
|
/// A 'var'
|
||||||
kVar,
|
kVar,
|
||||||
/// A 'vec2'
|
/// A 'vec2'
|
||||||
|
@ -483,8 +477,6 @@ class Token {
|
||||||
bool IsUniform() const { return type_ == Type::kUniform; }
|
bool IsUniform() const { return type_ == Type::kUniform; }
|
||||||
/// @returns true if token is a 'uniform_constant'
|
/// @returns true if token is a 'uniform_constant'
|
||||||
bool IsUniformConstant() const { return type_ == Type::kUniformConstant; }
|
bool IsUniformConstant() const { return type_ == Type::kUniformConstant; }
|
||||||
/// @returns true if token is a 'unless'
|
|
||||||
bool IsUnless() const { return type_ == Type::kUnless; }
|
|
||||||
/// @returns true if token is a 'var'
|
/// @returns true if token is a 'var'
|
||||||
bool IsVar() const { return type_ == Type::kVar; }
|
bool IsVar() const { return type_ == Type::kVar; }
|
||||||
/// @returns true if token is a 'vec2'
|
/// @returns true if token is a 'vec2'
|
||||||
|
|
|
@ -43,7 +43,6 @@
|
||||||
#include "src/ast/type/vector_type.h"
|
#include "src/ast/type/vector_type.h"
|
||||||
#include "src/ast/type_constructor_expression.h"
|
#include "src/ast/type_constructor_expression.h"
|
||||||
#include "src/ast/unary_op_expression.h"
|
#include "src/ast/unary_op_expression.h"
|
||||||
#include "src/ast/unless_statement.h"
|
|
||||||
#include "src/ast/variable_decl_statement.h"
|
#include "src/ast/variable_decl_statement.h"
|
||||||
|
|
||||||
namespace tint {
|
namespace tint {
|
||||||
|
@ -214,11 +213,6 @@ bool TypeDeterminer::DetermineResultType(ast::Statement* stmt) {
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (stmt->IsUnless()) {
|
|
||||||
auto* u = stmt->AsUnless();
|
|
||||||
return DetermineResultType(u->condition()) &&
|
|
||||||
DetermineStatements(u->body());
|
|
||||||
}
|
|
||||||
if (stmt->IsVariableDecl()) {
|
if (stmt->IsVariableDecl()) {
|
||||||
auto* v = stmt->AsVariableDecl();
|
auto* v = stmt->AsVariableDecl();
|
||||||
variable_stack_.set(v->variable()->name(), v->variable());
|
variable_stack_.set(v->variable()->name(), v->variable());
|
||||||
|
|
|
@ -52,7 +52,6 @@
|
||||||
#include "src/ast/type/vector_type.h"
|
#include "src/ast/type/vector_type.h"
|
||||||
#include "src/ast/type_constructor_expression.h"
|
#include "src/ast/type_constructor_expression.h"
|
||||||
#include "src/ast/unary_op_expression.h"
|
#include "src/ast/unary_op_expression.h"
|
||||||
#include "src/ast/unless_statement.h"
|
|
||||||
#include "src/ast/variable_decl_statement.h"
|
#include "src/ast/variable_decl_statement.h"
|
||||||
|
|
||||||
namespace tint {
|
namespace tint {
|
||||||
|
@ -337,36 +336,6 @@ TEST_F(TypeDeterminerTest, Stmt_Switch) {
|
||||||
EXPECT_TRUE(rhs_ptr->result_type()->IsF32());
|
EXPECT_TRUE(rhs_ptr->result_type()->IsF32());
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(TypeDeterminerTest, Stmt_Unless) {
|
|
||||||
ast::type::I32Type i32;
|
|
||||||
ast::type::F32Type f32;
|
|
||||||
|
|
||||||
auto lhs = std::make_unique<ast::ScalarConstructorExpression>(
|
|
||||||
std::make_unique<ast::SintLiteral>(&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::UnlessStatement unless(
|
|
||||||
std::make_unique<ast::ScalarConstructorExpression>(
|
|
||||||
std::make_unique<ast::SintLiteral>(&i32, 3)),
|
|
||||||
std::move(body));
|
|
||||||
|
|
||||||
EXPECT_TRUE(td()->DetermineResultType(&unless));
|
|
||||||
ASSERT_NE(unless.condition()->result_type(), nullptr);
|
|
||||||
ASSERT_NE(lhs_ptr->result_type(), nullptr);
|
|
||||||
ASSERT_NE(rhs_ptr->result_type(), nullptr);
|
|
||||||
EXPECT_TRUE(unless.condition()->result_type()->IsI32());
|
|
||||||
EXPECT_TRUE(lhs_ptr->result_type()->IsI32());
|
|
||||||
EXPECT_TRUE(rhs_ptr->result_type()->IsF32());
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(TypeDeterminerTest, Stmt_VariableDecl) {
|
TEST_F(TypeDeterminerTest, Stmt_VariableDecl) {
|
||||||
ast::type::I32Type i32;
|
ast::type::I32Type i32;
|
||||||
auto var =
|
auto var =
|
||||||
|
|
|
@ -55,7 +55,6 @@
|
||||||
#include "src/ast/type_constructor_expression.h"
|
#include "src/ast/type_constructor_expression.h"
|
||||||
#include "src/ast/uint_literal.h"
|
#include "src/ast/uint_literal.h"
|
||||||
#include "src/ast/unary_op_expression.h"
|
#include "src/ast/unary_op_expression.h"
|
||||||
#include "src/ast/unless_statement.h"
|
|
||||||
#include "src/ast/variable_decl_statement.h"
|
#include "src/ast/variable_decl_statement.h"
|
||||||
|
|
||||||
namespace tint {
|
namespace tint {
|
||||||
|
@ -665,9 +664,6 @@ bool GeneratorImpl::EmitStatement(ast::Statement* stmt) {
|
||||||
if (stmt->IsVariableDecl()) {
|
if (stmt->IsVariableDecl()) {
|
||||||
return EmitVariable(stmt->AsVariableDecl()->variable());
|
return EmitVariable(stmt->AsVariableDecl()->variable());
|
||||||
}
|
}
|
||||||
if (stmt->IsUnless()) {
|
|
||||||
return EmitUnless(stmt->AsUnless());
|
|
||||||
}
|
|
||||||
|
|
||||||
error_ = "unknown statement type";
|
error_ = "unknown statement type";
|
||||||
return false;
|
return false;
|
||||||
|
@ -846,18 +842,6 @@ bool GeneratorImpl::EmitSwitch(ast::SwitchStatement* stmt) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool GeneratorImpl::EmitUnless(ast::UnlessStatement* stmt) {
|
|
||||||
make_indent();
|
|
||||||
|
|
||||||
out_ << "unless (";
|
|
||||||
if (!EmitExpression(stmt->condition())) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
out_ << ")";
|
|
||||||
|
|
||||||
return EmitStatementBlockAndNewline(stmt->body());
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace wgsl
|
} // namespace wgsl
|
||||||
} // namespace writer
|
} // namespace writer
|
||||||
} // namespace tint
|
} // namespace tint
|
||||||
|
|
|
@ -194,10 +194,6 @@ class GeneratorImpl {
|
||||||
/// @param expr the expression to emit
|
/// @param expr the expression to emit
|
||||||
/// @returns true if the expression was emitted
|
/// @returns true if the expression was emitted
|
||||||
bool EmitUnaryOp(ast::UnaryOpExpression* expr);
|
bool EmitUnaryOp(ast::UnaryOpExpression* expr);
|
||||||
/// Handles generating an unless statement
|
|
||||||
/// @param stmt the statement to generate
|
|
||||||
/// @returns true if the statement was successfully emitted
|
|
||||||
bool EmitUnless(ast::UnlessStatement* stmt);
|
|
||||||
/// Handles generating a variable
|
/// Handles generating a variable
|
||||||
/// @param var the variable to generate
|
/// @param var the variable to generate
|
||||||
/// @returns true if the variable was emitted
|
/// @returns true if the variable was emitted
|
||||||
|
|
|
@ -1,53 +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/unless_statement.h"
|
|
||||||
#include "src/writer/wgsl/generator_impl.h"
|
|
||||||
|
|
||||||
namespace tint {
|
|
||||||
namespace writer {
|
|
||||||
namespace wgsl {
|
|
||||||
namespace {
|
|
||||||
|
|
||||||
using GeneratorImplTest = testing::Test;
|
|
||||||
|
|
||||||
TEST_F(GeneratorImplTest, Emit_Unless) {
|
|
||||||
auto cond = std::make_unique<ast::IdentifierExpression>("cond");
|
|
||||||
|
|
||||||
ast::StatementList body;
|
|
||||||
body.push_back(std::make_unique<ast::KillStatement>());
|
|
||||||
body.push_back(std::make_unique<ast::KillStatement>());
|
|
||||||
|
|
||||||
ast::UnlessStatement u(std::move(cond), std::move(body));
|
|
||||||
|
|
||||||
GeneratorImpl g;
|
|
||||||
g.increment_indent();
|
|
||||||
|
|
||||||
ASSERT_TRUE(g.EmitStatement(&u)) << g.error();
|
|
||||||
EXPECT_EQ(g.result(), R"( unless (cond) {
|
|
||||||
kill;
|
|
||||||
kill;
|
|
||||||
}
|
|
||||||
)");
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace
|
|
||||||
} // namespace wgsl
|
|
||||||
} // namespace writer
|
|
||||||
} // namespace tint
|
|
Loading…
Reference in New Issue