From 4248a46bfb0d6edcb05c3a934fd024fa862db9a0 Mon Sep 17 00:00:00 2001 From: James Price Date: Thu, 29 Apr 2021 15:54:44 +0000 Subject: [PATCH] reader/wgsl: Set source locations for literals Change-Id: I34c6fd6760fb948682d427648cae963b9c1d8a6d Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/49442 Commit-Queue: James Price Auto-Submit: James Price Reviewed-by: Ben Clayton --- src/reader/wgsl/parser_impl.cc | 10 +++++----- src/reader/wgsl/parser_impl_const_literal_test.cc | 5 +++++ 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/reader/wgsl/parser_impl.cc b/src/reader/wgsl/parser_impl.cc index 874e05b4f2..6f75fde05f 100644 --- a/src/reader/wgsl/parser_impl.cc +++ b/src/reader/wgsl/parser_impl.cc @@ -2815,16 +2815,16 @@ Maybe ParserImpl::assignment_stmt() { Maybe ParserImpl::const_literal() { auto t = peek(); if (match(Token::Type::kTrue)) { - return create(Source{}, true); + return create(t.source(), true); } if (match(Token::Type::kFalse)) { - return create(Source{}, false); + return create(t.source(), false); } if (match(Token::Type::kSintLiteral)) { - return create(Source{}, t.to_i32()); + return create(t.source(), t.to_i32()); } if (match(Token::Type::kUintLiteral)) { - return create(Source{}, t.to_u32()); + return create(t.source(), t.to_u32()); } if (match(Token::Type::kFloatLiteral)) { auto p = peek(); @@ -2832,7 +2832,7 @@ Maybe ParserImpl::const_literal() { next(); // Consume 'f' add_error(p.source(), "float literals must not be suffixed with 'f'"); } - return create(Source{}, t.to_f32()); + return create(t.source(), t.to_f32()); } return Failure::kNoMatch; } diff --git a/src/reader/wgsl/parser_impl_const_literal_test.cc b/src/reader/wgsl/parser_impl_const_literal_test.cc index da619252fb..d73abaa25e 100644 --- a/src/reader/wgsl/parser_impl_const_literal_test.cc +++ b/src/reader/wgsl/parser_impl_const_literal_test.cc @@ -28,6 +28,7 @@ TEST_F(ParserImplTest, ConstLiteral_Int) { ASSERT_NE(c.value, nullptr); ASSERT_TRUE(c->Is()); EXPECT_EQ(c->As()->value(), -234); + EXPECT_EQ(c->source().range, (Source::Range{{1u, 1u}, {1u, 5u}})); } TEST_F(ParserImplTest, ConstLiteral_Uint) { @@ -39,6 +40,7 @@ TEST_F(ParserImplTest, ConstLiteral_Uint) { ASSERT_NE(c.value, nullptr); ASSERT_TRUE(c->Is()); EXPECT_EQ(c->As()->value(), 234u); + EXPECT_EQ(c->source().range, (Source::Range{{1u, 1u}, {1u, 5u}})); } TEST_F(ParserImplTest, ConstLiteral_Float) { @@ -50,6 +52,7 @@ TEST_F(ParserImplTest, ConstLiteral_Float) { ASSERT_NE(c.value, nullptr); ASSERT_TRUE(c->Is()); EXPECT_FLOAT_EQ(c->As()->value(), 234e12f); + EXPECT_EQ(c->source().range, (Source::Range{{1u, 1u}, {1u, 8u}})); } TEST_F(ParserImplTest, ConstLiteral_InvalidFloat) { @@ -69,6 +72,7 @@ TEST_F(ParserImplTest, ConstLiteral_True) { ASSERT_NE(c.value, nullptr); ASSERT_TRUE(c->Is()); EXPECT_TRUE(c->As()->IsTrue()); + EXPECT_EQ(c->source().range, (Source::Range{{1u, 1u}, {1u, 5u}})); } TEST_F(ParserImplTest, ConstLiteral_False) { @@ -80,6 +84,7 @@ TEST_F(ParserImplTest, ConstLiteral_False) { ASSERT_NE(c.value, nullptr); ASSERT_TRUE(c->Is()); EXPECT_TRUE(c->As()->IsFalse()); + EXPECT_EQ(c->source().range, (Source::Range{{1u, 1u}, {1u, 6u}})); } TEST_F(ParserImplTest, ConstLiteral_NoMatch) {