| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <stdarg.h> | 5 #include <stdarg.h> |
| 6 | 6 |
| 7 #include "v8.h" | 7 #include "v8.h" |
| 8 | 8 |
| 9 #include "prettyprinter.h" | 9 #include "prettyprinter.h" |
| 10 #include "scopes.h" | 10 #include "scopes.h" |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 126 Visit(node->then_statement()); | 126 Visit(node->then_statement()); |
| 127 if (node->HasElseStatement()) { | 127 if (node->HasElseStatement()) { |
| 128 Print(" else "); | 128 Print(" else "); |
| 129 Visit(node->else_statement()); | 129 Visit(node->else_statement()); |
| 130 } | 130 } |
| 131 } | 131 } |
| 132 | 132 |
| 133 | 133 |
| 134 void PrettyPrinter::VisitContinueStatement(ContinueStatement* node) { | 134 void PrettyPrinter::VisitContinueStatement(ContinueStatement* node) { |
| 135 Print("continue"); | 135 Print("continue"); |
| 136 ZoneStringList* labels = node->target()->labels(); | 136 ZoneList<ParserSymbolTable::Symbol*>* labels = node->target()->labels(); |
| 137 if (labels != NULL) { | 137 if (labels != NULL) { |
| 138 Print(" "); | 138 Print(" "); |
| 139 ASSERT(labels->length() > 0); // guaranteed to have at least one entry | 139 ASSERT(labels->length() > 0); // guaranteed to have at least one entry |
| 140 PrintLiteral(labels->at(0), false); // any label from the list is fine | 140 PrintLiteral(labels->at(0), false); // any label from the list is fine |
| 141 } | 141 } |
| 142 Print(";"); | 142 Print(";"); |
| 143 } | 143 } |
| 144 | 144 |
| 145 | 145 |
| 146 void PrettyPrinter::VisitBreakStatement(BreakStatement* node) { | 146 void PrettyPrinter::VisitBreakStatement(BreakStatement* node) { |
| 147 Print("break"); | 147 Print("break"); |
| 148 ZoneStringList* labels = node->target()->labels(); | 148 ZoneList<ParserSymbolTable::Symbol*>* labels = node->target()->labels(); |
| 149 if (labels != NULL) { | 149 if (labels != NULL) { |
| 150 Print(" "); | 150 Print(" "); |
| 151 ASSERT(labels->length() > 0); // guaranteed to have at least one entry | 151 ASSERT(labels->length() > 0); // guaranteed to have at least one entry |
| 152 PrintLiteral(labels->at(0), false); // any label from the list is fine | 152 PrintLiteral(labels->at(0), false); // any label from the list is fine |
| 153 } | 153 } |
| 154 Print(";"); | 154 Print(";"); |
| 155 } | 155 } |
| 156 | 156 |
| 157 | 157 |
| 158 void PrettyPrinter::VisitReturnStatement(ReturnStatement* node) { | 158 void PrettyPrinter::VisitReturnStatement(ReturnStatement* node) { |
| (...skipping 358 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 517 | 517 |
| 518 void PrettyPrinter::PrintStatements(ZoneList<Statement*>* statements) { | 518 void PrettyPrinter::PrintStatements(ZoneList<Statement*>* statements) { |
| 519 if (statements == NULL) return; | 519 if (statements == NULL) return; |
| 520 for (int i = 0; i < statements->length(); i++) { | 520 for (int i = 0; i < statements->length(); i++) { |
| 521 if (i != 0) Print(" "); | 521 if (i != 0) Print(" "); |
| 522 Visit(statements->at(i)); | 522 Visit(statements->at(i)); |
| 523 } | 523 } |
| 524 } | 524 } |
| 525 | 525 |
| 526 | 526 |
| 527 void PrettyPrinter::PrintLabels(ZoneStringList* labels) { | 527 void PrettyPrinter::PrintLabels(ZoneList<ParserSymbolTable::Symbol*>* labels) { |
| 528 if (labels != NULL) { | 528 if (labels != NULL) { |
| 529 for (int i = 0; i < labels->length(); i++) { | 529 for (int i = 0; i < labels->length(); i++) { |
| 530 PrintLiteral(labels->at(i), false); | 530 PrintLiteral(labels->at(i), false); |
| 531 Print(": "); | 531 Print(": "); |
| 532 } | 532 } |
| 533 } | 533 } |
| 534 } | 534 } |
| 535 | 535 |
| 536 | 536 |
| 537 void PrettyPrinter::PrintArguments(ZoneList<Expression*>* arguments) { | 537 void PrettyPrinter::PrintArguments(ZoneList<Expression*>* arguments) { |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 575 Print("?UNKNOWN?"); | 575 Print("?UNKNOWN?"); |
| 576 } | 576 } |
| 577 } else if (object->IsFixedArray()) { | 577 } else if (object->IsFixedArray()) { |
| 578 Print("FixedArray"); | 578 Print("FixedArray"); |
| 579 } else { | 579 } else { |
| 580 Print("<unknown literal %p>", object); | 580 Print("<unknown literal %p>", object); |
| 581 } | 581 } |
| 582 } | 582 } |
| 583 | 583 |
| 584 | 584 |
| 585 void PrettyPrinter::PrintLiteral(ParserSymbolTable::Symbol* value, bool quote) { |
| 586 if (quote) Print("\""); |
| 587 Print("%.*s", value->literal_bytes.length(), value->literal_bytes.start()); |
| 588 if (quote) Print("\""); |
| 589 } |
| 590 |
| 591 |
| 585 void PrettyPrinter::PrintParameters(Scope* scope) { | 592 void PrettyPrinter::PrintParameters(Scope* scope) { |
| 586 Print("("); | 593 Print("("); |
| 587 for (int i = 0; i < scope->num_parameters(); i++) { | 594 for (int i = 0; i < scope->num_parameters(); i++) { |
| 588 if (i > 0) Print(", "); | 595 if (i > 0) Print(", "); |
| 589 PrintLiteral(scope->parameter(i)->name(), false); | 596 PrintLiteral(scope->parameter(i)->name(), false); |
| 590 } | 597 } |
| 591 Print(")"); | 598 Print(")"); |
| 592 } | 599 } |
| 593 | 600 |
| 594 | 601 |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 669 } else { | 676 } else { |
| 670 EmbeddedVector<char, 256> buf; | 677 EmbeddedVector<char, 256> buf; |
| 671 int pos = OS::SNPrintF(buf, "%s (mode = %s", info, | 678 int pos = OS::SNPrintF(buf, "%s (mode = %s", info, |
| 672 Variable::Mode2String(var->mode())); | 679 Variable::Mode2String(var->mode())); |
| 673 OS::SNPrintF(buf + pos, ")"); | 680 OS::SNPrintF(buf + pos, ")"); |
| 674 PrintLiteralIndented(buf.start(), value, true); | 681 PrintLiteralIndented(buf.start(), value, true); |
| 675 } | 682 } |
| 676 } | 683 } |
| 677 | 684 |
| 678 | 685 |
| 679 void AstPrinter::PrintLabelsIndented(ZoneStringList* labels) { | 686 void AstPrinter::PrintLabelsIndented(ZoneList<ParserSymbolTable::Symbol*>* label
s) { |
| 680 if (labels == NULL || labels->length() == 0) return; | 687 if (labels == NULL || labels->length() == 0) return; |
| 681 PrintIndented("LABELS "); | 688 PrintIndented("LABELS "); |
| 682 PrintLabels(labels); | 689 PrintLabels(labels); |
| 683 Print("\n"); | 690 Print("\n"); |
| 684 } | 691 } |
| 685 | 692 |
| 686 | 693 |
| 687 void AstPrinter::PrintIndentedVisit(const char* s, AstNode* node) { | 694 void AstPrinter::PrintIndentedVisit(const char* s, AstNode* node) { |
| 688 IndentedScope indent(this, s); | 695 IndentedScope indent(this, s); |
| 689 Visit(node); | 696 Visit(node); |
| (...skipping 445 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1135 } | 1142 } |
| 1136 | 1143 |
| 1137 | 1144 |
| 1138 void AstPrinter::VisitThisFunction(ThisFunction* node) { | 1145 void AstPrinter::VisitThisFunction(ThisFunction* node) { |
| 1139 IndentedScope indent(this, "THIS-FUNCTION"); | 1146 IndentedScope indent(this, "THIS-FUNCTION"); |
| 1140 } | 1147 } |
| 1141 | 1148 |
| 1142 #endif // DEBUG | 1149 #endif // DEBUG |
| 1143 | 1150 |
| 1144 } } // namespace v8::internal | 1151 } } // namespace v8::internal |
| OLD | NEW |