Consistently start (almost) all AstPrinter::VisitFoo functions with IndentedScope.

This makes IndentedScope the single point where we can print additional info in
the future, like e.g. AST IDs (at least when the TODOs are fixed). Minor other
cleanups.

R=mvstanton@chromium.org

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

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@14592 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
This commit is contained in:
svenpanne@chromium.org 2013-05-08 13:24:45 +00:00
parent 2bb4603cb1
commit bd8df839c6
2 changed files with 41 additions and 35 deletions

View File

@ -628,10 +628,6 @@ void PrettyPrinter::PrintCaseClause(CaseClause* clause) {
class IndentedScope BASE_EMBEDDED {
public:
explicit IndentedScope(AstPrinter* printer) : ast_printer_(printer) {
ast_printer_->inc_indent();
}
IndentedScope(AstPrinter* printer, const char* txt)
: ast_printer_(printer) {
ast_printer_->PrintIndented(txt);
@ -693,16 +689,11 @@ void AstPrinter::PrintLiteralWithModeIndented(const char* info,
}
void AstPrinter::PrintLabelsIndented(const char* info, ZoneStringList* labels) {
if (labels != NULL && labels->length() > 0) {
PrintIndented(info == NULL ? "LABELS" : info);
Print(" ");
void AstPrinter::PrintLabelsIndented(ZoneStringList* labels) {
if (labels == NULL || labels->length() == 0) return;
PrintIndented("LABELS ");
PrintLabels(labels);
Print("\n");
} else if (info != NULL) {
PrintIndented(info);
Print("\n");
}
}
@ -779,6 +770,7 @@ void AstPrinter::VisitBlock(Block* node) {
}
// TODO(svenpanne) Start with IndentedScope.
void AstPrinter::VisitVariableDeclaration(VariableDeclaration* node) {
PrintLiteralWithModeIndented(Variable::Mode2String(node->mode()),
node->proxy()->var(),
@ -786,6 +778,7 @@ void AstPrinter::VisitVariableDeclaration(VariableDeclaration* node) {
}
// TODO(svenpanne) Start with IndentedScope.
void AstPrinter::VisitFunctionDeclaration(FunctionDeclaration* node) {
PrintIndented("FUNCTION ");
PrintLiteral(node->proxy()->name(), true);
@ -816,19 +809,21 @@ void AstPrinter::VisitExportDeclaration(ExportDeclaration* node) {
void AstPrinter::VisitModuleLiteral(ModuleLiteral* node) {
IndentedScope indent(this, "MODULE LITERAL");
VisitBlock(node->body());
}
void AstPrinter::VisitModuleVariable(ModuleVariable* node) {
IndentedScope indent(this, "MODULE VARIABLE");
Visit(node->proxy());
}
void AstPrinter::VisitModulePath(ModulePath* node) {
IndentedScope indent(this, "PATH");
PrintIndentedVisit("MODULE", node->module());
PrintLiteralIndented("NAME", node->name(), false);
IndentedScope indent(this, "MODULE PATH");
PrintIndentedVisit("MODULE PATH PARENT", node->module());
PrintLiteralIndented("NAME", node->name(), true);
}
@ -838,24 +833,26 @@ void AstPrinter::VisitModuleUrl(ModuleUrl* node) {
void AstPrinter::VisitModuleStatement(ModuleStatement* node) {
IndentedScope indent(this, "MODULE");
IndentedScope indent(this, "MODULE STATEMENT");
PrintLiteralIndented("NAME", node->proxy()->name(), true);
PrintStatements(node->body()->statements());
}
void AstPrinter::VisitExpressionStatement(ExpressionStatement* node) {
IndentedScope indent(this, "EXPRESSION STATEMENT");
Visit(node->expression());
}
void AstPrinter::VisitEmptyStatement(EmptyStatement* node) {
PrintIndented("EMPTY\n");
IndentedScope indent(this, "EMPTY");
}
void AstPrinter::VisitIfStatement(IfStatement* node) {
PrintIndentedVisit("IF", node->condition());
IndentedScope indent(this, "IF");
PrintIndentedVisit("CONDITION", node->condition());
PrintIndentedVisit("THEN", node->then_statement());
if (node->HasElseStatement()) {
PrintIndentedVisit("ELSE", node->else_statement());
@ -864,17 +861,20 @@ void AstPrinter::VisitIfStatement(IfStatement* node) {
void AstPrinter::VisitContinueStatement(ContinueStatement* node) {
PrintLabelsIndented("CONTINUE", node->target()->labels());
IndentedScope indent(this, "CONTINUE");
PrintLabelsIndented(node->target()->labels());
}
void AstPrinter::VisitBreakStatement(BreakStatement* node) {
PrintLabelsIndented("BREAK", node->target()->labels());
IndentedScope indent(this, "BREAK");
PrintLabelsIndented(node->target()->labels());
}
void AstPrinter::VisitReturnStatement(ReturnStatement* node) {
PrintIndentedVisit("RETURN", node->expression());
IndentedScope indent(this, "RETURN");
Visit(node->expression());
}
@ -887,7 +887,7 @@ void AstPrinter::VisitWithStatement(WithStatement* node) {
void AstPrinter::VisitSwitchStatement(SwitchStatement* node) {
IndentedScope indent(this, "SWITCH");
PrintLabelsIndented(NULL, node->labels());
PrintLabelsIndented(node->labels());
PrintIndentedVisit("TAG", node->tag());
for (int i = 0; i < node->cases()->length(); i++) {
PrintCaseClause(node->cases()->at(i));
@ -897,7 +897,7 @@ void AstPrinter::VisitSwitchStatement(SwitchStatement* node) {
void AstPrinter::VisitDoWhileStatement(DoWhileStatement* node) {
IndentedScope indent(this, "DO");
PrintLabelsIndented(NULL, node->labels());
PrintLabelsIndented(node->labels());
PrintIndentedVisit("BODY", node->body());
PrintIndentedVisit("COND", node->cond());
}
@ -905,7 +905,7 @@ void AstPrinter::VisitDoWhileStatement(DoWhileStatement* node) {
void AstPrinter::VisitWhileStatement(WhileStatement* node) {
IndentedScope indent(this, "WHILE");
PrintLabelsIndented(NULL, node->labels());
PrintLabelsIndented(node->labels());
PrintIndentedVisit("COND", node->cond());
PrintIndentedVisit("BODY", node->body());
}
@ -913,7 +913,7 @@ void AstPrinter::VisitWhileStatement(WhileStatement* node) {
void AstPrinter::VisitForStatement(ForStatement* node) {
IndentedScope indent(this, "FOR");
PrintLabelsIndented(NULL, node->labels());
PrintLabelsIndented(node->labels());
if (node->init()) PrintIndentedVisit("INIT", node->init());
if (node->cond()) PrintIndentedVisit("COND", node->cond());
PrintIndentedVisit("BODY", node->body());
@ -972,12 +972,13 @@ void AstPrinter::VisitSharedFunctionInfoLiteral(
void AstPrinter::VisitConditional(Conditional* node) {
IndentedScope indent(this, "CONDITIONAL");
PrintIndentedVisit("?", node->condition());
PrintIndentedVisit("CONDITION", node->condition());
PrintIndentedVisit("THEN", node->then_expression());
PrintIndentedVisit("ELSE", node->else_expression());
}
// TODO(svenpanne) Start with IndentedScope.
void AstPrinter::VisitLiteral(Literal* node) {
PrintLiteralIndented("LITERAL", node->handle(), true);
}
@ -1034,6 +1035,7 @@ void AstPrinter::VisitArrayLiteral(ArrayLiteral* node) {
}
// TODO(svenpanne) Start with IndentedScope.
void AstPrinter::VisitVariableProxy(VariableProxy* node) {
Variable* var = node->var();
EmbeddedVector<char, 128> buf;
@ -1066,12 +1068,14 @@ void AstPrinter::VisitAssignment(Assignment* node) {
void AstPrinter::VisitYield(Yield* node) {
PrintIndentedVisit("YIELD", node->expression());
IndentedScope indent(this, "YIELD");
Visit(node->expression());
}
void AstPrinter::VisitThrow(Throw* node) {
PrintIndentedVisit("THROW", node->exception());
IndentedScope indent(this, "THROW");
Visit(node->exception());
}
@ -1102,14 +1106,15 @@ void AstPrinter::VisitCallNew(CallNew* node) {
void AstPrinter::VisitCallRuntime(CallRuntime* node) {
PrintLiteralIndented("CALL RUNTIME ", node->name(), false);
IndentedScope indent(this);
IndentedScope indent(this, "CALL RUNTIME");
PrintLiteralIndented("NAME", node->name(), false);
PrintArguments(node->arguments());
}
void AstPrinter::VisitUnaryOperation(UnaryOperation* node) {
PrintIndentedVisit(Token::Name(node->op()), node->expression());
IndentedScope indent(this, Token::Name(node->op()));
Visit(node->expression());
}
@ -1117,7 +1122,8 @@ void AstPrinter::VisitCountOperation(CountOperation* node) {
EmbeddedVector<char, 128> buf;
OS::SNPrintF(buf, "%s %s", (node->is_prefix() ? "PRE" : "POST"),
Token::Name(node->op()));
PrintIndentedVisit(buf.start(), node->expression());
IndentedScope indent(this, buf.start());
Visit(node->expression());
}

View File

@ -106,7 +106,7 @@ class AstPrinter: public PrettyPrinter {
void PrintLiteralWithModeIndented(const char* info,
Variable* var,
Handle<Object> value);
void PrintLabelsIndented(const char* info, ZoneStringList* labels);
void PrintLabelsIndented(ZoneStringList* labels);
void inc_indent() { indent_++; }
void dec_indent() { indent_--; }