OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 20 matching lines...) Expand all Loading... |
31 | 31 |
32 #include "prettyprinter.h" | 32 #include "prettyprinter.h" |
33 #include "scopes.h" | 33 #include "scopes.h" |
34 #include "platform.h" | 34 #include "platform.h" |
35 | 35 |
36 namespace v8 { | 36 namespace v8 { |
37 namespace internal { | 37 namespace internal { |
38 | 38 |
39 #ifdef DEBUG | 39 #ifdef DEBUG |
40 | 40 |
41 PrettyPrinter::PrettyPrinter() { | 41 PrettyPrinter::PrettyPrinter(Isolate* isolate) { |
42 output_ = NULL; | 42 output_ = NULL; |
43 size_ = 0; | 43 size_ = 0; |
44 pos_ = 0; | 44 pos_ = 0; |
45 InitializeAstVisitor(); | 45 InitializeAstVisitor(isolate); |
46 } | 46 } |
47 | 47 |
48 | 48 |
49 PrettyPrinter::~PrettyPrinter() { | 49 PrettyPrinter::~PrettyPrinter() { |
50 DeleteArray(output_); | 50 DeleteArray(output_); |
51 } | 51 } |
52 | 52 |
53 | 53 |
54 void PrettyPrinter::VisitBlock(Block* node) { | 54 void PrettyPrinter::VisitBlock(Block* node) { |
55 if (!node->is_initializer_block()) Print("{ "); | 55 if (!node->is_initializer_block()) Print("{ "); |
(...skipping 417 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
473 | 473 |
474 | 474 |
475 const char* PrettyPrinter::PrintProgram(FunctionLiteral* program) { | 475 const char* PrettyPrinter::PrintProgram(FunctionLiteral* program) { |
476 Init(); | 476 Init(); |
477 PrintStatements(program->body()); | 477 PrintStatements(program->body()); |
478 Print("\n"); | 478 Print("\n"); |
479 return output_; | 479 return output_; |
480 } | 480 } |
481 | 481 |
482 | 482 |
483 void PrettyPrinter::PrintOut(AstNode* node) { | 483 void PrettyPrinter::PrintOut(Isolate* isolate, AstNode* node) { |
484 PrettyPrinter printer; | 484 PrettyPrinter printer(isolate); |
485 PrintF("%s", printer.Print(node)); | 485 PrintF("%s", printer.Print(node)); |
486 } | 486 } |
487 | 487 |
488 | 488 |
489 void PrettyPrinter::Init() { | 489 void PrettyPrinter::Init() { |
490 if (size_ == 0) { | 490 if (size_ == 0) { |
491 ASSERT(output_ == NULL); | 491 ASSERT(output_ == NULL); |
492 const int initial_size = 256; | 492 const int initial_size = 256; |
493 output_ = NewArray<char>(initial_size); | 493 output_ = NewArray<char>(initial_size); |
494 size_ = initial_size; | 494 size_ = initial_size; |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
651 } | 651 } |
652 | 652 |
653 private: | 653 private: |
654 AstPrinter* ast_printer_; | 654 AstPrinter* ast_printer_; |
655 }; | 655 }; |
656 | 656 |
657 | 657 |
658 //----------------------------------------------------------------------------- | 658 //----------------------------------------------------------------------------- |
659 | 659 |
660 | 660 |
661 AstPrinter::AstPrinter() : indent_(0) { | 661 AstPrinter::AstPrinter(Isolate* isolate) : PrettyPrinter(isolate), indent_(0) { |
662 } | 662 } |
663 | 663 |
664 | 664 |
665 AstPrinter::~AstPrinter() { | 665 AstPrinter::~AstPrinter() { |
666 ASSERT(indent_ == 0); | 666 ASSERT(indent_ == 0); |
667 } | 667 } |
668 | 668 |
669 | 669 |
670 void AstPrinter::PrintIndented(const char* txt) { | 670 void AstPrinter::PrintIndented(const char* txt) { |
671 for (int i = 0; i < indent_; i++) { | 671 for (int i = 0; i < indent_; i++) { |
(...skipping 488 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1160 } | 1160 } |
1161 | 1161 |
1162 | 1162 |
1163 void AstPrinter::VisitThisFunction(ThisFunction* node) { | 1163 void AstPrinter::VisitThisFunction(ThisFunction* node) { |
1164 IndentedScope indent(this, "THIS-FUNCTION"); | 1164 IndentedScope indent(this, "THIS-FUNCTION"); |
1165 } | 1165 } |
1166 | 1166 |
1167 #endif // DEBUG | 1167 #endif // DEBUG |
1168 | 1168 |
1169 } } // namespace v8::internal | 1169 } } // namespace v8::internal |
OLD | NEW |