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 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
105 SetElement(array, 0, pattern); | 105 SetElement(array, 0, pattern); |
106 SetElement(array, 1, error_text); | 106 SetElement(array, 1, error_text); |
107 Handle<Object> regexp_err = Factory::NewSyntaxError(message, array); | 107 Handle<Object> regexp_err = Factory::NewSyntaxError(message, array); |
108 Top::Throw(*regexp_err); | 108 Top::Throw(*regexp_err); |
109 } | 109 } |
110 | 110 |
111 | 111 |
112 // Generic RegExp methods. Dispatches to implementation specific methods. | 112 // Generic RegExp methods. Dispatches to implementation specific methods. |
113 | 113 |
114 | 114 |
115 class OffsetsVector { | |
116 public: | |
117 inline OffsetsVector(int num_registers) | |
118 : offsets_vector_length_(num_registers) { | |
119 if (offsets_vector_length_ > kStaticOffsetsVectorSize) { | |
120 vector_ = NewArray<int>(offsets_vector_length_); | |
121 } else { | |
122 vector_ = static_offsets_vector_; | |
123 } | |
124 } | |
125 inline ~OffsetsVector() { | |
126 if (offsets_vector_length_ > kStaticOffsetsVectorSize) { | |
127 DeleteArray(vector_); | |
128 vector_ = NULL; | |
129 } | |
130 } | |
131 inline int* vector() { return vector_; } | |
132 inline int length() { return offsets_vector_length_; } | |
133 | |
134 private: | |
135 int* vector_; | |
136 int offsets_vector_length_; | |
137 static const int kStaticOffsetsVectorSize = 50; | |
138 static int static_offsets_vector_[kStaticOffsetsVectorSize]; | |
139 }; | |
140 | |
141 | |
142 int OffsetsVector::static_offsets_vector_[ | |
143 OffsetsVector::kStaticOffsetsVectorSize]; | |
144 | |
145 | |
146 Handle<Object> RegExpImpl::Compile(Handle<JSRegExp> re, | 115 Handle<Object> RegExpImpl::Compile(Handle<JSRegExp> re, |
147 Handle<String> pattern, | 116 Handle<String> pattern, |
148 Handle<String> flag_str) { | 117 Handle<String> flag_str) { |
149 JSRegExp::Flags flags = RegExpFlagsFromString(flag_str); | 118 JSRegExp::Flags flags = RegExpFlagsFromString(flag_str); |
150 Handle<FixedArray> cached = CompilationCache::LookupRegExp(pattern, flags); | 119 Handle<FixedArray> cached = CompilationCache::LookupRegExp(pattern, flags); |
151 bool in_cache = !cached.is_null(); | 120 bool in_cache = !cached.is_null(); |
152 LOG(RegExpCompileEvent(re, in_cache)); | 121 LOG(RegExpCompileEvent(re, in_cache)); |
153 | 122 |
154 Handle<Object> result; | 123 Handle<Object> result; |
155 if (in_cache) { | 124 if (in_cache) { |
(...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
441 } | 410 } |
442 ASSERT(res == NativeRegExpMacroAssembler::SUCCESS | 411 ASSERT(res == NativeRegExpMacroAssembler::SUCCESS |
443 || res == NativeRegExpMacroAssembler::FAILURE); | 412 || res == NativeRegExpMacroAssembler::FAILURE); |
444 | 413 |
445 if (res != NativeRegExpMacroAssembler::SUCCESS) return Factory::null_value(); | 414 if (res != NativeRegExpMacroAssembler::SUCCESS) return Factory::null_value(); |
446 | 415 |
447 array = Handle<FixedArray>(FixedArray::cast(last_match_info->elements())); | 416 array = Handle<FixedArray>(FixedArray::cast(last_match_info->elements())); |
448 ASSERT(array->length() >= number_of_capture_registers + kLastMatchOverhead); | 417 ASSERT(array->length() >= number_of_capture_registers + kLastMatchOverhead); |
449 // The captures come in (start, end+1) pairs. | 418 // The captures come in (start, end+1) pairs. |
450 for (int i = 0; i < number_of_capture_registers; i += 2) { | 419 for (int i = 0; i < number_of_capture_registers; i += 2) { |
| 420 // Capture values are relative to start_offset only. |
| 421 // Convert them to be relative to start of string. |
| 422 if (captures_vector[i] >= 0) { |
| 423 captures_vector[i] += previous_index; |
| 424 } |
| 425 if (captures_vector[i + 1] >= 0) { |
| 426 captures_vector[i + 1] += previous_index; |
| 427 } |
451 SetCapture(*array, i, captures_vector[i]); | 428 SetCapture(*array, i, captures_vector[i]); |
452 SetCapture(*array, i + 1, captures_vector[i + 1]); | 429 SetCapture(*array, i + 1, captures_vector[i + 1]); |
453 } | 430 } |
454 | 431 |
455 #else // ! V8_NATIVE_REGEXP | 432 #else // ! V8_NATIVE_REGEXP |
456 | 433 |
457 bool is_ascii = subject->IsAsciiRepresentation(); | 434 bool is_ascii = subject->IsAsciiRepresentation(); |
458 if (!EnsureCompiledIrregexp(jsregexp, is_ascii)) { | 435 if (!EnsureCompiledIrregexp(jsregexp, is_ascii)) { |
459 return Handle<Object>::null(); | 436 return Handle<Object>::null(); |
460 } | 437 } |
(...skipping 4138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4599 EmbeddedVector<byte, 1024> codes; | 4576 EmbeddedVector<byte, 1024> codes; |
4600 RegExpMacroAssemblerIrregexp macro_assembler(codes); | 4577 RegExpMacroAssemblerIrregexp macro_assembler(codes); |
4601 #endif | 4578 #endif |
4602 | 4579 |
4603 return compiler.Assemble(¯o_assembler, | 4580 return compiler.Assemble(¯o_assembler, |
4604 node, | 4581 node, |
4605 data->capture_count, | 4582 data->capture_count, |
4606 pattern); | 4583 pattern); |
4607 } | 4584 } |
4608 | 4585 |
| 4586 |
| 4587 int OffsetsVector::static_offsets_vector_[ |
| 4588 OffsetsVector::kStaticOffsetsVectorSize]; |
| 4589 |
4609 }} // namespace v8::internal | 4590 }} // namespace v8::internal |
OLD | NEW |