mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-12-21 18:59:21 +00:00
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:
@@ -576,8 +576,6 @@ Token Lexer::check_keyword(const Source& source, const std::string& str) {
|
||||
return {Token::Type::kUniform, source, "uniform"};
|
||||
if (str == "uniform_constant")
|
||||
return {Token::Type::kUniformConstant, source, "uniform_constant"};
|
||||
if (str == "unless")
|
||||
return {Token::Type::kUnless, source, "unless"};
|
||||
if (str == "var")
|
||||
return {Token::Type::kVar, source, "var"};
|
||||
if (str == "vec2")
|
||||
@@ -621,6 +619,8 @@ Token Lexer::check_reserved(const Source& source, const std::string& str) {
|
||||
return {Token::Type::kReservedKeyword, source, "let"};
|
||||
if (str == "premerge")
|
||||
return {Token::Type::kReservedKeyword, source, "premerge"};
|
||||
if (str == "regardless")
|
||||
return {Token::Type::kReservedKeyword, source, "regardless"};
|
||||
if (str == "typedef")
|
||||
return {Token::Type::kReservedKeyword, source, "typedef"};
|
||||
if (str == "u8")
|
||||
@@ -629,8 +629,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"};
|
||||
if (str == "unless")
|
||||
return {Token::Type::kReservedKeyword, source, "unless"};
|
||||
return {};
|
||||
}
|
||||
|
||||
|
||||
@@ -463,7 +463,6 @@ INSTANTIATE_TEST_SUITE_P(
|
||||
TokenData{"uniform", Token::Type::kUniform},
|
||||
TokenData{"uniform_constant",
|
||||
Token::Type::kUniformConstant},
|
||||
TokenData{"unless", Token::Type::kUnless},
|
||||
TokenData{"var", Token::Type::kVar},
|
||||
TokenData{"vec2", Token::Type::kVec2},
|
||||
TokenData{"vec3", Token::Type::kVec3},
|
||||
@@ -499,6 +498,7 @@ INSTANTIATE_TEST_SUITE_P(LexerTest,
|
||||
"u8",
|
||||
"u16",
|
||||
"u64",
|
||||
"unless",
|
||||
"regardless"));
|
||||
|
||||
} // namespace
|
||||
|
||||
@@ -1420,7 +1420,6 @@ ast::StatementList ParserImpl::statements() {
|
||||
// : SEMICOLON
|
||||
// | return_stmt SEMICOLON
|
||||
// | if_stmt
|
||||
// | unless_stmt
|
||||
// | switch_stmt
|
||||
// | loop_stmt
|
||||
// | variable_stmt SEMICOLON
|
||||
@@ -1453,12 +1452,6 @@ std::unique_ptr<ast::Statement> ParserImpl::statement() {
|
||||
if (stmt_if != nullptr)
|
||||
return stmt_if;
|
||||
|
||||
auto unless = unless_stmt();
|
||||
if (has_error())
|
||||
return nullptr;
|
||||
if (unless != nullptr)
|
||||
return unless;
|
||||
|
||||
auto sw = switch_stmt();
|
||||
if (has_error())
|
||||
return nullptr;
|
||||
@@ -1728,32 +1721,6 @@ std::unique_ptr<ast::ElseStatement> ParserImpl::else_stmt() {
|
||||
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 paren_rhs_stmt BRACKET_LEFT switch_body+ BRACKET_RIGHT
|
||||
std::unique_ptr<ast::SwitchStatement> ParserImpl::switch_stmt() {
|
||||
|
||||
@@ -40,7 +40,6 @@
|
||||
#include "src/ast/struct_member.h"
|
||||
#include "src/ast/struct_member_decoration.h"
|
||||
#include "src/ast/type/type.h"
|
||||
#include "src/ast/unless_statement.h"
|
||||
#include "src/ast/variable.h"
|
||||
#include "src/ast/variable_decoration.h"
|
||||
#include "src/context.h"
|
||||
@@ -208,9 +207,6 @@ class ParserImpl {
|
||||
/// Parses a `else_stmt` grammar element
|
||||
/// @returns the parsed statement or nullptr
|
||||
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
|
||||
/// @returns the parsed statement or nullptr
|
||||
std::unique_ptr<ast::SwitchStatement> switch_stmt();
|
||||
|
||||
@@ -93,22 +93,6 @@ TEST_F(ParserImplTest, Statement_If_Invalid) {
|
||||
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) {
|
||||
auto* p = parser("var a : i32 = 1;");
|
||||
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";
|
||||
case Token::Type::kOut:
|
||||
return "out";
|
||||
case Token::Type::kPremerge:
|
||||
return "premerge";
|
||||
case Token::Type::kPrivate:
|
||||
return "private";
|
||||
case Token::Type::kPtr:
|
||||
return "ptr";
|
||||
case Token::Type::kRegardless:
|
||||
return "regardless";
|
||||
case Token::Type::kReturn:
|
||||
return "return";
|
||||
case Token::Type::kSet:
|
||||
@@ -217,8 +213,6 @@ std::string Token::TypeToName(Type type) {
|
||||
return "uniform";
|
||||
case Token::Type::kUniformConstant:
|
||||
return "uniform_constant";
|
||||
case Token::Type::kUnless:
|
||||
return "unless";
|
||||
case Token::Type::kVar:
|
||||
return "var";
|
||||
case Token::Type::kVec2:
|
||||
|
||||
@@ -200,14 +200,10 @@ class Token {
|
||||
kOffset,
|
||||
/// A 'out'
|
||||
kOut,
|
||||
/// A 'premerge'
|
||||
kPremerge,
|
||||
/// A 'private'
|
||||
kPrivate,
|
||||
/// A 'ptr'
|
||||
kPtr,
|
||||
/// A 'regardless'
|
||||
kRegardless,
|
||||
/// A 'return'
|
||||
kReturn,
|
||||
/// A 'set'
|
||||
@@ -228,8 +224,6 @@ class Token {
|
||||
kUniform,
|
||||
/// A 'uniform_constant'
|
||||
kUniformConstant,
|
||||
/// A 'unless'
|
||||
kUnless,
|
||||
/// A 'var'
|
||||
kVar,
|
||||
/// A 'vec2'
|
||||
@@ -483,8 +477,6 @@ class Token {
|
||||
bool IsUniform() const { return type_ == Type::kUniform; }
|
||||
/// @returns true if token is a 'uniform_constant'
|
||||
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'
|
||||
bool IsVar() const { return type_ == Type::kVar; }
|
||||
/// @returns true if token is a 'vec2'
|
||||
|
||||
Reference in New Issue
Block a user