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 10 matching lines...) Expand all Loading... |
21 // It invokes VisitNode on each AST node, before proceeding with its subtrees. | 21 // It invokes VisitNode on each AST node, before proceeding with its subtrees. |
22 // It invokes VisitExpression (after VisitNode) on each AST node that is an | 22 // It invokes VisitExpression (after VisitNode) on each AST node that is an |
23 // expression, before proceeding with its subtrees. | 23 // expression, before proceeding with its subtrees. |
24 // It proceeds with the subtrees only if these two methods return true. | 24 // It proceeds with the subtrees only if these two methods return true. |
25 // Sub-classes may override VisitNode and VisitExpressions, whose implementation | 25 // Sub-classes may override VisitNode and VisitExpressions, whose implementation |
26 // is dummy here. Or they may override the specific Visit* methods. | 26 // is dummy here. Or they may override the specific Visit* methods. |
27 | 27 |
28 template <class Subclass> | 28 template <class Subclass> |
29 class AstTraversalVisitor : public AstVisitor<Subclass> { | 29 class AstTraversalVisitor : public AstVisitor<Subclass> { |
30 public: | 30 public: |
31 explicit AstTraversalVisitor(Isolate* isolate, AstNode* root = nullptr); | |
32 explicit AstTraversalVisitor(uintptr_t stack_limit, AstNode* root = nullptr); | 31 explicit AstTraversalVisitor(uintptr_t stack_limit, AstNode* root = nullptr); |
33 | 32 |
34 void Run() { | 33 void Run() { |
35 DCHECK_NOT_NULL(root_); | 34 DCHECK_NOT_NULL(root_); |
36 Visit(root_); | 35 Visit(root_); |
37 } | 36 } |
38 | 37 |
39 bool VisitNode(AstNode* node) { return true; } | 38 bool VisitNode(AstNode* node) { return true; } |
40 bool VisitExpression(Expression* node) { return true; } | 39 bool VisitExpression(Expression* node) { return true; } |
41 | 40 |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
81 | 80 |
82 #define RECURSE_EXPRESSION(call) \ | 81 #define RECURSE_EXPRESSION(call) \ |
83 do { \ | 82 do { \ |
84 DCHECK(!HasStackOverflow()); \ | 83 DCHECK(!HasStackOverflow()); \ |
85 ++depth_; \ | 84 ++depth_; \ |
86 this->impl()->call; \ | 85 this->impl()->call; \ |
87 --depth_; \ | 86 --depth_; \ |
88 if (HasStackOverflow()) return; \ | 87 if (HasStackOverflow()) return; \ |
89 } while (false) | 88 } while (false) |
90 | 89 |
91 template <class Subclass> | |
92 AstTraversalVisitor<Subclass>::AstTraversalVisitor(Isolate* isolate, | |
93 AstNode* root) | |
94 : root_(root), depth_(0) { | |
95 InitializeAstVisitor(isolate); | |
96 } | |
97 | 90 |
98 template <class Subclass> | 91 template <class Subclass> |
99 AstTraversalVisitor<Subclass>::AstTraversalVisitor(uintptr_t stack_limit, | 92 AstTraversalVisitor<Subclass>::AstTraversalVisitor(uintptr_t stack_limit, |
100 AstNode* root) | 93 AstNode* root) |
101 : root_(root), depth_(0) { | 94 : root_(root), depth_(0) { |
102 InitializeAstVisitor(stack_limit); | 95 InitializeAstVisitor(stack_limit); |
103 } | 96 } |
104 | 97 |
105 template <class Subclass> | 98 template <class Subclass> |
106 void AstTraversalVisitor<Subclass>::VisitDeclarations( | 99 void AstTraversalVisitor<Subclass>::VisitDeclarations( |
(...skipping 388 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
495 | 488 |
496 #undef PROCESS_NODE | 489 #undef PROCESS_NODE |
497 #undef PROCESS_EXPRESSION | 490 #undef PROCESS_EXPRESSION |
498 #undef RECURSE_EXPRESSION | 491 #undef RECURSE_EXPRESSION |
499 #undef RECURSE | 492 #undef RECURSE |
500 | 493 |
501 } // namespace internal | 494 } // namespace internal |
502 } // namespace v8 | 495 } // namespace v8 |
503 | 496 |
504 #endif // V8_AST_AST_TRAVERSAL_VISITOR_H_ | 497 #endif // V8_AST_AST_TRAVERSAL_VISITOR_H_ |
OLD | NEW |