OLD | NEW |
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 RUNTIME_VM_REGEXP_AST_H_ | 5 #ifndef RUNTIME_VM_REGEXP_AST_H_ |
6 #define RUNTIME_VM_REGEXP_AST_H_ | 6 #define RUNTIME_VM_REGEXP_AST_H_ |
7 | 7 |
8 #include "platform/globals.h" | 8 #include "platform/globals.h" |
9 #include "platform/utils.h" | 9 #include "platform/utils.h" |
10 #include "vm/allocation.h" | 10 #include "vm/allocation.h" |
(...skipping 10 matching lines...) Expand all Loading... |
21 class RegExpCompiler; | 21 class RegExpCompiler; |
22 class RegExpDisjunction; | 22 class RegExpDisjunction; |
23 class RegExpEmpty; | 23 class RegExpEmpty; |
24 class RegExpLookahead; | 24 class RegExpLookahead; |
25 class RegExpQuantifier; | 25 class RegExpQuantifier; |
26 class RegExpText; | 26 class RegExpText; |
27 | 27 |
28 | 28 |
29 class RegExpVisitor : public ValueObject { | 29 class RegExpVisitor : public ValueObject { |
30 public: | 30 public: |
31 virtual ~RegExpVisitor() { } | 31 virtual ~RegExpVisitor() {} |
32 #define MAKE_CASE(Name) \ | 32 #define MAKE_CASE(Name) \ |
33 virtual void* Visit##Name(RegExp##Name*, void* data) = 0; | 33 virtual void* Visit##Name(RegExp##Name*, void* data) = 0; |
34 FOR_EACH_REG_EXP_TREE_TYPE(MAKE_CASE) | 34 FOR_EACH_REG_EXP_TREE_TYPE(MAKE_CASE) |
35 #undef MAKE_CASE | 35 #undef MAKE_CASE |
36 }; | 36 }; |
37 | 37 |
38 | 38 |
39 class RegExpTree : public ZoneAllocated { | 39 class RegExpTree : public ZoneAllocated { |
40 public: | 40 public: |
41 static const intptr_t kInfinity = kMaxInt32; | 41 static const intptr_t kInfinity = kMaxInt32; |
42 virtual ~RegExpTree() {} | 42 virtual ~RegExpTree() {} |
43 virtual void* Accept(RegExpVisitor* visitor, void* data) = 0; | 43 virtual void* Accept(RegExpVisitor* visitor, void* data) = 0; |
44 virtual RegExpNode* ToNode(RegExpCompiler* compiler, | 44 virtual RegExpNode* ToNode(RegExpCompiler* compiler, |
45 RegExpNode* on_success) = 0; | 45 RegExpNode* on_success) = 0; |
46 virtual bool IsTextElement() const { return false; } | 46 virtual bool IsTextElement() const { return false; } |
47 virtual bool IsAnchoredAtStart() const { return false; } | 47 virtual bool IsAnchoredAtStart() const { return false; } |
48 virtual bool IsAnchoredAtEnd() const { return false; } | 48 virtual bool IsAnchoredAtEnd() const { return false; } |
49 virtual intptr_t min_match() const = 0; | 49 virtual intptr_t min_match() const = 0; |
50 virtual intptr_t max_match() const = 0; | 50 virtual intptr_t max_match() const = 0; |
51 // Returns the interval of registers used for captures within this | 51 // Returns the interval of registers used for captures within this |
52 // expression. | 52 // expression. |
53 virtual Interval CaptureRegisters() const { return Interval::Empty(); } | 53 virtual Interval CaptureRegisters() const { return Interval::Empty(); } |
54 virtual void AppendToText(RegExpText* text); | 54 virtual void AppendToText(RegExpText* text); |
55 void Print(); | 55 void Print(); |
56 #define MAKE_ASTYPE(Name) \ | 56 #define MAKE_ASTYPE(Name) \ |
57 virtual RegExp##Name* As##Name(); \ | 57 virtual RegExp##Name* As##Name(); \ |
58 virtual bool Is##Name() const; | 58 virtual bool Is##Name() const; |
59 FOR_EACH_REG_EXP_TREE_TYPE(MAKE_ASTYPE) | 59 FOR_EACH_REG_EXP_TREE_TYPE(MAKE_ASTYPE) |
60 #undef MAKE_ASTYPE | 60 #undef MAKE_ASTYPE |
61 }; | 61 }; |
62 | 62 |
63 | 63 |
64 class RegExpDisjunction : public RegExpTree { | 64 class RegExpDisjunction : public RegExpTree { |
65 public: | 65 public: |
66 explicit RegExpDisjunction(ZoneGrowableArray<RegExpTree*>* alternatives); | 66 explicit RegExpDisjunction(ZoneGrowableArray<RegExpTree*>* alternatives); |
67 virtual void* Accept(RegExpVisitor* visitor, void* data); | 67 virtual void* Accept(RegExpVisitor* visitor, void* data); |
68 virtual RegExpNode* ToNode(RegExpCompiler* compiler, | 68 virtual RegExpNode* ToNode(RegExpCompiler* compiler, RegExpNode* on_success); |
69 RegExpNode* on_success); | |
70 virtual RegExpDisjunction* AsDisjunction(); | 69 virtual RegExpDisjunction* AsDisjunction(); |
71 virtual Interval CaptureRegisters() const; | 70 virtual Interval CaptureRegisters() const; |
72 virtual bool IsDisjunction() const; | 71 virtual bool IsDisjunction() const; |
73 virtual bool IsAnchoredAtStart() const; | 72 virtual bool IsAnchoredAtStart() const; |
74 virtual bool IsAnchoredAtEnd() const; | 73 virtual bool IsAnchoredAtEnd() const; |
75 virtual intptr_t min_match() const { return min_match_; } | 74 virtual intptr_t min_match() const { return min_match_; } |
76 virtual intptr_t max_match() const { return max_match_; } | 75 virtual intptr_t max_match() const { return max_match_; } |
77 ZoneGrowableArray<RegExpTree*>* alternatives() const { return alternatives_; } | 76 ZoneGrowableArray<RegExpTree*>* alternatives() const { return alternatives_; } |
| 77 |
78 private: | 78 private: |
79 ZoneGrowableArray<RegExpTree*>* alternatives_; | 79 ZoneGrowableArray<RegExpTree*>* alternatives_; |
80 intptr_t min_match_; | 80 intptr_t min_match_; |
81 intptr_t max_match_; | 81 intptr_t max_match_; |
82 }; | 82 }; |
83 | 83 |
84 | 84 |
85 class RegExpAlternative : public RegExpTree { | 85 class RegExpAlternative : public RegExpTree { |
86 public: | 86 public: |
87 explicit RegExpAlternative(ZoneGrowableArray<RegExpTree*>* nodes); | 87 explicit RegExpAlternative(ZoneGrowableArray<RegExpTree*>* nodes); |
88 virtual void* Accept(RegExpVisitor* visitor, void* data); | 88 virtual void* Accept(RegExpVisitor* visitor, void* data); |
89 virtual RegExpNode* ToNode(RegExpCompiler* compiler, | 89 virtual RegExpNode* ToNode(RegExpCompiler* compiler, RegExpNode* on_success); |
90 RegExpNode* on_success); | |
91 virtual RegExpAlternative* AsAlternative(); | 90 virtual RegExpAlternative* AsAlternative(); |
92 virtual Interval CaptureRegisters() const; | 91 virtual Interval CaptureRegisters() const; |
93 virtual bool IsAlternative() const; | 92 virtual bool IsAlternative() const; |
94 virtual bool IsAnchoredAtStart() const; | 93 virtual bool IsAnchoredAtStart() const; |
95 virtual bool IsAnchoredAtEnd() const; | 94 virtual bool IsAnchoredAtEnd() const; |
96 virtual intptr_t min_match() const { return min_match_; } | 95 virtual intptr_t min_match() const { return min_match_; } |
97 virtual intptr_t max_match() const { return max_match_; } | 96 virtual intptr_t max_match() const { return max_match_; } |
98 ZoneGrowableArray<RegExpTree*>* nodes() const { return nodes_; } | 97 ZoneGrowableArray<RegExpTree*>* nodes() const { return nodes_; } |
| 98 |
99 private: | 99 private: |
100 ZoneGrowableArray<RegExpTree*>* nodes_; | 100 ZoneGrowableArray<RegExpTree*>* nodes_; |
101 intptr_t min_match_; | 101 intptr_t min_match_; |
102 intptr_t max_match_; | 102 intptr_t max_match_; |
103 }; | 103 }; |
104 | 104 |
105 | 105 |
106 class RegExpAssertion : public RegExpTree { | 106 class RegExpAssertion : public RegExpTree { |
107 public: | 107 public: |
108 enum AssertionType { | 108 enum AssertionType { |
109 START_OF_LINE, | 109 START_OF_LINE, |
110 START_OF_INPUT, | 110 START_OF_INPUT, |
111 END_OF_LINE, | 111 END_OF_LINE, |
112 END_OF_INPUT, | 112 END_OF_INPUT, |
113 BOUNDARY, | 113 BOUNDARY, |
114 NON_BOUNDARY | 114 NON_BOUNDARY |
115 }; | 115 }; |
116 explicit RegExpAssertion(AssertionType type) : assertion_type_(type) { } | 116 explicit RegExpAssertion(AssertionType type) : assertion_type_(type) {} |
117 virtual void* Accept(RegExpVisitor* visitor, void* data); | 117 virtual void* Accept(RegExpVisitor* visitor, void* data); |
118 virtual RegExpNode* ToNode(RegExpCompiler* compiler, | 118 virtual RegExpNode* ToNode(RegExpCompiler* compiler, RegExpNode* on_success); |
119 RegExpNode* on_success); | |
120 virtual RegExpAssertion* AsAssertion(); | 119 virtual RegExpAssertion* AsAssertion(); |
121 virtual bool IsAssertion() const; | 120 virtual bool IsAssertion() const; |
122 virtual bool IsAnchoredAtStart() const; | 121 virtual bool IsAnchoredAtStart() const; |
123 virtual bool IsAnchoredAtEnd() const; | 122 virtual bool IsAnchoredAtEnd() const; |
124 virtual intptr_t min_match() const { return 0; } | 123 virtual intptr_t min_match() const { return 0; } |
125 virtual intptr_t max_match() const { return 0; } | 124 virtual intptr_t max_match() const { return 0; } |
126 AssertionType assertion_type() const { return assertion_type_; } | 125 AssertionType assertion_type() const { return assertion_type_; } |
| 126 |
127 private: | 127 private: |
128 AssertionType assertion_type_; | 128 AssertionType assertion_type_; |
129 }; | 129 }; |
130 | 130 |
131 | 131 |
132 class CharacterSet : public ValueObject { | 132 class CharacterSet : public ValueObject { |
133 public: | 133 public: |
134 explicit CharacterSet(uint16_t standard_set_type) | 134 explicit CharacterSet(uint16_t standard_set_type) |
135 : ranges_(NULL), | 135 : ranges_(NULL), standard_set_type_(standard_set_type) {} |
136 standard_set_type_(standard_set_type) {} | |
137 explicit CharacterSet(ZoneGrowableArray<CharacterRange>* ranges) | 136 explicit CharacterSet(ZoneGrowableArray<CharacterRange>* ranges) |
138 : ranges_(ranges), | 137 : ranges_(ranges), standard_set_type_(0) {} |
139 standard_set_type_(0) {} | |
140 CharacterSet(const CharacterSet& that) | 138 CharacterSet(const CharacterSet& that) |
141 : ValueObject(), | 139 : ValueObject(), |
142 ranges_(that.ranges_), | 140 ranges_(that.ranges_), |
143 standard_set_type_(that.standard_set_type_) {} | 141 standard_set_type_(that.standard_set_type_) {} |
144 ZoneGrowableArray<CharacterRange>* ranges(); | 142 ZoneGrowableArray<CharacterRange>* ranges(); |
145 uint16_t standard_set_type() const { return standard_set_type_; } | 143 uint16_t standard_set_type() const { return standard_set_type_; } |
146 void set_standard_set_type(uint16_t special_set_type) { | 144 void set_standard_set_type(uint16_t special_set_type) { |
147 standard_set_type_ = special_set_type; | 145 standard_set_type_ = special_set_type; |
148 } | 146 } |
149 bool is_standard() { return standard_set_type_ != 0; } | 147 bool is_standard() { return standard_set_type_ != 0; } |
150 void Canonicalize(); | 148 void Canonicalize(); |
| 149 |
151 private: | 150 private: |
152 ZoneGrowableArray<CharacterRange>* ranges_; | 151 ZoneGrowableArray<CharacterRange>* ranges_; |
153 // If non-zero, the value represents a standard set (e.g., all whitespace | 152 // If non-zero, the value represents a standard set (e.g., all whitespace |
154 // characters) without having to expand the ranges. | 153 // characters) without having to expand the ranges. |
155 uint16_t standard_set_type_; | 154 uint16_t standard_set_type_; |
156 }; | 155 }; |
157 | 156 |
158 | 157 |
159 class RegExpCharacterClass : public RegExpTree { | 158 class RegExpCharacterClass : public RegExpTree { |
160 public: | 159 public: |
161 RegExpCharacterClass(ZoneGrowableArray<CharacterRange>* ranges, | 160 RegExpCharacterClass(ZoneGrowableArray<CharacterRange>* ranges, |
162 bool is_negated) | 161 bool is_negated) |
163 : set_(ranges), | 162 : set_(ranges), is_negated_(is_negated) {} |
164 is_negated_(is_negated) { } | |
165 explicit RegExpCharacterClass(uint16_t type) | 163 explicit RegExpCharacterClass(uint16_t type) |
166 : set_(type), | 164 : set_(type), is_negated_(false) {} |
167 is_negated_(false) { } | |
168 virtual void* Accept(RegExpVisitor* visitor, void* data); | 165 virtual void* Accept(RegExpVisitor* visitor, void* data); |
169 virtual RegExpNode* ToNode(RegExpCompiler* compiler, | 166 virtual RegExpNode* ToNode(RegExpCompiler* compiler, RegExpNode* on_success); |
170 RegExpNode* on_success); | |
171 virtual RegExpCharacterClass* AsCharacterClass(); | 167 virtual RegExpCharacterClass* AsCharacterClass(); |
172 virtual bool IsCharacterClass() const; | 168 virtual bool IsCharacterClass() const; |
173 virtual bool IsTextElement() const { return true; } | 169 virtual bool IsTextElement() const { return true; } |
174 virtual intptr_t min_match() const { return 1; } | 170 virtual intptr_t min_match() const { return 1; } |
175 virtual intptr_t max_match() const { return 1; } | 171 virtual intptr_t max_match() const { return 1; } |
176 virtual void AppendToText(RegExpText* text); | 172 virtual void AppendToText(RegExpText* text); |
177 CharacterSet character_set() const { return set_; } | 173 CharacterSet character_set() const { return set_; } |
178 // TODO(lrn): Remove need for complex version if is_standard that | 174 // TODO(lrn): Remove need for complex version if is_standard that |
179 // recognizes a mangled standard set and just do { return set_.is_special(); } | 175 // recognizes a mangled standard set and just do { return set_.is_special(); } |
180 bool is_standard(); | 176 bool is_standard(); |
181 // Returns a value representing the standard character set if is_standard() | 177 // Returns a value representing the standard character set if is_standard() |
182 // returns true. | 178 // returns true. |
183 // Currently used values are: | 179 // Currently used values are: |
184 // s : unicode whitespace | 180 // s : unicode whitespace |
185 // S : unicode non-whitespace | 181 // S : unicode non-whitespace |
186 // w : ASCII word character (digit, letter, underscore) | 182 // w : ASCII word character (digit, letter, underscore) |
187 // W : non-ASCII word character | 183 // W : non-ASCII word character |
188 // d : ASCII digit | 184 // d : ASCII digit |
189 // D : non-ASCII digit | 185 // D : non-ASCII digit |
190 // . : non-unicode non-newline | 186 // . : non-unicode non-newline |
191 // * : All characters | 187 // * : All characters |
192 uint16_t standard_type() const { return set_.standard_set_type(); } | 188 uint16_t standard_type() const { return set_.standard_set_type(); } |
193 ZoneGrowableArray<CharacterRange>* ranges() { | 189 ZoneGrowableArray<CharacterRange>* ranges() { return set_.ranges(); } |
194 return set_.ranges(); | |
195 } | |
196 bool is_negated() const { return is_negated_; } | 190 bool is_negated() const { return is_negated_; } |
197 | 191 |
198 private: | 192 private: |
199 CharacterSet set_; | 193 CharacterSet set_; |
200 bool is_negated_; | 194 bool is_negated_; |
201 }; | 195 }; |
202 | 196 |
203 | 197 |
204 class RegExpAtom : public RegExpTree { | 198 class RegExpAtom : public RegExpTree { |
205 public: | 199 public: |
206 explicit RegExpAtom(ZoneGrowableArray<uint16_t>* data) : data_(data) { } | 200 explicit RegExpAtom(ZoneGrowableArray<uint16_t>* data) : data_(data) {} |
207 virtual void* Accept(RegExpVisitor* visitor, void* data); | 201 virtual void* Accept(RegExpVisitor* visitor, void* data); |
208 virtual RegExpNode* ToNode(RegExpCompiler* compiler, | 202 virtual RegExpNode* ToNode(RegExpCompiler* compiler, RegExpNode* on_success); |
209 RegExpNode* on_success); | |
210 virtual RegExpAtom* AsAtom(); | 203 virtual RegExpAtom* AsAtom(); |
211 virtual bool IsAtom() const; | 204 virtual bool IsAtom() const; |
212 virtual bool IsTextElement() const { return true; } | 205 virtual bool IsTextElement() const { return true; } |
213 virtual intptr_t min_match() const { return data_->length(); } | 206 virtual intptr_t min_match() const { return data_->length(); } |
214 virtual intptr_t max_match() const { return data_->length(); } | 207 virtual intptr_t max_match() const { return data_->length(); } |
215 virtual void AppendToText(RegExpText* text); | 208 virtual void AppendToText(RegExpText* text); |
216 ZoneGrowableArray<uint16_t>* data() const { return data_; } | 209 ZoneGrowableArray<uint16_t>* data() const { return data_; } |
217 intptr_t length() const { return data_->length(); } | 210 intptr_t length() const { return data_->length(); } |
| 211 |
218 private: | 212 private: |
219 ZoneGrowableArray<uint16_t>* data_; | 213 ZoneGrowableArray<uint16_t>* data_; |
220 }; | 214 }; |
221 | 215 |
222 | 216 |
223 class RegExpText : public RegExpTree { | 217 class RegExpText : public RegExpTree { |
224 public: | 218 public: |
225 RegExpText() : elements_(2), length_(0) {} | 219 RegExpText() : elements_(2), length_(0) {} |
226 virtual void* Accept(RegExpVisitor* visitor, void* data); | 220 virtual void* Accept(RegExpVisitor* visitor, void* data); |
227 virtual RegExpNode* ToNode(RegExpCompiler* compiler, | 221 virtual RegExpNode* ToNode(RegExpCompiler* compiler, RegExpNode* on_success); |
228 RegExpNode* on_success); | |
229 virtual RegExpText* AsText(); | 222 virtual RegExpText* AsText(); |
230 virtual bool IsText() const; | 223 virtual bool IsText() const; |
231 virtual bool IsTextElement() const { return true; } | 224 virtual bool IsTextElement() const { return true; } |
232 virtual intptr_t min_match() const { return length_; } | 225 virtual intptr_t min_match() const { return length_; } |
233 virtual intptr_t max_match() const { return length_; } | 226 virtual intptr_t max_match() const { return length_; } |
234 virtual void AppendToText(RegExpText* text); | 227 virtual void AppendToText(RegExpText* text); |
235 void AddElement(TextElement elm) { | 228 void AddElement(TextElement elm) { |
236 elements_.Add(elm); | 229 elements_.Add(elm); |
237 length_ += elm.length(); | 230 length_ += elm.length(); |
238 } | 231 } |
239 GrowableArray<TextElement>* elements() { return &elements_; } | 232 GrowableArray<TextElement>* elements() { return &elements_; } |
| 233 |
240 private: | 234 private: |
241 GrowableArray<TextElement> elements_; | 235 GrowableArray<TextElement> elements_; |
242 intptr_t length_; | 236 intptr_t length_; |
243 }; | 237 }; |
244 | 238 |
245 | 239 |
246 class RegExpQuantifier : public RegExpTree { | 240 class RegExpQuantifier : public RegExpTree { |
247 public: | 241 public: |
248 enum QuantifierType { GREEDY, NON_GREEDY, POSSESSIVE }; | 242 enum QuantifierType { GREEDY, NON_GREEDY, POSSESSIVE }; |
249 RegExpQuantifier(intptr_t min, intptr_t max, | 243 RegExpQuantifier(intptr_t min, |
250 QuantifierType type, RegExpTree* body) | 244 intptr_t max, |
| 245 QuantifierType type, |
| 246 RegExpTree* body) |
251 : body_(body), | 247 : body_(body), |
252 min_(min), | 248 min_(min), |
253 max_(max), | 249 max_(max), |
254 min_match_(min * body->min_match()), | 250 min_match_(min * body->min_match()), |
255 quantifier_type_(type) { | 251 quantifier_type_(type) { |
256 if (max > 0 && body->max_match() > kInfinity / max) { | 252 if (max > 0 && body->max_match() > kInfinity / max) { |
257 max_match_ = kInfinity; | 253 max_match_ = kInfinity; |
258 } else { | 254 } else { |
259 max_match_ = max * body->max_match(); | 255 max_match_ = max * body->max_match(); |
260 } | 256 } |
261 } | 257 } |
262 virtual void* Accept(RegExpVisitor* visitor, void* data); | 258 virtual void* Accept(RegExpVisitor* visitor, void* data); |
263 virtual RegExpNode* ToNode(RegExpCompiler* compiler, | 259 virtual RegExpNode* ToNode(RegExpCompiler* compiler, RegExpNode* on_success); |
264 RegExpNode* on_success); | |
265 static RegExpNode* ToNode(intptr_t min, | 260 static RegExpNode* ToNode(intptr_t min, |
266 intptr_t max, | 261 intptr_t max, |
267 bool is_greedy, | 262 bool is_greedy, |
268 RegExpTree* body, | 263 RegExpTree* body, |
269 RegExpCompiler* compiler, | 264 RegExpCompiler* compiler, |
270 RegExpNode* on_success, | 265 RegExpNode* on_success, |
271 bool not_at_start = false); | 266 bool not_at_start = false); |
272 virtual RegExpQuantifier* AsQuantifier(); | 267 virtual RegExpQuantifier* AsQuantifier(); |
273 virtual Interval CaptureRegisters() const; | 268 virtual Interval CaptureRegisters() const; |
274 virtual bool IsQuantifier() const; | 269 virtual bool IsQuantifier() const; |
(...skipping 12 matching lines...) Expand all Loading... |
287 intptr_t max_; | 282 intptr_t max_; |
288 intptr_t min_match_; | 283 intptr_t min_match_; |
289 intptr_t max_match_; | 284 intptr_t max_match_; |
290 QuantifierType quantifier_type_; | 285 QuantifierType quantifier_type_; |
291 }; | 286 }; |
292 | 287 |
293 | 288 |
294 class RegExpCapture : public RegExpTree { | 289 class RegExpCapture : public RegExpTree { |
295 public: | 290 public: |
296 explicit RegExpCapture(RegExpTree* body, intptr_t index) | 291 explicit RegExpCapture(RegExpTree* body, intptr_t index) |
297 : body_(body), index_(index) { } | 292 : body_(body), index_(index) {} |
298 virtual void* Accept(RegExpVisitor* visitor, void* data); | 293 virtual void* Accept(RegExpVisitor* visitor, void* data); |
299 virtual RegExpNode* ToNode(RegExpCompiler* compiler, | 294 virtual RegExpNode* ToNode(RegExpCompiler* compiler, RegExpNode* on_success); |
300 RegExpNode* on_success); | |
301 static RegExpNode* ToNode(RegExpTree* body, | 295 static RegExpNode* ToNode(RegExpTree* body, |
302 intptr_t index, | 296 intptr_t index, |
303 RegExpCompiler* compiler, | 297 RegExpCompiler* compiler, |
304 RegExpNode* on_success); | 298 RegExpNode* on_success); |
305 virtual RegExpCapture* AsCapture(); | 299 virtual RegExpCapture* AsCapture(); |
306 virtual bool IsAnchoredAtStart() const; | 300 virtual bool IsAnchoredAtStart() const; |
307 virtual bool IsAnchoredAtEnd() const; | 301 virtual bool IsAnchoredAtEnd() const; |
308 virtual Interval CaptureRegisters() const; | 302 virtual Interval CaptureRegisters() const; |
309 virtual bool IsCapture() const; | 303 virtual bool IsCapture() const; |
310 virtual intptr_t min_match() const { return body_->min_match(); } | 304 virtual intptr_t min_match() const { return body_->min_match(); } |
(...skipping 11 matching lines...) Expand all Loading... |
322 | 316 |
323 class RegExpLookahead : public RegExpTree { | 317 class RegExpLookahead : public RegExpTree { |
324 public: | 318 public: |
325 RegExpLookahead(RegExpTree* body, | 319 RegExpLookahead(RegExpTree* body, |
326 bool is_positive, | 320 bool is_positive, |
327 intptr_t capture_count, | 321 intptr_t capture_count, |
328 intptr_t capture_from) | 322 intptr_t capture_from) |
329 : body_(body), | 323 : body_(body), |
330 is_positive_(is_positive), | 324 is_positive_(is_positive), |
331 capture_count_(capture_count), | 325 capture_count_(capture_count), |
332 capture_from_(capture_from) { } | 326 capture_from_(capture_from) {} |
333 | 327 |
334 virtual void* Accept(RegExpVisitor* visitor, void* data); | 328 virtual void* Accept(RegExpVisitor* visitor, void* data); |
335 virtual RegExpNode* ToNode(RegExpCompiler* compiler, | 329 virtual RegExpNode* ToNode(RegExpCompiler* compiler, RegExpNode* on_success); |
336 RegExpNode* on_success); | |
337 virtual RegExpLookahead* AsLookahead(); | 330 virtual RegExpLookahead* AsLookahead(); |
338 virtual Interval CaptureRegisters() const; | 331 virtual Interval CaptureRegisters() const; |
339 virtual bool IsLookahead() const; | 332 virtual bool IsLookahead() const; |
340 virtual bool IsAnchoredAtStart() const; | 333 virtual bool IsAnchoredAtStart() const; |
341 virtual intptr_t min_match() const { return 0; } | 334 virtual intptr_t min_match() const { return 0; } |
342 virtual intptr_t max_match() const { return 0; } | 335 virtual intptr_t max_match() const { return 0; } |
343 RegExpTree* body() const { return body_; } | 336 RegExpTree* body() const { return body_; } |
344 bool is_positive() const { return is_positive_; } | 337 bool is_positive() const { return is_positive_; } |
345 intptr_t capture_count() const { return capture_count_; } | 338 intptr_t capture_count() const { return capture_count_; } |
346 intptr_t capture_from() const { return capture_from_; } | 339 intptr_t capture_from() const { return capture_from_; } |
347 | 340 |
348 private: | 341 private: |
349 RegExpTree* body_; | 342 RegExpTree* body_; |
350 bool is_positive_; | 343 bool is_positive_; |
351 intptr_t capture_count_; | 344 intptr_t capture_count_; |
352 intptr_t capture_from_; | 345 intptr_t capture_from_; |
353 }; | 346 }; |
354 | 347 |
355 | 348 |
356 class RegExpBackReference : public RegExpTree { | 349 class RegExpBackReference : public RegExpTree { |
357 public: | 350 public: |
358 explicit RegExpBackReference(RegExpCapture* capture) | 351 explicit RegExpBackReference(RegExpCapture* capture) : capture_(capture) {} |
359 : capture_(capture) { } | |
360 virtual void* Accept(RegExpVisitor* visitor, void* data); | 352 virtual void* Accept(RegExpVisitor* visitor, void* data); |
361 virtual RegExpNode* ToNode(RegExpCompiler* compiler, | 353 virtual RegExpNode* ToNode(RegExpCompiler* compiler, RegExpNode* on_success); |
362 RegExpNode* on_success); | |
363 virtual RegExpBackReference* AsBackReference(); | 354 virtual RegExpBackReference* AsBackReference(); |
364 virtual bool IsBackReference() const; | 355 virtual bool IsBackReference() const; |
365 virtual intptr_t min_match() const { return 0; } | 356 virtual intptr_t min_match() const { return 0; } |
366 virtual intptr_t max_match() const { return capture_->max_match(); } | 357 virtual intptr_t max_match() const { return capture_->max_match(); } |
367 intptr_t index() const { return capture_->index(); } | 358 intptr_t index() const { return capture_->index(); } |
368 RegExpCapture* capture() const { return capture_; } | 359 RegExpCapture* capture() const { return capture_; } |
| 360 |
369 private: | 361 private: |
370 RegExpCapture* capture_; | 362 RegExpCapture* capture_; |
371 }; | 363 }; |
372 | 364 |
373 | 365 |
374 class RegExpEmpty : public RegExpTree { | 366 class RegExpEmpty : public RegExpTree { |
375 public: | 367 public: |
376 RegExpEmpty() { } | 368 RegExpEmpty() {} |
377 virtual void* Accept(RegExpVisitor* visitor, void* data); | 369 virtual void* Accept(RegExpVisitor* visitor, void* data); |
378 virtual RegExpNode* ToNode(RegExpCompiler* compiler, | 370 virtual RegExpNode* ToNode(RegExpCompiler* compiler, RegExpNode* on_success); |
379 RegExpNode* on_success); | |
380 virtual RegExpEmpty* AsEmpty(); | 371 virtual RegExpEmpty* AsEmpty(); |
381 virtual bool IsEmpty() const; | 372 virtual bool IsEmpty() const; |
382 virtual intptr_t min_match() const { return 0; } | 373 virtual intptr_t min_match() const { return 0; } |
383 virtual intptr_t max_match() const { return 0; } | 374 virtual intptr_t max_match() const { return 0; } |
384 static RegExpEmpty* GetInstance() { | 375 static RegExpEmpty* GetInstance() { |
385 static RegExpEmpty* instance = ::new RegExpEmpty(); | 376 static RegExpEmpty* instance = ::new RegExpEmpty(); |
386 return instance; | 377 return instance; |
387 } | 378 } |
388 }; | 379 }; |
389 | 380 |
390 } // namespace dart | 381 } // namespace dart |
391 | 382 |
392 #endif // RUNTIME_VM_REGEXP_AST_H_ | 383 #endif // RUNTIME_VM_REGEXP_AST_H_ |
OLD | NEW |