tint: Add missing source information for | and ||

Add tests for the source information for all binary expressions.

Change-Id: I163cddf60eab4b7af8a1bafb899a1d5bfff6fe0c
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/89802
Reviewed-by: Ben Clayton <bclayton@google.com>
Reviewed-by: Dan Sinclair <dsinclair@chromium.org>
This commit is contained in:
James Price 2022-05-12 11:43:37 +00:00
parent 816148fe32
commit 53547db1d4
11 changed files with 77 additions and 2 deletions

View File

@ -2577,7 +2577,7 @@ Maybe<const ast::Expression*> ParserImpl::exclusive_or_expression() {
Expect<const ast::Expression*> ParserImpl::expect_inclusive_or_expr(const ast::Expression* lhs) {
while (continue_parsing()) {
Source source;
if (!match(Token::Type::kOr))
if (!match(Token::Type::kOr, &source))
return lhs;
auto rhs = exclusive_or_expression();
@ -2644,7 +2644,7 @@ Maybe<const ast::Expression*> ParserImpl::logical_and_expression() {
Expect<const ast::Expression*> ParserImpl::expect_logical_or_expr(const ast::Expression* lhs) {
while (continue_parsing()) {
Source source;
if (!match(Token::Type::kOrOr))
if (!match(Token::Type::kOrOr, &source))
return lhs;
auto rhs = logical_and_expression();

View File

@ -25,6 +25,11 @@ TEST_F(ParserImplTest, AdditiveExpression_Parses_Plus) {
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);

View File

@ -25,6 +25,11 @@ TEST_F(ParserImplTest, AndExpression_Parses) {
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);

View File

@ -25,6 +25,11 @@ TEST_F(ParserImplTest, EqualityExpression_Parses_Equal) {
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);
@ -45,6 +50,11 @@ TEST_F(ParserImplTest, EqualityExpression_Parses_NotEqual) {
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);

View File

@ -25,6 +25,11 @@ TEST_F(ParserImplTest, ExclusiveOrExpression_Parses) {
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);

View File

@ -25,6 +25,11 @@ TEST_F(ParserImplTest, InclusiveOrExpression_Parses) {
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);

View File

@ -25,6 +25,11 @@ TEST_F(ParserImplTest, LogicalAndExpression_Parses) {
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);

View File

@ -25,6 +25,11 @@ TEST_F(ParserImplTest, LogicalOrExpression_Parses) {
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);

View File

@ -25,6 +25,11 @@ TEST_F(ParserImplTest, MultiplicativeExpression_Parses_Multiply) {
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);

View File

@ -25,6 +25,11 @@ TEST_F(ParserImplTest, RelationalExpression_Parses_LessThan) {
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);
@ -45,6 +50,11 @@ TEST_F(ParserImplTest, RelationalExpression_Parses_GreaterThan) {
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);
@ -65,6 +75,11 @@ TEST_F(ParserImplTest, RelationalExpression_Parses_LessThanEqual) {
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);
@ -85,6 +100,11 @@ TEST_F(ParserImplTest, RelationalExpression_Parses_GreaterThanEqual) {
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);

View File

@ -25,6 +25,11 @@ TEST_F(ParserImplTest, ShiftExpression_Parses_ShiftLeft) {
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);
@ -45,6 +50,11 @@ TEST_F(ParserImplTest, ShiftExpression_Parses_ShiftRight) {
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);