summaryrefslogtreecommitdiff
path: root/deps/v8/src/prettyprinter.cc
diff options
context:
space:
mode:
authorRyan Dahl <ry@tinyclouds.org>2011-06-29 17:26:51 +0200
committerRyan Dahl <ry@tinyclouds.org>2011-06-29 17:26:51 +0200
commit33af2720f26c2b25bc7f75ce7eb454ff99db6d35 (patch)
tree9a38f0c96420edf503eebd6325dd8d2d8249f653 /deps/v8/src/prettyprinter.cc
parent6afdca885adeeeed9eef8cbb01c3d97af0bc084d (diff)
downloadnode-new-33af2720f26c2b25bc7f75ce7eb454ff99db6d35.tar.gz
Upgrade V8 to 3.4.8
Diffstat (limited to 'deps/v8/src/prettyprinter.cc')
-rw-r--r--deps/v8/src/prettyprinter.cc220
1 files changed, 77 insertions, 143 deletions
diff --git a/deps/v8/src/prettyprinter.cc b/deps/v8/src/prettyprinter.cc
index dda7abbb3f..cd38d1334c 100644
--- a/deps/v8/src/prettyprinter.cc
+++ b/deps/v8/src/prettyprinter.cc
@@ -1,4 +1,4 @@
-// Copyright 2006-2008 the V8 project authors. All rights reserved.
+// Copyright 2011 the V8 project authors. All rights reserved.
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
@@ -123,15 +123,16 @@ void PrettyPrinter::VisitReturnStatement(ReturnStatement* node) {
}
-void PrettyPrinter::VisitWithEnterStatement(WithEnterStatement* node) {
- Print("<enter with> (");
+void PrettyPrinter::VisitEnterWithContextStatement(
+ EnterWithContextStatement* node) {
+ Print("<enter with context> (");
Visit(node->expression());
Print(") ");
}
-void PrettyPrinter::VisitWithExitStatement(WithExitStatement* node) {
- Print("<exit with>");
+void PrettyPrinter::VisitExitContextStatement(ExitContextStatement* node) {
+ Print("<exit context>");
}
@@ -201,7 +202,8 @@ void PrettyPrinter::VisitTryCatchStatement(TryCatchStatement* node) {
Print("try ");
Visit(node->try_block());
Print(" catch (");
- Visit(node->catch_var());
+ const bool quote = false;
+ PrintLiteral(node->name(), quote);
Print(") ");
Visit(node->catch_block());
}
@@ -282,15 +284,6 @@ void PrettyPrinter::VisitArrayLiteral(ArrayLiteral* node) {
}
-void PrettyPrinter::VisitCatchExtensionObject(CatchExtensionObject* node) {
- Print("{ ");
- Visit(node->key());
- Print(": ");
- Visit(node->value());
- Print(" }");
-}
-
-
void PrettyPrinter::VisitSlot(Slot* node) {
switch (node->type()) {
case Slot::PARAMETER:
@@ -370,17 +363,15 @@ void PrettyPrinter::VisitCallRuntime(CallRuntime* node) {
void PrettyPrinter::VisitUnaryOperation(UnaryOperation* node) {
- Print("(%s", Token::String(node->op()));
+ Token::Value op = node->op();
+ bool needsSpace =
+ op == Token::DELETE || op == Token::TYPEOF || op == Token::VOID;
+ Print("(%s%s", Token::String(op), needsSpace ? " " : "");
Visit(node->expression());
Print(")");
}
-void PrettyPrinter::VisitIncrementOperation(IncrementOperation* node) {
- UNREACHABLE();
-}
-
-
void PrettyPrinter::VisitCountOperation(CountOperation* node) {
Print("(");
if (node->is_prefix()) Print("%s", Token::String(node->op()));
@@ -393,7 +384,7 @@ void PrettyPrinter::VisitCountOperation(CountOperation* node) {
void PrettyPrinter::VisitBinaryOperation(BinaryOperation* node) {
Print("(");
Visit(node->left());
- Print("%s", Token::String(node->op()));
+ Print(" %s ", Token::String(node->op()));
Visit(node->right());
Print(")");
}
@@ -402,7 +393,7 @@ void PrettyPrinter::VisitBinaryOperation(BinaryOperation* node) {
void PrettyPrinter::VisitCompareOperation(CompareOperation* node) {
Print("(");
Visit(node->left());
- Print("%s", Token::String(node->op()));
+ Print(" %s ", Token::String(node->op()));
Visit(node->right());
Print(")");
}
@@ -526,13 +517,13 @@ void PrettyPrinter::PrintLiteral(Handle<Object> value, bool quote) {
Print("%c", string->Get(i));
}
if (quote) Print("\"");
- } else if (object == Heap::null_value()) {
+ } else if (object->IsNull()) {
Print("null");
- } else if (object == Heap::true_value()) {
+ } else if (object->IsTrue()) {
Print("true");
- } else if (object == Heap::false_value()) {
+ } else if (object->IsFalse()) {
Print("false");
- } else if (object == Heap::undefined_value()) {
+ } else if (object->IsUndefined()) {
Print("undefined");
} else if (object->IsNumber()) {
Print("%g", object->Number());
@@ -602,22 +593,13 @@ void PrettyPrinter::PrintCaseClause(CaseClause* clause) {
class IndentedScope BASE_EMBEDDED {
public:
- IndentedScope() {
+ explicit IndentedScope(AstPrinter* printer) : ast_printer_(printer) {
ast_printer_->inc_indent();
}
- explicit IndentedScope(const char* txt, AstNode* node = NULL) {
+ IndentedScope(AstPrinter* printer, const char* txt, AstNode* node = NULL)
+ : ast_printer_(printer) {
ast_printer_->PrintIndented(txt);
- if (node != NULL && node->AsExpression() != NULL) {
- Expression* expr = node->AsExpression();
- bool printed_first = false;
- if ((expr->type() != NULL) && (expr->type()->IsKnown())) {
- ast_printer_->Print(" (type = ");
- ast_printer_->Print(StaticType::Type2String(expr->type()));
- printed_first = true;
- }
- if (printed_first) ast_printer_->Print(")");
- }
ast_printer_->Print("\n");
ast_printer_->inc_indent();
}
@@ -626,30 +608,20 @@ class IndentedScope BASE_EMBEDDED {
ast_printer_->dec_indent();
}
- static void SetAstPrinter(AstPrinter* a) { ast_printer_ = a; }
-
private:
- static AstPrinter* ast_printer_;
+ AstPrinter* ast_printer_;
};
-AstPrinter* IndentedScope::ast_printer_ = NULL;
-
-
//-----------------------------------------------------------------------------
-int AstPrinter::indent_ = 0;
-
-AstPrinter::AstPrinter() {
- ASSERT(indent_ == 0);
- IndentedScope::SetAstPrinter(this);
+AstPrinter::AstPrinter() : indent_(0) {
}
AstPrinter::~AstPrinter() {
ASSERT(indent_ == 0);
- IndentedScope::SetAstPrinter(NULL);
}
@@ -673,18 +645,13 @@ void AstPrinter::PrintLiteralIndented(const char* info,
void AstPrinter::PrintLiteralWithModeIndented(const char* info,
Variable* var,
- Handle<Object> value,
- StaticType* type) {
+ Handle<Object> value) {
if (var == NULL) {
PrintLiteralIndented(info, value, true);
} else {
EmbeddedVector<char, 256> buf;
int pos = OS::SNPrintF(buf, "%s (mode = %s", info,
Variable::Mode2String(var->mode()));
- if (type->IsKnown()) {
- pos += OS::SNPrintF(buf + pos, ", type = %s",
- StaticType::Type2String(type));
- }
OS::SNPrintF(buf + pos, ")");
PrintLiteralIndented(buf.start(), value, true);
}
@@ -708,14 +675,14 @@ void AstPrinter::PrintLabelsIndented(const char* info, ZoneStringList* labels) {
void AstPrinter::PrintIndentedVisit(const char* s, AstNode* node) {
- IndentedScope indent(s, node);
+ IndentedScope indent(this, s, node);
Visit(node);
}
const char* AstPrinter::PrintProgram(FunctionLiteral* program) {
Init();
- { IndentedScope indent("FUNC");
+ { IndentedScope indent(this, "FUNC");
PrintLiteralIndented("NAME", program->name(), true);
PrintLiteralIndented("INFERRED NAME", program->inferred_name(), true);
PrintParameters(program->scope());
@@ -728,7 +695,7 @@ const char* AstPrinter::PrintProgram(FunctionLiteral* program) {
void AstPrinter::PrintDeclarations(ZoneList<Declaration*>* declarations) {
if (declarations->length() > 0) {
- IndentedScope indent("DECLS");
+ IndentedScope indent(this, "DECLS");
for (int i = 0; i < declarations->length(); i++) {
Visit(declarations->at(i));
}
@@ -738,11 +705,10 @@ void AstPrinter::PrintDeclarations(ZoneList<Declaration*>* declarations) {
void AstPrinter::PrintParameters(Scope* scope) {
if (scope->num_parameters() > 0) {
- IndentedScope indent("PARAMS");
+ IndentedScope indent(this, "PARAMS");
for (int i = 0; i < scope->num_parameters(); i++) {
PrintLiteralWithModeIndented("VAR", scope->parameter(i),
- scope->parameter(i)->name(),
- scope->parameter(i)->type());
+ scope->parameter(i)->name());
}
}
}
@@ -764,10 +730,10 @@ void AstPrinter::PrintArguments(ZoneList<Expression*>* arguments) {
void AstPrinter::PrintCaseClause(CaseClause* clause) {
if (clause->is_default()) {
- IndentedScope indent("DEFAULT");
+ IndentedScope indent(this, "DEFAULT");
PrintStatements(clause->statements());
} else {
- IndentedScope indent("CASE");
+ IndentedScope indent(this, "CASE");
Visit(clause->label());
PrintStatements(clause->statements());
}
@@ -776,7 +742,7 @@ void AstPrinter::PrintCaseClause(CaseClause* clause) {
void AstPrinter::VisitBlock(Block* node) {
const char* block_txt = node->is_initializer_block() ? "BLOCK INIT" : "BLOCK";
- IndentedScope indent(block_txt);
+ IndentedScope indent(this, block_txt);
PrintStatements(node->statements());
}
@@ -786,8 +752,7 @@ void AstPrinter::VisitDeclaration(Declaration* node) {
// var or const declarations
PrintLiteralWithModeIndented(Variable::Mode2String(node->mode()),
node->proxy()->AsVariable(),
- node->proxy()->name(),
- node->proxy()->AsVariable()->type());
+ node->proxy()->name());
} else {
// function declarations
PrintIndented("FUNCTION ");
@@ -833,18 +798,19 @@ void AstPrinter::VisitReturnStatement(ReturnStatement* node) {
}
-void AstPrinter::VisitWithEnterStatement(WithEnterStatement* node) {
- PrintIndentedVisit("WITH ENTER", node->expression());
+void AstPrinter::VisitEnterWithContextStatement(
+ EnterWithContextStatement* node) {
+ PrintIndentedVisit("ENTER WITH CONTEXT", node->expression());
}
-void AstPrinter::VisitWithExitStatement(WithExitStatement* node) {
- PrintIndented("WITH EXIT\n");
+void AstPrinter::VisitExitContextStatement(ExitContextStatement* node) {
+ PrintIndented("EXIT CONTEXT\n");
}
void AstPrinter::VisitSwitchStatement(SwitchStatement* node) {
- IndentedScope indent("SWITCH");
+ IndentedScope indent(this, "SWITCH");
PrintLabelsIndented(NULL, node->labels());
PrintIndentedVisit("TAG", node->tag());
for (int i = 0; i < node->cases()->length(); i++) {
@@ -854,7 +820,7 @@ void AstPrinter::VisitSwitchStatement(SwitchStatement* node) {
void AstPrinter::VisitDoWhileStatement(DoWhileStatement* node) {
- IndentedScope indent("DO");
+ IndentedScope indent(this, "DO");
PrintLabelsIndented(NULL, node->labels());
PrintIndentedVisit("BODY", node->body());
PrintIndentedVisit("COND", node->cond());
@@ -862,7 +828,7 @@ void AstPrinter::VisitDoWhileStatement(DoWhileStatement* node) {
void AstPrinter::VisitWhileStatement(WhileStatement* node) {
- IndentedScope indent("WHILE");
+ IndentedScope indent(this, "WHILE");
PrintLabelsIndented(NULL, node->labels());
PrintIndentedVisit("COND", node->cond());
PrintIndentedVisit("BODY", node->body());
@@ -870,7 +836,7 @@ void AstPrinter::VisitWhileStatement(WhileStatement* node) {
void AstPrinter::VisitForStatement(ForStatement* node) {
- IndentedScope indent("FOR");
+ IndentedScope indent(this, "FOR");
PrintLabelsIndented(NULL, node->labels());
if (node->init()) PrintIndentedVisit("INIT", node->init());
if (node->cond()) PrintIndentedVisit("COND", node->cond());
@@ -880,7 +846,7 @@ void AstPrinter::VisitForStatement(ForStatement* node) {
void AstPrinter::VisitForInStatement(ForInStatement* node) {
- IndentedScope indent("FOR IN");
+ IndentedScope indent(this, "FOR IN");
PrintIndentedVisit("FOR", node->each());
PrintIndentedVisit("IN", node->enumerable());
PrintIndentedVisit("BODY", node->body());
@@ -888,27 +854,28 @@ void AstPrinter::VisitForInStatement(ForInStatement* node) {
void AstPrinter::VisitTryCatchStatement(TryCatchStatement* node) {
- IndentedScope indent("TRY CATCH");
+ IndentedScope indent(this, "TRY CATCH");
PrintIndentedVisit("TRY", node->try_block());
- PrintIndentedVisit("CATCHVAR", node->catch_var());
+ const bool quote = false;
+ PrintLiteralIndented("CATCHVAR", node->name(), quote);
PrintIndentedVisit("CATCH", node->catch_block());
}
void AstPrinter::VisitTryFinallyStatement(TryFinallyStatement* node) {
- IndentedScope indent("TRY FINALLY");
+ IndentedScope indent(this, "TRY FINALLY");
PrintIndentedVisit("TRY", node->try_block());
PrintIndentedVisit("FINALLY", node->finally_block());
}
void AstPrinter::VisitDebuggerStatement(DebuggerStatement* node) {
- IndentedScope indent("DEBUGGER");
+ IndentedScope indent(this, "DEBUGGER");
}
void AstPrinter::VisitFunctionLiteral(FunctionLiteral* node) {
- IndentedScope indent("FUNC LITERAL");
+ IndentedScope indent(this, "FUNC LITERAL");
PrintLiteralIndented("NAME", node->name(), false);
PrintLiteralIndented("INFERRED NAME", node->inferred_name(), false);
PrintParameters(node->scope());
@@ -921,13 +888,13 @@ void AstPrinter::VisitFunctionLiteral(FunctionLiteral* node) {
void AstPrinter::VisitSharedFunctionInfoLiteral(
SharedFunctionInfoLiteral* node) {
- IndentedScope indent("FUNC LITERAL");
+ IndentedScope indent(this, "FUNC LITERAL");
PrintLiteralIndented("SHARED INFO", node->shared_function_info(), true);
}
void AstPrinter::VisitConditional(Conditional* node) {
- IndentedScope indent("CONDITIONAL");
+ IndentedScope indent(this, "CONDITIONAL");
PrintIndentedVisit("?", node->condition());
PrintIndentedVisit("THEN", node->then_expression());
PrintIndentedVisit("ELSE", node->else_expression());
@@ -940,14 +907,14 @@ void AstPrinter::VisitLiteral(Literal* node) {
void AstPrinter::VisitRegExpLiteral(RegExpLiteral* node) {
- IndentedScope indent("REGEXP LITERAL");
+ IndentedScope indent(this, "REGEXP LITERAL");
PrintLiteralIndented("PATTERN", node->pattern(), false);
PrintLiteralIndented("FLAGS", node->flags(), false);
}
void AstPrinter::VisitObjectLiteral(ObjectLiteral* node) {
- IndentedScope indent("OBJ LITERAL");
+ IndentedScope indent(this, "OBJ LITERAL");
for (int i = 0; i < node->properties()->length(); i++) {
const char* prop_kind = NULL;
switch (node->properties()->at(i)->kind()) {
@@ -972,7 +939,7 @@ void AstPrinter::VisitObjectLiteral(ObjectLiteral* node) {
default:
UNREACHABLE();
}
- IndentedScope prop(prop_kind);
+ IndentedScope prop(this, prop_kind);
PrintIndentedVisit("KEY", node->properties()->at(i)->key());
PrintIndentedVisit("VALUE", node->properties()->at(i)->value());
}
@@ -980,9 +947,9 @@ void AstPrinter::VisitObjectLiteral(ObjectLiteral* node) {
void AstPrinter::VisitArrayLiteral(ArrayLiteral* node) {
- IndentedScope indent("ARRAY LITERAL");
+ IndentedScope indent(this, "ARRAY LITERAL");
if (node->values()->length() > 0) {
- IndentedScope indent("VALUES");
+ IndentedScope indent(this, "VALUES");
for (int i = 0; i < node->values()->length(); i++) {
Visit(node->values()->at(i));
}
@@ -990,13 +957,6 @@ void AstPrinter::VisitArrayLiteral(ArrayLiteral* node) {
}
-void AstPrinter::VisitCatchExtensionObject(CatchExtensionObject* node) {
- IndentedScope indent("CatchExtensionObject");
- PrintIndentedVisit("KEY", node->key());
- PrintIndentedVisit("VALUE", node->value());
-}
-
-
void AstPrinter::VisitSlot(Slot* node) {
PrintIndented("SLOT ");
PrettyPrinter::VisitSlot(node);
@@ -1005,18 +965,17 @@ void AstPrinter::VisitSlot(Slot* node) {
void AstPrinter::VisitVariableProxy(VariableProxy* node) {
- PrintLiteralWithModeIndented("VAR PROXY", node->AsVariable(), node->name(),
- node->type());
+ PrintLiteralWithModeIndented("VAR PROXY", node->AsVariable(), node->name());
Variable* var = node->var();
if (var != NULL && var->rewrite() != NULL) {
- IndentedScope indent;
+ IndentedScope indent(this);
Visit(var->rewrite());
}
}
void AstPrinter::VisitAssignment(Assignment* node) {
- IndentedScope indent(Token::Name(node->op()), node);
+ IndentedScope indent(this, Token::Name(node->op()), node);
Visit(node->target());
Visit(node->value());
}
@@ -1028,7 +987,7 @@ void AstPrinter::VisitThrow(Throw* node) {
void AstPrinter::VisitProperty(Property* node) {
- IndentedScope indent("PROPERTY", node);
+ IndentedScope indent(this, "PROPERTY", node);
Visit(node->obj());
Literal* literal = node->key()->AsLiteral();
if (literal != NULL && literal->handle()->IsSymbol()) {
@@ -1040,14 +999,14 @@ void AstPrinter::VisitProperty(Property* node) {
void AstPrinter::VisitCall(Call* node) {
- IndentedScope indent("CALL");
+ IndentedScope indent(this, "CALL");
Visit(node->expression());
PrintArguments(node->arguments());
}
void AstPrinter::VisitCallNew(CallNew* node) {
- IndentedScope indent("CALL NEW");
+ IndentedScope indent(this, "CALL NEW");
Visit(node->expression());
PrintArguments(node->arguments());
}
@@ -1055,7 +1014,7 @@ void AstPrinter::VisitCallNew(CallNew* node) {
void AstPrinter::VisitCallRuntime(CallRuntime* node) {
PrintLiteralIndented("CALL RUNTIME ", node->name(), false);
- IndentedScope indent;
+ IndentedScope indent(this);
PrintArguments(node->arguments());
}
@@ -1065,35 +1024,23 @@ void AstPrinter::VisitUnaryOperation(UnaryOperation* node) {
}
-void AstPrinter::VisitIncrementOperation(IncrementOperation* node) {
- UNREACHABLE();
-}
-
-
void AstPrinter::VisitCountOperation(CountOperation* node) {
EmbeddedVector<char, 128> buf;
- if (node->type()->IsKnown()) {
- OS::SNPrintF(buf, "%s %s (type = %s)",
- (node->is_prefix() ? "PRE" : "POST"),
- Token::Name(node->op()),
- StaticType::Type2String(node->type()));
- } else {
- OS::SNPrintF(buf, "%s %s", (node->is_prefix() ? "PRE" : "POST"),
- Token::Name(node->op()));
- }
+ OS::SNPrintF(buf, "%s %s", (node->is_prefix() ? "PRE" : "POST"),
+ Token::Name(node->op()));
PrintIndentedVisit(buf.start(), node->expression());
}
void AstPrinter::VisitBinaryOperation(BinaryOperation* node) {
- IndentedScope indent(Token::Name(node->op()), node);
+ IndentedScope indent(this, Token::Name(node->op()), node);
Visit(node->left());
Visit(node->right());
}
void AstPrinter::VisitCompareOperation(CompareOperation* node) {
- IndentedScope indent(Token::Name(node->op()), node);
+ IndentedScope indent(this, Token::Name(node->op()), node);
Visit(node->left());
Visit(node->right());
}
@@ -1103,13 +1050,13 @@ void AstPrinter::VisitCompareToNull(CompareToNull* node) {
const char* name = node->is_strict()
? "COMPARE-TO-NULL-STRICT"
: "COMPARE-TO-NULL";
- IndentedScope indent(name, node);
+ IndentedScope indent(this, name, node);
Visit(node->expression());
}
void AstPrinter::VisitThisFunction(ThisFunction* node) {
- IndentedScope indent("THIS-FUNCTION");
+ IndentedScope indent(this, "THIS-FUNCTION");
}
@@ -1246,14 +1193,15 @@ void JsonAstBuilder::VisitReturnStatement(ReturnStatement* stmt) {
}
-void JsonAstBuilder::VisitWithEnterStatement(WithEnterStatement* stmt) {
- TagScope tag(this, "WithEnterStatement");
+void JsonAstBuilder::VisitEnterWithContextStatement(
+ EnterWithContextStatement* stmt) {
+ TagScope tag(this, "EnterWithContextStatement");
Visit(stmt->expression());
}
-void JsonAstBuilder::VisitWithExitStatement(WithExitStatement* stmt) {
- TagScope tag(this, "WithExitStatement");
+void JsonAstBuilder::VisitExitContextStatement(ExitContextStatement* stmt) {
+ TagScope tag(this, "ExitContextStatement");
}
@@ -1295,8 +1243,10 @@ void JsonAstBuilder::VisitForInStatement(ForInStatement* stmt) {
void JsonAstBuilder::VisitTryCatchStatement(TryCatchStatement* stmt) {
TagScope tag(this, "TryCatchStatement");
+ { AttributesScope attributes(this);
+ AddAttribute("variable", stmt->name());
+ }
Visit(stmt->try_block());
- Visit(stmt->catch_var());
Visit(stmt->catch_block());
}
@@ -1401,13 +1351,6 @@ void JsonAstBuilder::VisitArrayLiteral(ArrayLiteral* expr) {
}
-void JsonAstBuilder::VisitCatchExtensionObject(CatchExtensionObject* expr) {
- TagScope tag(this, "CatchExtensionObject");
- Visit(expr->key());
- Visit(expr->value());
-}
-
-
void JsonAstBuilder::VisitAssignment(Assignment* expr) {
TagScope tag(this, "Assignment");
{
@@ -1427,10 +1370,6 @@ void JsonAstBuilder::VisitThrow(Throw* expr) {
void JsonAstBuilder::VisitProperty(Property* expr) {
TagScope tag(this, "Property");
- {
- AttributesScope attributes(this);
- AddAttribute("type", expr->is_synthetic() ? "SYNTHETIC" : "NORMAL");
- }
Visit(expr->obj());
Visit(expr->key());
}
@@ -1470,11 +1409,6 @@ void JsonAstBuilder::VisitUnaryOperation(UnaryOperation* expr) {
}
-void JsonAstBuilder::VisitIncrementOperation(IncrementOperation* expr) {
- UNREACHABLE();
-}
-
-
void JsonAstBuilder::VisitCountOperation(CountOperation* expr) {
TagScope tag(this, "CountOperation");
{