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 "src/prettyprinter.h" | 5 #include "src/prettyprinter.h" |
6 | 6 |
7 #include <stdarg.h> | 7 #include <stdarg.h> |
8 | 8 |
9 #include "src/ast-value-factory.h" | 9 #include "src/ast-value-factory.h" |
10 #include "src/base/platform/platform.h" | 10 #include "src/base/platform/platform.h" |
11 #include "src/scopes.h" | 11 #include "src/scopes.h" |
12 | 12 |
13 namespace v8 { | 13 namespace v8 { |
14 namespace internal { | 14 namespace internal { |
15 | 15 |
| 16 #define RETURN_IF_FIND_NODE(node) \ |
| 17 do { \ |
| 18 AstNode* tmp = node; \ |
| 19 if (tmp != nullptr) { \ |
| 20 Find(tmp); \ |
| 21 return; \ |
| 22 } \ |
| 23 } while (false) |
| 24 |
16 CallPrinter::CallPrinter(Isolate* isolate) { | 25 CallPrinter::CallPrinter(Isolate* isolate) { |
17 output_ = NULL; | 26 output_ = NULL; |
18 size_ = 0; | 27 size_ = 0; |
19 pos_ = 0; | 28 pos_ = 0; |
20 position_ = 0; | 29 position_ = 0; |
21 found_ = false; | 30 found_ = false; |
22 done_ = false; | 31 done_ = false; |
23 InitializeAstVisitor(isolate); | 32 InitializeAstVisitor(isolate); |
24 } | 33 } |
25 | 34 |
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
267 Print("]"); | 276 Print("]"); |
268 } | 277 } |
269 | 278 |
270 | 279 |
271 void CallPrinter::VisitVariableProxy(VariableProxy* node) { | 280 void CallPrinter::VisitVariableProxy(VariableProxy* node) { |
272 PrintLiteral(node->name(), false); | 281 PrintLiteral(node->name(), false); |
273 } | 282 } |
274 | 283 |
275 | 284 |
276 void CallPrinter::VisitAssignment(Assignment* node) { | 285 void CallPrinter::VisitAssignment(Assignment* node) { |
| 286 RETURN_IF_FIND_NODE(node->destructuring_assignment()); |
277 Find(node->target()); | 287 Find(node->target()); |
278 Find(node->value()); | 288 Find(node->value()); |
279 } | 289 } |
280 | 290 |
281 | 291 |
282 void CallPrinter::VisitYield(Yield* node) { Find(node->expression()); } | 292 void CallPrinter::VisitYield(Yield* node) { Find(node->expression()); } |
283 | 293 |
284 | 294 |
285 void CallPrinter::VisitThrow(Throw* node) { Find(node->exception()); } | 295 void CallPrinter::VisitThrow(Throw* node) { Find(node->exception()); } |
286 | 296 |
(...skipping 486 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
773 Print(" ]"); | 783 Print(" ]"); |
774 } | 784 } |
775 | 785 |
776 | 786 |
777 void PrettyPrinter::VisitVariableProxy(VariableProxy* node) { | 787 void PrettyPrinter::VisitVariableProxy(VariableProxy* node) { |
778 PrintLiteral(node->name(), false); | 788 PrintLiteral(node->name(), false); |
779 } | 789 } |
780 | 790 |
781 | 791 |
782 void PrettyPrinter::VisitAssignment(Assignment* node) { | 792 void PrettyPrinter::VisitAssignment(Assignment* node) { |
| 793 RETURN_IF_VISIT_NODE(node->destructuring_assignment()); |
783 Visit(node->target()); | 794 Visit(node->target()); |
784 Print(" %s ", Token::String(node->op())); | 795 Print(" %s ", Token::String(node->op())); |
785 Visit(node->value()); | 796 Visit(node->value()); |
786 } | 797 } |
787 | 798 |
788 | 799 |
789 void PrettyPrinter::VisitYield(Yield* node) { | 800 void PrettyPrinter::VisitYield(Yield* node) { |
790 Print("yield "); | 801 Print("yield "); |
791 Visit(node->expression()); | 802 Visit(node->expression()); |
792 } | 803 } |
(...skipping 729 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1522 case VariableLocation::LOOKUP: | 1533 case VariableLocation::LOOKUP: |
1523 SNPrintF(buf + pos, " lookup"); | 1534 SNPrintF(buf + pos, " lookup"); |
1524 break; | 1535 break; |
1525 } | 1536 } |
1526 PrintLiteralWithModeIndented(buf.start(), var, node->name()); | 1537 PrintLiteralWithModeIndented(buf.start(), var, node->name()); |
1527 } | 1538 } |
1528 | 1539 |
1529 | 1540 |
1530 void AstPrinter::VisitAssignment(Assignment* node) { | 1541 void AstPrinter::VisitAssignment(Assignment* node) { |
1531 IndentedScope indent(this, Token::Name(node->op()), node->position()); | 1542 IndentedScope indent(this, Token::Name(node->op()), node->position()); |
| 1543 RETURN_IF_VISIT_NODE(node->destructuring_assignment()); |
1532 Visit(node->target()); | 1544 Visit(node->target()); |
1533 Visit(node->value()); | 1545 Visit(node->value()); |
1534 } | 1546 } |
1535 | 1547 |
1536 | 1548 |
1537 void AstPrinter::VisitYield(Yield* node) { | 1549 void AstPrinter::VisitYield(Yield* node) { |
1538 IndentedScope indent(this, "YIELD", node->position()); | 1550 IndentedScope indent(this, "YIELD", node->position()); |
1539 Visit(node->expression()); | 1551 Visit(node->expression()); |
1540 } | 1552 } |
1541 | 1553 |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1638 | 1650 |
1639 void AstPrinter::VisitSuperCallReference(SuperCallReference* node) { | 1651 void AstPrinter::VisitSuperCallReference(SuperCallReference* node) { |
1640 IndentedScope indent(this, "SUPER-CALL-REFERENCE", node->position()); | 1652 IndentedScope indent(this, "SUPER-CALL-REFERENCE", node->position()); |
1641 } | 1653 } |
1642 | 1654 |
1643 | 1655 |
1644 #endif // DEBUG | 1656 #endif // DEBUG |
1645 | 1657 |
1646 } // namespace internal | 1658 } // namespace internal |
1647 } // namespace v8 | 1659 } // namespace v8 |
OLD | NEW |