OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 2474 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2485 proxy_(proxy) { | 2485 proxy_(proxy) { |
2486 } | 2486 } |
2487 | 2487 |
2488 | 2488 |
2489 // ---------------------------------------------------------------------------- | 2489 // ---------------------------------------------------------------------------- |
2490 // Basic visitor | 2490 // Basic visitor |
2491 // - leaf node visitors are abstract. | 2491 // - leaf node visitors are abstract. |
2492 | 2492 |
2493 class AstVisitor BASE_EMBEDDED { | 2493 class AstVisitor BASE_EMBEDDED { |
2494 public: | 2494 public: |
2495 AstVisitor() {} | 2495 AstVisitor() : isolate_(Isolate::Current()), stack_overflow_(false) { } |
2496 virtual ~AstVisitor() { } | 2496 virtual ~AstVisitor() { } |
2497 | 2497 |
2498 // Stack overflow check and dynamic dispatch. | 2498 // Stack overflow check and dynamic dispatch. |
2499 virtual void Visit(AstNode* node) = 0; | 2499 void Visit(AstNode* node) { if (!CheckStackOverflow()) node->Accept(this); } |
2500 | 2500 |
2501 // Iteration left-to-right. | 2501 // Iteration left-to-right. |
2502 virtual void VisitDeclarations(ZoneList<Declaration*>* declarations); | 2502 virtual void VisitDeclarations(ZoneList<Declaration*>* declarations); |
2503 virtual void VisitStatements(ZoneList<Statement*>* statements); | 2503 virtual void VisitStatements(ZoneList<Statement*>* statements); |
2504 virtual void VisitExpressions(ZoneList<Expression*>* expressions); | 2504 virtual void VisitExpressions(ZoneList<Expression*>* expressions); |
2505 | 2505 |
| 2506 // Stack overflow tracking support. |
| 2507 bool HasStackOverflow() const { return stack_overflow_; } |
| 2508 bool CheckStackOverflow(); |
| 2509 |
| 2510 // If a stack-overflow exception is encountered when visiting a |
| 2511 // node, calling SetStackOverflow will make sure that the visitor |
| 2512 // bails out without visiting more nodes. |
| 2513 void SetStackOverflow() { stack_overflow_ = true; } |
| 2514 void ClearStackOverflow() { stack_overflow_ = false; } |
| 2515 |
2506 // Individual AST nodes. | 2516 // Individual AST nodes. |
2507 #define DEF_VISIT(type) \ | 2517 #define DEF_VISIT(type) \ |
2508 virtual void Visit##type(type* node) = 0; | 2518 virtual void Visit##type(type* node) = 0; |
2509 AST_NODE_LIST(DEF_VISIT) | 2519 AST_NODE_LIST(DEF_VISIT) |
2510 #undef DEF_VISIT | 2520 #undef DEF_VISIT |
| 2521 |
| 2522 protected: |
| 2523 Isolate* isolate() { return isolate_; } |
| 2524 |
| 2525 private: |
| 2526 Isolate* isolate_; |
| 2527 bool stack_overflow_; |
2511 }; | 2528 }; |
2512 | 2529 |
2513 | 2530 |
2514 #define DEFINE_AST_VISITOR_SUBCLASS_MEMBERS() \ | |
2515 public: \ | |
2516 virtual void Visit(AstNode* node) { \ | |
2517 if (!CheckStackOverflow()) node->Accept(this); \ | |
2518 } \ | |
2519 \ | |
2520 void SetStackOverflow() { stack_overflow_ = true; } \ | |
2521 void ClearStackOverflow() { stack_overflow_ = false; } \ | |
2522 bool HasStackOverflow() const { return stack_overflow_; } \ | |
2523 \ | |
2524 bool CheckStackOverflow() { \ | |
2525 if (stack_overflow_) return true; \ | |
2526 StackLimitCheck check(isolate_); \ | |
2527 if (!check.HasOverflowed()) return false; \ | |
2528 return (stack_overflow_ = true); \ | |
2529 } \ | |
2530 \ | |
2531 private: \ | |
2532 void InitializeAstVisitor() { \ | |
2533 isolate_ = Isolate::Current(); \ | |
2534 stack_overflow_ = false; \ | |
2535 } \ | |
2536 Isolate* isolate() { return isolate_; } \ | |
2537 \ | |
2538 Isolate* isolate_; \ | |
2539 bool stack_overflow_ | |
2540 | |
2541 | |
2542 // ---------------------------------------------------------------------------- | 2531 // ---------------------------------------------------------------------------- |
2543 // Construction time visitor. | 2532 // Construction time visitor. |
2544 | 2533 |
2545 class AstConstructionVisitor BASE_EMBEDDED { | 2534 class AstConstructionVisitor BASE_EMBEDDED { |
2546 public: | 2535 public: |
2547 AstConstructionVisitor() { } | 2536 AstConstructionVisitor() { } |
2548 | 2537 |
2549 AstProperties* ast_properties() { return &properties_; } | 2538 AstProperties* ast_properties() { return &properties_; } |
2550 | 2539 |
2551 private: | 2540 private: |
(...skipping 380 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2932 private: | 2921 private: |
2933 Isolate* isolate_; | 2922 Isolate* isolate_; |
2934 Zone* zone_; | 2923 Zone* zone_; |
2935 Visitor visitor_; | 2924 Visitor visitor_; |
2936 }; | 2925 }; |
2937 | 2926 |
2938 | 2927 |
2939 } } // namespace v8::internal | 2928 } } // namespace v8::internal |
2940 | 2929 |
2941 #endif // V8_AST_H_ | 2930 #endif // V8_AST_H_ |
OLD | NEW |