OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef V8_JSREGEXP_H_ | 5 #ifndef V8_JSREGEXP_H_ |
6 #define V8_JSREGEXP_H_ | 6 #define V8_JSREGEXP_H_ |
7 | 7 |
8 #include "src/allocation.h" | 8 #include "src/allocation.h" |
9 #include "src/assembler.h" | 9 #include "src/assembler.h" |
10 #include "src/zone-inl.h" | 10 #include "src/zone-inl.h" |
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
256 return CharacterRange(0, 0xFFFF); | 256 return CharacterRange(0, 0xFFFF); |
257 } | 257 } |
258 bool Contains(uc16 i) { return from_ <= i && i <= to_; } | 258 bool Contains(uc16 i) { return from_ <= i && i <= to_; } |
259 uc16 from() const { return from_; } | 259 uc16 from() const { return from_; } |
260 void set_from(uc16 value) { from_ = value; } | 260 void set_from(uc16 value) { from_ = value; } |
261 uc16 to() const { return to_; } | 261 uc16 to() const { return to_; } |
262 void set_to(uc16 value) { to_ = value; } | 262 void set_to(uc16 value) { to_ = value; } |
263 bool is_valid() { return from_ <= to_; } | 263 bool is_valid() { return from_ <= to_; } |
264 bool IsEverything(uc16 max) { return from_ == 0 && to_ >= max; } | 264 bool IsEverything(uc16 max) { return from_ == 0 && to_ >= max; } |
265 bool IsSingleton() { return (from_ == to_); } | 265 bool IsSingleton() { return (from_ == to_); } |
266 void AddCaseEquivalents(ZoneList<CharacterRange>* ranges, bool is_one_byte, | 266 void AddCaseEquivalents(Isolate* isolate, Zone* zone, |
267 Zone* zone); | 267 ZoneList<CharacterRange>* ranges, bool is_one_byte); |
268 static void Split(ZoneList<CharacterRange>* base, | 268 static void Split(ZoneList<CharacterRange>* base, |
269 Vector<const int> overlay, | 269 Vector<const int> overlay, |
270 ZoneList<CharacterRange>** included, | 270 ZoneList<CharacterRange>** included, |
271 ZoneList<CharacterRange>** excluded, | 271 ZoneList<CharacterRange>** excluded, |
272 Zone* zone); | 272 Zone* zone); |
273 // Whether a range list is in canonical form: Ranges ordered by from value, | 273 // Whether a range list is in canonical form: Ranges ordered by from value, |
274 // and ranges non-overlapping and non-adjacent. | 274 // and ranges non-overlapping and non-adjacent. |
275 static bool IsCanonical(ZoneList<CharacterRange>* ranges); | 275 static bool IsCanonical(ZoneList<CharacterRange>* ranges); |
276 // Convert range list to canonical form. The characters covered by the ranges | 276 // Convert range list to canonical form. The characters covered by the ranges |
277 // will still be the same, but no character is in more than one range, and | 277 // will still be the same, but no character is in more than one range, and |
(...skipping 562 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
840 elms_->Add(TextElement::CharClass(that), zone()); | 840 elms_->Add(TextElement::CharClass(that), zone()); |
841 } | 841 } |
842 virtual void Accept(NodeVisitor* visitor); | 842 virtual void Accept(NodeVisitor* visitor); |
843 virtual void Emit(RegExpCompiler* compiler, Trace* trace); | 843 virtual void Emit(RegExpCompiler* compiler, Trace* trace); |
844 virtual int EatsAtLeast(int still_to_find, int budget, bool not_at_start); | 844 virtual int EatsAtLeast(int still_to_find, int budget, bool not_at_start); |
845 virtual void GetQuickCheckDetails(QuickCheckDetails* details, | 845 virtual void GetQuickCheckDetails(QuickCheckDetails* details, |
846 RegExpCompiler* compiler, | 846 RegExpCompiler* compiler, |
847 int characters_filled_in, | 847 int characters_filled_in, |
848 bool not_at_start); | 848 bool not_at_start); |
849 ZoneList<TextElement>* elements() { return elms_; } | 849 ZoneList<TextElement>* elements() { return elms_; } |
850 void MakeCaseIndependent(bool is_one_byte); | 850 void MakeCaseIndependent(Isolate* isolate, bool is_one_byte); |
851 virtual int GreedyLoopTextLength(); | 851 virtual int GreedyLoopTextLength(); |
852 virtual RegExpNode* GetSuccessorOfOmnivorousTextNode( | 852 virtual RegExpNode* GetSuccessorOfOmnivorousTextNode( |
853 RegExpCompiler* compiler); | 853 RegExpCompiler* compiler); |
854 virtual void FillInBMInfo(int offset, | 854 virtual void FillInBMInfo(int offset, |
855 int budget, | 855 int budget, |
856 BoyerMooreLookahead* bm, | 856 BoyerMooreLookahead* bm, |
857 bool not_at_start); | 857 bool not_at_start); |
858 void CalculateOffsets(); | 858 void CalculateOffsets(); |
859 virtual RegExpNode* FilterOneByte(int depth, bool ignore_case); | 859 virtual RegExpNode* FilterOneByte(int depth, bool ignore_case); |
860 | 860 |
(...skipping 730 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1591 // has to check if it succeeds a word or non-word. In this case the | 1591 // has to check if it succeeds a word or non-word. In this case the |
1592 // result will be something like: | 1592 // result will be something like: |
1593 // | 1593 // |
1594 // +-------+ +------------+ | 1594 // +-------+ +------------+ |
1595 // | . | | . | | 1595 // | . | | . | |
1596 // +-------+ ---> +------------+ | 1596 // +-------+ ---> +------------+ |
1597 // | word? | | check word | | 1597 // | word? | | check word | |
1598 // +-------+ +------------+ | 1598 // +-------+ +------------+ |
1599 class Analysis: public NodeVisitor { | 1599 class Analysis: public NodeVisitor { |
1600 public: | 1600 public: |
1601 Analysis(bool ignore_case, bool is_one_byte) | 1601 Analysis(Isolate* isolate, bool ignore_case, bool is_one_byte) |
1602 : ignore_case_(ignore_case), | 1602 : isolate_(isolate), |
| 1603 ignore_case_(ignore_case), |
1603 is_one_byte_(is_one_byte), | 1604 is_one_byte_(is_one_byte), |
1604 error_message_(NULL) {} | 1605 error_message_(NULL) {} |
1605 void EnsureAnalyzed(RegExpNode* node); | 1606 void EnsureAnalyzed(RegExpNode* node); |
1606 | 1607 |
1607 #define DECLARE_VISIT(Type) \ | 1608 #define DECLARE_VISIT(Type) \ |
1608 virtual void Visit##Type(Type##Node* that); | 1609 virtual void Visit##Type(Type##Node* that); |
1609 FOR_EACH_NODE_TYPE(DECLARE_VISIT) | 1610 FOR_EACH_NODE_TYPE(DECLARE_VISIT) |
1610 #undef DECLARE_VISIT | 1611 #undef DECLARE_VISIT |
1611 virtual void VisitLoopChoice(LoopChoiceNode* that); | 1612 virtual void VisitLoopChoice(LoopChoiceNode* that); |
1612 | 1613 |
1613 bool has_failed() { return error_message_ != NULL; } | 1614 bool has_failed() { return error_message_ != NULL; } |
1614 const char* error_message() { | 1615 const char* error_message() { |
1615 DCHECK(error_message_ != NULL); | 1616 DCHECK(error_message_ != NULL); |
1616 return error_message_; | 1617 return error_message_; |
1617 } | 1618 } |
1618 void fail(const char* error_message) { | 1619 void fail(const char* error_message) { |
1619 error_message_ = error_message; | 1620 error_message_ = error_message; |
1620 } | 1621 } |
1621 | 1622 |
| 1623 Isolate* isolate() const { return isolate_; } |
| 1624 |
1622 private: | 1625 private: |
| 1626 Isolate* isolate_; |
1623 bool ignore_case_; | 1627 bool ignore_case_; |
1624 bool is_one_byte_; | 1628 bool is_one_byte_; |
1625 const char* error_message_; | 1629 const char* error_message_; |
1626 | 1630 |
1627 DISALLOW_IMPLICIT_CONSTRUCTORS(Analysis); | 1631 DISALLOW_IMPLICIT_CONSTRUCTORS(Analysis); |
1628 }; | 1632 }; |
1629 | 1633 |
1630 | 1634 |
1631 struct RegExpCompileData { | 1635 struct RegExpCompileData { |
1632 RegExpCompileData() | 1636 RegExpCompileData() |
(...skipping 12 matching lines...) Expand all Loading... |
1645 | 1649 |
1646 | 1650 |
1647 class RegExpEngine: public AllStatic { | 1651 class RegExpEngine: public AllStatic { |
1648 public: | 1652 public: |
1649 struct CompilationResult { | 1653 struct CompilationResult { |
1650 CompilationResult(Isolate* isolate, const char* error_message) | 1654 CompilationResult(Isolate* isolate, const char* error_message) |
1651 : error_message(error_message), | 1655 : error_message(error_message), |
1652 code(isolate->heap()->the_hole_value()), | 1656 code(isolate->heap()->the_hole_value()), |
1653 num_registers(0) {} | 1657 num_registers(0) {} |
1654 CompilationResult(Object* code, int registers) | 1658 CompilationResult(Object* code, int registers) |
1655 : error_message(NULL), | 1659 : error_message(NULL), code(code), num_registers(registers) {} |
1656 code(code), | |
1657 num_registers(registers) {} | |
1658 const char* error_message; | 1660 const char* error_message; |
1659 Object* code; | 1661 Object* code; |
1660 int num_registers; | 1662 int num_registers; |
1661 }; | 1663 }; |
1662 | 1664 |
1663 static CompilationResult Compile(RegExpCompileData* input, bool ignore_case, | 1665 static CompilationResult Compile(Isolate* isolate, Zone* zone, |
| 1666 RegExpCompileData* input, bool ignore_case, |
1664 bool global, bool multiline, bool sticky, | 1667 bool global, bool multiline, bool sticky, |
1665 Handle<String> pattern, | 1668 Handle<String> pattern, |
1666 Handle<String> sample_subject, | 1669 Handle<String> sample_subject, |
1667 bool is_one_byte, Zone* zone); | 1670 bool is_one_byte); |
1668 | 1671 |
1669 static bool TooMuchRegExpCode(Handle<String> pattern); | 1672 static bool TooMuchRegExpCode(Handle<String> pattern); |
1670 | 1673 |
1671 static void DotPrint(const char* label, RegExpNode* node, bool ignore_case); | 1674 static void DotPrint(const char* label, RegExpNode* node, bool ignore_case); |
1672 }; | 1675 }; |
1673 | 1676 |
1674 | 1677 |
1675 } } // namespace v8::internal | 1678 } } // namespace v8::internal |
1676 | 1679 |
1677 #endif // V8_JSREGEXP_H_ | 1680 #endif // V8_JSREGEXP_H_ |
OLD | NEW |