Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1094)

Side by Side Diff: runtime/vm/regexp.h

Issue 683433003: Integrate the Irregexp Regular Expression Engine. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: more comments Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « runtime/vm/raw_object_snapshot.cc ('k') | runtime/vm/regexp.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #ifndef VM_REGEXP_H_ 5 #ifndef VM_REGEXP_H_
6 #define VM_REGEXP_H_ 6 #define VM_REGEXP_H_
7 7
8 // SNIP 8 #include "vm/assembler.h"
9 #include "vm/intermediate_language.h"
10 #include "vm/object.h"
11 #include "vm/regexp_assembler.h"
9 12
10 namespace dart { 13 namespace dart {
11 14
12 class NodeVisitor; 15 class NodeVisitor;
13 class RegExpCompiler; 16 class RegExpCompiler;
14 class RegExpMacroAssembler; 17 class RegExpMacroAssembler;
15 class RegExpNode; 18 class RegExpNode;
16 class RegExpTree; 19 class RegExpTree;
17 class BoyerMooreLookahead; 20 class BoyerMooreLookahead;
18 21
19 // Represents the location of one element relative to the intersection of
20 // two sets. Corresponds to the four areas of a Venn diagram.
21 enum ElementInSetsRelation {
22 kInsideNone = 0,
23 kInsideFirst = 1,
24 kInsideSecond = 2,
25 kInsideBoth = 3
26 };
27
28 22
29 // Represents code units in the range from from_ to to_, both ends are 23 // Represents code units in the range from from_ to to_, both ends are
30 // inclusive. 24 // inclusive.
31 class CharacterRange { 25 class CharacterRange {
32 public: 26 public:
33 CharacterRange() : from_(0), to_(0) { } 27 CharacterRange() : from_(0), to_(0) { }
34 // For compatibility with the CHECK_OK macro 28 CharacterRange(uint16_t from, uint16_t to) : from_(from), to_(to) { }
35 CharacterRange(void* null) { DCHECK_EQ(NULL, null); } //NOLINT 29
36 CharacterRange(uc16 from, uc16 to) : from_(from), to_(to) { } 30 static void AddClassEscape(uint16_t type,
37 static void AddClassEscape(uc16 type, ZoneList<CharacterRange>* ranges, 31 ZoneGrowableArray<CharacterRange>* ranges);
38 Zone* zone); 32 static GrowableArray<const intptr_t> GetWordBounds();
39 static Vector<const int> GetWordBounds(); 33 static inline CharacterRange Singleton(uint16_t value) {
40 static inline CharacterRange Singleton(uc16 value) {
41 return CharacterRange(value, value); 34 return CharacterRange(value, value);
42 } 35 }
43 static inline CharacterRange Range(uc16 from, uc16 to) { 36 static inline CharacterRange Range(uint16_t from, uint16_t to) {
44 DCHECK(from <= to); 37 ASSERT(from <= to);
45 return CharacterRange(from, to); 38 return CharacterRange(from, to);
46 } 39 }
47 static inline CharacterRange Everything() { 40 static inline CharacterRange Everything() {
48 return CharacterRange(0, 0xFFFF); 41 return CharacterRange(0, 0xFFFF);
49 } 42 }
50 bool Contains(uc16 i) { return from_ <= i && i <= to_; } 43 bool Contains(uint16_t i) const { return from_ <= i && i <= to_; }
51 uc16 from() const { return from_; } 44 uint16_t from() const { return from_; }
52 void set_from(uc16 value) { from_ = value; } 45 void set_from(uint16_t value) { from_ = value; }
53 uc16 to() const { return to_; } 46 uint16_t to() const { return to_; }
54 void set_to(uc16 value) { to_ = value; } 47 void set_to(uint16_t value) { to_ = value; }
55 bool is_valid() { return from_ <= to_; } 48 bool is_valid() const { return from_ <= to_; }
56 bool IsEverything(uc16 max) { return from_ == 0 && to_ >= max; } 49 bool IsEverything(uint16_t max) const { return from_ == 0 && to_ >= max; }
57 bool IsSingleton() { return (from_ == to_); } 50 bool IsSingleton() const { return (from_ == to_); }
58 void AddCaseEquivalents(ZoneList<CharacterRange>* ranges, bool is_one_byte, 51 void AddCaseEquivalents(ZoneGrowableArray<CharacterRange>* ranges,
59 Zone* zone); 52 bool is_one_byte,
60 static void Split(ZoneList<CharacterRange>* base, 53 Isolate* isolate);
61 Vector<const int> overlay, 54 static void Split(ZoneGrowableArray<CharacterRange>* base,
62 ZoneList<CharacterRange>** included, 55 GrowableArray<const intptr_t> overlay,
63 ZoneList<CharacterRange>** excluded, 56 ZoneGrowableArray<CharacterRange>** included,
64 Zone* zone); 57 ZoneGrowableArray<CharacterRange>** excluded,
58 Isolate* isolate);
65 // Whether a range list is in canonical form: Ranges ordered by from value, 59 // Whether a range list is in canonical form: Ranges ordered by from value,
66 // and ranges non-overlapping and non-adjacent. 60 // and ranges non-overlapping and non-adjacent.
67 static bool IsCanonical(ZoneList<CharacterRange>* ranges); 61 static bool IsCanonical(ZoneGrowableArray<CharacterRange>* ranges);
68 // Convert range list to canonical form. The characters covered by the ranges 62 // Convert range list to canonical form. The characters covered by the ranges
69 // will still be the same, but no character is in more than one range, and 63 // will still be the same, but no character is in more than one range, and
70 // adjacent ranges are merged. The resulting list may be shorter than the 64 // adjacent ranges are merged. The resulting list may be shorter than the
71 // original, but cannot be longer. 65 // original, but cannot be longer.
72 static void Canonicalize(ZoneList<CharacterRange>* ranges); 66 static void Canonicalize(ZoneGrowableArray<CharacterRange>* ranges);
73 // Negate the contents of a character range in canonical form. 67 // Negate the contents of a character range in canonical form.
74 static void Negate(ZoneList<CharacterRange>* src, 68 static void Negate(ZoneGrowableArray<CharacterRange>* src,
75 ZoneList<CharacterRange>* dst, 69 ZoneGrowableArray<CharacterRange>* dst);
76 Zone* zone); 70 static const intptr_t kStartMarker = (1 << 24);
77 static const int kStartMarker = (1 << 24); 71 static const intptr_t kPayloadMask = (1 << 24) - 1;
78 static const int kPayloadMask = (1 << 24) - 1;
79 72
80 private: 73 private:
81 uc16 from_; 74 uint16_t from_;
82 uc16 to_; 75 uint16_t to_;
76
77 DISALLOW_ALLOCATION();
83 }; 78 };
84 79
85 80
86 // A set of unsigned integers that behaves especially well on small 81 // A set of unsigned integers that behaves especially well on small
87 // integers (< 32). May do zone-allocation. 82 // integers (< 32). May do zone-allocation.
88 class OutSet: public ZoneObject { 83 class OutSet: public ZoneAllocated {
89 public: 84 public:
90 OutSet() : first_(0), remaining_(NULL), successors_(NULL) { } 85 OutSet() : first_(0), remaining_(NULL), successors_(NULL) { }
91 OutSet* Extend(unsigned value, Zone* zone); 86 OutSet* Extend(unsigned value, Isolate* isolate);
92 bool Get(unsigned value) const; 87 bool Get(unsigned value) const;
93 static const unsigned kFirstLimit = 32; 88 static const unsigned kFirstLimit = 32;
94 89
95 private: 90 private:
96 // Destructively set a value in this set. In most cases you want 91 // Destructively set a value in this set. In most cases you want
97 // to use Extend instead to ensure that only one instance exists 92 // to use Extend instead to ensure that only one instance exists
98 // that contains the same values. 93 // that contains the same values.
99 void Set(unsigned value, Zone* zone); 94 void Set(unsigned value, Isolate* isolate);
100 95
101 // The successors are a list of sets that contain the same values 96 // The successors are a list of sets that contain the same values
102 // as this set and the one more value that is not present in this 97 // as this set and the one more value that is not present in this
103 // set. 98 // set.
104 ZoneList<OutSet*>* successors(Zone* zone) { return successors_; } 99 ZoneGrowableArray<OutSet*>* successors() { return successors_; }
105 100
106 OutSet(uint32_t first, ZoneList<unsigned>* remaining) 101 OutSet(uint32_t first, ZoneGrowableArray<unsigned>* remaining)
107 : first_(first), remaining_(remaining), successors_(NULL) { } 102 : first_(first), remaining_(remaining), successors_(NULL) { }
108 uint32_t first_; 103 uint32_t first_;
109 ZoneList<unsigned>* remaining_; 104 ZoneGrowableArray<unsigned>* remaining_;
110 ZoneList<OutSet*>* successors_; 105 ZoneGrowableArray<OutSet*>* successors_;
111 friend class Trace; 106 friend class Trace;
112 }; 107 };
113 108
114 109
115 // A mapping from integers, specified as ranges, to a set of integers.
116 // Used for mapping character ranges to choices.
117 class DispatchTable : public ZoneObject {
118 public:
119 explicit DispatchTable(Zone* zone) : tree_(zone) { }
120
121 class Entry {
122 public:
123 Entry() : from_(0), to_(0), out_set_(NULL) { }
124 Entry(uc16 from, uc16 to, OutSet* out_set)
125 : from_(from), to_(to), out_set_(out_set) { }
126 uc16 from() { return from_; }
127 uc16 to() { return to_; }
128 void set_to(uc16 value) { to_ = value; }
129 void AddValue(int value, Zone* zone) {
130 out_set_ = out_set_->Extend(value, zone);
131 }
132 OutSet* out_set() { return out_set_; }
133 private:
134 uc16 from_;
135 uc16 to_;
136 OutSet* out_set_;
137 };
138
139 class Config {
140 public:
141 typedef uc16 Key;
142 typedef Entry Value;
143 static const uc16 kNoKey;
144 static const Entry NoValue() { return Value(); }
145 static inline int Compare(uc16 a, uc16 b) {
146 if (a == b)
147 return 0;
148 else if (a < b)
149 return -1;
150 else
151 return 1;
152 }
153 };
154
155 void AddRange(CharacterRange range, int value, Zone* zone);
156 OutSet* Get(uc16 value);
157 void Dump();
158
159 template <typename Callback>
160 void ForEach(Callback* callback) {
161 return tree()->ForEach(callback);
162 }
163
164 private:
165 // There can't be a static empty set since it allocates its
166 // successors in a zone and caches them.
167 OutSet* empty() { return &empty_; }
168 OutSet empty_;
169 ZoneSplayTree<Config>* tree() { return &tree_; }
170 ZoneSplayTree<Config> tree_;
171 };
172
173
174 #define FOR_EACH_NODE_TYPE(VISIT) \ 110 #define FOR_EACH_NODE_TYPE(VISIT) \
175 VISIT(End) \ 111 VISIT(End) \
176 VISIT(Action) \ 112 VISIT(Action) \
177 VISIT(Choice) \ 113 VISIT(Choice) \
178 VISIT(BackReference) \ 114 VISIT(BackReference) \
179 VISIT(Assertion) \ 115 VISIT(Assertion) \
180 VISIT(Text) 116 VISIT(Text)
181 117
182 118
183 #define FOR_EACH_REG_EXP_TREE_TYPE(VISIT) \ 119 #define FOR_EACH_REG_EXP_TREE_TYPE(VISIT) \
184 VISIT(Disjunction) \ 120 VISIT(Disjunction) \
185 VISIT(Alternative) \ 121 VISIT(Alternative) \
186 VISIT(Assertion) \ 122 VISIT(Assertion) \
187 VISIT(CharacterClass) \ 123 VISIT(CharacterClass) \
188 VISIT(Atom) \ 124 VISIT(Atom) \
189 VISIT(Quantifier) \ 125 VISIT(Quantifier) \
190 VISIT(Capture) \ 126 VISIT(Capture) \
191 VISIT(Lookahead) \ 127 VISIT(Lookahead) \
192 VISIT(BackReference) \ 128 VISIT(BackReference) \
193 VISIT(Empty) \ 129 VISIT(Empty) \
194 VISIT(Text) 130 VISIT(Text)
195 131
196 132
197 #define FORWARD_DECLARE(Name) class RegExp##Name; 133 #define FORWARD_DECLARE(Name) class RegExp##Name;
198 FOR_EACH_REG_EXP_TREE_TYPE(FORWARD_DECLARE) 134 FOR_EACH_REG_EXP_TREE_TYPE(FORWARD_DECLARE)
199 #undef FORWARD_DECLARE 135 #undef FORWARD_DECLARE
200 136
201 137
202 class TextElement FINAL BASE_EMBEDDED { 138 class TextElement {
203 public: 139 public:
204 enum TextType { 140 enum TextType {
205 ATOM, 141 ATOM,
206 CHAR_CLASS 142 CHAR_CLASS
207 }; 143 };
208 144
209 static TextElement Atom(RegExpAtom* atom); 145 static TextElement Atom(RegExpAtom* atom);
210 static TextElement CharClass(RegExpCharacterClass* char_class); 146 static TextElement CharClass(RegExpCharacterClass* char_class);
211 147
212 int cp_offset() const { return cp_offset_; } 148 intptr_t cp_offset() const { return cp_offset_; }
213 void set_cp_offset(int cp_offset) { cp_offset_ = cp_offset; } 149 void set_cp_offset(intptr_t cp_offset) { cp_offset_ = cp_offset; }
214 int length() const; 150 intptr_t length() const;
215 151
216 TextType text_type() const { return text_type_; } 152 TextType text_type() const { return text_type_; }
217 153
218 RegExpTree* tree() const { return tree_; } 154 RegExpTree* tree() const { return tree_; }
219 155
220 RegExpAtom* atom() const { 156 RegExpAtom* atom() const {
221 DCHECK(text_type() == ATOM); 157 ASSERT(text_type() == ATOM);
222 return reinterpret_cast<RegExpAtom*>(tree()); 158 return reinterpret_cast<RegExpAtom*>(tree());
223 } 159 }
224 160
225 RegExpCharacterClass* char_class() const { 161 RegExpCharacterClass* char_class() const {
226 DCHECK(text_type() == CHAR_CLASS); 162 ASSERT(text_type() == CHAR_CLASS);
227 return reinterpret_cast<RegExpCharacterClass*>(tree()); 163 return reinterpret_cast<RegExpCharacterClass*>(tree());
228 } 164 }
229 165
230 private: 166 private:
231 TextElement(TextType text_type, RegExpTree* tree) 167 TextElement(TextType text_type, RegExpTree* tree)
232 : cp_offset_(-1), text_type_(text_type), tree_(tree) {} 168 : cp_offset_(-1), text_type_(text_type), tree_(tree) {}
233 169
234 int cp_offset_; 170 intptr_t cp_offset_;
235 TextType text_type_; 171 TextType text_type_;
236 RegExpTree* tree_; 172 RegExpTree* tree_;
173
174 DISALLOW_ALLOCATION();
237 }; 175 };
238 176
239 177
240 class Trace; 178 class Trace;
241 struct PreloadState; 179 struct PreloadState;
242 class GreedyLoopState; 180 class GreedyLoopState;
243 class AlternativeGenerationList; 181 class AlternativeGenerationList;
244 182
245 struct NodeInfo { 183 struct NodeInfo {
246 NodeInfo() 184 NodeInfo()
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
307 245
308 // Details of a quick mask-compare check that can look ahead in the 246 // Details of a quick mask-compare check that can look ahead in the
309 // input stream. 247 // input stream.
310 class QuickCheckDetails { 248 class QuickCheckDetails {
311 public: 249 public:
312 QuickCheckDetails() 250 QuickCheckDetails()
313 : characters_(0), 251 : characters_(0),
314 mask_(0), 252 mask_(0),
315 value_(0), 253 value_(0),
316 cannot_match_(false) { } 254 cannot_match_(false) { }
317 explicit QuickCheckDetails(int characters) 255 explicit QuickCheckDetails(intptr_t characters)
318 : characters_(characters), 256 : characters_(characters),
319 mask_(0), 257 mask_(0),
320 value_(0), 258 value_(0),
321 cannot_match_(false) { } 259 cannot_match_(false) { }
322 bool Rationalize(bool one_byte); 260 bool Rationalize(bool one_byte);
323 // Merge in the information from another branch of an alternation. 261 // Merge in the information from another branch of an alternation.
324 void Merge(QuickCheckDetails* other, int from_index); 262 void Merge(QuickCheckDetails* other, intptr_t from_index);
325 // Advance the current position by some amount. 263 // Advance the current position by some amount.
326 void Advance(int by, bool one_byte); 264 void Advance(intptr_t by, bool one_byte);
327 void Clear(); 265 void Clear();
328 bool cannot_match() { return cannot_match_; } 266 bool cannot_match() { return cannot_match_; }
329 void set_cannot_match() { cannot_match_ = true; } 267 void set_cannot_match() { cannot_match_ = true; }
330 struct Position { 268 struct Position {
331 Position() : mask(0), value(0), determines_perfectly(false) { } 269 Position() : mask(0), value(0), determines_perfectly(false) { }
332 uc16 mask; 270 uint16_t mask;
333 uc16 value; 271 uint16_t value;
334 bool determines_perfectly; 272 bool determines_perfectly;
335 }; 273 };
336 int characters() { return characters_; } 274 intptr_t characters() { return characters_; }
337 void set_characters(int characters) { characters_ = characters; } 275 void set_characters(intptr_t characters) { characters_ = characters; }
338 Position* positions(int index) { 276 Position* positions(intptr_t index) {
339 DCHECK(index >= 0); 277 ASSERT(index >= 0);
340 DCHECK(index < characters_); 278 ASSERT(index < characters_);
341 return positions_ + index; 279 return positions_ + index;
342 } 280 }
343 uint32_t mask() { return mask_; } 281 uint32_t mask() { return mask_; }
344 uint32_t value() { return value_; } 282 uint32_t value() { return value_; }
345 283
346 private: 284 private:
347 // How many characters do we have quick check information from. This is 285 // How many characters do we have quick check information from. This is
348 // the same for all branches of a choice node. 286 // the same for all branches of a choice node.
349 int characters_; 287 intptr_t characters_;
350 Position positions_[4]; 288 Position positions_[4];
351 // These values are the condensate of the above array after Rationalize(). 289 // These values are the condensate of the above array after Rationalize().
352 uint32_t mask_; 290 uint32_t mask_;
353 uint32_t value_; 291 uint32_t value_;
354 // If set to true, there is no way this quick check can match at all. 292 // If set to true, there is no way this quick check can match at all.
355 // E.g., if it requires to be at the start of the input, and isn't. 293 // E.g., if it requires to be at the start of the input, and isn't.
356 bool cannot_match_; 294 bool cannot_match_;
295
296 DISALLOW_ALLOCATION();
357 }; 297 };
358 298
359 299
360 extern int kUninitializedRegExpNodePlaceHolder; 300 class RegExpNode: public ZoneAllocated {
361
362
363 class RegExpNode: public ZoneObject {
364 public: 301 public:
365 explicit RegExpNode(Zone* zone) 302 explicit RegExpNode(Isolate* isolate)
366 : replacement_(NULL), trace_count_(0), zone_(zone) { 303 : replacement_(NULL), trace_count_(0), isolate_(isolate) {
367 bm_info_[0] = bm_info_[1] = NULL; 304 bm_info_[0] = bm_info_[1] = NULL;
368 } 305 }
369 virtual ~RegExpNode(); 306 virtual ~RegExpNode();
370 virtual void Accept(NodeVisitor* visitor) = 0; 307 virtual void Accept(NodeVisitor* visitor) = 0;
371 // Generates a goto to this node or actually generates the code at this point. 308 // Generates a goto to this node or actually generates the code at this point.
372 virtual void Emit(RegExpCompiler* compiler, Trace* trace) = 0; 309 virtual void Emit(RegExpCompiler* compiler, Trace* trace) = 0;
373 // How many characters must this node consume at a minimum in order to 310 // How many characters must this node consume at a minimum in order to
374 // succeed. If we have found at least 'still_to_find' characters that 311 // succeed. If we have found at least 'still_to_find' characters that
375 // must be consumed there is no need to ask any following nodes whether 312 // must be consumed there is no need to ask any following nodes whether
376 // they are sure to eat any more characters. The not_at_start argument is 313 // they are sure to eat any more characters. The not_at_start argument is
377 // used to indicate that we know we are not at the start of the input. In 314 // used to indicate that we know we are not at the start of the input. In
378 // this case anchored branches will always fail and can be ignored when 315 // this case anchored branches will always fail and can be ignored when
379 // determining how many characters are consumed on success. 316 // determining how many characters are consumed on success.
380 virtual int EatsAtLeast(int still_to_find, int budget, bool not_at_start) = 0; 317 virtual intptr_t EatsAtLeast(intptr_t still_to_find, intptr_t budget,
318 bool not_at_start) = 0;
381 // Emits some quick code that checks whether the preloaded characters match. 319 // Emits some quick code that checks whether the preloaded characters match.
382 // Falls through on certain failure, jumps to the label on possible success. 320 // Falls through on certain failure, jumps to the label on possible success.
383 // If the node cannot make a quick check it does nothing and returns false. 321 // If the node cannot make a quick check it does nothing and returns false.
384 bool EmitQuickCheck(RegExpCompiler* compiler, 322 bool EmitQuickCheck(RegExpCompiler* compiler,
385 Trace* bounds_check_trace, 323 Trace* bounds_check_trace,
386 Trace* trace, 324 Trace* trace,
387 bool preload_has_checked_bounds, 325 bool preload_has_checked_bounds,
388 Label* on_possible_success, 326 BlockLabel* on_possible_success,
389 QuickCheckDetails* details_return, 327 QuickCheckDetails* details_return,
390 bool fall_through_on_failure); 328 bool fall_through_on_failure);
391 // For a given number of characters this returns a mask and a value. The 329 // For a given number of characters this returns a mask and a value. The
392 // next n characters are anded with the mask and compared with the value. 330 // next n characters are anded with the mask and compared with the value.
393 // A comparison failure indicates the node cannot match the next n characters. 331 // A comparison failure indicates the node cannot match the next n characters.
394 // A comparison success indicates the node may match. 332 // A comparison success indicates the node may match.
395 virtual void GetQuickCheckDetails(QuickCheckDetails* details, 333 virtual void GetQuickCheckDetails(QuickCheckDetails* details,
396 RegExpCompiler* compiler, 334 RegExpCompiler* compiler,
397 int characters_filled_in, 335 intptr_t characters_filled_in,
398 bool not_at_start) = 0; 336 bool not_at_start) = 0;
399 static const int kNodeIsTooComplexForGreedyLoops = -1; 337 static const intptr_t kNodeIsTooComplexForGreedyLoops = -1;
400 virtual int GreedyLoopTextLength() { return kNodeIsTooComplexForGreedyLoops; } 338 virtual intptr_t GreedyLoopTextLength() {
339 return kNodeIsTooComplexForGreedyLoops;
340 }
401 // Only returns the successor for a text node of length 1 that matches any 341 // Only returns the successor for a text node of length 1 that matches any
402 // character and that has no guards on it. 342 // character and that has no guards on it.
403 virtual RegExpNode* GetSuccessorOfOmnivorousTextNode( 343 virtual RegExpNode* GetSuccessorOfOmnivorousTextNode(
404 RegExpCompiler* compiler) { 344 RegExpCompiler* compiler) {
405 return NULL; 345 return NULL;
406 } 346 }
407 347
408 // Collects information on the possible code units (mod 128) that can match if 348 // Collects information on the possible code units (mod 128) that can match if
409 // we look forward. This is used for a Boyer-Moore-like string searching 349 // we look forward. This is used for a Boyer-Moore-like string searching
410 // implementation. TODO(erikcorry): This should share more code with 350 // implementation. TODO(erikcorry): This should share more code with
411 // EatsAtLeast, GetQuickCheckDetails. The budget argument is used to limit 351 // EatsAtLeast, GetQuickCheckDetails. The budget argument is used to limit
412 // the number of nodes we are willing to look at in order to create this data. 352 // the number of nodes we are willing to look at in order to create this data.
413 static const int kRecursionBudget = 200; 353 static const intptr_t kRecursionBudget = 200;
414 virtual void FillInBMInfo(int offset, 354 virtual void FillInBMInfo(intptr_t offset,
415 int budget, 355 intptr_t budget,
416 BoyerMooreLookahead* bm, 356 BoyerMooreLookahead* bm,
417 bool not_at_start) { 357 bool not_at_start) {
418 UNREACHABLE(); 358 UNREACHABLE();
419 } 359 }
420 360
421 // If we know that the input is one-byte then there are some nodes that can 361 // If we know that the input is one-byte then there are some nodes that can
422 // never match. This method returns a node that can be substituted for 362 // never match. This method returns a node that can be substituted for
423 // itself, or NULL if the node can never match. 363 // itself, or NULL if the node can never match.
424 virtual RegExpNode* FilterOneByte(int depth, bool ignore_case) { 364 virtual RegExpNode* FilterOneByte(intptr_t depth, bool ignore_case) {
425 return this; 365 return this;
426 } 366 }
427 // Helper for FilterOneByte. 367 // Helper for FilterOneByte.
428 RegExpNode* replacement() { 368 RegExpNode* replacement() {
429 DCHECK(info()->replacement_calculated); 369 ASSERT(info()->replacement_calculated);
430 return replacement_; 370 return replacement_;
431 } 371 }
432 RegExpNode* set_replacement(RegExpNode* replacement) { 372 RegExpNode* set_replacement(RegExpNode* replacement) {
433 info()->replacement_calculated = true; 373 info()->replacement_calculated = true;
434 replacement_ = replacement; 374 replacement_ = replacement;
435 return replacement; // For convenience. 375 return replacement; // For convenience.
436 } 376 }
437 377
438 // We want to avoid recalculating the lookahead info, so we store it on the 378 // We want to avoid recalculating the lookahead info, so we store it on the
439 // node. Only info that is for this node is stored. We can tell that the 379 // node. Only info that is for this node is stored. We can tell that the
440 // info is for this node when offset == 0, so the information is calculated 380 // info is for this node when offset == 0, so the information is calculated
441 // relative to this node. 381 // relative to this node.
442 void SaveBMInfo(BoyerMooreLookahead* bm, bool not_at_start, int offset) { 382 void SaveBMInfo(BoyerMooreLookahead* bm, bool not_at_start, intptr_t offset) {
443 if (offset == 0) set_bm_info(not_at_start, bm); 383 if (offset == 0) set_bm_info(not_at_start, bm);
444 } 384 }
445 385
446 Label* label() { return &label_; } 386 BlockLabel* label() { return &label_; }
447 // If non-generic code is generated for a node (i.e. the node is not at the 387 // If non-generic code is generated for a node (i.e. the node is not at the
448 // start of the trace) then it cannot be reused. This variable sets a limit 388 // start of the trace) then it cannot be reused. This variable sets a limit
449 // on how often we allow that to happen before we insist on starting a new 389 // on how often we allow that to happen before we insist on starting a new
450 // trace and generating generic code for a node that can be reused by flushing 390 // trace and generating generic code for a node that can be reused by flushing
451 // the deferred actions in the current trace and generating a goto. 391 // the deferred actions in the current trace and generating a goto.
452 static const int kMaxCopiesCodeGenerated = 10; 392 static const intptr_t kMaxCopiesCodeGenerated = 10;
453 393
454 NodeInfo* info() { return &info_; } 394 NodeInfo* info() { return &info_; }
455 395
456 BoyerMooreLookahead* bm_info(bool not_at_start) { 396 BoyerMooreLookahead* bm_info(bool not_at_start) {
457 return bm_info_[not_at_start ? 1 : 0]; 397 return bm_info_[not_at_start ? 1 : 0];
458 } 398 }
459 399
460 Zone* zone() const { return zone_; } 400 Isolate* isolate() const { return isolate_; }
461 401
462 protected: 402 protected:
463 enum LimitResult { DONE, CONTINUE }; 403 enum LimitResult { DONE, CONTINUE };
464 RegExpNode* replacement_; 404 RegExpNode* replacement_;
465 405
466 LimitResult LimitVersions(RegExpCompiler* compiler, Trace* trace); 406 LimitResult LimitVersions(RegExpCompiler* compiler, Trace* trace);
467 407
468 void set_bm_info(bool not_at_start, BoyerMooreLookahead* bm) { 408 void set_bm_info(bool not_at_start, BoyerMooreLookahead* bm) {
469 bm_info_[not_at_start ? 1 : 0] = bm; 409 bm_info_[not_at_start ? 1 : 0] = bm;
470 } 410 }
471 411
472 private: 412 private:
473 static const int kFirstCharBudget = 10; 413 static const intptr_t kFirstCharBudget = 10;
474 Label label_; 414 BlockLabel label_;
475 NodeInfo info_; 415 NodeInfo info_;
476 // This variable keeps track of how many times code has been generated for 416 // This variable keeps track of how many times code has been generated for
477 // this node (in different traces). We don't keep track of where the 417 // this node (in different traces). We don't keep track of where the
478 // generated code is located unless the code is generated at the start of 418 // generated code is located unless the code is generated at the start of
479 // a trace, in which case it is generic and can be reused by flushing the 419 // a trace, in which case it is generic and can be reused by flushing the
480 // deferred operations in the current trace and generating a goto. 420 // deferred operations in the current trace and generating a goto.
481 int trace_count_; 421 intptr_t trace_count_;
482 BoyerMooreLookahead* bm_info_[2]; 422 BoyerMooreLookahead* bm_info_[2];
483 423 Isolate* isolate_;
484 Zone* zone_;
485 }; 424 };
486 425
487 426
488 // A simple closed interval. 427 // A simple closed interval.
489 class Interval { 428 class Interval {
490 public: 429 public:
491 Interval() : from_(kNone), to_(kNone) { } 430 Interval() : from_(kNone), to_(kNone) { }
492 Interval(int from, int to) : from_(from), to_(to) { } 431 Interval(intptr_t from, intptr_t to) : from_(from), to_(to) { }
432
493 Interval Union(Interval that) { 433 Interval Union(Interval that) {
494 if (that.from_ == kNone) 434 if (that.from_ == kNone)
495 return *this; 435 return *this;
496 else if (from_ == kNone) 436 else if (from_ == kNone)
497 return that; 437 return that;
498 else 438 else
499 return Interval(Min(from_, that.from_), Max(to_, that.to_)); 439 return Interval(Utils::Minimum(from_, that.from_),
440 Utils::Maximum(to_, that.to_));
500 } 441 }
501 bool Contains(int value) { 442 bool Contains(intptr_t value) const {
502 return (from_ <= value) && (value <= to_); 443 return (from_ <= value) && (value <= to_);
503 } 444 }
504 bool is_empty() { return from_ == kNone; } 445 bool is_empty() const { return from_ == kNone; }
505 int from() const { return from_; } 446 intptr_t from() const { return from_; }
506 int to() const { return to_; } 447 intptr_t to() const { return to_; }
507 static Interval Empty() { return Interval(); } 448 static Interval Empty() { return Interval(); }
508 static const int kNone = -1; 449 static const intptr_t kNone = -1;
450
509 private: 451 private:
510 int from_; 452 intptr_t from_;
511 int to_; 453 intptr_t to_;
454
455 DISALLOW_ALLOCATION();
512 }; 456 };
513 457
514 458
515 class SeqRegExpNode: public RegExpNode { 459 class SeqRegExpNode: public RegExpNode {
516 public: 460 public:
517 explicit SeqRegExpNode(RegExpNode* on_success) 461 explicit SeqRegExpNode(RegExpNode* on_success)
518 : RegExpNode(on_success->zone()), on_success_(on_success) { } 462 : RegExpNode(on_success->isolate()), on_success_(on_success) { }
519 RegExpNode* on_success() { return on_success_; } 463 RegExpNode* on_success() { return on_success_; }
520 void set_on_success(RegExpNode* node) { on_success_ = node; } 464 void set_on_success(RegExpNode* node) { on_success_ = node; }
521 virtual RegExpNode* FilterOneByte(int depth, bool ignore_case); 465 virtual RegExpNode* FilterOneByte(intptr_t depth, bool ignore_case);
522 virtual void FillInBMInfo(int offset, 466 virtual void FillInBMInfo(intptr_t offset,
523 int budget, 467 intptr_t budget,
524 BoyerMooreLookahead* bm, 468 BoyerMooreLookahead* bm,
525 bool not_at_start) { 469 bool not_at_start) {
526 on_success_->FillInBMInfo(offset, budget - 1, bm, not_at_start); 470 on_success_->FillInBMInfo(offset, budget - 1, bm, not_at_start);
527 if (offset == 0) set_bm_info(not_at_start, bm); 471 if (offset == 0) set_bm_info(not_at_start, bm);
528 } 472 }
529 473
530 protected: 474 protected:
531 RegExpNode* FilterSuccessor(int depth, bool ignore_case); 475 RegExpNode* FilterSuccessor(intptr_t depth, bool ignore_case);
532 476
533 private: 477 private:
534 RegExpNode* on_success_; 478 RegExpNode* on_success_;
535 }; 479 };
536 480
537 481
538 class ActionNode: public SeqRegExpNode { 482 class ActionNode: public SeqRegExpNode {
539 public: 483 public:
540 enum ActionType { 484 enum ActionType {
541 SET_REGISTER, 485 SET_REGISTER,
542 INCREMENT_REGISTER, 486 INCREMENT_REGISTER,
543 STORE_POSITION, 487 STORE_POSITION,
544 BEGIN_SUBMATCH, 488 BEGIN_SUBMATCH,
545 POSITIVE_SUBMATCH_SUCCESS, 489 POSITIVE_SUBMATCH_SUCCESS,
546 EMPTY_MATCH_CHECK, 490 EMPTY_MATCH_CHECK,
547 CLEAR_CAPTURES 491 CLEAR_CAPTURES
548 }; 492 };
549 static ActionNode* SetRegister(int reg, int val, RegExpNode* on_success); 493 static ActionNode* SetRegister(intptr_t reg, intptr_t val,
550 static ActionNode* IncrementRegister(int reg, RegExpNode* on_success); 494 RegExpNode* on_success);
551 static ActionNode* StorePosition(int reg, 495 static ActionNode* IncrementRegister(intptr_t reg, RegExpNode* on_success);
496 static ActionNode* StorePosition(intptr_t reg,
552 bool is_capture, 497 bool is_capture,
553 RegExpNode* on_success); 498 RegExpNode* on_success);
554 static ActionNode* ClearCaptures(Interval range, RegExpNode* on_success); 499 static ActionNode* ClearCaptures(Interval range, RegExpNode* on_success);
555 static ActionNode* BeginSubmatch(int stack_pointer_reg, 500 static ActionNode* BeginSubmatch(intptr_t stack_pointer_reg,
556 int position_reg, 501 intptr_t position_reg,
557 RegExpNode* on_success); 502 RegExpNode* on_success);
558 static ActionNode* PositiveSubmatchSuccess(int stack_pointer_reg, 503 static ActionNode* PositiveSubmatchSuccess(intptr_t stack_pointer_reg,
559 int restore_reg, 504 intptr_t restore_reg,
560 int clear_capture_count, 505 intptr_t clear_capture_count,
561 int clear_capture_from, 506 intptr_t clear_capture_from,
562 RegExpNode* on_success); 507 RegExpNode* on_success);
563 static ActionNode* EmptyMatchCheck(int start_register, 508 static ActionNode* EmptyMatchCheck(intptr_t start_register,
564 int repetition_register, 509 intptr_t repetition_register,
565 int repetition_limit, 510 intptr_t repetition_limit,
566 RegExpNode* on_success); 511 RegExpNode* on_success);
567 virtual void Accept(NodeVisitor* visitor); 512 virtual void Accept(NodeVisitor* visitor);
568 virtual void Emit(RegExpCompiler* compiler, Trace* trace); 513 virtual void Emit(RegExpCompiler* compiler, Trace* trace);
569 virtual int EatsAtLeast(int still_to_find, int budget, bool not_at_start); 514 virtual intptr_t EatsAtLeast(intptr_t still_to_find, intptr_t budget,
515 bool not_at_start);
570 virtual void GetQuickCheckDetails(QuickCheckDetails* details, 516 virtual void GetQuickCheckDetails(QuickCheckDetails* details,
571 RegExpCompiler* compiler, 517 RegExpCompiler* compiler,
572 int filled_in, 518 intptr_t filled_in,
573 bool not_at_start) { 519 bool not_at_start) {
574 return on_success()->GetQuickCheckDetails( 520 return on_success()->GetQuickCheckDetails(
575 details, compiler, filled_in, not_at_start); 521 details, compiler, filled_in, not_at_start);
576 } 522 }
577 virtual void FillInBMInfo(int offset, 523 virtual void FillInBMInfo(intptr_t offset,
578 int budget, 524 intptr_t budget,
579 BoyerMooreLookahead* bm, 525 BoyerMooreLookahead* bm,
580 bool not_at_start); 526 bool not_at_start);
581 ActionType action_type() { return action_type_; } 527 ActionType action_type() { return action_type_; }
582 // TODO(erikcorry): We should allow some action nodes in greedy loops. 528 // TODO(erikcorry): We should allow some action nodes in greedy loops.
583 virtual int GreedyLoopTextLength() { return kNodeIsTooComplexForGreedyLoops; } 529 virtual intptr_t GreedyLoopTextLength() {
530 return kNodeIsTooComplexForGreedyLoops;
531 }
584 532
585 private: 533 private:
586 union { 534 union {
587 struct { 535 struct {
588 int reg; 536 intptr_t reg;
589 int value; 537 intptr_t value;
590 } u_store_register; 538 } u_store_register;
591 struct { 539 struct {
592 int reg; 540 intptr_t reg;
593 } u_increment_register; 541 } u_increment_register;
594 struct { 542 struct {
595 int reg; 543 intptr_t reg;
596 bool is_capture; 544 bool is_capture;
597 } u_position_register; 545 } u_position_register;
598 struct { 546 struct {
599 int stack_pointer_register; 547 intptr_t stack_pointer_register;
600 int current_position_register; 548 intptr_t current_position_register;
601 int clear_register_count; 549 intptr_t clear_register_count;
602 int clear_register_from; 550 intptr_t clear_register_from;
603 } u_submatch; 551 } u_submatch;
604 struct { 552 struct {
605 int start_register; 553 intptr_t start_register;
606 int repetition_register; 554 intptr_t repetition_register;
607 int repetition_limit; 555 intptr_t repetition_limit;
608 } u_empty_match_check; 556 } u_empty_match_check;
609 struct { 557 struct {
610 int range_from; 558 intptr_t range_from;
611 int range_to; 559 intptr_t range_to;
612 } u_clear_captures; 560 } u_clear_captures;
613 } data_; 561 } data_;
614 ActionNode(ActionType action_type, RegExpNode* on_success) 562 ActionNode(ActionType action_type, RegExpNode* on_success)
615 : SeqRegExpNode(on_success), 563 : SeqRegExpNode(on_success),
616 action_type_(action_type) { } 564 action_type_(action_type) { }
617 ActionType action_type_; 565 ActionType action_type_;
618 friend class DotPrinter; 566 friend class DotPrinter;
619 }; 567 };
620 568
621 569
622 class TextNode: public SeqRegExpNode { 570 class TextNode: public SeqRegExpNode {
623 public: 571 public:
624 TextNode(ZoneList<TextElement>* elms, 572 TextNode(ZoneGrowableArray<TextElement>* elms,
625 RegExpNode* on_success) 573 RegExpNode* on_success)
626 : SeqRegExpNode(on_success), 574 : SeqRegExpNode(on_success),
627 elms_(elms) { } 575 elms_(elms) { }
628 TextNode(RegExpCharacterClass* that, 576 TextNode(RegExpCharacterClass* that,
629 RegExpNode* on_success) 577 RegExpNode* on_success)
630 : SeqRegExpNode(on_success), 578 : SeqRegExpNode(on_success),
631 elms_(new(zone()) ZoneList<TextElement>(1, zone())) { 579 elms_(new(isolate()) ZoneGrowableArray<TextElement>(1)) {
632 elms_->Add(TextElement::CharClass(that), zone()); 580 elms_->Add(TextElement::CharClass(that));
633 } 581 }
634 virtual void Accept(NodeVisitor* visitor); 582 virtual void Accept(NodeVisitor* visitor);
635 virtual void Emit(RegExpCompiler* compiler, Trace* trace); 583 virtual void Emit(RegExpCompiler* compiler, Trace* trace);
636 virtual int EatsAtLeast(int still_to_find, int budget, bool not_at_start); 584 virtual intptr_t EatsAtLeast(intptr_t still_to_find, intptr_t budget,
585 bool not_at_start);
637 virtual void GetQuickCheckDetails(QuickCheckDetails* details, 586 virtual void GetQuickCheckDetails(QuickCheckDetails* details,
638 RegExpCompiler* compiler, 587 RegExpCompiler* compiler,
639 int characters_filled_in, 588 intptr_t characters_filled_in,
640 bool not_at_start); 589 bool not_at_start);
641 ZoneList<TextElement>* elements() { return elms_; } 590 ZoneGrowableArray<TextElement>* elements() { return elms_; }
642 void MakeCaseIndependent(bool is_one_byte); 591 void MakeCaseIndependent(bool is_one_byte);
643 virtual int GreedyLoopTextLength(); 592 virtual intptr_t GreedyLoopTextLength();
644 virtual RegExpNode* GetSuccessorOfOmnivorousTextNode( 593 virtual RegExpNode* GetSuccessorOfOmnivorousTextNode(
645 RegExpCompiler* compiler); 594 RegExpCompiler* compiler);
646 virtual void FillInBMInfo(int offset, 595 virtual void FillInBMInfo(intptr_t offset,
647 int budget, 596 intptr_t budget,
648 BoyerMooreLookahead* bm, 597 BoyerMooreLookahead* bm,
649 bool not_at_start); 598 bool not_at_start);
650 void CalculateOffsets(); 599 void CalculateOffsets();
651 virtual RegExpNode* FilterOneByte(int depth, bool ignore_case); 600 virtual RegExpNode* FilterOneByte(intptr_t depth, bool ignore_case);
652 601
653 private: 602 private:
654 enum TextEmitPassType { 603 enum TextEmitPassType {
655 NON_LATIN1_MATCH, // Check for characters that can't match. 604 NON_LATIN1_MATCH, // Check for characters that can't match.
656 SIMPLE_CHARACTER_MATCH, // Case-dependent single character check. 605 SIMPLE_CHARACTER_MATCH, // Case-dependent single character check.
657 NON_LETTER_CHARACTER_MATCH, // Check characters that have no case equivs. 606 NON_LETTER_CHARACTER_MATCH, // Check characters that have no case equivs.
658 CASE_CHARACTER_MATCH, // Case-independent single character check. 607 CASE_CHARACTER_MATCH, // Case-independent single character check.
659 CHARACTER_CLASS_MATCH // Character class. 608 CHARACTER_CLASS_MATCH // Character class.
660 }; 609 };
661 static bool SkipPass(int pass, bool ignore_case); 610 static bool SkipPass(intptr_t pass, bool ignore_case);
662 static const int kFirstRealPass = SIMPLE_CHARACTER_MATCH; 611 static const intptr_t kFirstRealPass = SIMPLE_CHARACTER_MATCH;
663 static const int kLastPass = CHARACTER_CLASS_MATCH; 612 static const intptr_t kLastPass = CHARACTER_CLASS_MATCH;
664 void TextEmitPass(RegExpCompiler* compiler, 613 void TextEmitPass(RegExpCompiler* compiler,
665 TextEmitPassType pass, 614 TextEmitPassType pass,
666 bool preloaded, 615 bool preloaded,
667 Trace* trace, 616 Trace* trace,
668 bool first_element_checked, 617 bool first_element_checked,
669 int* checked_up_to); 618 intptr_t* checked_up_to);
670 int Length(); 619 intptr_t Length();
671 ZoneList<TextElement>* elms_; 620 ZoneGrowableArray<TextElement>* elms_;
672 }; 621 };
673 622
674 623
675 class AssertionNode: public SeqRegExpNode { 624 class AssertionNode: public SeqRegExpNode {
676 public: 625 public:
677 enum AssertionType { 626 enum AssertionType {
678 AT_END, 627 AT_END,
679 AT_START, 628 AT_START,
680 AT_BOUNDARY, 629 AT_BOUNDARY,
681 AT_NON_BOUNDARY, 630 AT_NON_BOUNDARY,
682 AFTER_NEWLINE 631 AFTER_NEWLINE
683 }; 632 };
684 static AssertionNode* AtEnd(RegExpNode* on_success) { 633 static AssertionNode* AtEnd(RegExpNode* on_success) {
685 return new(on_success->zone()) AssertionNode(AT_END, on_success); 634 return new(on_success->isolate()) AssertionNode(AT_END, on_success);
686 } 635 }
687 static AssertionNode* AtStart(RegExpNode* on_success) { 636 static AssertionNode* AtStart(RegExpNode* on_success) {
688 return new(on_success->zone()) AssertionNode(AT_START, on_success); 637 return new(on_success->isolate()) AssertionNode(AT_START, on_success);
689 } 638 }
690 static AssertionNode* AtBoundary(RegExpNode* on_success) { 639 static AssertionNode* AtBoundary(RegExpNode* on_success) {
691 return new(on_success->zone()) AssertionNode(AT_BOUNDARY, on_success); 640 return new(on_success->isolate()) AssertionNode(AT_BOUNDARY, on_success);
692 } 641 }
693 static AssertionNode* AtNonBoundary(RegExpNode* on_success) { 642 static AssertionNode* AtNonBoundary(RegExpNode* on_success) {
694 return new(on_success->zone()) AssertionNode(AT_NON_BOUNDARY, on_success); 643 return new(on_success->isolate()) AssertionNode(AT_NON_BOUNDARY,
644 on_success);
695 } 645 }
696 static AssertionNode* AfterNewline(RegExpNode* on_success) { 646 static AssertionNode* AfterNewline(RegExpNode* on_success) {
697 return new(on_success->zone()) AssertionNode(AFTER_NEWLINE, on_success); 647 return new(on_success->isolate()) AssertionNode(AFTER_NEWLINE, on_success);
698 } 648 }
699 virtual void Accept(NodeVisitor* visitor); 649 virtual void Accept(NodeVisitor* visitor);
700 virtual void Emit(RegExpCompiler* compiler, Trace* trace); 650 virtual void Emit(RegExpCompiler* compiler, Trace* trace);
701 virtual int EatsAtLeast(int still_to_find, int budget, bool not_at_start); 651 virtual intptr_t EatsAtLeast(intptr_t still_to_find, intptr_t budget,
652 bool not_at_start);
702 virtual void GetQuickCheckDetails(QuickCheckDetails* details, 653 virtual void GetQuickCheckDetails(QuickCheckDetails* details,
703 RegExpCompiler* compiler, 654 RegExpCompiler* compiler,
704 int filled_in, 655 intptr_t filled_in,
705 bool not_at_start); 656 bool not_at_start);
706 virtual void FillInBMInfo(int offset, 657 virtual void FillInBMInfo(intptr_t offset,
707 int budget, 658 intptr_t budget,
708 BoyerMooreLookahead* bm, 659 BoyerMooreLookahead* bm,
709 bool not_at_start); 660 bool not_at_start);
710 AssertionType assertion_type() { return assertion_type_; } 661 AssertionType assertion_type() { return assertion_type_; }
711 662
712 private: 663 private:
713 void EmitBoundaryCheck(RegExpCompiler* compiler, Trace* trace); 664 void EmitBoundaryCheck(RegExpCompiler* compiler, Trace* trace);
714 enum IfPrevious { kIsNonWord, kIsWord }; 665 enum IfPrevious { kIsNonWord, kIsWord };
715 void BacktrackIfPrevious(RegExpCompiler* compiler, 666 void BacktrackIfPrevious(RegExpCompiler* compiler,
716 Trace* trace, 667 Trace* trace,
717 IfPrevious backtrack_if_previous); 668 IfPrevious backtrack_if_previous);
718 AssertionNode(AssertionType t, RegExpNode* on_success) 669 AssertionNode(AssertionType t, RegExpNode* on_success)
719 : SeqRegExpNode(on_success), assertion_type_(t) { } 670 : SeqRegExpNode(on_success), assertion_type_(t) { }
720 AssertionType assertion_type_; 671 AssertionType assertion_type_;
721 }; 672 };
722 673
723 674
724 class BackReferenceNode: public SeqRegExpNode { 675 class BackReferenceNode: public SeqRegExpNode {
725 public: 676 public:
726 BackReferenceNode(int start_reg, 677 BackReferenceNode(intptr_t start_reg,
727 int end_reg, 678 intptr_t end_reg,
728 RegExpNode* on_success) 679 RegExpNode* on_success)
729 : SeqRegExpNode(on_success), 680 : SeqRegExpNode(on_success),
730 start_reg_(start_reg), 681 start_reg_(start_reg),
731 end_reg_(end_reg) { } 682 end_reg_(end_reg) { }
732 virtual void Accept(NodeVisitor* visitor); 683 virtual void Accept(NodeVisitor* visitor);
733 int start_register() { return start_reg_; } 684 intptr_t start_register() { return start_reg_; }
734 int end_register() { return end_reg_; } 685 intptr_t end_register() { return end_reg_; }
735 virtual void Emit(RegExpCompiler* compiler, Trace* trace); 686 virtual void Emit(RegExpCompiler* compiler, Trace* trace);
736 virtual int EatsAtLeast(int still_to_find, 687 virtual intptr_t EatsAtLeast(intptr_t still_to_find,
737 int recursion_depth, 688 intptr_t recursion_depth,
738 bool not_at_start); 689 bool not_at_start);
739 virtual void GetQuickCheckDetails(QuickCheckDetails* details, 690 virtual void GetQuickCheckDetails(QuickCheckDetails* details,
740 RegExpCompiler* compiler, 691 RegExpCompiler* compiler,
741 int characters_filled_in, 692 intptr_t characters_filled_in,
742 bool not_at_start) { 693 bool not_at_start) {
743 return; 694 return;
744 } 695 }
745 virtual void FillInBMInfo(int offset, 696 virtual void FillInBMInfo(intptr_t offset,
746 int budget, 697 intptr_t budget,
747 BoyerMooreLookahead* bm, 698 BoyerMooreLookahead* bm,
748 bool not_at_start); 699 bool not_at_start);
749 700
750 private: 701 private:
751 int start_reg_; 702 intptr_t start_reg_;
752 int end_reg_; 703 intptr_t end_reg_;
753 }; 704 };
754 705
755 706
756 class EndNode: public RegExpNode { 707 class EndNode: public RegExpNode {
757 public: 708 public:
758 enum Action { ACCEPT, BACKTRACK, NEGATIVE_SUBMATCH_SUCCESS }; 709 enum Action { ACCEPT, BACKTRACK, NEGATIVE_SUBMATCH_SUCCESS };
759 explicit EndNode(Action action, Zone* zone) 710 explicit EndNode(Action action, Isolate* isolate)
760 : RegExpNode(zone), action_(action) { } 711 : RegExpNode(isolate), action_(action) { }
761 virtual void Accept(NodeVisitor* visitor); 712 virtual void Accept(NodeVisitor* visitor);
762 virtual void Emit(RegExpCompiler* compiler, Trace* trace); 713 virtual void Emit(RegExpCompiler* compiler, Trace* trace);
763 virtual int EatsAtLeast(int still_to_find, 714 virtual intptr_t EatsAtLeast(intptr_t still_to_find,
764 int recursion_depth, 715 intptr_t recursion_depth,
765 bool not_at_start) { return 0; } 716 bool not_at_start) { return 0; }
766 virtual void GetQuickCheckDetails(QuickCheckDetails* details, 717 virtual void GetQuickCheckDetails(QuickCheckDetails* details,
767 RegExpCompiler* compiler, 718 RegExpCompiler* compiler,
768 int characters_filled_in, 719 intptr_t characters_filled_in,
769 bool not_at_start) { 720 bool not_at_start) {
770 // Returning 0 from EatsAtLeast should ensure we never get here. 721 // Returning 0 from EatsAtLeast should ensure we never get here.
771 UNREACHABLE(); 722 UNREACHABLE();
772 } 723 }
773 virtual void FillInBMInfo(int offset, 724 virtual void FillInBMInfo(intptr_t offset,
774 int budget, 725 intptr_t budget,
775 BoyerMooreLookahead* bm, 726 BoyerMooreLookahead* bm,
776 bool not_at_start) { 727 bool not_at_start) {
777 // Returning 0 from EatsAtLeast should ensure we never get here. 728 // Returning 0 from EatsAtLeast should ensure we never get here.
778 UNREACHABLE(); 729 UNREACHABLE();
779 } 730 }
780 731
781 private: 732 private:
782 Action action_; 733 Action action_;
783 }; 734 };
784 735
785 736
786 class NegativeSubmatchSuccess: public EndNode { 737 class NegativeSubmatchSuccess: public EndNode {
787 public: 738 public:
788 NegativeSubmatchSuccess(int stack_pointer_reg, 739 NegativeSubmatchSuccess(intptr_t stack_pointer_reg,
789 int position_reg, 740 intptr_t position_reg,
790 int clear_capture_count, 741 intptr_t clear_capture_count,
791 int clear_capture_start, 742 intptr_t clear_capture_start,
792 Zone* zone) 743 Isolate* isolate)
793 : EndNode(NEGATIVE_SUBMATCH_SUCCESS, zone), 744 : EndNode(NEGATIVE_SUBMATCH_SUCCESS, isolate),
794 stack_pointer_register_(stack_pointer_reg), 745 stack_pointer_register_(stack_pointer_reg),
795 current_position_register_(position_reg), 746 current_position_register_(position_reg),
796 clear_capture_count_(clear_capture_count), 747 clear_capture_count_(clear_capture_count),
797 clear_capture_start_(clear_capture_start) { } 748 clear_capture_start_(clear_capture_start) { }
798 virtual void Emit(RegExpCompiler* compiler, Trace* trace); 749 virtual void Emit(RegExpCompiler* compiler, Trace* trace);
799 750
800 private: 751 private:
801 int stack_pointer_register_; 752 intptr_t stack_pointer_register_;
802 int current_position_register_; 753 intptr_t current_position_register_;
803 int clear_capture_count_; 754 intptr_t clear_capture_count_;
804 int clear_capture_start_; 755 intptr_t clear_capture_start_;
805 }; 756 };
806 757
807 758
808 class Guard: public ZoneObject { 759 class Guard: public ZoneAllocated {
809 public: 760 public:
810 enum Relation { LT, GEQ }; 761 enum Relation { LT, GEQ };
811 Guard(int reg, Relation op, int value) 762 Guard(intptr_t reg, Relation op, intptr_t value)
812 : reg_(reg), 763 : reg_(reg),
813 op_(op), 764 op_(op),
814 value_(value) { } 765 value_(value) { }
815 int reg() { return reg_; } 766 intptr_t reg() { return reg_; }
816 Relation op() { return op_; } 767 Relation op() { return op_; }
817 int value() { return value_; } 768 intptr_t value() { return value_; }
818 769
819 private: 770 private:
820 int reg_; 771 intptr_t reg_;
821 Relation op_; 772 Relation op_;
822 int value_; 773 intptr_t value_;
823 }; 774 };
824 775
825 776
826 class GuardedAlternative { 777 class GuardedAlternative {
827 public: 778 public:
828 explicit GuardedAlternative(RegExpNode* node) : node_(node), guards_(NULL) { } 779 explicit GuardedAlternative(RegExpNode* node) : node_(node), guards_(NULL) { }
829 void AddGuard(Guard* guard, Zone* zone); 780 void AddGuard(Guard* guard, Isolate* isolate);
830 RegExpNode* node() { return node_; } 781 RegExpNode* node() { return node_; }
831 void set_node(RegExpNode* node) { node_ = node; } 782 void set_node(RegExpNode* node) { node_ = node; }
832 ZoneList<Guard*>* guards() { return guards_; } 783 ZoneGrowableArray<Guard*>* guards() { return guards_; }
833 784
834 private: 785 private:
835 RegExpNode* node_; 786 RegExpNode* node_;
836 ZoneList<Guard*>* guards_; 787 ZoneGrowableArray<Guard*>* guards_;
788
789 DISALLOW_ALLOCATION();
837 }; 790 };
838 791
839 792
840 class AlternativeGeneration; 793 class AlternativeGeneration;
841 794
842 795
843 class ChoiceNode: public RegExpNode { 796 class ChoiceNode: public RegExpNode {
844 public: 797 public:
845 explicit ChoiceNode(int expected_size, Zone* zone) 798 explicit ChoiceNode(intptr_t expected_size, Isolate* isolate)
846 : RegExpNode(zone), 799 : RegExpNode(isolate),
847 alternatives_(new(zone) 800 alternatives_(new(isolate)
848 ZoneList<GuardedAlternative>(expected_size, zone)), 801 ZoneGrowableArray<GuardedAlternative>(expected_size)),
849 table_(NULL),
850 not_at_start_(false), 802 not_at_start_(false),
851 being_calculated_(false) { } 803 being_calculated_(false) { }
852 virtual void Accept(NodeVisitor* visitor); 804 virtual void Accept(NodeVisitor* visitor);
853 void AddAlternative(GuardedAlternative node) { 805 void AddAlternative(GuardedAlternative node) {
854 alternatives()->Add(node, zone()); 806 alternatives()->Add(node);
855 } 807 }
856 ZoneList<GuardedAlternative>* alternatives() { return alternatives_; } 808 ZoneGrowableArray<GuardedAlternative>* alternatives() {
857 DispatchTable* GetTable(bool ignore_case); 809 return alternatives_;
810 }
858 virtual void Emit(RegExpCompiler* compiler, Trace* trace); 811 virtual void Emit(RegExpCompiler* compiler, Trace* trace);
859 virtual int EatsAtLeast(int still_to_find, int budget, bool not_at_start); 812 virtual intptr_t EatsAtLeast(intptr_t still_to_find, intptr_t budget,
860 int EatsAtLeastHelper(int still_to_find, 813 bool not_at_start);
861 int budget, 814 intptr_t EatsAtLeastHelper(intptr_t still_to_find,
862 RegExpNode* ignore_this_node, 815 intptr_t budget,
863 bool not_at_start); 816 RegExpNode* ignore_this_node,
817 bool not_at_start);
864 virtual void GetQuickCheckDetails(QuickCheckDetails* details, 818 virtual void GetQuickCheckDetails(QuickCheckDetails* details,
865 RegExpCompiler* compiler, 819 RegExpCompiler* compiler,
866 int characters_filled_in, 820 intptr_t characters_filled_in,
867 bool not_at_start); 821 bool not_at_start);
868 virtual void FillInBMInfo(int offset, 822 virtual void FillInBMInfo(intptr_t offset,
869 int budget, 823 intptr_t budget,
870 BoyerMooreLookahead* bm, 824 BoyerMooreLookahead* bm,
871 bool not_at_start); 825 bool not_at_start);
872 826
873 bool being_calculated() { return being_calculated_; } 827 bool being_calculated() { return being_calculated_; }
874 bool not_at_start() { return not_at_start_; } 828 bool not_at_start() { return not_at_start_; }
875 void set_not_at_start() { not_at_start_ = true; } 829 void set_not_at_start() { not_at_start_ = true; }
876 void set_being_calculated(bool b) { being_calculated_ = b; } 830 void set_being_calculated(bool b) { being_calculated_ = b; }
877 virtual bool try_to_emit_quick_check_for_alternative(bool is_first) { 831 virtual bool try_to_emit_quick_check_for_alternative(bool is_first) {
878 return true; 832 return true;
879 } 833 }
880 virtual RegExpNode* FilterOneByte(int depth, bool ignore_case); 834 virtual RegExpNode* FilterOneByte(intptr_t depth, bool ignore_case);
881 835
882 protected: 836 protected:
883 int GreedyLoopTextLengthForAlternative(GuardedAlternative* alternative); 837 intptr_t GreedyLoopTextLengthForAlternative(GuardedAlternative* alternative);
884 ZoneList<GuardedAlternative>* alternatives_; 838 ZoneGrowableArray<GuardedAlternative>* alternatives_;
885 839
886 private: 840 private:
887 friend class DispatchTableConstructor;
888 friend class Analysis; 841 friend class Analysis;
889 void GenerateGuard(RegExpMacroAssembler* macro_assembler, 842 void GenerateGuard(RegExpMacroAssembler* macro_assembler,
890 Guard* guard, 843 Guard* guard,
891 Trace* trace); 844 Trace* trace);
892 int CalculatePreloadCharacters(RegExpCompiler* compiler, int eats_at_least); 845 intptr_t CalculatePreloadCharacters(RegExpCompiler* compiler,
846 intptr_t eats_at_least);
893 void EmitOutOfLineContinuation(RegExpCompiler* compiler, 847 void EmitOutOfLineContinuation(RegExpCompiler* compiler,
894 Trace* trace, 848 Trace* trace,
895 GuardedAlternative alternative, 849 GuardedAlternative alternative,
896 AlternativeGeneration* alt_gen, 850 AlternativeGeneration* alt_gen,
897 int preload_characters, 851 intptr_t preload_characters,
898 bool next_expects_preload); 852 bool next_expects_preload);
899 void SetUpPreLoad(RegExpCompiler* compiler, 853 void SetUpPreLoad(RegExpCompiler* compiler,
900 Trace* current_trace, 854 Trace* current_trace,
901 PreloadState* preloads); 855 PreloadState* preloads);
902 void AssertGuardsMentionRegisters(Trace* trace); 856 void AssertGuardsMentionRegisters(Trace* trace);
903 int EmitOptimizedUnanchoredSearch(RegExpCompiler* compiler, Trace* trace); 857 intptr_t EmitOptimizedUnanchoredSearch(RegExpCompiler* compiler,
858 Trace* trace);
904 Trace* EmitGreedyLoop(RegExpCompiler* compiler, 859 Trace* EmitGreedyLoop(RegExpCompiler* compiler,
905 Trace* trace, 860 Trace* trace,
906 AlternativeGenerationList* alt_gens, 861 AlternativeGenerationList* alt_gens,
907 PreloadState* preloads, 862 PreloadState* preloads,
908 GreedyLoopState* greedy_loop_state, 863 GreedyLoopState* greedy_loop_state,
909 int text_length); 864 intptr_t text_length);
910 void EmitChoices(RegExpCompiler* compiler, 865 void EmitChoices(RegExpCompiler* compiler,
911 AlternativeGenerationList* alt_gens, 866 AlternativeGenerationList* alt_gens,
912 int first_choice, 867 intptr_t first_choice,
913 Trace* trace, 868 Trace* trace,
914 PreloadState* preloads); 869 PreloadState* preloads);
915 DispatchTable* table_;
916 // If true, this node is never checked at the start of the input. 870 // If true, this node is never checked at the start of the input.
917 // Allows a new trace to start with at_start() set to false. 871 // Allows a new trace to start with at_start() set to false.
918 bool not_at_start_; 872 bool not_at_start_;
919 bool being_calculated_; 873 bool being_calculated_;
920 }; 874 };
921 875
922 876
923 class NegativeLookaheadChoiceNode: public ChoiceNode { 877 class NegativeLookaheadChoiceNode: public ChoiceNode {
924 public: 878 public:
925 explicit NegativeLookaheadChoiceNode(GuardedAlternative this_must_fail, 879 explicit NegativeLookaheadChoiceNode(GuardedAlternative this_must_fail,
926 GuardedAlternative then_do_this, 880 GuardedAlternative then_do_this,
927 Zone* zone) 881 Isolate* isolate)
928 : ChoiceNode(2, zone) { 882 : ChoiceNode(2, isolate) {
929 AddAlternative(this_must_fail); 883 AddAlternative(this_must_fail);
930 AddAlternative(then_do_this); 884 AddAlternative(then_do_this);
931 } 885 }
932 virtual int EatsAtLeast(int still_to_find, int budget, bool not_at_start); 886 virtual intptr_t EatsAtLeast(intptr_t still_to_find, intptr_t budget,
887 bool not_at_start);
933 virtual void GetQuickCheckDetails(QuickCheckDetails* details, 888 virtual void GetQuickCheckDetails(QuickCheckDetails* details,
934 RegExpCompiler* compiler, 889 RegExpCompiler* compiler,
935 int characters_filled_in, 890 intptr_t characters_filled_in,
936 bool not_at_start); 891 bool not_at_start);
937 virtual void FillInBMInfo(int offset, 892 virtual void FillInBMInfo(intptr_t offset,
938 int budget, 893 intptr_t budget,
939 BoyerMooreLookahead* bm, 894 BoyerMooreLookahead* bm,
940 bool not_at_start) { 895 bool not_at_start) {
941 alternatives_->at(1).node()->FillInBMInfo( 896 (*alternatives_)[1].node()->FillInBMInfo(
942 offset, budget - 1, bm, not_at_start); 897 offset, budget - 1, bm, not_at_start);
943 if (offset == 0) set_bm_info(not_at_start, bm); 898 if (offset == 0) set_bm_info(not_at_start, bm);
944 } 899 }
945 // For a negative lookahead we don't emit the quick check for the 900 // For a negative lookahead we don't emit the quick check for the
946 // alternative that is expected to fail. This is because quick check code 901 // alternative that is expected to fail. This is because quick check code
947 // starts by loading enough characters for the alternative that takes fewest 902 // starts by loading enough characters for the alternative that takes fewest
948 // characters, but on a negative lookahead the negative branch did not take 903 // characters, but on a negative lookahead the negative branch did not take
949 // part in that calculation (EatsAtLeast) so the assumptions don't hold. 904 // part in that calculation (EatsAtLeast) so the assumptions don't hold.
950 virtual bool try_to_emit_quick_check_for_alternative(bool is_first) { 905 virtual bool try_to_emit_quick_check_for_alternative(bool is_first) {
951 return !is_first; 906 return !is_first;
952 } 907 }
953 virtual RegExpNode* FilterOneByte(int depth, bool ignore_case); 908 virtual RegExpNode* FilterOneByte(intptr_t depth, bool ignore_case);
954 }; 909 };
955 910
956 911
957 class LoopChoiceNode: public ChoiceNode { 912 class LoopChoiceNode: public ChoiceNode {
958 public: 913 public:
959 explicit LoopChoiceNode(bool body_can_be_zero_length, Zone* zone) 914 explicit LoopChoiceNode(bool body_can_be_zero_length, Isolate* isolate)
960 : ChoiceNode(2, zone), 915 : ChoiceNode(2, isolate),
961 loop_node_(NULL), 916 loop_node_(NULL),
962 continue_node_(NULL), 917 continue_node_(NULL),
963 body_can_be_zero_length_(body_can_be_zero_length) 918 body_can_be_zero_length_(body_can_be_zero_length) { }
964 { }
965 void AddLoopAlternative(GuardedAlternative alt); 919 void AddLoopAlternative(GuardedAlternative alt);
966 void AddContinueAlternative(GuardedAlternative alt); 920 void AddContinueAlternative(GuardedAlternative alt);
967 virtual void Emit(RegExpCompiler* compiler, Trace* trace); 921 virtual void Emit(RegExpCompiler* compiler, Trace* trace);
968 virtual int EatsAtLeast(int still_to_find, int budget, bool not_at_start); 922 virtual intptr_t EatsAtLeast(intptr_t still_to_find, intptr_t budget,
923 bool not_at_start);
969 virtual void GetQuickCheckDetails(QuickCheckDetails* details, 924 virtual void GetQuickCheckDetails(QuickCheckDetails* details,
970 RegExpCompiler* compiler, 925 RegExpCompiler* compiler,
971 int characters_filled_in, 926 intptr_t characters_filled_in,
972 bool not_at_start); 927 bool not_at_start);
973 virtual void FillInBMInfo(int offset, 928 virtual void FillInBMInfo(intptr_t offset,
974 int budget, 929 intptr_t budget,
975 BoyerMooreLookahead* bm, 930 BoyerMooreLookahead* bm,
976 bool not_at_start); 931 bool not_at_start);
977 RegExpNode* loop_node() { return loop_node_; } 932 RegExpNode* loop_node() { return loop_node_; }
978 RegExpNode* continue_node() { return continue_node_; } 933 RegExpNode* continue_node() { return continue_node_; }
979 bool body_can_be_zero_length() { return body_can_be_zero_length_; } 934 bool body_can_be_zero_length() { return body_can_be_zero_length_; }
980 virtual void Accept(NodeVisitor* visitor); 935 virtual void Accept(NodeVisitor* visitor);
981 virtual RegExpNode* FilterOneByte(int depth, bool ignore_case); 936 virtual RegExpNode* FilterOneByte(intptr_t depth, bool ignore_case);
982 937
983 private: 938 private:
984 // AddAlternative is made private for loop nodes because alternatives 939 // AddAlternative is made private for loop nodes because alternatives
985 // should not be added freely, we need to keep track of which node 940 // should not be added freely, we need to keep track of which node
986 // goes back to the node itself. 941 // goes back to the node itself.
987 void AddAlternative(GuardedAlternative node) { 942 void AddAlternative(GuardedAlternative node) {
988 ChoiceNode::AddAlternative(node); 943 ChoiceNode::AddAlternative(node);
989 } 944 }
990 945
991 RegExpNode* loop_node_; 946 RegExpNode* loop_node_;
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
1026 kLatticeUnknown = 3 // Can also mean both in and out. 981 kLatticeUnknown = 3 // Can also mean both in and out.
1027 }; 982 };
1028 983
1029 984
1030 inline ContainedInLattice Combine(ContainedInLattice a, ContainedInLattice b) { 985 inline ContainedInLattice Combine(ContainedInLattice a, ContainedInLattice b) {
1031 return static_cast<ContainedInLattice>(a | b); 986 return static_cast<ContainedInLattice>(a | b);
1032 } 987 }
1033 988
1034 989
1035 ContainedInLattice AddRange(ContainedInLattice a, 990 ContainedInLattice AddRange(ContainedInLattice a,
1036 const int* ranges, 991 const intptr_t* ranges,
1037 int ranges_size, 992 intptr_t ranges_size,
1038 Interval new_range); 993 Interval new_range);
1039 994
1040 995
1041 class BoyerMoorePositionInfo : public ZoneObject { 996 class BoyerMoorePositionInfo : public ZoneAllocated {
1042 public: 997 public:
1043 explicit BoyerMoorePositionInfo(Zone* zone) 998 explicit BoyerMoorePositionInfo(Isolate* isolate)
1044 : map_(new(zone) ZoneList<bool>(kMapSize, zone)), 999 : map_(new(isolate) ZoneGrowableArray<bool>(kMapSize)),
1045 map_count_(0), 1000 map_count_(0),
1046 w_(kNotYet), 1001 w_(kNotYet),
1047 s_(kNotYet), 1002 s_(kNotYet),
1048 d_(kNotYet), 1003 d_(kNotYet),
1049 surrogate_(kNotYet) { 1004 surrogate_(kNotYet) {
1050 for (int i = 0; i < kMapSize; i++) { 1005 for (intptr_t i = 0; i < kMapSize; i++) {
1051 map_->Add(false, zone); 1006 map_->Add(false);
1052 } 1007 }
1053 } 1008 }
1054 1009
1055 bool& at(int i) { return map_->at(i); } 1010 bool& at(intptr_t i) { return (*map_)[i]; }
1056 1011
1057 static const int kMapSize = 128; 1012 static const intptr_t kMapSize = 128;
1058 static const int kMask = kMapSize - 1; 1013 static const intptr_t kMask = kMapSize - 1;
1059 1014
1060 int map_count() const { return map_count_; } 1015 intptr_t map_count() const { return map_count_; }
1061 1016
1062 void Set(int character); 1017 void Set(intptr_t character);
1063 void SetInterval(const Interval& interval); 1018 void SetInterval(const Interval& interval);
1064 void SetAll(); 1019 void SetAll();
1065 bool is_non_word() { return w_ == kLatticeOut; } 1020 bool is_non_word() { return w_ == kLatticeOut; }
1066 bool is_word() { return w_ == kLatticeIn; } 1021 bool is_word() { return w_ == kLatticeIn; }
1067 1022
1068 private: 1023 private:
1069 ZoneList<bool>* map_; 1024 ZoneGrowableArray<bool>* map_;
1070 int map_count_; // Number of set bits in the map. 1025 intptr_t map_count_; // Number of set bits in the map.
1071 ContainedInLattice w_; // The \w character class. 1026 ContainedInLattice w_; // The \w character class.
1072 ContainedInLattice s_; // The \s character class. 1027 ContainedInLattice s_; // The \s character class.
1073 ContainedInLattice d_; // The \d character class. 1028 ContainedInLattice d_; // The \d character class.
1074 ContainedInLattice surrogate_; // Surrogate UTF-16 code units. 1029 ContainedInLattice surrogate_; // Surrogate UTF-16 code units.
1075 }; 1030 };
1076 1031
1077 1032
1078 class BoyerMooreLookahead : public ZoneObject { 1033 class BoyerMooreLookahead : public ZoneAllocated{
1079 public: 1034 public:
1080 BoyerMooreLookahead(int length, RegExpCompiler* compiler, Zone* zone); 1035 BoyerMooreLookahead(intptr_t length, RegExpCompiler* compiler,
1036 Isolate* Isolate);
1081 1037
1082 int length() { return length_; } 1038 intptr_t length() { return length_; }
1083 int max_char() { return max_char_; } 1039 intptr_t max_char() { return max_char_; }
1084 RegExpCompiler* compiler() { return compiler_; } 1040 RegExpCompiler* compiler() { return compiler_; }
1085 1041
1086 int Count(int map_number) { 1042 intptr_t Count(intptr_t map_number) {
1087 return bitmaps_->at(map_number)->map_count(); 1043 return bitmaps_->At(map_number)->map_count();
1088 } 1044 }
1089 1045
1090 BoyerMoorePositionInfo* at(int i) { return bitmaps_->at(i); } 1046 BoyerMoorePositionInfo* at(intptr_t i) { return bitmaps_->At(i); }
1091 1047
1092 void Set(int map_number, int character) { 1048 void Set(intptr_t map_number, intptr_t character) {
1093 if (character > max_char_) return; 1049 if (character > max_char_) return;
1094 BoyerMoorePositionInfo* info = bitmaps_->at(map_number); 1050 BoyerMoorePositionInfo* info = bitmaps_->At(map_number);
1095 info->Set(character); 1051 info->Set(character);
1096 } 1052 }
1097 1053
1098 void SetInterval(int map_number, const Interval& interval) { 1054 void SetInterval(intptr_t map_number, const Interval& interval) {
1099 if (interval.from() > max_char_) return; 1055 if (interval.from() > max_char_) return;
1100 BoyerMoorePositionInfo* info = bitmaps_->at(map_number); 1056 BoyerMoorePositionInfo* info = bitmaps_->At(map_number);
1101 if (interval.to() > max_char_) { 1057 if (interval.to() > max_char_) {
1102 info->SetInterval(Interval(interval.from(), max_char_)); 1058 info->SetInterval(Interval(interval.from(), max_char_));
1103 } else { 1059 } else {
1104 info->SetInterval(interval); 1060 info->SetInterval(interval);
1105 } 1061 }
1106 } 1062 }
1107 1063
1108 void SetAll(int map_number) { 1064 void SetAll(intptr_t map_number) {
1109 bitmaps_->at(map_number)->SetAll(); 1065 bitmaps_->At(map_number)->SetAll();
1110 } 1066 }
1111 1067
1112 void SetRest(int from_map) { 1068 void SetRest(intptr_t from_map) {
1113 for (int i = from_map; i < length_; i++) SetAll(i); 1069 for (intptr_t i = from_map; i < length_; i++) SetAll(i);
1114 } 1070 }
1115 void EmitSkipInstructions(RegExpMacroAssembler* masm); 1071 void EmitSkipInstructions(RegExpMacroAssembler* masm);
1116 1072
1117 private: 1073 private:
1118 // This is the value obtained by EatsAtLeast. If we do not have at least this 1074 // This is the value obtained by EatsAtLeast. If we do not have at least this
1119 // many characters left in the sample string then the match is bound to fail. 1075 // many characters left in the sample string then the match is bound to fail.
1120 // Therefore it is OK to read a character this far ahead of the current match 1076 // Therefore it is OK to read a character this far ahead of the current match
1121 // point. 1077 // point.
1122 int length_; 1078 intptr_t length_;
1123 RegExpCompiler* compiler_; 1079 RegExpCompiler* compiler_;
1124 // 0xff for Latin1, 0xffff for UTF-16. 1080 // 0xff for Latin1, 0xffff for UTF-16.
1125 int max_char_; 1081 intptr_t max_char_;
1126 ZoneList<BoyerMoorePositionInfo*>* bitmaps_; 1082 ZoneGrowableArray<BoyerMoorePositionInfo*>* bitmaps_;
1127 1083
1128 int GetSkipTable(int min_lookahead, 1084 intptr_t GetSkipTable(intptr_t min_lookahead,
1129 int max_lookahead, 1085 intptr_t max_lookahead,
1130 Handle<ByteArray> boolean_skip_table); 1086 const TypedData& boolean_skip_table);
1131 bool FindWorthwhileInterval(int* from, int* to); 1087 bool FindWorthwhileInterval(intptr_t* from, intptr_t* to);
1132 int FindBestInterval( 1088 intptr_t FindBestInterval(
1133 int max_number_of_chars, int old_biggest_points, int* from, int* to); 1089 intptr_t max_number_of_chars,
1090 intptr_t old_biggest_points,
1091 intptr_t* from, intptr_t* to);
1134 }; 1092 };
1135 1093
1136 1094
1137 // There are many ways to generate code for a node. This class encapsulates 1095 // There are many ways to generate code for a node. This class encapsulates
1138 // the current way we should be generating. In other words it encapsulates 1096 // the current way we should be generating. In other words it encapsulates
1139 // the current state of the code generator. The effect of this is that we 1097 // the current state of the code generator. The effect of this is that we
1140 // generate code for paths that the matcher can take through the regular 1098 // generate code for paths that the matcher can take through the regular
1141 // expression. A given node in the regexp can be code-generated several times 1099 // expression. A given node in the regexp can be code-generated several times
1142 // as it can be part of several traces. For example for the regexp: 1100 // as it can be part of several traces. For example for the regexp:
1143 // /foo(bar|ip)baz/ the code to match baz will be generated twice, once as part 1101 // /foo(bar|ip)baz/ the code to match baz will be generated twice, once as part
1144 // of the foo-bar-baz trace and once as part of the foo-ip-baz trace. The code 1102 // of the foo-bar-baz trace and once as part of the foo-ip-baz trace. The code
1145 // to match foo is generated only once (the traces have a common prefix). The 1103 // to match foo is generated only once (the traces have a common prefix). The
1146 // code to store the capture is deferred and generated (twice) after the places 1104 // code to store the capture is deferred and generated (twice) after the places
1147 // where baz has been matched. 1105 // where baz has been matched.
1148 class Trace { 1106 class Trace {
1149 public: 1107 public:
1150 // A value for a property that is either known to be true, know to be false, 1108 // A value for a property that is either known to be true, know to be false,
1151 // or not known. 1109 // or not known.
1152 enum TriBool { 1110 enum TriBool {
1153 UNKNOWN = -1, FALSE_VALUE = 0, TRUE_VALUE = 1 1111 UNKNOWN = -1, FALSE_VALUE = 0, TRUE_VALUE = 1
1154 }; 1112 };
1155 1113
1156 class DeferredAction { 1114 class DeferredAction {
1157 public: 1115 public:
1158 DeferredAction(ActionNode::ActionType action_type, int reg) 1116 DeferredAction(ActionNode::ActionType action_type, intptr_t reg)
1159 : action_type_(action_type), reg_(reg), next_(NULL) { } 1117 : action_type_(action_type), reg_(reg), next_(NULL) { }
1160 DeferredAction* next() { return next_; } 1118 DeferredAction* next() { return next_; }
1161 bool Mentions(int reg); 1119 bool Mentions(intptr_t reg);
1162 int reg() { return reg_; } 1120 intptr_t reg() { return reg_; }
1163 ActionNode::ActionType action_type() { return action_type_; } 1121 ActionNode::ActionType action_type() { return action_type_; }
1164 private: 1122 private:
1165 ActionNode::ActionType action_type_; 1123 ActionNode::ActionType action_type_;
1166 int reg_; 1124 intptr_t reg_;
1167 DeferredAction* next_; 1125 DeferredAction* next_;
1168 friend class Trace; 1126 friend class Trace;
1127
1128 DISALLOW_ALLOCATION();
1169 }; 1129 };
1170 1130
1171 class DeferredCapture : public DeferredAction { 1131 class DeferredCapture : public DeferredAction {
1172 public: 1132 public:
1173 DeferredCapture(int reg, bool is_capture, Trace* trace) 1133 DeferredCapture(intptr_t reg, bool is_capture, Trace* trace)
1174 : DeferredAction(ActionNode::STORE_POSITION, reg), 1134 : DeferredAction(ActionNode::STORE_POSITION, reg),
1175 cp_offset_(trace->cp_offset()), 1135 cp_offset_(trace->cp_offset()),
1176 is_capture_(is_capture) { } 1136 is_capture_(is_capture) { }
1177 int cp_offset() { return cp_offset_; } 1137 intptr_t cp_offset() { return cp_offset_; }
1178 bool is_capture() { return is_capture_; } 1138 bool is_capture() { return is_capture_; }
1179 private: 1139 private:
1180 int cp_offset_; 1140 intptr_t cp_offset_;
1181 bool is_capture_; 1141 bool is_capture_;
1182 void set_cp_offset(int cp_offset) { cp_offset_ = cp_offset; } 1142 void set_cp_offset(intptr_t cp_offset) { cp_offset_ = cp_offset; }
1183 }; 1143 };
1184 1144
1185 class DeferredSetRegister : public DeferredAction { 1145 class DeferredSetRegister : public DeferredAction {
1186 public: 1146 public:
1187 DeferredSetRegister(int reg, int value) 1147 DeferredSetRegister(intptr_t reg, intptr_t value)
1188 : DeferredAction(ActionNode::SET_REGISTER, reg), 1148 : DeferredAction(ActionNode::SET_REGISTER, reg),
1189 value_(value) { } 1149 value_(value) { }
1190 int value() { return value_; } 1150 intptr_t value() { return value_; }
1191 private: 1151 private:
1192 int value_; 1152 intptr_t value_;
1193 }; 1153 };
1194 1154
1195 class DeferredClearCaptures : public DeferredAction { 1155 class DeferredClearCaptures : public DeferredAction {
1196 public: 1156 public:
1197 explicit DeferredClearCaptures(Interval range) 1157 explicit DeferredClearCaptures(Interval range)
1198 : DeferredAction(ActionNode::CLEAR_CAPTURES, -1), 1158 : DeferredAction(ActionNode::CLEAR_CAPTURES, -1),
1199 range_(range) { } 1159 range_(range) { }
1200 Interval range() { return range_; } 1160 Interval range() { return range_; }
1201 private: 1161 private:
1202 Interval range_; 1162 Interval range_;
1203 }; 1163 };
1204 1164
1205 class DeferredIncrementRegister : public DeferredAction { 1165 class DeferredIncrementRegister : public DeferredAction {
1206 public: 1166 public:
1207 explicit DeferredIncrementRegister(int reg) 1167 explicit DeferredIncrementRegister(intptr_t reg)
1208 : DeferredAction(ActionNode::INCREMENT_REGISTER, reg) { } 1168 : DeferredAction(ActionNode::INCREMENT_REGISTER, reg) { }
1209 }; 1169 };
1210 1170
1211 Trace() 1171 Trace()
1212 : cp_offset_(0), 1172 : cp_offset_(0),
1213 actions_(NULL), 1173 actions_(NULL),
1214 backtrack_(NULL), 1174 backtrack_(NULL),
1215 stop_node_(NULL), 1175 stop_node_(NULL),
1216 loop_label_(NULL), 1176 loop_label_(NULL),
1217 characters_preloaded_(0), 1177 characters_preloaded_(0),
1218 bound_checked_up_to_(0), 1178 bound_checked_up_to_(0),
1219 flush_budget_(100), 1179 flush_budget_(100),
1220 at_start_(UNKNOWN) { } 1180 at_start_(UNKNOWN) { }
1221 1181
1222 // End the trace. This involves flushing the deferred actions in the trace 1182 // End the trace. This involves flushing the deferred actions in the trace
1223 // and pushing a backtrack location onto the backtrack stack. Once this is 1183 // and pushing a backtrack location onto the backtrack stack. Once this is
1224 // done we can start a new trace or go to one that has already been 1184 // done we can start a new trace or go to one that has already been
1225 // generated. 1185 // generated.
1226 void Flush(RegExpCompiler* compiler, RegExpNode* successor); 1186 void Flush(RegExpCompiler* compiler, RegExpNode* successor);
1227 int cp_offset() { return cp_offset_; } 1187 intptr_t cp_offset() { return cp_offset_; }
1228 DeferredAction* actions() { return actions_; } 1188 DeferredAction* actions() { return actions_; }
1229 // A trivial trace is one that has no deferred actions or other state that 1189 // A trivial trace is one that has no deferred actions or other state that
1230 // affects the assumptions used when generating code. There is no recorded 1190 // affects the assumptions used when generating code. There is no recorded
1231 // backtrack location in a trivial trace, so with a trivial trace we will 1191 // backtrack location in a trivial trace, so with a trivial trace we will
1232 // generate code that, on a failure to match, gets the backtrack location 1192 // generate code that, on a failure to match, gets the backtrack location
1233 // from the backtrack stack rather than using a direct jump instruction. We 1193 // from the backtrack stack rather than using a direct jump instruction. We
1234 // always start code generation with a trivial trace and non-trivial traces 1194 // always start code generation with a trivial trace and non-trivial traces
1235 // are created as we emit code for nodes or add to the list of deferred 1195 // are created as we emit code for nodes or add to the list of deferred
1236 // actions in the trace. The location of the code generated for a node using 1196 // actions in the trace. The location of the code generated for a node using
1237 // a trivial trace is recorded in a label in the node so that gotos can be 1197 // a trivial trace is recorded in a label in the node so that gotos can be
1238 // generated to that code. 1198 // generated to that code.
1239 bool is_trivial() { 1199 bool is_trivial() {
1240 return backtrack_ == NULL && 1200 return backtrack_ == NULL &&
1241 actions_ == NULL && 1201 actions_ == NULL &&
1242 cp_offset_ == 0 && 1202 cp_offset_ == 0 &&
1243 characters_preloaded_ == 0 && 1203 characters_preloaded_ == 0 &&
1244 bound_checked_up_to_ == 0 && 1204 bound_checked_up_to_ == 0 &&
1245 quick_check_performed_.characters() == 0 && 1205 quick_check_performed_.characters() == 0 &&
1246 at_start_ == UNKNOWN; 1206 at_start_ == UNKNOWN;
1247 } 1207 }
1248 TriBool at_start() { return at_start_; } 1208 TriBool at_start() { return at_start_; }
1249 void set_at_start(bool at_start) { 1209 void set_at_start(bool at_start) {
1250 at_start_ = at_start ? TRUE_VALUE : FALSE_VALUE; 1210 at_start_ = at_start ? TRUE_VALUE : FALSE_VALUE;
1251 } 1211 }
1252 Label* backtrack() { return backtrack_; } 1212 BlockLabel* backtrack() { return backtrack_; }
1253 Label* loop_label() { return loop_label_; } 1213 BlockLabel* loop_label() { return loop_label_; }
1254 RegExpNode* stop_node() { return stop_node_; } 1214 RegExpNode* stop_node() { return stop_node_; }
1255 int characters_preloaded() { return characters_preloaded_; } 1215 intptr_t characters_preloaded() { return characters_preloaded_; }
1256 int bound_checked_up_to() { return bound_checked_up_to_; } 1216 intptr_t bound_checked_up_to() { return bound_checked_up_to_; }
1257 int flush_budget() { return flush_budget_; } 1217 intptr_t flush_budget() { return flush_budget_; }
1258 QuickCheckDetails* quick_check_performed() { return &quick_check_performed_; } 1218 QuickCheckDetails* quick_check_performed() { return &quick_check_performed_; }
1259 bool mentions_reg(int reg); 1219 bool mentions_reg(intptr_t reg);
1260 // Returns true if a deferred position store exists to the specified 1220 // Returns true if a deferred position store exists to the specified
1261 // register and stores the offset in the out-parameter. Otherwise 1221 // register and stores the offset in the out-parameter. Otherwise
1262 // returns false. 1222 // returns false.
1263 bool GetStoredPosition(int reg, int* cp_offset); 1223 bool GetStoredPosition(intptr_t reg, intptr_t* cp_offset);
1264 // These set methods and AdvanceCurrentPositionInTrace should be used only on 1224 // These set methods and AdvanceCurrentPositionInTrace should be used only on
1265 // new traces - the intention is that traces are immutable after creation. 1225 // new traces - the intention is that traces are immutable after creation.
1266 void add_action(DeferredAction* new_action) { 1226 void add_action(DeferredAction* new_action) {
1267 DCHECK(new_action->next_ == NULL); 1227 ASSERT(new_action->next_ == NULL);
1268 new_action->next_ = actions_; 1228 new_action->next_ = actions_;
1269 actions_ = new_action; 1229 actions_ = new_action;
1270 } 1230 }
1271 void set_backtrack(Label* backtrack) { backtrack_ = backtrack; } 1231 void set_backtrack(BlockLabel* backtrack) { backtrack_ = backtrack; }
1272 void set_stop_node(RegExpNode* node) { stop_node_ = node; } 1232 void set_stop_node(RegExpNode* node) { stop_node_ = node; }
1273 void set_loop_label(Label* label) { loop_label_ = label; } 1233 void set_loop_label(BlockLabel* label) { loop_label_ = label; }
1274 void set_characters_preloaded(int count) { characters_preloaded_ = count; } 1234 void set_characters_preloaded(intptr_t count) {
1275 void set_bound_checked_up_to(int to) { bound_checked_up_to_ = to; } 1235 characters_preloaded_ = count;
1276 void set_flush_budget(int to) { flush_budget_ = to; } 1236 }
1237 void set_bound_checked_up_to(intptr_t to) { bound_checked_up_to_ = to; }
1238 void set_flush_budget(intptr_t to) { flush_budget_ = to; }
1277 void set_quick_check_performed(QuickCheckDetails* d) { 1239 void set_quick_check_performed(QuickCheckDetails* d) {
1278 quick_check_performed_ = *d; 1240 quick_check_performed_ = *d;
1279 } 1241 }
1280 void InvalidateCurrentCharacter(); 1242 void InvalidateCurrentCharacter();
1281 void AdvanceCurrentPositionInTrace(int by, RegExpCompiler* compiler); 1243 void AdvanceCurrentPositionInTrace(intptr_t by, RegExpCompiler* compiler);
1282 1244
1283 private: 1245 private:
1284 int FindAffectedRegisters(OutSet* affected_registers, Zone* zone); 1246 intptr_t FindAffectedRegisters(OutSet* affected_registers, Isolate* isolate);
1285 void PerformDeferredActions(RegExpMacroAssembler* macro, 1247 void PerformDeferredActions(RegExpMacroAssembler* macro,
1286 int max_register, 1248 intptr_t max_register,
1287 const OutSet& affected_registers, 1249 const OutSet& affected_registers,
1288 OutSet* registers_to_pop, 1250 OutSet* registers_to_pop,
1289 OutSet* registers_to_clear, 1251 OutSet* registers_to_clear,
1290 Zone* zone); 1252 Isolate* isolate);
1291 void RestoreAffectedRegisters(RegExpMacroAssembler* macro, 1253 void RestoreAffectedRegisters(RegExpMacroAssembler* macro,
1292 int max_register, 1254 intptr_t max_register,
1293 const OutSet& registers_to_pop, 1255 const OutSet& registers_to_pop,
1294 const OutSet& registers_to_clear); 1256 const OutSet& registers_to_clear);
1295 int cp_offset_; 1257 intptr_t cp_offset_;
1296 DeferredAction* actions_; 1258 DeferredAction* actions_;
1297 Label* backtrack_; 1259 BlockLabel* backtrack_;
1298 RegExpNode* stop_node_; 1260 RegExpNode* stop_node_;
1299 Label* loop_label_; 1261 BlockLabel* loop_label_;
1300 int characters_preloaded_; 1262 intptr_t characters_preloaded_;
1301 int bound_checked_up_to_; 1263 intptr_t bound_checked_up_to_;
1302 QuickCheckDetails quick_check_performed_; 1264 QuickCheckDetails quick_check_performed_;
1303 int flush_budget_; 1265 intptr_t flush_budget_;
1304 TriBool at_start_; 1266 TriBool at_start_;
1267
1268 DISALLOW_ALLOCATION();
1305 }; 1269 };
1306 1270
1307 1271
1308 class GreedyLoopState { 1272 class GreedyLoopState {
1309 public: 1273 public:
1310 explicit GreedyLoopState(bool not_at_start); 1274 explicit GreedyLoopState(bool not_at_start);
1311 1275
1312 Label* label() { return &label_; } 1276 BlockLabel* label() { return &label_; }
1313 Trace* counter_backtrack_trace() { return &counter_backtrack_trace_; } 1277 Trace* counter_backtrack_trace() { return &counter_backtrack_trace_; }
1314 1278
1315 private: 1279 private:
1316 Label label_; 1280 BlockLabel label_;
1317 Trace counter_backtrack_trace_; 1281 Trace counter_backtrack_trace_;
1318 }; 1282 };
1319 1283
1320 1284
1321 struct PreloadState { 1285 struct PreloadState {
1322 static const int kEatsAtLeastNotYetInitialized = -1; 1286 static const intptr_t kEatsAtLeastNotYetInitialized = -1;
1323 bool preload_is_current_; 1287 bool preload_is_current_;
1324 bool preload_has_checked_bounds_; 1288 bool preload_has_checked_bounds_;
1325 int preload_characters_; 1289 intptr_t preload_characters_;
1326 int eats_at_least_; 1290 intptr_t eats_at_least_;
1327 void init() { 1291 void init() {
1328 eats_at_least_ = kEatsAtLeastNotYetInitialized; 1292 eats_at_least_ = kEatsAtLeastNotYetInitialized;
1329 } 1293 }
1294
1295 DISALLOW_ALLOCATION();
1330 }; 1296 };
1331 1297
1332 1298
1333 class NodeVisitor { 1299 class NodeVisitor : public ValueObject {
1334 public: 1300 public:
1335 virtual ~NodeVisitor() { } 1301 virtual ~NodeVisitor() { }
1336 #define DECLARE_VISIT(Type) \ 1302 #define DECLARE_VISIT(Type) \
1337 virtual void Visit##Type(Type##Node* that) = 0; 1303 virtual void Visit##Type(Type##Node* that) = 0;
1338 FOR_EACH_NODE_TYPE(DECLARE_VISIT) 1304 FOR_EACH_NODE_TYPE(DECLARE_VISIT)
1339 #undef DECLARE_VISIT 1305 #undef DECLARE_VISIT
1340 virtual void VisitLoopChoice(LoopChoiceNode* that) { VisitChoice(that); } 1306 virtual void VisitLoopChoice(LoopChoiceNode* that) { VisitChoice(that); }
1341 }; 1307 };
1342 1308
1343 1309
1344 // Node visitor used to add the start set of the alternatives to the
1345 // dispatch table of a choice node.
1346 class DispatchTableConstructor: public NodeVisitor {
1347 public:
1348 DispatchTableConstructor(DispatchTable* table, bool ignore_case,
1349 Zone* zone)
1350 : table_(table),
1351 choice_index_(-1),
1352 ignore_case_(ignore_case),
1353 zone_(zone) { }
1354
1355 void BuildTable(ChoiceNode* node);
1356
1357 void AddRange(CharacterRange range) {
1358 table()->AddRange(range, choice_index_, zone_);
1359 }
1360
1361 void AddInverse(ZoneList<CharacterRange>* ranges);
1362
1363 #define DECLARE_VISIT(Type) \
1364 virtual void Visit##Type(Type##Node* that);
1365 FOR_EACH_NODE_TYPE(DECLARE_VISIT)
1366 #undef DECLARE_VISIT
1367
1368 DispatchTable* table() { return table_; }
1369 void set_choice_index(int value) { choice_index_ = value; }
1370
1371 protected:
1372 DispatchTable* table_;
1373 int choice_index_;
1374 bool ignore_case_;
1375 Zone* zone_;
1376 };
1377
1378
1379 // Assertion propagation moves information about assertions such as 1310 // Assertion propagation moves information about assertions such as
1380 // \b to the affected nodes. For instance, in /.\b./ information must 1311 // \b to the affected nodes. For instance, in /.\b./ information must
1381 // be propagated to the first '.' that whatever follows needs to know 1312 // be propagated to the first '.' that whatever follows needs to know
1382 // if it matched a word or a non-word, and to the second '.' that it 1313 // if it matched a word or a non-word, and to the second '.' that it
1383 // has to check if it succeeds a word or non-word. In this case the 1314 // has to check if it succeeds a word or non-word. In this case the
1384 // result will be something like: 1315 // result will be something like:
1385 // 1316 //
1386 // +-------+ +------------+ 1317 // +-------+ +------------+
1387 // | . | | . | 1318 // | . | | . |
1388 // +-------+ ---> +------------+ 1319 // +-------+ ---> +------------+
1389 // | word? | | check word | 1320 // | word? | | check word |
1390 // +-------+ +------------+ 1321 // +-------+ +------------+
1391 class Analysis: public NodeVisitor { 1322 class Analysis: public NodeVisitor {
1392 public: 1323 public:
1393 Analysis(bool ignore_case, bool is_one_byte) 1324 Analysis(bool ignore_case, bool is_one_byte)
1394 : ignore_case_(ignore_case), 1325 : ignore_case_(ignore_case),
1395 is_one_byte_(is_one_byte), 1326 is_one_byte_(is_one_byte),
1396 error_message_(NULL) {} 1327 error_message_(NULL) { }
1397 void EnsureAnalyzed(RegExpNode* node); 1328 void EnsureAnalyzed(RegExpNode* node);
1398 1329
1399 #define DECLARE_VISIT(Type) \ 1330 #define DECLARE_VISIT(Type) \
1400 virtual void Visit##Type(Type##Node* that); 1331 virtual void Visit##Type(Type##Node* that);
1401 FOR_EACH_NODE_TYPE(DECLARE_VISIT) 1332 FOR_EACH_NODE_TYPE(DECLARE_VISIT)
1402 #undef DECLARE_VISIT 1333 #undef DECLARE_VISIT
1403 virtual void VisitLoopChoice(LoopChoiceNode* that); 1334 virtual void VisitLoopChoice(LoopChoiceNode* that);
1404 1335
1405 bool has_failed() { return error_message_ != NULL; } 1336 bool has_failed() { return error_message_ != NULL; }
1406 const char* error_message() { 1337 const char* error_message() {
1407 DCHECK(error_message_ != NULL); 1338 ASSERT(error_message_ != NULL);
1408 return error_message_; 1339 return error_message_;
1409 } 1340 }
1410 void fail(const char* error_message) { 1341 void fail(const char* error_message) {
1411 error_message_ = error_message; 1342 error_message_ = error_message;
1412 } 1343 }
1413 1344
1414 private: 1345 private:
1415 bool ignore_case_; 1346 bool ignore_case_;
1416 bool is_one_byte_; 1347 bool is_one_byte_;
1417 const char* error_message_; 1348 const char* error_message_;
1418 1349
1419 DISALLOW_IMPLICIT_CONSTRUCTORS(Analysis); 1350 DISALLOW_IMPLICIT_CONSTRUCTORS(Analysis);
1420 }; 1351 };
1421 1352
1422 1353
1423 struct RegExpCompileData { 1354 struct RegExpCompileData : public ZoneAllocated {
1424 RegExpCompileData() 1355 RegExpCompileData()
1425 : tree(NULL), 1356 : tree(NULL),
1426 node(NULL), 1357 node(NULL),
1427 simple(true), 1358 simple(true),
1428 contains_anchor(false), 1359 contains_anchor(false),
1360 error(String::Handle(String::null())),
1429 capture_count(0) { } 1361 capture_count(0) { }
1430 RegExpTree* tree; 1362 RegExpTree* tree;
1431 RegExpNode* node; 1363 RegExpNode* node;
1432 bool simple; 1364 bool simple;
1433 bool contains_anchor; 1365 bool contains_anchor;
1434 Handle<String> error; 1366 String& error;
1435 int capture_count; 1367 intptr_t capture_count;
1436 }; 1368 };
1437 1369
1438 1370
1439 class RegExpEngine: public AllStatic { 1371 class RegExpEngine: public AllStatic {
1440 public: 1372 public:
1441 struct CompilationResult { 1373 struct CompilationResult {
1442 CompilationResult(Isolate* isolate, const char* error_message) 1374 explicit CompilationResult(const char* error_message)
1443 : error_message(error_message), 1375 : macro_assembler(NULL),
1444 code(isolate->heap()->the_hole_value()), 1376 graph_entry(NULL),
1445 num_registers(0) {} 1377 num_blocks(-1),
1446 CompilationResult(Object* code, int registers) 1378 num_stack_locals(-1),
1447 : error_message(NULL), 1379 error_message(error_message) {}
1448 code(code), 1380 CompilationResult(IRRegExpMacroAssembler* macro_assembler,
1449 num_registers(registers) {} 1381 GraphEntryInstr* graph_entry,
1382 intptr_t num_blocks,
1383 intptr_t num_stack_locals)
1384 : macro_assembler(macro_assembler),
1385 graph_entry(graph_entry),
1386 num_blocks(num_blocks),
1387 num_stack_locals(num_stack_locals),
1388 error_message(NULL) {}
1389
1390 IRRegExpMacroAssembler* macro_assembler;
1391 GraphEntryInstr* graph_entry;
1392 const intptr_t num_blocks;
1393 const intptr_t num_stack_locals;
1394
1450 const char* error_message; 1395 const char* error_message;
1451 Object* code;
1452 int num_registers;
1453 }; 1396 };
1454 1397
1455 static CompilationResult Compile(RegExpCompileData* input, bool ignore_case, 1398 static CompilationResult Compile(
1456 bool global, bool multiline, bool sticky, 1399 RegExpCompileData* input,
1457 Handle<String> pattern, 1400 const ParsedFunction* parsed_function,
1458 Handle<String> sample_subject, 1401 const ZoneGrowableArray<const ICData*>& ic_data_array);
1459 bool is_one_byte, Zone* zone); 1402
1403 static RawJSRegExp* CreateJSRegExp(
1404 Isolate* isolate,
1405 const String& pattern,
1406 bool multi_line,
1407 bool ignore_case);
1460 1408
1461 static void DotPrint(const char* label, RegExpNode* node, bool ignore_case); 1409 static void DotPrint(const char* label, RegExpNode* node, bool ignore_case);
1462 }; 1410 };
1463 1411
1464 } // namespace dart 1412 } // namespace dart
1465 1413
1466 #endif // VM_REGEXP_H_ 1414 #endif // VM_REGEXP_H_
OLDNEW
« no previous file with comments | « runtime/vm/raw_object_snapshot.cc ('k') | runtime/vm/regexp.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698