| 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 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 248 // Sets are equal. | 248 // Sets are equal. |
| 249 bool Equals() { return (bits_ & (kInFirst | kInSecond)) == 0; } | 249 bool Equals() { return (bits_ & (kInFirst | kInSecond)) == 0; } |
| 250 // First set contains second. | 250 // First set contains second. |
| 251 bool Contains() { return (bits_ & kInSecond) == 0; } | 251 bool Contains() { return (bits_ & kInSecond) == 0; } |
| 252 // Second set contains first. | 252 // Second set contains first. |
| 253 bool ContainedIn() { return (bits_ & kInFirst) == 0; } | 253 bool ContainedIn() { return (bits_ & kInFirst) == 0; } |
| 254 bool NonTrivialIntersection() { | 254 bool NonTrivialIntersection() { |
| 255 return (bits_ == (kInFirst | kInSecond | kInBoth)); | 255 return (bits_ == (kInFirst | kInSecond | kInBoth)); |
| 256 } | 256 } |
| 257 int value() { return bits_; } | 257 int value() { return bits_; } |
| 258 |
| 258 private: | 259 private: |
| 259 int bits_; | 260 int bits_; |
| 260 }; | 261 }; |
| 261 | 262 |
| 262 | 263 |
| 263 class CharacterRange { | 264 class CharacterRange { |
| 264 public: | 265 public: |
| 265 CharacterRange() : from_(0), to_(0) { } | 266 CharacterRange() : from_(0), to_(0) { } |
| 266 // For compatibility with the CHECK_OK macro | 267 // For compatibility with the CHECK_OK macro |
| 267 CharacterRange(void* null) { ASSERT_EQ(NULL, null); } //NOLINT | 268 CharacterRange(void* null) { ASSERT_EQ(NULL, null); } //NOLINT |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 397 return 1; | 398 return 1; |
| 398 } | 399 } |
| 399 }; | 400 }; |
| 400 | 401 |
| 401 void AddRange(CharacterRange range, int value); | 402 void AddRange(CharacterRange range, int value); |
| 402 OutSet* Get(uc16 value); | 403 OutSet* Get(uc16 value); |
| 403 void Dump(); | 404 void Dump(); |
| 404 | 405 |
| 405 template <typename Callback> | 406 template <typename Callback> |
| 406 void ForEach(Callback* callback) { return tree()->ForEach(callback); } | 407 void ForEach(Callback* callback) { return tree()->ForEach(callback); } |
| 408 |
| 407 private: | 409 private: |
| 408 // There can't be a static empty set since it allocates its | 410 // There can't be a static empty set since it allocates its |
| 409 // successors in a zone and caches them. | 411 // successors in a zone and caches them. |
| 410 OutSet* empty() { return &empty_; } | 412 OutSet* empty() { return &empty_; } |
| 411 OutSet empty_; | 413 OutSet empty_; |
| 412 ZoneSplayTree<Config>* tree() { return &tree_; } | 414 ZoneSplayTree<Config>* tree() { return &tree_; } |
| 413 ZoneSplayTree<Config> tree_; | 415 ZoneSplayTree<Config> tree_; |
| 414 }; | 416 }; |
| 415 | 417 |
| 416 | 418 |
| (...skipping 369 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 786 int filled_in, | 788 int filled_in, |
| 787 bool not_at_start) { | 789 bool not_at_start) { |
| 788 return on_success()->GetQuickCheckDetails( | 790 return on_success()->GetQuickCheckDetails( |
| 789 details, compiler, filled_in, not_at_start); | 791 details, compiler, filled_in, not_at_start); |
| 790 } | 792 } |
| 791 Type type() { return type_; } | 793 Type type() { return type_; } |
| 792 // TODO(erikcorry): We should allow some action nodes in greedy loops. | 794 // TODO(erikcorry): We should allow some action nodes in greedy loops. |
| 793 virtual int GreedyLoopTextLength() { return kNodeIsTooComplexForGreedyLoops; } | 795 virtual int GreedyLoopTextLength() { return kNodeIsTooComplexForGreedyLoops; } |
| 794 virtual ActionNode* Clone() { return new ActionNode(*this); } | 796 virtual ActionNode* Clone() { return new ActionNode(*this); } |
| 795 virtual int ComputeFirstCharacterSet(int budget); | 797 virtual int ComputeFirstCharacterSet(int budget); |
| 798 |
| 796 private: | 799 private: |
| 797 union { | 800 union { |
| 798 struct { | 801 struct { |
| 799 int reg; | 802 int reg; |
| 800 int value; | 803 int value; |
| 801 } u_store_register; | 804 } u_store_register; |
| 802 struct { | 805 struct { |
| 803 int reg; | 806 int reg; |
| 804 } u_increment_register; | 807 } u_increment_register; |
| 805 struct { | 808 struct { |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 854 ZoneList<TextElement>* elements() { return elms_; } | 857 ZoneList<TextElement>* elements() { return elms_; } |
| 855 void MakeCaseIndependent(bool is_ascii); | 858 void MakeCaseIndependent(bool is_ascii); |
| 856 virtual int GreedyLoopTextLength(); | 859 virtual int GreedyLoopTextLength(); |
| 857 virtual TextNode* Clone() { | 860 virtual TextNode* Clone() { |
| 858 TextNode* result = new TextNode(*this); | 861 TextNode* result = new TextNode(*this); |
| 859 result->CalculateOffsets(); | 862 result->CalculateOffsets(); |
| 860 return result; | 863 return result; |
| 861 } | 864 } |
| 862 void CalculateOffsets(); | 865 void CalculateOffsets(); |
| 863 virtual int ComputeFirstCharacterSet(int budget); | 866 virtual int ComputeFirstCharacterSet(int budget); |
| 867 |
| 864 private: | 868 private: |
| 865 enum TextEmitPassType { | 869 enum TextEmitPassType { |
| 866 NON_ASCII_MATCH, // Check for characters that can't match. | 870 NON_ASCII_MATCH, // Check for characters that can't match. |
| 867 SIMPLE_CHARACTER_MATCH, // Case-dependent single character check. | 871 SIMPLE_CHARACTER_MATCH, // Case-dependent single character check. |
| 868 NON_LETTER_CHARACTER_MATCH, // Check characters that have no case equivs. | 872 NON_LETTER_CHARACTER_MATCH, // Check characters that have no case equivs. |
| 869 CASE_CHARACTER_MATCH, // Case-independent single character check. | 873 CASE_CHARACTER_MATCH, // Case-independent single character check. |
| 870 CHARACTER_CLASS_MATCH // Character class. | 874 CHARACTER_CLASS_MATCH // Character class. |
| 871 }; | 875 }; |
| 872 static bool SkipPass(int pass, bool ignore_case); | 876 static bool SkipPass(int pass, bool ignore_case); |
| 873 static const int kFirstRealPass = SIMPLE_CHARACTER_MATCH; | 877 static const int kFirstRealPass = SIMPLE_CHARACTER_MATCH; |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 918 int recursion_depth, | 922 int recursion_depth, |
| 919 bool not_at_start); | 923 bool not_at_start); |
| 920 virtual void GetQuickCheckDetails(QuickCheckDetails* details, | 924 virtual void GetQuickCheckDetails(QuickCheckDetails* details, |
| 921 RegExpCompiler* compiler, | 925 RegExpCompiler* compiler, |
| 922 int filled_in, | 926 int filled_in, |
| 923 bool not_at_start); | 927 bool not_at_start); |
| 924 virtual int ComputeFirstCharacterSet(int budget); | 928 virtual int ComputeFirstCharacterSet(int budget); |
| 925 virtual AssertionNode* Clone() { return new AssertionNode(*this); } | 929 virtual AssertionNode* Clone() { return new AssertionNode(*this); } |
| 926 AssertionNodeType type() { return type_; } | 930 AssertionNodeType type() { return type_; } |
| 927 void set_type(AssertionNodeType type) { type_ = type; } | 931 void set_type(AssertionNodeType type) { type_ = type; } |
| 932 |
| 928 private: | 933 private: |
| 929 AssertionNode(AssertionNodeType t, RegExpNode* on_success) | 934 AssertionNode(AssertionNodeType t, RegExpNode* on_success) |
| 930 : SeqRegExpNode(on_success), type_(t) { } | 935 : SeqRegExpNode(on_success), type_(t) { } |
| 931 AssertionNodeType type_; | 936 AssertionNodeType type_; |
| 932 }; | 937 }; |
| 933 | 938 |
| 934 | 939 |
| 935 class BackReferenceNode: public SeqRegExpNode { | 940 class BackReferenceNode: public SeqRegExpNode { |
| 936 public: | 941 public: |
| 937 BackReferenceNode(int start_reg, | 942 BackReferenceNode(int start_reg, |
| (...skipping 10 matching lines...) Expand all Loading... |
| 948 int recursion_depth, | 953 int recursion_depth, |
| 949 bool not_at_start); | 954 bool not_at_start); |
| 950 virtual void GetQuickCheckDetails(QuickCheckDetails* details, | 955 virtual void GetQuickCheckDetails(QuickCheckDetails* details, |
| 951 RegExpCompiler* compiler, | 956 RegExpCompiler* compiler, |
| 952 int characters_filled_in, | 957 int characters_filled_in, |
| 953 bool not_at_start) { | 958 bool not_at_start) { |
| 954 return; | 959 return; |
| 955 } | 960 } |
| 956 virtual BackReferenceNode* Clone() { return new BackReferenceNode(*this); } | 961 virtual BackReferenceNode* Clone() { return new BackReferenceNode(*this); } |
| 957 virtual int ComputeFirstCharacterSet(int budget); | 962 virtual int ComputeFirstCharacterSet(int budget); |
| 963 |
| 958 private: | 964 private: |
| 959 int start_reg_; | 965 int start_reg_; |
| 960 int end_reg_; | 966 int end_reg_; |
| 961 }; | 967 }; |
| 962 | 968 |
| 963 | 969 |
| 964 class EndNode: public RegExpNode { | 970 class EndNode: public RegExpNode { |
| 965 public: | 971 public: |
| 966 enum Action { ACCEPT, BACKTRACK, NEGATIVE_SUBMATCH_SUCCESS }; | 972 enum Action { ACCEPT, BACKTRACK, NEGATIVE_SUBMATCH_SUCCESS }; |
| 967 explicit EndNode(Action action) : action_(action) { } | 973 explicit EndNode(Action action) : action_(action) { } |
| (...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1294 void set_stop_node(RegExpNode* node) { stop_node_ = node; } | 1300 void set_stop_node(RegExpNode* node) { stop_node_ = node; } |
| 1295 void set_loop_label(Label* label) { loop_label_ = label; } | 1301 void set_loop_label(Label* label) { loop_label_ = label; } |
| 1296 void set_characters_preloaded(int count) { characters_preloaded_ = count; } | 1302 void set_characters_preloaded(int count) { characters_preloaded_ = count; } |
| 1297 void set_bound_checked_up_to(int to) { bound_checked_up_to_ = to; } | 1303 void set_bound_checked_up_to(int to) { bound_checked_up_to_ = to; } |
| 1298 void set_flush_budget(int to) { flush_budget_ = to; } | 1304 void set_flush_budget(int to) { flush_budget_ = to; } |
| 1299 void set_quick_check_performed(QuickCheckDetails* d) { | 1305 void set_quick_check_performed(QuickCheckDetails* d) { |
| 1300 quick_check_performed_ = *d; | 1306 quick_check_performed_ = *d; |
| 1301 } | 1307 } |
| 1302 void InvalidateCurrentCharacter(); | 1308 void InvalidateCurrentCharacter(); |
| 1303 void AdvanceCurrentPositionInTrace(int by, RegExpCompiler* compiler); | 1309 void AdvanceCurrentPositionInTrace(int by, RegExpCompiler* compiler); |
| 1310 |
| 1304 private: | 1311 private: |
| 1305 int FindAffectedRegisters(OutSet* affected_registers); | 1312 int FindAffectedRegisters(OutSet* affected_registers); |
| 1306 void PerformDeferredActions(RegExpMacroAssembler* macro, | 1313 void PerformDeferredActions(RegExpMacroAssembler* macro, |
| 1307 int max_register, | 1314 int max_register, |
| 1308 OutSet& affected_registers, | 1315 OutSet& affected_registers, |
| 1309 OutSet* registers_to_pop, | 1316 OutSet* registers_to_pop, |
| 1310 OutSet* registers_to_clear); | 1317 OutSet* registers_to_clear); |
| 1311 void RestoreAffectedRegisters(RegExpMacroAssembler* macro, | 1318 void RestoreAffectedRegisters(RegExpMacroAssembler* macro, |
| 1312 int max_register, | 1319 int max_register, |
| 1313 OutSet& registers_to_pop, | 1320 OutSet& registers_to_pop, |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1395 virtual void VisitLoopChoice(LoopChoiceNode* that); | 1402 virtual void VisitLoopChoice(LoopChoiceNode* that); |
| 1396 | 1403 |
| 1397 bool has_failed() { return error_message_ != NULL; } | 1404 bool has_failed() { return error_message_ != NULL; } |
| 1398 const char* error_message() { | 1405 const char* error_message() { |
| 1399 ASSERT(error_message_ != NULL); | 1406 ASSERT(error_message_ != NULL); |
| 1400 return error_message_; | 1407 return error_message_; |
| 1401 } | 1408 } |
| 1402 void fail(const char* error_message) { | 1409 void fail(const char* error_message) { |
| 1403 error_message_ = error_message; | 1410 error_message_ = error_message; |
| 1404 } | 1411 } |
| 1412 |
| 1405 private: | 1413 private: |
| 1406 bool ignore_case_; | 1414 bool ignore_case_; |
| 1407 bool is_ascii_; | 1415 bool is_ascii_; |
| 1408 const char* error_message_; | 1416 const char* error_message_; |
| 1409 | 1417 |
| 1410 DISALLOW_IMPLICIT_CONSTRUCTORS(Analysis); | 1418 DISALLOW_IMPLICIT_CONSTRUCTORS(Analysis); |
| 1411 }; | 1419 }; |
| 1412 | 1420 |
| 1413 | 1421 |
| 1414 struct RegExpCompileData { | 1422 struct RegExpCompileData { |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1482 int* vector_; | 1490 int* vector_; |
| 1483 int offsets_vector_length_; | 1491 int offsets_vector_length_; |
| 1484 | 1492 |
| 1485 friend class ExternalReference; | 1493 friend class ExternalReference; |
| 1486 }; | 1494 }; |
| 1487 | 1495 |
| 1488 | 1496 |
| 1489 } } // namespace v8::internal | 1497 } } // namespace v8::internal |
| 1490 | 1498 |
| 1491 #endif // V8_JSREGEXP_H_ | 1499 #endif // V8_JSREGEXP_H_ |
| OLD | NEW |