| OLD | NEW |
| 1 // Copyright 2016 the V8 project authors. All rights reserved. | 1 // Copyright 2016 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef V8_AST_AST_TRAVERSAL_VISITOR_H_ | 5 #ifndef V8_AST_AST_TRAVERSAL_VISITOR_H_ |
| 6 #define V8_AST_AST_TRAVERSAL_VISITOR_H_ | 6 #define V8_AST_AST_TRAVERSAL_VISITOR_H_ |
| 7 | 7 |
| 8 #include "src/ast/ast.h" | 8 #include "src/ast/ast.h" |
| 9 #include "src/ast/scopes.h" | 9 #include "src/ast/scopes.h" |
| 10 | 10 |
| (...skipping 23 matching lines...) Expand all Loading... |
| 34 void Run() { | 34 void Run() { |
| 35 DCHECK_NOT_NULL(root_); | 35 DCHECK_NOT_NULL(root_); |
| 36 Visit(root_); | 36 Visit(root_); |
| 37 } | 37 } |
| 38 | 38 |
| 39 bool VisitNode(AstNode* node) { return true; } | 39 bool VisitNode(AstNode* node) { return true; } |
| 40 bool VisitExpression(Expression* node) { return true; } | 40 bool VisitExpression(Expression* node) { return true; } |
| 41 | 41 |
| 42 // Iteration left-to-right. | 42 // Iteration left-to-right. |
| 43 void VisitDeclarations(ZoneList<Declaration*>* declarations); | 43 void VisitDeclarations(ZoneList<Declaration*>* declarations); |
| 44 void VisitStatements(ZoneList<Statement*>* statements); | 44 void VisitStatements(ZoneChunkList<Statement*>* statements); |
| 45 | 45 |
| 46 // Individual nodes | 46 // Individual nodes |
| 47 #define DECLARE_VISIT(type) void Visit##type(type* node); | 47 #define DECLARE_VISIT(type) void Visit##type(type* node); |
| 48 AST_NODE_LIST(DECLARE_VISIT) | 48 AST_NODE_LIST(DECLARE_VISIT) |
| 49 #undef DECLARE_VISIT | 49 #undef DECLARE_VISIT |
| 50 | 50 |
| 51 protected: | 51 protected: |
| 52 int depth() const { return depth_; } | 52 int depth() const { return depth_; } |
| 53 | 53 |
| 54 private: | 54 private: |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 106 void AstTraversalVisitor<Subclass>::VisitDeclarations( | 106 void AstTraversalVisitor<Subclass>::VisitDeclarations( |
| 107 ZoneList<Declaration*>* decls) { | 107 ZoneList<Declaration*>* decls) { |
| 108 for (int i = 0; i < decls->length(); ++i) { | 108 for (int i = 0; i < decls->length(); ++i) { |
| 109 Declaration* decl = decls->at(i); | 109 Declaration* decl = decls->at(i); |
| 110 RECURSE(Visit(decl)); | 110 RECURSE(Visit(decl)); |
| 111 } | 111 } |
| 112 } | 112 } |
| 113 | 113 |
| 114 template <class Subclass> | 114 template <class Subclass> |
| 115 void AstTraversalVisitor<Subclass>::VisitStatements( | 115 void AstTraversalVisitor<Subclass>::VisitStatements( |
| 116 ZoneList<Statement*>* stmts) { | 116 ZoneChunkList<Statement*>* statements) { |
| 117 for (int i = 0; i < stmts->length(); ++i) { | 117 for (auto statement : *statements) { |
| 118 Statement* stmt = stmts->at(i); | 118 RECURSE(Visit(statement)); |
| 119 RECURSE(Visit(stmt)); | 119 if (statement->IsJump()) break; |
| 120 if (stmt->IsJump()) break; | |
| 121 } | 120 } |
| 122 } | 121 } |
| 123 | 122 |
| 124 template <class Subclass> | 123 template <class Subclass> |
| 125 void AstTraversalVisitor<Subclass>::VisitVariableDeclaration( | 124 void AstTraversalVisitor<Subclass>::VisitVariableDeclaration( |
| 126 VariableDeclaration* decl) { | 125 VariableDeclaration* decl) { |
| 127 PROCESS_NODE(decl); | 126 PROCESS_NODE(decl); |
| 128 } | 127 } |
| 129 | 128 |
| 130 template <class Subclass> | 129 template <class Subclass> |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 196 PROCESS_NODE(stmt); | 195 PROCESS_NODE(stmt); |
| 197 RECURSE(Visit(stmt->tag())); | 196 RECURSE(Visit(stmt->tag())); |
| 198 | 197 |
| 199 ZoneList<CaseClause*>* clauses = stmt->cases(); | 198 ZoneList<CaseClause*>* clauses = stmt->cases(); |
| 200 for (int i = 0; i < clauses->length(); ++i) { | 199 for (int i = 0; i < clauses->length(); ++i) { |
| 201 CaseClause* clause = clauses->at(i); | 200 CaseClause* clause = clauses->at(i); |
| 202 if (!clause->is_default()) { | 201 if (!clause->is_default()) { |
| 203 Expression* label = clause->label(); | 202 Expression* label = clause->label(); |
| 204 RECURSE(Visit(label)); | 203 RECURSE(Visit(label)); |
| 205 } | 204 } |
| 206 ZoneList<Statement*>* stmts = clause->statements(); | 205 ZoneChunkList<Statement*>* stmts = clause->statements(); |
| 207 RECURSE(VisitStatements(stmts)); | 206 RECURSE(VisitStatements(stmts)); |
| 208 } | 207 } |
| 209 } | 208 } |
| 210 | 209 |
| 211 template <class Subclass> | 210 template <class Subclass> |
| 212 void AstTraversalVisitor<Subclass>::VisitCaseClause(CaseClause* clause) { | 211 void AstTraversalVisitor<Subclass>::VisitCaseClause(CaseClause* clause) { |
| 213 UNREACHABLE(); | 212 UNREACHABLE(); |
| 214 } | 213 } |
| 215 | 214 |
| 216 template <class Subclass> | 215 template <class Subclass> |
| (...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 497 | 496 |
| 498 #undef PROCESS_NODE | 497 #undef PROCESS_NODE |
| 499 #undef PROCESS_EXPRESSION | 498 #undef PROCESS_EXPRESSION |
| 500 #undef RECURSE_EXPRESSION | 499 #undef RECURSE_EXPRESSION |
| 501 #undef RECURSE | 500 #undef RECURSE |
| 502 | 501 |
| 503 } // namespace internal | 502 } // namespace internal |
| 504 } // namespace v8 | 503 } // namespace v8 |
| 505 | 504 |
| 506 #endif // V8_AST_AST_TRAVERSAL_VISITOR_H_ | 505 #endif // V8_AST_AST_TRAVERSAL_VISITOR_H_ |
| OLD | NEW |