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