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