tint/parser: Use = for source of assignment

Change-Id: I09ebd529fad775d0ce74fc56e2d7ff161a33f15a
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/118380
Reviewed-by: Ben Clayton <bclayton@google.com>
Commit-Queue: James Price <jrprice@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
This commit is contained in:
James Price 2023-02-02 15:05:21 +00:00 committed by Dawn LUCI CQ
parent c87b1fe8c9
commit 6e31bc24b1
2 changed files with 27 additions and 4 deletions

View File

@ -3364,6 +3364,7 @@ Maybe<const ast::Statement*> ParserImpl::variable_updating_statement() {
return add_error(peek(0).source(), "expected 'var' for variable declaration");
}
Source source;
const ast::Expression* lhs = nullptr;
ast::BinaryOp compound_op = ast::BinaryOp::kNone;
if (peek_is(Token::Type::kUnderscore)) {
@ -3372,6 +3373,7 @@ Maybe<const ast::Statement*> ParserImpl::variable_updating_statement() {
if (!expect("assignment", Token::Type::kEqual)) {
return Failure::kErrored;
}
source = last_source();
lhs = create<ast::PhonyExpression>(t.source());
@ -3388,12 +3390,13 @@ Maybe<const ast::Statement*> ParserImpl::variable_updating_statement() {
// Handle increment and decrement statements.
if (match(Token::Type::kPlusPlus)) {
return create<ast::IncrementDecrementStatement>(t.source(), lhs, true);
return create<ast::IncrementDecrementStatement>(last_source(), lhs, true);
}
if (match(Token::Type::kMinusMinus)) {
return create<ast::IncrementDecrementStatement>(t.source(), lhs, false);
return create<ast::IncrementDecrementStatement>(last_source(), lhs, false);
}
source = peek().source();
auto compound_op_result = compound_assignment_operator();
if (compound_op_result.errored) {
return Failure::kErrored;
@ -3416,9 +3419,9 @@ Maybe<const ast::Statement*> ParserImpl::variable_updating_statement() {
}
if (compound_op != ast::BinaryOp::kNone) {
return create<ast::CompoundAssignmentStatement>(t.source(), lhs, rhs.value, compound_op);
return create<ast::CompoundAssignmentStatement>(source, lhs, rhs.value, compound_op);
}
return create<ast::AssignmentStatement>(t.source(), lhs, rhs.value);
return create<ast::AssignmentStatement>(source, lhs, rhs.value);
}
// const_literal

View File

@ -30,6 +30,11 @@ TEST_F(ParserImplTest, AssignmentStmt_Parses_ToVariable) {
ASSERT_NE(a->lhs, nullptr);
ASSERT_NE(a->rhs, nullptr);
EXPECT_EQ(a->source.range.begin.line, 1u);
EXPECT_EQ(a->source.range.begin.column, 3u);
EXPECT_EQ(a->source.range.end.line, 1u);
EXPECT_EQ(a->source.range.end.column, 4u);
ASSERT_TRUE(a->lhs->Is<ast::IdentifierExpression>());
auto* ident = a->lhs->As<ast::IdentifierExpression>();
EXPECT_EQ(ident->symbol, p->builder().Symbols().Get("a"));
@ -53,6 +58,11 @@ TEST_F(ParserImplTest, AssignmentStmt_Parses_ToMember) {
ASSERT_NE(a->lhs, nullptr);
ASSERT_NE(a->rhs, nullptr);
EXPECT_EQ(a->source.range.begin.line, 1u);
EXPECT_EQ(a->source.range.begin.column, 12u);
EXPECT_EQ(a->source.range.end.line, 1u);
EXPECT_EQ(a->source.range.end.column, 13u);
ASSERT_TRUE(a->rhs->Is<ast::IntLiteralExpression>());
EXPECT_EQ(a->rhs->As<ast::IntLiteralExpression>()->value, 123);
EXPECT_EQ(a->rhs->As<ast::IntLiteralExpression>()->suffix,
@ -103,6 +113,11 @@ TEST_F(ParserImplTest, AssignmentStmt_Parses_ToPhony) {
ASSERT_NE(a->lhs, nullptr);
ASSERT_NE(a->rhs, nullptr);
EXPECT_EQ(a->source.range.begin.line, 1u);
EXPECT_EQ(a->source.range.begin.column, 3u);
EXPECT_EQ(a->source.range.end.line, 1u);
EXPECT_EQ(a->source.range.end.column, 4u);
ASSERT_TRUE(a->rhs->Is<ast::IntLiteralExpression>());
EXPECT_EQ(a->rhs->As<ast::IntLiteralExpression>()->value, 123);
EXPECT_EQ(a->rhs->As<ast::IntLiteralExpression>()->suffix,
@ -163,6 +178,11 @@ TEST_P(CompoundOpTest, CompoundOp) {
ASSERT_NE(a->rhs, nullptr);
EXPECT_EQ(a->op, params.op);
EXPECT_EQ(a->source.range.begin.line, 1u);
EXPECT_EQ(a->source.range.begin.column, 3u);
EXPECT_EQ(a->source.range.end.line, 1u);
EXPECT_EQ(a->source.range.end.column, 3u + params.str.length());
ASSERT_TRUE(a->lhs->Is<ast::IdentifierExpression>());
auto* ident = a->lhs->As<ast::IdentifierExpression>();
EXPECT_EQ(ident->symbol, p->builder().Symbols().Get("a"));