OLD | NEW |
1 // Copyright 2006-2009 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2009 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 15 matching lines...) Expand all Loading... |
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
27 | 27 |
28 #include "v8.h" | 28 #include "v8.h" |
29 | 29 |
30 #include "ast.h" | 30 #include "ast.h" |
31 #include "compiler.h" | 31 #include "compiler.h" |
32 #include "execution.h" | 32 #include "execution.h" |
33 #include "factory.h" | 33 #include "factory.h" |
34 #include "jsregexp.h" | 34 #include "jsregexp.h" |
35 #include "platform.h" | 35 #include "platform.h" |
| 36 #include "string-search.h" |
36 #include "runtime.h" | 37 #include "runtime.h" |
37 #include "top.h" | 38 #include "top.h" |
38 #include "compilation-cache.h" | 39 #include "compilation-cache.h" |
39 #include "string-stream.h" | 40 #include "string-stream.h" |
40 #include "parser.h" | 41 #include "parser.h" |
41 #include "regexp-macro-assembler.h" | 42 #include "regexp-macro-assembler.h" |
42 #include "regexp-macro-assembler-tracer.h" | 43 #include "regexp-macro-assembler-tracer.h" |
43 #include "regexp-macro-assembler-irregexp.h" | 44 #include "regexp-macro-assembler-irregexp.h" |
44 #include "regexp-stack.h" | 45 #include "regexp-stack.h" |
45 | 46 |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
113 JSRegExp::Flags flags = RegExpFlagsFromString(flag_str); | 114 JSRegExp::Flags flags = RegExpFlagsFromString(flag_str); |
114 Handle<FixedArray> cached = CompilationCache::LookupRegExp(pattern, flags); | 115 Handle<FixedArray> cached = CompilationCache::LookupRegExp(pattern, flags); |
115 bool in_cache = !cached.is_null(); | 116 bool in_cache = !cached.is_null(); |
116 LOG(RegExpCompileEvent(re, in_cache)); | 117 LOG(RegExpCompileEvent(re, in_cache)); |
117 | 118 |
118 Handle<Object> result; | 119 Handle<Object> result; |
119 if (in_cache) { | 120 if (in_cache) { |
120 re->set_data(*cached); | 121 re->set_data(*cached); |
121 return re; | 122 return re; |
122 } | 123 } |
123 FlattenString(pattern); | 124 pattern = FlattenGetString(pattern); |
124 CompilationZoneScope zone_scope(DELETE_ON_EXIT); | 125 CompilationZoneScope zone_scope(DELETE_ON_EXIT); |
125 PostponeInterruptsScope postpone; | 126 PostponeInterruptsScope postpone; |
126 RegExpCompileData parse_result; | 127 RegExpCompileData parse_result; |
127 FlatStringReader reader(pattern); | 128 FlatStringReader reader(pattern); |
128 if (!RegExpParser::ParseRegExp(&reader, flags.is_multiline(), | 129 if (!RegExpParser::ParseRegExp(&reader, flags.is_multiline(), |
129 &parse_result)) { | 130 &parse_result)) { |
130 // Throw an exception if we fail to parse the pattern. | 131 // Throw an exception if we fail to parse the pattern. |
131 ThrowRegExpException(re, | 132 ThrowRegExpException(re, |
132 pattern, | 133 pattern, |
133 parse_result.error, | 134 parse_result.error, |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
198 int from, | 199 int from, |
199 int to) { | 200 int to) { |
200 NoHandleAllocation no_handles; | 201 NoHandleAllocation no_handles; |
201 RegExpImpl::SetLastCaptureCount(array, 2); | 202 RegExpImpl::SetLastCaptureCount(array, 2); |
202 RegExpImpl::SetLastSubject(array, subject); | 203 RegExpImpl::SetLastSubject(array, subject); |
203 RegExpImpl::SetLastInput(array, subject); | 204 RegExpImpl::SetLastInput(array, subject); |
204 RegExpImpl::SetCapture(array, 0, from); | 205 RegExpImpl::SetCapture(array, 0, from); |
205 RegExpImpl::SetCapture(array, 1, to); | 206 RegExpImpl::SetCapture(array, 1, to); |
206 } | 207 } |
207 | 208 |
| 209 /* template <typename SubjectChar>, typename PatternChar> |
| 210 static int ReStringMatch(Vector<const SubjectChar> sub_vector, |
| 211 Vector<const PatternChar> pat_vector, |
| 212 int start_index) { |
208 | 213 |
| 214 int pattern_length = pat_vector.length(); |
| 215 if (pattern_length == 0) return start_index; |
| 216 |
| 217 int subject_length = sub_vector.length(); |
| 218 if (start_index + pattern_length > subject_length) return -1; |
| 219 return SearchString(sub_vector, pat_vector, start_index); |
| 220 } |
| 221 */ |
209 Handle<Object> RegExpImpl::AtomExec(Handle<JSRegExp> re, | 222 Handle<Object> RegExpImpl::AtomExec(Handle<JSRegExp> re, |
210 Handle<String> subject, | 223 Handle<String> subject, |
211 int index, | 224 int index, |
212 Handle<JSArray> last_match_info) { | 225 Handle<JSArray> last_match_info) { |
213 Handle<String> needle(String::cast(re->DataAt(JSRegExp::kAtomPatternIndex))); | 226 ASSERT(0 <= index); |
| 227 ASSERT(index <= subject->length()); |
214 | 228 |
215 uint32_t start_index = index; | 229 if (!subject->IsFlat()) FlattenString(subject); |
| 230 AssertNoAllocation no_heap_allocation; // ensure vectors stay valid |
| 231 // Extract flattened substrings of cons strings before determining asciiness. |
| 232 String* seq_sub = *subject; |
| 233 if (seq_sub->IsConsString()) seq_sub = ConsString::cast(seq_sub)->first(); |
216 | 234 |
217 int value = Runtime::StringMatch(subject, needle, start_index); | 235 String* needle = String::cast(re->DataAt(JSRegExp::kAtomPatternIndex)); |
218 if (value == -1) return Factory::null_value(); | 236 int needle_len = needle->length(); |
| 237 |
| 238 if (needle_len != 0) { |
| 239 if (index + needle_len > subject->length()) return Factory::null_value(); |
| 240 // dispatch on type of strings |
| 241 index = (needle->IsAsciiRepresentation() |
| 242 ? (seq_sub->IsAsciiRepresentation() |
| 243 ? SearchString(seq_sub->ToAsciiVector(), |
| 244 needle->ToAsciiVector(), |
| 245 index) |
| 246 : SearchString(seq_sub->ToUC16Vector(), |
| 247 needle->ToAsciiVector(), |
| 248 index)) |
| 249 : (seq_sub->IsAsciiRepresentation() |
| 250 ? SearchString(seq_sub->ToAsciiVector(), |
| 251 needle->ToUC16Vector(), |
| 252 index) |
| 253 : SearchString(seq_sub->ToUC16Vector(), |
| 254 needle->ToUC16Vector(), |
| 255 index))); |
| 256 if (index == -1) return Factory::null_value(); |
| 257 } |
219 ASSERT(last_match_info->HasFastElements()); | 258 ASSERT(last_match_info->HasFastElements()); |
220 | 259 |
221 { | 260 { |
222 NoHandleAllocation no_handles; | 261 NoHandleAllocation no_handles; |
223 FixedArray* array = FixedArray::cast(last_match_info->elements()); | 262 FixedArray* array = FixedArray::cast(last_match_info->elements()); |
224 SetAtomLastCapture(array, *subject, value, value + needle->length()); | 263 SetAtomLastCapture(array, *subject, index, index + needle_len); |
225 } | 264 } |
226 return last_match_info; | 265 return last_match_info; |
227 } | 266 } |
228 | 267 |
229 | 268 |
230 // Irregexp implementation. | 269 // Irregexp implementation. |
231 | 270 |
232 // Ensures that the regexp object contains a compiled version of the | 271 // Ensures that the regexp object contains a compiled version of the |
233 // source for either ASCII or non-ASCII strings. | 272 // source for either ASCII or non-ASCII strings. |
234 // If the compiled version doesn't already exist, it is compiled | 273 // If the compiled version doesn't already exist, it is compiled |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
357 Handle<String> subject) { | 396 Handle<String> subject) { |
358 if (!subject->IsFlat()) { | 397 if (!subject->IsFlat()) { |
359 FlattenString(subject); | 398 FlattenString(subject); |
360 } | 399 } |
361 // Check the asciiness of the underlying storage. | 400 // Check the asciiness of the underlying storage. |
362 bool is_ascii; | 401 bool is_ascii; |
363 { | 402 { |
364 AssertNoAllocation no_gc; | 403 AssertNoAllocation no_gc; |
365 String* sequential_string = *subject; | 404 String* sequential_string = *subject; |
366 if (subject->IsConsString()) { | 405 if (subject->IsConsString()) { |
367 sequential_string = ConsString::cast(*subject)->first(); | 406 sequential_string = ConsString::cast(*subject)->first(); |
368 } | 407 } |
369 is_ascii = sequential_string->IsAsciiRepresentation(); | 408 is_ascii = sequential_string->IsAsciiRepresentation(); |
370 } | 409 } |
371 if (!EnsureCompiledIrregexp(regexp, is_ascii)) { | 410 if (!EnsureCompiledIrregexp(regexp, is_ascii)) { |
372 return -1; | 411 return -1; |
373 } | 412 } |
374 #ifdef V8_INTERPRETED_REGEXP | 413 #ifdef V8_INTERPRETED_REGEXP |
375 // Byte-code regexp needs space allocated for all its registers. | 414 // Byte-code regexp needs space allocated for all its registers. |
376 return IrregexpNumberOfRegisters(FixedArray::cast(regexp->data())); | 415 return IrregexpNumberOfRegisters(FixedArray::cast(regexp->data())); |
377 #else // V8_INTERPRETED_REGEXP | 416 #else // V8_INTERPRETED_REGEXP |
(...skipping 4876 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5254 node, | 5293 node, |
5255 data->capture_count, | 5294 data->capture_count, |
5256 pattern); | 5295 pattern); |
5257 } | 5296 } |
5258 | 5297 |
5259 | 5298 |
5260 int OffsetsVector::static_offsets_vector_[ | 5299 int OffsetsVector::static_offsets_vector_[ |
5261 OffsetsVector::kStaticOffsetsVectorSize]; | 5300 OffsetsVector::kStaticOffsetsVectorSize]; |
5262 | 5301 |
5263 }} // namespace v8::internal | 5302 }} // namespace v8::internal |
OLD | NEW |