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 610 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
621 int recursion_depth, | 621 int recursion_depth, |
622 int budget, | 622 int budget, |
623 BoyerMooreLookahead* bm, | 623 BoyerMooreLookahead* bm, |
624 bool not_at_start) { | 624 bool not_at_start) { |
625 UNREACHABLE(); | 625 UNREACHABLE(); |
626 } | 626 } |
627 | 627 |
628 // If we know that the input is ASCII then there are some nodes that can | 628 // If we know that the input is ASCII then there are some nodes that can |
629 // never match. This method returns a node that can be substituted for | 629 // never match. This method returns a node that can be substituted for |
630 // itself, or NULL if the node can never match. | 630 // itself, or NULL if the node can never match. |
631 virtual RegExpNode* FilterASCII(int depth) { return this; } | 631 virtual RegExpNode* FilterASCII(int depth, bool ignore_case) { return this; } |
632 // Helper for FilterASCII. | 632 // Helper for FilterASCII. |
633 RegExpNode* replacement() { | 633 RegExpNode* replacement() { |
634 ASSERT(info()->replacement_calculated); | 634 ASSERT(info()->replacement_calculated); |
635 return replacement_; | 635 return replacement_; |
636 } | 636 } |
637 RegExpNode* set_replacement(RegExpNode* replacement) { | 637 RegExpNode* set_replacement(RegExpNode* replacement) { |
638 info()->replacement_calculated = true; | 638 info()->replacement_calculated = true; |
639 replacement_ = replacement; | 639 replacement_ = replacement; |
640 return replacement; // For convenience. | 640 return replacement; // For convenience. |
641 } | 641 } |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
716 int to_; | 716 int to_; |
717 }; | 717 }; |
718 | 718 |
719 | 719 |
720 class SeqRegExpNode: public RegExpNode { | 720 class SeqRegExpNode: public RegExpNode { |
721 public: | 721 public: |
722 explicit SeqRegExpNode(RegExpNode* on_success) | 722 explicit SeqRegExpNode(RegExpNode* on_success) |
723 : RegExpNode(on_success->zone()), on_success_(on_success) { } | 723 : RegExpNode(on_success->zone()), on_success_(on_success) { } |
724 RegExpNode* on_success() { return on_success_; } | 724 RegExpNode* on_success() { return on_success_; } |
725 void set_on_success(RegExpNode* node) { on_success_ = node; } | 725 void set_on_success(RegExpNode* node) { on_success_ = node; } |
726 virtual RegExpNode* FilterASCII(int depth); | 726 virtual RegExpNode* FilterASCII(int depth, bool ignore_case); |
727 virtual void FillInBMInfo(int offset, | 727 virtual void FillInBMInfo(int offset, |
728 int recursion_depth, | 728 int recursion_depth, |
729 int budget, | 729 int budget, |
730 BoyerMooreLookahead* bm, | 730 BoyerMooreLookahead* bm, |
731 bool not_at_start) { | 731 bool not_at_start) { |
732 on_success_->FillInBMInfo( | 732 on_success_->FillInBMInfo( |
733 offset, recursion_depth + 1, budget - 1, bm, not_at_start); | 733 offset, recursion_depth + 1, budget - 1, bm, not_at_start); |
734 if (offset == 0) set_bm_info(not_at_start, bm); | 734 if (offset == 0) set_bm_info(not_at_start, bm); |
735 } | 735 } |
736 | 736 |
737 protected: | 737 protected: |
738 RegExpNode* FilterSuccessor(int depth); | 738 RegExpNode* FilterSuccessor(int depth, bool ignore_case); |
739 | 739 |
740 private: | 740 private: |
741 RegExpNode* on_success_; | 741 RegExpNode* on_success_; |
742 }; | 742 }; |
743 | 743 |
744 | 744 |
745 class ActionNode: public SeqRegExpNode { | 745 class ActionNode: public SeqRegExpNode { |
746 public: | 746 public: |
747 enum Type { | 747 enum Type { |
748 SET_REGISTER, | 748 SET_REGISTER, |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
854 void MakeCaseIndependent(bool is_ascii); | 854 void MakeCaseIndependent(bool is_ascii); |
855 virtual int GreedyLoopTextLength(); | 855 virtual int GreedyLoopTextLength(); |
856 virtual RegExpNode* GetSuccessorOfOmnivorousTextNode( | 856 virtual RegExpNode* GetSuccessorOfOmnivorousTextNode( |
857 RegExpCompiler* compiler); | 857 RegExpCompiler* compiler); |
858 virtual void FillInBMInfo(int offset, | 858 virtual void FillInBMInfo(int offset, |
859 int recursion_depth, | 859 int recursion_depth, |
860 int budget, | 860 int budget, |
861 BoyerMooreLookahead* bm, | 861 BoyerMooreLookahead* bm, |
862 bool not_at_start); | 862 bool not_at_start); |
863 void CalculateOffsets(); | 863 void CalculateOffsets(); |
864 virtual RegExpNode* FilterASCII(int depth); | 864 virtual RegExpNode* FilterASCII(int depth, bool ignore_case); |
865 | 865 |
866 private: | 866 private: |
867 enum TextEmitPassType { | 867 enum TextEmitPassType { |
868 NON_ASCII_MATCH, // Check for characters that can't match. | 868 NON_ASCII_MATCH, // Check for characters that can't match. |
869 SIMPLE_CHARACTER_MATCH, // Case-dependent single character check. | 869 SIMPLE_CHARACTER_MATCH, // Case-dependent single character check. |
870 NON_LETTER_CHARACTER_MATCH, // Check characters that have no case equivs. | 870 NON_LETTER_CHARACTER_MATCH, // Check characters that have no case equivs. |
871 CASE_CHARACTER_MATCH, // Case-independent single character check. | 871 CASE_CHARACTER_MATCH, // Case-independent single character check. |
872 CHARACTER_CLASS_MATCH // Character class. | 872 CHARACTER_CLASS_MATCH // Character class. |
873 }; | 873 }; |
874 static bool SkipPass(int pass, bool ignore_case); | 874 static bool SkipPass(int pass, bool ignore_case); |
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1090 int recursion_depth, | 1090 int recursion_depth, |
1091 int budget, | 1091 int budget, |
1092 BoyerMooreLookahead* bm, | 1092 BoyerMooreLookahead* bm, |
1093 bool not_at_start); | 1093 bool not_at_start); |
1094 | 1094 |
1095 bool being_calculated() { return being_calculated_; } | 1095 bool being_calculated() { return being_calculated_; } |
1096 bool not_at_start() { return not_at_start_; } | 1096 bool not_at_start() { return not_at_start_; } |
1097 void set_not_at_start() { not_at_start_ = true; } | 1097 void set_not_at_start() { not_at_start_ = true; } |
1098 void set_being_calculated(bool b) { being_calculated_ = b; } | 1098 void set_being_calculated(bool b) { being_calculated_ = b; } |
1099 virtual bool try_to_emit_quick_check_for_alternative(int i) { return true; } | 1099 virtual bool try_to_emit_quick_check_for_alternative(int i) { return true; } |
1100 virtual RegExpNode* FilterASCII(int depth); | 1100 virtual RegExpNode* FilterASCII(int depth, bool ignore_case); |
1101 | 1101 |
1102 protected: | 1102 protected: |
1103 int GreedyLoopTextLengthForAlternative(GuardedAlternative* alternative); | 1103 int GreedyLoopTextLengthForAlternative(GuardedAlternative* alternative); |
1104 ZoneList<GuardedAlternative>* alternatives_; | 1104 ZoneList<GuardedAlternative>* alternatives_; |
1105 | 1105 |
1106 private: | 1106 private: |
1107 friend class DispatchTableConstructor; | 1107 friend class DispatchTableConstructor; |
1108 friend class Analysis; | 1108 friend class Analysis; |
1109 void GenerateGuard(RegExpMacroAssembler* macro_assembler, | 1109 void GenerateGuard(RegExpMacroAssembler* macro_assembler, |
1110 Guard* guard, | 1110 Guard* guard, |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1148 alternatives_->at(1).node()->FillInBMInfo( | 1148 alternatives_->at(1).node()->FillInBMInfo( |
1149 offset, recursion_depth + 1, budget - 1, bm, not_at_start); | 1149 offset, recursion_depth + 1, budget - 1, bm, not_at_start); |
1150 if (offset == 0) set_bm_info(not_at_start, bm); | 1150 if (offset == 0) set_bm_info(not_at_start, bm); |
1151 } | 1151 } |
1152 // For a negative lookahead we don't emit the quick check for the | 1152 // For a negative lookahead we don't emit the quick check for the |
1153 // alternative that is expected to fail. This is because quick check code | 1153 // alternative that is expected to fail. This is because quick check code |
1154 // starts by loading enough characters for the alternative that takes fewest | 1154 // starts by loading enough characters for the alternative that takes fewest |
1155 // characters, but on a negative lookahead the negative branch did not take | 1155 // characters, but on a negative lookahead the negative branch did not take |
1156 // part in that calculation (EatsAtLeast) so the assumptions don't hold. | 1156 // part in that calculation (EatsAtLeast) so the assumptions don't hold. |
1157 virtual bool try_to_emit_quick_check_for_alternative(int i) { return i != 0; } | 1157 virtual bool try_to_emit_quick_check_for_alternative(int i) { return i != 0; } |
1158 virtual RegExpNode* FilterASCII(int depth); | 1158 virtual RegExpNode* FilterASCII(int depth, bool ignore_case); |
1159 }; | 1159 }; |
1160 | 1160 |
1161 | 1161 |
1162 class LoopChoiceNode: public ChoiceNode { | 1162 class LoopChoiceNode: public ChoiceNode { |
1163 public: | 1163 public: |
1164 explicit LoopChoiceNode(bool body_can_be_zero_length, Zone* zone) | 1164 explicit LoopChoiceNode(bool body_can_be_zero_length, Zone* zone) |
1165 : ChoiceNode(2, zone), | 1165 : ChoiceNode(2, zone), |
1166 loop_node_(NULL), | 1166 loop_node_(NULL), |
1167 continue_node_(NULL), | 1167 continue_node_(NULL), |
1168 body_can_be_zero_length_(body_can_be_zero_length) { } | 1168 body_can_be_zero_length_(body_can_be_zero_length) { } |
1169 void AddLoopAlternative(GuardedAlternative alt); | 1169 void AddLoopAlternative(GuardedAlternative alt); |
1170 void AddContinueAlternative(GuardedAlternative alt); | 1170 void AddContinueAlternative(GuardedAlternative alt); |
1171 virtual void Emit(RegExpCompiler* compiler, Trace* trace); | 1171 virtual void Emit(RegExpCompiler* compiler, Trace* trace); |
1172 virtual int EatsAtLeast(int still_to_find, | 1172 virtual int EatsAtLeast(int still_to_find, |
1173 int recursion_depth, | 1173 int recursion_depth, |
1174 bool not_at_start); | 1174 bool not_at_start); |
1175 virtual void GetQuickCheckDetails(QuickCheckDetails* details, | 1175 virtual void GetQuickCheckDetails(QuickCheckDetails* details, |
1176 RegExpCompiler* compiler, | 1176 RegExpCompiler* compiler, |
1177 int characters_filled_in, | 1177 int characters_filled_in, |
1178 bool not_at_start); | 1178 bool not_at_start); |
1179 virtual void FillInBMInfo(int offset, | 1179 virtual void FillInBMInfo(int offset, |
1180 int recursion_depth, | 1180 int recursion_depth, |
1181 int budget, | 1181 int budget, |
1182 BoyerMooreLookahead* bm, | 1182 BoyerMooreLookahead* bm, |
1183 bool not_at_start); | 1183 bool not_at_start); |
1184 RegExpNode* loop_node() { return loop_node_; } | 1184 RegExpNode* loop_node() { return loop_node_; } |
1185 RegExpNode* continue_node() { return continue_node_; } | 1185 RegExpNode* continue_node() { return continue_node_; } |
1186 bool body_can_be_zero_length() { return body_can_be_zero_length_; } | 1186 bool body_can_be_zero_length() { return body_can_be_zero_length_; } |
1187 virtual void Accept(NodeVisitor* visitor); | 1187 virtual void Accept(NodeVisitor* visitor); |
1188 virtual RegExpNode* FilterASCII(int depth); | 1188 virtual RegExpNode* FilterASCII(int depth, bool ignore_case); |
1189 | 1189 |
1190 private: | 1190 private: |
1191 // AddAlternative is made private for loop nodes because alternatives | 1191 // AddAlternative is made private for loop nodes because alternatives |
1192 // should not be added freely, we need to keep track of which node | 1192 // should not be added freely, we need to keep track of which node |
1193 // goes back to the node itself. | 1193 // goes back to the node itself. |
1194 void AddAlternative(GuardedAlternative node) { | 1194 void AddAlternative(GuardedAlternative node) { |
1195 ChoiceNode::AddAlternative(node); | 1195 ChoiceNode::AddAlternative(node); |
1196 } | 1196 } |
1197 | 1197 |
1198 RegExpNode* loop_node_; | 1198 RegExpNode* loop_node_; |
(...skipping 441 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1640 Handle<String> sample_subject, | 1640 Handle<String> sample_subject, |
1641 bool is_ascii, Zone* zone); | 1641 bool is_ascii, Zone* zone); |
1642 | 1642 |
1643 static void DotPrint(const char* label, RegExpNode* node, bool ignore_case); | 1643 static void DotPrint(const char* label, RegExpNode* node, bool ignore_case); |
1644 }; | 1644 }; |
1645 | 1645 |
1646 | 1646 |
1647 } } // namespace v8::internal | 1647 } } // namespace v8::internal |
1648 | 1648 |
1649 #endif // V8_JSREGEXP_H_ | 1649 #endif // V8_JSREGEXP_H_ |
OLD | NEW |