OLD | NEW |
1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 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 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
127 #define DECLARE_TYPE_ENUM(type) k##type, | 127 #define DECLARE_TYPE_ENUM(type) k##type, |
128 enum Type { | 128 enum Type { |
129 AST_NODE_LIST(DECLARE_TYPE_ENUM) | 129 AST_NODE_LIST(DECLARE_TYPE_ENUM) |
130 kInvalid = -1 | 130 kInvalid = -1 |
131 }; | 131 }; |
132 #undef DECLARE_TYPE_ENUM | 132 #undef DECLARE_TYPE_ENUM |
133 | 133 |
134 static const int kNoNumber = -1; | 134 static const int kNoNumber = -1; |
135 static const int kFunctionEntryId = 2; // Using 0 could disguise errors. | 135 static const int kFunctionEntryId = 2; // Using 0 could disguise errors. |
136 | 136 |
137 AstNode() { | 137 // Override ZoneObjects's new to count allocated AST nodes. |
138 Isolate* isolate = Isolate::Current(); | 138 void* operator new(size_t size, Zone* zone) { |
| 139 Isolate* isolate = zone->isolate(); |
139 isolate->set_ast_node_count(isolate->ast_node_count() + 1); | 140 isolate->set_ast_node_count(isolate->ast_node_count() + 1); |
| 141 return zone->New(size); |
140 } | 142 } |
141 | 143 |
| 144 AstNode() {} |
| 145 |
142 virtual ~AstNode() { } | 146 virtual ~AstNode() { } |
143 | 147 |
144 virtual void Accept(AstVisitor* v) = 0; | 148 virtual void Accept(AstVisitor* v) = 0; |
145 virtual Type node_type() const { return kInvalid; } | 149 virtual Type node_type() const { return kInvalid; } |
146 | 150 |
147 // Type testing & conversion functions overridden by concrete subclasses. | 151 // Type testing & conversion functions overridden by concrete subclasses. |
148 #define DECLARE_NODE_FUNCTIONS(type) \ | 152 #define DECLARE_NODE_FUNCTIONS(type) \ |
149 virtual type* As##type() { return NULL; } | 153 virtual type* As##type() { return NULL; } |
150 AST_NODE_LIST(DECLARE_NODE_FUNCTIONS) | 154 AST_NODE_LIST(DECLARE_NODE_FUNCTIONS) |
151 #undef DECLARE_NODE_FUNCTIONS | 155 #undef DECLARE_NODE_FUNCTIONS |
(...skipping 14 matching lines...) Expand all Loading... |
166 | 170 |
167 protected: | 171 protected: |
168 static unsigned GetNextId() { return ReserveIdRange(1); } | 172 static unsigned GetNextId() { return ReserveIdRange(1); } |
169 static unsigned ReserveIdRange(int n) { | 173 static unsigned ReserveIdRange(int n) { |
170 Isolate* isolate = Isolate::Current(); | 174 Isolate* isolate = Isolate::Current(); |
171 unsigned tmp = isolate->ast_node_id(); | 175 unsigned tmp = isolate->ast_node_id(); |
172 isolate->set_ast_node_id(tmp + n); | 176 isolate->set_ast_node_id(tmp + n); |
173 return tmp; | 177 return tmp; |
174 } | 178 } |
175 | 179 |
| 180 private: |
| 181 // Hidden to prevent accidental usage. It would have to load the |
| 182 // current zone from the TLS. |
| 183 void* operator new(size_t size); |
| 184 |
176 friend class CaseClause; // Generates AST IDs. | 185 friend class CaseClause; // Generates AST IDs. |
177 }; | 186 }; |
178 | 187 |
179 | 188 |
180 class Statement: public AstNode { | 189 class Statement: public AstNode { |
181 public: | 190 public: |
182 Statement() : statement_pos_(RelocInfo::kNoPosition) {} | 191 Statement() : statement_pos_(RelocInfo::kNoPosition) {} |
183 | 192 |
184 virtual Statement* AsStatement() { return this; } | 193 virtual Statement* AsStatement() { return this; } |
185 | 194 |
(...skipping 1964 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2150 | 2159 |
2151 private: | 2160 private: |
2152 Isolate* isolate_; | 2161 Isolate* isolate_; |
2153 bool stack_overflow_; | 2162 bool stack_overflow_; |
2154 }; | 2163 }; |
2155 | 2164 |
2156 | 2165 |
2157 } } // namespace v8::internal | 2166 } } // namespace v8::internal |
2158 | 2167 |
2159 #endif // V8_AST_H_ | 2168 #endif // V8_AST_H_ |
OLD | NEW |