Commit 477495c8 authored by rmcilroy's avatar rmcilroy Committed by Commit bot

[Parser] Track ContainsDot for SMI values.

Ensures SMI values have SMI type even if they have a dot (e.g., 1.0).
Adds SMI_WITH_DOT type to maintain this.

BUG=chromium:638134

Review-Url: https://codereview.chromium.org/2248693005
Cr-Commit-Position: refs/heads/master@{#38698}
parent 3cbb5e48
...@@ -156,6 +156,7 @@ bool AstValue::BooleanValue() const { ...@@ -156,6 +156,7 @@ bool AstValue::BooleanValue() const {
case NUMBER_WITH_DOT: 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:
...@@ -195,6 +196,7 @@ void AstValue::Internalize(Isolate* isolate) { ...@@ -195,6 +196,7 @@ void AstValue::Internalize(Isolate* isolate) {
case NUMBER: case NUMBER:
value_ = isolate->factory()->NewNumber(number_, TENURED); value_ = isolate->factory()->NewNumber(number_, TENURED);
break; break;
case SMI_WITH_DOT:
case SMI: case SMI:
value_ = handle(Smi::FromInt(smi_), isolate); value_ = handle(Smi::FromInt(smi_), isolate);
break; break;
......
...@@ -154,10 +154,13 @@ class AstValue : public ZoneObject { ...@@ -154,10 +154,13 @@ class AstValue : public ZoneObject {
} }
bool IsNumber() const { bool IsNumber() const {
return type_ == NUMBER || type_ == NUMBER_WITH_DOT || type_ == SMI; return type_ == NUMBER || type_ == NUMBER_WITH_DOT || type_ == SMI ||
type_ == SMI_WITH_DOT;
} }
bool ContainsDot() const { return type_ == NUMBER_WITH_DOT; } 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_);
...@@ -167,14 +170,14 @@ class AstValue : public ZoneObject { ...@@ -167,14 +170,14 @@ class AstValue : public ZoneObject {
double AsNumber() const { double AsNumber() const {
if (type_ == NUMBER || type_ == NUMBER_WITH_DOT) if (type_ == NUMBER || type_ == NUMBER_WITH_DOT)
return number_; return number_;
if (type_ == SMI) if (type_ == SMI || type_ == SMI_WITH_DOT)
return smi_; return smi_;
UNREACHABLE(); UNREACHABLE();
return 0; return 0;
} }
Smi* AsSmi() const { Smi* AsSmi() const {
CHECK_EQ(SMI, type_); CHECK(type_ == SMI || type_ == SMI_WITH_DOT);
return Smi::FromInt(smi_); return Smi::FromInt(smi_);
} }
...@@ -186,7 +189,7 @@ class AstValue : public ZoneObject { ...@@ -186,7 +189,7 @@ class AstValue : public ZoneObject {
bool BooleanValue() const; bool BooleanValue() const;
bool IsSmi() const { return type_ == SMI; } bool IsSmi() const { return type_ == SMI || type_ == SMI_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; }
...@@ -215,6 +218,7 @@ class AstValue : public ZoneObject { ...@@ -215,6 +218,7 @@ class AstValue : public ZoneObject {
NUMBER, NUMBER,
NUMBER_WITH_DOT, NUMBER_WITH_DOT,
SMI, SMI,
SMI_WITH_DOT,
BOOLEAN, BOOLEAN,
NULL_TYPE, NULL_TYPE,
UNDEFINED, UNDEFINED,
...@@ -230,20 +234,15 @@ class AstValue : public ZoneObject { ...@@ -230,20 +234,15 @@ class AstValue : public ZoneObject {
} }
explicit AstValue(double n, bool with_dot) : next_(nullptr) { explicit AstValue(double n, bool with_dot) : next_(nullptr) {
if (with_dot) {
type_ = NUMBER_WITH_DOT;
number_ = n;
} else {
int int_value; int int_value;
if (DoubleToSmiInteger(n, &int_value)) { if (DoubleToSmiInteger(n, &int_value)) {
type_ = SMI; type_ = with_dot ? SMI_WITH_DOT : SMI;
smi_ = int_value; smi_ = int_value;
} else { } else {
type_ = NUMBER; type_ = with_dot ? NUMBER_WITH_DOT : NUMBER;
number_ = n; number_ = n;
} }
} }
}
AstValue(Type t, int i) : type_(t), next_(nullptr) { AstValue(Type t, int i) : type_(t), next_(nullptr) {
DCHECK(type_ == SMI); DCHECK(type_ == SMI);
......
...@@ -185,11 +185,10 @@ parameter count: 1 ...@@ -185,11 +185,10 @@ parameter count: 1
bytecode array length: 4 bytecode array length: 4
bytecodes: [ bytecodes: [
/* 30 E> */ B(StackCheck), /* 30 E> */ B(StackCheck),
/* 34 S> */ B(LdaConstant), U8(0), /* 34 S> */ B(LdaSmi), U8(2),
/* 46 S> */ B(Return), /* 46 S> */ B(Return),
] ]
constant pool: [ constant pool: [
2,
] ]
handlers: [ handlers: [
] ]
......
...@@ -150,12 +150,11 @@ bytecodes: [ ...@@ -150,12 +150,11 @@ bytecodes: [
/* 30 E> */ B(StackCheck), /* 30 E> */ B(StackCheck),
/* 42 S> */ B(LdaSmi), U8(13), /* 42 S> */ B(LdaSmi), U8(13),
B(Star), R(0), B(Star), R(0),
/* 46 S> */ B(LdaConstant), U8(0), /* 46 S> */ B(LdaSmi), U8(1),
B(Mul), R(0), U8(1), B(Mul), R(0), U8(1),
/* 57 S> */ B(Return), /* 57 S> */ B(Return),
] ]
constant pool: [ constant pool: [
1,
] ]
handlers: [ handlers: [
] ]
......
// Copyright 2016 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
function foo() {
// Generates a forward branch that puts 200 in the constant pool.
var i = 0;
if (i) {
i = 0; i = 0; i = 0; i = 0; i = 0; i = 0; i = 0; i = 0; i = 0; i = 0;
i = 0; i = 0; i = 0; i = 0; i = 0; i = 0; i = 0; i = 0; i = 0; i = 0;
i = 0; i = 0; i = 0; i = 0; i = 0; i = 0; i = 0; i = 0; i = 0; i = 0;
i = 0; i = 0; i = 0; i = 0; i = 0; i = 0; i = 0; i = 0; i = 0; i = 0;
i = 0; i = 0; i = 0; i = 0; i = 0; i = 0; i = 0; i = 0; i = 0; i = 0;
i = 0; i = 0; i = 0; i = 0; i = 0; i = 0; i = 0; i = 0; i = 0; i = 0;
i = 0; i = 0; i = 0; i = 0; i = 0; i = 0;
}
// Emit a 200 literal which also ends up in the constant pool.
var j = 0.2e3;
}
foo();
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