• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/ast/ast-literal-reindexer.h"
6 
7 #include "src/ast/ast.h"
8 #include "src/ast/scopes.h"
9 
10 namespace v8 {
11 namespace internal {
12 
13 
VisitVariableDeclaration(VariableDeclaration * node)14 void AstLiteralReindexer::VisitVariableDeclaration(VariableDeclaration* node) {
15   VisitVariableProxy(node->proxy());
16 }
17 
18 
VisitExportDeclaration(ExportDeclaration * node)19 void AstLiteralReindexer::VisitExportDeclaration(ExportDeclaration* node) {
20   VisitVariableProxy(node->proxy());
21 }
22 
23 
VisitEmptyStatement(EmptyStatement * node)24 void AstLiteralReindexer::VisitEmptyStatement(EmptyStatement* node) {}
25 
26 
VisitSloppyBlockFunctionStatement(SloppyBlockFunctionStatement * node)27 void AstLiteralReindexer::VisitSloppyBlockFunctionStatement(
28     SloppyBlockFunctionStatement* node) {
29   Visit(node->statement());
30 }
31 
32 
VisitContinueStatement(ContinueStatement * node)33 void AstLiteralReindexer::VisitContinueStatement(ContinueStatement* node) {}
34 
35 
VisitBreakStatement(BreakStatement * node)36 void AstLiteralReindexer::VisitBreakStatement(BreakStatement* node) {}
37 
38 
VisitDebuggerStatement(DebuggerStatement * node)39 void AstLiteralReindexer::VisitDebuggerStatement(DebuggerStatement* node) {}
40 
41 
VisitNativeFunctionLiteral(NativeFunctionLiteral * node)42 void AstLiteralReindexer::VisitNativeFunctionLiteral(
43     NativeFunctionLiteral* node) {}
44 
45 
VisitDoExpression(DoExpression * node)46 void AstLiteralReindexer::VisitDoExpression(DoExpression* node) {
47   Visit(node->block());
48   Visit(node->result());
49 }
50 
51 
VisitLiteral(Literal * node)52 void AstLiteralReindexer::VisitLiteral(Literal* node) {}
53 
54 
VisitRegExpLiteral(RegExpLiteral * node)55 void AstLiteralReindexer::VisitRegExpLiteral(RegExpLiteral* node) {
56   UpdateIndex(node);
57 }
58 
59 
VisitVariableProxy(VariableProxy * node)60 void AstLiteralReindexer::VisitVariableProxy(VariableProxy* node) {}
61 
62 
VisitThisFunction(ThisFunction * node)63 void AstLiteralReindexer::VisitThisFunction(ThisFunction* node) {}
64 
65 
VisitSuperPropertyReference(SuperPropertyReference * node)66 void AstLiteralReindexer::VisitSuperPropertyReference(
67     SuperPropertyReference* node) {
68   Visit(node->this_var());
69   Visit(node->home_object());
70 }
71 
72 
VisitSuperCallReference(SuperCallReference * node)73 void AstLiteralReindexer::VisitSuperCallReference(SuperCallReference* node) {
74   Visit(node->this_var());
75   Visit(node->new_target_var());
76   Visit(node->this_function_var());
77 }
78 
79 
VisitRewritableExpression(RewritableExpression * node)80 void AstLiteralReindexer::VisitRewritableExpression(
81     RewritableExpression* node) {
82   Visit(node->expression());
83 }
84 
85 
VisitImportDeclaration(ImportDeclaration * node)86 void AstLiteralReindexer::VisitImportDeclaration(ImportDeclaration* node) {
87   VisitVariableProxy(node->proxy());
88 }
89 
90 
VisitExpressionStatement(ExpressionStatement * node)91 void AstLiteralReindexer::VisitExpressionStatement(ExpressionStatement* node) {
92   Visit(node->expression());
93 }
94 
95 
VisitReturnStatement(ReturnStatement * node)96 void AstLiteralReindexer::VisitReturnStatement(ReturnStatement* node) {
97   Visit(node->expression());
98 }
99 
100 
VisitYield(Yield * node)101 void AstLiteralReindexer::VisitYield(Yield* node) {
102   Visit(node->generator_object());
103   Visit(node->expression());
104 }
105 
106 
VisitThrow(Throw * node)107 void AstLiteralReindexer::VisitThrow(Throw* node) { Visit(node->exception()); }
108 
109 
VisitUnaryOperation(UnaryOperation * node)110 void AstLiteralReindexer::VisitUnaryOperation(UnaryOperation* node) {
111   Visit(node->expression());
112 }
113 
114 
VisitCountOperation(CountOperation * node)115 void AstLiteralReindexer::VisitCountOperation(CountOperation* node) {
116   Visit(node->expression());
117 }
118 
119 
VisitBlock(Block * node)120 void AstLiteralReindexer::VisitBlock(Block* node) {
121   VisitStatements(node->statements());
122 }
123 
124 
VisitFunctionDeclaration(FunctionDeclaration * node)125 void AstLiteralReindexer::VisitFunctionDeclaration(FunctionDeclaration* node) {
126   VisitVariableProxy(node->proxy());
127   VisitFunctionLiteral(node->fun());
128 }
129 
130 
VisitCallRuntime(CallRuntime * node)131 void AstLiteralReindexer::VisitCallRuntime(CallRuntime* node) {
132   VisitArguments(node->arguments());
133 }
134 
135 
VisitWithStatement(WithStatement * node)136 void AstLiteralReindexer::VisitWithStatement(WithStatement* node) {
137   Visit(node->expression());
138   Visit(node->statement());
139 }
140 
141 
VisitDoWhileStatement(DoWhileStatement * node)142 void AstLiteralReindexer::VisitDoWhileStatement(DoWhileStatement* node) {
143   Visit(node->body());
144   Visit(node->cond());
145 }
146 
147 
VisitWhileStatement(WhileStatement * node)148 void AstLiteralReindexer::VisitWhileStatement(WhileStatement* node) {
149   Visit(node->cond());
150   Visit(node->body());
151 }
152 
153 
VisitTryCatchStatement(TryCatchStatement * node)154 void AstLiteralReindexer::VisitTryCatchStatement(TryCatchStatement* node) {
155   Visit(node->try_block());
156   Visit(node->catch_block());
157 }
158 
159 
VisitTryFinallyStatement(TryFinallyStatement * node)160 void AstLiteralReindexer::VisitTryFinallyStatement(TryFinallyStatement* node) {
161   Visit(node->try_block());
162   Visit(node->finally_block());
163 }
164 
165 
VisitProperty(Property * node)166 void AstLiteralReindexer::VisitProperty(Property* node) {
167   Visit(node->key());
168   Visit(node->obj());
169 }
170 
171 
VisitAssignment(Assignment * node)172 void AstLiteralReindexer::VisitAssignment(Assignment* node) {
173   Visit(node->target());
174   Visit(node->value());
175 }
176 
177 
VisitBinaryOperation(BinaryOperation * node)178 void AstLiteralReindexer::VisitBinaryOperation(BinaryOperation* node) {
179   Visit(node->left());
180   Visit(node->right());
181 }
182 
183 
VisitCompareOperation(CompareOperation * node)184 void AstLiteralReindexer::VisitCompareOperation(CompareOperation* node) {
185   Visit(node->left());
186   Visit(node->right());
187 }
188 
189 
VisitSpread(Spread * node)190 void AstLiteralReindexer::VisitSpread(Spread* node) {
191   // This is reachable because ParserBase::ParseArrowFunctionLiteral calls
192   // ReindexLiterals before calling RewriteDestructuringAssignments.
193   Visit(node->expression());
194 }
195 
196 
VisitEmptyParentheses(EmptyParentheses * node)197 void AstLiteralReindexer::VisitEmptyParentheses(EmptyParentheses* node) {}
198 
199 
VisitForInStatement(ForInStatement * node)200 void AstLiteralReindexer::VisitForInStatement(ForInStatement* node) {
201   Visit(node->each());
202   Visit(node->enumerable());
203   Visit(node->body());
204 }
205 
206 
VisitForOfStatement(ForOfStatement * node)207 void AstLiteralReindexer::VisitForOfStatement(ForOfStatement* node) {
208   Visit(node->assign_iterator());
209   Visit(node->next_result());
210   Visit(node->result_done());
211   Visit(node->assign_each());
212   Visit(node->body());
213 }
214 
215 
VisitConditional(Conditional * node)216 void AstLiteralReindexer::VisitConditional(Conditional* node) {
217   Visit(node->condition());
218   Visit(node->then_expression());
219   Visit(node->else_expression());
220 }
221 
222 
VisitIfStatement(IfStatement * node)223 void AstLiteralReindexer::VisitIfStatement(IfStatement* node) {
224   Visit(node->condition());
225   Visit(node->then_statement());
226   if (node->HasElseStatement()) {
227     Visit(node->else_statement());
228   }
229 }
230 
231 
VisitSwitchStatement(SwitchStatement * node)232 void AstLiteralReindexer::VisitSwitchStatement(SwitchStatement* node) {
233   Visit(node->tag());
234   ZoneList<CaseClause*>* cases = node->cases();
235   for (int i = 0; i < cases->length(); i++) {
236     VisitCaseClause(cases->at(i));
237   }
238 }
239 
240 
VisitCaseClause(CaseClause * node)241 void AstLiteralReindexer::VisitCaseClause(CaseClause* node) {
242   if (!node->is_default()) Visit(node->label());
243   VisitStatements(node->statements());
244 }
245 
246 
VisitForStatement(ForStatement * node)247 void AstLiteralReindexer::VisitForStatement(ForStatement* node) {
248   if (node->init() != NULL) Visit(node->init());
249   if (node->cond() != NULL) Visit(node->cond());
250   if (node->next() != NULL) Visit(node->next());
251   Visit(node->body());
252 }
253 
254 
VisitClassLiteral(ClassLiteral * node)255 void AstLiteralReindexer::VisitClassLiteral(ClassLiteral* node) {
256   if (node->extends()) Visit(node->extends());
257   if (node->constructor()) Visit(node->constructor());
258   if (node->class_variable_proxy()) {
259     VisitVariableProxy(node->class_variable_proxy());
260   }
261   for (int i = 0; i < node->properties()->length(); i++) {
262     VisitObjectLiteralProperty(node->properties()->at(i));
263   }
264 }
265 
266 
VisitObjectLiteral(ObjectLiteral * node)267 void AstLiteralReindexer::VisitObjectLiteral(ObjectLiteral* node) {
268   UpdateIndex(node);
269   for (int i = 0; i < node->properties()->length(); i++) {
270     VisitObjectLiteralProperty(node->properties()->at(i));
271   }
272 }
273 
274 
VisitObjectLiteralProperty(ObjectLiteralProperty * node)275 void AstLiteralReindexer::VisitObjectLiteralProperty(
276     ObjectLiteralProperty* node) {
277   Visit(node->key());
278   Visit(node->value());
279 }
280 
281 
VisitArrayLiteral(ArrayLiteral * node)282 void AstLiteralReindexer::VisitArrayLiteral(ArrayLiteral* node) {
283   UpdateIndex(node);
284   for (int i = 0; i < node->values()->length(); i++) {
285     Visit(node->values()->at(i));
286   }
287 }
288 
289 
VisitCall(Call * node)290 void AstLiteralReindexer::VisitCall(Call* node) {
291   Visit(node->expression());
292   VisitArguments(node->arguments());
293 }
294 
295 
VisitCallNew(CallNew * node)296 void AstLiteralReindexer::VisitCallNew(CallNew* node) {
297   Visit(node->expression());
298   VisitArguments(node->arguments());
299 }
300 
301 
VisitStatements(ZoneList<Statement * > * statements)302 void AstLiteralReindexer::VisitStatements(ZoneList<Statement*>* statements) {
303   if (statements == NULL) return;
304   for (int i = 0; i < statements->length(); i++) {
305     Visit(statements->at(i));
306   }
307 }
308 
309 
VisitDeclarations(ZoneList<Declaration * > * declarations)310 void AstLiteralReindexer::VisitDeclarations(
311     ZoneList<Declaration*>* declarations) {
312   for (int i = 0; i < declarations->length(); i++) {
313     Visit(declarations->at(i));
314   }
315 }
316 
317 
VisitArguments(ZoneList<Expression * > * arguments)318 void AstLiteralReindexer::VisitArguments(ZoneList<Expression*>* arguments) {
319   for (int i = 0; i < arguments->length(); i++) {
320     Visit(arguments->at(i));
321   }
322 }
323 
324 
VisitFunctionLiteral(FunctionLiteral * node)325 void AstLiteralReindexer::VisitFunctionLiteral(FunctionLiteral* node) {
326   // We don't recurse into the declarations or body of the function literal:
327 }
328 
329 
Reindex(Expression * pattern)330 void AstLiteralReindexer::Reindex(Expression* pattern) {
331   pattern->Accept(this);
332 }
333 }  // namespace internal
334 }  // namespace v8
335