| OLD | NEW |
| 1 // Copyright 2006-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2008 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 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 157 uc16 to() { return to_; } | 157 uc16 to() { return to_; } |
| 158 void set_to(uc16 value) { to_ = value; } | 158 void set_to(uc16 value) { to_ = value; } |
| 159 bool is_valid() { return from_ <= to_; } | 159 bool is_valid() { return from_ <= to_; } |
| 160 bool IsSingleton() { return (from_ == to_); } | 160 bool IsSingleton() { return (from_ == to_); } |
| 161 private: | 161 private: |
| 162 uc16 from_; | 162 uc16 from_; |
| 163 uc16 to_; | 163 uc16 to_; |
| 164 }; | 164 }; |
| 165 | 165 |
| 166 | 166 |
| 167 template <typename Node, class Callback> |
| 168 static void DoForEach(Node* node, Callback callback); |
| 169 |
| 170 |
| 167 // A zone splay tree. The config type parameter encapsulates the | 171 // A zone splay tree. The config type parameter encapsulates the |
| 168 // different configurations of a concrete splay tree: | 172 // different configurations of a concrete splay tree: |
| 169 // | 173 // |
| 170 // typedef Key: the key type | 174 // typedef Key: the key type |
| 171 // typedef Value: the value type | 175 // typedef Value: the value type |
| 172 // static const kNoKey: the dummy key used when no key is set | 176 // static const kNoKey: the dummy key used when no key is set |
| 173 // static const kNoValue: the dummy value used to initialize nodes | 177 // static const kNoValue: the dummy value used to initialize nodes |
| 174 // int (Compare)(Key& a, Key& b) -> {-1, 0, 1}: comparison function | 178 // int (Compare)(Key& a, Key& b) -> {-1, 0, 1}: comparison function |
| 175 // | 179 // |
| 176 template <typename Config> | 180 template <typename Config> |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 218 // tree. | 222 // tree. |
| 219 void Splay(const Key& key); | 223 void Splay(const Key& key); |
| 220 | 224 |
| 221 class Node : public ZoneObject { | 225 class Node : public ZoneObject { |
| 222 public: | 226 public: |
| 223 Node(const Key& key, const Value& value) | 227 Node(const Key& key, const Value& value) |
| 224 : key_(key), | 228 : key_(key), |
| 225 value_(value), | 229 value_(value), |
| 226 left_(NULL), | 230 left_(NULL), |
| 227 right_(NULL) { } | 231 right_(NULL) { } |
| 232 Key key() { return key_; } |
| 233 Value value() { return value_; } |
| 234 Node* left() { return left_; } |
| 235 Node* right() { return right_; } |
| 228 private: | 236 private: |
| 229 friend class ZoneSplayTree; | 237 friend class ZoneSplayTree; |
| 230 friend class Locator; | 238 friend class Locator; |
| 231 Key key_; | 239 Key key_; |
| 232 Value value_; | 240 Value value_; |
| 233 Node* left_; | 241 Node* left_; |
| 234 Node* right_; | 242 Node* right_; |
| 235 }; | 243 }; |
| 236 | 244 |
| 237 // A locator provides access to a node in the tree without actually | 245 // A locator provides access to a node in the tree without actually |
| 238 // exposing the node. | 246 // exposing the node. |
| 239 class Locator { | 247 class Locator { |
| 240 public: | 248 public: |
| 249 Locator(Node* node) : node_(node) { } |
| 241 Locator() : node_(NULL) { } | 250 Locator() : node_(NULL) { } |
| 242 const Key& key() { return node_->key_; } | 251 const Key& key() { return node_->key_; } |
| 243 Value& value() { return node_->value_; } | 252 Value& value() { return node_->value_; } |
| 244 void set_value(const Value& value) { node_->value_ = value; } | 253 void set_value(const Value& value) { node_->value_ = value; } |
| 245 inline void bind(Node* node) { node_ = node; } | 254 inline void bind(Node* node) { node_ = node; } |
| 246 private: | 255 private: |
| 247 Node* node_; | 256 Node* node_; |
| 248 }; | 257 }; |
| 249 | 258 |
| 259 template <class Callback> |
| 260 void ForEach(Callback c) { |
| 261 DoForEach<typename ZoneSplayTree<Config>::Node, Callback>(root_, c); |
| 262 } |
| 263 |
| 250 private: | 264 private: |
| 251 Node* root_; | 265 Node* root_; |
| 252 }; | 266 }; |
| 253 | 267 |
| 254 | 268 |
| 255 // A set of unsigned integers that behaves especially well on small | 269 // A set of unsigned integers that behaves especially well on small |
| 256 // integers (< 32). May do zone-allocation. | 270 // integers (< 32). May do zone-allocation. |
| 257 class OutSet { | 271 class OutSet { |
| 258 public: | 272 public: |
| 259 OutSet() : first_(0), remaining_(NULL) { } | 273 OutSet() : first_(0), remaining_(NULL) { } |
| 260 explicit inline OutSet(unsigned value); | 274 explicit inline OutSet(unsigned value); |
| 261 static inline OutSet empty() { return OutSet(); } | 275 static inline OutSet empty() { return OutSet(); } |
| 262 void Set(unsigned value); | 276 void Set(unsigned value); |
| 263 bool Get(unsigned value); | 277 bool Get(unsigned value); |
| 264 OutSet Clone(); | 278 OutSet Clone(); |
| 279 static const unsigned kFirstLimit = 32; |
| 265 private: | 280 private: |
| 266 OutSet(uint32_t first, ZoneList<unsigned>* remaining) | 281 OutSet(uint32_t first, ZoneList<unsigned>* remaining) |
| 267 : first_(first), remaining_(remaining) { } | 282 : first_(first), remaining_(remaining) { } |
| 268 static const unsigned kFirstLimit = 32; | |
| 269 uint32_t first_; | 283 uint32_t first_; |
| 270 ZoneList<unsigned>* remaining_; | 284 ZoneList<unsigned>* remaining_; |
| 271 }; | 285 }; |
| 272 | 286 |
| 273 | 287 |
| 274 // A mapping from integers, specified as ranges, to a set of integers. | 288 // A mapping from integers, specified as ranges, to a set of integers. |
| 275 // Used for mapping character ranges to choices. | 289 // Used for mapping character ranges to choices. |
| 276 class DispatchTable { | 290 class DispatchTable { |
| 277 public: | 291 public: |
| 278 class Entry { | 292 class Entry { |
| (...skipping 23 matching lines...) Expand all Loading... |
| 302 if (a == b) | 316 if (a == b) |
| 303 return 0; | 317 return 0; |
| 304 else if (a < b) | 318 else if (a < b) |
| 305 return -1; | 319 return -1; |
| 306 else | 320 else |
| 307 return 1; | 321 return 1; |
| 308 } | 322 } |
| 309 }; | 323 }; |
| 310 void AddRange(CharacterRange range, int value); | 324 void AddRange(CharacterRange range, int value); |
| 311 OutSet Get(uc16 value); | 325 OutSet Get(uc16 value); |
| 326 void Dump(); |
| 312 private: | 327 private: |
| 313 ZoneSplayTree<Config>* tree() { return &tree_; } | 328 ZoneSplayTree<Config>* tree() { return &tree_; } |
| 314 ZoneSplayTree<Config> tree_; | 329 ZoneSplayTree<Config> tree_; |
| 315 }; | 330 }; |
| 316 | 331 |
| 317 | 332 |
| 318 struct RegExpParseResult { | 333 struct RegExpParseResult { |
| 319 RegExpTree* tree; | 334 RegExpTree* tree; |
| 320 bool has_character_escapes; | 335 bool has_character_escapes; |
| 321 Handle<String> error; | 336 Handle<String> error; |
| 322 int capture_count; | 337 int capture_count; |
| 323 }; | 338 }; |
| 324 | 339 |
| 325 | 340 |
| 326 class RegExpEngine: public AllStatic { | 341 class RegExpEngine: public AllStatic { |
| 327 public: | 342 public: |
| 328 static RegExpNode* Compile(RegExpParseResult* input); | 343 static RegExpNode* Compile(RegExpParseResult* input); |
| 329 static void DotPrint(const char* label, RegExpNode* node); | 344 static void DotPrint(const char* label, RegExpNode* node); |
| 330 }; | 345 }; |
| 331 | 346 |
| 332 | 347 |
| 333 } } // namespace v8::internal | 348 } } // namespace v8::internal |
| 334 | 349 |
| 335 #endif // V8_JSREGEXP_H_ | 350 #endif // V8_JSREGEXP_H_ |
| OLD | NEW |