| 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 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 184 to_(to) { | 184 to_(to) { |
| 185 } | 185 } |
| 186 static void AddClassEscape(uc16 type, ZoneList<CharacterRange>* ranges); | 186 static void AddClassEscape(uc16 type, ZoneList<CharacterRange>* ranges); |
| 187 static inline CharacterRange Singleton(uc16 value) { | 187 static inline CharacterRange Singleton(uc16 value) { |
| 188 return CharacterRange(value, value); | 188 return CharacterRange(value, value); |
| 189 } | 189 } |
| 190 static inline CharacterRange Range(uc16 from, uc16 to) { | 190 static inline CharacterRange Range(uc16 from, uc16 to) { |
| 191 ASSERT(from <= to); | 191 ASSERT(from <= to); |
| 192 return CharacterRange(from, to); | 192 return CharacterRange(from, to); |
| 193 } | 193 } |
| 194 static inline CharacterRange Everything() { |
| 195 return CharacterRange(0, 0xFFFF); |
| 196 } |
| 194 bool Contains(uc16 i) { return from_ <= i && i <= to_; } | 197 bool Contains(uc16 i) { return from_ <= i && i <= to_; } |
| 195 uc16 from() const { return from_; } | 198 uc16 from() const { return from_; } |
| 196 void set_from(uc16 value) { from_ = value; } | 199 void set_from(uc16 value) { from_ = value; } |
| 197 uc16 to() const { return to_; } | 200 uc16 to() const { return to_; } |
| 198 void set_to(uc16 value) { to_ = value; } | 201 void set_to(uc16 value) { to_ = value; } |
| 199 bool is_valid() { return from_ <= to_; } | 202 bool is_valid() { return from_ <= to_; } |
| 200 bool IsSingleton() { return (from_ == to_); } | 203 bool IsSingleton() { return (from_ == to_); } |
| 201 private: | 204 private: |
| 202 uc16 from_; | 205 uc16 from_; |
| 203 uc16 to_; | 206 uc16 to_; |
| (...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 382 // successors in a zone and caches them. | 385 // successors in a zone and caches them. |
| 383 OutSet* empty() { return &empty_; } | 386 OutSet* empty() { return &empty_; } |
| 384 OutSet empty_; | 387 OutSet empty_; |
| 385 ZoneSplayTree<Config>* tree() { return &tree_; } | 388 ZoneSplayTree<Config>* tree() { return &tree_; } |
| 386 ZoneSplayTree<Config> tree_; | 389 ZoneSplayTree<Config> tree_; |
| 387 }; | 390 }; |
| 388 | 391 |
| 389 | 392 |
| 390 #define FOR_EACH_NODE_TYPE(VISIT) \ | 393 #define FOR_EACH_NODE_TYPE(VISIT) \ |
| 391 VISIT(End) \ | 394 VISIT(End) \ |
| 392 VISIT(Atom) \ | |
| 393 VISIT(Action) \ | 395 VISIT(Action) \ |
| 394 VISIT(Choice) \ | 396 VISIT(Choice) \ |
| 395 VISIT(Backreference) \ | 397 VISIT(Backreference) \ |
| 396 VISIT(CharacterClass) | 398 VISIT(Text) |
| 399 |
| 400 |
| 401 #define FOR_EACH_REG_EXP_TREE_TYPE(VISIT) \ |
| 402 VISIT(Disjunction) \ |
| 403 VISIT(Alternative) \ |
| 404 VISIT(Assertion) \ |
| 405 VISIT(CharacterClass) \ |
| 406 VISIT(Atom) \ |
| 407 VISIT(Quantifier) \ |
| 408 VISIT(Capture) \ |
| 409 VISIT(Lookahead) \ |
| 410 VISIT(Backreference) \ |
| 411 VISIT(Empty) \ |
| 412 VISIT(Text) |
| 413 |
| 414 |
| 415 #define FORWARD_DECLARE(Name) class RegExp##Name; |
| 416 FOR_EACH_REG_EXP_TREE_TYPE(FORWARD_DECLARE) |
| 417 #undef FORWARD_DECLARE |
| 418 |
| 419 |
| 420 class TextElement { |
| 421 public: |
| 422 enum Type {UNINITIALIZED, ATOM, CHAR_CLASS}; |
| 423 TextElement() : type(UNINITIALIZED) { } |
| 424 TextElement(Type t) : type(t) { } |
| 425 static TextElement Atom(RegExpAtom* atom); |
| 426 static TextElement CharClass(RegExpCharacterClass* char_class); |
| 427 Type type; |
| 428 union { |
| 429 RegExpAtom* u_atom; |
| 430 RegExpCharacterClass* u_char_class; |
| 431 } data; |
| 432 }; |
| 397 | 433 |
| 398 | 434 |
| 399 class NodeInfo { | 435 class NodeInfo { |
| 400 public: | 436 public: |
| 401 NodeInfo() | 437 NodeInfo() |
| 402 : being_analyzed(false), | 438 : being_analyzed(false), |
| 403 been_analyzed(false), | 439 been_analyzed(false), |
| 404 propagate_word(false), | 440 propagate_word(false), |
| 405 propagate_line(false) { } | 441 propagate_line(false) { } |
| 406 bool being_analyzed: 1; | 442 bool being_analyzed: 1; |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 479 } u_position_register; | 515 } u_position_register; |
| 480 } data_; | 516 } data_; |
| 481 ActionNode(Type type, RegExpNode* on_success) | 517 ActionNode(Type type, RegExpNode* on_success) |
| 482 : SeqRegExpNode(on_success), | 518 : SeqRegExpNode(on_success), |
| 483 type_(type) { } | 519 type_(type) { } |
| 484 Type type_; | 520 Type type_; |
| 485 friend class DotPrinter; | 521 friend class DotPrinter; |
| 486 }; | 522 }; |
| 487 | 523 |
| 488 | 524 |
| 489 class AtomNode: public SeqRegExpNode { | 525 class TextNode: public SeqRegExpNode { |
| 490 public: | 526 public: |
| 491 AtomNode(Vector<const uc16> data, | 527 TextNode(ZoneList<TextElement>* elms, |
| 492 RegExpNode* on_success, | 528 RegExpNode* on_success, |
| 493 RegExpNode* on_failure) | 529 RegExpNode* on_failure) |
| 494 : SeqRegExpNode(on_success), | 530 : SeqRegExpNode(on_success), |
| 495 on_failure_(on_failure), | 531 on_failure_(on_failure), |
| 496 data_(data) { } | 532 elms_(elms) { } |
| 497 virtual void Accept(NodeVisitor* visitor); | 533 virtual void Accept(NodeVisitor* visitor); |
| 498 Vector<const uc16> data() { return data_; } | 534 virtual bool Emit(RegExpCompiler* compiler) { return false; } |
| 499 RegExpNode* on_failure() { return on_failure_; } | 535 RegExpNode* on_failure() { return on_failure_; } |
| 500 virtual bool Emit(RegExpCompiler* compiler) { return false; } | 536 ZoneList<TextElement>* elements() { return elms_; } |
| 501 private: | 537 private: |
| 502 RegExpNode* on_failure_; | 538 RegExpNode* on_failure_; |
| 503 Vector<const uc16> data_; | 539 ZoneList<TextElement>* elms_; |
| 504 }; | 540 }; |
| 505 | 541 |
| 506 | 542 |
| 507 class BackreferenceNode: public SeqRegExpNode { | 543 class BackreferenceNode: public SeqRegExpNode { |
| 508 public: | 544 public: |
| 509 BackreferenceNode(int start_reg, | 545 BackreferenceNode(int start_reg, |
| 510 int end_reg, | 546 int end_reg, |
| 511 RegExpNode* on_success, | 547 RegExpNode* on_success, |
| 512 RegExpNode* on_failure) | 548 RegExpNode* on_failure) |
| 513 : SeqRegExpNode(on_success), | 549 : SeqRegExpNode(on_success), |
| 514 on_failure_(on_failure), | 550 on_failure_(on_failure), |
| 515 start_reg_(start_reg), | 551 start_reg_(start_reg), |
| 516 end_reg_(end_reg) { } | 552 end_reg_(end_reg) { } |
| 517 virtual void Accept(NodeVisitor* visitor); | 553 virtual void Accept(NodeVisitor* visitor); |
| 518 RegExpNode* on_failure() { return on_failure_; } | 554 RegExpNode* on_failure() { return on_failure_; } |
| 519 int start_register() { return start_reg_; } | 555 int start_register() { return start_reg_; } |
| 520 int end_register() { return end_reg_; } | 556 int end_register() { return end_reg_; } |
| 521 virtual bool Emit(RegExpCompiler* compiler) { return false; } | 557 virtual bool Emit(RegExpCompiler* compiler) { return false; } |
| 522 private: | 558 private: |
| 523 RegExpNode* on_failure_; | 559 RegExpNode* on_failure_; |
| 524 int start_reg_; | 560 int start_reg_; |
| 525 int end_reg_; | 561 int end_reg_; |
| 526 }; | 562 }; |
| 527 | 563 |
| 528 | 564 |
| 529 class CharacterClassNode: public SeqRegExpNode { | |
| 530 public: | |
| 531 CharacterClassNode(ZoneList<CharacterRange>* ranges, | |
| 532 bool is_negated, | |
| 533 RegExpNode* on_success, | |
| 534 RegExpNode* on_failure) | |
| 535 : SeqRegExpNode(on_success), | |
| 536 on_failure_(on_failure), | |
| 537 ranges_(ranges), | |
| 538 is_negated_(is_negated ) { } | |
| 539 virtual void Accept(NodeVisitor* visitor); | |
| 540 ZoneList<CharacterRange>* ranges() { return ranges_; } | |
| 541 bool is_negated() { return is_negated_; } | |
| 542 RegExpNode* on_failure() { return on_failure_; } | |
| 543 virtual bool Emit(RegExpCompiler* compiler) { return false; } | |
| 544 static void AddInverseToTable(ZoneList<CharacterRange>* ranges, | |
| 545 DispatchTable* table, | |
| 546 int index); | |
| 547 private: | |
| 548 RegExpNode* on_failure_; | |
| 549 ZoneList<CharacterRange>* ranges_; | |
| 550 bool is_negated_; | |
| 551 }; | |
| 552 | |
| 553 | |
| 554 class EndNode: public RegExpNode { | 565 class EndNode: public RegExpNode { |
| 555 public: | 566 public: |
| 556 enum Action { ACCEPT, BACKTRACK }; | 567 enum Action { ACCEPT, BACKTRACK }; |
| 557 explicit EndNode(Action action) : action_(action) { } | 568 explicit EndNode(Action action) : action_(action) { } |
| 558 virtual void Accept(NodeVisitor* visitor); | 569 virtual void Accept(NodeVisitor* visitor); |
| 559 virtual bool Emit(RegExpCompiler* compiler); | 570 virtual bool Emit(RegExpCompiler* compiler); |
| 560 virtual bool IsBacktrack() { return action_ == BACKTRACK; } | 571 virtual bool IsBacktrack() { return action_ == BACKTRACK; } |
| 561 private: | 572 private: |
| 562 Action action_; | 573 Action action_; |
| 563 }; | 574 }; |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 685 static Handle<FixedArray> Compile(RegExpParseResult* input, | 696 static Handle<FixedArray> Compile(RegExpParseResult* input, |
| 686 RegExpNode** node_return, | 697 RegExpNode** node_return, |
| 687 bool ignore_case); | 698 bool ignore_case); |
| 688 static void DotPrint(const char* label, RegExpNode* node); | 699 static void DotPrint(const char* label, RegExpNode* node); |
| 689 }; | 700 }; |
| 690 | 701 |
| 691 | 702 |
| 692 } } // namespace v8::internal | 703 } } // namespace v8::internal |
| 693 | 704 |
| 694 #endif // V8_JSREGEXP_H_ | 705 #endif // V8_JSREGEXP_H_ |
| OLD | NEW |