Rename the IntLiteral to SintLiteral.

This Cl clarifies that IntLiteral is a signed value, which matches with
the usage of UintLiteral.

Change-Id: Ic8f0e2382cb66eb6b09daed096886dcc55e6b0f0
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/22540
Reviewed-by: David Neto <dneto@google.com>
This commit is contained in:
dan sinclair
2020-06-02 20:11:44 +00:00
committed by dan sinclair
parent 1649dfadd7
commit c6f2947ceb
41 changed files with 262 additions and 261 deletions

View File

@@ -39,8 +39,8 @@
#include "src/ast/builtin_decoration.h"
#include "src/ast/decorated_variable.h"
#include "src/ast/float_literal.h"
#include "src/ast/int_literal.h"
#include "src/ast/scalar_constructor_expression.h"
#include "src/ast/sint_literal.h"
#include "src/ast/struct.h"
#include "src/ast/struct_decoration.h"
#include "src/ast/struct_member.h"
@@ -882,7 +882,7 @@ TypedExpression ParserImpl::MakeConstantExpression(uint32_t id) {
}
if (ast_type->IsI32()) {
return {ast_type, std::make_unique<ast::ScalarConstructorExpression>(
std::make_unique<ast::IntLiteral>(
std::make_unique<ast::SintLiteral>(
ast_type, spirv_const->GetS32()))};
}
if (ast_type->IsF32()) {
@@ -954,7 +954,7 @@ std::unique_ptr<ast::Expression> ParserImpl::MakeNullValue(
}
if (type->IsI32()) {
return std::make_unique<ast::ScalarConstructorExpression>(
std::make_unique<ast::IntLiteral>(type, 0));
std::make_unique<ast::SintLiteral>(type, 0));
}
if (type->IsF32()) {
return std::make_unique<ast::ScalarConstructorExpression>(

View File

@@ -201,7 +201,7 @@ TEST_P(IntegerTest_HexSigned, Matches) {
Lexer l(std::string(params.input));
auto t = l.next();
EXPECT_TRUE(t.IsIntLiteral());
EXPECT_TRUE(t.IsSintLiteral());
EXPECT_EQ(t.line(), 1u);
EXPECT_EQ(t.column(), 1u);
EXPECT_EQ(t.to_i32(), params.result);
@@ -308,7 +308,7 @@ TEST_P(IntegerTest_Signed, Matches) {
Lexer l(params.input);
auto t = l.next();
EXPECT_TRUE(t.IsIntLiteral());
EXPECT_TRUE(t.IsSintLiteral());
EXPECT_EQ(t.to_i32(), params.result);
EXPECT_EQ(1u, t.line());
EXPECT_EQ(1u, t.column());
@@ -328,7 +328,7 @@ TEST_P(IntegerTest_Invalid, Parses) {
Lexer l(GetParam());
auto t = l.next();
EXPECT_FALSE(t.IsIntLiteral());
EXPECT_FALSE(t.IsSintLiteral());
EXPECT_FALSE(t.IsUintLiteral());
}
INSTANTIATE_TEST_SUITE_P(LexerTest,

View File

@@ -34,13 +34,13 @@
#include "src/ast/float_literal.h"
#include "src/ast/identifier_expression.h"
#include "src/ast/if_statement.h"
#include "src/ast/int_literal.h"
#include "src/ast/kill_statement.h"
#include "src/ast/location_decoration.h"
#include "src/ast/member_accessor_expression.h"
#include "src/ast/return_statement.h"
#include "src/ast/scalar_constructor_expression.h"
#include "src/ast/set_decoration.h"
#include "src/ast/sint_literal.h"
#include "src/ast/statement_condition.h"
#include "src/ast/struct_member_offset_decoration.h"
#include "src/ast/switch_statement.h"
@@ -497,7 +497,7 @@ std::unique_ptr<ast::VariableDecoration> ParserImpl::variable_decoration() {
next(); // consume the peek
t = next();
if (!t.IsIntLiteral()) {
if (!t.IsSintLiteral()) {
set_error(t, "invalid value for location decoration");
return {};
}
@@ -525,7 +525,7 @@ std::unique_ptr<ast::VariableDecoration> ParserImpl::variable_decoration() {
next(); // consume the peek
t = next();
if (!t.IsIntLiteral()) {
if (!t.IsSintLiteral()) {
set_error(t, "invalid value for binding decoration");
return {};
}
@@ -536,7 +536,7 @@ std::unique_ptr<ast::VariableDecoration> ParserImpl::variable_decoration() {
next(); // consume the peek
t = next();
if (!t.IsIntLiteral()) {
if (!t.IsSintLiteral()) {
set_error(t, "invalid value for set decoration");
return {};
}
@@ -837,7 +837,7 @@ ast::type::Type* ParserImpl::type_decl_array(Token t) {
uint32_t size = 0;
if (t.IsComma()) {
t = next();
if (!t.IsIntLiteral()) {
if (!t.IsSintLiteral()) {
set_error(t, "missing size of array declaration");
return nullptr;
}
@@ -1143,7 +1143,7 @@ ParserImpl::struct_member_decoration() {
next(); // Consume the peek
t = next();
if (!t.IsIntLiteral()) {
if (!t.IsSintLiteral()) {
set_error(t, "invalid value for offset decoration");
return nullptr;
}
@@ -2741,13 +2741,13 @@ std::unique_ptr<ast::Literal> ParserImpl::const_literal() {
}
return std::make_unique<ast::BoolLiteral>(type, false);
}
if (t.IsIntLiteral()) {
if (t.IsSintLiteral()) {
next(); // Consume the peek
auto* type = ctx_.type_mgr().Get(std::make_unique<ast::type::I32Type>());
if (!type) {
return nullptr;
}
return std::make_unique<ast::IntLiteral>(type, t.to_i32());
return std::make_unique<ast::SintLiteral>(type, t.to_i32());
}
if (t.IsUintLiteral()) {
next(); // Consume the peek

View File

@@ -15,8 +15,8 @@
#include "gtest/gtest.h"
#include "src/ast/array_accessor_expression.h"
#include "src/ast/identifier_expression.h"
#include "src/ast/int_literal.h"
#include "src/ast/scalar_constructor_expression.h"
#include "src/ast/sint_literal.h"
#include "src/ast/unary_op_expression.h"
#include "src/reader/wgsl/parser_impl.h"
#include "src/reader/wgsl/parser_impl_test_helper.h"

View File

@@ -16,10 +16,10 @@
#include "src/ast/array_accessor_expression.h"
#include "src/ast/assignment_statement.h"
#include "src/ast/identifier_expression.h"
#include "src/ast/int_literal.h"
#include "src/ast/literal.h"
#include "src/ast/member_accessor_expression.h"
#include "src/ast/scalar_constructor_expression.h"
#include "src/ast/sint_literal.h"
#include "src/reader/wgsl/parser_impl.h"
#include "src/reader/wgsl/parser_impl_test_helper.h"
@@ -47,8 +47,8 @@ TEST_F(ParserImplTest, AssignmentStmt_Parses_ToVariable) {
auto* init = e->rhs()->AsConstructor()->AsScalarConstructor();
ASSERT_NE(init->literal(), nullptr);
ASSERT_TRUE(init->literal()->IsInt());
EXPECT_EQ(init->literal()->AsInt()->value(), 123);
ASSERT_TRUE(init->literal()->IsSint());
EXPECT_EQ(init->literal()->AsSint()->value(), 123);
}
TEST_F(ParserImplTest, AssignmentStmt_Parses_ToMember) {
@@ -65,8 +65,8 @@ TEST_F(ParserImplTest, AssignmentStmt_Parses_ToMember) {
ASSERT_TRUE(e->rhs()->AsConstructor()->IsScalarConstructor());
auto* init = e->rhs()->AsConstructor()->AsScalarConstructor();
ASSERT_NE(init->literal(), nullptr);
ASSERT_TRUE(init->literal()->IsInt());
EXPECT_EQ(init->literal()->AsInt()->value(), 123);
ASSERT_TRUE(init->literal()->IsSint());
EXPECT_EQ(init->literal()->AsSint()->value(), 123);
ASSERT_TRUE(e->lhs()->IsMemberAccessor());
auto* mem = e->lhs()->AsMemberAccessor();
@@ -82,8 +82,8 @@ TEST_F(ParserImplTest, AssignmentStmt_Parses_ToMember) {
ASSERT_TRUE(ary->idx_expr()->AsConstructor()->IsScalarConstructor());
init = ary->idx_expr()->AsConstructor()->AsScalarConstructor();
ASSERT_NE(init->literal(), nullptr);
ASSERT_TRUE(init->literal()->IsInt());
EXPECT_EQ(init->literal()->AsInt()->value(), 2);
ASSERT_TRUE(init->literal()->IsSint());
EXPECT_EQ(init->literal()->AsSint()->value(), 2);
ASSERT_TRUE(ary->array()->IsMemberAccessor());
mem = ary->array()->AsMemberAccessor();

View File

@@ -15,7 +15,7 @@
#include "gtest/gtest.h"
#include "src/ast/bool_literal.h"
#include "src/ast/float_literal.h"
#include "src/ast/int_literal.h"
#include "src/ast/sint_literal.h"
#include "src/ast/uint_literal.h"
#include "src/reader/wgsl/parser_impl.h"
#include "src/reader/wgsl/parser_impl_test_helper.h"
@@ -30,8 +30,8 @@ TEST_F(ParserImplTest, ConstLiteral_Int) {
auto c = p->const_literal();
ASSERT_FALSE(p->has_error());
ASSERT_NE(c, nullptr);
ASSERT_TRUE(c->IsInt());
EXPECT_EQ(c->AsInt()->value(), -234);
ASSERT_TRUE(c->IsSint());
EXPECT_EQ(c->AsSint()->value(), -234);
}
TEST_F(ParserImplTest, ConstLiteral_Uint) {

View File

@@ -16,9 +16,9 @@
#include "src/ast/array_accessor_expression.h"
#include "src/ast/call_expression.h"
#include "src/ast/identifier_expression.h"
#include "src/ast/int_literal.h"
#include "src/ast/member_accessor_expression.h"
#include "src/ast/scalar_constructor_expression.h"
#include "src/ast/sint_literal.h"
#include "src/ast/unary_op_expression.h"
#include "src/reader/wgsl/parser_impl.h"
#include "src/reader/wgsl/parser_impl_test_helper.h"
@@ -44,8 +44,8 @@ TEST_F(ParserImplTest, PostfixExpression_Array_ConstantIndex) {
ASSERT_TRUE(ary->idx_expr()->IsConstructor());
ASSERT_TRUE(ary->idx_expr()->AsConstructor()->IsScalarConstructor());
auto* c = ary->idx_expr()->AsConstructor()->AsScalarConstructor();
ASSERT_TRUE(c->literal()->IsInt());
EXPECT_EQ(c->literal()->AsInt()->value(), 1);
ASSERT_TRUE(c->literal()->IsSint());
EXPECT_EQ(c->literal()->AsSint()->value(), 1);
}
TEST_F(ParserImplTest, PostfixExpression_Array_ExpressionIndex) {

View File

@@ -18,8 +18,8 @@
#include "src/ast/bool_literal.h"
#include "src/ast/cast_expression.h"
#include "src/ast/identifier_expression.h"
#include "src/ast/int_literal.h"
#include "src/ast/scalar_constructor_expression.h"
#include "src/ast/sint_literal.h"
#include "src/ast/type/f32_type.h"
#include "src/ast/type/i32_type.h"
#include "src/ast/type_constructor_expression.h"
@@ -76,26 +76,26 @@ TEST_F(ParserImplTest, PrimaryExpression_TypeDecl) {
ASSERT_TRUE(val[0]->IsConstructor());
ASSERT_TRUE(val[0]->AsConstructor()->IsScalarConstructor());
auto* ident = val[0]->AsConstructor()->AsScalarConstructor();
ASSERT_TRUE(ident->literal()->IsInt());
EXPECT_EQ(ident->literal()->AsInt()->value(), 1);
ASSERT_TRUE(ident->literal()->IsSint());
EXPECT_EQ(ident->literal()->AsSint()->value(), 1);
ASSERT_TRUE(val[1]->IsConstructor());
ASSERT_TRUE(val[1]->AsConstructor()->IsScalarConstructor());
ident = val[1]->AsConstructor()->AsScalarConstructor();
ASSERT_TRUE(ident->literal()->IsInt());
EXPECT_EQ(ident->literal()->AsInt()->value(), 2);
ASSERT_TRUE(ident->literal()->IsSint());
EXPECT_EQ(ident->literal()->AsSint()->value(), 2);
ASSERT_TRUE(val[2]->IsConstructor());
ASSERT_TRUE(val[2]->AsConstructor()->IsScalarConstructor());
ident = val[2]->AsConstructor()->AsScalarConstructor();
ASSERT_TRUE(ident->literal()->IsInt());
EXPECT_EQ(ident->literal()->AsInt()->value(), 3);
ASSERT_TRUE(ident->literal()->IsSint());
EXPECT_EQ(ident->literal()->AsSint()->value(), 3);
ASSERT_TRUE(val[3]->IsConstructor());
ASSERT_TRUE(val[3]->AsConstructor()->IsScalarConstructor());
ident = val[3]->AsConstructor()->AsScalarConstructor();
ASSERT_TRUE(ident->literal()->IsInt());
EXPECT_EQ(ident->literal()->AsInt()->value(), 4);
ASSERT_TRUE(ident->literal()->IsSint());
EXPECT_EQ(ident->literal()->AsSint()->value(), 4);
}
TEST_F(ParserImplTest, PrimaryExpression_TypeDecl_InvalidTypeDecl) {

View File

@@ -15,8 +15,8 @@
#include "gtest/gtest.h"
#include "src/ast/array_accessor_expression.h"
#include "src/ast/identifier_expression.h"
#include "src/ast/int_literal.h"
#include "src/ast/scalar_constructor_expression.h"
#include "src/ast/sint_literal.h"
#include "src/ast/unary_op_expression.h"
#include "src/reader/wgsl/parser_impl.h"
#include "src/reader/wgsl/parser_impl_test_helper.h"
@@ -41,8 +41,8 @@ TEST_F(ParserImplTest, UnaryExpression_Postix) {
ASSERT_TRUE(ary->idx_expr()->IsConstructor());
ASSERT_TRUE(ary->idx_expr()->AsConstructor()->IsScalarConstructor());
auto* init = ary->idx_expr()->AsConstructor()->AsScalarConstructor();
ASSERT_TRUE(init->literal()->IsInt());
ASSERT_EQ(init->literal()->AsInt()->value(), 2);
ASSERT_TRUE(init->literal()->IsSint());
ASSERT_EQ(init->literal()->AsSint()->value(), 2);
}
TEST_F(ParserImplTest, UnaryExpression_Minus) {
@@ -59,8 +59,8 @@ TEST_F(ParserImplTest, UnaryExpression_Minus) {
ASSERT_TRUE(u->expr()->AsConstructor()->IsScalarConstructor());
auto* init = u->expr()->AsConstructor()->AsScalarConstructor();
ASSERT_TRUE(init->literal()->IsInt());
EXPECT_EQ(init->literal()->AsInt()->value(), 1);
ASSERT_TRUE(init->literal()->IsSint());
EXPECT_EQ(init->literal()->AsSint()->value(), 1);
}
TEST_F(ParserImplTest, UnaryExpression_Minus_InvalidRHS) {
@@ -85,8 +85,8 @@ TEST_F(ParserImplTest, UnaryExpression_Bang) {
ASSERT_TRUE(u->expr()->AsConstructor()->IsScalarConstructor());
auto* init = u->expr()->AsConstructor()->AsScalarConstructor();
ASSERT_TRUE(init->literal()->IsInt());
EXPECT_EQ(init->literal()->AsInt()->value(), 1);
ASSERT_TRUE(init->literal()->IsSint());
EXPECT_EQ(init->literal()->AsSint()->value(), 1);
}
TEST_F(ParserImplTest, UnaryExpression_Bang_InvalidRHS) {

View File

@@ -69,7 +69,7 @@ TEST_F(ParserImplTest, VariableIdentDecl_InvalidIdent) {
ASSERT_EQ(type, nullptr);
auto t = p->next();
ASSERT_TRUE(t.IsIntLiteral());
ASSERT_TRUE(t.IsSintLiteral());
}
TEST_F(ParserImplTest, VariableIdentDecl_InvalidType) {

View File

@@ -33,8 +33,8 @@ std::string Token::TypeToName(Type type) {
return "kStringLiteral";
case Token::Type::kFloatLiteral:
return "kFloatLiteral";
case Token::Type::kIntLiteral:
return "kIntLiteral";
case Token::Type::kSintLiteral:
return "kSintLiteral";
case Token::Type::kUintLiteral:
return "kUintLiteral";
case Token::Type::kUninitialized:
@@ -247,7 +247,7 @@ Token::Token(const Source& source, uint32_t val)
: type_(Type::kUintLiteral), source_(source), val_uint_(val) {}
Token::Token(const Source& source, int32_t val)
: type_(Type::kIntLiteral), source_(source), val_int_(val) {}
: type_(Type::kSintLiteral), source_(source), val_int_(val) {}
Token::Token(const Source& source, float val)
: type_(Type::kFloatLiteral), source_(source), val_float_(val) {}
@@ -266,7 +266,7 @@ std::string Token::to_str() const {
if (type_ == Type::kFloatLiteral) {
return std::to_string(val_float_);
}
if (type_ == Type::kIntLiteral) {
if (type_ == Type::kSintLiteral) {
return std::to_string(val_int_);
}
if (type_ == Type::kUintLiteral) {

View File

@@ -46,9 +46,9 @@ class Token {
kStringLiteral,
/// A float value
kFloatLiteral,
/// An int value
kIntLiteral,
/// A uint value
/// An signed int value
kSintLiteral,
/// A unsigned int value
kUintLiteral,
/// A '&'
@@ -305,8 +305,8 @@ class Token {
bool IsStringLiteral() const { return type_ == Type::kStringLiteral; }
/// @returns true if the token is a float
bool IsFloatLiteral() const { return type_ == Type::kFloatLiteral; }
/// @returns true if the token is an int
bool IsIntLiteral() const { return type_ == Type::kIntLiteral; }
/// @returns true if the token is an signed int
bool IsSintLiteral() const { return type_ == Type::kSintLiteral; }
/// @returns true if the token is a unsigned int
bool IsUintLiteral() const { return type_ == Type::kUintLiteral; }