From 436b4a2bd06e0b058c25e69ffd8c2cd650b1752d Mon Sep 17 00:00:00 2001 From: dan sinclair Date: Wed, 24 Aug 2022 19:11:55 +0000 Subject: [PATCH] Drop `maybe_` from method names. With the old grammar elements removed, rename the new elements and drop the `maybe_` prefixes. Bug: tint:1633 Change-Id: Iafe223546f8af1ddd8a4b60572a106160a226b72 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/99921 Reviewed-by: Ben Clayton Kokoro: Kokoro Commit-Queue: Dan Sinclair --- src/tint/reader/wgsl/parser_impl.cc | 40 +++++++++---------- src/tint/reader/wgsl/parser_impl.h | 6 +-- .../wgsl/parser_impl_expression_test.cc | 28 ++++++------- .../parser_impl_relational_expression_test.cc | 12 +++--- .../wgsl/parser_impl_shift_expression_test.cc | 6 +-- 5 files changed, 46 insertions(+), 46 deletions(-) diff --git a/src/tint/reader/wgsl/parser_impl.cc b/src/tint/reader/wgsl/parser_impl.cc index f0c6a18a23..eff842b812 100644 --- a/src/tint/reader/wgsl/parser_impl.cc +++ b/src/tint/reader/wgsl/parser_impl.cc @@ -579,7 +579,7 @@ Maybe ParserImpl::global_variable_decl(AttributeList& attr const ast::Expression* initializer = nullptr; if (match(Token::Type::kEqual)) { - auto expr = maybe_expression(); + auto expr = expression(); if (expr.errored) { return Failure::kErrored; } @@ -639,7 +639,7 @@ Maybe ParserImpl::global_constant_decl(AttributeList& attr const ast::Expression* initializer = nullptr; if (has_initializer) { - auto expr = maybe_expression(); + auto expr = expression(); if (expr.errored) { return Failure::kErrored; } @@ -1426,7 +1426,7 @@ Maybe ParserImpl::static_assert_statement() { return Failure::kNoMatch; } - auto condition = maybe_expression(); + auto condition = expression(); if (condition.errored) { return Failure::kErrored; } @@ -1691,7 +1691,7 @@ Expect ParserImpl::expect_compound_statement() { // : PAREN_LEFT expression PAREN_RIGHT Expect ParserImpl::expect_paren_expression() { return expect_paren_block("", [&]() -> Expect { - auto expr = maybe_expression(); + auto expr = expression(); if (expr.errored) { return Failure::kErrored; } @@ -1895,7 +1895,7 @@ Maybe ParserImpl::return_statement() { return create(source, nullptr); } - auto expr = maybe_expression(); + auto expr = expression(); if (expr.errored) { return Failure::kErrored; } @@ -1920,7 +1920,7 @@ Maybe ParserImpl::variable_statement() { return Failure::kErrored; } - auto initializer = maybe_expression(); + auto initializer = expression(); if (initializer.errored) { return Failure::kErrored; } @@ -1947,7 +1947,7 @@ Maybe ParserImpl::variable_statement() { return Failure::kErrored; } - auto initializer = maybe_expression(); + auto initializer = expression(); if (initializer.errored) { return Failure::kErrored; } @@ -1974,7 +1974,7 @@ Maybe ParserImpl::variable_statement() { const ast::Expression* initializer = nullptr; if (match(Token::Type::kEqual)) { - auto initializer_expr = maybe_expression(); + auto initializer_expr = expression(); if (initializer_expr.errored) { return Failure::kErrored; } @@ -2018,7 +2018,7 @@ Maybe ParserImpl::if_statement() { return Failure::kNoMatch; } - auto condition = maybe_expression(); + auto condition = expression(); if (condition.errored) { return Failure::kErrored; } @@ -2086,7 +2086,7 @@ Maybe ParserImpl::switch_statement() { return Failure::kNoMatch; } - auto condition = maybe_expression(); + auto condition = expression(); if (condition.errored) { return Failure::kErrored; } @@ -2319,7 +2319,7 @@ Expect> ParserImpl::expect_for_header() { return Failure::kErrored; } - auto condition = maybe_expression(); + auto condition = expression(); if (condition.errored) { return Failure::kErrored; } @@ -2367,7 +2367,7 @@ Maybe ParserImpl::while_statement() { return Failure::kNoMatch; } - auto condition = maybe_expression(); + auto condition = expression(); if (condition.errored) { return Failure::kErrored; } @@ -2601,7 +2601,7 @@ Maybe ParserImpl::postfix_expression(const ast::Expressi while (continue_parsing()) { if (match(Token::Type::kBracketLeft, &source)) { auto res = sync(Token::Type::kBracketRight, [&]() -> Maybe { - auto param = maybe_expression(); + auto param = expression(); if (param.errored) { return Failure::kErrored; } @@ -2649,7 +2649,7 @@ Expect ParserImpl::expect_argument_expression_list( return expect_paren_block(use, [&]() -> Expect { ExpressionList ret; while (continue_parsing()) { - auto arg = maybe_expression(); + auto arg = expression(); if (arg.errored) { return Failure::kErrored; } else if (!arg.matched) { @@ -2881,7 +2881,7 @@ Maybe ParserImpl::element_count_expression() { // shift_expression // : unary_expression shift_expression.post.unary_expression -Maybe ParserImpl::maybe_shift_expression() { +Maybe ParserImpl::shift_expression() { auto lhs = unary_expression(); if (lhs.errored) { return Failure::kErrored; @@ -2930,7 +2930,7 @@ Expect ParserImpl::expect_shift_expression_post_unary_ex // relational_expression // : unary_expression relational_expression.post.unary_expression -Maybe ParserImpl::maybe_relational_expression() { +Maybe ParserImpl::relational_expression() { auto lhs = unary_expression(); if (lhs.errored) { return Failure::kErrored; @@ -2979,7 +2979,7 @@ Expect ParserImpl::expect_relational_expression_post_una } auto& next = peek(); - auto rhs = maybe_shift_expression(); + auto rhs = shift_expression(); if (rhs.errored) { return Failure::kErrored; } @@ -3001,7 +3001,7 @@ Expect ParserImpl::expect_relational_expression_post_una // relational_expression ( or_or relational_expression )* // // Note, a `relational_expression` element was added to simplify many of the right sides -Maybe ParserImpl::maybe_expression() { +Maybe ParserImpl::expression() { auto lhs = unary_expression(); if (lhs.errored) { return Failure::kErrored; @@ -3045,7 +3045,7 @@ Maybe ParserImpl::maybe_expression() { } next(); - auto rhs = maybe_relational_expression(); + auto rhs = relational_expression(); if (rhs.errored) { return Failure::kErrored; } @@ -3305,7 +3305,7 @@ Maybe ParserImpl::variable_updating_statement() { } } - auto rhs = maybe_expression(); + auto rhs = expression(); if (rhs.errored) { return Failure::kErrored; } diff --git a/src/tint/reader/wgsl/parser_impl.h b/src/tint/reader/wgsl/parser_impl.h index c733d02a3f..cc0cd2b708 100644 --- a/src/tint/reader/wgsl/parser_impl.h +++ b/src/tint/reader/wgsl/parser_impl.h @@ -623,7 +623,7 @@ class ParserImpl { Maybe unary_expression(); /// Parses the `expression` grammar rule /// @returns the parsed expression or nullptr - Maybe maybe_expression(); + Maybe expression(); /// Parses the `bitwise_expression.post.unary_expression` grammar element /// @param lhs the left side of the expression /// @returns the parsed expression or nullptr @@ -652,7 +652,7 @@ class ParserImpl { Maybe element_count_expression(); /// Parses a `unary_expression shift.post.unary_expression` /// @returns the parsed expression or nullptr - Maybe maybe_shift_expression(); + Maybe shift_expression(); /// Parses a `shift_expression.post.unary_expression` grammar element /// @param lhs the left side of the expression /// @returns the parsed expression or `lhs` if no match @@ -660,7 +660,7 @@ class ParserImpl { const ast::Expression* lhs); /// Parses a `unary_expression relational_expression.post.unary_expression` /// @returns the parsed expression or nullptr - Maybe maybe_relational_expression(); + Maybe relational_expression(); /// Parses a `relational_expression.post.unary_expression` grammar element /// @param lhs the left side of the expression /// @returns the parsed expression or `lhs` if no match diff --git a/src/tint/reader/wgsl/parser_impl_expression_test.cc b/src/tint/reader/wgsl/parser_impl_expression_test.cc index 2938e3c7b7..0adbeeff01 100644 --- a/src/tint/reader/wgsl/parser_impl_expression_test.cc +++ b/src/tint/reader/wgsl/parser_impl_expression_test.cc @@ -19,7 +19,7 @@ namespace { TEST_F(ParserImplTest, Expression_InvalidLHS) { auto p = parser("if (a) {} || true"); - auto e = p->maybe_expression(); + auto e = p->expression(); EXPECT_FALSE(e.matched); EXPECT_FALSE(e.errored); EXPECT_FALSE(p->has_error()) << p->error(); @@ -28,7 +28,7 @@ TEST_F(ParserImplTest, Expression_InvalidLHS) { TEST_F(ParserImplTest, Expression_Or_Parses) { auto p = parser("a || true"); - auto e = p->maybe_expression(); + auto e = p->expression(); EXPECT_TRUE(e.matched); EXPECT_FALSE(e.errored); EXPECT_FALSE(p->has_error()) << p->error(); @@ -53,7 +53,7 @@ TEST_F(ParserImplTest, Expression_Or_Parses) { TEST_F(ParserImplTest, Expression_Or_Parses_Multiple) { auto p = parser("a || true || b"); - auto e = p->maybe_expression(); + auto e = p->expression(); EXPECT_TRUE(e.matched); EXPECT_FALSE(e.errored); EXPECT_FALSE(p->has_error()) << p->error(); @@ -85,7 +85,7 @@ TEST_F(ParserImplTest, Expression_Or_Parses_Multiple) { TEST_F(ParserImplTest, Expression_Or_InvalidRHS) { auto p = parser("true || if (a) {}"); - auto e = p->maybe_expression(); + auto e = p->expression(); EXPECT_FALSE(e.matched); EXPECT_TRUE(e.errored); EXPECT_EQ(e.value, nullptr); @@ -95,7 +95,7 @@ TEST_F(ParserImplTest, Expression_Or_InvalidRHS) { TEST_F(ParserImplTest, Expression_And_Parses) { auto p = parser("a && true"); - auto e = p->maybe_expression(); + auto e = p->expression(); EXPECT_TRUE(e.matched); EXPECT_FALSE(e.errored); EXPECT_FALSE(p->has_error()) << p->error(); @@ -120,7 +120,7 @@ TEST_F(ParserImplTest, Expression_And_Parses) { TEST_F(ParserImplTest, Expression_And_Parses_Multple) { auto p = parser("a && true && b"); - auto e = p->maybe_expression(); + auto e = p->expression(); EXPECT_TRUE(e.matched); EXPECT_FALSE(e.errored); EXPECT_FALSE(p->has_error()) << p->error(); @@ -150,7 +150,7 @@ TEST_F(ParserImplTest, Expression_And_Parses_Multple) { TEST_F(ParserImplTest, Expression_And_InvalidRHS) { auto p = parser("true && if (a) {}"); - auto e = p->maybe_expression(); + auto e = p->expression(); EXPECT_FALSE(e.matched); EXPECT_TRUE(e.errored); EXPECT_EQ(e.value, nullptr); @@ -160,7 +160,7 @@ TEST_F(ParserImplTest, Expression_And_InvalidRHS) { TEST_F(ParserImplTest, Expression_Mixing_OrWithAnd) { auto p = parser("a && true || b"); - auto e = p->maybe_expression(); + auto e = p->expression(); EXPECT_FALSE(e.matched); EXPECT_TRUE(e.errored); EXPECT_EQ(e.value, nullptr); @@ -170,7 +170,7 @@ TEST_F(ParserImplTest, Expression_Mixing_OrWithAnd) { TEST_F(ParserImplTest, Expression_Mixing_AndWithOr) { auto p = parser("a || true && b"); - auto e = p->maybe_expression(); + auto e = p->expression(); EXPECT_FALSE(e.matched); EXPECT_TRUE(e.errored); EXPECT_EQ(e.value, nullptr); @@ -180,7 +180,7 @@ TEST_F(ParserImplTest, Expression_Mixing_AndWithOr) { TEST_F(ParserImplTest, Expression_Bitwise) { auto p = parser("a & b"); - auto e = p->maybe_expression(); + auto e = p->expression(); EXPECT_TRUE(e.matched); EXPECT_FALSE(e.errored); EXPECT_FALSE(p->has_error()) << p->error(); @@ -201,7 +201,7 @@ TEST_F(ParserImplTest, Expression_Bitwise) { TEST_F(ParserImplTest, Expression_Relational) { auto p = parser("a <= b"); - auto e = p->maybe_expression(); + auto e = p->expression(); EXPECT_TRUE(e.matched); EXPECT_FALSE(e.errored); EXPECT_FALSE(p->has_error()) << p->error(); @@ -222,7 +222,7 @@ TEST_F(ParserImplTest, Expression_Relational) { TEST_F(ParserImplTest, Expression_InvalidUnary) { auto p = parser("!if || true"); - auto e = p->maybe_expression(); + auto e = p->expression(); EXPECT_FALSE(e.matched); EXPECT_TRUE(e.errored); EXPECT_EQ(e.value, nullptr); @@ -232,7 +232,7 @@ TEST_F(ParserImplTest, Expression_InvalidUnary) { TEST_F(ParserImplTest, Expression_InvalidBitwise) { auto p = parser("a & if"); - auto e = p->maybe_expression(); + auto e = p->expression(); EXPECT_FALSE(e.matched); EXPECT_TRUE(e.errored); EXPECT_EQ(e.value, nullptr); @@ -242,7 +242,7 @@ TEST_F(ParserImplTest, Expression_InvalidBitwise) { TEST_F(ParserImplTest, Expression_InvalidRelational) { auto p = parser("a <= if"); - auto e = p->maybe_expression(); + auto e = p->expression(); EXPECT_FALSE(e.matched); EXPECT_TRUE(e.errored); EXPECT_EQ(e.value, nullptr); diff --git a/src/tint/reader/wgsl/parser_impl_relational_expression_test.cc b/src/tint/reader/wgsl/parser_impl_relational_expression_test.cc index 0d0eabcc71..ebd8ffd289 100644 --- a/src/tint/reader/wgsl/parser_impl_relational_expression_test.cc +++ b/src/tint/reader/wgsl/parser_impl_relational_expression_test.cc @@ -188,7 +188,7 @@ TEST_F(ParserImplTest, RelationalExpression_PostUnary_NoMatch_ReturnsLHS) { TEST_F(ParserImplTest, RelationalExpression_Matches) { auto p = parser("a >= true"); - auto e = p->maybe_relational_expression(); + auto e = p->relational_expression(); EXPECT_TRUE(e.matched); EXPECT_FALSE(e.errored); EXPECT_FALSE(p->has_error()) << p->error(); @@ -208,7 +208,7 @@ TEST_F(ParserImplTest, RelationalExpression_Matches) { TEST_F(ParserImplTest, RelationalExpression_InvalidLHS) { auto p = parser("if (a) {}< 3"); - auto e = p->maybe_relational_expression(); + auto e = p->relational_expression(); ASSERT_FALSE(e.matched); EXPECT_FALSE(e.errored); ASSERT_FALSE(p->has_error()) << p->error(); @@ -217,7 +217,7 @@ TEST_F(ParserImplTest, RelationalExpression_InvalidLHS) { TEST_F(ParserImplTest, RelationalExpression_InvalidRHS) { auto p = parser("true < if (a) {}"); - auto e = p->maybe_relational_expression(); + auto e = p->relational_expression(); ASSERT_FALSE(e.matched); EXPECT_TRUE(e.errored); ASSERT_TRUE(p->has_error()); @@ -227,7 +227,7 @@ TEST_F(ParserImplTest, RelationalExpression_InvalidRHS) { TEST_F(ParserImplTest, RelationalExpression_Parses_Equal) { auto p = parser("a == true"); - auto e = p->maybe_relational_expression(); + auto e = p->relational_expression(); EXPECT_TRUE(e.matched); EXPECT_FALSE(e.errored); EXPECT_FALSE(p->has_error()) << p->error(); @@ -252,7 +252,7 @@ TEST_F(ParserImplTest, RelationalExpression_Parses_Equal) { TEST_F(ParserImplTest, RelationalExpression_Parses_NotEqual) { auto p = parser("a != true"); - auto e = p->maybe_relational_expression(); + auto e = p->relational_expression(); EXPECT_TRUE(e.matched); EXPECT_FALSE(e.errored); EXPECT_FALSE(p->has_error()) << p->error(); @@ -277,7 +277,7 @@ TEST_F(ParserImplTest, RelationalExpression_Parses_NotEqual) { TEST_F(ParserImplTest, RelationalExpression_Equal_InvalidRHS) { auto p = parser("true == if (a) {}"); - auto e = p->maybe_relational_expression(); + auto e = p->relational_expression(); EXPECT_FALSE(e.matched); EXPECT_TRUE(e.errored); EXPECT_EQ(e.value, nullptr); diff --git a/src/tint/reader/wgsl/parser_impl_shift_expression_test.cc b/src/tint/reader/wgsl/parser_impl_shift_expression_test.cc index 2c8aef30a4..016f86f95d 100644 --- a/src/tint/reader/wgsl/parser_impl_shift_expression_test.cc +++ b/src/tint/reader/wgsl/parser_impl_shift_expression_test.cc @@ -149,7 +149,7 @@ TEST_F(ParserImplTest, ShiftExpression_PostUnary_NoOr_ReturnsLHS) { TEST_F(ParserImplTest, ShiftExpression_Parses) { auto p = parser("a << true"); - auto e = p->maybe_shift_expression(); + auto e = p->shift_expression(); EXPECT_TRUE(e.matched); EXPECT_FALSE(e.errored); EXPECT_FALSE(p->has_error()) << p->error(); @@ -169,7 +169,7 @@ TEST_F(ParserImplTest, ShiftExpression_Parses) { TEST_F(ParserImplTest, ShiftExpression_Invalid_Unary) { auto p = parser("if >> true"); - auto e = p->maybe_shift_expression(); + auto e = p->shift_expression(); EXPECT_FALSE(e.matched); EXPECT_FALSE(e.errored); EXPECT_FALSE(p->has_error()) << p->error(); @@ -178,7 +178,7 @@ TEST_F(ParserImplTest, ShiftExpression_Invalid_Unary) { TEST_F(ParserImplTest, ShiftExpression_Inavlid_ShiftExpressionPostUnary) { auto p = parser("a * if (a) {}"); - auto e = p->maybe_shift_expression(); + auto e = p->shift_expression(); EXPECT_FALSE(e.matched); EXPECT_TRUE(e.errored); EXPECT_TRUE(p->has_error());