| OLD | NEW |
| 1 // Copyright 2006-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2008 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 259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 270 } | 270 } |
| 271 | 271 |
| 272 | 272 |
| 273 static bool NotDigit(uc16 c) { | 273 static bool NotDigit(uc16 c) { |
| 274 return !IsDigit(c); | 274 return !IsDigit(c); |
| 275 } | 275 } |
| 276 | 276 |
| 277 | 277 |
| 278 static bool IsWhiteSpace(uc16 c) { | 278 static bool IsWhiteSpace(uc16 c) { |
| 279 switch (c) { | 279 switch (c) { |
| 280 case 0x09: case 0x0B: case 0x0C: case 0x20: case 0xA0: | 280 case 0x09: |
| 281 case 0x0A: |
| 282 case 0x0B: |
| 283 case 0x0C: |
| 284 case 0x0d: |
| 285 case 0x20: |
| 286 case 0xA0: |
| 287 case 0x2028: |
| 288 case 0x2029: |
| 281 return true; | 289 return true; |
| 282 default: | 290 default: |
| 283 return unibrow::Space::Is(c); | 291 return unibrow::Space::Is(c); |
| 284 } | 292 } |
| 285 } | 293 } |
| 286 | 294 |
| 287 | 295 |
| 288 static bool NotWhiteSpace(uc16 c) { | 296 static bool NotWhiteSpace(uc16 c) { |
| 289 return !IsWhiteSpace(c); | 297 return !IsWhiteSpace(c); |
| 290 } | 298 } |
| (...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 512 __ Bind(&fail); | 520 __ Bind(&fail); |
| 513 __ Fail(); | 521 __ Fail(); |
| 514 | 522 |
| 515 v8::HandleScope scope; | 523 v8::HandleScope scope; |
| 516 Handle<ByteArray> array = Factory::NewByteArray(assembler.length()); | 524 Handle<ByteArray> array = Factory::NewByteArray(assembler.length()); |
| 517 assembler.Copy(array->GetDataStartAddress()); | 525 assembler.Copy(array->GetDataStartAddress()); |
| 518 int captures[2]; | 526 int captures[2]; |
| 519 | 527 |
| 520 Handle<String> f1 = | 528 Handle<String> f1 = |
| 521 Factory::NewStringFromAscii(CStrVector("Now is the time")); | 529 Factory::NewStringFromAscii(CStrVector("Now is the time")); |
| 522 CHECK(!Re2kInterpreter::Match(array, f1, captures, 0)); | 530 Handle<String> f1_16 = RegExpImpl::StringToTwoByte(f1); |
| 531 CHECK(!Re2kInterpreter::Match(array, f1_16, captures, 0)); |
| 523 | 532 |
| 524 Handle<String> f2 = Factory::NewStringFromAscii(CStrVector("foo bar baz")); | 533 Handle<String> f2 = Factory::NewStringFromAscii(CStrVector("foo bar baz")); |
| 525 CHECK(Re2kInterpreter::Match(array, f2, captures, 0)); | 534 Handle<String> f2_16 = RegExpImpl::StringToTwoByte(f2); |
| 535 CHECK(Re2kInterpreter::Match(array, f2_16, captures, 0)); |
| 526 CHECK_EQ(0, captures[0]); | 536 CHECK_EQ(0, captures[0]); |
| 527 CHECK_EQ(2, captures[1]); | 537 CHECK_EQ(2, captures[1]); |
| 528 | 538 |
| 529 Handle<String> f3 = Factory::NewStringFromAscii(CStrVector("tomfoolery")); | 539 Handle<String> f3 = Factory::NewStringFromAscii(CStrVector("tomfoolery")); |
| 530 CHECK(Re2kInterpreter::Match(array, f3, captures, 0)); | 540 Handle<String> f3_16 = RegExpImpl::StringToTwoByte(f3); |
| 541 CHECK(Re2kInterpreter::Match(array, f3_16, captures, 0)); |
| 531 CHECK_EQ(3, captures[0]); | 542 CHECK_EQ(3, captures[0]); |
| 532 CHECK_EQ(5, captures[1]); | 543 CHECK_EQ(5, captures[1]); |
| 533 } | 544 } |
| 534 | 545 |
| 535 | 546 |
| 536 TEST(Assembler2) { | 547 TEST(Assembler2) { |
| 537 V8::Initialize(NULL); | 548 V8::Initialize(NULL); |
| 538 byte codes[1024]; | 549 byte codes[1024]; |
| 539 Re2kAssembler assembler(Vector<byte>(codes, 1024)); | 550 Re2kAssembler assembler(Vector<byte>(codes, 1024)); |
| 540 #define __ assembler. | 551 #define __ assembler. |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 584 __ PopCurrentPosition(); | 595 __ PopCurrentPosition(); |
| 585 __ Fail(); | 596 __ Fail(); |
| 586 | 597 |
| 587 v8::HandleScope scope; | 598 v8::HandleScope scope; |
| 588 Handle<ByteArray> array = Factory::NewByteArray(assembler.length()); | 599 Handle<ByteArray> array = Factory::NewByteArray(assembler.length()); |
| 589 assembler.Copy(array->GetDataStartAddress()); | 600 assembler.Copy(array->GetDataStartAddress()); |
| 590 int captures[2]; | 601 int captures[2]; |
| 591 | 602 |
| 592 Handle<String> f1 = | 603 Handle<String> f1 = |
| 593 Factory::NewStringFromAscii(CStrVector("Now is the time")); | 604 Factory::NewStringFromAscii(CStrVector("Now is the time")); |
| 594 CHECK(!Re2kInterpreter::Match(array, f1, captures, 0)); | 605 Handle<String> f1_16 = RegExpImpl::StringToTwoByte(f1); |
| 606 CHECK(!Re2kInterpreter::Match(array, f1_16, captures, 0)); |
| 595 | 607 |
| 596 Handle<String> f2 = Factory::NewStringFromAscii(CStrVector("foo bar baz")); | 608 Handle<String> f2 = Factory::NewStringFromAscii(CStrVector("foo bar baz")); |
| 597 CHECK(Re2kInterpreter::Match(array, f2, captures, 0)); | 609 Handle<String> f2_16 = RegExpImpl::StringToTwoByte(f2); |
| 610 CHECK(Re2kInterpreter::Match(array, f2_16, captures, 0)); |
| 598 CHECK_EQ(0, captures[0]); | 611 CHECK_EQ(0, captures[0]); |
| 599 CHECK_EQ(2, captures[1]); | 612 CHECK_EQ(2, captures[1]); |
| 600 | 613 |
| 601 Handle<String> f3 = Factory::NewStringFromAscii(CStrVector("tomfoolery")); | 614 Handle<String> f3 = Factory::NewStringFromAscii(CStrVector("tomfoolery")); |
| 602 CHECK(Re2kInterpreter::Match(array, f3, captures, 0)); | 615 Handle<String> f3_16 = RegExpImpl::StringToTwoByte(f3); |
| 616 CHECK(Re2kInterpreter::Match(array, f3_16, captures, 0)); |
| 603 CHECK_EQ(0, captures[0]); | 617 CHECK_EQ(0, captures[0]); |
| 604 CHECK_EQ(5, captures[1]); | 618 CHECK_EQ(5, captures[1]); |
| 605 | 619 |
| 606 Handle<String> f4 = | 620 Handle<String> f4 = |
| 607 Factory::NewStringFromAscii(CStrVector("football buffoonery")); | 621 Factory::NewStringFromAscii(CStrVector("football buffoonery")); |
| 608 CHECK(Re2kInterpreter::Match(array, f4, captures, 0)); | 622 Handle<String> f4_16 = RegExpImpl::StringToTwoByte(f4); |
| 623 CHECK(Re2kInterpreter::Match(array, f4_16, captures, 0)); |
| 609 CHECK_EQ(0, captures[0]); | 624 CHECK_EQ(0, captures[0]); |
| 610 CHECK_EQ(14, captures[1]); | 625 CHECK_EQ(14, captures[1]); |
| 611 | 626 |
| 612 Handle<String> f5 = | 627 Handle<String> f5 = |
| 613 Factory::NewStringFromAscii(CStrVector("walking\nbarefoot")); | 628 Factory::NewStringFromAscii(CStrVector("walking\nbarefoot")); |
| 614 CHECK(!Re2kInterpreter::Match(array, f5, captures, 0)); | 629 Handle<String> f5_16 = RegExpImpl::StringToTwoByte(f5); |
| 630 CHECK(!Re2kInterpreter::Match(array, f5_16, captures, 0)); |
| 615 } | 631 } |
| 616 | 632 |
| 617 | 633 |
| 618 TEST(MacroAssembler) { | 634 TEST(MacroAssembler) { |
| 619 V8::Initialize(NULL); | 635 V8::Initialize(NULL); |
| 620 byte codes[1024]; | 636 byte codes[1024]; |
| 621 Re2kAssembler assembler(Vector<byte>(codes, 1024)); | 637 Re2kAssembler assembler(Vector<byte>(codes, 1024)); |
| 622 RegExpMacroAssemblerRe2k m(&assembler); | 638 RegExpMacroAssemblerRe2k m(&assembler); |
| 623 // ^f(o)o. | 639 // ^f(o)o. |
| 624 Label fail, fail2, start; | 640 Label fail, fail2, start; |
| (...skipping 30 matching lines...) Expand all Loading... |
| 655 m.Fail(); | 671 m.Fail(); |
| 656 | 672 |
| 657 v8::HandleScope scope; | 673 v8::HandleScope scope; |
| 658 | 674 |
| 659 Handle<ByteArray> array = Factory::NewByteArray(assembler.length()); | 675 Handle<ByteArray> array = Factory::NewByteArray(assembler.length()); |
| 660 assembler.Copy(array->GetDataStartAddress()); | 676 assembler.Copy(array->GetDataStartAddress()); |
| 661 int captures[5]; | 677 int captures[5]; |
| 662 | 678 |
| 663 Handle<String> f1 = | 679 Handle<String> f1 = |
| 664 Factory::NewStringFromAscii(CStrVector("foobar")); | 680 Factory::NewStringFromAscii(CStrVector("foobar")); |
| 665 CHECK(Re2kInterpreter::Match(array, f1, captures, 0)); | 681 Handle<String> f1_16 = RegExpImpl::StringToTwoByte(f1); |
| 682 CHECK(Re2kInterpreter::Match(array, f1_16, captures, 0)); |
| 666 CHECK_EQ(0, captures[0]); | 683 CHECK_EQ(0, captures[0]); |
| 667 CHECK_EQ(3, captures[1]); | 684 CHECK_EQ(3, captures[1]); |
| 668 CHECK_EQ(1, captures[2]); | 685 CHECK_EQ(1, captures[2]); |
| 669 CHECK_EQ(2, captures[3]); | 686 CHECK_EQ(2, captures[3]); |
| 670 CHECK_EQ(84, captures[4]); | 687 CHECK_EQ(84, captures[4]); |
| 671 | 688 |
| 672 Handle<String> f2 = | 689 Handle<String> f2 = |
| 673 Factory::NewStringFromAscii(CStrVector("barfoo")); | 690 Factory::NewStringFromAscii(CStrVector("barfoo")); |
| 674 CHECK(!Re2kInterpreter::Match(array, f2, captures, 0)); | 691 Handle<String> f2_16 = RegExpImpl::StringToTwoByte(f2); |
| 692 CHECK(!Re2kInterpreter::Match(array, f2_16, captures, 0)); |
| 675 CHECK_EQ(42, captures[0]); | 693 CHECK_EQ(42, captures[0]); |
| 676 } | 694 } |
| 677 | 695 |
| 678 | 696 |
| 679 TEST(AddInverseToTable) { | 697 TEST(AddInverseToTable) { |
| 680 static const int kLimit = 1000; | 698 static const int kLimit = 1000; |
| 681 static const int kRangeCount = 16; | 699 static const int kRangeCount = 16; |
| 682 for (int t = 0; t < 10; t++) { | 700 for (int t = 0; t < 10; t++) { |
| 683 ZoneScope zone_scope(DELETE_ON_EXIT); | 701 ZoneScope zone_scope(DELETE_ON_EXIT); |
| 684 ZoneList<CharacterRange>* ranges = | 702 ZoneList<CharacterRange>* ranges = |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 763 | 781 |
| 764 TEST(SimplePropagation) { | 782 TEST(SimplePropagation) { |
| 765 v8::HandleScope scope; | 783 v8::HandleScope scope; |
| 766 ZoneScope zone_scope(DELETE_ON_EXIT); | 784 ZoneScope zone_scope(DELETE_ON_EXIT); |
| 767 RegExpNode* node = Compile("(a|^b|c)"); | 785 RegExpNode* node = Compile("(a|^b|c)"); |
| 768 CHECK(node->info()->determine_start); | 786 CHECK(node->info()->determine_start); |
| 769 } | 787 } |
| 770 | 788 |
| 771 | 789 |
| 772 TEST(Graph) { | 790 TEST(Graph) { |
| 791 V8::Initialize(NULL); |
| 773 Execute("(a|^b|c)", "", true); | 792 Execute("(a|^b|c)", "", true); |
| 774 } | 793 } |
| OLD | NEW |