tint: Rename float / int literal tokens

Rename:
• kFloatFLiteral -> kFloatLiteral_F
• kIntILiteral   -> kIntLiteral_I
• kIntULiteral   -> kIntLiteral_U

As suggested in review:
https://dawn-review.googlesource.com/c/dawn/+/89031/comments/b37253a3_e830b482

Bug: tint:1504
Change-Id: I4120f2904d8614152d4c804c226c9710f2ef8653
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/89661
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: Dan Sinclair <dsinclair@chromium.org>
Kokoro: Kokoro <noreply+kokoro@google.com>
This commit is contained in:
Ben Clayton 2022-05-10 22:26:04 +00:00 committed by Dawn LUCI CQ
parent 508e4a5a82
commit 824e824709
6 changed files with 38 additions and 38 deletions

View File

@ -406,7 +406,7 @@ Token Lexer::try_float() {
case LimitCheck::kTooLarge:
return {Token::Type::kError, source, "value too large for f32"};
default:
return {Token::Type::kFloatFLiteral, source, value};
return {Token::Type::kFloatLiteral_F, source, value};
}
}
@ -715,7 +715,7 @@ Token Lexer::try_hex_float() {
float result_f32;
std::memcpy(&result_f32, &result_u32, sizeof(result_f32));
double result_f64 = static_cast<double>(result_f32);
return {has_f_suffix ? Token::Type::kFloatFLiteral : Token::Type::kFloatLiteral, source,
return {has_f_suffix ? Token::Type::kFloatLiteral_F : Token::Type::kFloatLiteral, source,
result_f64};
}
@ -731,7 +731,7 @@ Token Lexer::build_token_from_int_if_possible(Source source, size_t start, int32
default:
advance(1);
end_source(source);
return {Token::Type::kIntULiteral, source, res};
return {Token::Type::kIntLiteral_U, source, res};
}
}
@ -746,7 +746,7 @@ Token Lexer::build_token_from_int_if_possible(Source source, size_t start, int32
}
advance(1);
end_source(source);
return {Token::Type::kIntILiteral, source, res};
return {Token::Type::kIntLiteral_I, source, res};
}
// TODO(crbug.com/tint/1504): Properly support abstract int:

View File

