| 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 430 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 441 } | 441 } |
| 442 output_[0] = '\0'; | 442 output_[0] = '\0'; |
| 443 pos_ = 0; | 443 pos_ = 0; |
| 444 } | 444 } |
| 445 | 445 |
| 446 | 446 |
| 447 void PrettyPrinter::Print(const char* format, ...) { | 447 void PrettyPrinter::Print(const char* format, ...) { |
| 448 for (;;) { | 448 for (;;) { |
| 449 va_list arguments; | 449 va_list arguments; |
| 450 va_start(arguments, format); | 450 va_start(arguments, format); |
| 451 int available = size_ - pos_; | 451 int n = OS::VSNPrintF(Vector<char>(output_, size_) + pos_, |
| 452 int n = OS::VSNPrintF(output_ + pos_, available, format, arguments); | 452 format, |
| 453 arguments); |
| 453 va_end(arguments); | 454 va_end(arguments); |
| 454 | 455 |
| 455 if (n >= 0) { | 456 if (n >= 0) { |
| 456 // there was enough space - we are done | 457 // there was enough space - we are done |
| 457 pos_ += n; | 458 pos_ += n; |
| 458 return; | 459 return; |
| 459 } else { | 460 } else { |
| 460 // there was not enough space - allocate more and try again | 461 // there was not enough space - allocate more and try again |
| 461 const int slack = 32; | 462 const int slack = 32; |
| 462 int new_size = size_ + (size_ >> 1) + slack; | 463 int new_size = size_ + (size_ >> 1) + slack; |
| (...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 641 Print("\n"); | 642 Print("\n"); |
| 642 } | 643 } |
| 643 | 644 |
| 644 | 645 |
| 645 void AstPrinter::PrintLiteralWithModeIndented(const char* info, | 646 void AstPrinter::PrintLiteralWithModeIndented(const char* info, |
| 646 Variable* var, | 647 Variable* var, |
| 647 Handle<Object> value) { | 648 Handle<Object> value) { |
| 648 if (var == NULL) { | 649 if (var == NULL) { |
| 649 PrintLiteralIndented(info, value, true); | 650 PrintLiteralIndented(info, value, true); |
| 650 } else { | 651 } else { |
| 651 char buf[256]; | 652 EmbeddedVector<char, 256> buf; |
| 652 OS::SNPrintF(buf, sizeof(buf), "%s (mode = %s)", info, | 653 OS::SNPrintF(buf, "%s (mode = %s)", info, |
| 653 Variable::Mode2String(var->mode())); | 654 Variable::Mode2String(var->mode())); |
| 654 PrintLiteralIndented(buf, value, true); | 655 PrintLiteralIndented(buf.start(), value, true); |
| 655 } | 656 } |
| 656 } | 657 } |
| 657 | 658 |
| 658 | 659 |
| 659 void AstPrinter::PrintLabelsIndented(const char* info, ZoneStringList* labels) { | 660 void AstPrinter::PrintLabelsIndented(const char* info, ZoneStringList* labels) { |
| 660 if (labels != NULL && labels->length() > 0) { | 661 if (labels != NULL && labels->length() > 0) { |
| 661 if (info == NULL) { | 662 if (info == NULL) { |
| 662 PrintIndented("LABELS "); | 663 PrintIndented("LABELS "); |
| 663 } else { | 664 } else { |
| 664 PrintIndented(info); | 665 PrintIndented(info); |
| (...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1012 PrintArguments(node->arguments()); | 1013 PrintArguments(node->arguments()); |
| 1013 } | 1014 } |
| 1014 | 1015 |
| 1015 | 1016 |
| 1016 void AstPrinter::VisitUnaryOperation(UnaryOperation* node) { | 1017 void AstPrinter::VisitUnaryOperation(UnaryOperation* node) { |
| 1017 PrintIndentedVisit(Token::Name(node->op()), node->expression()); | 1018 PrintIndentedVisit(Token::Name(node->op()), node->expression()); |
| 1018 } | 1019 } |
| 1019 | 1020 |
| 1020 | 1021 |
| 1021 void AstPrinter::VisitCountOperation(CountOperation* node) { | 1022 void AstPrinter::VisitCountOperation(CountOperation* node) { |
| 1022 char buf[128]; | 1023 EmbeddedVector<char, 128> buf; |
| 1023 OS::SNPrintF(buf, sizeof(buf), "%s %s", (node->is_prefix() ? "PRE" : "POST"), | 1024 OS::SNPrintF(buf, "%s %s", (node->is_prefix() ? "PRE" : "POST"), |
| 1024 Token::Name(node->op())); | 1025 Token::Name(node->op())); |
| 1025 PrintIndentedVisit(buf, node->expression()); | 1026 PrintIndentedVisit(buf.start(), node->expression()); |
| 1026 } | 1027 } |
| 1027 | 1028 |
| 1028 | 1029 |
| 1029 void AstPrinter::VisitBinaryOperation(BinaryOperation* node) { | 1030 void AstPrinter::VisitBinaryOperation(BinaryOperation* node) { |
| 1030 IndentedScope indent(Token::Name(node->op())); | 1031 IndentedScope indent(Token::Name(node->op())); |
| 1031 Visit(node->left()); | 1032 Visit(node->left()); |
| 1032 Visit(node->right()); | 1033 Visit(node->right()); |
| 1033 } | 1034 } |
| 1034 | 1035 |
| 1035 | 1036 |
| 1036 void AstPrinter::VisitCompareOperation(CompareOperation* node) { | 1037 void AstPrinter::VisitCompareOperation(CompareOperation* node) { |
| 1037 IndentedScope indent(Token::Name(node->op())); | 1038 IndentedScope indent(Token::Name(node->op())); |
| 1038 Visit(node->left()); | 1039 Visit(node->left()); |
| 1039 Visit(node->right()); | 1040 Visit(node->right()); |
| 1040 } | 1041 } |
| 1041 | 1042 |
| 1042 | 1043 |
| 1043 void AstPrinter::VisitThisFunction(ThisFunction* node) { | 1044 void AstPrinter::VisitThisFunction(ThisFunction* node) { |
| 1044 IndentedScope indent("THIS-FUNCTION"); | 1045 IndentedScope indent("THIS-FUNCTION"); |
| 1045 } | 1046 } |
| 1046 | 1047 |
| 1047 | 1048 |
| 1048 | 1049 |
| 1049 #endif // DEBUG | 1050 #endif // DEBUG |
| 1050 | 1051 |
| 1051 } } // namespace v8::internal | 1052 } } // namespace v8::internal |
| OLD | NEW |