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