Chromium Code Reviews| Index: src/ast-expression-visitor.cc |
| diff --git a/src/ast-expression-visitor.cc b/src/ast-expression-visitor.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..3af13f9b7b121b3d4a22db238712022f680e9c21 |
| --- /dev/null |
| +++ b/src/ast-expression-visitor.cc |
| @@ -0,0 +1,349 @@ |
| +// Copyright 2015 the V8 project authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "src/v8.h" |
| + |
| +#include "src/ast-expression-visitor.h" |
| + |
| +#include "src/ast.h" |
| +#include "src/codegen.h" |
| +#include "src/scopes.h" |
| + |
| +namespace v8 { |
| +namespace internal { |
| + |
| + |
| +#define RECURSE(call) \ |
| + do { \ |
| + DCHECK(!HasStackOverflow()); \ |
| + call; \ |
| + if (HasStackOverflow()) return; \ |
| + } while (false) |
| + |
| + |
| +AstExpressionVisitor::AstExpressionVisitor(CompilationInfo* info) |
| + : compilation_info_(info), depth_(0) { |
| + InitializeAstVisitor(info->isolate(), info->zone()); |
| +} |
| + |
| + |
| +void AstExpressionVisitor::VisitAll() { |
| + VisitFunctionLiteral(compilation_info_->function()); |
| +} |
| + |
| + |
| +void AstExpressionVisitor::VisitVariableDeclaration(VariableDeclaration* decl) { |
| +} |
| + |
| + |
| +void AstExpressionVisitor::VisitFunctionDeclaration(FunctionDeclaration* decl) { |
| + RECURSE(Visit(decl->fun())); |
| +} |
| + |
| + |
| +void AstExpressionVisitor::VisitImportDeclaration(ImportDeclaration* decl) {} |
| + |
| + |
| +void AstExpressionVisitor::VisitExportDeclaration(ExportDeclaration* decl) {} |
| + |
| + |
| +void AstExpressionVisitor::VisitStatements(ZoneList<Statement*>* stmts) { |
| + for (int i = 0; i < stmts->length(); ++i) { |
| + Statement* stmt = stmts->at(i); |
| + RECURSE(Visit(stmt)); |
| + if (stmt->IsJump()) break; |
| + } |
| +} |
| + |
| + |
| +void AstExpressionVisitor::VisitBlock(Block* stmt) { |
| + RECURSE(VisitStatements(stmt->statements())); |
| +} |
| + |
| + |
| +void AstExpressionVisitor::VisitExpressionStatement(ExpressionStatement* stmt) { |
| + RECURSE(Visit(stmt->expression())); |
| +} |
| + |
| + |
| +void AstExpressionVisitor::VisitEmptyStatement(EmptyStatement* stmt) {} |
| + |
| + |
| +void AstExpressionVisitor::VisitIfStatement(IfStatement* stmt) { |
| + RECURSE(Visit(stmt->condition())); |
| + RECURSE(Visit(stmt->then_statement())); |
| + RECURSE(Visit(stmt->else_statement())); |
| +} |
| + |
| + |
| +void AstExpressionVisitor::VisitContinueStatement(ContinueStatement* stmt) {} |
| + |
| + |
| +void AstExpressionVisitor::VisitBreakStatement(BreakStatement* stmt) {} |
| + |
| + |
| +void AstExpressionVisitor::VisitReturnStatement(ReturnStatement* stmt) { |
| + RECURSE(Visit(stmt->expression())); |
| +} |
| + |
| + |
| +void AstExpressionVisitor::VisitWithStatement(WithStatement* stmt) { |
| + RECURSE(stmt->expression()); |
| + RECURSE(stmt->statement()); |
| +} |
| + |
| + |
| +void AstExpressionVisitor::VisitSwitchStatement(SwitchStatement* stmt) { |
| + RECURSE(Visit(stmt->tag())); |
| + |
| + ZoneList<CaseClause*>* clauses = stmt->cases(); |
| + |
| + for (int i = 0; i < clauses->length(); ++i) { |
| + CaseClause* clause = clauses->at(i); |
| + Expression* label = clause->label(); |
| + RECURSE(Visit(label)); |
| + ZoneList<Statement*>* stmts = clause->statements(); |
| + RECURSE(VisitStatements(stmts)); |
| + } |
| +} |
| + |
| + |
| +void AstExpressionVisitor::VisitCaseClause(CaseClause* clause) { |
| + UNREACHABLE(); |
| +} |
| + |
| + |
| +void AstExpressionVisitor::VisitDoWhileStatement(DoWhileStatement* stmt) { |
| + RECURSE(Visit(stmt->body())); |
| + RECURSE(Visit(stmt->cond())); |
| +} |
| + |
| + |
| +void AstExpressionVisitor::VisitWhileStatement(WhileStatement* stmt) { |
| + RECURSE(Visit(stmt->cond())); |
| + RECURSE(Visit(stmt->body())); |
| +} |
| + |
| + |
| +void AstExpressionVisitor::VisitForStatement(ForStatement* stmt) { |
| + RECURSE(Visit(stmt->init())); |
| + RECURSE(Visit(stmt->cond())); |
| + RECURSE(Visit(stmt->next())); |
| + RECURSE(Visit(stmt->body())); |
| +} |
| + |
| + |
| +void AstExpressionVisitor::VisitForInStatement(ForInStatement* stmt) { |
| + RECURSE(Visit(stmt->enumerable())); |
| + RECURSE(Visit(stmt->body())); |
| +} |
| + |
| + |
| +void AstExpressionVisitor::VisitForOfStatement(ForOfStatement* stmt) { |
| + RECURSE(Visit(stmt->iterable())); |
| + RECURSE(Visit(stmt->body())); |
| +} |
| + |
| + |
| +void AstExpressionVisitor::VisitTryCatchStatement(TryCatchStatement* stmt) { |
| + RECURSE(Visit(stmt->try_block())); |
| + RECURSE(Visit(stmt->catch_block())); |
| +} |
| + |
| + |
| +void AstExpressionVisitor::VisitTryFinallyStatement(TryFinallyStatement* stmt) { |
| + RECURSE(Visit(stmt->try_block())); |
| + RECURSE(Visit(stmt->finally_block())); |
| +} |
| + |
| + |
| +void AstExpressionVisitor::VisitDebuggerStatement(DebuggerStatement* stmt) {} |
| + |
| + |
| +void AstExpressionVisitor::VisitFunctionLiteral(FunctionLiteral* expr) { |
| + Scope* scope = expr->scope(); |
| + VisitExpression(expr); |
| + ++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.
|
| + RECURSE(VisitDeclarations(scope->declarations())); |
| + RECURSE(VisitStatements(expr->body())); |
| + --depth_; |
| +} |
| + |
| + |
| +void AstExpressionVisitor::VisitNativeFunctionLiteral( |
| + NativeFunctionLiteral* expr) {} |
| + |
| + |
| +void AstExpressionVisitor::VisitConditional(Conditional* expr) { |
| + RECURSE(Visit(expr->condition())); |
| + RECURSE(Visit(expr->then_expression())); |
| + RECURSE(Visit(expr->else_expression())); |
| +} |
| + |
| + |
| +void AstExpressionVisitor::VisitVariableProxy(VariableProxy* expr) { |
| + VisitExpression(expr); |
| +} |
| + |
| + |
| +void AstExpressionVisitor::VisitLiteral(Literal* expr) { |
| + VisitExpression(expr); |
| +} |
| + |
| + |
| +void AstExpressionVisitor::VisitRegExpLiteral(RegExpLiteral* expr) { |
| + VisitExpression(expr); |
| +} |
| + |
| + |
| +void AstExpressionVisitor::VisitObjectLiteral(ObjectLiteral* expr) { |
| + VisitExpression(expr); |
| + ++depth_; |
| + ZoneList<ObjectLiteralProperty*>* props = expr->properties(); |
| + for (int i = 0; i < props->length(); ++i) { |
| + ObjectLiteralProperty* prop = props->at(i); |
| + RECURSE(Visit(prop->value())); |
| + } |
| + --depth_; |
| +} |
| + |
| + |
| +void AstExpressionVisitor::VisitArrayLiteral(ArrayLiteral* expr) { |
| + VisitExpression(expr); |
| + ++depth_; |
| + ZoneList<Expression*>* values = expr->values(); |
| + for (int i = 0; i < values->length(); ++i) { |
| + Expression* value = values->at(i); |
| + RECURSE(Visit(value)); |
| + } |
| + --depth_; |
| +} |
| + |
| + |
| +void AstExpressionVisitor::VisitAssignment(Assignment* expr) { |
| + VisitExpression(expr); |
| + ++depth_; |
| + RECURSE(Visit(expr->target())); |
| + RECURSE(Visit(expr->value())); |
| + --depth_; |
| +} |
| + |
| + |
| +void AstExpressionVisitor::VisitYield(Yield* expr) { |
| + RECURSE(Visit(expr->generator_object())); |
| + RECURSE(Visit(expr->expression())); |
| +} |
| + |
| + |
| +void AstExpressionVisitor::VisitThrow(Throw* expr) { |
| + RECURSE(Visit(expr->exception())); |
| +} |
| + |
| + |
| +void AstExpressionVisitor::VisitProperty(Property* expr) { |
| + RECURSE(Visit(expr->obj())); |
| + RECURSE(Visit(expr->key())); |
| +} |
| + |
| + |
| +void AstExpressionVisitor::VisitCall(Call* expr) { |
| + VisitExpression(expr); |
| + ++depth_; |
| + RECURSE(Visit(expr->expression())); |
| + ZoneList<Expression*>* args = expr->arguments(); |
| + for (int i = 0; i < args->length(); ++i) { |
| + Expression* arg = args->at(i); |
| + RECURSE(Visit(arg)); |
| + } |
| + --depth_; |
| +} |
| + |
| + |
| +void AstExpressionVisitor::VisitCallNew(CallNew* expr) { |
| + VisitExpression(expr); |
| + ++depth_; |
| + RECURSE(Visit(expr->expression())); |
| + ZoneList<Expression*>* args = expr->arguments(); |
| + for (int i = 0; i < args->length(); ++i) { |
| + Expression* arg = args->at(i); |
| + RECURSE(Visit(arg)); |
| + } |
| + --depth_; |
| +} |
| + |
| + |
| +void AstExpressionVisitor::VisitCallRuntime(CallRuntime* expr) { |
| + VisitExpression(expr); |
| + ++depth_; |
| + ZoneList<Expression*>* args = expr->arguments(); |
| + for (int i = 0; i < args->length(); ++i) { |
| + Expression* arg = args->at(i); |
| + RECURSE(Visit(arg)); |
| + } |
| + --depth_; |
| +} |
| + |
| + |
| +void AstExpressionVisitor::VisitUnaryOperation(UnaryOperation* expr) { |
| + VisitExpression(expr); |
| + ++depth_; |
| + RECURSE(Visit(expr->expression())); |
| + --depth_; |
| +} |
| + |
| + |
| +void AstExpressionVisitor::VisitCountOperation(CountOperation* expr) { |
| + VisitExpression(expr); |
| + ++depth_; |
| + RECURSE(Visit(expr->expression())); |
| + --depth_; |
| +} |
| + |
| + |
| +void AstExpressionVisitor::VisitBinaryOperation(BinaryOperation* expr) { |
| + VisitExpression(expr); |
| + ++depth_; |
| + RECURSE(Visit(expr->left())); |
| + RECURSE(Visit(expr->right())); |
| + --depth_; |
| +} |
| + |
| + |
| +void AstExpressionVisitor::VisitCompareOperation(CompareOperation* expr) { |
| + VisitExpression(expr); |
| + ++depth_; |
| + RECURSE(Visit(expr->left())); |
| + RECURSE(Visit(expr->right())); |
| + --depth_; |
| +} |
| + |
| + |
| +void AstExpressionVisitor::VisitThisFunction(ThisFunction* expr) { |
| + VisitExpression(expr); |
| +} |
| + |
| + |
| +void AstExpressionVisitor::VisitDeclarations(ZoneList<Declaration*>* decls) { |
| + for (int i = 0; i < decls->length(); ++i) { |
| + Declaration* decl = decls->at(i); |
| + RECURSE(Visit(decl)); |
| + } |
| +} |
| + |
| + |
| +void AstExpressionVisitor::VisitClassLiteral(ClassLiteral* expr) {} |
| + |
| + |
| +void AstExpressionVisitor::VisitSpread(Spread* expr) {} |
| + |
| + |
| +void AstExpressionVisitor::VisitSuperPropertyReference( |
| + SuperPropertyReference* expr) {} |
| + |
| + |
| +void AstExpressionVisitor::VisitSuperCallReference(SuperCallReference* expr) {} |
| +} |
| + |
| + |
| +} // namespace v8::internal |