Convert to new expression grammar
This CL moves all the grammar rules to use the new `maybe_expression` rules. All of the old `expression` rules are removed. Bug: tint:1633 Change-Id: I29637a4c6fcd200650a2b57011b6539c66be942a Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/99920 Reviewed-by: Ben Clayton <bclayton@google.com> Commit-Queue: Dan Sinclair <dsinclair@chromium.org> Kokoro: Kokoro <noreply+kokoro@google.com>
This commit is contained in:
parent
acdf6e1a53
commit
202362f47d
|
@ -1350,7 +1350,6 @@ if (tint_build_unittests) {
|
||||||
sources = [
|
sources = [
|
||||||
"reader/wgsl/lexer_test.cc",
|
"reader/wgsl/lexer_test.cc",
|
||||||
"reader/wgsl/parser_impl_additive_expression_test.cc",
|
"reader/wgsl/parser_impl_additive_expression_test.cc",
|
||||||
"reader/wgsl/parser_impl_and_expression_test.cc",
|
|
||||||
"reader/wgsl/parser_impl_argument_expression_list_test.cc",
|
"reader/wgsl/parser_impl_argument_expression_list_test.cc",
|
||||||
"reader/wgsl/parser_impl_assignment_stmt_test.cc",
|
"reader/wgsl/parser_impl_assignment_stmt_test.cc",
|
||||||
"reader/wgsl/parser_impl_bitwise_expression_test.cc",
|
"reader/wgsl/parser_impl_bitwise_expression_test.cc",
|
||||||
|
@ -1367,10 +1366,8 @@ if (tint_build_unittests) {
|
||||||
"reader/wgsl/parser_impl_depth_texture_test.cc",
|
"reader/wgsl/parser_impl_depth_texture_test.cc",
|
||||||
"reader/wgsl/parser_impl_element_count_expression_test.cc",
|
"reader/wgsl/parser_impl_element_count_expression_test.cc",
|
||||||
"reader/wgsl/parser_impl_enable_directive_test.cc",
|
"reader/wgsl/parser_impl_enable_directive_test.cc",
|
||||||
"reader/wgsl/parser_impl_equality_expression_test.cc",
|
|
||||||
"reader/wgsl/parser_impl_error_msg_test.cc",
|
"reader/wgsl/parser_impl_error_msg_test.cc",
|
||||||
"reader/wgsl/parser_impl_error_resync_test.cc",
|
"reader/wgsl/parser_impl_error_resync_test.cc",
|
||||||
"reader/wgsl/parser_impl_exclusive_or_expression_test.cc",
|
|
||||||
"reader/wgsl/parser_impl_expression_test.cc",
|
"reader/wgsl/parser_impl_expression_test.cc",
|
||||||
"reader/wgsl/parser_impl_external_texture_test.cc",
|
"reader/wgsl/parser_impl_external_texture_test.cc",
|
||||||
"reader/wgsl/parser_impl_for_stmt_test.cc",
|
"reader/wgsl/parser_impl_for_stmt_test.cc",
|
||||||
|
@ -1382,11 +1379,8 @@ if (tint_build_unittests) {
|
||||||
"reader/wgsl/parser_impl_global_decl_test.cc",
|
"reader/wgsl/parser_impl_global_decl_test.cc",
|
||||||
"reader/wgsl/parser_impl_global_variable_decl_test.cc",
|
"reader/wgsl/parser_impl_global_variable_decl_test.cc",
|
||||||
"reader/wgsl/parser_impl_if_stmt_test.cc",
|
"reader/wgsl/parser_impl_if_stmt_test.cc",
|
||||||
"reader/wgsl/parser_impl_inclusive_or_expression_test.cc",
|
|
||||||
"reader/wgsl/parser_impl_increment_decrement_stmt_test.cc",
|
"reader/wgsl/parser_impl_increment_decrement_stmt_test.cc",
|
||||||
"reader/wgsl/parser_impl_lhs_expression_test.cc",
|
"reader/wgsl/parser_impl_lhs_expression_test.cc",
|
||||||
"reader/wgsl/parser_impl_logical_and_expression_test.cc",
|
|
||||||
"reader/wgsl/parser_impl_logical_or_expression_test.cc",
|
|
||||||
"reader/wgsl/parser_impl_loop_stmt_test.cc",
|
"reader/wgsl/parser_impl_loop_stmt_test.cc",
|
||||||
"reader/wgsl/parser_impl_math_expression_test.cc",
|
"reader/wgsl/parser_impl_math_expression_test.cc",
|
||||||
"reader/wgsl/parser_impl_multiplicative_expression_test.cc",
|
"reader/wgsl/parser_impl_multiplicative_expression_test.cc",
|
||||||
|
|
|
@ -945,7 +945,6 @@ if(TINT_BUILD_TESTS)
|
||||||
reader/wgsl/lexer_test.cc
|
reader/wgsl/lexer_test.cc
|
||||||
reader/wgsl/parser_test.cc
|
reader/wgsl/parser_test.cc
|
||||||
reader/wgsl/parser_impl_additive_expression_test.cc
|
reader/wgsl/parser_impl_additive_expression_test.cc
|
||||||
reader/wgsl/parser_impl_and_expression_test.cc
|
|
||||||
reader/wgsl/parser_impl_argument_expression_list_test.cc
|
reader/wgsl/parser_impl_argument_expression_list_test.cc
|
||||||
reader/wgsl/parser_impl_assignment_stmt_test.cc
|
reader/wgsl/parser_impl_assignment_stmt_test.cc
|
||||||
reader/wgsl/parser_impl_bitwise_expression_test.cc
|
reader/wgsl/parser_impl_bitwise_expression_test.cc
|
||||||
|
@ -962,10 +961,8 @@ if(TINT_BUILD_TESTS)
|
||||||
reader/wgsl/parser_impl_depth_texture_test.cc
|
reader/wgsl/parser_impl_depth_texture_test.cc
|
||||||
reader/wgsl/parser_impl_element_count_expression_test.cc
|
reader/wgsl/parser_impl_element_count_expression_test.cc
|
||||||
reader/wgsl/parser_impl_enable_directive_test.cc
|
reader/wgsl/parser_impl_enable_directive_test.cc
|
||||||
reader/wgsl/parser_impl_equality_expression_test.cc
|
|
||||||
reader/wgsl/parser_impl_error_msg_test.cc
|
reader/wgsl/parser_impl_error_msg_test.cc
|
||||||
reader/wgsl/parser_impl_error_resync_test.cc
|
reader/wgsl/parser_impl_error_resync_test.cc
|
||||||
reader/wgsl/parser_impl_exclusive_or_expression_test.cc
|
|
||||||
reader/wgsl/parser_impl_expression_test.cc
|
reader/wgsl/parser_impl_expression_test.cc
|
||||||
reader/wgsl/parser_impl_external_texture_test.cc
|
reader/wgsl/parser_impl_external_texture_test.cc
|
||||||
reader/wgsl/parser_impl_for_stmt_test.cc
|
reader/wgsl/parser_impl_for_stmt_test.cc
|
||||||
|
@ -977,11 +974,8 @@ if(TINT_BUILD_TESTS)
|
||||||
reader/wgsl/parser_impl_global_decl_test.cc
|
reader/wgsl/parser_impl_global_decl_test.cc
|
||||||
reader/wgsl/parser_impl_global_variable_decl_test.cc
|
reader/wgsl/parser_impl_global_variable_decl_test.cc
|
||||||
reader/wgsl/parser_impl_if_stmt_test.cc
|
reader/wgsl/parser_impl_if_stmt_test.cc
|
||||||
reader/wgsl/parser_impl_inclusive_or_expression_test.cc
|
|
||||||
reader/wgsl/parser_impl_increment_decrement_stmt_test.cc
|
reader/wgsl/parser_impl_increment_decrement_stmt_test.cc
|
||||||
reader/wgsl/parser_impl_lhs_expression_test.cc
|
reader/wgsl/parser_impl_lhs_expression_test.cc
|
||||||
reader/wgsl/parser_impl_logical_and_expression_test.cc
|
|
||||||
reader/wgsl/parser_impl_logical_or_expression_test.cc
|
|
||||||
reader/wgsl/parser_impl_loop_stmt_test.cc
|
reader/wgsl/parser_impl_loop_stmt_test.cc
|
||||||
reader/wgsl/parser_impl_math_expression_test.cc
|
reader/wgsl/parser_impl_math_expression_test.cc
|
||||||
reader/wgsl/parser_impl_multiplicative_expression_test.cc
|
reader/wgsl/parser_impl_multiplicative_expression_test.cc
|
||||||
|
|
|
@ -579,7 +579,7 @@ Maybe<const ast::Variable*> ParserImpl::global_variable_decl(AttributeList& attr
|
||||||
|
|
||||||
const ast::Expression* initializer = nullptr;
|
const ast::Expression* initializer = nullptr;
|
||||||
if (match(Token::Type::kEqual)) {
|
if (match(Token::Type::kEqual)) {
|
||||||
auto expr = expression();
|
auto expr = maybe_expression();
|
||||||
if (expr.errored) {
|
if (expr.errored) {
|
||||||
return Failure::kErrored;
|
return Failure::kErrored;
|
||||||
}
|
}
|
||||||
|
@ -639,7 +639,7 @@ Maybe<const ast::Variable*> ParserImpl::global_constant_decl(AttributeList& attr
|
||||||
|
|
||||||
const ast::Expression* initializer = nullptr;
|
const ast::Expression* initializer = nullptr;
|
||||||
if (has_initializer) {
|
if (has_initializer) {
|
||||||
auto expr = expression();
|
auto expr = maybe_expression();
|
||||||
if (expr.errored) {
|
if (expr.errored) {
|
||||||
return Failure::kErrored;
|
return Failure::kErrored;
|
||||||
}
|
}
|
||||||
|
@ -1426,7 +1426,7 @@ Maybe<const ast::StaticAssert*> ParserImpl::static_assert_statement() {
|
||||||
return Failure::kNoMatch;
|
return Failure::kNoMatch;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto condition = expression();
|
auto condition = maybe_expression();
|
||||||
if (condition.errored) {
|
if (condition.errored) {
|
||||||
return Failure::kErrored;
|
return Failure::kErrored;
|
||||||
}
|
}
|
||||||
|
@ -1691,7 +1691,7 @@ Expect<ast::BlockStatement*> ParserImpl::expect_compound_statement() {
|
||||||
// : PAREN_LEFT expression PAREN_RIGHT
|
// : PAREN_LEFT expression PAREN_RIGHT
|
||||||
Expect<const ast::Expression*> ParserImpl::expect_paren_expression() {
|
Expect<const ast::Expression*> ParserImpl::expect_paren_expression() {
|
||||||
return expect_paren_block("", [&]() -> Expect<const ast::Expression*> {
|
return expect_paren_block("", [&]() -> Expect<const ast::Expression*> {
|
||||||
auto expr = expression();
|
auto expr = maybe_expression();
|
||||||
if (expr.errored) {
|
if (expr.errored) {
|
||||||
return Failure::kErrored;
|
return Failure::kErrored;
|
||||||
}
|
}
|
||||||
|
@ -1895,7 +1895,7 @@ Maybe<const ast::ReturnStatement*> ParserImpl::return_statement() {
|
||||||
return create<ast::ReturnStatement>(source, nullptr);
|
return create<ast::ReturnStatement>(source, nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
auto expr = expression();
|
auto expr = maybe_expression();
|
||||||
if (expr.errored) {
|
if (expr.errored) {
|
||||||
return Failure::kErrored;
|
return Failure::kErrored;
|
||||||
}
|
}
|
||||||
|
@ -2018,7 +2018,7 @@ Maybe<const ast::IfStatement*> ParserImpl::if_statement() {
|
||||||
return Failure::kNoMatch;
|
return Failure::kNoMatch;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto condition = expression();
|
auto condition = maybe_expression();
|
||||||
if (condition.errored) {
|
if (condition.errored) {
|
||||||
return Failure::kErrored;
|
return Failure::kErrored;
|
||||||
}
|
}
|
||||||
|
@ -2086,7 +2086,7 @@ Maybe<const ast::SwitchStatement*> ParserImpl::switch_statement() {
|
||||||
return Failure::kNoMatch;
|
return Failure::kNoMatch;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto condition = expression();
|
auto condition = maybe_expression();
|
||||||
if (condition.errored) {
|
if (condition.errored) {
|
||||||
return Failure::kErrored;
|
return Failure::kErrored;
|
||||||
}
|
}
|
||||||
|
@ -2319,7 +2319,7 @@ Expect<std::unique_ptr<ForHeader>> ParserImpl::expect_for_header() {
|
||||||
return Failure::kErrored;
|
return Failure::kErrored;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto condition = expression();
|
auto condition = maybe_expression();
|
||||||
if (condition.errored) {
|
if (condition.errored) {
|
||||||
return Failure::kErrored;
|
return Failure::kErrored;
|
||||||
}
|
}
|
||||||
|
@ -2367,7 +2367,7 @@ Maybe<const ast::WhileStatement*> ParserImpl::while_statement() {
|
||||||
return Failure::kNoMatch;
|
return Failure::kNoMatch;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto condition = expression();
|
auto condition = maybe_expression();
|
||||||
if (condition.errored) {
|
if (condition.errored) {
|
||||||
return Failure::kErrored;
|
return Failure::kErrored;
|
||||||
}
|
}
|
||||||
|
@ -2601,7 +2601,7 @@ Maybe<const ast::Expression*> ParserImpl::postfix_expression(const ast::Expressi
|
||||||
while (continue_parsing()) {
|
while (continue_parsing()) {
|
||||||
if (match(Token::Type::kBracketLeft, &source)) {
|
if (match(Token::Type::kBracketLeft, &source)) {
|
||||||
auto res = sync(Token::Type::kBracketRight, [&]() -> Maybe<const ast::Expression*> {
|
auto res = sync(Token::Type::kBracketRight, [&]() -> Maybe<const ast::Expression*> {
|
||||||
auto param = expression();
|
auto param = maybe_expression();
|
||||||
if (param.errored) {
|
if (param.errored) {
|
||||||
return Failure::kErrored;
|
return Failure::kErrored;
|
||||||
}
|
}
|
||||||
|
@ -2649,7 +2649,7 @@ Expect<ParserImpl::ExpressionList> ParserImpl::expect_argument_expression_list(
|
||||||
return expect_paren_block(use, [&]() -> Expect<ExpressionList> {
|
return expect_paren_block(use, [&]() -> Expect<ExpressionList> {
|
||||||
ExpressionList ret;
|
ExpressionList ret;
|
||||||
while (continue_parsing()) {
|
while (continue_parsing()) {
|
||||||
auto arg = expression();
|
auto arg = maybe_expression();
|
||||||
if (arg.errored) {
|
if (arg.errored) {
|
||||||
return Failure::kErrored;
|
return Failure::kErrored;
|
||||||
} else if (!arg.matched) {
|
} else if (!arg.matched) {
|
||||||
|
@ -2913,12 +2913,13 @@ Expect<const ast::Expression*> ParserImpl::expect_shift_expression_post_unary_ex
|
||||||
name = ">>";
|
name = ">>";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
auto& rhs_start = peek();
|
||||||
auto rhs = unary_expression();
|
auto rhs = unary_expression();
|
||||||
if (rhs.errored) {
|
if (rhs.errored) {
|
||||||
return Failure::kErrored;
|
return Failure::kErrored;
|
||||||
}
|
}
|
||||||
if (!rhs.matched) {
|
if (!rhs.matched) {
|
||||||
return add_error(t,
|
return add_error(rhs_start,
|
||||||
std::string("unable to parse right side of ") + name + " expression");
|
std::string("unable to parse right side of ") + name + " expression");
|
||||||
}
|
}
|
||||||
return create<ast::BinaryExpression>(t.source(), op, lhs, rhs.value);
|
return create<ast::BinaryExpression>(t.source(), op, lhs, rhs.value);
|
||||||
|
@ -3044,7 +3045,7 @@ Maybe<const ast::Expression*> ParserImpl::maybe_expression() {
|
||||||
}
|
}
|
||||||
next();
|
next();
|
||||||
|
|
||||||
auto rhs = relational_expression();
|
auto rhs = maybe_relational_expression();
|
||||||
if (rhs.errored) {
|
if (rhs.errored) {
|
||||||
return Failure::kErrored;
|
return Failure::kErrored;
|
||||||
}
|
}
|
||||||
|
@ -3130,437 +3131,6 @@ Maybe<const ast::Expression*> ParserImpl::unary_expression() {
|
||||||
return create<ast::UnaryOpExpression>(t.source(), op, expr.value);
|
return create<ast::UnaryOpExpression>(t.source(), op, expr.value);
|
||||||
}
|
}
|
||||||
|
|
||||||
// multiplicative_expr
|
|
||||||
// :
|
|
||||||
// | STAR unary_expression multiplicative_expr
|
|
||||||
// | FORWARD_SLASH unary_expression multiplicative_expr
|
|
||||||
// | MODULO unary_expression multiplicative_expr
|
|
||||||
Expect<const ast::Expression*> ParserImpl::expect_multiplicative_expr(const ast::Expression* lhs) {
|
|
||||||
while (continue_parsing()) {
|
|
||||||
ast::BinaryOp op = ast::BinaryOp::kNone;
|
|
||||||
if (peek_is(Token::Type::kStar)) {
|
|
||||||
op = ast::BinaryOp::kMultiply;
|
|
||||||
} else if (peek_is(Token::Type::kForwardSlash)) {
|
|
||||||
op = ast::BinaryOp::kDivide;
|
|
||||||
} else if (peek_is(Token::Type::kMod)) {
|
|
||||||
op = ast::BinaryOp::kModulo;
|
|
||||||
} else {
|
|
||||||
return lhs;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto& t = next();
|
|
||||||
|
|
||||||
auto rhs = unary_expression();
|
|
||||||
if (rhs.errored) {
|
|
||||||
return Failure::kErrored;
|
|
||||||
}
|
|
||||||
if (!rhs.matched) {
|
|
||||||
return add_error(peek(), "unable to parse right side of " + std::string(t.to_name()) +
|
|
||||||
" expression");
|
|
||||||
}
|
|
||||||
|
|
||||||
lhs = create<ast::BinaryExpression>(t.source(), op, lhs, rhs.value);
|
|
||||||
}
|
|
||||||
return Failure::kErrored;
|
|
||||||
}
|
|
||||||
|
|
||||||
// multiplicative_expression
|
|
||||||
// : unary_expression multiplicative_expr
|
|
||||||
Maybe<const ast::Expression*> ParserImpl::multiplicative_expression() {
|
|
||||||
auto lhs = unary_expression();
|
|
||||||
if (lhs.errored) {
|
|
||||||
return Failure::kErrored;
|
|
||||||
}
|
|
||||||
if (!lhs.matched) {
|
|
||||||
return Failure::kNoMatch;
|
|
||||||
}
|
|
||||||
|
|
||||||
return expect_multiplicative_expr(lhs.value);
|
|
||||||
}
|
|
||||||
|
|
||||||
// additive_expr
|
|
||||||
// :
|
|
||||||
// | PLUS multiplicative_expression additive_expr
|
|
||||||
// | MINUS multiplicative_expression additive_expr
|
|
||||||
Expect<const ast::Expression*> ParserImpl::expect_additive_expr(const ast::Expression* lhs) {
|
|
||||||
while (continue_parsing()) {
|
|
||||||
ast::BinaryOp op = ast::BinaryOp::kNone;
|
|
||||||
if (peek_is(Token::Type::kPlus)) {
|
|
||||||
op = ast::BinaryOp::kAdd;
|
|
||||||
} else if (peek_is(Token::Type::kMinus)) {
|
|
||||||
op = ast::BinaryOp::kSubtract;
|
|
||||||
} else {
|
|
||||||
return lhs;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto& t = next();
|
|
||||||
|
|
||||||
auto rhs = multiplicative_expression();
|
|
||||||
if (rhs.errored) {
|
|
||||||
return Failure::kErrored;
|
|
||||||
}
|
|
||||||
if (!rhs.matched) {
|
|
||||||
return add_error(peek(), "unable to parse right side of + expression");
|
|
||||||
}
|
|
||||||
|
|
||||||
lhs = create<ast::BinaryExpression>(t.source(), op, lhs, rhs.value);
|
|
||||||
}
|
|
||||||
return Failure::kErrored;
|
|
||||||
}
|
|
||||||
|
|
||||||
// additive_expression
|
|
||||||
// : multiplicative_expression additive_expr
|
|
||||||
Maybe<const ast::Expression*> ParserImpl::additive_expression() {
|
|
||||||
auto lhs = multiplicative_expression();
|
|
||||||
if (lhs.errored) {
|
|
||||||
return Failure::kErrored;
|
|
||||||
}
|
|
||||||
if (!lhs.matched) {
|
|
||||||
return Failure::kNoMatch;
|
|
||||||
}
|
|
||||||
|
|
||||||
return expect_additive_expr(lhs.value);
|
|
||||||
}
|
|
||||||
|
|
||||||
// shift_expr
|
|
||||||
// :
|
|
||||||
// | SHIFT_LEFT additive_expression shift_expr
|
|
||||||
// | SHIFT_RIGHT additive_expression shift_expr
|
|
||||||
Expect<const ast::Expression*> ParserImpl::expect_shift_expr(const ast::Expression* lhs) {
|
|
||||||
while (continue_parsing()) {
|
|
||||||
auto* name = "";
|
|
||||||
ast::BinaryOp op = ast::BinaryOp::kNone;
|
|
||||||
if (peek_is(Token::Type::kShiftLeft)) {
|
|
||||||
op = ast::BinaryOp::kShiftLeft;
|
|
||||||
name = "<<";
|
|
||||||
} else if (peek_is(Token::Type::kShiftRight)) {
|
|
||||||
op = ast::BinaryOp::kShiftRight;
|
|
||||||
name = ">>";
|
|
||||||
} else {
|
|
||||||
return lhs;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto& t = next();
|
|
||||||
auto rhs = additive_expression();
|
|
||||||
if (rhs.errored) {
|
|
||||||
return Failure::kErrored;
|
|
||||||
}
|
|
||||||
if (!rhs.matched) {
|
|
||||||
return add_error(peek(),
|
|
||||||
std::string("unable to parse right side of ") + name + " expression");
|
|
||||||
}
|
|
||||||
|
|
||||||
return lhs = create<ast::BinaryExpression>(t.source(), op, lhs, rhs.value);
|
|
||||||
}
|
|
||||||
return Failure::kErrored;
|
|
||||||
}
|
|
||||||
|
|
||||||
// shift_expression
|
|
||||||
// : additive_expression shift_expr
|
|
||||||
Maybe<const ast::Expression*> ParserImpl::shift_expression() {
|
|
||||||
auto lhs = additive_expression();
|
|
||||||
if (lhs.errored) {
|
|
||||||
return Failure::kErrored;
|
|
||||||
}
|
|
||||||
if (!lhs.matched) {
|
|
||||||
return Failure::kNoMatch;
|
|
||||||
}
|
|
||||||
|
|
||||||
return expect_shift_expr(lhs.value);
|
|
||||||
}
|
|
||||||
|
|
||||||
// relational_expr
|
|
||||||
// :
|
|
||||||
// | LESS_THAN shift_expression relational_expr
|
|
||||||
// | GREATER_THAN shift_expression relational_expr
|
|
||||||
// | LESS_THAN_EQUAL shift_expression relational_expr
|
|
||||||
// | GREATER_THAN_EQUAL shift_expression relational_expr
|
|
||||||
Expect<const ast::Expression*> ParserImpl::expect_relational_expr(const ast::Expression* lhs) {
|
|
||||||
while (continue_parsing()) {
|
|
||||||
ast::BinaryOp op = ast::BinaryOp::kNone;
|
|
||||||
if (peek_is(Token::Type::kLessThan)) {
|
|
||||||
op = ast::BinaryOp::kLessThan;
|
|
||||||
} else if (peek_is(Token::Type::kGreaterThan)) {
|
|
||||||
op = ast::BinaryOp::kGreaterThan;
|
|
||||||
} else if (peek_is(Token::Type::kLessThanEqual)) {
|
|
||||||
op = ast::BinaryOp::kLessThanEqual;
|
|
||||||
} else if (peek_is(Token::Type::kGreaterThanEqual)) {
|
|
||||||
op = ast::BinaryOp::kGreaterThanEqual;
|
|
||||||
} else {
|
|
||||||
return lhs;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto& t = next();
|
|
||||||
|
|
||||||
auto rhs = shift_expression();
|
|
||||||
if (rhs.errored) {
|
|
||||||
return Failure::kErrored;
|
|
||||||
}
|
|
||||||
if (!rhs.matched) {
|
|
||||||
return add_error(peek(), "unable to parse right side of " + std::string(t.to_name()) +
|
|
||||||
" expression");
|
|
||||||
}
|
|
||||||
|
|
||||||
lhs = create<ast::BinaryExpression>(t.source(), op, lhs, rhs.value);
|
|
||||||
}
|
|
||||||
return Failure::kErrored;
|
|
||||||
}
|
|
||||||
|
|
||||||
// relational_expression
|
|
||||||
// : shift_expression relational_expr
|
|
||||||
Maybe<const ast::Expression*> ParserImpl::relational_expression() {
|
|
||||||
auto lhs = shift_expression();
|
|
||||||
if (lhs.errored) {
|
|
||||||
return Failure::kErrored;
|
|
||||||
}
|
|
||||||
if (!lhs.matched) {
|
|
||||||
return Failure::kNoMatch;
|
|
||||||
}
|
|
||||||
|
|
||||||
return expect_relational_expr(lhs.value);
|
|
||||||
}
|
|
||||||
|
|
||||||
// equality_expr
|
|
||||||
// :
|
|
||||||
// | EQUAL_EQUAL relational_expression equality_expr
|
|
||||||
// | NOT_EQUAL relational_expression equality_expr
|
|
||||||
Expect<const ast::Expression*> ParserImpl::expect_equality_expr(const ast::Expression* lhs) {
|
|
||||||
while (continue_parsing()) {
|
|
||||||
ast::BinaryOp op = ast::BinaryOp::kNone;
|
|
||||||
if (peek_is(Token::Type::kEqualEqual)) {
|
|
||||||
op = ast::BinaryOp::kEqual;
|
|
||||||
} else if (peek_is(Token::Type::kNotEqual)) {
|
|
||||||
op = ast::BinaryOp::kNotEqual;
|
|
||||||
} else {
|
|
||||||
return lhs;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto& t = next();
|
|
||||||
|
|
||||||
auto rhs = relational_expression();
|
|
||||||
if (rhs.errored) {
|
|
||||||
return Failure::kErrored;
|
|
||||||
}
|
|
||||||
if (!rhs.matched) {
|
|
||||||
return add_error(peek(), "unable to parse right side of " + std::string(t.to_name()) +
|
|
||||||
" expression");
|
|
||||||
}
|
|
||||||
|
|
||||||
lhs = create<ast::BinaryExpression>(t.source(), op, lhs, rhs.value);
|
|
||||||
}
|
|
||||||
return Failure::kErrored;
|
|
||||||
}
|
|
||||||
|
|
||||||
// equality_expression
|
|
||||||
// : relational_expression equality_expr
|
|
||||||
Maybe<const ast::Expression*> ParserImpl::equality_expression() {
|
|
||||||
auto lhs = relational_expression();
|
|
||||||
if (lhs.errored) {
|
|
||||||
return Failure::kErrored;
|
|
||||||
}
|
|
||||||
if (!lhs.matched) {
|
|
||||||
return Failure::kNoMatch;
|
|
||||||
}
|
|
||||||
|
|
||||||
return expect_equality_expr(lhs.value);
|
|
||||||
}
|
|
||||||
|
|
||||||
// and_expr
|
|
||||||
// :
|
|
||||||
// | AND equality_expression and_expr
|
|
||||||
Expect<const ast::Expression*> ParserImpl::expect_and_expr(const ast::Expression* lhs) {
|
|
||||||
while (continue_parsing()) {
|
|
||||||
if (!peek_is(Token::Type::kAnd)) {
|
|
||||||
return lhs;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto& t = next();
|
|
||||||
|
|
||||||
auto rhs = equality_expression();
|
|
||||||
if (rhs.errored) {
|
|
||||||
return Failure::kErrored;
|
|
||||||
}
|
|
||||||
if (!rhs.matched) {
|
|
||||||
return add_error(peek(), "unable to parse right side of & expression");
|
|
||||||
}
|
|
||||||
|
|
||||||
lhs = create<ast::BinaryExpression>(t.source(), ast::BinaryOp::kAnd, lhs, rhs.value);
|
|
||||||
}
|
|
||||||
return Failure::kErrored;
|
|
||||||
}
|
|
||||||
|
|
||||||
// and_expression
|
|
||||||
// : equality_expression and_expr
|
|
||||||
Maybe<const ast::Expression*> ParserImpl::and_expression() {
|
|
||||||
auto lhs = equality_expression();
|
|
||||||
if (lhs.errored) {
|
|
||||||
return Failure::kErrored;
|
|
||||||
}
|
|
||||||
if (!lhs.matched) {
|
|
||||||
return Failure::kNoMatch;
|
|
||||||
}
|
|
||||||
|
|
||||||
return expect_and_expr(lhs.value);
|
|
||||||
}
|
|
||||||
|
|
||||||
// exclusive_or_expr
|
|
||||||
// :
|
|
||||||
// | XOR and_expression exclusive_or_expr
|
|
||||||
Expect<const ast::Expression*> ParserImpl::expect_exclusive_or_expr(const ast::Expression* lhs) {
|
|
||||||
while (continue_parsing()) {
|
|
||||||
Source source;
|
|
||||||
if (!match(Token::Type::kXor, &source)) {
|
|
||||||
return lhs;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto rhs = and_expression();
|
|
||||||
if (rhs.errored) {
|
|
||||||
return Failure::kErrored;
|
|
||||||
}
|
|
||||||
if (!rhs.matched) {
|
|
||||||
return add_error(peek(), "unable to parse right side of ^ expression");
|
|
||||||
}
|
|
||||||
|
|
||||||
lhs = create<ast::BinaryExpression>(source, ast::BinaryOp::kXor, lhs, rhs.value);
|
|
||||||
}
|
|
||||||
return Failure::kErrored;
|
|
||||||
}
|
|
||||||
|
|
||||||
// exclusive_or_expression
|
|
||||||
// : and_expression exclusive_or_expr
|
|
||||||
Maybe<const ast::Expression*> ParserImpl::exclusive_or_expression() {
|
|
||||||
auto lhs = and_expression();
|
|
||||||
if (lhs.errored) {
|
|
||||||
return Failure::kErrored;
|
|
||||||
}
|
|
||||||
if (!lhs.matched) {
|
|
||||||
return Failure::kNoMatch;
|
|
||||||
}
|
|
||||||
|
|
||||||
return expect_exclusive_or_expr(lhs.value);
|
|
||||||
}
|
|
||||||
|
|
||||||
// inclusive_or_expr
|
|
||||||
// :
|
|
||||||
// | OR exclusive_or_expression inclusive_or_expr
|
|
||||||
Expect<const ast::Expression*> ParserImpl::expect_inclusive_or_expr(const ast::Expression* lhs) {
|
|
||||||
while (continue_parsing()) {
|
|
||||||
Source source;
|
|
||||||
if (!match(Token::Type::kOr, &source)) {
|
|
||||||
return lhs;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto rhs = exclusive_or_expression();
|
|
||||||
if (rhs.errored) {
|
|
||||||
return Failure::kErrored;
|
|
||||||
}
|
|
||||||
if (!rhs.matched) {
|
|
||||||
return add_error(peek(), "unable to parse right side of | expression");
|
|
||||||
}
|
|
||||||
|
|
||||||
lhs = create<ast::BinaryExpression>(source, ast::BinaryOp::kOr, lhs, rhs.value);
|
|
||||||
}
|
|
||||||
return Failure::kErrored;
|
|
||||||
}
|
|
||||||
|
|
||||||
// inclusive_or_expression
|
|
||||||
// : exclusive_or_expression inclusive_or_expr
|
|
||||||
Maybe<const ast::Expression*> ParserImpl::inclusive_or_expression() {
|
|
||||||
auto lhs = exclusive_or_expression();
|
|
||||||
if (lhs.errored) {
|
|
||||||
return Failure::kErrored;
|
|
||||||
}
|
|
||||||
if (!lhs.matched) {
|
|
||||||
return Failure::kNoMatch;
|
|
||||||
}
|
|
||||||
|
|
||||||
return expect_inclusive_or_expr(lhs.value);
|
|
||||||
}
|
|
||||||
|
|
||||||
// logical_and_expr
|
|
||||||
// :
|
|
||||||
// | AND_AND inclusive_or_expression logical_and_expr
|
|
||||||
Expect<const ast::Expression*> ParserImpl::expect_logical_and_expr(const ast::Expression* lhs) {
|
|
||||||
while (continue_parsing()) {
|
|
||||||
if (!peek_is(Token::Type::kAndAnd)) {
|
|
||||||
return lhs;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto& t = next();
|
|
||||||
|
|
||||||
auto rhs = inclusive_or_expression();
|
|
||||||
if (rhs.errored) {
|
|
||||||
return Failure::kErrored;
|
|
||||||
}
|
|
||||||
if (!rhs.matched) {
|
|
||||||
return add_error(peek(), "unable to parse right side of && expression");
|
|
||||||
}
|
|
||||||
|
|
||||||
lhs = create<ast::BinaryExpression>(t.source(), ast::BinaryOp::kLogicalAnd, lhs, rhs.value);
|
|
||||||
}
|
|
||||||
return Failure::kErrored;
|
|
||||||
}
|
|
||||||
|
|
||||||
// logical_and_expression
|
|
||||||
// : inclusive_or_expression logical_and_expr
|
|
||||||
Maybe<const ast::Expression*> ParserImpl::logical_and_expression() {
|
|
||||||
auto lhs = inclusive_or_expression();
|
|
||||||
if (lhs.errored) {
|
|
||||||
return Failure::kErrored;
|
|
||||||
}
|
|
||||||
if (!lhs.matched) {
|
|
||||||
return Failure::kNoMatch;
|
|
||||||
}
|
|
||||||
|
|
||||||
return expect_logical_and_expr(lhs.value);
|
|
||||||
}
|
|
||||||
|
|
||||||
// logical_or_expr
|
|
||||||
// :
|
|
||||||
// | OR_OR logical_and_expression logical_or_expr
|
|
||||||
Expect<const ast::Expression*> ParserImpl::expect_logical_or_expr(const ast::Expression* lhs) {
|
|
||||||
while (continue_parsing()) {
|
|
||||||
Source source;
|
|
||||||
if (!match(Token::Type::kOrOr, &source)) {
|
|
||||||
return lhs;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto rhs = logical_and_expression();
|
|
||||||
if (rhs.errored) {
|
|
||||||
return Failure::kErrored;
|
|
||||||
}
|
|
||||||
if (!rhs.matched) {
|
|
||||||
return add_error(peek(), "unable to parse right side of || expression");
|
|
||||||
}
|
|
||||||
|
|
||||||
lhs = create<ast::BinaryExpression>(source, ast::BinaryOp::kLogicalOr, lhs, rhs.value);
|
|
||||||
}
|
|
||||||
return Failure::kErrored;
|
|
||||||
}
|
|
||||||
|
|
||||||
// logical_or_expression
|
|
||||||
// : logical_and_expression logical_or_expr
|
|
||||||
Maybe<const ast::Expression*> ParserImpl::logical_or_expression() {
|
|
||||||
auto lhs = logical_and_expression();
|
|
||||||
if (lhs.errored) {
|
|
||||||
return Failure::kErrored;
|
|
||||||
}
|
|
||||||
if (!lhs.matched) {
|
|
||||||
return Failure::kNoMatch;
|
|
||||||
}
|
|
||||||
|
|
||||||
return expect_logical_or_expr(lhs.value);
|
|
||||||
}
|
|
||||||
|
|
||||||
// expression:
|
|
||||||
// : relational_expression
|
|
||||||
// | short_circuit_or_expression or_or relational_expression
|
|
||||||
// | short_circuit_and_expression and_and relational_expression
|
|
||||||
// | bitwise_expression
|
|
||||||
Maybe<const ast::Expression*> ParserImpl::expression() {
|
|
||||||
return logical_or_expression();
|
|
||||||
}
|
|
||||||
|
|
||||||
// compound_assignment_operator
|
// compound_assignment_operator
|
||||||
// : plus_equal
|
// : plus_equal
|
||||||
// | minus_equal
|
// | minus_equal
|
||||||
|
@ -3735,7 +3305,7 @@ Maybe<const ast::Statement*> ParserImpl::variable_updating_statement() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
auto rhs = expression();
|
auto rhs = maybe_expression();
|
||||||
if (rhs.errored) {
|
if (rhs.errored) {
|
||||||
return Failure::kErrored;
|
return Failure::kErrored;
|
||||||
}
|
}
|
||||||
|
|
|
@ -621,49 +621,9 @@ class ParserImpl {
|
||||||
/// Parses a `unary_expression` grammar element
|
/// Parses a `unary_expression` grammar element
|
||||||
/// @returns the parsed expression or nullptr
|
/// @returns the parsed expression or nullptr
|
||||||
Maybe<const ast::Expression*> unary_expression();
|
Maybe<const ast::Expression*> unary_expression();
|
||||||
/// Parses the recursive part of the `multiplicative_expression`, erroring on
|
|
||||||
/// parse failure.
|
|
||||||
/// @param lhs the left side of the expression
|
|
||||||
/// @returns the parsed expression or nullptr
|
|
||||||
Expect<const ast::Expression*> expect_multiplicative_expr(const ast::Expression* lhs);
|
|
||||||
/// Parses the `multiplicative_expression` grammar element
|
|
||||||
/// @returns the parsed expression or nullptr
|
|
||||||
Maybe<const ast::Expression*> multiplicative_expression();
|
|
||||||
/// Parses the recursive part of the `additive_expression`, erroring on parse
|
|
||||||
/// failure.
|
|
||||||
/// @param lhs the left side of the expression
|
|
||||||
/// @returns the parsed expression or nullptr
|
|
||||||
Expect<const ast::Expression*> expect_additive_expr(const ast::Expression* lhs);
|
|
||||||
/// Parses the `additive_expression` grammar element
|
|
||||||
/// @returns the parsed expression or nullptr
|
|
||||||
Maybe<const ast::Expression*> additive_expression();
|
|
||||||
/// Parses the recursive part of the `shift_expression`, erroring on parse
|
|
||||||
/// failure.
|
|
||||||
/// @param lhs the left side of the expression
|
|
||||||
/// @returns the parsed expression or nullptr
|
|
||||||
Expect<const ast::Expression*> expect_shift_expr(const ast::Expression* lhs);
|
|
||||||
/// Parses the `shift_expression` grammar element
|
|
||||||
/// @returns the parsed expression or nullptr
|
|
||||||
Maybe<const ast::Expression*> shift_expression();
|
|
||||||
/// Parses the recursive part of the `relational_expression`, erroring on
|
|
||||||
/// parse failure.
|
|
||||||
/// @param lhs the left side of the expression
|
|
||||||
/// @returns the parsed expression or nullptr
|
|
||||||
Expect<const ast::Expression*> expect_relational_expr(const ast::Expression* lhs);
|
|
||||||
/// Parses the `expression` grammar rule
|
/// Parses the `expression` grammar rule
|
||||||
/// @returns the parsed expression or nullptr
|
/// @returns the parsed expression or nullptr
|
||||||
Maybe<const ast::Expression*> maybe_expression();
|
Maybe<const ast::Expression*> maybe_expression();
|
||||||
/// Parses the `relational_expression` grammar element
|
|
||||||
/// @returns the parsed expression or nullptr
|
|
||||||
Maybe<const ast::Expression*> relational_expression();
|
|
||||||
/// Parses the recursive part of the `equality_expression`, erroring on parse
|
|
||||||
/// failure.
|
|
||||||
/// @param lhs the left side of the expression
|
|
||||||
/// @returns the parsed expression or nullptr
|
|
||||||
Expect<const ast::Expression*> expect_equality_expr(const ast::Expression* lhs);
|
|
||||||
/// Parses the `equality_expression` grammar element
|
|
||||||
/// @returns the parsed expression or nullptr
|
|
||||||
Maybe<const ast::Expression*> equality_expression();
|
|
||||||
/// Parses the `bitwise_expression.post.unary_expression` grammar element
|
/// Parses the `bitwise_expression.post.unary_expression` grammar element
|
||||||
/// @param lhs the left side of the expression
|
/// @param lhs the left side of the expression
|
||||||
/// @returns the parsed expression or nullptr
|
/// @returns the parsed expression or nullptr
|
||||||
|
@ -709,49 +669,6 @@ class ParserImpl {
|
||||||
/// Parse the `additive_operator` grammar element
|
/// Parse the `additive_operator` grammar element
|
||||||
/// @returns the parsed operator if successful
|
/// @returns the parsed operator if successful
|
||||||
Maybe<ast::BinaryOp> additive_operator();
|
Maybe<ast::BinaryOp> additive_operator();
|
||||||
/// Parses the recursive part of the `and_expression`, erroring on parse
|
|
||||||
/// failure.
|
|
||||||
/// @param lhs the left side of the expression
|
|
||||||
/// @returns the parsed expression or nullptr
|
|
||||||
Expect<const ast::Expression*> expect_and_expr(const ast::Expression* lhs);
|
|
||||||
/// Parses the `and_expression` grammar element
|
|
||||||
/// @returns the parsed expression or nullptr
|
|
||||||
Maybe<const ast::Expression*> and_expression();
|
|
||||||
/// Parses the recursive part of the `exclusive_or_expression`, erroring on
|
|
||||||
/// parse failure.
|
|
||||||
/// @param lhs the left side of the expression
|
|
||||||
/// @returns the parsed expression or nullptr
|
|
||||||
Expect<const ast::Expression*> expect_exclusive_or_expr(const ast::Expression* lhs);
|
|
||||||
/// Parses the `exclusive_or_expression` grammar elememnt
|
|
||||||
/// @returns the parsed expression or nullptr
|
|
||||||
Maybe<const ast::Expression*> exclusive_or_expression();
|
|
||||||
/// Parses the recursive part of the `inclusive_or_expression`, erroring on
|
|
||||||
/// parse failure.
|
|
||||||
/// @param lhs the left side of the expression
|
|
||||||
/// @returns the parsed expression or nullptr
|
|
||||||
Expect<const ast::Expression*> expect_inclusive_or_expr(const ast::Expression* lhs);
|
|
||||||
/// Parses the `inclusive_or_expression` grammar element
|
|
||||||
/// @returns the parsed expression or nullptr
|
|
||||||
Maybe<const ast::Expression*> inclusive_or_expression();
|
|
||||||
/// Parses the recursive part of the `logical_and_expression`, erroring on
|
|
||||||
/// parse failure.
|
|
||||||
/// @param lhs the left side of the expression
|
|
||||||
/// @returns the parsed expression or nullptr
|
|
||||||
Expect<const ast::Expression*> expect_logical_and_expr(const ast::Expression* lhs);
|
|
||||||
/// Parses a `logical_and_expression` grammar element
|
|
||||||
/// @returns the parsed expression or nullptr
|
|
||||||
Maybe<const ast::Expression*> logical_and_expression();
|
|
||||||
/// Parses the recursive part of the `logical_or_expression`, erroring on
|
|
||||||
/// parse failure.
|
|
||||||
/// @param lhs the left side of the expression
|
|
||||||
/// @returns the parsed expression or nullptr
|
|
||||||
Expect<const ast::Expression*> expect_logical_or_expr(const ast::Expression* lhs);
|
|
||||||
/// Parses a `logical_or_expression` grammar element
|
|
||||||
/// @returns the parsed expression or nullptr
|
|
||||||
Maybe<const ast::Expression*> logical_or_expression();
|
|
||||||
/// Parses an `expression` grammar element
|
|
||||||
/// @returns the parsed expression or nullptr
|
|
||||||
Maybe<const ast::Expression*> expression();
|
|
||||||
/// Parses a `compound_assignment_operator` grammar element
|
/// Parses a `compound_assignment_operator` grammar element
|
||||||
/// @returns the parsed compound assignment operator
|
/// @returns the parsed compound assignment operator
|
||||||
Maybe<ast::BinaryOp> compound_assignment_operator();
|
Maybe<ast::BinaryOp> compound_assignment_operator();
|
||||||
|
|
|
@ -17,80 +17,6 @@
|
||||||
namespace tint::reader::wgsl {
|
namespace tint::reader::wgsl {
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
TEST_F(ParserImplTest, AdditiveExpression_Orig_Parses_Plus) {
|
|
||||||
auto p = parser("a + true");
|
|
||||||
auto e = p->additive_expression();
|
|
||||||
EXPECT_TRUE(e.matched);
|
|
||||||
EXPECT_FALSE(e.errored);
|
|
||||||
EXPECT_FALSE(p->has_error()) << p->error();
|
|
||||||
ASSERT_NE(e.value, nullptr);
|
|
||||||
|
|
||||||
EXPECT_EQ(e->source.range.begin.line, 1u);
|
|
||||||
EXPECT_EQ(e->source.range.begin.column, 3u);
|
|
||||||
EXPECT_EQ(e->source.range.end.line, 1u);
|
|
||||||
EXPECT_EQ(e->source.range.end.column, 4u);
|
|
||||||
|
|
||||||
ASSERT_TRUE(e->Is<ast::BinaryExpression>());
|
|
||||||
auto* rel = e->As<ast::BinaryExpression>();
|
|
||||||
EXPECT_EQ(ast::BinaryOp::kAdd, rel->op);
|
|
||||||
|
|
||||||
ASSERT_TRUE(rel->lhs->Is<ast::IdentifierExpression>());
|
|
||||||
auto* ident = rel->lhs->As<ast::IdentifierExpression>();
|
|
||||||
EXPECT_EQ(ident->symbol, p->builder().Symbols().Get("a"));
|
|
||||||
|
|
||||||
ASSERT_TRUE(rel->rhs->Is<ast::BoolLiteralExpression>());
|
|
||||||
ASSERT_TRUE(rel->rhs->As<ast::BoolLiteralExpression>()->value);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(ParserImplTest, AdditiveExpression_Orig_Parses_Minus) {
|
|
||||||
auto p = parser("a - true");
|
|
||||||
auto e = p->additive_expression();
|
|
||||||
EXPECT_TRUE(e.matched);
|
|
||||||
EXPECT_FALSE(e.errored);
|
|
||||||
EXPECT_FALSE(p->has_error()) << p->error();
|
|
||||||
ASSERT_NE(e.value, nullptr);
|
|
||||||
|
|
||||||
ASSERT_TRUE(e->Is<ast::BinaryExpression>());
|
|
||||||
auto* rel = e->As<ast::BinaryExpression>();
|
|
||||||
EXPECT_EQ(ast::BinaryOp::kSubtract, rel->op);
|
|
||||||
|
|
||||||
ASSERT_TRUE(rel->lhs->Is<ast::IdentifierExpression>());
|
|
||||||
auto* ident = rel->lhs->As<ast::IdentifierExpression>();
|
|
||||||
EXPECT_EQ(ident->symbol, p->builder().Symbols().Get("a"));
|
|
||||||
|
|
||||||
ASSERT_TRUE(rel->rhs->Is<ast::BoolLiteralExpression>());
|
|
||||||
ASSERT_TRUE(rel->rhs->As<ast::BoolLiteralExpression>()->value);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(ParserImplTest, AdditiveExpression_Orig_InvalidLHS) {
|
|
||||||
auto p = parser("if (a) {} + true");
|
|
||||||
auto e = p->additive_expression();
|
|
||||||
EXPECT_FALSE(e.matched);
|
|
||||||
EXPECT_FALSE(e.errored);
|
|
||||||
EXPECT_FALSE(p->has_error()) << p->error();
|
|
||||||
EXPECT_EQ(e.value, nullptr);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(ParserImplTest, AdditiveExpression_Orig_InvalidRHS) {
|
|
||||||
auto p = parser("true + if (a) {}");
|
|
||||||
auto e = p->additive_expression();
|
|
||||||
EXPECT_FALSE(e.matched);
|
|
||||||
EXPECT_TRUE(e.errored);
|
|
||||||
EXPECT_EQ(e.value, nullptr);
|
|
||||||
EXPECT_TRUE(p->has_error());
|
|
||||||
EXPECT_EQ(p->error(), "1:8: unable to parse right side of + expression");
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(ParserImplTest, AdditiveExpression_Orig_NoOr_ReturnsLHS) {
|
|
||||||
auto p = parser("a true");
|
|
||||||
auto e = p->additive_expression();
|
|
||||||
EXPECT_TRUE(e.matched);
|
|
||||||
EXPECT_FALSE(e.errored);
|
|
||||||
EXPECT_FALSE(p->has_error()) << p->error();
|
|
||||||
ASSERT_NE(e.value, nullptr);
|
|
||||||
ASSERT_TRUE(e->Is<ast::IdentifierExpression>());
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(ParserImplTest, AdditiveExpression_Parses_Plus) {
|
TEST_F(ParserImplTest, AdditiveExpression_Parses_Plus) {
|
||||||
auto p = parser("a + b");
|
auto p = parser("a + b");
|
||||||
auto lhs = p->unary_expression();
|
auto lhs = p->unary_expression();
|
||||||
|
|
|
@ -1,75 +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 "src/tint/reader/wgsl/parser_impl_test_helper.h"
|
|
||||||
|
|
||||||
namespace tint::reader::wgsl {
|
|
||||||
namespace {
|
|
||||||
|
|
||||||
TEST_F(ParserImplTest, AndExpression_Parses) {
|
|
||||||
auto p = parser("a & true");
|
|
||||||
auto e = p->and_expression();
|
|
||||||
EXPECT_TRUE(e.matched);
|
|
||||||
EXPECT_FALSE(e.errored);
|
|
||||||
EXPECT_FALSE(p->has_error()) << p->error();
|
|
||||||
ASSERT_NE(e.value, nullptr);
|
|
||||||
|
|
||||||
EXPECT_EQ(e->source.range.begin.line, 1u);
|
|
||||||
EXPECT_EQ(e->source.range.begin.column, 3u);
|
|
||||||
EXPECT_EQ(e->source.range.end.line, 1u);
|
|
||||||
EXPECT_EQ(e->source.range.end.column, 4u);
|
|
||||||
|
|
||||||
ASSERT_TRUE(e->Is<ast::BinaryExpression>());
|
|
||||||
auto* rel = e->As<ast::BinaryExpression>();
|
|
||||||
EXPECT_EQ(ast::BinaryOp::kAnd, rel->op);
|
|
||||||
|
|
||||||
ASSERT_TRUE(rel->lhs->Is<ast::IdentifierExpression>());
|
|
||||||
auto* ident = rel->lhs->As<ast::IdentifierExpression>();
|
|
||||||
EXPECT_EQ(ident->symbol, p->builder().Symbols().Register("a"));
|
|
||||||
|
|
||||||
ASSERT_TRUE(rel->rhs->Is<ast::BoolLiteralExpression>());
|
|
||||||
ASSERT_TRUE(rel->rhs->As<ast::BoolLiteralExpression>()->value);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(ParserImplTest, AndExpression_InvalidLHS) {
|
|
||||||
auto p = parser("if (a) {} & true");
|
|
||||||
auto e = p->and_expression();
|
|
||||||
EXPECT_FALSE(e.matched);
|
|
||||||
EXPECT_FALSE(e.errored);
|
|
||||||
EXPECT_FALSE(p->has_error()) << p->error();
|
|
||||||
EXPECT_EQ(e.value, nullptr);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(ParserImplTest, AndExpression_InvalidRHS) {
|
|
||||||
auto p = parser("true & if (a) {}");
|
|
||||||
auto e = p->and_expression();
|
|
||||||
EXPECT_FALSE(e.matched);
|
|
||||||
EXPECT_TRUE(e.errored);
|
|
||||||
EXPECT_EQ(e.value, nullptr);
|
|
||||||
EXPECT_TRUE(p->has_error());
|
|
||||||
EXPECT_EQ(p->error(), "1:8: unable to parse right side of & expression");
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(ParserImplTest, AndExpression_NoOr_ReturnsLHS) {
|
|
||||||
auto p = parser("a true");
|
|
||||||
auto e = p->and_expression();
|
|
||||||
EXPECT_TRUE(e.matched);
|
|
||||||
EXPECT_FALSE(e.errored);
|
|
||||||
EXPECT_FALSE(p->has_error()) << p->error();
|
|
||||||
ASSERT_NE(e.value, nullptr);
|
|
||||||
ASSERT_TRUE(e->Is<ast::IdentifierExpression>());
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace
|
|
||||||
} // namespace tint::reader::wgsl
|
|
|
@ -1,100 +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 "src/tint/reader/wgsl/parser_impl_test_helper.h"
|
|
||||||
|
|
||||||
namespace tint::reader::wgsl {
|
|
||||||
namespace {
|
|
||||||
|
|
||||||
TEST_F(ParserImplTest, EqualityExpression_Parses_Equal) {
|
|
||||||
auto p = parser("a == true");
|
|
||||||
auto e = p->equality_expression();
|
|
||||||
EXPECT_TRUE(e.matched);
|
|
||||||
EXPECT_FALSE(e.errored);
|
|
||||||
EXPECT_FALSE(p->has_error()) << p->error();
|
|
||||||
ASSERT_NE(e.value, nullptr);
|
|
||||||
|
|
||||||
EXPECT_EQ(e->source.range.begin.line, 1u);
|
|
||||||
EXPECT_EQ(e->source.range.begin.column, 3u);
|
|
||||||
EXPECT_EQ(e->source.range.end.line, 1u);
|
|
||||||
EXPECT_EQ(e->source.range.end.column, 5u);
|
|
||||||
|
|
||||||
ASSERT_TRUE(e->Is<ast::BinaryExpression>());
|
|
||||||
auto* rel = e->As<ast::BinaryExpression>();
|
|
||||||
EXPECT_EQ(ast::BinaryOp::kEqual, rel->op);
|
|
||||||
|
|
||||||
ASSERT_TRUE(rel->lhs->Is<ast::IdentifierExpression>());
|
|
||||||
auto* ident = rel->lhs->As<ast::IdentifierExpression>();
|
|
||||||
EXPECT_EQ(ident->symbol, p->builder().Symbols().Get("a"));
|
|
||||||
|
|
||||||
ASSERT_TRUE(rel->rhs->Is<ast::BoolLiteralExpression>());
|
|
||||||
ASSERT_TRUE(rel->rhs->As<ast::BoolLiteralExpression>()->value);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(ParserImplTest, EqualityExpression_Parses_NotEqual) {
|
|
||||||
auto p = parser("a != true");
|
|
||||||
auto e = p->equality_expression();
|
|
||||||
EXPECT_TRUE(e.matched);
|
|
||||||
EXPECT_FALSE(e.errored);
|
|
||||||
EXPECT_FALSE(p->has_error()) << p->error();
|
|
||||||
ASSERT_NE(e.value, nullptr);
|
|
||||||
|
|
||||||
EXPECT_EQ(e->source.range.begin.line, 1u);
|
|
||||||
EXPECT_EQ(e->source.range.begin.column, 3u);
|
|
||||||
EXPECT_EQ(e->source.range.end.line, 1u);
|
|
||||||
EXPECT_EQ(e->source.range.end.column, 5u);
|
|
||||||
|
|
||||||
ASSERT_TRUE(e->Is<ast::BinaryExpression>());
|
|
||||||
auto* rel = e->As<ast::BinaryExpression>();
|
|
||||||
EXPECT_EQ(ast::BinaryOp::kNotEqual, rel->op);
|
|
||||||
|
|
||||||
ASSERT_TRUE(rel->lhs->Is<ast::IdentifierExpression>());
|
|
||||||
auto* ident = rel->lhs->As<ast::IdentifierExpression>();
|
|
||||||
EXPECT_EQ(ident->symbol, p->builder().Symbols().Get("a"));
|
|
||||||
|
|
||||||
ASSERT_TRUE(rel->rhs->Is<ast::BoolLiteralExpression>());
|
|
||||||
ASSERT_TRUE(rel->rhs->As<ast::BoolLiteralExpression>()->value);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(ParserImplTest, EqualityExpression_InvalidLHS) {
|
|
||||||
auto p = parser("if (a) {} == true");
|
|
||||||
auto e = p->equality_expression();
|
|
||||||
EXPECT_FALSE(e.matched);
|
|
||||||
EXPECT_FALSE(e.errored);
|
|
||||||
EXPECT_FALSE(p->has_error()) << p->error();
|
|
||||||
EXPECT_EQ(e.value, nullptr);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(ParserImplTest, EqualityExpression_InvalidRHS) {
|
|
||||||
auto p = parser("true == if (a) {}");
|
|
||||||
auto e = p->equality_expression();
|
|
||||||
EXPECT_FALSE(e.matched);
|
|
||||||
EXPECT_TRUE(e.errored);
|
|
||||||
EXPECT_EQ(e.value, nullptr);
|
|
||||||
EXPECT_TRUE(p->has_error());
|
|
||||||
EXPECT_EQ(p->error(), "1:9: unable to parse right side of == expression");
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(ParserImplTest, EqualityExpression_NoOr_ReturnsLHS) {
|
|
||||||
auto p = parser("a true");
|
|
||||||
auto e = p->equality_expression();
|
|
||||||
EXPECT_TRUE(e.matched);
|
|
||||||
EXPECT_FALSE(e.errored);
|
|
||||||
EXPECT_FALSE(p->has_error()) << p->error();
|
|
||||||
ASSERT_NE(e.value, nullptr);
|
|
||||||
ASSERT_TRUE(e->Is<ast::IdentifierExpression>());
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace
|
|
||||||
} // namespace tint::reader::wgsl
|
|
|
@ -1,75 +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 "src/tint/reader/wgsl/parser_impl_test_helper.h"
|
|
||||||
|
|
||||||
namespace tint::reader::wgsl {
|
|
||||||
namespace {
|
|
||||||
|
|
||||||
TEST_F(ParserImplTest, ExclusiveOrExpression_Parses) {
|
|
||||||
auto p = parser("a ^ true");
|
|
||||||
auto e = p->exclusive_or_expression();
|
|
||||||
EXPECT_TRUE(e.matched);
|
|
||||||
EXPECT_FALSE(e.errored);
|
|
||||||
EXPECT_FALSE(p->has_error()) << p->error();
|
|
||||||
ASSERT_NE(e.value, nullptr);
|
|
||||||
|
|
||||||
EXPECT_EQ(e->source.range.begin.line, 1u);
|
|
||||||
EXPECT_EQ(e->source.range.begin.column, 3u);
|
|
||||||
EXPECT_EQ(e->source.range.end.line, 1u);
|
|
||||||
EXPECT_EQ(e->source.range.end.column, 4u);
|
|
||||||
|
|
||||||
ASSERT_TRUE(e->Is<ast::BinaryExpression>());
|
|
||||||
auto* rel = e->As<ast::BinaryExpression>();
|
|
||||||
EXPECT_EQ(ast::BinaryOp::kXor, rel->op);
|
|
||||||
|
|
||||||
ASSERT_TRUE(rel->lhs->Is<ast::IdentifierExpression>());
|
|
||||||
auto* ident = rel->lhs->As<ast::IdentifierExpression>();
|
|
||||||
EXPECT_EQ(ident->symbol, p->builder().Symbols().Get("a"));
|
|
||||||
|
|
||||||
ASSERT_TRUE(rel->rhs->Is<ast::BoolLiteralExpression>());
|
|
||||||
ASSERT_TRUE(rel->rhs->As<ast::BoolLiteralExpression>()->value);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(ParserImplTest, ExclusiveOrExpression_InvalidLHS) {
|
|
||||||
auto p = parser("if (a) {} ^ true");
|
|
||||||
auto e = p->exclusive_or_expression();
|
|
||||||
EXPECT_FALSE(e.matched);
|
|
||||||
EXPECT_FALSE(e.errored);
|
|
||||||
EXPECT_FALSE(p->has_error()) << p->error();
|
|
||||||
EXPECT_EQ(e.value, nullptr);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(ParserImplTest, ExclusiveOrExpression_InvalidRHS) {
|
|
||||||
auto p = parser("true ^ if (a) {}");
|
|
||||||
auto e = p->exclusive_or_expression();
|
|
||||||
EXPECT_FALSE(e.matched);
|
|
||||||
EXPECT_TRUE(e.errored);
|
|
||||||
EXPECT_EQ(e.value, nullptr);
|
|
||||||
ASSERT_TRUE(p->has_error());
|
|
||||||
EXPECT_EQ(p->error(), "1:8: unable to parse right side of ^ expression");
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(ParserImplTest, ExclusiveOrExpression_NoOr_ReturnsLHS) {
|
|
||||||
auto p = parser("a true");
|
|
||||||
auto e = p->exclusive_or_expression();
|
|
||||||
EXPECT_TRUE(e.matched);
|
|
||||||
EXPECT_FALSE(e.errored);
|
|
||||||
EXPECT_FALSE(p->has_error()) << p->error();
|
|
||||||
ASSERT_NE(e.value, nullptr);
|
|
||||||
ASSERT_TRUE(e->Is<ast::IdentifierExpression>());
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace
|
|
||||||
} // namespace tint::reader::wgsl
|
|
|
@ -1,75 +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 "src/tint/reader/wgsl/parser_impl_test_helper.h"
|
|
||||||
|
|
||||||
namespace tint::reader::wgsl {
|
|
||||||
namespace {
|
|
||||||
|
|
||||||
TEST_F(ParserImplTest, InclusiveOrExpression_Parses) {
|
|
||||||
auto p = parser("a | true");
|
|
||||||
auto e = p->inclusive_or_expression();
|
|
||||||
EXPECT_TRUE(e.matched);
|
|
||||||
EXPECT_FALSE(e.errored);
|
|
||||||
EXPECT_FALSE(p->has_error()) << p->error();
|
|
||||||
ASSERT_NE(e.value, nullptr);
|
|
||||||
|
|
||||||
EXPECT_EQ(e->source.range.begin.line, 1u);
|
|
||||||
EXPECT_EQ(e->source.range.begin.column, 3u);
|
|
||||||
EXPECT_EQ(e->source.range.end.line, 1u);
|
|
||||||
EXPECT_EQ(e->source.range.end.column, 4u);
|
|
||||||
|
|
||||||
ASSERT_TRUE(e->Is<ast::BinaryExpression>());
|
|
||||||
auto* rel = e->As<ast::BinaryExpression>();
|
|
||||||
EXPECT_EQ(ast::BinaryOp::kOr, rel->op);
|
|
||||||
|
|
||||||
ASSERT_TRUE(rel->lhs->Is<ast::IdentifierExpression>());
|
|
||||||
auto* ident = rel->lhs->As<ast::IdentifierExpression>();
|
|
||||||
EXPECT_EQ(ident->symbol, p->builder().Symbols().Get("a"));
|
|
||||||
|
|
||||||
ASSERT_TRUE(rel->rhs->Is<ast::BoolLiteralExpression>());
|
|
||||||
ASSERT_TRUE(rel->rhs->As<ast::BoolLiteralExpression>()->value);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(ParserImplTest, InclusiveOrExpression_InvalidLHS) {
|
|
||||||
auto p = parser("if (a) {} | true");
|
|
||||||
auto e = p->inclusive_or_expression();
|
|
||||||
EXPECT_FALSE(e.matched);
|
|
||||||
EXPECT_FALSE(e.errored);
|
|
||||||
EXPECT_FALSE(p->has_error()) << p->error();
|
|
||||||
ASSERT_EQ(e.value, nullptr);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(ParserImplTest, InclusiveOrExpression_InvalidRHS) {
|
|
||||||
auto p = parser("true | if (a) {}");
|
|
||||||
auto e = p->inclusive_or_expression();
|
|
||||||
EXPECT_FALSE(e.matched);
|
|
||||||
EXPECT_TRUE(e.errored);
|
|
||||||
EXPECT_EQ(e.value, nullptr);
|
|
||||||
EXPECT_TRUE(p->has_error());
|
|
||||||
EXPECT_EQ(p->error(), "1:8: unable to parse right side of | expression");
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(ParserImplTest, InclusiveOrExpression_NoOr_ReturnsLHS) {
|
|
||||||
auto p = parser("a true");
|
|
||||||
auto e = p->inclusive_or_expression();
|
|
||||||
EXPECT_TRUE(e.matched);
|
|
||||||
EXPECT_FALSE(e.errored);
|
|
||||||
EXPECT_FALSE(p->has_error()) << p->error();
|
|
||||||
ASSERT_NE(e.value, nullptr);
|
|
||||||
ASSERT_TRUE(e->Is<ast::IdentifierExpression>());
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace
|
|
||||||
} // namespace tint::reader::wgsl
|
|
|
@ -1,75 +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 "src/tint/reader/wgsl/parser_impl_test_helper.h"
|
|
||||||
|
|
||||||
namespace tint::reader::wgsl {
|
|
||||||
namespace {
|
|
||||||
|
|
||||||
TEST_F(ParserImplTest, LogicalAndExpression_Parses) {
|
|
||||||
auto p = parser("a && true");
|
|
||||||
auto e = p->logical_and_expression();
|
|
||||||
EXPECT_TRUE(e.matched);
|
|
||||||
EXPECT_FALSE(e.errored);
|
|
||||||
EXPECT_FALSE(p->has_error()) << p->error();
|
|
||||||
ASSERT_NE(e.value, nullptr);
|
|
||||||
|
|
||||||
EXPECT_EQ(e->source.range.begin.line, 1u);
|
|
||||||
EXPECT_EQ(e->source.range.begin.column, 3u);
|
|
||||||
EXPECT_EQ(e->source.range.end.line, 1u);
|
|
||||||
EXPECT_EQ(e->source.range.end.column, 5u);
|
|
||||||
|
|
||||||
ASSERT_TRUE(e->Is<ast::BinaryExpression>());
|
|
||||||
auto* rel = e->As<ast::BinaryExpression>();
|
|
||||||
EXPECT_EQ(ast::BinaryOp::kLogicalAnd, rel->op);
|
|
||||||
|
|
||||||
ASSERT_TRUE(rel->lhs->Is<ast::IdentifierExpression>());
|
|
||||||
auto* ident = rel->lhs->As<ast::IdentifierExpression>();
|
|
||||||
EXPECT_EQ(ident->symbol, p->builder().Symbols().Get("a"));
|
|
||||||
|
|
||||||
ASSERT_TRUE(rel->rhs->Is<ast::BoolLiteralExpression>());
|
|
||||||
ASSERT_TRUE(rel->rhs->As<ast::BoolLiteralExpression>()->value);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(ParserImplTest, LogicalAndExpression_InvalidLHS) {
|
|
||||||
auto p = parser("if (a) {} && true");
|
|
||||||
auto e = p->logical_and_expression();
|
|
||||||
EXPECT_FALSE(e.matched);
|
|
||||||
EXPECT_FALSE(e.errored);
|
|
||||||
EXPECT_FALSE(p->has_error()) << p->error();
|
|
||||||
EXPECT_EQ(e.value, nullptr);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(ParserImplTest, LogicalAndExpression_InvalidRHS) {
|
|
||||||
auto p = parser("true && if (a) {}");
|
|
||||||
auto e = p->logical_and_expression();
|
|
||||||
EXPECT_FALSE(e.matched);
|
|
||||||
EXPECT_TRUE(e.errored);
|
|
||||||
EXPECT_EQ(e.value, nullptr);
|
|
||||||
EXPECT_TRUE(p->has_error());
|
|
||||||
EXPECT_EQ(p->error(), "1:9: unable to parse right side of && expression");
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(ParserImplTest, LogicalAndExpression_NoOr_ReturnsLHS) {
|
|
||||||
auto p = parser("a true");
|
|
||||||
auto e = p->logical_and_expression();
|
|
||||||
EXPECT_TRUE(e.matched);
|
|
||||||
EXPECT_FALSE(e.errored);
|
|
||||||
EXPECT_FALSE(p->has_error()) << p->error();
|
|
||||||
ASSERT_NE(e.value, nullptr);
|
|
||||||
ASSERT_TRUE(e->Is<ast::IdentifierExpression>());
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace
|
|
||||||
} // namespace tint::reader::wgsl
|
|
|
@ -1,75 +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 "src/tint/reader/wgsl/parser_impl_test_helper.h"
|
|
||||||
|
|
||||||
namespace tint::reader::wgsl {
|
|
||||||
namespace {
|
|
||||||
|
|
||||||
TEST_F(ParserImplTest, LogicalOrExpression_Parses) {
|
|
||||||
auto p = parser("a || true");
|
|
||||||
auto e = p->logical_or_expression();
|
|
||||||
EXPECT_TRUE(e.matched);
|
|
||||||
EXPECT_FALSE(e.errored);
|
|
||||||
EXPECT_FALSE(p->has_error()) << p->error();
|
|
||||||
ASSERT_NE(e.value, nullptr);
|
|
||||||
|
|
||||||
EXPECT_EQ(e->source.range.begin.line, 1u);
|
|
||||||
EXPECT_EQ(e->source.range.begin.column, 3u);
|
|
||||||
EXPECT_EQ(e->source.range.end.line, 1u);
|
|
||||||
EXPECT_EQ(e->source.range.end.column, 5u);
|
|
||||||
|
|
||||||
ASSERT_TRUE(e->Is<ast::BinaryExpression>());
|
|
||||||
auto* rel = e->As<ast::BinaryExpression>();
|
|
||||||
EXPECT_EQ(ast::BinaryOp::kLogicalOr, rel->op);
|
|
||||||
|
|
||||||
ASSERT_TRUE(rel->lhs->Is<ast::IdentifierExpression>());
|
|
||||||
auto* ident = rel->lhs->As<ast::IdentifierExpression>();
|
|
||||||
EXPECT_EQ(ident->symbol, p->builder().Symbols().Get("a"));
|
|
||||||
|
|
||||||
ASSERT_TRUE(rel->rhs->Is<ast::BoolLiteralExpression>());
|
|
||||||
ASSERT_TRUE(rel->rhs->As<ast::BoolLiteralExpression>()->value);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(ParserImplTest, LogicalOrExpression_InvalidLHS) {
|
|
||||||
auto p = parser("if (a) {} || true");
|
|
||||||
auto e = p->logical_or_expression();
|
|
||||||
EXPECT_FALSE(e.matched);
|
|
||||||
EXPECT_FALSE(e.errored);
|
|
||||||
EXPECT_FALSE(p->has_error()) << p->error();
|
|
||||||
EXPECT_EQ(e.value, nullptr);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(ParserImplTest, LogicalOrExpression_InvalidRHS) {
|
|
||||||
auto p = parser("true || if (a) {}");
|
|
||||||
auto e = p->logical_or_expression();
|
|
||||||
EXPECT_FALSE(e.matched);
|
|
||||||
EXPECT_TRUE(e.errored);
|
|
||||||
EXPECT_EQ(e.value, nullptr);
|
|
||||||
EXPECT_TRUE(p->has_error());
|
|
||||||
EXPECT_EQ(p->error(), "1:9: unable to parse right side of || expression");
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(ParserImplTest, LogicalOrExpression_NoOr_ReturnsLHS) {
|
|
||||||
auto p = parser("a true");
|
|
||||||
auto e = p->logical_or_expression();
|
|
||||||
EXPECT_TRUE(e.matched);
|
|
||||||
EXPECT_FALSE(e.errored);
|
|
||||||
EXPECT_FALSE(p->has_error()) << p->error();
|
|
||||||
ASSERT_NE(e.value, nullptr);
|
|
||||||
ASSERT_TRUE(e->Is<ast::IdentifierExpression>());
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace
|
|
||||||
} // namespace tint::reader::wgsl
|
|
|
@ -17,100 +17,6 @@
|
||||||
namespace tint::reader::wgsl {
|
namespace tint::reader::wgsl {
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
TEST_F(ParserImplTest, MultiplicativeExpression_Orig_Parses_Multiply) {
|
|
||||||
auto p = parser("a * true");
|
|
||||||
auto e = p->multiplicative_expression();
|
|
||||||
EXPECT_TRUE(e.matched);
|
|
||||||
EXPECT_FALSE(e.errored);
|
|
||||||
EXPECT_FALSE(p->has_error()) << p->error();
|
|
||||||
ASSERT_NE(e.value, nullptr);
|
|
||||||
|
|
||||||
EXPECT_EQ(e->source.range.begin.line, 1u);
|
|
||||||
EXPECT_EQ(e->source.range.begin.column, 3u);
|
|
||||||
EXPECT_EQ(e->source.range.end.line, 1u);
|
|
||||||
EXPECT_EQ(e->source.range.end.column, 4u);
|
|
||||||
|
|
||||||
ASSERT_TRUE(e->Is<ast::BinaryExpression>());
|
|
||||||
auto* rel = e->As<ast::BinaryExpression>();
|
|
||||||
EXPECT_EQ(ast::BinaryOp::kMultiply, rel->op);
|
|
||||||
|
|
||||||
ASSERT_TRUE(rel->lhs->Is<ast::IdentifierExpression>());
|
|
||||||
auto* ident = rel->lhs->As<ast::IdentifierExpression>();
|
|
||||||
EXPECT_EQ(ident->symbol, p->builder().Symbols().Get("a"));
|
|
||||||
|
|
||||||
ASSERT_TRUE(rel->rhs->Is<ast::BoolLiteralExpression>());
|
|
||||||
ASSERT_TRUE(rel->rhs->As<ast::BoolLiteralExpression>()->value);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(ParserImplTest, MultiplicativeExpression_Orig_Parses_Divide) {
|
|
||||||
auto p = parser("a / true");
|
|
||||||
auto e = p->multiplicative_expression();
|
|
||||||
EXPECT_TRUE(e.matched);
|
|
||||||
EXPECT_FALSE(e.errored);
|
|
||||||
EXPECT_FALSE(p->has_error()) << p->error();
|
|
||||||
ASSERT_NE(e.value, nullptr);
|
|
||||||
|
|
||||||
ASSERT_TRUE(e->Is<ast::BinaryExpression>());
|
|
||||||
auto* rel = e->As<ast::BinaryExpression>();
|
|
||||||
EXPECT_EQ(ast::BinaryOp::kDivide, rel->op);
|
|
||||||
|
|
||||||
ASSERT_TRUE(rel->lhs->Is<ast::IdentifierExpression>());
|
|
||||||
auto* ident = rel->lhs->As<ast::IdentifierExpression>();
|
|
||||||
EXPECT_EQ(ident->symbol, p->builder().Symbols().Get("a"));
|
|
||||||
|
|
||||||
ASSERT_TRUE(rel->rhs->Is<ast::BoolLiteralExpression>());
|
|
||||||
ASSERT_TRUE(rel->rhs->As<ast::BoolLiteralExpression>()->value);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(ParserImplTest, MultiplicativeExpression_Orig_Parses_Modulo) {
|
|
||||||
auto p = parser("a % true");
|
|
||||||
auto e = p->multiplicative_expression();
|
|
||||||
EXPECT_TRUE(e.matched);
|
|
||||||
EXPECT_FALSE(e.errored);
|
|
||||||
EXPECT_FALSE(p->has_error()) << p->error();
|
|
||||||
ASSERT_NE(e.value, nullptr);
|
|
||||||
|
|
||||||
ASSERT_TRUE(e->Is<ast::BinaryExpression>());
|
|
||||||
auto* rel = e->As<ast::BinaryExpression>();
|
|
||||||
EXPECT_EQ(ast::BinaryOp::kModulo, rel->op);
|
|
||||||
|
|
||||||
ASSERT_TRUE(rel->lhs->Is<ast::IdentifierExpression>());
|
|
||||||
auto* ident = rel->lhs->As<ast::IdentifierExpression>();
|
|
||||||
EXPECT_EQ(ident->symbol, p->builder().Symbols().Get("a"));
|
|
||||||
|
|
||||||
ASSERT_TRUE(rel->rhs->Is<ast::BoolLiteralExpression>());
|
|
||||||
ASSERT_TRUE(rel->rhs->As<ast::BoolLiteralExpression>()->value);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(ParserImplTest, MultiplicativeExpression_Orig_InvalidLHS) {
|
|
||||||
auto p = parser("if (a) {} * true");
|
|
||||||
auto e = p->multiplicative_expression();
|
|
||||||
EXPECT_FALSE(e.matched);
|
|
||||||
EXPECT_FALSE(e.errored);
|
|
||||||
EXPECT_FALSE(p->has_error()) << p->error();
|
|
||||||
EXPECT_EQ(e.value, nullptr);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(ParserImplTest, MultiplicativeExpression_Orig_InvalidRHS) {
|
|
||||||
auto p = parser("true * if (a) {}");
|
|
||||||
auto e = p->multiplicative_expression();
|
|
||||||
EXPECT_FALSE(e.matched);
|
|
||||||
EXPECT_TRUE(e.errored);
|
|
||||||
EXPECT_EQ(e.value, nullptr);
|
|
||||||
ASSERT_TRUE(p->has_error());
|
|
||||||
EXPECT_EQ(p->error(), "1:8: unable to parse right side of * expression");
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(ParserImplTest, MultiplicativeExpression_Orig_NoOr_ReturnsLHS) {
|
|
||||||
auto p = parser("a true");
|
|
||||||
auto e = p->multiplicative_expression();
|
|
||||||
EXPECT_TRUE(e.matched);
|
|
||||||
EXPECT_FALSE(e.errored);
|
|
||||||
EXPECT_FALSE(p->has_error()) << p->error();
|
|
||||||
ASSERT_NE(e.value, nullptr);
|
|
||||||
ASSERT_TRUE(e->Is<ast::IdentifierExpression>());
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(ParserImplTest, MultiplicativeExpression_Parses_Multiply) {
|
TEST_F(ParserImplTest, MultiplicativeExpression_Parses_Multiply) {
|
||||||
auto p = parser("a * b");
|
auto p = parser("a * b");
|
||||||
auto lhs = p->unary_expression();
|
auto lhs = p->unary_expression();
|
||||||
|
|
|
@ -17,133 +17,6 @@
|
||||||
namespace tint::reader::wgsl {
|
namespace tint::reader::wgsl {
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
TEST_F(ParserImplTest, RelationalExpression_Orig_Parses_LessThan) {
|
|
||||||
auto p = parser("a < true");
|
|
||||||
auto e = p->relational_expression();
|
|
||||||
EXPECT_TRUE(e.matched);
|
|
||||||
EXPECT_FALSE(e.errored);
|
|
||||||
EXPECT_FALSE(p->has_error()) << p->error();
|
|
||||||
ASSERT_NE(e.value, nullptr);
|
|
||||||
|
|
||||||
EXPECT_EQ(e->source.range.begin.line, 1u);
|
|
||||||
EXPECT_EQ(e->source.range.begin.column, 3u);
|
|
||||||
EXPECT_EQ(e->source.range.end.line, 1u);
|
|
||||||
EXPECT_EQ(e->source.range.end.column, 4u);
|
|
||||||
|
|
||||||
ASSERT_TRUE(e->Is<ast::BinaryExpression>());
|
|
||||||
auto* rel = e->As<ast::BinaryExpression>();
|
|
||||||
EXPECT_EQ(ast::BinaryOp::kLessThan, rel->op);
|
|
||||||
|
|
||||||
ASSERT_TRUE(rel->lhs->Is<ast::IdentifierExpression>());
|
|
||||||
auto* ident = rel->lhs->As<ast::IdentifierExpression>();
|
|
||||||
EXPECT_EQ(ident->symbol, p->builder().Symbols().Register("a"));
|
|
||||||
|
|
||||||
ASSERT_TRUE(rel->rhs->Is<ast::BoolLiteralExpression>());
|
|
||||||
ASSERT_TRUE(rel->rhs->As<ast::BoolLiteralExpression>()->value);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(ParserImplTest, RelationalExpression_Orig_Parses_GreaterThan) {
|
|
||||||
auto p = parser("a > true");
|
|
||||||
auto e = p->relational_expression();
|
|
||||||
EXPECT_TRUE(e.matched);
|
|
||||||
EXPECT_FALSE(e.errored);
|
|
||||||
EXPECT_FALSE(p->has_error()) << p->error();
|
|
||||||
ASSERT_NE(e.value, nullptr);
|
|
||||||
|
|
||||||
EXPECT_EQ(e->source.range.begin.line, 1u);
|
|
||||||
EXPECT_EQ(e->source.range.begin.column, 3u);
|
|
||||||
EXPECT_EQ(e->source.range.end.line, 1u);
|
|
||||||
EXPECT_EQ(e->source.range.end.column, 4u);
|
|
||||||
|
|
||||||
ASSERT_TRUE(e->Is<ast::BinaryExpression>());
|
|
||||||
auto* rel = e->As<ast::BinaryExpression>();
|
|
||||||
EXPECT_EQ(ast::BinaryOp::kGreaterThan, rel->op);
|
|
||||||
|
|
||||||
ASSERT_TRUE(rel->lhs->Is<ast::IdentifierExpression>());
|
|
||||||
auto* ident = rel->lhs->As<ast::IdentifierExpression>();
|
|
||||||
EXPECT_EQ(ident->symbol, p->builder().Symbols().Register("a"));
|
|
||||||
|
|
||||||
ASSERT_TRUE(rel->rhs->Is<ast::BoolLiteralExpression>());
|
|
||||||
ASSERT_TRUE(rel->rhs->As<ast::BoolLiteralExpression>()->value);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(ParserImplTest, RelationalExpression_Orig_Parses_LessThanEqual) {
|
|
||||||
auto p = parser("a <= true");
|
|
||||||
auto e = p->relational_expression();
|
|
||||||
EXPECT_TRUE(e.matched);
|
|
||||||
EXPECT_FALSE(e.errored);
|
|
||||||
EXPECT_FALSE(p->has_error()) << p->error();
|
|
||||||
ASSERT_NE(e.value, nullptr);
|
|
||||||
|
|
||||||
EXPECT_EQ(e->source.range.begin.line, 1u);
|
|
||||||
EXPECT_EQ(e->source.range.begin.column, 3u);
|
|
||||||
EXPECT_EQ(e->source.range.end.line, 1u);
|
|
||||||
EXPECT_EQ(e->source.range.end.column, 5u);
|
|
||||||
|
|
||||||
ASSERT_TRUE(e->Is<ast::BinaryExpression>());
|
|
||||||
auto* rel = e->As<ast::BinaryExpression>();
|
|
||||||
EXPECT_EQ(ast::BinaryOp::kLessThanEqual, rel->op);
|
|
||||||
|
|
||||||
ASSERT_TRUE(rel->lhs->Is<ast::IdentifierExpression>());
|
|
||||||
auto* ident = rel->lhs->As<ast::IdentifierExpression>();
|
|
||||||
EXPECT_EQ(ident->symbol, p->builder().Symbols().Register("a"));
|
|
||||||
|
|
||||||
ASSERT_TRUE(rel->rhs->Is<ast::BoolLiteralExpression>());
|
|
||||||
ASSERT_TRUE(rel->rhs->As<ast::BoolLiteralExpression>()->value);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(ParserImplTest, RelationalExpression_Orig_Parses_GreaterThanEqual) {
|
|
||||||
auto p = parser("a >= true");
|
|
||||||
auto e = p->relational_expression();
|
|
||||||
EXPECT_TRUE(e.matched);
|
|
||||||
EXPECT_FALSE(e.errored);
|
|
||||||
EXPECT_FALSE(p->has_error()) << p->error();
|
|
||||||
ASSERT_NE(e.value, nullptr);
|
|
||||||
|
|
||||||
EXPECT_EQ(e->source.range.begin.line, 1u);
|
|
||||||
EXPECT_EQ(e->source.range.begin.column, 3u);
|
|
||||||
EXPECT_EQ(e->source.range.end.line, 1u);
|
|
||||||
EXPECT_EQ(e->source.range.end.column, 5u);
|
|
||||||
|
|
||||||
ASSERT_TRUE(e->Is<ast::BinaryExpression>());
|
|
||||||
auto* rel = e->As<ast::BinaryExpression>();
|
|
||||||
EXPECT_EQ(ast::BinaryOp::kGreaterThanEqual, rel->op);
|
|
||||||
|
|
||||||
ASSERT_TRUE(rel->lhs->Is<ast::IdentifierExpression>());
|
|
||||||
auto* ident = rel->lhs->As<ast::IdentifierExpression>();
|
|
||||||
EXPECT_EQ(ident->symbol, p->builder().Symbols().Register("a"));
|
|
||||||
|
|
||||||
ASSERT_TRUE(rel->rhs->Is<ast::BoolLiteralExpression>());
|
|
||||||
ASSERT_TRUE(rel->rhs->As<ast::BoolLiteralExpression>()->value);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(ParserImplTest, RelationalExpression_Orig_InvalidLHS) {
|
|
||||||
auto p = parser("if (a) {} < true");
|
|
||||||
auto e = p->relational_expression();
|
|
||||||
EXPECT_FALSE(e.matched);
|
|
||||||
EXPECT_FALSE(e.errored);
|
|
||||||
EXPECT_FALSE(p->has_error()) << p->error();
|
|
||||||
EXPECT_EQ(e.value, nullptr);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(ParserImplTest, RelationalExpression_Orig_InvalidRHS) {
|
|
||||||
auto p = parser("true < if (a) {}");
|
|
||||||
auto e = p->relational_expression();
|
|
||||||
ASSERT_TRUE(p->has_error());
|
|
||||||
EXPECT_EQ(e.value, nullptr);
|
|
||||||
EXPECT_EQ(p->error(), "1:8: unable to parse right side of < expression");
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(ParserImplTest, RelationalExpression_Orig_NoOr_ReturnsLHS) {
|
|
||||||
auto p = parser("a true");
|
|
||||||
auto e = p->relational_expression();
|
|
||||||
EXPECT_TRUE(e.matched);
|
|
||||||
EXPECT_FALSE(e.errored);
|
|
||||||
EXPECT_FALSE(p->has_error()) << p->error();
|
|
||||||
ASSERT_NE(e.value, nullptr);
|
|
||||||
ASSERT_TRUE(e->Is<ast::IdentifierExpression>());
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(ParserImplTest, RelationalExpression_PostUnary_Parses_LessThan) {
|
TEST_F(ParserImplTest, RelationalExpression_PostUnary_Parses_LessThan) {
|
||||||
auto p = parser("a < true");
|
auto p = parser("a < true");
|
||||||
auto lhs = p->unary_expression();
|
auto lhs = p->unary_expression();
|
||||||
|
@ -352,5 +225,65 @@ TEST_F(ParserImplTest, RelationalExpression_InvalidRHS) {
|
||||||
EXPECT_EQ(p->error(), "1:8: unable to parse right side of < expression");
|
EXPECT_EQ(p->error(), "1:8: unable to parse right side of < expression");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_F(ParserImplTest, RelationalExpression_Parses_Equal) {
|
||||||
|
auto p = parser("a == true");
|
||||||
|
auto e = p->maybe_relational_expression();
|
||||||
|
EXPECT_TRUE(e.matched);
|
||||||
|
EXPECT_FALSE(e.errored);
|
||||||
|
EXPECT_FALSE(p->has_error()) << p->error();
|
||||||
|
ASSERT_NE(e.value, nullptr);
|
||||||
|
|
||||||
|
EXPECT_EQ(e->source.range.begin.line, 1u);
|
||||||
|
EXPECT_EQ(e->source.range.begin.column, 3u);
|
||||||
|
EXPECT_EQ(e->source.range.end.line, 1u);
|
||||||
|
EXPECT_EQ(e->source.range.end.column, 5u);
|
||||||
|
|
||||||
|
ASSERT_TRUE(e->Is<ast::BinaryExpression>());
|
||||||
|
auto* rel = e->As<ast::BinaryExpression>();
|
||||||
|
EXPECT_EQ(ast::BinaryOp::kEqual, rel->op);
|
||||||
|
|
||||||
|
ASSERT_TRUE(rel->lhs->Is<ast::IdentifierExpression>());
|
||||||
|
auto* ident = rel->lhs->As<ast::IdentifierExpression>();
|
||||||
|
EXPECT_EQ(ident->symbol, p->builder().Symbols().Get("a"));
|
||||||
|
|
||||||
|
ASSERT_TRUE(rel->rhs->Is<ast::BoolLiteralExpression>());
|
||||||
|
ASSERT_TRUE(rel->rhs->As<ast::BoolLiteralExpression>()->value);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(ParserImplTest, RelationalExpression_Parses_NotEqual) {
|
||||||
|
auto p = parser("a != true");
|
||||||
|
auto e = p->maybe_relational_expression();
|
||||||
|
EXPECT_TRUE(e.matched);
|
||||||
|
EXPECT_FALSE(e.errored);
|
||||||
|
EXPECT_FALSE(p->has_error()) << p->error();
|
||||||
|
ASSERT_NE(e.value, nullptr);
|
||||||
|
|
||||||
|
EXPECT_EQ(e->source.range.begin.line, 1u);
|
||||||
|
EXPECT_EQ(e->source.range.begin.column, 3u);
|
||||||
|
EXPECT_EQ(e->source.range.end.line, 1u);
|
||||||
|
EXPECT_EQ(e->source.range.end.column, 5u);
|
||||||
|
|
||||||
|
ASSERT_TRUE(e->Is<ast::BinaryExpression>());
|
||||||
|
auto* rel = e->As<ast::BinaryExpression>();
|
||||||
|
EXPECT_EQ(ast::BinaryOp::kNotEqual, rel->op);
|
||||||
|
|
||||||
|
ASSERT_TRUE(rel->lhs->Is<ast::IdentifierExpression>());
|
||||||
|
auto* ident = rel->lhs->As<ast::IdentifierExpression>();
|
||||||
|
EXPECT_EQ(ident->symbol, p->builder().Symbols().Get("a"));
|
||||||
|
|
||||||
|
ASSERT_TRUE(rel->rhs->Is<ast::BoolLiteralExpression>());
|
||||||
|
ASSERT_TRUE(rel->rhs->As<ast::BoolLiteralExpression>()->value);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(ParserImplTest, RelationalExpression_Equal_InvalidRHS) {
|
||||||
|
auto p = parser("true == if (a) {}");
|
||||||
|
auto e = p->maybe_relational_expression();
|
||||||
|
EXPECT_FALSE(e.matched);
|
||||||
|
EXPECT_TRUE(e.errored);
|
||||||
|
EXPECT_EQ(e.value, nullptr);
|
||||||
|
EXPECT_TRUE(p->has_error());
|
||||||
|
EXPECT_EQ(p->error(), "1:9: unable to parse right side of == expression");
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
} // namespace tint::reader::wgsl
|
} // namespace tint::reader::wgsl
|
||||||
|
|
|
@ -17,103 +17,6 @@
|
||||||
namespace tint::reader::wgsl {
|
namespace tint::reader::wgsl {
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
TEST_F(ParserImplTest, ShiftExpression_Orig_Parses_ShiftLeft) {
|
|
||||||
auto p = parser("a << true");
|
|
||||||
auto e = p->shift_expression();
|
|
||||||
EXPECT_TRUE(e.matched);
|
|
||||||
EXPECT_FALSE(e.errored);
|
|
||||||
EXPECT_FALSE(p->has_error()) << p->error();
|
|
||||||
ASSERT_NE(e.value, nullptr);
|
|
||||||
|
|
||||||
EXPECT_EQ(e->source.range.begin.line, 1u);
|
|
||||||
EXPECT_EQ(e->source.range.begin.column, 3u);
|
|
||||||
EXPECT_EQ(e->source.range.end.line, 1u);
|
|
||||||
EXPECT_EQ(e->source.range.end.column, 5u);
|
|
||||||
|
|
||||||
ASSERT_TRUE(e->Is<ast::BinaryExpression>());
|
|
||||||
auto* rel = e->As<ast::BinaryExpression>();
|
|
||||||
EXPECT_EQ(ast::BinaryOp::kShiftLeft, rel->op);
|
|
||||||
|
|
||||||
ASSERT_TRUE(rel->lhs->Is<ast::IdentifierExpression>());
|
|
||||||
auto* ident = rel->lhs->As<ast::IdentifierExpression>();
|
|
||||||
EXPECT_EQ(ident->symbol, p->builder().Symbols().Get("a"));
|
|
||||||
|
|
||||||
ASSERT_TRUE(rel->rhs->Is<ast::BoolLiteralExpression>());
|
|
||||||
ASSERT_TRUE(rel->rhs->As<ast::BoolLiteralExpression>()->value);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(ParserImplTest, ShiftExpression_Orig_Parses_ShiftRight) {
|
|
||||||
auto p = parser("a >> true");
|
|
||||||
auto e = p->shift_expression();
|
|
||||||
EXPECT_TRUE(e.matched);
|
|
||||||
EXPECT_FALSE(e.errored);
|
|
||||||
EXPECT_FALSE(p->has_error()) << p->error();
|
|
||||||
ASSERT_NE(e.value, nullptr);
|
|
||||||
|
|
||||||
EXPECT_EQ(e->source.range.begin.line, 1u);
|
|
||||||
EXPECT_EQ(e->source.range.begin.column, 3u);
|
|
||||||
EXPECT_EQ(e->source.range.end.line, 1u);
|
|
||||||
EXPECT_EQ(e->source.range.end.column, 5u);
|
|
||||||
|
|
||||||
ASSERT_TRUE(e->Is<ast::BinaryExpression>());
|
|
||||||
auto* rel = e->As<ast::BinaryExpression>();
|
|
||||||
EXPECT_EQ(ast::BinaryOp::kShiftRight, rel->op);
|
|
||||||
|
|
||||||
ASSERT_TRUE(rel->lhs->Is<ast::IdentifierExpression>());
|
|
||||||
auto* ident = rel->lhs->As<ast::IdentifierExpression>();
|
|
||||||
EXPECT_EQ(ident->symbol, p->builder().Symbols().Get("a"));
|
|
||||||
|
|
||||||
ASSERT_TRUE(rel->rhs->Is<ast::BoolLiteralExpression>());
|
|
||||||
ASSERT_TRUE(rel->rhs->As<ast::BoolLiteralExpression>()->value);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(ParserImplTest, ShiftExpression_Orig_InvalidSpaceLeft) {
|
|
||||||
auto p = parser("a < < true");
|
|
||||||
auto e = p->shift_expression();
|
|
||||||
EXPECT_TRUE(e.matched);
|
|
||||||
EXPECT_FALSE(e.errored);
|
|
||||||
ASSERT_NE(e.value, nullptr);
|
|
||||||
EXPECT_FALSE(e.value->Is<ast::BinaryExpression>());
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(ParserImplTest, ShiftExpression_Orig_InvalidSpaceRight) {
|
|
||||||
auto p = parser("a > > true");
|
|
||||||
auto e = p->shift_expression();
|
|
||||||
EXPECT_TRUE(e.matched);
|
|
||||||
EXPECT_FALSE(e.errored);
|
|
||||||
ASSERT_NE(e.value, nullptr);
|
|
||||||
EXPECT_FALSE(e.value->Is<ast::BinaryExpression>());
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(ParserImplTest, ShiftExpression_Orig_InvalidLHS) {
|
|
||||||
auto p = parser("if (a) {} << true");
|
|
||||||
auto e = p->shift_expression();
|
|
||||||
EXPECT_FALSE(e.matched);
|
|
||||||
EXPECT_FALSE(e.errored);
|
|
||||||
EXPECT_FALSE(p->has_error()) << p->error();
|
|
||||||
EXPECT_EQ(e.value, nullptr);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(ParserImplTest, ShiftExpression_Orig_InvalidRHS) {
|
|
||||||
auto p = parser("true << if (a) {}");
|
|
||||||
auto e = p->shift_expression();
|
|
||||||
EXPECT_FALSE(e.matched);
|
|
||||||
EXPECT_TRUE(e.errored);
|
|
||||||
EXPECT_TRUE(p->has_error());
|
|
||||||
EXPECT_EQ(e.value, nullptr);
|
|
||||||
EXPECT_EQ(p->error(), "1:9: unable to parse right side of << expression");
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(ParserImplTest, ShiftExpression_Orig_NoOr_ReturnsLHS) {
|
|
||||||
auto p = parser("a true");
|
|
||||||
auto e = p->shift_expression();
|
|
||||||
EXPECT_TRUE(e.matched);
|
|
||||||
EXPECT_FALSE(e.errored);
|
|
||||||
EXPECT_FALSE(p->has_error()) << p->error();
|
|
||||||
ASSERT_NE(e.value, nullptr);
|
|
||||||
ASSERT_TRUE(e->Is<ast::IdentifierExpression>());
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(ParserImplTest, ShiftExpression_PostUnary_Parses_ShiftLeft) {
|
TEST_F(ParserImplTest, ShiftExpression_PostUnary_Parses_ShiftLeft) {
|
||||||
auto p = parser("a << true");
|
auto p = parser("a << true");
|
||||||
auto lhs = p->unary_expression();
|
auto lhs = p->unary_expression();
|
||||||
|
@ -231,7 +134,7 @@ TEST_F(ParserImplTest, ShiftExpression_PostUnary_InvalidRHS) {
|
||||||
EXPECT_TRUE(e.errored);
|
EXPECT_TRUE(e.errored);
|
||||||
EXPECT_TRUE(p->has_error());
|
EXPECT_TRUE(p->has_error());
|
||||||
EXPECT_EQ(e.value, nullptr);
|
EXPECT_EQ(e.value, nullptr);
|
||||||
EXPECT_EQ(p->error(), "1:3: unable to parse right side of << expression");
|
EXPECT_EQ(p->error(), "1:6: unable to parse right side of << expression");
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(ParserImplTest, ShiftExpression_PostUnary_NoOr_ReturnsLHS) {
|
TEST_F(ParserImplTest, ShiftExpression_PostUnary_NoOr_ReturnsLHS) {
|
||||||
|
|
|
@ -86,7 +86,7 @@ TEST_F(ParserImplTest, UnaryExpression_Dereference) {
|
||||||
|
|
||||||
TEST_F(ParserImplTest, UnaryExpression_AddressOf_Precedence) {
|
TEST_F(ParserImplTest, UnaryExpression_AddressOf_Precedence) {
|
||||||
auto p = parser("&x.y");
|
auto p = parser("&x.y");
|
||||||
auto e = p->logical_or_expression();
|
auto e = p->unary_expression();
|
||||||
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();
|
||||||
|
@ -100,7 +100,7 @@ TEST_F(ParserImplTest, UnaryExpression_AddressOf_Precedence) {
|
||||||
|
|
||||||
TEST_F(ParserImplTest, UnaryExpression_Dereference_Precedence) {
|
TEST_F(ParserImplTest, UnaryExpression_Dereference_Precedence) {
|
||||||
auto p = parser("*x.y");
|
auto p = parser("*x.y");
|
||||||
auto e = p->logical_or_expression();
|
auto e = p->unary_expression();
|
||||||
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();
|
||||||
|
|
Loading…
Reference in New Issue