OLD | NEW |
1 // Copyright 2006-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2008 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 576 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
587 | 587 |
588 | 588 |
589 //----------------------------------------------------------------------------- | 589 //----------------------------------------------------------------------------- |
590 | 590 |
591 class IndentedScope BASE_EMBEDDED { | 591 class IndentedScope BASE_EMBEDDED { |
592 public: | 592 public: |
593 IndentedScope() { | 593 IndentedScope() { |
594 ast_printer_->inc_indent(); | 594 ast_printer_->inc_indent(); |
595 } | 595 } |
596 | 596 |
597 explicit IndentedScope(const char* txt, StaticType* type = NULL) { | 597 explicit IndentedScope(const char* txt, AstNode* node = NULL) { |
598 ast_printer_->PrintIndented(txt); | 598 ast_printer_->PrintIndented(txt); |
599 if ((type != NULL) && (type->IsKnown())) { | 599 if (node != NULL && node->AsExpression() != NULL) { |
600 ast_printer_->Print(" (type = "); | 600 Expression* expr = node->AsExpression(); |
601 ast_printer_->Print(StaticType::Type2String(type)); | 601 bool printed_first = false; |
602 ast_printer_->Print(")"); | 602 if ((expr->type() != NULL) && (expr->type()->IsKnown())) { |
| 603 ast_printer_->Print(" (type = "); |
| 604 ast_printer_->Print(StaticType::Type2String(expr->type())); |
| 605 printed_first = true; |
| 606 } |
| 607 if (expr->num() != Expression::kNoLabel) { |
| 608 ast_printer_->Print(printed_first ? ", num = " : " (num = "); |
| 609 ast_printer_->Print("%d", expr->num()); |
| 610 printed_first = true; |
| 611 } |
| 612 if (printed_first) ast_printer_->Print(")"); |
603 } | 613 } |
604 ast_printer_->Print("\n"); | 614 ast_printer_->Print("\n"); |
605 ast_printer_->inc_indent(); | 615 ast_printer_->inc_indent(); |
606 } | 616 } |
607 | 617 |
608 virtual ~IndentedScope() { | 618 virtual ~IndentedScope() { |
609 ast_printer_->dec_indent(); | 619 ast_printer_->dec_indent(); |
610 } | 620 } |
611 | 621 |
612 static void SetAstPrinter(AstPrinter* a) { ast_printer_ = a; } | 622 static void SetAstPrinter(AstPrinter* a) { ast_printer_ = a; } |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
650 PrintIndented(info); | 660 PrintIndented(info); |
651 Print(" "); | 661 Print(" "); |
652 PrintLiteral(value, quote); | 662 PrintLiteral(value, quote); |
653 Print("\n"); | 663 Print("\n"); |
654 } | 664 } |
655 | 665 |
656 | 666 |
657 void AstPrinter::PrintLiteralWithModeIndented(const char* info, | 667 void AstPrinter::PrintLiteralWithModeIndented(const char* info, |
658 Variable* var, | 668 Variable* var, |
659 Handle<Object> value, | 669 Handle<Object> value, |
660 StaticType* type) { | 670 StaticType* type, |
| 671 int num) { |
661 if (var == NULL) { | 672 if (var == NULL) { |
662 PrintLiteralIndented(info, value, true); | 673 PrintLiteralIndented(info, value, true); |
663 } else { | 674 } else { |
664 EmbeddedVector<char, 256> buf; | 675 EmbeddedVector<char, 256> buf; |
| 676 int pos = OS::SNPrintF(buf, "%s (mode = %s", info, |
| 677 Variable::Mode2String(var->mode())); |
665 if (type->IsKnown()) { | 678 if (type->IsKnown()) { |
666 OS::SNPrintF(buf, "%s (mode = %s, type = %s)", info, | 679 pos += OS::SNPrintF(buf + pos, ", type = %s", |
667 Variable::Mode2String(var->mode()), | 680 StaticType::Type2String(type)); |
668 StaticType::Type2String(type)); | |
669 } else { | |
670 OS::SNPrintF(buf, "%s (mode = %s)", info, | |
671 Variable::Mode2String(var->mode())); | |
672 } | 681 } |
| 682 if (num != Expression::kNoLabel) { |
| 683 pos += OS::SNPrintF(buf + pos, ", num = %d", num); |
| 684 } |
| 685 OS::SNPrintF(buf + pos, ")"); |
673 PrintLiteralIndented(buf.start(), value, true); | 686 PrintLiteralIndented(buf.start(), value, true); |
674 } | 687 } |
675 } | 688 } |
676 | 689 |
677 | 690 |
678 void AstPrinter::PrintLabelsIndented(const char* info, ZoneStringList* labels) { | 691 void AstPrinter::PrintLabelsIndented(const char* info, ZoneStringList* labels) { |
679 if (labels != NULL && labels->length() > 0) { | 692 if (labels != NULL && labels->length() > 0) { |
680 if (info == NULL) { | 693 if (info == NULL) { |
681 PrintIndented("LABELS "); | 694 PrintIndented("LABELS "); |
682 } else { | 695 } else { |
683 PrintIndented(info); | 696 PrintIndented(info); |
684 Print(" "); | 697 Print(" "); |
685 } | 698 } |
686 PrintLabels(labels); | 699 PrintLabels(labels); |
687 } else if (info != NULL) { | 700 } else if (info != NULL) { |
688 PrintIndented(info); | 701 PrintIndented(info); |
689 } | 702 } |
690 Print("\n"); | 703 Print("\n"); |
691 } | 704 } |
692 | 705 |
693 | 706 |
694 void AstPrinter::PrintIndentedVisit(const char* s, AstNode* node) { | 707 void AstPrinter::PrintIndentedVisit(const char* s, AstNode* node) { |
695 IndentedScope indent(s); | 708 IndentedScope indent(s, node); |
696 Visit(node); | 709 Visit(node); |
697 } | 710 } |
698 | 711 |
699 | 712 |
700 const char* AstPrinter::PrintProgram(FunctionLiteral* program) { | 713 const char* AstPrinter::PrintProgram(FunctionLiteral* program) { |
701 Init(); | 714 Init(); |
702 { IndentedScope indent("FUNC"); | 715 { IndentedScope indent("FUNC"); |
703 PrintLiteralIndented("NAME", program->name(), true); | 716 PrintLiteralIndented("NAME", program->name(), true); |
704 PrintLiteralIndented("INFERRED NAME", program->inferred_name(), true); | 717 PrintLiteralIndented("INFERRED NAME", program->inferred_name(), true); |
705 PrintParameters(program->scope()); | 718 PrintParameters(program->scope()); |
(...skipping 13 matching lines...) Expand all Loading... |
719 } | 732 } |
720 } | 733 } |
721 | 734 |
722 | 735 |
723 void AstPrinter::PrintParameters(Scope* scope) { | 736 void AstPrinter::PrintParameters(Scope* scope) { |
724 if (scope->num_parameters() > 0) { | 737 if (scope->num_parameters() > 0) { |
725 IndentedScope indent("PARAMS"); | 738 IndentedScope indent("PARAMS"); |
726 for (int i = 0; i < scope->num_parameters(); i++) { | 739 for (int i = 0; i < scope->num_parameters(); i++) { |
727 PrintLiteralWithModeIndented("VAR", scope->parameter(i), | 740 PrintLiteralWithModeIndented("VAR", scope->parameter(i), |
728 scope->parameter(i)->name(), | 741 scope->parameter(i)->name(), |
729 scope->parameter(i)->type()); | 742 scope->parameter(i)->type(), |
| 743 Expression::kNoLabel); |
730 } | 744 } |
731 } | 745 } |
732 } | 746 } |
733 | 747 |
734 | 748 |
735 void AstPrinter::PrintStatements(ZoneList<Statement*>* statements) { | 749 void AstPrinter::PrintStatements(ZoneList<Statement*>* statements) { |
736 for (int i = 0; i < statements->length(); i++) { | 750 for (int i = 0; i < statements->length(); i++) { |
737 Visit(statements->at(i)); | 751 Visit(statements->at(i)); |
738 } | 752 } |
739 } | 753 } |
(...skipping 24 matching lines...) Expand all Loading... |
764 PrintStatements(node->statements()); | 778 PrintStatements(node->statements()); |
765 } | 779 } |
766 | 780 |
767 | 781 |
768 void AstPrinter::VisitDeclaration(Declaration* node) { | 782 void AstPrinter::VisitDeclaration(Declaration* node) { |
769 if (node->fun() == NULL) { | 783 if (node->fun() == NULL) { |
770 // var or const declarations | 784 // var or const declarations |
771 PrintLiteralWithModeIndented(Variable::Mode2String(node->mode()), | 785 PrintLiteralWithModeIndented(Variable::Mode2String(node->mode()), |
772 node->proxy()->AsVariable(), | 786 node->proxy()->AsVariable(), |
773 node->proxy()->name(), | 787 node->proxy()->name(), |
774 node->proxy()->AsVariable()->type()); | 788 node->proxy()->AsVariable()->type(), |
| 789 Expression::kNoLabel); |
775 } else { | 790 } else { |
776 // function declarations | 791 // function declarations |
777 PrintIndented("FUNCTION "); | 792 PrintIndented("FUNCTION "); |
778 PrintLiteral(node->proxy()->name(), true); | 793 PrintLiteral(node->proxy()->name(), true); |
779 Print(" = function "); | 794 Print(" = function "); |
780 PrintLiteral(node->fun()->name(), false); | 795 PrintLiteral(node->fun()->name(), false); |
781 Print("\n"); | 796 Print("\n"); |
782 } | 797 } |
783 } | 798 } |
784 | 799 |
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1000 break; | 1015 break; |
1001 default: | 1016 default: |
1002 UNREACHABLE(); | 1017 UNREACHABLE(); |
1003 } | 1018 } |
1004 Print("\n"); | 1019 Print("\n"); |
1005 } | 1020 } |
1006 | 1021 |
1007 | 1022 |
1008 void AstPrinter::VisitVariableProxy(VariableProxy* node) { | 1023 void AstPrinter::VisitVariableProxy(VariableProxy* node) { |
1009 PrintLiteralWithModeIndented("VAR PROXY", node->AsVariable(), node->name(), | 1024 PrintLiteralWithModeIndented("VAR PROXY", node->AsVariable(), node->name(), |
1010 node->type()); | 1025 node->type(), node->num()); |
1011 Variable* var = node->var(); | 1026 Variable* var = node->var(); |
1012 if (var != NULL && var->rewrite() != NULL) { | 1027 if (var != NULL && var->rewrite() != NULL) { |
1013 IndentedScope indent; | 1028 IndentedScope indent; |
1014 Visit(var->rewrite()); | 1029 Visit(var->rewrite()); |
1015 } | 1030 } |
1016 } | 1031 } |
1017 | 1032 |
1018 | 1033 |
1019 void AstPrinter::VisitAssignment(Assignment* node) { | 1034 void AstPrinter::VisitAssignment(Assignment* node) { |
1020 IndentedScope indent(Token::Name(node->op()), node->type()); | 1035 IndentedScope indent(Token::Name(node->op()), node); |
1021 Visit(node->target()); | 1036 Visit(node->target()); |
1022 Visit(node->value()); | 1037 Visit(node->value()); |
1023 } | 1038 } |
1024 | 1039 |
1025 | 1040 |
1026 void AstPrinter::VisitThrow(Throw* node) { | 1041 void AstPrinter::VisitThrow(Throw* node) { |
1027 PrintIndentedVisit("THROW", node->exception()); | 1042 PrintIndentedVisit("THROW", node->exception()); |
1028 } | 1043 } |
1029 | 1044 |
1030 | 1045 |
1031 void AstPrinter::VisitProperty(Property* node) { | 1046 void AstPrinter::VisitProperty(Property* node) { |
1032 IndentedScope indent("PROPERTY"); | 1047 IndentedScope indent("PROPERTY", node); |
1033 Visit(node->obj()); | 1048 Visit(node->obj()); |
1034 Literal* literal = node->key()->AsLiteral(); | 1049 Literal* literal = node->key()->AsLiteral(); |
1035 if (literal != NULL && literal->handle()->IsSymbol()) { | 1050 if (literal != NULL && literal->handle()->IsSymbol()) { |
1036 PrintLiteralIndented("NAME", literal->handle(), false); | 1051 PrintLiteralIndented("NAME", literal->handle(), false); |
1037 } else { | 1052 } else { |
1038 PrintIndentedVisit("KEY", node->key()); | 1053 PrintIndentedVisit("KEY", node->key()); |
1039 } | 1054 } |
1040 } | 1055 } |
1041 | 1056 |
1042 | 1057 |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1075 StaticType::Type2String(node->type())); | 1090 StaticType::Type2String(node->type())); |
1076 } else { | 1091 } else { |
1077 OS::SNPrintF(buf, "%s %s", (node->is_prefix() ? "PRE" : "POST"), | 1092 OS::SNPrintF(buf, "%s %s", (node->is_prefix() ? "PRE" : "POST"), |
1078 Token::Name(node->op())); | 1093 Token::Name(node->op())); |
1079 } | 1094 } |
1080 PrintIndentedVisit(buf.start(), node->expression()); | 1095 PrintIndentedVisit(buf.start(), node->expression()); |
1081 } | 1096 } |
1082 | 1097 |
1083 | 1098 |
1084 void AstPrinter::VisitBinaryOperation(BinaryOperation* node) { | 1099 void AstPrinter::VisitBinaryOperation(BinaryOperation* node) { |
1085 IndentedScope indent(Token::Name(node->op()), node->type()); | 1100 IndentedScope indent(Token::Name(node->op()), node); |
1086 Visit(node->left()); | 1101 Visit(node->left()); |
1087 Visit(node->right()); | 1102 Visit(node->right()); |
1088 } | 1103 } |
1089 | 1104 |
1090 | 1105 |
1091 void AstPrinter::VisitCompareOperation(CompareOperation* node) { | 1106 void AstPrinter::VisitCompareOperation(CompareOperation* node) { |
1092 IndentedScope indent(Token::Name(node->op()), node->type()); | 1107 IndentedScope indent(Token::Name(node->op()), node); |
1093 Visit(node->left()); | 1108 Visit(node->left()); |
1094 Visit(node->right()); | 1109 Visit(node->right()); |
1095 } | 1110 } |
1096 | 1111 |
1097 | 1112 |
1098 void AstPrinter::VisitThisFunction(ThisFunction* node) { | 1113 void AstPrinter::VisitThisFunction(ThisFunction* node) { |
1099 IndentedScope indent("THIS-FUNCTION"); | 1114 IndentedScope indent("THIS-FUNCTION"); |
1100 } | 1115 } |
1101 | 1116 |
1102 | 1117 |
(...skipping 399 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1502 AddAttribute("mode", Variable::Mode2String(decl->mode())); | 1517 AddAttribute("mode", Variable::Mode2String(decl->mode())); |
1503 } | 1518 } |
1504 Visit(decl->proxy()); | 1519 Visit(decl->proxy()); |
1505 if (decl->fun() != NULL) Visit(decl->fun()); | 1520 if (decl->fun() != NULL) Visit(decl->fun()); |
1506 } | 1521 } |
1507 | 1522 |
1508 | 1523 |
1509 #endif // DEBUG | 1524 #endif // DEBUG |
1510 | 1525 |
1511 } } // namespace v8::internal | 1526 } } // namespace v8::internal |
OLD | NEW |