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 385 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
396 | 396 |
397 void PrettyPrinter::VisitCompareOperation(CompareOperation* node) { | 397 void PrettyPrinter::VisitCompareOperation(CompareOperation* node) { |
398 Print("("); | 398 Print("("); |
399 Visit(node->left()); | 399 Visit(node->left()); |
400 Print("%s", Token::String(node->op())); | 400 Print("%s", Token::String(node->op())); |
401 Visit(node->right()); | 401 Visit(node->right()); |
402 Print(")"); | 402 Print(")"); |
403 } | 403 } |
404 | 404 |
405 | 405 |
| 406 void PrettyPrinter::VisitCompareToNull(CompareToNull* node) { |
| 407 Print("("); |
| 408 Visit(node->expression()); |
| 409 Print("%s null)", Token::String(node->op())); |
| 410 } |
| 411 |
| 412 |
406 void PrettyPrinter::VisitThisFunction(ThisFunction* node) { | 413 void PrettyPrinter::VisitThisFunction(ThisFunction* node) { |
407 Print("<this-function>"); | 414 Print("<this-function>"); |
408 } | 415 } |
409 | 416 |
410 | 417 |
411 const char* PrettyPrinter::Print(AstNode* node) { | 418 const char* PrettyPrinter::Print(AstNode* node) { |
412 Init(); | 419 Init(); |
413 Visit(node); | 420 Visit(node); |
414 return output_; | 421 return output_; |
415 } | 422 } |
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
597 explicit IndentedScope(const char* txt, AstNode* node = NULL) { | 604 explicit IndentedScope(const char* txt, AstNode* node = NULL) { |
598 ast_printer_->PrintIndented(txt); | 605 ast_printer_->PrintIndented(txt); |
599 if (node != NULL && node->AsExpression() != NULL) { | 606 if (node != NULL && node->AsExpression() != NULL) { |
600 Expression* expr = node->AsExpression(); | 607 Expression* expr = node->AsExpression(); |
601 bool printed_first = false; | 608 bool printed_first = false; |
602 if ((expr->type() != NULL) && (expr->type()->IsKnown())) { | 609 if ((expr->type() != NULL) && (expr->type()->IsKnown())) { |
603 ast_printer_->Print(" (type = "); | 610 ast_printer_->Print(" (type = "); |
604 ast_printer_->Print(StaticType::Type2String(expr->type())); | 611 ast_printer_->Print(StaticType::Type2String(expr->type())); |
605 printed_first = true; | 612 printed_first = true; |
606 } | 613 } |
607 if (expr->num() != AstNode::kNoNumber) { | |
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(")"); | 614 if (printed_first) ast_printer_->Print(")"); |
613 } | 615 } |
614 ast_printer_->Print("\n"); | 616 ast_printer_->Print("\n"); |
615 ast_printer_->inc_indent(); | 617 ast_printer_->inc_indent(); |
616 } | 618 } |
617 | 619 |
618 virtual ~IndentedScope() { | 620 virtual ~IndentedScope() { |
619 ast_printer_->dec_indent(); | 621 ast_printer_->dec_indent(); |
620 } | 622 } |
621 | 623 |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
660 PrintIndented(info); | 662 PrintIndented(info); |
661 Print(" "); | 663 Print(" "); |
662 PrintLiteral(value, quote); | 664 PrintLiteral(value, quote); |
663 Print("\n"); | 665 Print("\n"); |
664 } | 666 } |
665 | 667 |
666 | 668 |
667 void AstPrinter::PrintLiteralWithModeIndented(const char* info, | 669 void AstPrinter::PrintLiteralWithModeIndented(const char* info, |
668 Variable* var, | 670 Variable* var, |
669 Handle<Object> value, | 671 Handle<Object> value, |
670 StaticType* type, | 672 StaticType* type) { |
671 int num, | |
672 bool is_primitive) { | |
673 if (var == NULL) { | 673 if (var == NULL) { |
674 PrintLiteralIndented(info, value, true); | 674 PrintLiteralIndented(info, value, true); |
675 } else { | 675 } else { |
676 EmbeddedVector<char, 256> buf; | 676 EmbeddedVector<char, 256> buf; |
677 int pos = OS::SNPrintF(buf, "%s (mode = %s", info, | 677 int pos = OS::SNPrintF(buf, "%s (mode = %s", info, |
678 Variable::Mode2String(var->mode())); | 678 Variable::Mode2String(var->mode())); |
679 if (type->IsKnown()) { | 679 if (type->IsKnown()) { |
680 pos += OS::SNPrintF(buf + pos, ", type = %s", | 680 pos += OS::SNPrintF(buf + pos, ", type = %s", |
681 StaticType::Type2String(type)); | 681 StaticType::Type2String(type)); |
682 } | 682 } |
683 if (num != AstNode::kNoNumber) { | |
684 pos += OS::SNPrintF(buf + pos, ", num = %d", num); | |
685 } | |
686 pos += OS::SNPrintF(buf + pos, | |
687 is_primitive ? ", primitive" : ", non-primitive"); | |
688 OS::SNPrintF(buf + pos, ")"); | 683 OS::SNPrintF(buf + pos, ")"); |
689 PrintLiteralIndented(buf.start(), value, true); | 684 PrintLiteralIndented(buf.start(), value, true); |
690 } | 685 } |
691 } | 686 } |
692 | 687 |
693 | 688 |
694 void AstPrinter::PrintLabelsIndented(const char* info, ZoneStringList* labels) { | 689 void AstPrinter::PrintLabelsIndented(const char* info, ZoneStringList* labels) { |
695 if (labels != NULL && labels->length() > 0) { | 690 if (labels != NULL && labels->length() > 0) { |
696 if (info == NULL) { | 691 if (info == NULL) { |
697 PrintIndented("LABELS "); | 692 PrintIndented("LABELS "); |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
735 } | 730 } |
736 } | 731 } |
737 | 732 |
738 | 733 |
739 void AstPrinter::PrintParameters(Scope* scope) { | 734 void AstPrinter::PrintParameters(Scope* scope) { |
740 if (scope->num_parameters() > 0) { | 735 if (scope->num_parameters() > 0) { |
741 IndentedScope indent("PARAMS"); | 736 IndentedScope indent("PARAMS"); |
742 for (int i = 0; i < scope->num_parameters(); i++) { | 737 for (int i = 0; i < scope->num_parameters(); i++) { |
743 PrintLiteralWithModeIndented("VAR", scope->parameter(i), | 738 PrintLiteralWithModeIndented("VAR", scope->parameter(i), |
744 scope->parameter(i)->name(), | 739 scope->parameter(i)->name(), |
745 scope->parameter(i)->type(), | 740 scope->parameter(i)->type()); |
746 AstNode::kNoNumber, | |
747 false); | |
748 } | 741 } |
749 } | 742 } |
750 } | 743 } |
751 | 744 |
752 | 745 |
753 void AstPrinter::PrintStatements(ZoneList<Statement*>* statements) { | 746 void AstPrinter::PrintStatements(ZoneList<Statement*>* statements) { |
754 for (int i = 0; i < statements->length(); i++) { | 747 for (int i = 0; i < statements->length(); i++) { |
755 Visit(statements->at(i)); | 748 Visit(statements->at(i)); |
756 } | 749 } |
757 } | 750 } |
(...skipping 24 matching lines...) Expand all Loading... |
782 PrintStatements(node->statements()); | 775 PrintStatements(node->statements()); |
783 } | 776 } |
784 | 777 |
785 | 778 |
786 void AstPrinter::VisitDeclaration(Declaration* node) { | 779 void AstPrinter::VisitDeclaration(Declaration* node) { |
787 if (node->fun() == NULL) { | 780 if (node->fun() == NULL) { |
788 // var or const declarations | 781 // var or const declarations |
789 PrintLiteralWithModeIndented(Variable::Mode2String(node->mode()), | 782 PrintLiteralWithModeIndented(Variable::Mode2String(node->mode()), |
790 node->proxy()->AsVariable(), | 783 node->proxy()->AsVariable(), |
791 node->proxy()->name(), | 784 node->proxy()->name(), |
792 node->proxy()->AsVariable()->type(), | 785 node->proxy()->AsVariable()->type()); |
793 AstNode::kNoNumber, | |
794 node->proxy()->IsPrimitive()); | |
795 } else { | 786 } else { |
796 // function declarations | 787 // function declarations |
797 PrintIndented("FUNCTION "); | 788 PrintIndented("FUNCTION "); |
798 PrintLiteral(node->proxy()->name(), true); | 789 PrintLiteral(node->proxy()->name(), true); |
799 Print(" = function "); | 790 Print(" = function "); |
800 PrintLiteral(node->fun()->name(), false); | 791 PrintLiteral(node->fun()->name(), false); |
801 Print("\n"); | 792 Print("\n"); |
802 } | 793 } |
803 } | 794 } |
804 | 795 |
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1020 break; | 1011 break; |
1021 default: | 1012 default: |
1022 UNREACHABLE(); | 1013 UNREACHABLE(); |
1023 } | 1014 } |
1024 Print("\n"); | 1015 Print("\n"); |
1025 } | 1016 } |
1026 | 1017 |
1027 | 1018 |
1028 void AstPrinter::VisitVariableProxy(VariableProxy* node) { | 1019 void AstPrinter::VisitVariableProxy(VariableProxy* node) { |
1029 PrintLiteralWithModeIndented("VAR PROXY", node->AsVariable(), node->name(), | 1020 PrintLiteralWithModeIndented("VAR PROXY", node->AsVariable(), node->name(), |
1030 node->type(), node->num(), node->IsPrimitive()); | 1021 node->type()); |
1031 Variable* var = node->var(); | 1022 Variable* var = node->var(); |
1032 if (var != NULL && var->rewrite() != NULL) { | 1023 if (var != NULL && var->rewrite() != NULL) { |
1033 IndentedScope indent; | 1024 IndentedScope indent; |
1034 Visit(var->rewrite()); | 1025 Visit(var->rewrite()); |
1035 } | 1026 } |
1036 } | 1027 } |
1037 | 1028 |
1038 | 1029 |
1039 void AstPrinter::VisitAssignment(Assignment* node) { | 1030 void AstPrinter::VisitAssignment(Assignment* node) { |
1040 IndentedScope indent(Token::Name(node->op()), node); | 1031 IndentedScope indent(Token::Name(node->op()), node); |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1108 } | 1099 } |
1109 | 1100 |
1110 | 1101 |
1111 void AstPrinter::VisitCompareOperation(CompareOperation* node) { | 1102 void AstPrinter::VisitCompareOperation(CompareOperation* node) { |
1112 IndentedScope indent(Token::Name(node->op()), node); | 1103 IndentedScope indent(Token::Name(node->op()), node); |
1113 Visit(node->left()); | 1104 Visit(node->left()); |
1114 Visit(node->right()); | 1105 Visit(node->right()); |
1115 } | 1106 } |
1116 | 1107 |
1117 | 1108 |
| 1109 void AstPrinter::VisitCompareToNull(CompareToNull* node) { |
| 1110 const char* name = node->is_strict() |
| 1111 ? "COMPARE-TO-NULL-STRICT" |
| 1112 : "COMPARE-TO-NULL"; |
| 1113 IndentedScope indent(name, node); |
| 1114 Visit(node->expression()); |
| 1115 } |
| 1116 |
| 1117 |
1118 void AstPrinter::VisitThisFunction(ThisFunction* node) { | 1118 void AstPrinter::VisitThisFunction(ThisFunction* node) { |
1119 IndentedScope indent("THIS-FUNCTION"); | 1119 IndentedScope indent("THIS-FUNCTION"); |
1120 } | 1120 } |
1121 | 1121 |
1122 | 1122 |
1123 TagScope::TagScope(JsonAstBuilder* builder, const char* name) | 1123 TagScope::TagScope(JsonAstBuilder* builder, const char* name) |
1124 : builder_(builder), next_(builder->tag()), has_body_(false) { | 1124 : builder_(builder), next_(builder->tag()), has_body_(false) { |
1125 if (next_ != NULL) { | 1125 if (next_ != NULL) { |
1126 next_->use(); | 1126 next_->use(); |
1127 builder->Print(",\n"); | 1127 builder->Print(",\n"); |
(...skipping 375 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1503 TagScope tag(this, "CompareOperation"); | 1503 TagScope tag(this, "CompareOperation"); |
1504 { | 1504 { |
1505 AttributesScope attributes(this); | 1505 AttributesScope attributes(this); |
1506 AddAttribute("op", Token::Name(expr->op())); | 1506 AddAttribute("op", Token::Name(expr->op())); |
1507 } | 1507 } |
1508 Visit(expr->left()); | 1508 Visit(expr->left()); |
1509 Visit(expr->right()); | 1509 Visit(expr->right()); |
1510 } | 1510 } |
1511 | 1511 |
1512 | 1512 |
| 1513 void JsonAstBuilder::VisitCompareToNull(CompareToNull* expr) { |
| 1514 TagScope tag(this, "CompareToNull"); |
| 1515 { |
| 1516 AttributesScope attributes(this); |
| 1517 AddAttribute("is_strict", expr->is_strict()); |
| 1518 } |
| 1519 Visit(expr->expression()); |
| 1520 } |
| 1521 |
| 1522 |
1513 void JsonAstBuilder::VisitThisFunction(ThisFunction* expr) { | 1523 void JsonAstBuilder::VisitThisFunction(ThisFunction* expr) { |
1514 TagScope tag(this, "ThisFunction"); | 1524 TagScope tag(this, "ThisFunction"); |
1515 } | 1525 } |
1516 | 1526 |
1517 | 1527 |
1518 void JsonAstBuilder::VisitDeclaration(Declaration* decl) { | 1528 void JsonAstBuilder::VisitDeclaration(Declaration* decl) { |
1519 TagScope tag(this, "Declaration"); | 1529 TagScope tag(this, "Declaration"); |
1520 { | 1530 { |
1521 AttributesScope attributes(this); | 1531 AttributesScope attributes(this); |
1522 AddAttribute("mode", Variable::Mode2String(decl->mode())); | 1532 AddAttribute("mode", Variable::Mode2String(decl->mode())); |
1523 } | 1533 } |
1524 Visit(decl->proxy()); | 1534 Visit(decl->proxy()); |
1525 if (decl->fun() != NULL) Visit(decl->fun()); | 1535 if (decl->fun() != NULL) Visit(decl->fun()); |
1526 } | 1536 } |
1527 | 1537 |
1528 | 1538 |
1529 #endif // DEBUG | 1539 #endif // DEBUG |
1530 | 1540 |
1531 } } // namespace v8::internal | 1541 } } // namespace v8::internal |
OLD | NEW |