Treat the x*1 generated by parsing a unary + as containing a dot.

Since we convert +x to x*1, we loose information about whether
the 1 was intended to be a floating point value for asm.js or not.

Mark the generated 1 as containing a dot (i.e. 1.0).

BUG= https://code.google.com/p/v8/issues/detail?id=4203
TEST=test-parser
R=rossberg@chromium.org,titzer@chromium.org
LOG=N

Review URL: https://codereview.chromium.org/1306683003

Cr-Commit-Position: refs/heads/master@{#30481}
This commit is contained in:
bradnelson 2015-08-31 09:35:51 -07:00 committed by Commit bot
parent 8b781ecc5d
commit 4d3a0a7ce6
2 changed files with 14 additions and 4 deletions

View File

@ -626,7 +626,7 @@ Expression* ParserTraits::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), pos); Token::MUL, expression, factory->NewNumberLiteral(1, pos, true), pos);
} }
// The same idea for '-foo' => 'foo*(-1)'. // The same idea for '-foo' => 'foo*(-1)'.
if (op == Token::SUB) { if (op == Token::SUB) {

View File

@ -1134,10 +1134,19 @@ static void CheckParsesToNumber(const char* source, bool with_dot) {
CHECK(fun->body()->length() == 1); CHECK(fun->body()->length() == 1);
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();
CHECK(ret->expression()->IsLiteral());
i::Literal* lit = ret->expression()->AsLiteral(); i::Literal* lit = ret->expression()->AsLiteral();
const i::AstValue* val = lit->raw_value(); if (lit != NULL) {
CHECK(with_dot == val->ContainsDot()); 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());
}
} }
@ -1148,6 +1157,7 @@ TEST(ParseNumbers) {
CheckParsesToNumber("134.e44", true); CheckParsesToNumber("134.e44", true);
CheckParsesToNumber("134.44e44", true); CheckParsesToNumber("134.44e44", true);
CheckParsesToNumber(".44", true); CheckParsesToNumber(".44", true);
CheckParsesToNumber("+x", true);
} }