Chromium Code Reviews| 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 448 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 459 capture_count); | 459 capture_count); |
| 460 } | 460 } |
| 461 | 461 |
| 462 | 462 |
| 463 Handle<Object> RegExpImpl::IrregexpExec(Handle<JSRegExp> regexp, | 463 Handle<Object> RegExpImpl::IrregexpExec(Handle<JSRegExp> regexp, |
| 464 Handle<String> subject, | 464 Handle<String> subject, |
| 465 int index, | 465 int index, |
| 466 Handle<JSArray> last_match_info) { | 466 Handle<JSArray> last_match_info) { |
| 467 ASSERT_EQ(regexp->TypeTag(), JSRegExp::IRREGEXP); | 467 ASSERT_EQ(regexp->TypeTag(), JSRegExp::IRREGEXP); |
| 468 | 468 |
| 469 bool is_ascii = StringShape(*subject).IsAsciiRepresentation(); | |
| 470 if (!EnsureCompiledIrregexp(regexp, is_ascii)) { | |
| 471 return Handle<Object>::null(); | |
| 472 } | |
| 473 | |
| 474 // Prepare space for the return values. | 469 // Prepare space for the return values. |
| 475 Handle<FixedArray> re_data(FixedArray::cast(regexp->data())); | |
| 476 int number_of_capture_registers = | 470 int number_of_capture_registers = |
| 477 (IrregexpNumberOfCaptures(*re_data) + 1) * 2; | 471 (IrregexpNumberOfCaptures(FixedArray::cast(regexp->data())) + 1) * 2; |
| 478 OffsetsVector offsets(number_of_capture_registers); | 472 OffsetsVector offsets(number_of_capture_registers); |
| 479 | 473 |
| 480 int previous_index = index; | 474 int previous_index = index; |
| 481 | 475 |
| 482 #ifdef DEBUG | 476 #ifdef DEBUG |
| 483 if (FLAG_trace_regexp_bytecodes) { | 477 if (FLAG_trace_regexp_bytecodes) { |
| 484 String* pattern = regexp->Pattern(); | 478 String* pattern = regexp->Pattern(); |
| 485 PrintF("\n\nRegexp match: /%s/\n\n", *(pattern->ToCString())); | 479 PrintF("\n\nRegexp match: /%s/\n\n", *(pattern->ToCString())); |
| 486 PrintF("\n\nSubject string: '%s'\n\n", *(subject->ToCString())); | 480 PrintF("\n\nSubject string: '%s'\n\n", *(subject->ToCString())); |
| 487 } | 481 } |
| 488 #endif | 482 #endif |
| 489 | 483 |
| 490 if (!subject->IsFlat()) { | 484 if (!subject->IsFlat()) { |
| 491 FlattenString(subject); | 485 FlattenString(subject); |
| 492 } | 486 } |
| 493 | 487 |
| 494 last_match_info->EnsureSize(number_of_capture_registers + kLastMatchOverhead); | 488 last_match_info->EnsureSize(number_of_capture_registers + kLastMatchOverhead); |
| 495 | 489 |
| 496 return IrregexpExecOnce(re_data, | 490 return IrregexpExecOnce(regexp, |
| 497 number_of_capture_registers, | 491 number_of_capture_registers, |
| 498 last_match_info, | 492 last_match_info, |
| 499 subject, | 493 subject, |
| 500 previous_index, | 494 previous_index, |
| 501 offsets.vector(), | 495 offsets.vector(), |
| 502 offsets.length()); | 496 offsets.length()); |
| 503 } | 497 } |
| 504 | 498 |
| 505 | 499 |
| 506 Handle<Object> RegExpImpl::IrregexpExecGlobal(Handle<JSRegExp> regexp, | 500 Handle<Object> RegExpImpl::IrregexpExecGlobal(Handle<JSRegExp> regexp, |
| 507 Handle<String> subject, | 501 Handle<String> subject, |
| 508 Handle<JSArray> last_match_info) { | 502 Handle<JSArray> last_match_info) { |
| 509 ASSERT_EQ(regexp->TypeTag(), JSRegExp::IRREGEXP); | 503 ASSERT_EQ(regexp->TypeTag(), JSRegExp::IRREGEXP); |
| 510 Handle<FixedArray> irregexp(FixedArray::cast(regexp->data())); | |
| 511 | |
| 512 bool is_ascii = StringShape(*subject).IsAsciiRepresentation(); | |
| 513 if (!EnsureCompiledIrregexp(regexp, is_ascii)) { | |
| 514 return Handle<Object>::null(); | |
| 515 } | |
| 516 | 504 |
| 517 // Prepare space for the return values. | 505 // Prepare space for the return values. |
| 518 int number_of_capture_registers = | 506 int number_of_capture_registers = |
| 519 (IrregexpNumberOfCaptures(*irregexp) + 1) * 2; | 507 (IrregexpNumberOfCaptures(FixedArray::cast(regexp->data())) + 1) * 2; |
| 520 OffsetsVector offsets(number_of_capture_registers); | 508 OffsetsVector offsets(number_of_capture_registers); |
| 521 | 509 |
| 522 int previous_index = 0; | 510 int previous_index = 0; |
| 523 | 511 |
| 524 Handle<JSArray> result = Factory::NewJSArray(0); | 512 Handle<JSArray> result = Factory::NewJSArray(0); |
| 525 int result_length = 0; | 513 int result_length = 0; |
| 526 Handle<Object> matches; | 514 Handle<Object> matches; |
| 527 | 515 |
| 528 if (!subject->IsFlat()) { | 516 if (!subject->IsFlat()) { |
| 529 FlattenString(subject); | 517 FlattenString(subject); |
| 530 } | 518 } |
| 531 | 519 |
| 532 last_match_info->EnsureSize(number_of_capture_registers + kLastMatchOverhead); | 520 last_match_info->EnsureSize(number_of_capture_registers + kLastMatchOverhead); |
| 533 | 521 |
| 534 while (true) { | 522 while (true) { |
| 535 if (previous_index > subject->length() || previous_index < 0) { | 523 if (previous_index > subject->length() || previous_index < 0) { |
| 536 // Per ECMA-262 15.10.6.2, if the previous index is greater than the | 524 // Per ECMA-262 15.10.6.2, if the previous index is greater than the |
| 537 // string length, there is no match. | 525 // string length, there is no match. |
| 538 return result; | 526 return result; |
| 539 } else { | 527 } else { |
| 540 #ifdef DEBUG | 528 #ifdef DEBUG |
| 541 if (FLAG_trace_regexp_bytecodes) { | 529 if (FLAG_trace_regexp_bytecodes) { |
| 542 String* pattern = regexp->Pattern(); | 530 String* pattern = regexp->Pattern(); |
| 543 PrintF("\n\nRegexp match: /%s/\n\n", *(pattern->ToCString())); | 531 PrintF("\n\nRegexp match: /%s/\n\n", *(pattern->ToCString())); |
| 544 PrintF("\n\nSubject string: '%s'\n\n", *(subject->ToCString())); | 532 PrintF("\n\nSubject string: '%s'\n\n", *(subject->ToCString())); |
| 545 } | 533 } |
| 546 #endif | 534 #endif |
| 547 HandleScope scope; | 535 HandleScope scope; |
| 548 matches = IrregexpExecOnce(irregexp, | 536 matches = IrregexpExecOnce(regexp, |
| 549 number_of_capture_registers, | 537 number_of_capture_registers, |
| 550 last_match_info, | 538 last_match_info, |
| 551 subject, | 539 subject, |
| 552 previous_index, | 540 previous_index, |
| 553 offsets.vector(), | 541 offsets.vector(), |
| 554 offsets.length()); | 542 offsets.length()); |
| 555 | 543 |
| 556 if (matches.is_null()) { | 544 if (matches.is_null()) { |
| 557 ASSERT(Top::has_pending_exception()); | 545 ASSERT(Top::has_pending_exception()); |
| 558 return matches; | 546 return matches; |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 580 } | 568 } |
| 581 } else { | 569 } else { |
| 582 ASSERT(matches->IsNull()); | 570 ASSERT(matches->IsNull()); |
| 583 return result; | 571 return result; |
| 584 } | 572 } |
| 585 } | 573 } |
| 586 } | 574 } |
| 587 } | 575 } |
| 588 | 576 |
| 589 | 577 |
| 590 Handle<Object> RegExpImpl::IrregexpExecOnce(Handle<FixedArray> regexp, | 578 Handle<Object> RegExpImpl::IrregexpExecOnce(Handle<JSRegExp> jsregexp, |
| 591 int number_of_capture_registers, | 579 int number_of_capture_registers, |
| 592 Handle<JSArray> last_match_info, | 580 Handle<JSArray> last_match_info, |
| 593 Handle<String> subject, | 581 Handle<String> subject, |
| 594 int previous_index, | 582 int previous_index, |
| 595 int* offsets_vector, | 583 int* offsets_vector, |
| 596 int offsets_vector_length) { | 584 int offsets_vector_length) { |
| 597 ASSERT(subject->IsFlat()); | 585 ASSERT(subject->IsFlat()); |
| 598 bool is_ascii = StringShape(*subject).IsAsciiRepresentation(); | |
| 599 bool rc; | 586 bool rc; |
| 600 | 587 |
| 601 Handle<String> original_subject = subject; | 588 Handle<String> original_subject = subject; |
| 589 Handle<FixedArray> regexp(FixedArray::cast(jsregexp->data())); | |
| 602 if (UseNativeRegexp()) { | 590 if (UseNativeRegexp()) { |
| 603 #ifdef ARM | 591 #ifdef ARM |
| 604 UNREACHABLE(); | 592 UNREACHABLE(); |
| 605 #else | 593 #else |
| 606 Handle<Code> code(RegExpImpl::IrregexpNativeCode(*regexp, is_ascii)); | 594 RegExpMacroAssemblerIA32::Result res; |
| 607 RegExpMacroAssemblerIA32::Result res = | 595 do { |
| 608 RegExpMacroAssemblerIA32::Match(code, | 596 bool is_ascii = StringShape(*subject).IsAsciiRepresentation(); |
| 609 subject, | 597 if (!EnsureCompiledIrregexp(jsregexp, is_ascii)) { |
| 610 offsets_vector, | 598 return Handle<Object>::null(); |
| 611 offsets_vector_length, | 599 } |
| 612 previous_index); | 600 Handle<Code> code(RegExpImpl::IrregexpNativeCode(*regexp, is_ascii)); |
| 613 | 601 res = RegExpMacroAssemblerIA32::Match(code, |
| 602 subject, | |
| 603 offsets_vector, | |
| 604 offsets_vector_length, | |
| 605 previous_index); | |
|
Erik Corry
2009/03/20 12:45:42
A comment would be in order here!
| |
| 606 } while (res == RegExpMacroAssemblerIA32::RETRY); | |
| 614 if (res == RegExpMacroAssemblerIA32::EXCEPTION) { | 607 if (res == RegExpMacroAssemblerIA32::EXCEPTION) { |
| 615 ASSERT(Top::has_pending_exception()); | 608 ASSERT(Top::has_pending_exception()); |
| 616 return Handle<Object>::null(); | 609 return Handle<Object>::null(); |
| 617 } | 610 } |
| 618 ASSERT(res == RegExpMacroAssemblerIA32::SUCCESS | 611 ASSERT(res == RegExpMacroAssemblerIA32::SUCCESS |
| 619 || res == RegExpMacroAssemblerIA32::FAILURE); | 612 || res == RegExpMacroAssemblerIA32::FAILURE); |
| 620 | 613 |
| 621 rc = (res == RegExpMacroAssemblerIA32::SUCCESS); | 614 rc = (res == RegExpMacroAssemblerIA32::SUCCESS); |
| 622 #endif | 615 #endif |
| 623 } else { | 616 } else { |
| 617 bool is_ascii = StringShape(*subject).IsAsciiRepresentation(); | |
| 624 for (int i = number_of_capture_registers - 1; i >= 0; i--) { | 618 for (int i = number_of_capture_registers - 1; i >= 0; i--) { |
| 625 offsets_vector[i] = -1; | 619 offsets_vector[i] = -1; |
| 626 } | 620 } |
| 627 Handle<ByteArray> byte_codes(IrregexpByteCode(*regexp, is_ascii)); | 621 Handle<ByteArray> byte_codes(IrregexpByteCode(*regexp, is_ascii)); |
| 628 | 622 |
| 629 rc = IrregexpInterpreter::Match(byte_codes, | 623 rc = IrregexpInterpreter::Match(byte_codes, |
| 630 subject, | 624 subject, |
| 631 offsets_vector, | 625 offsets_vector, |
| 632 previous_index); | 626 previous_index); |
| 633 } | 627 } |
| (...skipping 3983 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4617 EmbeddedVector<byte, 1024> codes; | 4611 EmbeddedVector<byte, 1024> codes; |
| 4618 RegExpMacroAssemblerIrregexp macro_assembler(codes); | 4612 RegExpMacroAssemblerIrregexp macro_assembler(codes); |
| 4619 return compiler.Assemble(¯o_assembler, | 4613 return compiler.Assemble(¯o_assembler, |
| 4620 node, | 4614 node, |
| 4621 data->capture_count, | 4615 data->capture_count, |
| 4622 pattern); | 4616 pattern); |
| 4623 } | 4617 } |
| 4624 | 4618 |
| 4625 | 4619 |
| 4626 }} // namespace v8::internal | 4620 }} // namespace v8::internal |
| OLD | NEW |