Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(19)

Side by Side Diff: src/ast/prettyprinter.h

Issue 2142233003: Templatize AstVisitor with its subclass (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Addressed comments Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/ast/ast-numbering.cc ('k') | src/compiler/ast-graph-builder.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 // Prints the AST structure 56 class AstPrinter final : public AstVisitor<AstPrinter> {
57 class AstPrinter : public AstVisitor {
58 public: 57 public:
59 explicit AstPrinter(Isolate* isolate); 58 explicit AstPrinter(Isolate* isolate);
60 virtual ~AstPrinter(); 59 ~AstPrinter();
61 60
62 // The following routines print a node into a string. 61 // The following routines print a node into a string.
63 // The result string is alive as long as the PrettyPrinter is alive. 62 // The result string is alive as long as the AstPrinter is alive.
64 const char* Print(AstNode* node); 63 const char* Print(AstNode* node);
65 const char* PrintProgram(FunctionLiteral* program); 64 const char* PrintProgram(FunctionLiteral* program);
66 65
67 void PRINTF_FORMAT(2, 3) Print(const char* format, ...); 66 void PRINTF_FORMAT(2, 3) Print(const char* format, ...);
68 67
69 // Print a node to stdout. 68 // Print a node to stdout.
70 static void PrintOut(Isolate* isolate, AstNode* node); 69 static void PrintOut(Isolate* isolate, AstNode* node);
71 70
72 // Individual nodes 71 // Individual nodes
73 #define DECLARE_VISIT(type) void Visit##type(type* node) override; 72 #define DECLARE_VISIT(type) void Visit##type(type* node);
74 AST_NODE_LIST(DECLARE_VISIT) 73 AST_NODE_LIST(DECLARE_VISIT)
75 #undef DECLARE_VISIT 74 #undef DECLARE_VISIT
76 75
77 private: 76 private:
78 friend class IndentedScope; 77 friend class IndentedScope;
79 78
80 void Init(); 79 void Init();
81 80
82 void PrintLabels(ZoneList<const AstRawString*>* labels); 81 void PrintLabels(ZoneList<const AstRawString*>* labels);
83 void PrintLiteral(const AstRawString* value, bool quote); 82 void PrintLiteral(const AstRawString* value, bool quote);
(...skipping 25 matching lines...) Expand all
109 int pos_; // current printing position 108 int pos_; // current printing position
110 int indent_; 109 int indent_;
111 }; 110 };
112 111
113 #endif // DEBUG 112 #endif // DEBUG
114 113
115 } // namespace internal 114 } // namespace internal
116 } // namespace v8 115 } // namespace v8
117 116
118 #endif // V8_AST_PRETTYPRINTER_H_ 117 #endif // V8_AST_PRETTYPRINTER_H_
OLDNEW
« no previous file with comments | « src/ast/ast-numbering.cc ('k') | src/compiler/ast-graph-builder.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698