v8  3.25.30(node0.11.13)
V8 is Google's open source JavaScript engine
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
prettyprinter.h
Go to the documentation of this file.
1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are
4 // met:
5 //
6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided
11 // with the distribution.
12 // * Neither the name of Google Inc. nor the names of its
13 // contributors may be used to endorse or promote products derived
14 // from this software without specific prior written permission.
15 //
16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 
28 #ifndef V8_PRETTYPRINTER_H_
29 #define V8_PRETTYPRINTER_H_
30 
31 #include "allocation.h"
32 #include "ast.h"
33 
34 namespace v8 {
35 namespace internal {
36 
37 #ifdef DEBUG
38 
39 class PrettyPrinter: public AstVisitor {
40  public:
41  explicit PrettyPrinter(Zone* zone);
42  virtual ~PrettyPrinter();
43 
44  // The following routines print a node into a string.
45  // The result string is alive as long as the PrettyPrinter is alive.
46  const char* Print(AstNode* node);
47  const char* PrintExpression(FunctionLiteral* program);
48  const char* PrintProgram(FunctionLiteral* program);
49 
50  void Print(const char* format, ...);
51 
52  // Print a node to stdout.
53  static void PrintOut(Zone* zone, AstNode* node);
54 
55  // Individual nodes
56 #define DECLARE_VISIT(type) virtual void Visit##type(type* node);
58 #undef DECLARE_VISIT
59 
60  private:
61  char* output_; // output string buffer
62  int size_; // output_ size
63  int pos_; // current printing position
64 
65  protected:
66  void Init();
67  const char* Output() const { return output_; }
68 
69  virtual void PrintStatements(ZoneList<Statement*>* statements);
70  void PrintLabels(ZoneStringList* labels);
71  virtual void PrintArguments(ZoneList<Expression*>* arguments);
72  void PrintLiteral(Handle<Object> value, bool quote);
73  void PrintParameters(Scope* scope);
74  void PrintDeclarations(ZoneList<Declaration*>* declarations);
75  void PrintFunctionLiteral(FunctionLiteral* function);
76  void PrintCaseClause(CaseClause* clause);
77 
79 };
80 
81 
82 // Prints the AST structure
83 class AstPrinter: public PrettyPrinter {
84  public:
85  explicit AstPrinter(Zone* zone);
86  virtual ~AstPrinter();
87 
88  const char* PrintProgram(FunctionLiteral* program);
89 
90  // Individual nodes
91 #define DECLARE_VISIT(type) virtual void Visit##type(type* node);
93 #undef DECLARE_VISIT
94 
95  private:
96  friend class IndentedScope;
97  void PrintIndented(const char* txt);
98  void PrintIndentedVisit(const char* s, AstNode* node);
99 
100  void PrintStatements(ZoneList<Statement*>* statements);
101  void PrintDeclarations(ZoneList<Declaration*>* declarations);
102  void PrintParameters(Scope* scope);
103  void PrintArguments(ZoneList<Expression*>* arguments);
104  void PrintCaseClause(CaseClause* clause);
105  void PrintLiteralIndented(const char* info, Handle<Object> value, bool quote);
106  void PrintLiteralWithModeIndented(const char* info,
107  Variable* var,
108  Handle<Object> value);
109  void PrintLabelsIndented(ZoneStringList* labels);
110 
111  void inc_indent() { indent_++; }
112  void dec_indent() { indent_--; }
113 
114  int indent_;
115 };
116 
117 #endif // DEBUG
118 
119 } } // namespace v8::internal
120 
121 #endif // V8_PRETTYPRINTER_H_
#define DECLARE_VISIT(type)
Definition: full-codegen.h:629
#define DEFINE_AST_VISITOR_SUBCLASS_MEMBERS()
Definition: ast.h:2878
#define AST_NODE_LIST(V)
Definition: ast.h:121
enable upcoming ES6 features enable harmony block scoping enable harmony enable harmony proxies enable harmony generators enable harmony numeric enable harmony string enable harmony math functions harmony_scoping harmony_symbols harmony_collections harmony_iteration harmony_strings harmony_scoping harmony_maths tracks arrays with only smi values Optimize object Array DOM strings and string pretenure call new trace pretenuring decisions of HAllocate instructions track fields with only smi values track fields with heap values track_fields track_fields Enables optimizations which favor memory size over execution speed use string slices optimization filter maximum number of GVN fix point iterations use function inlining use allocation folding eliminate write barriers targeting allocations in optimized code maximum source size in bytes considered for a single inlining maximum cumulative number of AST nodes considered for inlining crankshaft harvests type feedback from stub cache trace check elimination phase hydrogen tracing filter trace hydrogen to given file name trace inlining decisions trace store elimination trace all use positions trace global value numbering trace hydrogen escape analysis trace the tracking of allocation sites trace map generalization environment for every instruction deoptimize every n garbage collections put a break point before deoptimizing deoptimize uncommon cases use on stack replacement trace array bounds check elimination perform array index dehoisting use load elimination use store elimination use constant folding eliminate unreachable code number of stress runs when picking a function to watch for shared function info
Definition: flags.cc:317
void Print(const v8::FunctionCallbackInfo< v8::Value > &args)
ZoneList< Handle< String > > ZoneStringList
Definition: ast.h:161