[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/503228 Reviewed-by: Marja Hölttä <marja@chromium.org> Commit-Queue: Michael Starzinger <mstarzinger@chromium.org> Cr-Commit-Position: refs/heads/master@{#45255}
This commit is contained in:
parent
8a5382b789
commit
26f2d5c21e
@ -190,10 +190,8 @@ bool AstValue::BooleanValue() const {
|
||||
case SYMBOL:
|
||||
UNREACHABLE();
|
||||
break;
|
||||
case NUMBER_WITH_DOT:
|
||||
case NUMBER:
|
||||
return DoubleToBoolean(number_);
|
||||
case SMI_WITH_DOT:
|
||||
case SMI:
|
||||
return smi_ != 0;
|
||||
case BOOLEAN:
|
||||
@ -225,11 +223,9 @@ void AstValue::Internalize(Isolate* isolate) {
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case NUMBER_WITH_DOT:
|
||||
case NUMBER:
|
||||
set_value(isolate->factory()->NewNumber(number_, TENURED));
|
||||
break;
|
||||
case SMI_WITH_DOT:
|
||||
case SMI:
|
||||
set_value(handle(Smi::FromInt(smi_), isolate));
|
||||
break;
|
||||
@ -343,9 +339,8 @@ const AstValue* AstValueFactory::NewSymbol(AstSymbol symbol) {
|
||||
return AddValue(value);
|
||||
}
|
||||
|
||||
|
||||
const AstValue* AstValueFactory::NewNumber(double number, bool with_dot) {
|
||||
AstValue* value = new (zone_) AstValue(number, with_dot);
|
||||
const AstValue* AstValueFactory::NewNumber(double number) {
|
||||
AstValue* value = new (zone_) AstValue(number);
|
||||
return AddValue(value);
|
||||
}
|
||||
|
||||
|
@ -189,10 +189,6 @@ class AstValue : public ZoneObject {
|
||||
|
||||
bool IsNumber() const { return IsSmi() || IsHeapNumber(); }
|
||||
|
||||
bool ContainsDot() const {
|
||||
return type_ == NUMBER_WITH_DOT || type_ == SMI_WITH_DOT;
|
||||
}
|
||||
|
||||
const AstRawString* AsString() const {
|
||||
CHECK_EQ(STRING, type_);
|
||||
return string_;
|
||||
@ -236,10 +232,8 @@ class AstValue : public ZoneObject {
|
||||
|
||||
bool BooleanValue() const;
|
||||
|
||||
bool IsSmi() const { return type_ == SMI || type_ == SMI_WITH_DOT; }
|
||||
bool IsHeapNumber() const {
|
||||
return type_ == NUMBER || type_ == NUMBER_WITH_DOT;
|
||||
}
|
||||
bool IsSmi() const { return type_ == SMI; }
|
||||
bool IsHeapNumber() const { return type_ == NUMBER; }
|
||||
bool IsFalse() const { return type_ == BOOLEAN && !bool_; }
|
||||
bool IsTrue() const { return type_ == BOOLEAN && bool_; }
|
||||
bool IsUndefined() const { return type_ == UNDEFINED; }
|
||||
@ -267,9 +261,7 @@ class AstValue : public ZoneObject {
|
||||
STRING,
|
||||
SYMBOL,
|
||||
NUMBER,
|
||||
NUMBER_WITH_DOT,
|
||||
SMI,
|
||||
SMI_WITH_DOT,
|
||||
BOOLEAN,
|
||||
NULL_TYPE,
|
||||
UNDEFINED,
|
||||
@ -284,13 +276,13 @@ class AstValue : public ZoneObject {
|
||||
symbol_ = symbol;
|
||||
}
|
||||
|
||||
explicit AstValue(double n, bool with_dot) : next_(nullptr) {
|
||||
explicit AstValue(double n) : next_(nullptr) {
|
||||
int int_value;
|
||||
if (DoubleToSmiInteger(n, &int_value)) {
|
||||
type_ = with_dot ? SMI_WITH_DOT : SMI;
|
||||
type_ = SMI;
|
||||
smi_ = int_value;
|
||||
} else {
|
||||
type_ = with_dot ? NUMBER_WITH_DOT : NUMBER;
|
||||
type_ = NUMBER;
|
||||
number_ = n;
|
||||
}
|
||||
}
|
||||
@ -481,8 +473,7 @@ class AstValueFactory {
|
||||
V8_EXPORT_PRIVATE const AstValue* NewString(const AstRawString* string);
|
||||
// A JavaScript symbol (ECMA-262 edition 6).
|
||||
const AstValue* NewSymbol(AstSymbol symbol);
|
||||
V8_EXPORT_PRIVATE const AstValue* NewNumber(double number,
|
||||
bool with_dot = false);
|
||||
V8_EXPORT_PRIVATE const AstValue* NewNumber(double number);
|
||||
const AstValue* NewSmi(uint32_t number);
|
||||
const AstValue* NewBoolean(bool b);
|
||||
const AstValue* NewStringList(ZoneList<const AstRawString*>* strings);
|
||||
|
@ -3404,9 +3404,8 @@ class AstNodeFactory final BASE_EMBEDDED {
|
||||
return new (zone_) Literal(ast_value_factory_->NewSymbol(symbol), pos);
|
||||
}
|
||||
|
||||
Literal* NewNumberLiteral(double number, int pos, bool with_dot = false) {
|
||||
return new (zone_)
|
||||
Literal(ast_value_factory_->NewNumber(number, with_dot), pos);
|
||||
Literal* NewNumberLiteral(double number, int pos) {
|
||||
return new (zone_) Literal(ast_value_factory_->NewNumber(number), pos);
|
||||
}
|
||||
|
||||
Literal* NewSmiLiteral(uint32_t number, int pos) {
|
||||
|
@ -252,60 +252,56 @@ bool Parser::ShortcutNumericLiteralBinaryExpression(Expression** x,
|
||||
y->AsLiteral() && y->AsLiteral()->raw_value()->IsNumber()) {
|
||||
double x_val = (*x)->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) {
|
||||
case Token::ADD:
|
||||
*x = factory()->NewNumberLiteral(x_val + y_val, pos, has_dot);
|
||||
*x = factory()->NewNumberLiteral(x_val + y_val, pos);
|
||||
return true;
|
||||
case Token::SUB:
|
||||
*x = factory()->NewNumberLiteral(x_val - y_val, pos, has_dot);
|
||||
*x = factory()->NewNumberLiteral(x_val - y_val, pos);
|
||||
return true;
|
||||
case Token::MUL:
|
||||
*x = factory()->NewNumberLiteral(x_val * y_val, pos, has_dot);
|
||||
*x = factory()->NewNumberLiteral(x_val * y_val, pos);
|
||||
return true;
|
||||
case Token::DIV:
|
||||
*x = factory()->NewNumberLiteral(x_val / y_val, pos, has_dot);
|
||||
*x = factory()->NewNumberLiteral(x_val / y_val, pos);
|
||||
return true;
|
||||
case Token::BIT_OR: {
|
||||
int value = DoubleToInt32(x_val) | DoubleToInt32(y_val);
|
||||
*x = factory()->NewNumberLiteral(value, pos, has_dot);
|
||||
*x = factory()->NewNumberLiteral(value, pos);
|
||||
return true;
|
||||
}
|
||||
case Token::BIT_AND: {
|
||||
int value = DoubleToInt32(x_val) & DoubleToInt32(y_val);
|
||||
*x = factory()->NewNumberLiteral(value, pos, has_dot);
|
||||
*x = factory()->NewNumberLiteral(value, pos);
|
||||
return true;
|
||||
}
|
||||
case Token::BIT_XOR: {
|
||||
int value = DoubleToInt32(x_val) ^ DoubleToInt32(y_val);
|
||||
*x = factory()->NewNumberLiteral(value, pos, has_dot);
|
||||
*x = factory()->NewNumberLiteral(value, pos);
|
||||
return true;
|
||||
}
|
||||
case Token::SHL: {
|
||||
int value = DoubleToInt32(x_val) << (DoubleToInt32(y_val) & 0x1f);
|
||||
*x = factory()->NewNumberLiteral(value, pos, has_dot);
|
||||
*x = factory()->NewNumberLiteral(value, pos);
|
||||
return true;
|
||||
}
|
||||
case Token::SHR: {
|
||||
uint32_t shift = DoubleToInt32(y_val) & 0x1f;
|
||||
uint32_t value = DoubleToUint32(x_val) >> shift;
|
||||
*x = factory()->NewNumberLiteral(value, pos, has_dot);
|
||||
*x = factory()->NewNumberLiteral(value, pos);
|
||||
return true;
|
||||
}
|
||||
case Token::SAR: {
|
||||
uint32_t shift = DoubleToInt32(y_val) & 0x1f;
|
||||
int value = ArithmeticShiftRight(DoubleToInt32(x_val), shift);
|
||||
*x = factory()->NewNumberLiteral(value, pos, has_dot);
|
||||
*x = factory()->NewNumberLiteral(value, pos);
|
||||
return true;
|
||||
}
|
||||
case Token::EXP: {
|
||||
double value = Pow(x_val, y_val);
|
||||
int int_value = static_cast<int>(value);
|
||||
*x = factory()->NewNumberLiteral(
|
||||
int_value == value && value != -0.0 ? int_value : value, pos,
|
||||
has_dot);
|
||||
int_value == value && value != -0.0 ? int_value : value, pos);
|
||||
return true;
|
||||
}
|
||||
default:
|
||||
@ -327,15 +323,13 @@ Expression* Parser::BuildUnaryExpression(Expression* expression,
|
||||
} else if (literal->IsNumber()) {
|
||||
// Compute some expressions involving only number literals.
|
||||
double value = literal->AsNumber();
|
||||
bool has_dot = literal->ContainsDot();
|
||||
switch (op) {
|
||||
case Token::ADD:
|
||||
return expression;
|
||||
case Token::SUB:
|
||||
return factory()->NewNumberLiteral(-value, pos, has_dot);
|
||||
return factory()->NewNumberLiteral(-value, pos);
|
||||
case Token::BIT_NOT:
|
||||
return factory()->NewNumberLiteral(~DoubleToInt32(value), pos,
|
||||
has_dot);
|
||||
return factory()->NewNumberLiteral(~DoubleToInt32(value), pos);
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@ -344,7 +338,7 @@ Expression* Parser::BuildUnaryExpression(Expression* expression,
|
||||
// Desugar '+foo' => 'foo*1'
|
||||
if (op == Token::ADD) {
|
||||
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)'.
|
||||
if (op == Token::SUB) {
|
||||
@ -433,9 +427,8 @@ Literal* Parser::ExpressionFromLiteral(Token::Value token, int pos) {
|
||||
return factory()->NewSmiLiteral(value, pos);
|
||||
}
|
||||
case Token::NUMBER: {
|
||||
bool has_dot = scanner()->ContainsDot();
|
||||
double value = scanner()->DoubleValue();
|
||||
return factory()->NewNumberLiteral(value, pos, has_dot);
|
||||
return factory()->NewNumberLiteral(value, pos);
|
||||
}
|
||||
default:
|
||||
DCHECK(false);
|
||||
|
@ -1791,13 +1791,6 @@ double Scanner::DoubleValue() {
|
||||
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,
|
||||
AstValueFactory* ast_value_factory) const {
|
||||
DCHECK_NOT_NULL(duplicate_finder);
|
||||
|
@ -247,7 +247,6 @@ class Scanner {
|
||||
AstValueFactory* ast_value_factory) const;
|
||||
|
||||
double DoubleValue();
|
||||
bool ContainsDot();
|
||||
|
||||
inline bool CurrentMatches(Token::Value token) const {
|
||||
DCHECK(Token::IsKeyword(token));
|
||||
|
@ -867,8 +867,7 @@ TEST(ScopeUsesArgumentsSuperThis) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void CheckParsesToNumber(const char* source, bool with_dot) {
|
||||
static void CheckParsesToNumber(const char* source) {
|
||||
v8::V8::Initialize();
|
||||
HandleAndZoneScope handles;
|
||||
|
||||
@ -899,40 +898,27 @@ static void CheckParsesToNumber(const char* source, bool with_dot) {
|
||||
CHECK(fun->body()->at(0)->IsReturnStatement());
|
||||
i::ReturnStatement* ret = fun->body()->at(0)->AsReturnStatement();
|
||||
i::Literal* lit = ret->expression()->AsLiteral();
|
||||
if (lit != NULL) {
|
||||
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());
|
||||
}
|
||||
CHECK(lit->IsNumberLiteral());
|
||||
}
|
||||
|
||||
|
||||
TEST(ParseNumbers) {
|
||||
CheckParsesToNumber("1.", true);
|
||||
CheckParsesToNumber("1.34", true);
|
||||
CheckParsesToNumber("134", false);
|
||||
CheckParsesToNumber("134e44", false);
|
||||
CheckParsesToNumber("134.e44", true);
|
||||
CheckParsesToNumber("134.44e44", true);
|
||||
CheckParsesToNumber(".44", true);
|
||||
CheckParsesToNumber("1.");
|
||||
CheckParsesToNumber("1.34");
|
||||
CheckParsesToNumber("134");
|
||||
CheckParsesToNumber("134e44");
|
||||
CheckParsesToNumber("134.e44");
|
||||
CheckParsesToNumber("134.44e44");
|
||||
CheckParsesToNumber(".44");
|
||||
|
||||
CheckParsesToNumber("-1.", true);
|
||||
CheckParsesToNumber("-1.0", true);
|
||||
CheckParsesToNumber("-1.34", true);
|
||||
CheckParsesToNumber("-134", false);
|
||||
CheckParsesToNumber("-134e44", false);
|
||||
CheckParsesToNumber("-134.e44", true);
|
||||
CheckParsesToNumber("-134.44e44", true);
|
||||
CheckParsesToNumber("-.44", true);
|
||||
|
||||
CheckParsesToNumber("+x", true);
|
||||
CheckParsesToNumber("-1.");
|
||||
CheckParsesToNumber("-1.0");
|
||||
CheckParsesToNumber("-1.34");
|
||||
CheckParsesToNumber("-134");
|
||||
CheckParsesToNumber("-134e44");
|
||||
CheckParsesToNumber("-134.e44");
|
||||
CheckParsesToNumber("-134.44e44");
|
||||
CheckParsesToNumber("-.44");
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user