@ -317,7 +317,7 @@ TEST_P(FloatTest, Parse) {
auto t = l.next();
if (std::string(params.input).back() == 'f') {
EXPECT_TRUE(t.Is(Token::Type::kFloatFLiteral));
EXPECT_TRUE(t.Is(Token::Type::kFloatLiteral_F));
} else {
EXPECT_TRUE(t.Is(Token::Type::kFloatLiteral));
}
@ -611,7 +611,7 @@ TEST_P(IntegerTest_HexSigned, ISuffix) {
Lexer l(&file);
auto t = l.next();
EXPECT_TRUE(t.Is(Token::Type::kIntILiteral));
EXPECT_TRUE(t.Is(Token::Type::kIntLiteral_I));
EXPECT_EQ(t.source().range.begin.line, 1u);
EXPECT_EQ(t.source().range.begin.column, 1u);
EXPECT_EQ(t.source().range.end.line, 1u);
@ -727,7 +727,7 @@ TEST_P(IntegerTest_HexUnsigned, Matches) {
Lexer l(&file);
auto t = l.next();
EXPECT_TRUE(t.Is(Token::Type::kIntULiteral));
EXPECT_TRUE(t.Is(Token::Type::kIntLiteral_U));
EXPECT_EQ(t.source().range.begin.line, 1u);
EXPECT_EQ(t.source().range.begin.column, 1u);
EXPECT_EQ(t.source().range.end.line, 1u);
@ -770,7 +770,7 @@ TEST_P(IntegerTest_Unsigned, Matches) {
Lexer l(&file);
auto t = l.next();
EXPECT_TRUE(t.Is(Token::Type::kIntULiteral));
EXPECT_TRUE(t.Is(Token::Type::kIntLiteral_U));
EXPECT_EQ(t.to_i64(), params.result);
EXPECT_EQ(t.source().range.begin.line, 1u);
EXPECT_EQ(t.source().range.begin.column, 1u);
@ -839,8 +839,8 @@ TEST_P(IntegerTest_Invalid, Parses) {
auto t = l.next();
EXPECT_FALSE(t.Is(Token::Type::kIntLiteral));
EXPECT_FALSE(t.Is(Token::Type::kIntULiteral));
EXPECT_FALSE(t.Is(Token::Type::kIntILiteral));
EXPECT_FALSE(t.Is(Token::Type::kIntLiteral_U));
EXPECT_FALSE(t.Is(Token::Type::kIntLiteral_I));
}
INSTANTIATE_TEST_SUITE_P(
LexerTest,

View File

@ -2781,11 +2781,11 @@ Maybe<const ast::LiteralExpression*> ParserImpl::const_literal() {
return create<ast::IntLiteralExpression>(t.source(), t.to_i64(),
ast::IntLiteralExpression::Suffix::kNone);
}
if (match(Token::Type::kIntILiteral)) {
if (match(Token::Type::kIntLiteral_I)) {
return create<ast::IntLiteralExpression>(t.source(), t.to_i64(),
ast::IntLiteralExpression::Suffix::kI);
}
if (match(Token::Type::kIntULiteral)) {
if (match(Token::Type::kIntLiteral_U)) {
return create<ast::IntLiteralExpression>(t.source(), t.to_i64(),
ast::IntLiteralExpression::Suffix::kU);
}
@ -2793,7 +2793,7 @@ Maybe<const ast::LiteralExpression*> ParserImpl::const_literal() {
return create<ast::FloatLiteralExpression>(t.source(), t.to_f64(),
ast::FloatLiteralExpression::Suffix::kNone);
}
if (match(Token::Type::kFloatFLiteral)) {
if (match(Token::Type::kFloatLiteral_F)) {
return create<ast::FloatLiteralExpression>(t.source(), t.to_f64(),
ast::FloatLiteralExpression::Suffix::kF);
}
@ -3131,7 +3131,7 @@ bool ParserImpl::expect(std::string_view use, Token::Type tok) {
Expect<int32_t> ParserImpl::expect_sint(std::string_view use) {
auto t = peek();
if (!t.Is(Token::Type::kIntLiteral) && !t.Is(Token::Type::kIntILiteral)) {
if (!t.Is(Token::Type::kIntLiteral) && !t.Is(Token::Type::kIntLiteral_I)) {
return add_error(t.source(), "expected signed integer literal", use);
}

View File

@ -27,13 +27,13 @@ std::string_view Token::TypeToName(Type type) {
return "identifier";
case Token::Type::kFloatLiteral:
return "abstract float literal";
case Token::Type::kFloatFLiteral:
case Token::Type::kFloatLiteral_F:
return "'f'-suffixed float literal";
case Token::Type::kIntLiteral:
return "abstract integer literal";
case Token::Type::kIntILiteral:
case Token::Type::kIntLiteral_I:
return "'i'-suffixed integer literal";
case Token::Type::kIntULiteral:
case Token::Type::kIntLiteral_U:
return "'u'-suffixed integer literal";
case Token::Type::kUninitialized:
return "uninitialized";
@ -307,13 +307,13 @@ std::string Token::to_str() const {
switch (type_) {
case Type::kFloatLiteral:
return std::to_string(std::get<double>(value_));
case Type::kFloatFLiteral:
case Type::kFloatLiteral_F:
return std::to_string(std::get<double>(value_)) + "f";
case Type::kIntLiteral:
return std::to_string(std::get<int64_t>(value_));
case Type::kIntILiteral:
case Type::kIntLiteral_I:
return std::to_string(std::get<int64_t>(value_)) + "i";
case Type::kIntULiteral:
case Type::kIntLiteral_U:
return std::to_string(std::get<int64_t>(value_)) + "u";
case Type::kIdentifier:
case Type::kError:

View File

@ -41,13 +41,13 @@ class Token {
/// A float literal with no suffix
kFloatLiteral,
/// A float literal with an 'f' suffix
kFloatFLiteral,
kFloatLiteral_F,
/// An integer literal with no suffix
kIntLiteral,
/// An integer literal with an 'i' suffix
kIntILiteral,
kIntLiteral_I,
/// An integer literal with a 'u' suffix
kIntULiteral,
kIntLiteral_U,
/// A '&'
kAnd,
@ -342,9 +342,9 @@ class Token {
bool IsIdentifier() const { return type_ == Type::kIdentifier; }
/// @returns true if the token is a literal
bool IsLiteral() const {
return type_ == Type::kIntLiteral || type_ == Type::kIntILiteral ||
type_ == Type::kIntULiteral || type_ == Type::kFalse || type_ == Type::kTrue ||
type_ == Type::kFloatLiteral || type_ == Type::kFloatFLiteral;
return type_ == Type::kIntLiteral || type_ == Type::kIntLiteral_I ||
type_ == Type::kIntLiteral_U || type_ == Type::kFalse || type_ == Type::kTrue ||
type_ == Type::kFloatLiteral || type_ == Type::kFloatLiteral_F;
}
/// @returns true if token is a 'matNxM'
bool IsMatrix() const {

View File

@ -28,40 +28,40 @@ using ::testing::StartsWith;
using TokenTest = testing::Test;
TEST_F(TokenTest, ReturnsF64) {
Token t1(Token::Type::kFloatFLiteral, Source{}, -2.345);
Token t1(Token::Type::kFloatLiteral_F, Source{}, -2.345);
EXPECT_EQ(t1.to_f64(), -2.345);
Token t2(Token::Type::kFloatFLiteral, Source{}, 2.345);
Token t2(Token::Type::kFloatLiteral_F, Source{}, 2.345);
EXPECT_EQ(t2.to_f64(), 2.345);
}
TEST_F(TokenTest, ReturnsI32) {
Token t1(Token::Type::kIntILiteral, Source{}, static_cast<int64_t>(-2345));
Token t1(Token::Type::kIntLiteral_I, Source{}, static_cast<int64_t>(-2345));
EXPECT_EQ(t1.to_i64(), -2345);
Token t2(Token::Type::kIntILiteral, Source{}, static_cast<int64_t>(2345));
Token t2(Token::Type::kIntLiteral_I, Source{}, static_cast<int64_t>(2345));
EXPECT_EQ(t2.to_i64(), 2345);
}
TEST_F(TokenTest, HandlesMaxI32) {
Token t1(Token::Type::kIntILiteral, Source{},
Token t1(Token::Type::kIntLiteral_I, Source{},
static_cast<int64_t>(std::numeric_limits<int32_t>::max()));
EXPECT_EQ(t1.to_i64(), std::numeric_limits<int32_t>::max());
}
TEST_F(TokenTest, HandlesMinI32) {
Token t1(Token::Type::kIntILiteral, Source{},
Token t1(Token::Type::kIntLiteral_I, Source{},
static_cast<int64_t>(std::numeric_limits<int32_t>::min()));
EXPECT_EQ(t1.to_i64(), std::numeric_limits<int32_t>::min());
}
TEST_F(TokenTest, ReturnsU32) {
Token t2(Token::Type::kIntULiteral, Source{}, static_cast<int64_t>(2345u));
Token t2(Token::Type::kIntLiteral_U, Source{}, static_cast<int64_t>(2345u));
EXPECT_EQ(t2.to_i64(), 2345u);
}
TEST_F(TokenTest, ReturnsMaxU32) {
Token t1(Token::Type::kIntULiteral, Source{},
Token t1(Token::Type::kIntLiteral_U, Source{},
static_cast<int64_t>(std::numeric_limits<uint32_t>::max()));
EXPECT_EQ(t1.to_i64(), std::numeric_limits<uint32_t>::max());
}
@ -83,11 +83,11 @@ TEST_F(TokenTest, ToStr) {
int64_t i = 123;
EXPECT_THAT(Token(Token::Type::kFloatLiteral, Source{}, d).to_str(), StartsWith("123"));
EXPECT_THAT(Token(Token::Type::kFloatLiteral, Source{}, d).to_str(), Not(EndsWith("f")));
EXPECT_THAT(Token(Token::Type::kFloatFLiteral, Source{}, d).to_str(), StartsWith("123"));
EXPECT_THAT(Token(Token::Type::kFloatFLiteral, Source{}, d).to_str(), EndsWith("f"));
EXPECT_THAT(Token(Token::Type::kFloatLiteral_F, Source{}, d).to_str(), StartsWith("123"));
EXPECT_THAT(Token(Token::Type::kFloatLiteral_F, Source{}, d).to_str(), EndsWith("f"));
EXPECT_EQ(Token(Token::Type::kIntLiteral, Source{}, i).to_str(), "123");
EXPECT_EQ(Token(Token::Type::kIntILiteral, Source{}, i).to_str(), "123i");
EXPECT_EQ(Token(Token::Type::kIntULiteral, Source{}, i).to_str(), "123u");
EXPECT_EQ(Token(Token::Type::kIntLiteral_I, Source{}, i).to_str(), "123i");
EXPECT_EQ(Token(Token::Type::kIntLiteral_U, Source{}, i).to_str(), "123u");
EXPECT_EQ(Token(Token::Type::kIdentifier, Source{}, "blah").to_str(), "blah");
EXPECT_EQ(Token(Token::Type::kError, Source{}, "blah").to_str(), "blah");
}