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 <stdarg.h> | 5 #include <stdarg.h> |
6 | 6 |
7 #include "src/v8.h" | 7 #include "src/v8.h" |
8 | 8 |
9 #include "src/ast-value-factory.h" | 9 #include "src/ast-value-factory.h" |
10 #include "src/prettyprinter.h" | 10 #include "src/prettyprinter.h" |
(...skipping 475 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
486 } | 486 } |
487 output_[0] = '\0'; | 487 output_[0] = '\0'; |
488 pos_ = 0; | 488 pos_ = 0; |
489 } | 489 } |
490 | 490 |
491 | 491 |
492 void PrettyPrinter::Print(const char* format, ...) { | 492 void PrettyPrinter::Print(const char* format, ...) { |
493 for (;;) { | 493 for (;;) { |
494 va_list arguments; | 494 va_list arguments; |
495 va_start(arguments, format); | 495 va_start(arguments, format); |
496 int n = OS::VSNPrintF(Vector<char>(output_, size_) + pos_, | 496 int n = VSNPrintF(Vector<char>(output_, size_) + pos_, |
497 format, | 497 format, |
498 arguments); | 498 arguments); |
499 va_end(arguments); | 499 va_end(arguments); |
500 | 500 |
501 if (n >= 0) { | 501 if (n >= 0) { |
502 // there was enough space - we are done | 502 // there was enough space - we are done |
503 pos_ += n; | 503 pos_ += n; |
504 return; | 504 return; |
505 } else { | 505 } else { |
506 // there was not enough space - allocate more and try again | 506 // there was not enough space - allocate more and try again |
507 const int slack = 32; | 507 const int slack = 32; |
508 int new_size = size_ + (size_ >> 1) + slack; | 508 int new_size = size_ + (size_ >> 1) + slack; |
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
667 } | 667 } |
668 | 668 |
669 | 669 |
670 void AstPrinter::PrintLiteralWithModeIndented(const char* info, | 670 void AstPrinter::PrintLiteralWithModeIndented(const char* info, |
671 Variable* var, | 671 Variable* var, |
672 Handle<Object> value) { | 672 Handle<Object> value) { |
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 = SNPrintF(buf, "%s (mode = %s", info, |
678 Variable::Mode2String(var->mode())); | 678 Variable::Mode2String(var->mode())); |
679 OS::SNPrintF(buf + pos, ")"); | 679 SNPrintF(buf + pos, ")"); |
680 PrintLiteralIndented(buf.start(), value, true); | 680 PrintLiteralIndented(buf.start(), value, true); |
681 } | 681 } |
682 } | 682 } |
683 | 683 |
684 | 684 |
685 void AstPrinter::PrintLabelsIndented(ZoneList<const AstString*>* labels) { | 685 void AstPrinter::PrintLabelsIndented(ZoneList<const AstString*>* labels) { |
686 if (labels == NULL || labels->length() == 0) return; | 686 if (labels == NULL || labels->length() == 0) return; |
687 PrintIndented("LABELS "); | 687 PrintIndented("LABELS "); |
688 PrintLabels(labels); | 688 PrintLabels(labels); |
689 Print("\n"); | 689 Print("\n"); |
(...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1032 Visit(node->values()->at(i)); | 1032 Visit(node->values()->at(i)); |
1033 } | 1033 } |
1034 } | 1034 } |
1035 } | 1035 } |
1036 | 1036 |
1037 | 1037 |
1038 // TODO(svenpanne) Start with IndentedScope. | 1038 // TODO(svenpanne) Start with IndentedScope. |
1039 void AstPrinter::VisitVariableProxy(VariableProxy* node) { | 1039 void AstPrinter::VisitVariableProxy(VariableProxy* node) { |
1040 Variable* var = node->var(); | 1040 Variable* var = node->var(); |
1041 EmbeddedVector<char, 128> buf; | 1041 EmbeddedVector<char, 128> buf; |
1042 int pos = OS::SNPrintF(buf, "VAR PROXY"); | 1042 int pos = SNPrintF(buf, "VAR PROXY"); |
1043 switch (var->location()) { | 1043 switch (var->location()) { |
1044 case Variable::UNALLOCATED: | 1044 case Variable::UNALLOCATED: |
1045 break; | 1045 break; |
1046 case Variable::PARAMETER: | 1046 case Variable::PARAMETER: |
1047 OS::SNPrintF(buf + pos, " parameter[%d]", var->index()); | 1047 SNPrintF(buf + pos, " parameter[%d]", var->index()); |
1048 break; | 1048 break; |
1049 case Variable::LOCAL: | 1049 case Variable::LOCAL: |
1050 OS::SNPrintF(buf + pos, " local[%d]", var->index()); | 1050 SNPrintF(buf + pos, " local[%d]", var->index()); |
1051 break; | 1051 break; |
1052 case Variable::CONTEXT: | 1052 case Variable::CONTEXT: |
1053 OS::SNPrintF(buf + pos, " context[%d]", var->index()); | 1053 SNPrintF(buf + pos, " context[%d]", var->index()); |
1054 break; | 1054 break; |
1055 case Variable::LOOKUP: | 1055 case Variable::LOOKUP: |
1056 OS::SNPrintF(buf + pos, " lookup"); | 1056 SNPrintF(buf + pos, " lookup"); |
1057 break; | 1057 break; |
1058 } | 1058 } |
1059 PrintLiteralWithModeIndented(buf.start(), var, node->name()); | 1059 PrintLiteralWithModeIndented(buf.start(), var, node->name()); |
1060 } | 1060 } |
1061 | 1061 |
1062 | 1062 |
1063 void AstPrinter::VisitAssignment(Assignment* node) { | 1063 void AstPrinter::VisitAssignment(Assignment* node) { |
1064 IndentedScope indent(this, Token::Name(node->op())); | 1064 IndentedScope indent(this, Token::Name(node->op())); |
1065 Visit(node->target()); | 1065 Visit(node->target()); |
1066 Visit(node->value()); | 1066 Visit(node->value()); |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1113 | 1113 |
1114 | 1114 |
1115 void AstPrinter::VisitUnaryOperation(UnaryOperation* node) { | 1115 void AstPrinter::VisitUnaryOperation(UnaryOperation* node) { |
1116 IndentedScope indent(this, Token::Name(node->op())); | 1116 IndentedScope indent(this, Token::Name(node->op())); |
1117 Visit(node->expression()); | 1117 Visit(node->expression()); |
1118 } | 1118 } |
1119 | 1119 |
1120 | 1120 |
1121 void AstPrinter::VisitCountOperation(CountOperation* node) { | 1121 void AstPrinter::VisitCountOperation(CountOperation* node) { |
1122 EmbeddedVector<char, 128> buf; | 1122 EmbeddedVector<char, 128> buf; |
1123 OS::SNPrintF(buf, "%s %s", (node->is_prefix() ? "PRE" : "POST"), | 1123 SNPrintF(buf, "%s %s", (node->is_prefix() ? "PRE" : "POST"), |
1124 Token::Name(node->op())); | 1124 Token::Name(node->op())); |
1125 IndentedScope indent(this, buf.start()); | 1125 IndentedScope indent(this, buf.start()); |
1126 Visit(node->expression()); | 1126 Visit(node->expression()); |
1127 } | 1127 } |
1128 | 1128 |
1129 | 1129 |
1130 void AstPrinter::VisitBinaryOperation(BinaryOperation* node) { | 1130 void AstPrinter::VisitBinaryOperation(BinaryOperation* node) { |
1131 IndentedScope indent(this, Token::Name(node->op())); | 1131 IndentedScope indent(this, Token::Name(node->op())); |
1132 Visit(node->left()); | 1132 Visit(node->left()); |
1133 Visit(node->right()); | 1133 Visit(node->right()); |
1134 } | 1134 } |
1135 | 1135 |
1136 | 1136 |
1137 void AstPrinter::VisitCompareOperation(CompareOperation* node) { | 1137 void AstPrinter::VisitCompareOperation(CompareOperation* node) { |
1138 IndentedScope indent(this, Token::Name(node->op())); | 1138 IndentedScope indent(this, Token::Name(node->op())); |
1139 Visit(node->left()); | 1139 Visit(node->left()); |
1140 Visit(node->right()); | 1140 Visit(node->right()); |
1141 } | 1141 } |
1142 | 1142 |
1143 | 1143 |
1144 void AstPrinter::VisitThisFunction(ThisFunction* node) { | 1144 void AstPrinter::VisitThisFunction(ThisFunction* node) { |
1145 IndentedScope indent(this, "THIS-FUNCTION"); | 1145 IndentedScope indent(this, "THIS-FUNCTION"); |
1146 } | 1146 } |
1147 | 1147 |
1148 #endif // DEBUG | 1148 #endif // DEBUG |
1149 | 1149 |
1150 } } // namespace v8::internal | 1150 } } // namespace v8::internal |
OLD | NEW |