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

@@ -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 {};
}

View File

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

View File

@@ -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<ast::Statement> 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<ast::UnlessStatement> ParserImpl::unless_stmt() {
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 paren_rhs_stmt BRACKET_LEFT switch_body+ BRACKET_RIGHT
std::unique_ptr<ast::SwitchStatement> ParserImpl::switch_stmt() {

View File

@@ -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<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
/// @returns the parsed statement or nullptr
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");
}
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();

View File

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