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/ast/prettyprinter.h" | 5 #include "src/ast/prettyprinter.h" |
6 | 6 |
7 #include <stdarg.h> | 7 #include <stdarg.h> |
8 | 8 |
9 #include "src/ast/ast-value-factory.h" | 9 #include "src/ast/ast-value-factory.h" |
10 #include "src/ast/scopes.h" | 10 #include "src/ast/scopes.h" |
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
211 | 211 |
212 | 212 |
213 void CallPrinter::VisitDebuggerStatement(DebuggerStatement* node) {} | 213 void CallPrinter::VisitDebuggerStatement(DebuggerStatement* node) {} |
214 | 214 |
215 | 215 |
216 void CallPrinter::VisitFunctionLiteral(FunctionLiteral* node) { | 216 void CallPrinter::VisitFunctionLiteral(FunctionLiteral* node) { |
217 FindStatements(node->body()); | 217 FindStatements(node->body()); |
218 } | 218 } |
219 | 219 |
220 | 220 |
221 void CallPrinter::VisitClassLiteral(ClassLiteral* node) { | |
222 if (node->extends()) Find(node->extends()); | |
223 for (int i = 0; i < node->properties()->length(); i++) { | |
224 Find(node->properties()->at(i)->value()); | |
225 } | |
226 } | |
227 | |
228 | |
229 void CallPrinter::VisitNativeFunctionLiteral(NativeFunctionLiteral* node) {} | 221 void CallPrinter::VisitNativeFunctionLiteral(NativeFunctionLiteral* node) {} |
230 | 222 |
231 | 223 |
232 void CallPrinter::VisitDoExpression(DoExpression* node) { Find(node->block()); } | 224 void CallPrinter::VisitDoExpression(DoExpression* node) { Find(node->block()); } |
233 | 225 |
234 | 226 |
235 void CallPrinter::VisitConditional(Conditional* node) { | 227 void CallPrinter::VisitConditional(Conditional* node) { |
236 Find(node->condition()); | 228 Find(node->condition()); |
237 Find(node->then_expression()); | 229 Find(node->then_expression()); |
238 Find(node->else_expression()); | 230 Find(node->else_expression()); |
(...skipping 489 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
728 } | 720 } |
729 | 721 |
730 | 722 |
731 void PrettyPrinter::VisitFunctionLiteral(FunctionLiteral* node) { | 723 void PrettyPrinter::VisitFunctionLiteral(FunctionLiteral* node) { |
732 Print("("); | 724 Print("("); |
733 PrintFunctionLiteral(node); | 725 PrintFunctionLiteral(node); |
734 Print(")"); | 726 Print(")"); |
735 } | 727 } |
736 | 728 |
737 | 729 |
738 void PrettyPrinter::VisitClassLiteral(ClassLiteral* node) { | |
739 Print("(class "); | |
740 PrintLiteral(node->constructor()->name(), false); | |
741 if (node->extends()) { | |
742 Print(" extends "); | |
743 Visit(node->extends()); | |
744 } | |
745 Print(" { "); | |
746 for (int i = 0; i < node->properties()->length(); i++) { | |
747 PrintObjectLiteralProperty(node->properties()->at(i)); | |
748 } | |
749 Print(" })"); | |
750 } | |
751 | |
752 | |
753 void PrettyPrinter::VisitNativeFunctionLiteral(NativeFunctionLiteral* node) { | 730 void PrettyPrinter::VisitNativeFunctionLiteral(NativeFunctionLiteral* node) { |
754 Print("("); | 731 Print("("); |
755 PrintLiteral(node->name(), false); | 732 PrintLiteral(node->name(), false); |
756 Print(")"); | 733 Print(")"); |
757 } | 734 } |
758 | 735 |
759 | 736 |
760 void PrettyPrinter::VisitDoExpression(DoExpression* node) { | 737 void PrettyPrinter::VisitDoExpression(DoExpression* node) { |
761 Print("(do {"); | 738 Print("(do {"); |
762 PrintStatements(node->block()->statements()); | 739 PrintStatements(node->block()->statements()); |
(...skipping 698 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1461 PrintLiteralIndented("NAME", node->name(), false); | 1438 PrintLiteralIndented("NAME", node->name(), false); |
1462 PrintLiteralIndented("INFERRED NAME", node->inferred_name(), false); | 1439 PrintLiteralIndented("INFERRED NAME", node->inferred_name(), false); |
1463 PrintParameters(node->scope()); | 1440 PrintParameters(node->scope()); |
1464 // We don't want to see the function literal in this case: it | 1441 // We don't want to see the function literal in this case: it |
1465 // will be printed via PrintProgram when the code for it is | 1442 // will be printed via PrintProgram when the code for it is |
1466 // generated. | 1443 // generated. |
1467 // PrintStatements(node->body()); | 1444 // PrintStatements(node->body()); |
1468 } | 1445 } |
1469 | 1446 |
1470 | 1447 |
1471 void AstPrinter::VisitClassLiteral(ClassLiteral* node) { | |
1472 IndentedScope indent(this, "CLASS LITERAL", node->position()); | |
1473 PrintLiteralIndented("NAME", node->constructor()->name(), false); | |
1474 if (node->extends() != nullptr) { | |
1475 PrintIndentedVisit("EXTENDS", node->extends()); | |
1476 } | |
1477 PrintProperties(node->properties()); | |
1478 } | |
1479 | |
1480 | |
1481 void AstPrinter::PrintProperties( | 1448 void AstPrinter::PrintProperties( |
1482 ZoneList<ObjectLiteral::Property*>* properties) { | 1449 ZoneList<ObjectLiteral::Property*>* properties) { |
1483 for (int i = 0; i < properties->length(); i++) { | 1450 for (int i = 0; i < properties->length(); i++) { |
1484 ObjectLiteral::Property* property = properties->at(i); | 1451 ObjectLiteral::Property* property = properties->at(i); |
1485 const char* prop_kind = nullptr; | 1452 const char* prop_kind = nullptr; |
1486 switch (property->kind()) { | 1453 switch (property->kind()) { |
1487 case ObjectLiteral::Property::CONSTANT: | 1454 case ObjectLiteral::Property::CONSTANT: |
1488 prop_kind = "CONSTANT"; | 1455 prop_kind = "CONSTANT"; |
1489 break; | 1456 break; |
1490 case ObjectLiteral::Property::COMPUTED: | 1457 case ObjectLiteral::Property::COMPUTED: |
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1737 | 1704 |
1738 void AstPrinter::VisitRewritableExpression(RewritableExpression* node) { | 1705 void AstPrinter::VisitRewritableExpression(RewritableExpression* node) { |
1739 Visit(node->expression()); | 1706 Visit(node->expression()); |
1740 } | 1707 } |
1741 | 1708 |
1742 | 1709 |
1743 #endif // DEBUG | 1710 #endif // DEBUG |
1744 | 1711 |
1745 } // namespace internal | 1712 } // namespace internal |
1746 } // namespace v8 | 1713 } // namespace v8 |
OLD | NEW |