Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(18)

Unified Diff: src/ast/ast.cc

Issue 2169833002: [parser] Refactor AstTraversalVisitor (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Rebase Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/ast/ast.h ('k') | src/ast/ast-expression-visitor.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/ast/ast.cc
diff --git a/src/ast/ast.cc b/src/ast/ast.cc
index f22142207d7818094445705f90b56e3a33514c54..6fa7f53071f14286dd0442f61c74c644607e57ad 100644
--- a/src/ast/ast.cc
+++ b/src/ast/ast.cc
@@ -923,305 +923,6 @@ Call::CallType Call::GetCallType(Isolate* isolate) const {
}
-// ----------------------------------------------------------------------------
-// Implementation of AstTraversalVisitor
-
-#define RECURSE(call) \
- do { \
- DCHECK(!HasStackOverflow()); \
- call; \
- if (HasStackOverflow()) return; \
- } while (false)
-
-#define RECURSE_EXPRESSION(call) \
- do { \
- DCHECK(!HasStackOverflow()); \
- ++depth_; \
- call; \
- --depth_; \
- if (HasStackOverflow()) return; \
- } while (false)
-
-AstTraversalVisitor::AstTraversalVisitor(Isolate* isolate) : depth_(0) {
- InitializeAstVisitor(isolate);
-}
-
-AstTraversalVisitor::AstTraversalVisitor(uintptr_t stack_limit) : depth_(0) {
- InitializeAstVisitor(stack_limit);
-}
-
-void AstTraversalVisitor::VisitDeclarations(ZoneList<Declaration*>* decls) {
- for (int i = 0; i < decls->length(); ++i) {
- Declaration* decl = decls->at(i);
- RECURSE(Visit(decl));
- }
-}
-
-void AstTraversalVisitor::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 AstTraversalVisitor::VisitVariableDeclaration(VariableDeclaration* decl) {}
-
-void AstTraversalVisitor::VisitFunctionDeclaration(FunctionDeclaration* decl) {
- RECURSE(Visit(decl->fun()));
-}
-
-void AstTraversalVisitor::VisitBlock(Block* stmt) {
- RECURSE(VisitStatements(stmt->statements()));
-}
-
-void AstTraversalVisitor::VisitExpressionStatement(ExpressionStatement* stmt) {
- RECURSE(Visit(stmt->expression()));
-}
-
-void AstTraversalVisitor::VisitEmptyStatement(EmptyStatement* stmt) {}
-
-void AstTraversalVisitor::VisitSloppyBlockFunctionStatement(
- SloppyBlockFunctionStatement* stmt) {
- RECURSE(Visit(stmt->statement()));
-}
-
-void AstTraversalVisitor::VisitIfStatement(IfStatement* stmt) {
- RECURSE(Visit(stmt->condition()));
- RECURSE(Visit(stmt->then_statement()));
- RECURSE(Visit(stmt->else_statement()));
-}
-
-void AstTraversalVisitor::VisitContinueStatement(ContinueStatement* stmt) {}
-
-void AstTraversalVisitor::VisitBreakStatement(BreakStatement* stmt) {}
-
-void AstTraversalVisitor::VisitReturnStatement(ReturnStatement* stmt) {
- RECURSE(Visit(stmt->expression()));
-}
-
-void AstTraversalVisitor::VisitWithStatement(WithStatement* stmt) {
- RECURSE(stmt->expression());
- RECURSE(stmt->statement());
-}
-
-void AstTraversalVisitor::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);
- if (!clause->is_default()) {
- Expression* label = clause->label();
- RECURSE(Visit(label));
- }
- ZoneList<Statement*>* stmts = clause->statements();
- RECURSE(VisitStatements(stmts));
- }
-}
-
-void AstTraversalVisitor::VisitCaseClause(CaseClause* clause) { UNREACHABLE(); }
-
-void AstTraversalVisitor::VisitDoWhileStatement(DoWhileStatement* stmt) {
- RECURSE(Visit(stmt->body()));
- RECURSE(Visit(stmt->cond()));
-}
-
-void AstTraversalVisitor::VisitWhileStatement(WhileStatement* stmt) {
- RECURSE(Visit(stmt->cond()));
- RECURSE(Visit(stmt->body()));
-}
-
-void AstTraversalVisitor::VisitForStatement(ForStatement* stmt) {
- if (stmt->init() != NULL) {
- RECURSE(Visit(stmt->init()));
- }
- if (stmt->cond() != NULL) {
- RECURSE(Visit(stmt->cond()));
- }
- if (stmt->next() != NULL) {
- RECURSE(Visit(stmt->next()));
- }
- RECURSE(Visit(stmt->body()));
-}
-
-void AstTraversalVisitor::VisitForInStatement(ForInStatement* stmt) {
- RECURSE(Visit(stmt->enumerable()));
- RECURSE(Visit(stmt->body()));
-}
-
-void AstTraversalVisitor::VisitForOfStatement(ForOfStatement* stmt) {
- RECURSE(Visit(stmt->assign_iterator()));
- RECURSE(Visit(stmt->next_result()));
- RECURSE(Visit(stmt->result_done()));
- RECURSE(Visit(stmt->assign_each()));
- RECURSE(Visit(stmt->body()));
-}
-
-void AstTraversalVisitor::VisitTryCatchStatement(TryCatchStatement* stmt) {
- RECURSE(Visit(stmt->try_block()));
- RECURSE(Visit(stmt->catch_block()));
-}
-
-void AstTraversalVisitor::VisitTryFinallyStatement(TryFinallyStatement* stmt) {
- RECURSE(Visit(stmt->try_block()));
- RECURSE(Visit(stmt->finally_block()));
-}
-
-void AstTraversalVisitor::VisitDebuggerStatement(DebuggerStatement* stmt) {}
-
-void AstTraversalVisitor::VisitFunctionLiteral(FunctionLiteral* expr) {
- Scope* scope = expr->scope();
- RECURSE_EXPRESSION(VisitDeclarations(scope->declarations()));
- RECURSE_EXPRESSION(VisitStatements(expr->body()));
-}
-
-void AstTraversalVisitor::VisitNativeFunctionLiteral(
- NativeFunctionLiteral* expr) {}
-
-void AstTraversalVisitor::VisitDoExpression(DoExpression* expr) {
- RECURSE(VisitBlock(expr->block()));
- RECURSE(VisitVariableProxy(expr->result()));
-}
-
-void AstTraversalVisitor::VisitConditional(Conditional* expr) {
- RECURSE_EXPRESSION(Visit(expr->condition()));
- RECURSE_EXPRESSION(Visit(expr->then_expression()));
- RECURSE_EXPRESSION(Visit(expr->else_expression()));
-}
-
-void AstTraversalVisitor::VisitVariableProxy(VariableProxy* expr) {}
-
-void AstTraversalVisitor::VisitLiteral(Literal* expr) {}
-
-void AstTraversalVisitor::VisitRegExpLiteral(RegExpLiteral* expr) {}
-
-void AstTraversalVisitor::VisitObjectLiteral(ObjectLiteral* expr) {
- ZoneList<ObjectLiteralProperty*>* props = expr->properties();
- for (int i = 0; i < props->length(); ++i) {
- ObjectLiteralProperty* prop = props->at(i);
- if (!prop->key()->IsLiteral()) {
- RECURSE_EXPRESSION(Visit(prop->key()));
- }
- RECURSE_EXPRESSION(Visit(prop->value()));
- }
-}
-
-void AstTraversalVisitor::VisitArrayLiteral(ArrayLiteral* expr) {
- ZoneList<Expression*>* values = expr->values();
- for (int i = 0; i < values->length(); ++i) {
- Expression* value = values->at(i);
- RECURSE_EXPRESSION(Visit(value));
- }
-}
-
-void AstTraversalVisitor::VisitAssignment(Assignment* expr) {
- RECURSE_EXPRESSION(Visit(expr->target()));
- RECURSE_EXPRESSION(Visit(expr->value()));
-}
-
-void AstTraversalVisitor::VisitYield(Yield* expr) {
- RECURSE_EXPRESSION(Visit(expr->generator_object()));
- RECURSE_EXPRESSION(Visit(expr->expression()));
-}
-
-void AstTraversalVisitor::VisitThrow(Throw* expr) {
- RECURSE_EXPRESSION(Visit(expr->exception()));
-}
-
-void AstTraversalVisitor::VisitProperty(Property* expr) {
- RECURSE_EXPRESSION(Visit(expr->obj()));
- RECURSE_EXPRESSION(Visit(expr->key()));
-}
-
-void AstTraversalVisitor::VisitCall(Call* expr) {
- RECURSE_EXPRESSION(Visit(expr->expression()));
- ZoneList<Expression*>* args = expr->arguments();
- for (int i = 0; i < args->length(); ++i) {
- Expression* arg = args->at(i);
- RECURSE_EXPRESSION(Visit(arg));
- }
-}
-
-void AstTraversalVisitor::VisitCallNew(CallNew* expr) {
- RECURSE_EXPRESSION(Visit(expr->expression()));
- ZoneList<Expression*>* args = expr->arguments();
- for (int i = 0; i < args->length(); ++i) {
- Expression* arg = args->at(i);
- RECURSE_EXPRESSION(Visit(arg));
- }
-}
-
-void AstTraversalVisitor::VisitCallRuntime(CallRuntime* expr) {
- ZoneList<Expression*>* args = expr->arguments();
- for (int i = 0; i < args->length(); ++i) {
- Expression* arg = args->at(i);
- RECURSE_EXPRESSION(Visit(arg));
- }
-}
-
-void AstTraversalVisitor::VisitUnaryOperation(UnaryOperation* expr) {
- RECURSE_EXPRESSION(Visit(expr->expression()));
-}
-
-void AstTraversalVisitor::VisitCountOperation(CountOperation* expr) {
- RECURSE_EXPRESSION(Visit(expr->expression()));
-}
-
-void AstTraversalVisitor::VisitBinaryOperation(BinaryOperation* expr) {
- RECURSE_EXPRESSION(Visit(expr->left()));
- RECURSE_EXPRESSION(Visit(expr->right()));
-}
-
-void AstTraversalVisitor::VisitCompareOperation(CompareOperation* expr) {
- RECURSE_EXPRESSION(Visit(expr->left()));
- RECURSE_EXPRESSION(Visit(expr->right()));
-}
-
-void AstTraversalVisitor::VisitThisFunction(ThisFunction* expr) {}
-
-void AstTraversalVisitor::VisitClassLiteral(ClassLiteral* expr) {
- if (expr->extends() != nullptr) {
- RECURSE_EXPRESSION(Visit(expr->extends()));
- }
- RECURSE_EXPRESSION(Visit(expr->constructor()));
- ZoneList<ObjectLiteralProperty*>* props = expr->properties();
- for (int i = 0; i < props->length(); ++i) {
- ObjectLiteralProperty* prop = props->at(i);
- if (!prop->key()->IsLiteral()) {
- RECURSE_EXPRESSION(Visit(prop->key()));
- }
- RECURSE_EXPRESSION(Visit(prop->value()));
- }
-}
-
-void AstTraversalVisitor::VisitSpread(Spread* expr) {
- RECURSE_EXPRESSION(Visit(expr->expression()));
-}
-
-void AstTraversalVisitor::VisitEmptyParentheses(EmptyParentheses* expr) {}
-
-void AstTraversalVisitor::VisitSuperPropertyReference(
- SuperPropertyReference* expr) {
- RECURSE_EXPRESSION(VisitVariableProxy(expr->this_var()));
- RECURSE_EXPRESSION(Visit(expr->home_object()));
-}
-
-void AstTraversalVisitor::VisitSuperCallReference(SuperCallReference* expr) {
- RECURSE_EXPRESSION(VisitVariableProxy(expr->this_var()));
- RECURSE_EXPRESSION(VisitVariableProxy(expr->new_target_var()));
- RECURSE_EXPRESSION(VisitVariableProxy(expr->this_function_var()));
-}
-
-void AstTraversalVisitor::VisitRewritableExpression(
- RewritableExpression* expr) {
- RECURSE(Visit(expr->expression()));
-}
-
-#undef RECURSE_EXPRESSION
-#undef RECURSE
-
CaseClause::CaseClause(Zone* zone, Expression* label,
ZoneList<Statement*>* statements, int pos)
: Expression(zone, pos, kCaseClause),
« no previous file with comments | « src/ast/ast.h ('k') | src/ast/ast-expression-visitor.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698