| 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 #ifndef V8_PRETTYPRINTER_H_ | 5 #ifndef V8_PRETTYPRINTER_H_ |
| 6 #define V8_PRETTYPRINTER_H_ | 6 #define V8_PRETTYPRINTER_H_ |
| 7 | 7 |
| 8 #include "src/allocation.h" | 8 #include "src/allocation.h" |
| 9 #include "src/ast.h" | 9 #include "src/ast.h" |
| 10 | 10 |
| 11 namespace v8 { | 11 namespace v8 { |
| 12 namespace internal { | 12 namespace internal { |
| 13 | 13 |
| 14 class CallPrinter : public AstVisitor { |
| 15 public: |
| 16 explicit CallPrinter(Zone* zone); |
| 17 virtual ~CallPrinter(); |
| 18 |
| 19 // The following routine prints the node with position |position| into a |
| 20 // string. The result string is alive as long as the CallPrinter is alive. |
| 21 const char* Print(FunctionLiteral* program, int position); |
| 22 |
| 23 void Print(const char* format, ...); |
| 24 |
| 25 void Find(AstNode* node, bool print = false); |
| 26 |
| 27 // Individual nodes |
| 28 #define DECLARE_VISIT(type) void Visit##type(type* node) OVERRIDE; |
| 29 AST_NODE_LIST(DECLARE_VISIT) |
| 30 #undef DECLARE_VISIT |
| 31 |
| 32 private: |
| 33 void Init(); |
| 34 char* output_; // output string buffer |
| 35 int size_; // output_ size |
| 36 int pos_; // current printing position |
| 37 int position_; // position of ast node to print |
| 38 bool found_; |
| 39 bool done_; |
| 40 |
| 41 DEFINE_AST_VISITOR_SUBCLASS_MEMBERS(); |
| 42 |
| 43 protected: |
| 44 void PrintLiteral(Handle<Object> value, bool quote); |
| 45 void PrintLiteral(const AstRawString* value, bool quote); |
| 46 void FindStatements(ZoneList<Statement*>* statements); |
| 47 void FindArguments(ZoneList<Expression*>* arguments); |
| 48 }; |
| 49 |
| 50 |
| 14 #ifdef DEBUG | 51 #ifdef DEBUG |
| 15 | 52 |
| 16 class PrettyPrinter: public AstVisitor { | 53 class PrettyPrinter: public AstVisitor { |
| 17 public: | 54 public: |
| 18 explicit PrettyPrinter(Zone* zone); | 55 explicit PrettyPrinter(Zone* zone); |
| 19 virtual ~PrettyPrinter(); | 56 virtual ~PrettyPrinter(); |
| 20 | 57 |
| 21 // The following routines print a node into a string. | 58 // The following routines print a node into a string. |
| 22 // The result string is alive as long as the PrettyPrinter is alive. | 59 // The result string is alive as long as the PrettyPrinter is alive. |
| 23 const char* Print(AstNode* node); | 60 const char* Print(AstNode* node); |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 91 void dec_indent() { indent_--; } | 128 void dec_indent() { indent_--; } |
| 92 | 129 |
| 93 int indent_; | 130 int indent_; |
| 94 }; | 131 }; |
| 95 | 132 |
| 96 #endif // DEBUG | 133 #endif // DEBUG |
| 97 | 134 |
| 98 } } // namespace v8::internal | 135 } } // namespace v8::internal |
| 99 | 136 |
| 100 #endif // V8_PRETTYPRINTER_H_ | 137 #endif // V8_PRETTYPRINTER_H_ |
| OLD | NEW |