Syncing WGSL grammar to Tint.

This CL syncs some more grammar changes into Tint. The `break if`
statement is stubbed out to be completed later.

Bug: tint:1633
Change-Id: I9223278288383698f9cdecc1ae854720cc55dd2c
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/98660
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: Dan Sinclair <dsinclair@chromium.org>
Auto-Submit: Dan Sinclair <dsinclair@chromium.org>
Reviewed-by: Antonio Maiorano <amaiorano@google.com>
Commit-Queue: Antonio Maiorano <amaiorano@google.com>
This commit is contained in:
dan sinclair 2022-08-09 16:52:42 +00:00 committed by Dawn LUCI CQ
parent eaca2ebd4c
commit e62fbbc75c
3 changed files with 51 additions and 21 deletions

View File

@ -560,8 +560,7 @@ Maybe<bool> ParserImpl::global_decl() {
} }
// global_variable_decl // global_variable_decl
// : variable_attribute_list* variable_decl // : variable_attribute_list* variable_decl (EQUAL expression)?
// | variable_attribute_list* variable_decl EQUAL expression
Maybe<const ast::Variable*> ParserImpl::global_variable_decl(AttributeList& attrs) { Maybe<const ast::Variable*> ParserImpl::global_variable_decl(AttributeList& attrs) {
auto decl = variable_decl(); auto decl = variable_decl();
if (decl.errored) { if (decl.errored) {
@ -1044,10 +1043,8 @@ Maybe<const ast::Alias*> ParserImpl::type_alias_decl() {
// | VEC3 LESS_THAN type_decl GREATER_THAN // | VEC3 LESS_THAN type_decl GREATER_THAN
// | VEC4 LESS_THAN type_decl GREATER_THAN // | VEC4 LESS_THAN type_decl GREATER_THAN
// | PTR LESS_THAN storage_class, type_decl (COMMA access_mode)? GREATER_THAN // | PTR LESS_THAN storage_class, type_decl (COMMA access_mode)? GREATER_THAN
// | array_attribute_list* ARRAY LESS_THAN type_decl COMMA // | array_attribute_list* ARRAY LESS_THAN type_decl COMMA INT_LITERAL GREATER_THAN
// INT_LITERAL GREATER_THAN // | array_attribute_list* ARRAY LESS_THAN type_decl GREATER_THAN
// | array_attribute_list* ARRAY LESS_THAN type_decl
// GREATER_THAN
// | MAT2x2 LESS_THAN type_decl GREATER_THAN // | MAT2x2 LESS_THAN type_decl GREATER_THAN
// | MAT2x3 LESS_THAN type_decl GREATER_THAN // | MAT2x3 LESS_THAN type_decl GREATER_THAN
// | MAT2x4 LESS_THAN type_decl GREATER_THAN // | MAT2x4 LESS_THAN type_decl GREATER_THAN
@ -1366,7 +1363,7 @@ Expect<ast::StructMember*> ParserImpl::expect_struct_member() {
decl->type, std::move(attrs.value)); decl->type, std::move(attrs.value));
} }
// static_assert // static_assert_statement
// : STATIC_ASSERT expression // : STATIC_ASSERT expression
Maybe<const ast::StaticAssert*> ParserImpl::static_assert_statement() { Maybe<const ast::StaticAssert*> ParserImpl::static_assert_statement() {
Source start; Source start;
@ -2170,7 +2167,7 @@ Maybe<const ast::BlockStatement*> ParserImpl::case_body() {
} }
// loop_statement // loop_statement
// : LOOP BRACKET_LEFT statements continuing_stmt? BRACKET_RIGHT // : LOOP BRACKET_LEFT statements continuing_statement? BRACKET_RIGHT
Maybe<const ast::LoopStatement*> ParserImpl::loop_statement() { Maybe<const ast::LoopStatement*> ParserImpl::loop_statement() {
Source source; Source source;
if (!match(Token::Type::kLoop, &source)) { if (!match(Token::Type::kLoop, &source)) {
@ -2183,7 +2180,7 @@ Maybe<const ast::LoopStatement*> ParserImpl::loop_statement() {
return Failure::kErrored; return Failure::kErrored;
} }
auto continuing = continuing_stmt(); auto continuing = continuing_statement();
if (continuing.errored) { if (continuing.errored) {
return Failure::kErrored; return Failure::kErrored;
} }
@ -2376,14 +2373,42 @@ Maybe<const ast::ContinueStatement*> ParserImpl::continue_statement() {
return create<ast::ContinueStatement>(source); return create<ast::ContinueStatement>(source);
} }
// continuing_stmt // break_if_statement:
// : CONTINUING compound_statement // 'break' 'if' expression semicolon
Maybe<const ast::BlockStatement*> ParserImpl::continuing_stmt() { Maybe<const ast::Statement*> ParserImpl::break_if_statement() {
// TODO(crbug.com/tint/1451): Add support for break-if
return Failure::kNoMatch;
}
// continuing_compound_statement:
// brace_left statement* break_if_statement? brace_right
Maybe<const ast::BlockStatement*> ParserImpl::continuing_compound_statement() {
return expect_brace_block("", [&]() -> Expect<ast::BlockStatement*> {
auto stmts = expect_statements();
if (stmts.errored) {
return Failure::kErrored;
}
auto break_if = break_if_statement();
if (break_if.errored) {
return Failure::kErrored;
}
if (break_if.matched) {
stmts.value.Push(break_if.value);
}
return create<ast::BlockStatement>(Source{}, stmts.value);
});
}
// continuing_statement
// : CONTINUING continuing_compound_statement
Maybe<const ast::BlockStatement*> ParserImpl::continuing_statement() {
if (!match(Token::Type::kContinuing)) { if (!match(Token::Type::kContinuing)) {
return create<ast::BlockStatement>(Source{}, utils::Empty); return create<ast::BlockStatement>(Source{}, utils::Empty);
} }
return expect_compound_statement(); return continuing_compound_statement();
} }
// primary_expression // primary_expression
@ -2528,8 +2553,7 @@ Maybe<const ast::Expression*> ParserImpl::singular_expression() {
} }
// argument_expression_list // argument_expression_list
// : PAREN_LEFT ((expression COMMA)* expression COMMA?)? // : PAREN_LEFT ((expression COMMA)* expression COMMA?)? PAREN_RIGHT
// PAREN_RIGHT
Expect<ParserImpl::ExpressionList> ParserImpl::expect_argument_expression_list( Expect<ParserImpl::ExpressionList> ParserImpl::expect_argument_expression_list(
std::string_view use) { std::string_view use) {
return expect_paren_block(use, [&]() -> Expect<ExpressionList> { return expect_paren_block(use, [&]() -> Expect<ExpressionList> {
@ -3079,8 +3103,8 @@ Maybe<ast::BinaryOp> ParserImpl::compound_assignment_operator() {
} }
// assignment_statement // assignment_statement
// | lhs_expression ( equal | compound_assignment_operator ) expression // | lhs_expression ( EQUAL | compound_assignment_operator ) expression
// | underscore equal expression // | UNDERSCORE EQUAL expression
// //
// increment_statement // increment_statement
// | lhs_expression PLUS_PLUS // | lhs_expression PLUS_PLUS

View File

@ -559,9 +559,15 @@ class ParserImpl {
/// Parses a `while_statement` grammar element /// Parses a `while_statement` grammar element
/// @returns the parsed while loop or nullptr /// @returns the parsed while loop or nullptr
Maybe<const ast::WhileStatement*> while_statement(); Maybe<const ast::WhileStatement*> while_statement();
/// Parses a `continuing_stmt` grammar element /// Parses a `break_if_statement` grammar element
/// @returns the parsed statement or nullptr
Maybe<const ast::Statement*> break_if_statement();
/// Parses a `continuing_compound_statement` grammar element
/// @returns the parsed statements /// @returns the parsed statements
Maybe<const ast::BlockStatement*> continuing_stmt(); Maybe<const ast::BlockStatement*> continuing_compound_statement();
/// Parses a `continuing_statement` grammar element
/// @returns the parsed statements
Maybe<const ast::BlockStatement*> continuing_statement();
/// Parses a `const_literal` grammar element /// Parses a `const_literal` grammar element
/// @returns the const literal parsed or nullptr if none found /// @returns the const literal parsed or nullptr if none found
Maybe<const ast::LiteralExpression*> const_literal(); Maybe<const ast::LiteralExpression*> const_literal();

View File

@ -20,7 +20,7 @@ namespace {
TEST_F(ParserImplTest, ContinuingStmt) { TEST_F(ParserImplTest, ContinuingStmt) {
auto p = parser("continuing { discard; }"); auto p = parser("continuing { discard; }");
auto e = p->continuing_stmt(); auto e = p->continuing_statement();
EXPECT_TRUE(e.matched); EXPECT_TRUE(e.matched);
EXPECT_FALSE(e.errored); EXPECT_FALSE(e.errored);
EXPECT_FALSE(p->has_error()) << p->error(); EXPECT_FALSE(p->has_error()) << p->error();
@ -30,7 +30,7 @@ TEST_F(ParserImplTest, ContinuingStmt) {
TEST_F(ParserImplTest, ContinuingStmt_InvalidBody) { TEST_F(ParserImplTest, ContinuingStmt_InvalidBody) {
auto p = parser("continuing { discard }"); auto p = parser("continuing { discard }");
auto e = p->continuing_stmt(); auto e = p->continuing_statement();
EXPECT_FALSE(e.matched); EXPECT_FALSE(e.matched);
EXPECT_TRUE(e.errored); EXPECT_TRUE(e.errored);
EXPECT_EQ(e.value, nullptr); EXPECT_EQ(e.value, nullptr);