OLD | NEW |
1 // Copyright 2010 the V8 project authors. All rights reserved. | 1 // Copyright 2010 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 2042 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2053 | 2053 |
2054 // ---------------------------------------------------------------------------- | 2054 // ---------------------------------------------------------------------------- |
2055 // Basic visitor | 2055 // Basic visitor |
2056 // - leaf node visitors are abstract. | 2056 // - leaf node visitors are abstract. |
2057 | 2057 |
2058 class AstVisitor BASE_EMBEDDED { | 2058 class AstVisitor BASE_EMBEDDED { |
2059 public: | 2059 public: |
2060 AstVisitor() : stack_overflow_(false) { } | 2060 AstVisitor() : stack_overflow_(false) { } |
2061 virtual ~AstVisitor() { } | 2061 virtual ~AstVisitor() { } |
2062 | 2062 |
2063 // Dispatch | 2063 // Stack overflow check and dynamic dispatch. |
2064 void Visit(AstNode* node) { node->Accept(this); } | 2064 void Visit(AstNode* node) { if (!CheckStackOverflow()) node->Accept(this); } |
2065 | 2065 |
2066 // Iteration | 2066 // Iteration left-to-right. |
2067 virtual void VisitDeclarations(ZoneList<Declaration*>* declarations); | 2067 virtual void VisitDeclarations(ZoneList<Declaration*>* declarations); |
2068 virtual void VisitStatements(ZoneList<Statement*>* statements); | 2068 virtual void VisitStatements(ZoneList<Statement*>* statements); |
2069 virtual void VisitExpressions(ZoneList<Expression*>* expressions); | 2069 virtual void VisitExpressions(ZoneList<Expression*>* expressions); |
2070 | 2070 |
2071 // Stack overflow tracking support. | 2071 // Stack overflow tracking support. |
2072 bool HasStackOverflow() const { return stack_overflow_; } | 2072 bool HasStackOverflow() const { return stack_overflow_; } |
2073 bool CheckStackOverflow() { | 2073 bool CheckStackOverflow(); |
2074 if (stack_overflow_) return true; | |
2075 StackLimitCheck check; | |
2076 if (!check.HasOverflowed()) return false; | |
2077 return (stack_overflow_ = true); | |
2078 } | |
2079 | 2074 |
2080 // If a stack-overflow exception is encountered when visiting a | 2075 // If a stack-overflow exception is encountered when visiting a |
2081 // node, calling SetStackOverflow will make sure that the visitor | 2076 // node, calling SetStackOverflow will make sure that the visitor |
2082 // bails out without visiting more nodes. | 2077 // bails out without visiting more nodes. |
2083 void SetStackOverflow() { stack_overflow_ = true; } | 2078 void SetStackOverflow() { stack_overflow_ = true; } |
2084 | 2079 |
2085 | |
2086 // Individual nodes | 2080 // Individual nodes |
2087 #define DEF_VISIT(type) \ | 2081 #define DEF_VISIT(type) \ |
2088 virtual void Visit##type(type* node) = 0; | 2082 virtual void Visit##type(type* node) = 0; |
2089 AST_NODE_LIST(DEF_VISIT) | 2083 AST_NODE_LIST(DEF_VISIT) |
2090 #undef DEF_VISIT | 2084 #undef DEF_VISIT |
2091 | 2085 |
2092 private: | 2086 private: |
2093 bool stack_overflow_; | 2087 bool stack_overflow_; |
2094 }; | 2088 }; |
2095 | 2089 |
(...skipping 16 matching lines...) Expand all Loading... |
2112 | 2106 |
2113 // Holds the result of copying an expression. | 2107 // Holds the result of copying an expression. |
2114 Expression* expr_; | 2108 Expression* expr_; |
2115 // Holds the result of copying a statement. | 2109 // Holds the result of copying a statement. |
2116 Statement* stmt_; | 2110 Statement* stmt_; |
2117 }; | 2111 }; |
2118 | 2112 |
2119 } } // namespace v8::internal | 2113 } } // namespace v8::internal |
2120 | 2114 |
2121 #endif // V8_AST_H_ | 2115 #endif // V8_AST_H_ |
OLD | NEW |