OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2015 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 #include "src/v8.h" | |
6 | |
7 #include "src/ast-expression-visitor.h" | |
8 | |
9 #include "src/ast.h" | |
10 #include "src/codegen.h" | |
11 #include "src/scopes.h" | |
12 | |
13 namespace v8 { | |
14 namespace internal { | |
15 | |
16 | |
17 #define RECURSE(call) \ | |
18 do { \ | |
19 DCHECK(!HasStackOverflow()); \ | |
20 call; \ | |
21 if (HasStackOverflow()) return; \ | |
22 } while (false) | |
23 | |
24 | |
25 AstExpressionVisitor::AstExpressionVisitor(CompilationInfo* info) | |
26 : compilation_info_(info), depth_(0) { | |
27 InitializeAstVisitor(info->isolate(), info->zone()); | |
28 } | |
29 | |
30 | |
31 void AstExpressionVisitor::VisitAll() { | |
32 VisitFunctionLiteral(compilation_info_->function()); | |
33 } | |
34 | |
35 | |
36 void AstExpressionVisitor::VisitVariableDeclaration(VariableDeclaration* decl) { | |
37 } | |
38 | |
39 | |
40 void AstExpressionVisitor::VisitFunctionDeclaration(FunctionDeclaration* decl) { | |
41 RECURSE(Visit(decl->fun())); | |
42 } | |
43 | |
44 | |
45 void AstExpressionVisitor::VisitImportDeclaration(ImportDeclaration* decl) {} | |
46 | |
47 | |
48 void AstExpressionVisitor::VisitExportDeclaration(ExportDeclaration* decl) {} | |
49 | |
50 | |
51 void AstExpressionVisitor::VisitStatements(ZoneList<Statement*>* stmts) { | |
52 for (int i = 0; i < stmts->length(); ++i) { | |
53 Statement* stmt = stmts->at(i); | |
54 RECURSE(Visit(stmt)); | |
55 if (stmt->IsJump()) break; | |
56 } | |
57 } | |
58 | |
59 | |
60 void AstExpressionVisitor::VisitBlock(Block* stmt) { | |
61 RECURSE(VisitStatements(stmt->statements())); | |
62 } | |
63 | |
64 | |
65 void AstExpressionVisitor::VisitExpressionStatement(ExpressionStatement* stmt) { | |
66 RECURSE(Visit(stmt->expression())); | |
67 } | |
68 | |
69 | |
70 void AstExpressionVisitor::VisitEmptyStatement(EmptyStatement* stmt) {} | |
71 | |
72 | |
73 void AstExpressionVisitor::VisitIfStatement(IfStatement* stmt) { | |
74 RECURSE(Visit(stmt->condition())); | |
75 RECURSE(Visit(stmt->then_statement())); | |
76 RECURSE(Visit(stmt->else_statement())); | |
77 } | |
78 | |
79 | |
80 void AstExpressionVisitor::VisitContinueStatement(ContinueStatement* stmt) {} | |
81 | |
82 | |
83 void AstExpressionVisitor::VisitBreakStatement(BreakStatement* stmt) {} | |
84 | |
85 | |
86 void AstExpressionVisitor::VisitReturnStatement(ReturnStatement* stmt) { | |
87 RECURSE(Visit(stmt->expression())); | |
88 } | |
89 | |
90 | |
91 void AstExpressionVisitor::VisitWithStatement(WithStatement* stmt) { | |
92 RECURSE(stmt->expression()); | |
93 RECURSE(stmt->statement()); | |
94 } | |
95 | |
96 | |
97 void AstExpressionVisitor::VisitSwitchStatement(SwitchStatement* stmt) { | |
98 RECURSE(Visit(stmt->tag())); | |
99 | |
100 ZoneList<CaseClause*>* clauses = stmt->cases(); | |
101 | |
102 for (int i = 0; i < clauses->length(); ++i) { | |
103 CaseClause* clause = clauses->at(i); | |
104 Expression* label = clause->label(); | |
105 RECURSE(Visit(label)); | |
106 ZoneList<Statement*>* stmts = clause->statements(); | |
107 RECURSE(VisitStatements(stmts)); | |
108 } | |
109 } | |
110 | |
111 | |
112 void AstExpressionVisitor::VisitCaseClause(CaseClause* clause) { | |
113 UNREACHABLE(); | |
114 } | |
115 | |
116 | |
117 void AstExpressionVisitor::VisitDoWhileStatement(DoWhileStatement* stmt) { | |
118 RECURSE(Visit(stmt->body())); | |
119 RECURSE(Visit(stmt->cond())); | |
120 } | |
121 | |
122 | |
123 void AstExpressionVisitor::VisitWhileStatement(WhileStatement* stmt) { | |
124 RECURSE(Visit(stmt->cond())); | |
125 RECURSE(Visit(stmt->body())); | |
126 } | |
127 | |
128 | |
129 void AstExpressionVisitor::VisitForStatement(ForStatement* stmt) { | |
130 RECURSE(Visit(stmt->init())); | |
131 RECURSE(Visit(stmt->cond())); | |
132 RECURSE(Visit(stmt->next())); | |
133 RECURSE(Visit(stmt->body())); | |
134 } | |
135 | |
136 | |
137 void AstExpressionVisitor::VisitForInStatement(ForInStatement* stmt) { | |
138 RECURSE(Visit(stmt->enumerable())); | |
139 RECURSE(Visit(stmt->body())); | |
140 } | |
141 | |
142 | |
143 void AstExpressionVisitor::VisitForOfStatement(ForOfStatement* stmt) { | |
144 RECURSE(Visit(stmt->iterable())); | |
145 RECURSE(Visit(stmt->body())); | |
146 } | |
147 | |
148 | |
149 void AstExpressionVisitor::VisitTryCatchStatement(TryCatchStatement* stmt) { | |
150 RECURSE(Visit(stmt->try_block())); | |
151 RECURSE(Visit(stmt->catch_block())); | |
152 } | |
153 | |
154 | |
155 void AstExpressionVisitor::VisitTryFinallyStatement(TryFinallyStatement* stmt) { | |
156 RECURSE(Visit(stmt->try_block())); | |
157 RECURSE(Visit(stmt->finally_block())); | |
158 } | |
159 | |
160 | |
161 void AstExpressionVisitor::VisitDebuggerStatement(DebuggerStatement* stmt) {} | |
162 | |
163 | |
164 void AstExpressionVisitor::VisitFunctionLiteral(FunctionLiteral* expr) { | |
165 Scope* scope = expr->scope(); | |
166 VisitExpression(expr); | |
167 ++depth_; | |
titzer
2015/08/19 12:06:37
IIUC, you are using the depth counter as the expre
bradn
2015/08/20 04:01:40
Done.
| |
168 RECURSE(VisitDeclarations(scope->declarations())); | |
169 RECURSE(VisitStatements(expr->body())); | |
170 --depth_; | |
171 } | |
172 | |
173 | |
174 void AstExpressionVisitor::VisitNativeFunctionLiteral( | |
175 NativeFunctionLiteral* expr) {} | |
176 | |
177 | |
178 void AstExpressionVisitor::VisitConditional(Conditional* expr) { | |
179 RECURSE(Visit(expr->condition())); | |
180 RECURSE(Visit(expr->then_expression())); | |
181 RECURSE(Visit(expr->else_expression())); | |
182 } | |
183 | |
184 | |
185 void AstExpressionVisitor::VisitVariableProxy(VariableProxy* expr) { | |
186 VisitExpression(expr); | |
187 } | |
188 | |
189 | |
190 void AstExpressionVisitor::VisitLiteral(Literal* expr) { | |
191 VisitExpression(expr); | |
192 } | |
193 | |
194 | |
195 void AstExpressionVisitor::VisitRegExpLiteral(RegExpLiteral* expr) { | |
196 VisitExpression(expr); | |
197 } | |
198 | |
199 | |
200 void AstExpressionVisitor::VisitObjectLiteral(ObjectLiteral* expr) { | |
201 VisitExpression(expr); | |
202 ++depth_; | |
203 ZoneList<ObjectLiteralProperty*>* props = expr->properties(); | |
204 for (int i = 0; i < props->length(); ++i) { | |
205 ObjectLiteralProperty* prop = props->at(i); | |
206 RECURSE(Visit(prop->value())); | |
207 } | |
208 --depth_; | |
209 } | |
210 | |
211 | |
212 void AstExpressionVisitor::VisitArrayLiteral(ArrayLiteral* expr) { | |
213 VisitExpression(expr); | |
214 ++depth_; | |
215 ZoneList<Expression*>* values = expr->values(); | |
216 for (int i = 0; i < values->length(); ++i) { | |
217 Expression* value = values->at(i); | |
218 RECURSE(Visit(value)); | |
219 } | |
220 --depth_; | |
221 } | |
222 | |
223 | |
224 void AstExpressionVisitor::VisitAssignment(Assignment* expr) { | |
225 VisitExpression(expr); | |
226 ++depth_; | |
227 RECURSE(Visit(expr->target())); | |
228 RECURSE(Visit(expr->value())); | |
229 --depth_; | |
230 } | |
231 | |
232 | |
233 void AstExpressionVisitor::VisitYield(Yield* expr) { | |
234 RECURSE(Visit(expr->generator_object())); | |
235 RECURSE(Visit(expr->expression())); | |
236 } | |
237 | |
238 | |
239 void AstExpressionVisitor::VisitThrow(Throw* expr) { | |
240 RECURSE(Visit(expr->exception())); | |
241 } | |
242 | |
243 | |
244 void AstExpressionVisitor::VisitProperty(Property* expr) { | |
245 RECURSE(Visit(expr->obj())); | |
246 RECURSE(Visit(expr->key())); | |
247 } | |
248 | |
249 | |
250 void AstExpressionVisitor::VisitCall(Call* expr) { | |
251 VisitExpression(expr); | |
252 ++depth_; | |
253 RECURSE(Visit(expr->expression())); | |
254 ZoneList<Expression*>* args = expr->arguments(); | |
255 for (int i = 0; i < args->length(); ++i) { | |
256 Expression* arg = args->at(i); | |
257 RECURSE(Visit(arg)); | |
258 } | |
259 --depth_; | |
260 } | |
261 | |
262 | |
263 void AstExpressionVisitor::VisitCallNew(CallNew* expr) { | |
264 VisitExpression(expr); | |
265 ++depth_; | |
266 RECURSE(Visit(expr->expression())); | |
267 ZoneList<Expression*>* args = expr->arguments(); | |
268 for (int i = 0; i < args->length(); ++i) { | |
269 Expression* arg = args->at(i); | |
270 RECURSE(Visit(arg)); | |
271 } | |
272 --depth_; | |
273 } | |
274 | |
275 | |
276 void AstExpressionVisitor::VisitCallRuntime(CallRuntime* expr) { | |
277 VisitExpression(expr); | |
278 ++depth_; | |
279 ZoneList<Expression*>* args = expr->arguments(); | |
280 for (int i = 0; i < args->length(); ++i) { | |
281 Expression* arg = args->at(i); | |
282 RECURSE(Visit(arg)); | |
283 } | |
284 --depth_; | |
285 } | |
286 | |
287 | |
288 void AstExpressionVisitor::VisitUnaryOperation(UnaryOperation* expr) { | |
289 VisitExpression(expr); | |
290 ++depth_; | |
291 RECURSE(Visit(expr->expression())); | |
292 --depth_; | |
293 } | |
294 | |
295 | |
296 void AstExpressionVisitor::VisitCountOperation(CountOperation* expr) { | |
297 VisitExpression(expr); | |
298 ++depth_; | |
299 RECURSE(Visit(expr->expression())); | |
300 --depth_; | |
301 } | |
302 | |
303 | |
304 void AstExpressionVisitor::VisitBinaryOperation(BinaryOperation* expr) { | |
305 VisitExpression(expr); | |
306 ++depth_; | |
307 RECURSE(Visit(expr->left())); | |
308 RECURSE(Visit(expr->right())); | |
309 --depth_; | |
310 } | |
311 | |
312 | |
313 void AstExpressionVisitor::VisitCompareOperation(CompareOperation* expr) { | |
314 VisitExpression(expr); | |
315 ++depth_; | |
316 RECURSE(Visit(expr->left())); | |
317 RECURSE(Visit(expr->right())); | |
318 --depth_; | |
319 } | |
320 | |
321 | |
322 void AstExpressionVisitor::VisitThisFunction(ThisFunction* expr) { | |
323 VisitExpression(expr); | |
324 } | |
325 | |
326 | |
327 void AstExpressionVisitor::VisitDeclarations(ZoneList<Declaration*>* decls) { | |
328 for (int i = 0; i < decls->length(); ++i) { | |
329 Declaration* decl = decls->at(i); | |
330 RECURSE(Visit(decl)); | |
331 } | |
332 } | |
333 | |
334 | |
335 void AstExpressionVisitor::VisitClassLiteral(ClassLiteral* expr) {} | |
336 | |
337 | |
338 void AstExpressionVisitor::VisitSpread(Spread* expr) {} | |
339 | |
340 | |
341 void AstExpressionVisitor::VisitSuperPropertyReference( | |
342 SuperPropertyReference* expr) {} | |
343 | |
344 | |
345 void AstExpressionVisitor::VisitSuperCallReference(SuperCallReference* expr) {} | |
346 } | |
347 | |
348 | |
349 } // namespace v8::internal | |
OLD | NEW |