Commit 26f2d5c2 authored by Michael Starzinger's avatar Michael Starzinger Committed by Commit Bot

[parser] Remove redundant "dot" tracking for numbers.

This removes logic tracking whether a number literal in the source
contained a "dot" character or not. The tracking was only needed for
validation of asm.js modules on the AST, it is obsolete now.

R=marja@chromium.org

Change-Id: Ib474e2281db80fe56d43e1af52221a7c66261e01
Reviewed-on: https://chromium-review.googlesource.com/503228Reviewed-by: 's avatarMarja Hölttä <marja@chromium.org>
Commit-Queue: Michael Starzinger <mstarzinger@chromium.org>
Cr-Commit-Position: refs/heads/master@{#45255}
parent 8a5382b7
...@@ -190,10 +190,8 @@ bool AstValue::BooleanValue() const { ...@@ -190,10 +190,8 @@ bool AstValue::BooleanValue() const {
case SYMBOL: case SYMBOL:
UNREACHABLE(); UNREACHABLE();
break; break;
case NUMBER_WITH_DOT:
case NUMBER: case NUMBER:
return DoubleToBoolean(number_); return DoubleToBoolean(number_);
case SMI_WITH_DOT:
case SMI: case SMI:
return smi_ != 0; return smi_ != 0;
case BOOLEAN: case BOOLEAN:
...@@ -225,11 +223,9 @@ void AstValue::Internalize(Isolate* isolate) { ...@@ -225,11 +223,9 @@ void AstValue::Internalize(Isolate* isolate) {
break; break;
} }
break; break;
case NUMBER_WITH_DOT:
case NUMBER: case NUMBER:
set_value(isolate->factory()->NewNumber(number_, TENURED)); set_value(isolate->factory()->NewNumber(number_, TENURED));
break; break;
case SMI_WITH_DOT:
case SMI: case SMI:
set_value(handle(Smi::FromInt(smi_), isolate)); set_value(handle(Smi::FromInt(smi_), isolate));
break; break;
...@@ -343,9 +339,8 @@ const AstValue* AstValueFactory::NewSymbol(AstSymbol symbol) { ...@@ -343,9 +339,8 @@ const AstValue* AstValueFactory::NewSymbol(AstSymbol symbol) {
return AddValue(value); return AddValue(value);
} }
const AstValue* AstValueFactory::NewNumber(double number) {
const AstValue* AstValueFactory::NewNumber(double number, bool with_dot) { AstValue* value = new (zone_) AstValue(number);
AstValue* value = new (zone_) AstValue(number, with_dot);
return AddValue(value); return AddValue(value);
} }
......
...@@ -189,10 +189,6 @@ class AstValue : public ZoneObject { ...@@ -189,10 +189,6 @@ class AstValue : public ZoneObject {
bool IsNumber() const { return IsSmi() || IsHeapNumber(); } bool IsNumber() const { return IsSmi() || IsHeapNumber(); }
bool ContainsDot() const {
return type_ == NUMBER_WITH_DOT || type_ == SMI_WITH_DOT;
}
const AstRawString* AsString() const { const AstRawString* AsString() const {
CHECK_EQ(STRING, type_); CHECK_EQ(STRING, type_);
return string_; return string_;
...@@ -236,10 +232,8 @@ class AstValue : public ZoneObject { ...@@ -236,10 +232,8 @@ class AstValue : public ZoneObject {
bool BooleanValue() const; bool BooleanValue() const;
bool IsSmi() const { return type_ == SMI || type_ == SMI_WITH_DOT; } bool IsSmi() const { return type_ == SMI; }
bool IsHeapNumber() const { bool IsHeapNumber() const { return type_ == NUMBER; }
return type_ == NUMBER || type_ == NUMBER_WITH_DOT;
}
bool IsFalse() const { return type_ == BOOLEAN && !bool_; } bool IsFalse() const { return type_ == BOOLEAN && !bool_; }
bool IsTrue() const { return type_ == BOOLEAN && bool_; } bool IsTrue() const { return type_ == BOOLEAN && bool_; }
bool IsUndefined() const { return type_ == UNDEFINED; } bool IsUndefined() const { return type_ == UNDEFINED; }
...@@ -267,9 +261,7 @@ class AstValue : public ZoneObject { ...@@ -267,9 +261,7 @@ class AstValue : public ZoneObject {
STRING, STRING,
SYMBOL, SYMBOL,
NUMBER, NUMBER,
NUMBER_WITH_DOT,
SMI, SMI,
SMI_WITH_DOT,
BOOLEAN, BOOLEAN,
NULL_TYPE, NULL_TYPE,
UNDEFINED, UNDEFINED,
...@@ -284,13 +276,13 @@ class AstValue : public ZoneObject { ...@@ -284,13 +276,13 @@ class AstValue : public ZoneObject {
symbol_ = symbol; symbol_ = symbol;
} }
explicit AstValue(double n, bool with_dot) : next_(nullptr) { explicit AstValue(double n) : next_(nullptr) {
int int_value; int int_value;
if (DoubleToSmiInteger(n, &int_value)) { if (DoubleToSmiInteger(n, &int_value)) {
type_ = with_dot ? SMI_WITH_DOT : SMI; type_ = SMI;
smi_ = int_value; smi_ = int_value;
} else { } else {
type_ = with_dot ? NUMBER_WITH_DOT : NUMBER; type_ = NUMBER;
number_ = n; number_ = n;
} }
} }
...@@ -481,8 +473,7 @@ class AstValueFactory { ...@@ -481,8 +473,7 @@ class AstValueFactory {
V8_EXPORT_PRIVATE const AstValue* NewString(const AstRawString* string); V8_EXPORT_PRIVATE const AstValue* NewString(const AstRawString* string);
// A JavaScript symbol (ECMA-262 edition 6). // A JavaScript symbol (ECMA-262 edition 6).
const AstValue* NewSymbol(AstSymbol symbol); const AstValue* NewSymbol(AstSymbol symbol);
V8_EXPORT_PRIVATE const AstValue* NewNumber(double number, V8_EXPORT_PRIVATE const AstValue* NewNumber(double number);
bool with_dot = false);
const AstValue* NewSmi(uint32_t number); const AstValue* NewSmi(uint32_t number);
const AstValue* NewBoolean(bool b); const AstValue* NewBoolean(bool b);
const AstValue* NewStringList(ZoneList<const AstRawString*>* strings); const AstValue* NewStringList(ZoneList<const AstRawString*>* strings);
......
...@@ -3404,9 +3404,8 @@ class AstNodeFactory final BASE_EMBEDDED { ...@@ -3404,9 +3404,8 @@ class AstNodeFactory final BASE_EMBEDDED {
return new (zone_) Literal(ast_value_factory_->NewSymbol(symbol), pos); return new (zone_) Literal(ast_value_factory_->NewSymbol(symbol), pos);
} }
Literal* NewNumberLiteral(double number, int pos, bool with_dot = false) { Literal* NewNumberLiteral(double number, int pos) {
return new (zone_) return new (zone_) Literal(ast_value_factory_->NewNumber(number), pos);
Literal(ast_value_factory_->NewNumber(number, with_dot), pos);
} }
Literal* NewSmiLiteral(uint32_t number, int pos) { Literal* NewSmiLiteral(uint32_t number, int pos) {
......
...@@ -252,60 +252,56 @@ bool Parser::ShortcutNumericLiteralBinaryExpression(Expression** x, ...@@ -252,60 +252,56 @@ bool Parser::ShortcutNumericLiteralBinaryExpression(Expression** x,
y->AsLiteral() && y->AsLiteral()->raw_value()->IsNumber()) { y->AsLiteral() && y->AsLiteral()->raw_value()->IsNumber()) {
double x_val = (*x)->AsLiteral()->raw_value()->AsNumber(); double x_val = (*x)->AsLiteral()->raw_value()->AsNumber();
double y_val = y->AsLiteral()->raw_value()->AsNumber(); double y_val = y->AsLiteral()->raw_value()->AsNumber();
bool x_has_dot = (*x)->AsLiteral()->raw_value()->ContainsDot();
bool y_has_dot = y->AsLiteral()->raw_value()->ContainsDot();
bool has_dot = x_has_dot || y_has_dot;
switch (op) { switch (op) {
case Token::ADD: case Token::ADD:
*x = factory()->NewNumberLiteral(x_val + y_val, pos, has_dot); *x = factory()->NewNumberLiteral(x_val + y_val, pos);
return true; return true;
case Token::SUB: case Token::SUB:
*x = factory()->NewNumberLiteral(x_val - y_val, pos, has_dot); *x = factory()->NewNumberLiteral(x_val - y_val, pos);
return true; return true;
case Token::MUL: case Token::MUL:
*x = factory()->NewNumberLiteral(x_val * y_val, pos, has_dot); *x = factory()->NewNumberLiteral(x_val * y_val, pos);
return true; return true;
case Token::DIV: case Token::DIV:
*x = factory()->NewNumberLiteral(x_val / y_val, pos, has_dot); *x = factory()->NewNumberLiteral(x_val / y_val, pos);
return true; return true;
case Token::BIT_OR: { case Token::BIT_OR: {
int value = DoubleToInt32(x_val) | DoubleToInt32(y_val); int value = DoubleToInt32(x_val) | DoubleToInt32(y_val);
*x = factory()->NewNumberLiteral(value, pos, has_dot); *x = factory()->NewNumberLiteral(value, pos);
return true; return true;
} }
case Token::BIT_AND: { case Token::BIT_AND: {
int value = DoubleToInt32(x_val) & DoubleToInt32(y_val); int value = DoubleToInt32(x_val) & DoubleToInt32(y_val);
*x = factory()->NewNumberLiteral(value, pos, has_dot); *x = factory()->NewNumberLiteral(value, pos);
return true; return true;
} }
case Token::BIT_XOR: { case Token::BIT_XOR: {
int value = DoubleToInt32(x_val) ^ DoubleToInt32(y_val); int value = DoubleToInt32(x_val) ^ DoubleToInt32(y_val);
*x = factory()->NewNumberLiteral(value, pos, has_dot); *x = factory()->NewNumberLiteral(value, pos);
return true; return true;
} }
case Token::SHL: { case Token::SHL: {
int value = DoubleToInt32(x_val) << (DoubleToInt32(y_val) & 0x1f); int value = DoubleToInt32(x_val) << (DoubleToInt32(y_val) & 0x1f);
*x = factory()->NewNumberLiteral(value, pos, has_dot); *x = factory()->NewNumberLiteral(value, pos);
return true; return true;
} }
case Token::SHR: { case Token::SHR: {
uint32_t shift = DoubleToInt32(y_val) & 0x1f; uint32_t shift = DoubleToInt32(y_val) & 0x1f;
uint32_t value = DoubleToUint32(x_val) >> shift; uint32_t value = DoubleToUint32(x_val) >> shift;
*x = factory()->NewNumberLiteral(value, pos, has_dot); *x = factory()->NewNumberLiteral(value, pos);
return true; return true;
} }
case Token::SAR: { case Token::SAR: {
uint32_t shift = DoubleToInt32(y_val) & 0x1f; uint32_t shift = DoubleToInt32(y_val) & 0x1f;
int value = ArithmeticShiftRight(DoubleToInt32(x_val), shift); int value = ArithmeticShiftRight(DoubleToInt32(x_val), shift);
*x = factory()->NewNumberLiteral(value, pos, has_dot); *x = factory()->NewNumberLiteral(value, pos);
return true; return true;
} }
case Token::EXP: { case Token::EXP: {
double value = Pow(x_val, y_val); double value = Pow(x_val, y_val);
int int_value = static_cast<int>(value); int int_value = static_cast<int>(value);
*x = factory()->NewNumberLiteral( *x = factory()->NewNumberLiteral(
int_value == value && value != -0.0 ? int_value : value, pos, int_value == value && value != -0.0 ? int_value : value, pos);
has_dot);
return true; return true;
} }
default: default:
...@@ -327,15 +323,13 @@ Expression* Parser::BuildUnaryExpression(Expression* expression, ...@@ -327,15 +323,13 @@ Expression* Parser::BuildUnaryExpression(Expression* expression,
} else if (literal->IsNumber()) { } else if (literal->IsNumber()) {
// Compute some expressions involving only number literals. // Compute some expressions involving only number literals.
double value = literal->AsNumber(); double value = literal->AsNumber();
bool has_dot = literal->ContainsDot();
switch (op) { switch (op) {
case Token::ADD: case Token::ADD:
return expression; return expression;
case Token::SUB: case Token::SUB:
return factory()->NewNumberLiteral(-value, pos, has_dot); return factory()->NewNumberLiteral(-value, pos);
case Token::BIT_NOT: case Token::BIT_NOT:
return factory()->NewNumberLiteral(~DoubleToInt32(value), pos, return factory()->NewNumberLiteral(~DoubleToInt32(value), pos);
has_dot);
default: default:
break; break;
} }
...@@ -344,7 +338,7 @@ Expression* Parser::BuildUnaryExpression(Expression* expression, ...@@ -344,7 +338,7 @@ Expression* Parser::BuildUnaryExpression(Expression* expression,
// Desugar '+foo' => 'foo*1' // Desugar '+foo' => 'foo*1'
if (op == Token::ADD) { if (op == Token::ADD) {
return factory()->NewBinaryOperation( return factory()->NewBinaryOperation(
Token::MUL, expression, factory()->NewNumberLiteral(1, pos, true), pos); Token::MUL, expression, factory()->NewNumberLiteral(1, pos), pos);
} }
// The same idea for '-foo' => 'foo*(-1)'. // The same idea for '-foo' => 'foo*(-1)'.
if (op == Token::SUB) { if (op == Token::SUB) {
...@@ -433,9 +427,8 @@ Literal* Parser::ExpressionFromLiteral(Token::Value token, int pos) { ...@@ -433,9 +427,8 @@ Literal* Parser::ExpressionFromLiteral(Token::Value token, int pos) {
return factory()->NewSmiLiteral(value, pos); return factory()->NewSmiLiteral(value, pos);
} }
case Token::NUMBER: { case Token::NUMBER: {
bool has_dot = scanner()->ContainsDot();
double value = scanner()->DoubleValue(); double value = scanner()->DoubleValue();
return factory()->NewNumberLiteral(value, pos, has_dot); return factory()->NewNumberLiteral(value, pos);
} }
default: default:
DCHECK(false); DCHECK(false);
......
...@@ -1791,13 +1791,6 @@ double Scanner::DoubleValue() { ...@@ -1791,13 +1791,6 @@ double Scanner::DoubleValue() {
ALLOW_HEX | ALLOW_OCTAL | ALLOW_IMPLICIT_OCTAL | ALLOW_BINARY); ALLOW_HEX | ALLOW_OCTAL | ALLOW_IMPLICIT_OCTAL | ALLOW_BINARY);
} }
bool Scanner::ContainsDot() {
DCHECK(is_literal_one_byte());
Vector<const uint8_t> str = literal_one_byte_string();
return std::find(str.begin(), str.end(), '.') != str.end();
}
bool Scanner::IsDuplicateSymbol(DuplicateFinder* duplicate_finder, bool Scanner::IsDuplicateSymbol(DuplicateFinder* duplicate_finder,
AstValueFactory* ast_value_factory) const { AstValueFactory* ast_value_factory) const {
DCHECK_NOT_NULL(duplicate_finder); DCHECK_NOT_NULL(duplicate_finder);
......
...@@ -247,7 +247,6 @@ class Scanner { ...@@ -247,7 +247,6 @@ class Scanner {
AstValueFactory* ast_value_factory) const; AstValueFactory* ast_value_factory) const;
double DoubleValue(); double DoubleValue();
bool ContainsDot();
inline bool CurrentMatches(Token::Value token) const { inline bool CurrentMatches(Token::Value token) const {
DCHECK(Token::IsKeyword(token)); DCHECK(Token::IsKeyword(token));
......
...@@ -867,8 +867,7 @@ TEST(ScopeUsesArgumentsSuperThis) { ...@@ -867,8 +867,7 @@ TEST(ScopeUsesArgumentsSuperThis) {
} }
} }
static void CheckParsesToNumber(const char* source) {
static void CheckParsesToNumber(const char* source, bool with_dot) {
v8::V8::Initialize(); v8::V8::Initialize();
HandleAndZoneScope handles; HandleAndZoneScope handles;
...@@ -899,40 +898,27 @@ static void CheckParsesToNumber(const char* source, bool with_dot) { ...@@ -899,40 +898,27 @@ static void CheckParsesToNumber(const char* source, bool with_dot) {
CHECK(fun->body()->at(0)->IsReturnStatement()); CHECK(fun->body()->at(0)->IsReturnStatement());
i::ReturnStatement* ret = fun->body()->at(0)->AsReturnStatement(); i::ReturnStatement* ret = fun->body()->at(0)->AsReturnStatement();
i::Literal* lit = ret->expression()->AsLiteral(); i::Literal* lit = ret->expression()->AsLiteral();
if (lit != NULL) { CHECK(lit->IsNumberLiteral());
const i::AstValue* val = lit->raw_value();
CHECK(with_dot == val->ContainsDot());
} else if (with_dot) {
i::BinaryOperation* bin = ret->expression()->AsBinaryOperation();
CHECK(bin != NULL);
CHECK_EQ(i::Token::MUL, bin->op());
i::Literal* rlit = bin->right()->AsLiteral();
const i::AstValue* val = rlit->raw_value();
CHECK(with_dot == val->ContainsDot());
CHECK_EQ(1.0, val->AsNumber());
}
} }
TEST(ParseNumbers) { TEST(ParseNumbers) {
CheckParsesToNumber("1.", true); CheckParsesToNumber("1.");
CheckParsesToNumber("1.34", true); CheckParsesToNumber("1.34");
CheckParsesToNumber("134", false); CheckParsesToNumber("134");
CheckParsesToNumber("134e44", false); CheckParsesToNumber("134e44");
CheckParsesToNumber("134.e44", true); CheckParsesToNumber("134.e44");
CheckParsesToNumber("134.44e44", true); CheckParsesToNumber("134.44e44");
CheckParsesToNumber(".44", true); CheckParsesToNumber(".44");
CheckParsesToNumber("-1.", true); CheckParsesToNumber("-1.");
CheckParsesToNumber("-1.0", true); CheckParsesToNumber("-1.0");
CheckParsesToNumber("-1.34", true); CheckParsesToNumber("-1.34");
CheckParsesToNumber("-134", false); CheckParsesToNumber("-134");
CheckParsesToNumber("-134e44", false); CheckParsesToNumber("-134e44");
CheckParsesToNumber("-134.e44", true); CheckParsesToNumber("-134.e44");
CheckParsesToNumber("-134.44e44", true); CheckParsesToNumber("-134.44e44");
CheckParsesToNumber("-.44", true); CheckParsesToNumber("-.44");
CheckParsesToNumber("+x", true);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment