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