v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
prettyprinter.h
Go to the documentation of this file.
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
3// found in the LICENSE file.
4
5#ifndef V8_AST_PRETTYPRINTER_H_
6#define V8_AST_PRETTYPRINTER_H_
7
8#include "src/ast/ast.h"
13
14namespace v8 {
15namespace internal {
16
17class CallPrinter final : public AstVisitor<CallPrinter> {
18 public:
20
21 explicit CallPrinter(Isolate* isolate, bool is_user_js,
22 SpreadErrorInArgsHint error_in_spread_args =
25
26 // The following routine prints the node with position |position| into a
27 // string.
36
37 ErrorHint GetErrorHint() const;
38 Expression* spread_arg() const { return spread_arg_; }
45
46// Individual nodes
47#define DECLARE_VISIT(type) void Visit##type(type* node);
49#undef DECLARE_VISIT
50
51 private:
52 void Print(char c);
53 void Print(const char* str);
54 void Print(DirectHandle<String> str);
55
56 void Find(AstNode* node, bool print = false);
57
61 int position_; // position of ast node to print
62 bool found_;
63 bool done_;
74
75 protected:
76 void PrintLiteral(DirectHandle<Object> value, bool quote);
77 void PrintLiteral(const AstRawString* value, bool quote);
78 void FindStatements(const ZonePtrList<Statement>* statements);
79 void FindArguments(const ZonePtrList<Expression>* arguments);
80};
81
82
83#ifdef DEBUG
84
85class AstPrinter final : public AstVisitor<AstPrinter> {
86 public:
87 explicit AstPrinter(uintptr_t stack_limit);
88 ~AstPrinter();
89
90 // The following routines print a node into a string.
91 // The result string is alive as long as the AstPrinter is alive.
92 const char* Print(AstNode* node);
93 const char* PrintProgram(FunctionLiteral* program);
94
95 void PRINTF_FORMAT(2, 3) Print(const char* format, ...);
96
97 // Print a node to stdout.
98 static void PrintOut(Isolate* isolate, AstNode* node);
99
100 // Individual nodes
101#define DECLARE_VISIT(type) void Visit##type(type* node);
103#undef DECLARE_VISIT
104
105 private:
106 friend class IndentedScope;
107
108 void Init();
109
110 void PrintLabels(ZonePtrList<const AstRawString>* labels);
111 void PrintLiteral(const AstRawString* value, bool quote);
112 void PrintLiteral(const AstConsString* value, bool quote);
113 void PrintLiteral(Literal* literal, bool quote);
114 void PrintIndented(const char* txt);
115 void PrintIndentedVisit(const char* s, AstNode* node);
116
117 void PrintStatements(const ZonePtrList<Statement>* statements);
118 void PrintDeclarations(Declaration::List* declarations);
119 void PrintParameters(DeclarationScope* scope);
120 void PrintArguments(const ZonePtrList<Expression>* arguments);
121 void PrintCaseClause(CaseClause* clause);
122 void PrintLiteralIndented(const char* info, Literal* literal, bool quote);
123 void PrintLiteralIndented(const char* info, const AstRawString* value,
124 bool quote);
125 void PrintLiteralIndented(const char* info, const AstConsString* value,
126 bool quote);
127 void PrintLiteralWithModeIndented(const char* info, Variable* var,
128 const AstRawString* value);
129 void PrintLabelsIndented(ZonePtrList<const AstRawString>* labels,
130 const char* prefix = "");
131 void PrintObjectProperties(
132 const ZonePtrList<ObjectLiteral::Property>* properties);
133 void PrintClassProperty(ClassLiteral::Property* property);
134 void PrintClassProperties(
135 const ZonePtrList<ClassLiteral::Property>* properties);
136 void PrintClassStaticElements(
137 const ZonePtrList<ClassLiteral::StaticElement>* static_elements);
138
139 void inc_indent() { indent_++; }
140 void dec_indent() { indent_--; }
141
143
144 char* output_; // output string buffer
145 int size_; // output_ size
146 int pos_; // current printing position
147 int indent_;
148};
149
150#endif // DEBUG
151
152} // namespace internal
153} // namespace v8
154
155#endif // V8_AST_PRETTYPRINTER_H_
#define DECLARE_VISIT(type)
int pos_
#define DEFINE_AST_VISITOR_SUBCLASS_MEMBERS()
Definition ast.h:2978
#define AST_NODE_LIST(V)
Definition ast.h:121
Assignment * destructuring_assignment_
Expression * spread_arg() const
SpreadErrorInArgsHint error_in_spread_args_
IncrementalStringBuilder builder_
void FindArguments(const ZonePtrList< Expression > *arguments)
void PrintLiteral(DirectHandle< Object > value, bool quote)
ObjectLiteralProperty * destructuring_prop_
ErrorHint GetErrorHint() const
Assignment * destructuring_assignment() const
CallPrinter(Isolate *isolate, bool is_user_js, SpreadErrorInArgsHint error_in_spread_args=SpreadErrorInArgsHint::kNoErrorInArgs)
void Find(AstNode *node, bool print=false)
DirectHandle< String > Print(FunctionLiteral *program, int position)
void FindStatements(const ZonePtrList< Statement > *statements)
ObjectLiteralProperty * destructuring_prop() const
const int size_
Definition assembler.cc:132
Comparator::Output * output_
FunctionLiteral * literal
Definition liveedit.cc:294
int position
Definition liveedit.cc:290
#define PRINTF_FORMAT(format_param, dots_param)