Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1411)

Unified Diff: src/parser.cc

Issue 300103005: Split StringLiteral from Literal. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: number literals Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/mips/full-codegen-mips.cc ('k') | src/preparser.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/parser.cc
diff --git a/src/parser.cc b/src/parser.cc
index a08148c5974f3de8fb882935b774afd1e0d20abf..30a8945b395a78f4558cb2e3cff7b2a8bf96002a 100644
--- a/src/parser.cc
+++ b/src/parser.cc
@@ -424,7 +424,7 @@ bool ParserTraits::IsIdentifier(Expression* expression) {
void ParserTraits::PushPropertyName(FuncNameInferrer* fni,
Expression* expression) {
if (expression->IsPropertyName()) {
- fni->PushLiteralName(expression->AsLiteral()->AsPropertyName());
+ fni->PushLiteralName(expression->AsStringLiteral()->AsPropertyName());
} else {
fni->PushLiteralName(
parser_->isolate()->factory()->anonymous_function_string());
@@ -464,10 +464,9 @@ Expression* ParserTraits::MarkExpressionAsLValue(Expression* expression) {
bool ParserTraits::ShortcutNumericLiteralBinaryExpression(
Expression** x, Expression* y, Token::Value op, int pos,
AstNodeFactory<AstConstructionVisitor>* factory) {
- if ((*x)->AsLiteral() && (*x)->AsLiteral()->value()->IsNumber() &&
- y->AsLiteral() && y->AsLiteral()->value()->IsNumber()) {
- double x_val = (*x)->AsLiteral()->value()->Number();
- double y_val = y->AsLiteral()->value()->Number();
+ if ((*x)->AsNumberLiteral() && y->AsNumberLiteral()) {
+ double x_val = (*x)->AsNumberLiteral()->number();
+ double y_val = y->AsNumberLiteral()->number();
switch (op) {
case Token::ADD:
*x = factory->NewNumberLiteral(x_val + y_val, pos);
@@ -525,8 +524,8 @@ Expression* ParserTraits::BuildUnaryExpression(
Expression* expression, Token::Value op, int pos,
AstNodeFactory<AstConstructionVisitor>* factory) {
ASSERT(expression != NULL);
- if (expression->AsLiteral() != NULL) {
- Handle<Object> literal = expression->AsLiteral()->value();
+ if (expression->AsAnyLiteral() != NULL) {
+ Handle<Object> literal = expression->AsAnyLiteral()->value();
if (op == Token::NOT) {
// Convert the literal to a boolean condition and negate it.
bool condition = literal->BooleanValue();
@@ -548,6 +547,7 @@ Expression* ParserTraits::BuildUnaryExpression(
}
}
}
+
// Desugar '+foo' => 'foo*1'
if (op == Token::ADD) {
return factory->NewBinaryOperation(
@@ -612,7 +612,7 @@ Expression* ParserTraits::NewThrowError(
ZoneList<Expression*>* args = new(zone) ZoneList<Expression*>(2, zone);
Handle<String> type = factory->InternalizeUtf8String(message);
- args->Add(parser_->factory()->NewLiteral(type, pos), zone);
+ args->Add(parser_->factory()->NewStringLiteral(type, pos), zone);
args->Add(parser_->factory()->NewLiteral(array, pos), zone);
CallRuntime* call_constructor =
parser_->factory()->NewCallRuntime(constructor, NULL, args, pos);
@@ -729,7 +729,7 @@ Expression* ParserTraits::ExpressionFromString(
AstNodeFactory<AstConstructionVisitor>* factory) {
Handle<String> symbol = GetSymbol(scanner);
if (parser_->fni_ != NULL) parser_->fni_->PushLiteralName(symbol);
- return factory->NewLiteral(symbol, pos);
+ return factory->NewStringLiteral(symbol, pos);
}
@@ -1075,12 +1075,11 @@ void* Parser::ParseSourceElements(ZoneList<Statement*>* processor,
if (directive_prologue) {
// A shot at a directive.
ExpressionStatement* e_stat;
- Literal* literal;
+ StringLiteral* literal;
// Still processing directive prologue?
if ((e_stat = stat->AsExpressionStatement()) != NULL &&
- (literal = e_stat->expression()->AsLiteral()) != NULL &&
- literal->value()->IsString()) {
- Handle<String> directive = Handle<String>::cast(literal->value());
+ (literal = e_stat->expression()->AsStringLiteral()) != NULL) {
+ Handle<String> directive = literal->string();
// Check "use strict" directive (ES5 14.1).
if (strict_mode() == SLOPPY &&
@@ -2194,7 +2193,7 @@ Block* Parser::ParseVariableDeclarations(
ZoneList<Expression*>* arguments =
new(zone()) ZoneList<Expression*>(3, zone());
// We have at least 1 parameter.
- arguments->Add(factory()->NewLiteral(name, pos), zone());
+ arguments->Add(factory()->NewStringLiteral(name, pos), zone());
CallRuntime* initialize;
if (is_const) {
@@ -2796,7 +2795,7 @@ void Parser::InitializeForEachStatement(ForEachStatement* stmt,
// var result = iterator.next();
{
Expression* iterator_proxy = factory()->NewVariableProxy(iterator);
- Expression* next_literal = factory()->NewLiteral(
+ Expression* next_literal = factory()->NewStringLiteral(
heap_factory->next_string(), RelocInfo::kNoPosition);
Expression* next_property = factory()->NewProperty(
iterator_proxy, next_literal, RelocInfo::kNoPosition);
@@ -2811,7 +2810,7 @@ void Parser::InitializeForEachStatement(ForEachStatement* stmt,
// result.done
{
- Expression* done_literal = factory()->NewLiteral(
+ Expression* done_literal = factory()->NewStringLiteral(
heap_factory->done_string(), RelocInfo::kNoPosition);
Expression* result_proxy = factory()->NewVariableProxy(result);
result_done = factory()->NewProperty(
@@ -2820,7 +2819,7 @@ void Parser::InitializeForEachStatement(ForEachStatement* stmt,
// each = result.value
{
- Expression* value_literal = factory()->NewLiteral(
+ Expression* value_literal = factory()->NewStringLiteral(
heap_factory->value_string(), RelocInfo::kNoPosition);
Expression* result_proxy = factory()->NewVariableProxy(result);
Expression* result_value = factory()->NewProperty(
@@ -2905,7 +2904,8 @@ Statement* Parser::DesugarLetBindingsInForStatement(
// Make statement: flag = 1.
{
VariableProxy* flag_proxy = factory()->NewVariableProxy(flag);
- Expression* const1 = factory()->NewLiteral(smi1, RelocInfo::kNoPosition);
+ Expression* const1 =
+ factory()->NewNumberLiteral(smi1, RelocInfo::kNoPosition);
Assignment* assignment = factory()->NewAssignment(
Token::ASSIGN, flag_proxy, const1, RelocInfo::kNoPosition);
Statement* assignment_statement = factory()->NewExpressionStatement(
@@ -2945,7 +2945,8 @@ Statement* Parser::DesugarLetBindingsInForStatement(
Expression* compare = NULL;
// Make compare expresion: flag == 1.
{
- Expression* const1 = factory()->NewLiteral(smi1, RelocInfo::kNoPosition);
+ Expression* const1 =
+ factory()->NewNumberLiteral(smi1, RelocInfo::kNoPosition);
VariableProxy* flag_proxy = factory()->NewVariableProxy(flag);
compare = factory()->NewCompareOperation(
Token::EQ, flag_proxy, const1, RelocInfo::kNoPosition);
@@ -2954,7 +2955,8 @@ Statement* Parser::DesugarLetBindingsInForStatement(
// Make statement: flag = 0.
{
VariableProxy* flag_proxy = factory()->NewVariableProxy(flag);
- Expression* const0 = factory()->NewLiteral(smi0, RelocInfo::kNoPosition);
+ Expression* const0 =
+ factory()->NewNumberLiteral(smi0, RelocInfo::kNoPosition);
Assignment* assignment = factory()->NewAssignment(
Token::ASSIGN, flag_proxy, const0, RelocInfo::kNoPosition);
clear_flag = factory()->NewExpressionStatement(assignment, pos);
@@ -3224,7 +3226,9 @@ void Parser::ReportInvalidCachedData(Handle<String> name, bool* ok) {
bool CompileTimeValue::IsCompileTimeValue(Expression* expression) {
- if (expression->AsLiteral() != NULL) return true;
+ if (expression->AsAnyLiteral() != NULL) {
+ return true;
+ }
MaterializedLiteral* lit = expression->AsMaterializedLiteral();
return lit != NULL && lit->is_simple();
}
« no previous file with comments | « src/mips/full-codegen-mips.cc ('k') | src/preparser.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698