Chromium Code Reviews| 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_AST_PRETTYPRINTER_H_ | 5 #ifndef V8_AST_PRETTYPRINTER_H_ |
| 6 #define V8_AST_PRETTYPRINTER_H_ | 6 #define V8_AST_PRETTYPRINTER_H_ |
| 7 | 7 |
| 8 #include "src/allocation.h" | 8 #include "src/allocation.h" |
| 9 #include "src/ast/ast.h" | 9 #include "src/ast/ast.h" |
| 10 #include "src/base/compiler-specific.h" | 10 #include "src/base/compiler-specific.h" |
| 11 | 11 |
| 12 namespace v8 { | 12 namespace v8 { |
| 13 namespace internal { | 13 namespace internal { |
| 14 | 14 |
| 15 class CallPrinter : public AstVisitor { | 15 class CallPrinter final : public AstVisitor<CallPrinter> { |
| 16 public: | 16 public: |
| 17 explicit CallPrinter(Isolate* isolate, bool is_builtin); | 17 explicit CallPrinter(Isolate* isolate, bool is_builtin); |
| 18 virtual ~CallPrinter(); | 18 ~CallPrinter(); |
| 19 | 19 |
| 20 // The following routine prints the node with position |position| into a | 20 // The following routine prints the node with position |position| into a |
| 21 // string. The result string is alive as long as the CallPrinter is alive. | 21 // string. The result string is alive as long as the CallPrinter is alive. |
| 22 const char* Print(FunctionLiteral* program, int position); | 22 const char* Print(FunctionLiteral* program, int position); |
| 23 | 23 |
| 24 void PRINTF_FORMAT(2, 3) Print(const char* format, ...); | 24 void PRINTF_FORMAT(2, 3) Print(const char* format, ...); |
| 25 | 25 |
| 26 void Find(AstNode* node, bool print = false); | 26 void Find(AstNode* node, bool print = false); |
| 27 | 27 |
| 28 // Individual nodes | 28 // Individual nodes |
| 29 #define DECLARE_VISIT(type) void Visit##type(type* node) override; | 29 #define DECLARE_VISIT(type) void Visit##type(type* node); |
| 30 AST_NODE_LIST(DECLARE_VISIT) | 30 AST_NODE_LIST(DECLARE_VISIT) |
| 31 #undef DECLARE_VISIT | 31 #undef DECLARE_VISIT |
| 32 | 32 |
| 33 private: | 33 private: |
| 34 void Init(); | 34 void Init(); |
| 35 Isolate* isolate_; | 35 Isolate* isolate_; |
| 36 char* output_; // output string buffer | 36 char* output_; // output string buffer |
| 37 int size_; // output_ size | 37 int size_; // output_ size |
| 38 int pos_; // current printing position | 38 int pos_; // current printing position |
| 39 int position_; // position of ast node to print | 39 int position_; // position of ast node to print |
| 40 bool found_; | 40 bool found_; |
| 41 bool done_; | 41 bool done_; |
| 42 bool is_builtin_; | 42 bool is_builtin_; |
| 43 | 43 |
| 44 DEFINE_AST_VISITOR_SUBCLASS_MEMBERS(); | 44 DEFINE_AST_VISITOR_SUBCLASS_MEMBERS(); |
| 45 | 45 |
| 46 protected: | 46 protected: |
| 47 void PrintLiteral(Object* value, bool quote); | 47 void PrintLiteral(Object* value, bool quote); |
| 48 void PrintLiteral(const AstRawString* value, bool quote); | 48 void PrintLiteral(const AstRawString* value, bool quote); |
| 49 void FindStatements(ZoneList<Statement*>* statements); | 49 void FindStatements(ZoneList<Statement*>* statements); |
| 50 void FindArguments(ZoneList<Expression*>* arguments); | 50 void FindArguments(ZoneList<Expression*>* arguments); |
| 51 }; | 51 }; |
| 52 | 52 |
| 53 | 53 |
| 54 #ifdef DEBUG | 54 #ifdef DEBUG |
| 55 | 55 |
| 56 class PrettyPrinter: public AstVisitor { | 56 class PrettyPrinter : public AstVisitor<PrettyPrinter> { |
|
Igor Sheludko
2016/07/14 16:39:54
Same here (see HOptimizedGraphBuilder).
Toon Verwaest
2016/07/15 07:07:20
Done.
| |
| 57 public: | 57 public: |
| 58 explicit PrettyPrinter(Isolate* isolate); | 58 explicit PrettyPrinter(Isolate* isolate); |
| 59 virtual ~PrettyPrinter(); | 59 virtual ~PrettyPrinter(); |
| 60 | 60 |
| 61 // The following routines print a node into a string. | 61 // The following routines print a node into a string. |
| 62 // The result string is alive as long as the PrettyPrinter is alive. | 62 // The result string is alive as long as the PrettyPrinter is alive. |
| 63 const char* Print(AstNode* node); | 63 const char* Print(AstNode* node); |
| 64 const char* PrintExpression(FunctionLiteral* program); | 64 const char* PrintExpression(FunctionLiteral* program); |
| 65 const char* PrintProgram(FunctionLiteral* program); | 65 const char* PrintProgram(FunctionLiteral* program); |
| 66 | 66 |
| 67 void PRINTF_FORMAT(2, 3) Print(const char* format, ...); | 67 void PRINTF_FORMAT(2, 3) Print(const char* format, ...); |
| 68 | 68 |
| 69 // Print a node to stdout. | 69 // Print a node to stdout. |
| 70 static void PrintOut(Isolate* isolate, AstNode* node); | 70 static void PrintOut(Isolate* isolate, AstNode* node); |
| 71 | 71 |
| 72 // Individual nodes | 72 // Individual nodes |
| 73 #define DECLARE_VISIT(type) void Visit##type(type* node) override; | 73 #define DECLARE_VISIT(type) virtual void Visit##type(type* node); |
| 74 AST_NODE_LIST(DECLARE_VISIT) | 74 AST_NODE_LIST(DECLARE_VISIT) |
| 75 #undef DECLARE_VISIT | 75 #undef DECLARE_VISIT |
| 76 | 76 |
| 77 private: | 77 private: |
| 78 Isolate* isolate_; | 78 Isolate* isolate_; |
| 79 char* output_; // output string buffer | 79 char* output_; // output string buffer |
| 80 int size_; // output_ size | 80 int size_; // output_ size |
| 81 int pos_; // current printing position | 81 int pos_; // current printing position |
| 82 | 82 |
| 83 protected: | 83 protected: |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 104 public: | 104 public: |
| 105 explicit AstPrinter(Isolate* isolate); | 105 explicit AstPrinter(Isolate* isolate); |
| 106 virtual ~AstPrinter(); | 106 virtual ~AstPrinter(); |
| 107 | 107 |
| 108 const char* PrintProgram(FunctionLiteral* program); | 108 const char* PrintProgram(FunctionLiteral* program); |
| 109 | 109 |
| 110 // Print a node to stdout. | 110 // Print a node to stdout. |
| 111 static void PrintOut(Isolate* isolate, AstNode* node); | 111 static void PrintOut(Isolate* isolate, AstNode* node); |
| 112 | 112 |
| 113 // Individual nodes | 113 // Individual nodes |
| 114 #define DECLARE_VISIT(type) virtual void Visit##type(type* node); | 114 #define DECLARE_VISIT(type) void Visit##type(type* node) override; |
| 115 AST_NODE_LIST(DECLARE_VISIT) | 115 AST_NODE_LIST(DECLARE_VISIT) |
| 116 #undef DECLARE_VISIT | 116 #undef DECLARE_VISIT |
| 117 | 117 |
| 118 private: | 118 private: |
| 119 friend class IndentedScope; | 119 friend class IndentedScope; |
| 120 void PrintIndented(const char* txt); | 120 void PrintIndented(const char* txt); |
| 121 void PrintIndentedVisit(const char* s, AstNode* node); | 121 void PrintIndentedVisit(const char* s, AstNode* node); |
| 122 | 122 |
| 123 void PrintStatements(ZoneList<Statement*>* statements); | 123 void PrintStatements(ZoneList<Statement*>* statements) override; |
| 124 void PrintDeclarations(ZoneList<Declaration*>* declarations); | 124 void PrintDeclarations(ZoneList<Declaration*>* declarations); |
| 125 void PrintParameters(Scope* scope); | 125 void PrintParameters(Scope* scope); |
| 126 void PrintArguments(ZoneList<Expression*>* arguments); | 126 void PrintArguments(ZoneList<Expression*>* arguments) override; |
| 127 void PrintCaseClause(CaseClause* clause); | 127 void PrintCaseClause(CaseClause* clause); |
| 128 void PrintLiteralIndented(const char* info, Handle<Object> value, bool quote); | 128 void PrintLiteralIndented(const char* info, Handle<Object> value, bool quote); |
| 129 void PrintLiteralWithModeIndented(const char* info, | 129 void PrintLiteralWithModeIndented(const char* info, |
| 130 Variable* var, | 130 Variable* var, |
| 131 Handle<Object> value); | 131 Handle<Object> value); |
| 132 void PrintLabelsIndented(ZoneList<const AstRawString*>* labels); | 132 void PrintLabelsIndented(ZoneList<const AstRawString*>* labels); |
| 133 void PrintProperties(ZoneList<ObjectLiteral::Property*>* properties); | 133 void PrintProperties(ZoneList<ObjectLiteral::Property*>* properties); |
| 134 | 134 |
| 135 void inc_indent() { indent_++; } | 135 void inc_indent() { indent_++; } |
| 136 void dec_indent() { indent_--; } | 136 void dec_indent() { indent_--; } |
| 137 | 137 |
| 138 int indent_; | 138 int indent_; |
| 139 }; | 139 }; |
| 140 | 140 |
| 141 #endif // DEBUG | 141 #endif // DEBUG |
| 142 | 142 |
| 143 } // namespace internal | 143 } // namespace internal |
| 144 } // namespace v8 | 144 } // namespace v8 |
| 145 | 145 |
| 146 #endif // V8_AST_PRETTYPRINTER_H_ | 146 #endif // V8_AST_PRETTYPRINTER_H_ |
| OLD | NEW |