reader/wgsl: Set source locations for literals
Change-Id: I34c6fd6760fb948682d427648cae963b9c1d8a6d Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/49442 Commit-Queue: James Price <jrprice@google.com> Auto-Submit: James Price <jrprice@google.com> Reviewed-by: Ben Clayton <bclayton@google.com>
This commit is contained in:
parent
e80887d14c
commit
4248a46bfb
|
@ -2815,16 +2815,16 @@ Maybe<ast::AssignmentStatement*> ParserImpl::assignment_stmt() {
|
|||
Maybe<ast::Literal*> ParserImpl::const_literal() {
|
||||
auto t = peek();
|
||||
if (match(Token::Type::kTrue)) {
|
||||
return create<ast::BoolLiteral>(Source{}, true);
|
||||
return create<ast::BoolLiteral>(t.source(), true);
|
||||
}
|
||||
if (match(Token::Type::kFalse)) {
|
||||
return create<ast::BoolLiteral>(Source{}, false);
|
||||
return create<ast::BoolLiteral>(t.source(), false);
|
||||
}
|
||||
if (match(Token::Type::kSintLiteral)) {
|
||||
return create<ast::SintLiteral>(Source{}, t.to_i32());
|
||||
return create<ast::SintLiteral>(t.source(), t.to_i32());
|
||||
}
|
||||
if (match(Token::Type::kUintLiteral)) {
|
||||
return create<ast::UintLiteral>(Source{}, t.to_u32());
|
||||
return create<ast::UintLiteral>(t.source(), t.to_u32());
|
||||
}
|
||||
if (match(Token::Type::kFloatLiteral)) {
|
||||
auto p = peek();
|
||||
|
@ -2832,7 +2832,7 @@ Maybe<ast::Literal*> ParserImpl::const_literal() {
|
|||
next(); // Consume 'f'
|
||||
add_error(p.source(), "float literals must not be suffixed with 'f'");
|
||||
}
|
||||
return create<ast::FloatLiteral>(Source{}, t.to_f32());
|
||||
return create<ast::FloatLiteral>(t.source(), t.to_f32());
|
||||
}
|
||||
return Failure::kNoMatch;
|
||||
}
|
||||
|
|
|
@ -28,6 +28,7 @@ TEST_F(ParserImplTest, ConstLiteral_Int) {
|
|||
ASSERT_NE(c.value, nullptr);
|
||||
ASSERT_TRUE(c->Is<ast::SintLiteral>());
|
||||
EXPECT_EQ(c->As<ast::SintLiteral>()->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<ast::UintLiteral>());
|
||||
EXPECT_EQ(c->As<ast::UintLiteral>()->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<ast::FloatLiteral>());
|
||||
EXPECT_FLOAT_EQ(c->As<ast::FloatLiteral>()->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<ast::BoolLiteral>());
|
||||
EXPECT_TRUE(c->As<ast::BoolLiteral>()->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<ast::BoolLiteral>());
|
||||
EXPECT_TRUE(c->As<ast::BoolLiteral>()->IsFalse());
|
||||
EXPECT_EQ(c->source().range, (Source::Range{{1u, 1u}, {1u, 6u}}));
|
||||
}
|
||||
|
||||
TEST_F(ParserImplTest, ConstLiteral_NoMatch) {
|
||||
|
|
Loading…
Reference in New Issue