Remove fallthrough from WGSL parser.

This CL removes the `fallthrough` parsing from the WGSL parser. The
`fallthrough` token is left so we can generate a nicer error message
in the case `fallthrough` is used.

Bug: tint:1644
Change-Id: Ifb23d78d1219cba9c64b80c9b098a248bc68e5c5
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/109001
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
Commit-Queue: Dan Sinclair <dsinclair@chromium.org>
This commit is contained in:
dan sinclair
2022-11-15 00:20:24 +00:00
committed by Dawn LUCI CQ
parent d8a986beae
commit bf586f6dfd
5 changed files with 6 additions and 132 deletions

View File

@@ -25,7 +25,6 @@
#include "src/tint/ast/continue_statement.h"
#include "src/tint/ast/discard_statement.h"
#include "src/tint/ast/external_texture.h"
#include "src/tint/ast/fallthrough_statement.h"
#include "src/tint/ast/id_attribute.h"
#include "src/tint/ast/if_statement.h"
#include "src/tint/ast/increment_decrement_statement.h"
@@ -2189,24 +2188,17 @@ Maybe<const ast::CaseSelector*> ParserImpl::case_selector() {
// case_body
// :
// | statement case_body
// | FALLTHROUGH SEMICOLON
Maybe<const ast::BlockStatement*> ParserImpl::case_body() {
StatementList stmts;
while (continue_parsing()) {
Source source;
if (match(Token::Type::kFallthrough, &source)) {
if (!expect("fallthrough statement", Token::Type::kSemicolon)) {
return Failure::kErrored;
}
deprecated(source,
"fallthrough is set to be removed from WGSL. "
"Case can accept multiple selectors if the existing case bodies are empty. "
"(e.g. `case 1, 2, 3:`) "
"`default` is a valid case selector value. (e.g. `case 1, default:`)");
stmts.Push(create<ast::FallthroughStatement>(source));
break;
return add_error(
source,
"fallthrough is not premitted in WGSL. "
"Case can accept multiple selectors if the existing case bodies are empty. "
"(e.g. `case 1, 2, 3:`) "
"`default` is a valid case selector value. (e.g. `case 1, default:`)");
}
auto stmt = statement();

View File

@@ -12,7 +12,6 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#include "src/tint/ast/fallthrough_statement.h"
#include "src/tint/reader/wgsl/parser_impl_test_helper.h"
namespace tint::reader::wgsl {
@@ -50,25 +49,5 @@ TEST_F(ParserImplTest, CaseBody_InvalidStatement) {
EXPECT_EQ(e.value, nullptr);
}
TEST_F(ParserImplTest, CaseBody_Fallthrough) {
auto p = parser("fallthrough;");
auto e = p->case_body();
ASSERT_FALSE(p->has_error()) << p->error();
EXPECT_FALSE(e.errored);
EXPECT_TRUE(e.matched);
ASSERT_EQ(e->statements.Length(), 1u);
EXPECT_TRUE(e->statements[0]->Is<ast::FallthroughStatement>());
}
TEST_F(ParserImplTest, CaseBody_Fallthrough_MissingSemicolon) {
auto p = parser("fallthrough");
auto e = p->case_body();
EXPECT_TRUE(p->has_error());
EXPECT_TRUE(e.errored);
EXPECT_FALSE(e.matched);
EXPECT_EQ(e.value, nullptr);
EXPECT_EQ(p->error(), "1:12: expected ';' for fallthrough statement");
}
} // namespace
} // namespace tint::reader::wgsl

View File

@@ -1230,14 +1230,6 @@ fn f() { switch(1) { case 1: {
)");
}
TEST_F(ParserImplErrorTest, SwitchStmtCaseFallthroughMissingSemicolon) {
EXPECT("fn f() { switch(1) { case 1: { fallthrough } case 2: {} } }",
R"(test.wgsl:1:44 error: expected ';' for fallthrough statement
fn f() { switch(1) { case 1: { fallthrough } case 2: {} } }
^
)");
}
TEST_F(ParserImplErrorTest, VarStmtMissingSemicolon) {
EXPECT("fn f() { var a : u32 }",
R"(test.wgsl:1:22 error: expected ';' for variable declaration