| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 193 } | 193 } |
| 194 | 194 |
| 195 | 195 |
| 196 void PrettyPrinter::VisitSwitchStatement(SwitchStatement* node) { | 196 void PrettyPrinter::VisitSwitchStatement(SwitchStatement* node) { |
| 197 PrintLabels(node->labels()); | 197 PrintLabels(node->labels()); |
| 198 Print("switch ("); | 198 Print("switch ("); |
| 199 Visit(node->tag()); | 199 Visit(node->tag()); |
| 200 Print(") { "); | 200 Print(") { "); |
| 201 ZoneList<CaseClause*>* cases = node->cases(); | 201 ZoneList<CaseClause*>* cases = node->cases(); |
| 202 for (int i = 0; i < cases->length(); i++) | 202 for (int i = 0; i < cases->length(); i++) |
| 203 PrintCaseClause(cases->at(i)); | 203 Visit(cases->at(i)); |
| 204 Print("}"); | 204 Print("}"); |
| 205 } | 205 } |
| 206 | 206 |
| 207 | 207 |
| 208 void PrettyPrinter::VisitCaseClause(CaseClause* clause) { |
| 209 if (clause->is_default()) { |
| 210 Print("default"); |
| 211 } else { |
| 212 Print("case "); |
| 213 Visit(clause->label()); |
| 214 } |
| 215 Print(": "); |
| 216 PrintStatements(clause->statements()); |
| 217 if (clause->statements()->length() > 0) |
| 218 Print(" "); |
| 219 } |
| 220 |
| 221 |
| 208 void PrettyPrinter::VisitDoWhileStatement(DoWhileStatement* node) { | 222 void PrettyPrinter::VisitDoWhileStatement(DoWhileStatement* node) { |
| 209 PrintLabels(node->labels()); | 223 PrintLabels(node->labels()); |
| 210 Print("do "); | 224 Print("do "); |
| 211 Visit(node->body()); | 225 Visit(node->body()); |
| 212 Print(" while ("); | 226 Print(" while ("); |
| 213 Visit(node->cond()); | 227 Visit(node->cond()); |
| 214 Print(");"); | 228 Print(");"); |
| 215 } | 229 } |
| 216 | 230 |
| 217 | 231 |
| (...skipping 395 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 613 Print("function "); | 627 Print("function "); |
| 614 PrintLiteral(function->name(), false); | 628 PrintLiteral(function->name(), false); |
| 615 PrintParameters(function->scope()); | 629 PrintParameters(function->scope()); |
| 616 Print(" { "); | 630 Print(" { "); |
| 617 PrintDeclarations(function->scope()->declarations()); | 631 PrintDeclarations(function->scope()->declarations()); |
| 618 PrintStatements(function->body()); | 632 PrintStatements(function->body()); |
| 619 Print(" }"); | 633 Print(" }"); |
| 620 } | 634 } |
| 621 | 635 |
| 622 | 636 |
| 623 void PrettyPrinter::PrintCaseClause(CaseClause* clause) { | |
| 624 if (clause->is_default()) { | |
| 625 Print("default"); | |
| 626 } else { | |
| 627 Print("case "); | |
| 628 Visit(clause->label()); | |
| 629 } | |
| 630 Print(": "); | |
| 631 PrintStatements(clause->statements()); | |
| 632 if (clause->statements()->length() > 0) | |
| 633 Print(" "); | |
| 634 } | |
| 635 | |
| 636 | |
| 637 //----------------------------------------------------------------------------- | 637 //----------------------------------------------------------------------------- |
| 638 | 638 |
| 639 class IndentedScope BASE_EMBEDDED { | 639 class IndentedScope BASE_EMBEDDED { |
| 640 public: | 640 public: |
| 641 IndentedScope(AstPrinter* printer, const char* txt) | 641 IndentedScope(AstPrinter* printer, const char* txt) |
| 642 : ast_printer_(printer) { | 642 : ast_printer_(printer) { |
| 643 ast_printer_->PrintIndented(txt); | 643 ast_printer_->PrintIndented(txt); |
| 644 ast_printer_->Print("\n"); | 644 ast_printer_->Print("\n"); |
| 645 ast_printer_->inc_indent(); | 645 ast_printer_->inc_indent(); |
| 646 } | 646 } |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 754 } | 754 } |
| 755 | 755 |
| 756 | 756 |
| 757 void AstPrinter::PrintArguments(ZoneList<Expression*>* arguments) { | 757 void AstPrinter::PrintArguments(ZoneList<Expression*>* arguments) { |
| 758 for (int i = 0; i < arguments->length(); i++) { | 758 for (int i = 0; i < arguments->length(); i++) { |
| 759 Visit(arguments->at(i)); | 759 Visit(arguments->at(i)); |
| 760 } | 760 } |
| 761 } | 761 } |
| 762 | 762 |
| 763 | 763 |
| 764 void AstPrinter::PrintCaseClause(CaseClause* clause) { | |
| 765 if (clause->is_default()) { | |
| 766 IndentedScope indent(this, "DEFAULT"); | |
| 767 PrintStatements(clause->statements()); | |
| 768 } else { | |
| 769 IndentedScope indent(this, "CASE"); | |
| 770 Visit(clause->label()); | |
| 771 PrintStatements(clause->statements()); | |
| 772 } | |
| 773 } | |
| 774 | |
| 775 | |
| 776 void AstPrinter::VisitBlock(Block* node) { | 764 void AstPrinter::VisitBlock(Block* node) { |
| 777 const char* block_txt = node->is_initializer_block() ? "BLOCK INIT" : "BLOCK"; | 765 const char* block_txt = node->is_initializer_block() ? "BLOCK INIT" : "BLOCK"; |
| 778 IndentedScope indent(this, block_txt); | 766 IndentedScope indent(this, block_txt); |
| 779 PrintStatements(node->statements()); | 767 PrintStatements(node->statements()); |
| 780 } | 768 } |
| 781 | 769 |
| 782 | 770 |
| 783 // TODO(svenpanne) Start with IndentedScope. | 771 // TODO(svenpanne) Start with IndentedScope. |
| 784 void AstPrinter::VisitVariableDeclaration(VariableDeclaration* node) { | 772 void AstPrinter::VisitVariableDeclaration(VariableDeclaration* node) { |
| 785 PrintLiteralWithModeIndented(Variable::Mode2String(node->mode()), | 773 PrintLiteralWithModeIndented(Variable::Mode2String(node->mode()), |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 893 PrintIndentedVisit("OBJECT", node->expression()); | 881 PrintIndentedVisit("OBJECT", node->expression()); |
| 894 PrintIndentedVisit("BODY", node->statement()); | 882 PrintIndentedVisit("BODY", node->statement()); |
| 895 } | 883 } |
| 896 | 884 |
| 897 | 885 |
| 898 void AstPrinter::VisitSwitchStatement(SwitchStatement* node) { | 886 void AstPrinter::VisitSwitchStatement(SwitchStatement* node) { |
| 899 IndentedScope indent(this, "SWITCH"); | 887 IndentedScope indent(this, "SWITCH"); |
| 900 PrintLabelsIndented(node->labels()); | 888 PrintLabelsIndented(node->labels()); |
| 901 PrintIndentedVisit("TAG", node->tag()); | 889 PrintIndentedVisit("TAG", node->tag()); |
| 902 for (int i = 0; i < node->cases()->length(); i++) { | 890 for (int i = 0; i < node->cases()->length(); i++) { |
| 903 PrintCaseClause(node->cases()->at(i)); | 891 Visit(node->cases()->at(i)); |
| 904 } | 892 } |
| 905 } | 893 } |
| 906 | 894 |
| 895 |
| 896 void AstPrinter::VisitCaseClause(CaseClause* clause) { |
| 897 if (clause->is_default()) { |
| 898 IndentedScope indent(this, "DEFAULT"); |
| 899 PrintStatements(clause->statements()); |
| 900 } else { |
| 901 IndentedScope indent(this, "CASE"); |
| 902 Visit(clause->label()); |
| 903 PrintStatements(clause->statements()); |
| 904 } |
| 905 } |
| 906 |
| 907 | 907 |
| 908 void AstPrinter::VisitDoWhileStatement(DoWhileStatement* node) { | 908 void AstPrinter::VisitDoWhileStatement(DoWhileStatement* node) { |
| 909 IndentedScope indent(this, "DO"); | 909 IndentedScope indent(this, "DO"); |
| 910 PrintLabelsIndented(node->labels()); | 910 PrintLabelsIndented(node->labels()); |
| 911 PrintIndentedVisit("BODY", node->body()); | 911 PrintIndentedVisit("BODY", node->body()); |
| 912 PrintIndentedVisit("COND", node->cond()); | 912 PrintIndentedVisit("COND", node->cond()); |
| 913 } | 913 } |
| 914 | 914 |
| 915 | 915 |
| 916 void AstPrinter::VisitWhileStatement(WhileStatement* node) { | 916 void AstPrinter::VisitWhileStatement(WhileStatement* node) { |
| (...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1158 } | 1158 } |
| 1159 | 1159 |
| 1160 | 1160 |
| 1161 void AstPrinter::VisitThisFunction(ThisFunction* node) { | 1161 void AstPrinter::VisitThisFunction(ThisFunction* node) { |
| 1162 IndentedScope indent(this, "THIS-FUNCTION"); | 1162 IndentedScope indent(this, "THIS-FUNCTION"); |
| 1163 } | 1163 } |
| 1164 | 1164 |
| 1165 #endif // DEBUG | 1165 #endif // DEBUG |
| 1166 | 1166 |
| 1167 } } // namespace v8::internal | 1167 } } // namespace v8::internal |
| OLD | NEW |