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 "src/v8.h" | 7 #include "src/v8.h" |
8 | 8 |
9 #include "src/ast-value-factory.h" | |
10 #include "src/prettyprinter.h" | 9 #include "src/prettyprinter.h" |
11 #include "src/scopes.h" | 10 #include "src/scopes.h" |
12 #include "src/platform.h" | 11 #include "src/platform.h" |
13 | 12 |
14 namespace v8 { | 13 namespace v8 { |
15 namespace internal { | 14 namespace internal { |
16 | 15 |
17 #ifdef DEBUG | 16 #ifdef DEBUG |
18 | 17 |
19 PrettyPrinter::PrettyPrinter(Zone* zone) { | 18 PrettyPrinter::PrettyPrinter(Zone* zone) { |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
127 Visit(node->then_statement()); | 126 Visit(node->then_statement()); |
128 if (node->HasElseStatement()) { | 127 if (node->HasElseStatement()) { |
129 Print(" else "); | 128 Print(" else "); |
130 Visit(node->else_statement()); | 129 Visit(node->else_statement()); |
131 } | 130 } |
132 } | 131 } |
133 | 132 |
134 | 133 |
135 void PrettyPrinter::VisitContinueStatement(ContinueStatement* node) { | 134 void PrettyPrinter::VisitContinueStatement(ContinueStatement* node) { |
136 Print("continue"); | 135 Print("continue"); |
137 ZoneList<const AstString*>* labels = node->target()->labels(); | 136 ZoneStringList* labels = node->target()->labels(); |
138 if (labels != NULL) { | 137 if (labels != NULL) { |
139 Print(" "); | 138 Print(" "); |
140 ASSERT(labels->length() > 0); // guaranteed to have at least one entry | 139 ASSERT(labels->length() > 0); // guaranteed to have at least one entry |
141 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 |
142 } | 141 } |
143 Print(";"); | 142 Print(";"); |
144 } | 143 } |
145 | 144 |
146 | 145 |
147 void PrettyPrinter::VisitBreakStatement(BreakStatement* node) { | 146 void PrettyPrinter::VisitBreakStatement(BreakStatement* node) { |
148 Print("break"); | 147 Print("break"); |
149 ZoneList<const AstString*>* labels = node->target()->labels(); | 148 ZoneStringList* labels = node->target()->labels(); |
150 if (labels != NULL) { | 149 if (labels != NULL) { |
151 Print(" "); | 150 Print(" "); |
152 ASSERT(labels->length() > 0); // guaranteed to have at least one entry | 151 ASSERT(labels->length() > 0); // guaranteed to have at least one entry |
153 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 |
154 } | 153 } |
155 Print(";"); | 154 Print(";"); |
156 } | 155 } |
157 | 156 |
158 | 157 |
159 void PrettyPrinter::VisitReturnStatement(ReturnStatement* node) { | 158 void PrettyPrinter::VisitReturnStatement(ReturnStatement* node) { |
(...skipping 358 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
518 | 517 |
519 void PrettyPrinter::PrintStatements(ZoneList<Statement*>* statements) { | 518 void PrettyPrinter::PrintStatements(ZoneList<Statement*>* statements) { |
520 if (statements == NULL) return; | 519 if (statements == NULL) return; |
521 for (int i = 0; i < statements->length(); i++) { | 520 for (int i = 0; i < statements->length(); i++) { |
522 if (i != 0) Print(" "); | 521 if (i != 0) Print(" "); |
523 Visit(statements->at(i)); | 522 Visit(statements->at(i)); |
524 } | 523 } |
525 } | 524 } |
526 | 525 |
527 | 526 |
528 void PrettyPrinter::PrintLabels(ZoneList<const AstString*>* labels) { | 527 void PrettyPrinter::PrintLabels(ZoneStringList* labels) { |
529 if (labels != NULL) { | 528 if (labels != NULL) { |
530 for (int i = 0; i < labels->length(); i++) { | 529 for (int i = 0; i < labels->length(); i++) { |
531 PrintLiteral(labels->at(i), false); | 530 PrintLiteral(labels->at(i), false); |
532 Print(": "); | 531 Print(": "); |
533 } | 532 } |
534 } | 533 } |
535 } | 534 } |
536 | 535 |
537 | 536 |
538 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... |
576 Print("?UNKNOWN?"); | 575 Print("?UNKNOWN?"); |
577 } | 576 } |
578 } else if (object->IsFixedArray()) { | 577 } else if (object->IsFixedArray()) { |
579 Print("FixedArray"); | 578 Print("FixedArray"); |
580 } else { | 579 } else { |
581 Print("<unknown literal %p>", object); | 580 Print("<unknown literal %p>", object); |
582 } | 581 } |
583 } | 582 } |
584 | 583 |
585 | 584 |
586 void PrettyPrinter::PrintLiteral(const AstString* value, bool quote) { | |
587 PrintLiteral(value->string(), quote); | |
588 } | |
589 | |
590 | |
591 void PrettyPrinter::PrintParameters(Scope* scope) { | 585 void PrettyPrinter::PrintParameters(Scope* scope) { |
592 Print("("); | 586 Print("("); |
593 for (int i = 0; i < scope->num_parameters(); i++) { | 587 for (int i = 0; i < scope->num_parameters(); i++) { |
594 if (i > 0) Print(", "); | 588 if (i > 0) Print(", "); |
595 PrintLiteral(scope->parameter(i)->name(), false); | 589 PrintLiteral(scope->parameter(i)->name(), false); |
596 } | 590 } |
597 Print(")"); | 591 Print(")"); |
598 } | 592 } |
599 | 593 |
600 | 594 |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
675 } else { | 669 } else { |
676 EmbeddedVector<char, 256> buf; | 670 EmbeddedVector<char, 256> buf; |
677 int pos = SNPrintF(buf, "%s (mode = %s", info, | 671 int pos = SNPrintF(buf, "%s (mode = %s", info, |
678 Variable::Mode2String(var->mode())); | 672 Variable::Mode2String(var->mode())); |
679 SNPrintF(buf + pos, ")"); | 673 SNPrintF(buf + pos, ")"); |
680 PrintLiteralIndented(buf.start(), value, true); | 674 PrintLiteralIndented(buf.start(), value, true); |
681 } | 675 } |
682 } | 676 } |
683 | 677 |
684 | 678 |
685 void AstPrinter::PrintLabelsIndented(ZoneList<const AstString*>* labels) { | 679 void AstPrinter::PrintLabelsIndented(ZoneStringList* labels) { |
686 if (labels == NULL || labels->length() == 0) return; | 680 if (labels == NULL || labels->length() == 0) return; |
687 PrintIndented("LABELS "); | 681 PrintIndented("LABELS "); |
688 PrintLabels(labels); | 682 PrintLabels(labels); |
689 Print("\n"); | 683 Print("\n"); |
690 } | 684 } |
691 | 685 |
692 | 686 |
693 void AstPrinter::PrintIndentedVisit(const char* s, AstNode* node) { | 687 void AstPrinter::PrintIndentedVisit(const char* s, AstNode* node) { |
694 IndentedScope indent(this, s); | 688 IndentedScope indent(this, s); |
695 Visit(node); | 689 Visit(node); |
(...skipping 445 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1141 } | 1135 } |
1142 | 1136 |
1143 | 1137 |
1144 void AstPrinter::VisitThisFunction(ThisFunction* node) { | 1138 void AstPrinter::VisitThisFunction(ThisFunction* node) { |
1145 IndentedScope indent(this, "THIS-FUNCTION"); | 1139 IndentedScope indent(this, "THIS-FUNCTION"); |
1146 } | 1140 } |
1147 | 1141 |
1148 #endif // DEBUG | 1142 #endif // DEBUG |
1149 | 1143 |
1150 } } // namespace v8::internal | 1144 } } // namespace v8::internal |
OLD | NEW |