OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "src/regexp/jsregexp.h" | 5 #include "src/regexp/jsregexp.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 | 8 |
9 #include "src/ast/ast.h" | 9 #include "src/ast/ast.h" |
10 #include "src/base/platform/platform.h" | 10 #include "src/base/platform/platform.h" |
11 #include "src/compilation-cache.h" | 11 #include "src/compilation-cache.h" |
12 #include "src/compiler.h" | 12 #include "src/compiler.h" |
| 13 #include "src/elements.h" |
13 #include "src/execution.h" | 14 #include "src/execution.h" |
14 #include "src/factory.h" | 15 #include "src/factory.h" |
15 #include "src/isolate-inl.h" | 16 #include "src/isolate-inl.h" |
16 #include "src/messages.h" | 17 #include "src/messages.h" |
17 #include "src/ostreams.h" | 18 #include "src/ostreams.h" |
18 #include "src/regexp/interpreter-irregexp.h" | 19 #include "src/regexp/interpreter-irregexp.h" |
19 #include "src/regexp/jsregexp-inl.h" | 20 #include "src/regexp/jsregexp-inl.h" |
20 #include "src/regexp/regexp-macro-assembler.h" | |
21 #include "src/regexp/regexp-macro-assembler-irregexp.h" | 21 #include "src/regexp/regexp-macro-assembler-irregexp.h" |
22 #include "src/regexp/regexp-macro-assembler-tracer.h" | 22 #include "src/regexp/regexp-macro-assembler-tracer.h" |
| 23 #include "src/regexp/regexp-macro-assembler.h" |
23 #include "src/regexp/regexp-parser.h" | 24 #include "src/regexp/regexp-parser.h" |
24 #include "src/regexp/regexp-stack.h" | 25 #include "src/regexp/regexp-stack.h" |
25 #include "src/runtime/runtime.h" | 26 #include "src/runtime/runtime.h" |
26 #include "src/splay-tree-inl.h" | 27 #include "src/splay-tree-inl.h" |
27 #include "src/string-search.h" | 28 #include "src/string-search.h" |
28 #include "src/unicode-decoder.h" | 29 #include "src/unicode-decoder.h" |
29 | 30 |
30 #ifdef V8_I18N_SUPPORT | 31 #ifdef V8_I18N_SUPPORT |
31 #include "unicode/uset.h" | 32 #include "unicode/uset.h" |
32 #include "unicode/utypes.h" | 33 #include "unicode/utypes.h" |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
186 } | 187 } |
187 DCHECK(re->data()->IsFixedArray()); | 188 DCHECK(re->data()->IsFixedArray()); |
188 // Compilation succeeded so the data is set on the regexp | 189 // Compilation succeeded so the data is set on the regexp |
189 // and we can store it in the cache. | 190 // and we can store it in the cache. |
190 Handle<FixedArray> data(FixedArray::cast(re->data())); | 191 Handle<FixedArray> data(FixedArray::cast(re->data())); |
191 compilation_cache->PutRegExp(pattern, flags, data); | 192 compilation_cache->PutRegExp(pattern, flags, data); |
192 | 193 |
193 return re; | 194 return re; |
194 } | 195 } |
195 | 196 |
196 | |
197 MaybeHandle<Object> RegExpImpl::Exec(Handle<JSRegExp> regexp, | 197 MaybeHandle<Object> RegExpImpl::Exec(Handle<JSRegExp> regexp, |
198 Handle<String> subject, | 198 Handle<String> subject, int index, |
199 int index, | 199 Handle<JSObject> last_match_info) { |
200 Handle<JSArray> last_match_info) { | |
201 switch (regexp->TypeTag()) { | 200 switch (regexp->TypeTag()) { |
202 case JSRegExp::ATOM: | 201 case JSRegExp::ATOM: |
203 return AtomExec(regexp, subject, index, last_match_info); | 202 return AtomExec(regexp, subject, index, last_match_info); |
204 case JSRegExp::IRREGEXP: { | 203 case JSRegExp::IRREGEXP: { |
205 return IrregexpExec(regexp, subject, index, last_match_info); | 204 return IrregexpExec(regexp, subject, index, last_match_info); |
206 } | 205 } |
207 default: | 206 default: |
208 UNREACHABLE(); | 207 UNREACHABLE(); |
209 return MaybeHandle<Object>(); | 208 return MaybeHandle<Object>(); |
210 } | 209 } |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
283 return i / 2; // Return number of matches. | 282 return i / 2; // Return number of matches. |
284 } else { | 283 } else { |
285 output[i] = index; | 284 output[i] = index; |
286 output[i+1] = index + needle_len; | 285 output[i+1] = index + needle_len; |
287 index += needle_len; | 286 index += needle_len; |
288 } | 287 } |
289 } | 288 } |
290 return output_size / 2; | 289 return output_size / 2; |
291 } | 290 } |
292 | 291 |
293 | 292 Handle<Object> RegExpImpl::AtomExec(Handle<JSRegExp> re, Handle<String> subject, |
294 Handle<Object> RegExpImpl::AtomExec(Handle<JSRegExp> re, | |
295 Handle<String> subject, | |
296 int index, | 293 int index, |
297 Handle<JSArray> last_match_info) { | 294 Handle<JSObject> last_match_info) { |
298 Isolate* isolate = re->GetIsolate(); | 295 Isolate* isolate = re->GetIsolate(); |
299 | 296 |
300 static const int kNumRegisters = 2; | 297 static const int kNumRegisters = 2; |
301 STATIC_ASSERT(kNumRegisters <= Isolate::kJSRegexpStaticOffsetsVectorSize); | 298 STATIC_ASSERT(kNumRegisters <= Isolate::kJSRegexpStaticOffsetsVectorSize); |
302 int32_t* output_registers = isolate->jsregexp_static_offsets_vector(); | 299 int32_t* output_registers = isolate->jsregexp_static_offsets_vector(); |
303 | 300 |
304 int res = AtomExecRaw(re, subject, index, output_registers, kNumRegisters); | 301 int res = AtomExecRaw(re, subject, index, output_registers, kNumRegisters); |
305 | 302 |
306 if (res == RegExpImpl::RE_FAILURE) return isolate->factory()->null_value(); | 303 if (res == RegExpImpl::RE_FAILURE) return isolate->factory()->null_value(); |
307 | 304 |
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
564 MemCopy(output, raw_output, number_of_capture_registers * sizeof(int32_t)); | 561 MemCopy(output, raw_output, number_of_capture_registers * sizeof(int32_t)); |
565 } | 562 } |
566 if (result == RE_EXCEPTION) { | 563 if (result == RE_EXCEPTION) { |
567 DCHECK(!isolate->has_pending_exception()); | 564 DCHECK(!isolate->has_pending_exception()); |
568 isolate->StackOverflow(); | 565 isolate->StackOverflow(); |
569 } | 566 } |
570 return result; | 567 return result; |
571 #endif // V8_INTERPRETED_REGEXP | 568 #endif // V8_INTERPRETED_REGEXP |
572 } | 569 } |
573 | 570 |
574 | |
575 MaybeHandle<Object> RegExpImpl::IrregexpExec(Handle<JSRegExp> regexp, | 571 MaybeHandle<Object> RegExpImpl::IrregexpExec(Handle<JSRegExp> regexp, |
576 Handle<String> subject, | 572 Handle<String> subject, |
577 int previous_index, | 573 int previous_index, |
578 Handle<JSArray> last_match_info) { | 574 Handle<JSObject> last_match_info) { |
579 Isolate* isolate = regexp->GetIsolate(); | 575 Isolate* isolate = regexp->GetIsolate(); |
580 DCHECK_EQ(regexp->TypeTag(), JSRegExp::IRREGEXP); | 576 DCHECK_EQ(regexp->TypeTag(), JSRegExp::IRREGEXP); |
581 | 577 |
582 // Prepare space for the return values. | 578 // Prepare space for the return values. |
583 #if defined(V8_INTERPRETED_REGEXP) && defined(DEBUG) | 579 #if defined(V8_INTERPRETED_REGEXP) && defined(DEBUG) |
584 if (FLAG_trace_regexp_bytecodes) { | 580 if (FLAG_trace_regexp_bytecodes) { |
585 String* pattern = regexp->Pattern(); | 581 String* pattern = regexp->Pattern(); |
586 PrintF("\n\nRegexp match: /%s/\n\n", pattern->ToCString().get()); | 582 PrintF("\n\nRegexp match: /%s/\n\n", pattern->ToCString().get()); |
587 PrintF("\n\nSubject string: '%s'\n\n", subject->ToCString().get()); | 583 PrintF("\n\nSubject string: '%s'\n\n", subject->ToCString().get()); |
588 } | 584 } |
(...skipping 23 matching lines...) Expand all Loading... |
612 last_match_info, subject, capture_count, output_registers); | 608 last_match_info, subject, capture_count, output_registers); |
613 } | 609 } |
614 if (res == RE_EXCEPTION) { | 610 if (res == RE_EXCEPTION) { |
615 DCHECK(isolate->has_pending_exception()); | 611 DCHECK(isolate->has_pending_exception()); |
616 return MaybeHandle<Object>(); | 612 return MaybeHandle<Object>(); |
617 } | 613 } |
618 DCHECK(res == RE_FAILURE); | 614 DCHECK(res == RE_FAILURE); |
619 return isolate->factory()->null_value(); | 615 return isolate->factory()->null_value(); |
620 } | 616 } |
621 | 617 |
622 | 618 static void EnsureSize(Handle<JSObject> array, uint32_t minimum_size) { |
623 static void EnsureSize(Handle<JSArray> array, uint32_t minimum_size) { | |
624 if (static_cast<uint32_t>(array->elements()->length()) < minimum_size) { | 619 if (static_cast<uint32_t>(array->elements()->length()) < minimum_size) { |
625 JSArray::SetLength(array, minimum_size); | 620 array->GetElementsAccessor()->GrowCapacityAndConvert(array, minimum_size); |
626 } | 621 } |
627 } | 622 } |
628 | 623 |
629 | 624 Handle<JSObject> RegExpImpl::SetLastMatchInfo(Handle<JSObject> last_match_info, |
630 Handle<JSArray> RegExpImpl::SetLastMatchInfo(Handle<JSArray> last_match_info, | 625 Handle<String> subject, |
631 Handle<String> subject, | 626 int capture_count, |
632 int capture_count, | 627 int32_t* match) { |
633 int32_t* match) { | |
634 DCHECK(last_match_info->HasFastObjectElements()); | 628 DCHECK(last_match_info->HasFastObjectElements()); |
635 int capture_register_count = (capture_count + 1) * 2; | 629 int capture_register_count = (capture_count + 1) * 2; |
636 EnsureSize(last_match_info, capture_register_count + kLastMatchOverhead); | 630 EnsureSize(last_match_info, capture_register_count + kLastMatchOverhead); |
637 DisallowHeapAllocation no_allocation; | 631 DisallowHeapAllocation no_allocation; |
638 FixedArray* array = FixedArray::cast(last_match_info->elements()); | 632 FixedArray* array = FixedArray::cast(last_match_info->elements()); |
639 if (match != NULL) { | 633 if (match != NULL) { |
640 for (int i = 0; i < capture_register_count; i += 2) { | 634 for (int i = 0; i < capture_register_count; i += 2) { |
641 SetCapture(array, i, match[i]); | 635 SetCapture(array, i, match[i]); |
642 SetCapture(array, i + 1, match[i + 1]); | 636 SetCapture(array, i + 1, match[i + 1]); |
643 } | 637 } |
(...skipping 6234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6878 | 6872 |
6879 | 6873 |
6880 void RegExpResultsCache::Clear(FixedArray* cache) { | 6874 void RegExpResultsCache::Clear(FixedArray* cache) { |
6881 for (int i = 0; i < kRegExpResultsCacheSize; i++) { | 6875 for (int i = 0; i < kRegExpResultsCacheSize; i++) { |
6882 cache->set(i, Smi::FromInt(0)); | 6876 cache->set(i, Smi::FromInt(0)); |
6883 } | 6877 } |
6884 } | 6878 } |
6885 | 6879 |
6886 } // namespace internal | 6880 } // namespace internal |
6887 } // namespace v8 | 6881 } // namespace v8 |
OLD | NEW |