| 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 221 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|   232   kInsideBoth = 3 |   232   kInsideBoth = 3 | 
|   233 }; |   233 }; | 
|   234  |   234  | 
|   235  |   235  | 
|   236 // Represents code units in the range from from_ to to_, both ends are |   236 // Represents code units in the range from from_ to to_, both ends are | 
|   237 // inclusive. |   237 // inclusive. | 
|   238 class CharacterRange { |   238 class CharacterRange { | 
|   239  public: |   239  public: | 
|   240   CharacterRange() : from_(0), to_(0) { } |   240   CharacterRange() : from_(0), to_(0) { } | 
|   241   // For compatibility with the CHECK_OK macro |   241   // For compatibility with the CHECK_OK macro | 
|   242   CharacterRange(void* null) { ASSERT_EQ(NULL, null); }  //NOLINT |   242   CharacterRange(void* null) { DCHECK_EQ(NULL, null); }  //NOLINT | 
|   243   CharacterRange(uc16 from, uc16 to) : from_(from), to_(to) { } |   243   CharacterRange(uc16 from, uc16 to) : from_(from), to_(to) { } | 
|   244   static void AddClassEscape(uc16 type, ZoneList<CharacterRange>* ranges, |   244   static void AddClassEscape(uc16 type, ZoneList<CharacterRange>* ranges, | 
|   245                              Zone* zone); |   245                              Zone* zone); | 
|   246   static Vector<const int> GetWordBounds(); |   246   static Vector<const int> GetWordBounds(); | 
|   247   static inline CharacterRange Singleton(uc16 value) { |   247   static inline CharacterRange Singleton(uc16 value) { | 
|   248     return CharacterRange(value, value); |   248     return CharacterRange(value, value); | 
|   249   } |   249   } | 
|   250   static inline CharacterRange Range(uc16 from, uc16 to) { |   250   static inline CharacterRange Range(uc16 from, uc16 to) { | 
|   251     ASSERT(from <= to); |   251     DCHECK(from <= to); | 
|   252     return CharacterRange(from, to); |   252     return CharacterRange(from, to); | 
|   253   } |   253   } | 
|   254   static inline CharacterRange Everything() { |   254   static inline CharacterRange Everything() { | 
|   255     return CharacterRange(0, 0xFFFF); |   255     return CharacterRange(0, 0xFFFF); | 
|   256   } |   256   } | 
|   257   bool Contains(uc16 i) { return from_ <= i && i <= to_; } |   257   bool Contains(uc16 i) { return from_ <= i && i <= to_; } | 
|   258   uc16 from() const { return from_; } |   258   uc16 from() const { return from_; } | 
|   259   void set_from(uc16 value) { from_ = value; } |   259   void set_from(uc16 value) { from_ = value; } | 
|   260   uc16 to() const { return to_; } |   260   uc16 to() const { return to_; } | 
|   261   void set_to(uc16 value) { to_ = value; } |   261   void set_to(uc16 value) { to_ = value; } | 
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|   418  |   418  | 
|   419   int cp_offset() const { return cp_offset_; } |   419   int cp_offset() const { return cp_offset_; } | 
|   420   void set_cp_offset(int cp_offset) { cp_offset_ = cp_offset; } |   420   void set_cp_offset(int cp_offset) { cp_offset_ = cp_offset; } | 
|   421   int length() const; |   421   int length() const; | 
|   422  |   422  | 
|   423   TextType text_type() const { return text_type_; } |   423   TextType text_type() const { return text_type_; } | 
|   424  |   424  | 
|   425   RegExpTree* tree() const { return tree_; } |   425   RegExpTree* tree() const { return tree_; } | 
|   426  |   426  | 
|   427   RegExpAtom* atom() const { |   427   RegExpAtom* atom() const { | 
|   428     ASSERT(text_type() == ATOM); |   428     DCHECK(text_type() == ATOM); | 
|   429     return reinterpret_cast<RegExpAtom*>(tree()); |   429     return reinterpret_cast<RegExpAtom*>(tree()); | 
|   430   } |   430   } | 
|   431  |   431  | 
|   432   RegExpCharacterClass* char_class() const { |   432   RegExpCharacterClass* char_class() const { | 
|   433     ASSERT(text_type() == CHAR_CLASS); |   433     DCHECK(text_type() == CHAR_CLASS); | 
|   434     return reinterpret_cast<RegExpCharacterClass*>(tree()); |   434     return reinterpret_cast<RegExpCharacterClass*>(tree()); | 
|   435   } |   435   } | 
|   436  |   436  | 
|   437  private: |   437  private: | 
|   438   TextElement(TextType text_type, RegExpTree* tree) |   438   TextElement(TextType text_type, RegExpTree* tree) | 
|   439       : cp_offset_(-1), text_type_(text_type), tree_(tree) {} |   439       : cp_offset_(-1), text_type_(text_type), tree_(tree) {} | 
|   440  |   440  | 
|   441   int cp_offset_; |   441   int cp_offset_; | 
|   442   TextType text_type_; |   442   TextType text_type_; | 
|   443   RegExpTree* tree_; |   443   RegExpTree* tree_; | 
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|   534   void set_cannot_match() { cannot_match_ = true; } |   534   void set_cannot_match() { cannot_match_ = true; } | 
|   535   struct Position { |   535   struct Position { | 
|   536     Position() : mask(0), value(0), determines_perfectly(false) { } |   536     Position() : mask(0), value(0), determines_perfectly(false) { } | 
|   537     uc16 mask; |   537     uc16 mask; | 
|   538     uc16 value; |   538     uc16 value; | 
|   539     bool determines_perfectly; |   539     bool determines_perfectly; | 
|   540   }; |   540   }; | 
|   541   int characters() { return characters_; } |   541   int characters() { return characters_; } | 
|   542   void set_characters(int characters) { characters_ = characters; } |   542   void set_characters(int characters) { characters_ = characters; } | 
|   543   Position* positions(int index) { |   543   Position* positions(int index) { | 
|   544     ASSERT(index >= 0); |   544     DCHECK(index >= 0); | 
|   545     ASSERT(index < characters_); |   545     DCHECK(index < characters_); | 
|   546     return positions_ + index; |   546     return positions_ + index; | 
|   547   } |   547   } | 
|   548   uint32_t mask() { return mask_; } |   548   uint32_t mask() { return mask_; } | 
|   549   uint32_t value() { return value_; } |   549   uint32_t value() { return value_; } | 
|   550  |   550  | 
|   551  private: |   551  private: | 
|   552   // How many characters do we have quick check information from.  This is |   552   // How many characters do we have quick check information from.  This is | 
|   553   // the same for all branches of a choice node. |   553   // the same for all branches of a choice node. | 
|   554   int characters_; |   554   int characters_; | 
|   555   Position positions_[4]; |   555   Position positions_[4]; | 
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|   621                             bool not_at_start) { |   621                             bool not_at_start) { | 
|   622     UNREACHABLE(); |   622     UNREACHABLE(); | 
|   623   } |   623   } | 
|   624  |   624  | 
|   625   // If we know that the input is ASCII then there are some nodes that can |   625   // If we know that the input is ASCII then there are some nodes that can | 
|   626   // never match.  This method returns a node that can be substituted for |   626   // never match.  This method returns a node that can be substituted for | 
|   627   // itself, or NULL if the node can never match. |   627   // itself, or NULL if the node can never match. | 
|   628   virtual RegExpNode* FilterASCII(int depth, bool ignore_case) { return this; } |   628   virtual RegExpNode* FilterASCII(int depth, bool ignore_case) { return this; } | 
|   629   // Helper for FilterASCII. |   629   // Helper for FilterASCII. | 
|   630   RegExpNode* replacement() { |   630   RegExpNode* replacement() { | 
|   631     ASSERT(info()->replacement_calculated); |   631     DCHECK(info()->replacement_calculated); | 
|   632     return replacement_; |   632     return replacement_; | 
|   633   } |   633   } | 
|   634   RegExpNode* set_replacement(RegExpNode* replacement) { |   634   RegExpNode* set_replacement(RegExpNode* replacement) { | 
|   635     info()->replacement_calculated = true; |   635     info()->replacement_calculated = true; | 
|   636     replacement_ =  replacement; |   636     replacement_ =  replacement; | 
|   637     return replacement;  // For convenience. |   637     return replacement;  // For convenience. | 
|   638   } |   638   } | 
|   639  |   639  | 
|   640   // We want to avoid recalculating the lookahead info, so we store it on the |   640   // We want to avoid recalculating the lookahead info, so we store it on the | 
|   641   // node.  Only info that is for this node is stored.  We can tell that the |   641   // node.  Only info that is for this node is stored.  We can tell that the | 
| (...skipping 796 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  1438   int flush_budget() { return flush_budget_; } |  1438   int flush_budget() { return flush_budget_; } | 
|  1439   QuickCheckDetails* quick_check_performed() { return &quick_check_performed_; } |  1439   QuickCheckDetails* quick_check_performed() { return &quick_check_performed_; } | 
|  1440   bool mentions_reg(int reg); |  1440   bool mentions_reg(int reg); | 
|  1441   // Returns true if a deferred position store exists to the specified |  1441   // Returns true if a deferred position store exists to the specified | 
|  1442   // register and stores the offset in the out-parameter.  Otherwise |  1442   // register and stores the offset in the out-parameter.  Otherwise | 
|  1443   // returns false. |  1443   // returns false. | 
|  1444   bool GetStoredPosition(int reg, int* cp_offset); |  1444   bool GetStoredPosition(int reg, int* cp_offset); | 
|  1445   // These set methods and AdvanceCurrentPositionInTrace should be used only on |  1445   // These set methods and AdvanceCurrentPositionInTrace should be used only on | 
|  1446   // new traces - the intention is that traces are immutable after creation. |  1446   // new traces - the intention is that traces are immutable after creation. | 
|  1447   void add_action(DeferredAction* new_action) { |  1447   void add_action(DeferredAction* new_action) { | 
|  1448     ASSERT(new_action->next_ == NULL); |  1448     DCHECK(new_action->next_ == NULL); | 
|  1449     new_action->next_ = actions_; |  1449     new_action->next_ = actions_; | 
|  1450     actions_ = new_action; |  1450     actions_ = new_action; | 
|  1451   } |  1451   } | 
|  1452   void set_backtrack(Label* backtrack) { backtrack_ = backtrack; } |  1452   void set_backtrack(Label* backtrack) { backtrack_ = backtrack; } | 
|  1453   void set_stop_node(RegExpNode* node) { stop_node_ = node; } |  1453   void set_stop_node(RegExpNode* node) { stop_node_ = node; } | 
|  1454   void set_loop_label(Label* label) { loop_label_ = label; } |  1454   void set_loop_label(Label* label) { loop_label_ = label; } | 
|  1455   void set_characters_preloaded(int count) { characters_preloaded_ = count; } |  1455   void set_characters_preloaded(int count) { characters_preloaded_ = count; } | 
|  1456   void set_bound_checked_up_to(int to) { bound_checked_up_to_ = to; } |  1456   void set_bound_checked_up_to(int to) { bound_checked_up_to_ = to; } | 
|  1457   void set_flush_budget(int to) { flush_budget_ = to; } |  1457   void set_flush_budget(int to) { flush_budget_ = to; } | 
|  1458   void set_quick_check_performed(QuickCheckDetails* d) { |  1458   void set_quick_check_performed(QuickCheckDetails* d) { | 
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  1553   void EnsureAnalyzed(RegExpNode* node); |  1553   void EnsureAnalyzed(RegExpNode* node); | 
|  1554  |  1554  | 
|  1555 #define DECLARE_VISIT(Type)                                          \ |  1555 #define DECLARE_VISIT(Type)                                          \ | 
|  1556   virtual void Visit##Type(Type##Node* that); |  1556   virtual void Visit##Type(Type##Node* that); | 
|  1557 FOR_EACH_NODE_TYPE(DECLARE_VISIT) |  1557 FOR_EACH_NODE_TYPE(DECLARE_VISIT) | 
|  1558 #undef DECLARE_VISIT |  1558 #undef DECLARE_VISIT | 
|  1559   virtual void VisitLoopChoice(LoopChoiceNode* that); |  1559   virtual void VisitLoopChoice(LoopChoiceNode* that); | 
|  1560  |  1560  | 
|  1561   bool has_failed() { return error_message_ != NULL; } |  1561   bool has_failed() { return error_message_ != NULL; } | 
|  1562   const char* error_message() { |  1562   const char* error_message() { | 
|  1563     ASSERT(error_message_ != NULL); |  1563     DCHECK(error_message_ != NULL); | 
|  1564     return error_message_; |  1564     return error_message_; | 
|  1565   } |  1565   } | 
|  1566   void fail(const char* error_message) { |  1566   void fail(const char* error_message) { | 
|  1567     error_message_ = error_message; |  1567     error_message_ = error_message; | 
|  1568   } |  1568   } | 
|  1569  |  1569  | 
|  1570  private: |  1570  private: | 
|  1571   bool ignore_case_; |  1571   bool ignore_case_; | 
|  1572   bool is_ascii_; |  1572   bool is_ascii_; | 
|  1573   const char* error_message_; |  1573   const char* error_message_; | 
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  1616                                    Handle<String> sample_subject, |  1616                                    Handle<String> sample_subject, | 
|  1617                                    bool is_ascii, Zone* zone); |  1617                                    bool is_ascii, Zone* zone); | 
|  1618  |  1618  | 
|  1619   static void DotPrint(const char* label, RegExpNode* node, bool ignore_case); |  1619   static void DotPrint(const char* label, RegExpNode* node, bool ignore_case); | 
|  1620 }; |  1620 }; | 
|  1621  |  1621  | 
|  1622  |  1622  | 
|  1623 } }  // namespace v8::internal |  1623 } }  // namespace v8::internal | 
|  1624  |  1624  | 
|  1625 #endif  // V8_JSREGEXP_H_ |  1625 #endif  // V8_JSREGEXP_H_ | 
| OLD | NEW |