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 570 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
581 | 581 |
582 | 582 |
583 //----------------------------------------------------------------------------- | 583 //----------------------------------------------------------------------------- |
584 | 584 |
585 class IndentedScope BASE_EMBEDDED { | 585 class IndentedScope BASE_EMBEDDED { |
586 public: | 586 public: |
587 IndentedScope() { | 587 IndentedScope() { |
588 ast_printer_->inc_indent(); | 588 ast_printer_->inc_indent(); |
589 } | 589 } |
590 | 590 |
591 explicit IndentedScope(const char* txt) { | 591 explicit IndentedScope(const char* txt, StaticType* type = NULL) { |
592 ast_printer_->PrintIndented(txt); | 592 ast_printer_->PrintIndented(txt); |
| 593 if ((type != NULL) && (type->IsKnown())) { |
| 594 ast_printer_->Print(" (type = "); |
| 595 ast_printer_->Print(StaticType::Type2String(type)); |
| 596 ast_printer_->Print(")"); |
| 597 } |
593 ast_printer_->Print("\n"); | 598 ast_printer_->Print("\n"); |
594 ast_printer_->inc_indent(); | 599 ast_printer_->inc_indent(); |
595 } | 600 } |
596 | 601 |
597 virtual ~IndentedScope() { | 602 virtual ~IndentedScope() { |
598 ast_printer_->dec_indent(); | 603 ast_printer_->dec_indent(); |
599 } | 604 } |
600 | 605 |
601 static void SetAstPrinter(AstPrinter* a) { ast_printer_ = a; } | 606 static void SetAstPrinter(AstPrinter* a) { ast_printer_ = a; } |
602 | 607 |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
638 bool quote) { | 643 bool quote) { |
639 PrintIndented(info); | 644 PrintIndented(info); |
640 Print(" "); | 645 Print(" "); |
641 PrintLiteral(value, quote); | 646 PrintLiteral(value, quote); |
642 Print("\n"); | 647 Print("\n"); |
643 } | 648 } |
644 | 649 |
645 | 650 |
646 void AstPrinter::PrintLiteralWithModeIndented(const char* info, | 651 void AstPrinter::PrintLiteralWithModeIndented(const char* info, |
647 Variable* var, | 652 Variable* var, |
648 Handle<Object> value) { | 653 Handle<Object> value, |
| 654 StaticType* type) { |
649 if (var == NULL) { | 655 if (var == NULL) { |
650 PrintLiteralIndented(info, value, true); | 656 PrintLiteralIndented(info, value, true); |
651 } else { | 657 } else { |
652 EmbeddedVector<char, 256> buf; | 658 EmbeddedVector<char, 256> buf; |
653 OS::SNPrintF(buf, "%s (mode = %s)", info, | 659 if (type->IsKnown()) { |
654 Variable::Mode2String(var->mode())); | 660 OS::SNPrintF(buf, "%s (mode = %s, type = %s)", info, |
| 661 Variable::Mode2String(var->mode()), |
| 662 StaticType::Type2String(type)); |
| 663 } else { |
| 664 OS::SNPrintF(buf, "%s (mode = %s)", info, |
| 665 Variable::Mode2String(var->mode())); |
| 666 } |
655 PrintLiteralIndented(buf.start(), value, true); | 667 PrintLiteralIndented(buf.start(), value, true); |
656 } | 668 } |
657 } | 669 } |
658 | 670 |
659 | 671 |
660 void AstPrinter::PrintLabelsIndented(const char* info, ZoneStringList* labels) { | 672 void AstPrinter::PrintLabelsIndented(const char* info, ZoneStringList* labels) { |
661 if (labels != NULL && labels->length() > 0) { | 673 if (labels != NULL && labels->length() > 0) { |
662 if (info == NULL) { | 674 if (info == NULL) { |
663 PrintIndented("LABELS "); | 675 PrintIndented("LABELS "); |
664 } else { | 676 } else { |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
699 } | 711 } |
700 } | 712 } |
701 } | 713 } |
702 | 714 |
703 | 715 |
704 void AstPrinter::PrintParameters(Scope* scope) { | 716 void AstPrinter::PrintParameters(Scope* scope) { |
705 if (scope->num_parameters() > 0) { | 717 if (scope->num_parameters() > 0) { |
706 IndentedScope indent("PARAMS"); | 718 IndentedScope indent("PARAMS"); |
707 for (int i = 0; i < scope->num_parameters(); i++) { | 719 for (int i = 0; i < scope->num_parameters(); i++) { |
708 PrintLiteralWithModeIndented("VAR ", scope->parameter(i), | 720 PrintLiteralWithModeIndented("VAR ", scope->parameter(i), |
709 scope->parameter(i)->name()); | 721 scope->parameter(i)->name(), |
| 722 scope->parameter(i)->type()); |
710 } | 723 } |
711 } | 724 } |
712 } | 725 } |
713 | 726 |
714 | 727 |
715 void AstPrinter::PrintStatements(ZoneList<Statement*>* statements) { | 728 void AstPrinter::PrintStatements(ZoneList<Statement*>* statements) { |
716 for (int i = 0; i < statements->length(); i++) { | 729 for (int i = 0; i < statements->length(); i++) { |
717 Visit(statements->at(i)); | 730 Visit(statements->at(i)); |
718 } | 731 } |
719 } | 732 } |
(...skipping 21 matching lines...) Expand all Loading... |
741 void AstPrinter::VisitBlock(Block* node) { | 754 void AstPrinter::VisitBlock(Block* node) { |
742 const char* block_txt = node->is_initializer_block() ? "BLOCK INIT" : "BLOCK"; | 755 const char* block_txt = node->is_initializer_block() ? "BLOCK INIT" : "BLOCK"; |
743 IndentedScope indent(block_txt); | 756 IndentedScope indent(block_txt); |
744 PrintStatements(node->statements()); | 757 PrintStatements(node->statements()); |
745 } | 758 } |
746 | 759 |
747 | 760 |
748 void AstPrinter::VisitDeclaration(Declaration* node) { | 761 void AstPrinter::VisitDeclaration(Declaration* node) { |
749 if (node->fun() == NULL) { | 762 if (node->fun() == NULL) { |
750 // var or const declarations | 763 // var or const declarations |
751 PrintLiteralWithModeIndented( | 764 PrintLiteralWithModeIndented(Variable::Mode2String(node->mode()), |
752 Variable::Mode2String(node->mode()), | 765 node->proxy()->AsVariable(), |
753 node->proxy()->AsVariable(), node->proxy()->name()); | 766 node->proxy()->name(), |
| 767 node->proxy()->AsVariable()->type()); |
754 } else { | 768 } else { |
755 // function declarations | 769 // function declarations |
756 PrintIndented("FUNCTION "); | 770 PrintIndented("FUNCTION "); |
757 PrintLiteral(node->proxy()->name(), true); | 771 PrintLiteral(node->proxy()->name(), true); |
758 Print(" = function "); | 772 Print(" = function "); |
759 PrintLiteral(node->fun()->name(), false); | 773 PrintLiteral(node->fun()->name(), false); |
760 Print("\n"); | 774 Print("\n"); |
761 } | 775 } |
762 } | 776 } |
763 | 777 |
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
953 Print("]"); | 967 Print("]"); |
954 break; | 968 break; |
955 default: | 969 default: |
956 UNREACHABLE(); | 970 UNREACHABLE(); |
957 } | 971 } |
958 Print("\n"); | 972 Print("\n"); |
959 } | 973 } |
960 | 974 |
961 | 975 |
962 void AstPrinter::VisitVariableProxy(VariableProxy* node) { | 976 void AstPrinter::VisitVariableProxy(VariableProxy* node) { |
963 PrintLiteralWithModeIndented("VAR PROXY", node->AsVariable(), node->name()); | 977 PrintLiteralWithModeIndented("VAR PROXY", node->AsVariable(), node->name(), |
| 978 node->type()); |
964 Variable* var = node->var(); | 979 Variable* var = node->var(); |
965 if (var != NULL && var->rewrite() != NULL) { | 980 if (var != NULL && var->rewrite() != NULL) { |
966 IndentedScope indent; | 981 IndentedScope indent; |
967 Visit(var->rewrite()); | 982 Visit(var->rewrite()); |
968 } | 983 } |
969 } | 984 } |
970 | 985 |
971 | 986 |
972 void AstPrinter::VisitAssignment(Assignment* node) { | 987 void AstPrinter::VisitAssignment(Assignment* node) { |
973 IndentedScope indent(Token::Name(node->op())); | 988 IndentedScope indent(Token::Name(node->op()), node->type()); |
974 Visit(node->target()); | 989 Visit(node->target()); |
975 Visit(node->value()); | 990 Visit(node->value()); |
976 } | 991 } |
977 | 992 |
978 | 993 |
979 void AstPrinter::VisitThrow(Throw* node) { | 994 void AstPrinter::VisitThrow(Throw* node) { |
980 PrintIndentedVisit("THROW", node->exception()); | 995 PrintIndentedVisit("THROW", node->exception()); |
981 } | 996 } |
982 | 997 |
983 | 998 |
(...skipping 30 matching lines...) Expand all Loading... |
1014 } | 1029 } |
1015 | 1030 |
1016 | 1031 |
1017 void AstPrinter::VisitUnaryOperation(UnaryOperation* node) { | 1032 void AstPrinter::VisitUnaryOperation(UnaryOperation* node) { |
1018 PrintIndentedVisit(Token::Name(node->op()), node->expression()); | 1033 PrintIndentedVisit(Token::Name(node->op()), node->expression()); |
1019 } | 1034 } |
1020 | 1035 |
1021 | 1036 |
1022 void AstPrinter::VisitCountOperation(CountOperation* node) { | 1037 void AstPrinter::VisitCountOperation(CountOperation* node) { |
1023 EmbeddedVector<char, 128> buf; | 1038 EmbeddedVector<char, 128> buf; |
1024 OS::SNPrintF(buf, "%s %s", (node->is_prefix() ? "PRE" : "POST"), | 1039 if (node->type()->IsKnown()) { |
1025 Token::Name(node->op())); | 1040 OS::SNPrintF(buf, "%s %s (type = %s)", |
| 1041 (node->is_prefix() ? "PRE" : "POST"), |
| 1042 Token::Name(node->op()), |
| 1043 StaticType::Type2String(node->type())); |
| 1044 } else { |
| 1045 OS::SNPrintF(buf, "%s %s", (node->is_prefix() ? "PRE" : "POST"), |
| 1046 Token::Name(node->op())); |
| 1047 } |
1026 PrintIndentedVisit(buf.start(), node->expression()); | 1048 PrintIndentedVisit(buf.start(), node->expression()); |
1027 } | 1049 } |
1028 | 1050 |
1029 | 1051 |
1030 void AstPrinter::VisitBinaryOperation(BinaryOperation* node) { | 1052 void AstPrinter::VisitBinaryOperation(BinaryOperation* node) { |
1031 IndentedScope indent(Token::Name(node->op())); | 1053 IndentedScope indent(Token::Name(node->op()), node->type()); |
1032 Visit(node->left()); | 1054 Visit(node->left()); |
1033 Visit(node->right()); | 1055 Visit(node->right()); |
1034 } | 1056 } |
1035 | 1057 |
1036 | 1058 |
1037 void AstPrinter::VisitCompareOperation(CompareOperation* node) { | 1059 void AstPrinter::VisitCompareOperation(CompareOperation* node) { |
1038 IndentedScope indent(Token::Name(node->op())); | 1060 IndentedScope indent(Token::Name(node->op()), node->type()); |
1039 Visit(node->left()); | 1061 Visit(node->left()); |
1040 Visit(node->right()); | 1062 Visit(node->right()); |
1041 } | 1063 } |
1042 | 1064 |
1043 | 1065 |
1044 void AstPrinter::VisitThisFunction(ThisFunction* node) { | 1066 void AstPrinter::VisitThisFunction(ThisFunction* node) { |
1045 IndentedScope indent("THIS-FUNCTION"); | 1067 IndentedScope indent("THIS-FUNCTION"); |
1046 } | 1068 } |
1047 | 1069 |
1048 | 1070 |
1049 | 1071 |
1050 #endif // DEBUG | 1072 #endif // DEBUG |
1051 | 1073 |
1052 } } // namespace v8::internal | 1074 } } // namespace v8::internal |
OLD | NEW |