| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 84 #include "src/x87/regexp-macro-assembler-x87.h" | 84 #include "src/x87/regexp-macro-assembler-x87.h" |
| 85 #endif | 85 #endif |
| 86 #endif // V8_INTERPRETED_REGEXP | 86 #endif // V8_INTERPRETED_REGEXP |
| 87 #include "test/cctest/cctest.h" | 87 #include "test/cctest/cctest.h" |
| 88 | 88 |
| 89 using namespace v8::internal; | 89 using namespace v8::internal; |
| 90 | 90 |
| 91 | 91 |
| 92 static bool CheckParse(const char* input) { | 92 static bool CheckParse(const char* input) { |
| 93 v8::HandleScope scope(CcTest::isolate()); | 93 v8::HandleScope scope(CcTest::isolate()); |
| 94 Zone zone(CcTest::i_isolate()); | 94 Zone zone; |
| 95 FlatStringReader reader(CcTest::i_isolate(), CStrVector(input)); | 95 FlatStringReader reader(CcTest::i_isolate(), CStrVector(input)); |
| 96 RegExpCompileData result; | 96 RegExpCompileData result; |
| 97 return v8::internal::RegExpParser::ParseRegExp(&reader, false, false, &result, | 97 return v8::internal::RegExpParser::ParseRegExp( |
| 98 &zone); | 98 CcTest::i_isolate(), &zone, &reader, false, false, &result); |
| 99 } | 99 } |
| 100 | 100 |
| 101 | 101 |
| 102 static void CheckParseEq(const char* input, const char* expected) { | 102 static void CheckParseEq(const char* input, const char* expected) { |
| 103 v8::HandleScope scope(CcTest::isolate()); | 103 v8::HandleScope scope(CcTest::isolate()); |
| 104 Zone zone(CcTest::i_isolate()); | 104 Zone zone; |
| 105 FlatStringReader reader(CcTest::i_isolate(), CStrVector(input)); | 105 FlatStringReader reader(CcTest::i_isolate(), CStrVector(input)); |
| 106 RegExpCompileData result; | 106 RegExpCompileData result; |
| 107 CHECK(v8::internal::RegExpParser::ParseRegExp(&reader, false, false, &result, | 107 CHECK(v8::internal::RegExpParser::ParseRegExp( |
| 108 &zone)); | 108 CcTest::i_isolate(), &zone, &reader, false, false, &result)); |
| 109 CHECK(result.tree != NULL); | 109 CHECK(result.tree != NULL); |
| 110 CHECK(result.error.is_null()); | 110 CHECK(result.error.is_null()); |
| 111 std::ostringstream os; | 111 std::ostringstream os; |
| 112 result.tree->Print(os, &zone); | 112 result.tree->Print(os, &zone); |
| 113 CHECK_EQ(expected, os.str().c_str()); | 113 CHECK_EQ(expected, os.str().c_str()); |
| 114 } | 114 } |
| 115 | 115 |
| 116 | 116 |
| 117 static bool CheckSimple(const char* input) { | 117 static bool CheckSimple(const char* input) { |
| 118 v8::HandleScope scope(CcTest::isolate()); | 118 v8::HandleScope scope(CcTest::isolate()); |
| 119 Zone zone(CcTest::i_isolate()); | 119 Zone zone; |
| 120 FlatStringReader reader(CcTest::i_isolate(), CStrVector(input)); | 120 FlatStringReader reader(CcTest::i_isolate(), CStrVector(input)); |
| 121 RegExpCompileData result; | 121 RegExpCompileData result; |
| 122 CHECK(v8::internal::RegExpParser::ParseRegExp(&reader, false, false, &result, | 122 CHECK(v8::internal::RegExpParser::ParseRegExp( |
| 123 &zone)); | 123 CcTest::i_isolate(), &zone, &reader, false, false, &result)); |
| 124 CHECK(result.tree != NULL); | 124 CHECK(result.tree != NULL); |
| 125 CHECK(result.error.is_null()); | 125 CHECK(result.error.is_null()); |
| 126 return result.simple; | 126 return result.simple; |
| 127 } | 127 } |
| 128 | 128 |
| 129 struct MinMaxPair { | 129 struct MinMaxPair { |
| 130 int min_match; | 130 int min_match; |
| 131 int max_match; | 131 int max_match; |
| 132 }; | 132 }; |
| 133 | 133 |
| 134 | 134 |
| 135 static MinMaxPair CheckMinMaxMatch(const char* input) { | 135 static MinMaxPair CheckMinMaxMatch(const char* input) { |
| 136 v8::HandleScope scope(CcTest::isolate()); | 136 v8::HandleScope scope(CcTest::isolate()); |
| 137 Zone zone(CcTest::i_isolate()); | 137 Zone zone; |
| 138 FlatStringReader reader(CcTest::i_isolate(), CStrVector(input)); | 138 FlatStringReader reader(CcTest::i_isolate(), CStrVector(input)); |
| 139 RegExpCompileData result; | 139 RegExpCompileData result; |
| 140 CHECK(v8::internal::RegExpParser::ParseRegExp(&reader, false, false, &result, | 140 CHECK(v8::internal::RegExpParser::ParseRegExp( |
| 141 &zone)); | 141 CcTest::i_isolate(), &zone, &reader, false, false, &result)); |
| 142 CHECK(result.tree != NULL); | 142 CHECK(result.tree != NULL); |
| 143 CHECK(result.error.is_null()); | 143 CHECK(result.error.is_null()); |
| 144 int min_match = result.tree->min_match(); | 144 int min_match = result.tree->min_match(); |
| 145 int max_match = result.tree->max_match(); | 145 int max_match = result.tree->max_match(); |
| 146 MinMaxPair pair = { min_match, max_match }; | 146 MinMaxPair pair = { min_match, max_match }; |
| 147 return pair; | 147 return pair; |
| 148 } | 148 } |
| 149 | 149 |
| 150 | 150 |
| 151 #define CHECK_PARSE_ERROR(input) CHECK(!CheckParse(input)) | 151 #define CHECK_PARSE_ERROR(input) CHECK(!CheckParse(input)) |
| (...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 400 TEST(ParserRegression) { | 400 TEST(ParserRegression) { |
| 401 CheckParseEq("[A-Z$-][x]", "(! [A-Z $ -] [x])"); | 401 CheckParseEq("[A-Z$-][x]", "(! [A-Z $ -] [x])"); |
| 402 CheckParseEq("a{3,4*}", "(: 'a{3,' (# 0 - g '4') '}')"); | 402 CheckParseEq("a{3,4*}", "(: 'a{3,' (# 0 - g '4') '}')"); |
| 403 CheckParseEq("{", "'{'"); | 403 CheckParseEq("{", "'{'"); |
| 404 CheckParseEq("a|", "(| 'a' %)"); | 404 CheckParseEq("a|", "(| 'a' %)"); |
| 405 } | 405 } |
| 406 | 406 |
| 407 static void ExpectError(const char* input, | 407 static void ExpectError(const char* input, |
| 408 const char* expected) { | 408 const char* expected) { |
| 409 v8::HandleScope scope(CcTest::isolate()); | 409 v8::HandleScope scope(CcTest::isolate()); |
| 410 Zone zone(CcTest::i_isolate()); | 410 Zone zone; |
| 411 FlatStringReader reader(CcTest::i_isolate(), CStrVector(input)); | 411 FlatStringReader reader(CcTest::i_isolate(), CStrVector(input)); |
| 412 RegExpCompileData result; | 412 RegExpCompileData result; |
| 413 CHECK(!v8::internal::RegExpParser::ParseRegExp(&reader, false, false, &result, | 413 CHECK(!v8::internal::RegExpParser::ParseRegExp( |
| 414 &zone)); | 414 CcTest::i_isolate(), &zone, &reader, false, false, &result)); |
| 415 CHECK(result.tree == NULL); | 415 CHECK(result.tree == NULL); |
| 416 CHECK(!result.error.is_null()); | 416 CHECK(!result.error.is_null()); |
| 417 SmartArrayPointer<char> str = result.error->ToCString(ALLOW_NULLS); | 417 SmartArrayPointer<char> str = result.error->ToCString(ALLOW_NULLS); |
| 418 CHECK_EQ(expected, str.get()); | 418 CHECK_EQ(expected, str.get()); |
| 419 } | 419 } |
| 420 | 420 |
| 421 | 421 |
| 422 TEST(Errors) { | 422 TEST(Errors) { |
| 423 const char* kEndBackslash = "\\ at end of pattern"; | 423 const char* kEndBackslash = "\\ at end of pattern"; |
| 424 ExpectError("\\", kEndBackslash); | 424 ExpectError("\\", kEndBackslash); |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 469 return !IsWhiteSpaceOrLineTerminator(c); | 469 return !IsWhiteSpaceOrLineTerminator(c); |
| 470 } | 470 } |
| 471 | 471 |
| 472 | 472 |
| 473 static bool NotWord(uc16 c) { | 473 static bool NotWord(uc16 c) { |
| 474 return !IsRegExpWord(c); | 474 return !IsRegExpWord(c); |
| 475 } | 475 } |
| 476 | 476 |
| 477 | 477 |
| 478 static void TestCharacterClassEscapes(uc16 c, bool (pred)(uc16 c)) { | 478 static void TestCharacterClassEscapes(uc16 c, bool (pred)(uc16 c)) { |
| 479 Zone zone(CcTest::i_isolate()); | 479 Zone zone; |
| 480 ZoneList<CharacterRange>* ranges = | 480 ZoneList<CharacterRange>* ranges = |
| 481 new(&zone) ZoneList<CharacterRange>(2, &zone); | 481 new(&zone) ZoneList<CharacterRange>(2, &zone); |
| 482 CharacterRange::AddClassEscape(c, ranges, &zone); | 482 CharacterRange::AddClassEscape(c, ranges, &zone); |
| 483 for (unsigned i = 0; i < (1 << 16); i++) { | 483 for (unsigned i = 0; i < (1 << 16); i++) { |
| 484 bool in_class = false; | 484 bool in_class = false; |
| 485 for (int j = 0; !in_class && j < ranges->length(); j++) { | 485 for (int j = 0; !in_class && j < ranges->length(); j++) { |
| 486 CharacterRange& range = ranges->at(j); | 486 CharacterRange& range = ranges->at(j); |
| 487 in_class = (range.from() <= i && i <= range.to()); | 487 in_class = (range.from() <= i && i <= range.to()); |
| 488 } | 488 } |
| 489 CHECK_EQ(pred(i), in_class); | 489 CHECK_EQ(pred(i), in_class); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 500 TestCharacterClassEscapes('w', IsRegExpWord); | 500 TestCharacterClassEscapes('w', IsRegExpWord); |
| 501 TestCharacterClassEscapes('W', NotWord); | 501 TestCharacterClassEscapes('W', NotWord); |
| 502 } | 502 } |
| 503 | 503 |
| 504 | 504 |
| 505 static RegExpNode* Compile(const char* input, bool multiline, bool unicode, | 505 static RegExpNode* Compile(const char* input, bool multiline, bool unicode, |
| 506 bool is_one_byte, Zone* zone) { | 506 bool is_one_byte, Zone* zone) { |
| 507 Isolate* isolate = CcTest::i_isolate(); | 507 Isolate* isolate = CcTest::i_isolate(); |
| 508 FlatStringReader reader(isolate, CStrVector(input)); | 508 FlatStringReader reader(isolate, CStrVector(input)); |
| 509 RegExpCompileData compile_data; | 509 RegExpCompileData compile_data; |
| 510 if (!v8::internal::RegExpParser::ParseRegExp(&reader, multiline, unicode, | 510 if (!v8::internal::RegExpParser::ParseRegExp(CcTest::i_isolate(), zone, |
| 511 &compile_data, zone)) | 511 &reader, multiline, unicode, |
| 512 &compile_data)) |
| 512 return NULL; | 513 return NULL; |
| 513 Handle<String> pattern = isolate->factory() | 514 Handle<String> pattern = isolate->factory() |
| 514 ->NewStringFromUtf8(CStrVector(input)) | 515 ->NewStringFromUtf8(CStrVector(input)) |
| 515 .ToHandleChecked(); | 516 .ToHandleChecked(); |
| 516 Handle<String> sample_subject = | 517 Handle<String> sample_subject = |
| 517 isolate->factory()->NewStringFromUtf8(CStrVector("")).ToHandleChecked(); | 518 isolate->factory()->NewStringFromUtf8(CStrVector("")).ToHandleChecked(); |
| 518 RegExpEngine::Compile(&compile_data, false, false, multiline, false, pattern, | 519 RegExpEngine::Compile(isolate, zone, &compile_data, false, false, multiline, |
| 519 sample_subject, is_one_byte, zone); | 520 false, pattern, sample_subject, is_one_byte); |
| 520 return compile_data.node; | 521 return compile_data.node; |
| 521 } | 522 } |
| 522 | 523 |
| 523 | 524 |
| 524 static void Execute(const char* input, bool multiline, bool unicode, | 525 static void Execute(const char* input, bool multiline, bool unicode, |
| 525 bool is_one_byte, bool dot_output = false) { | 526 bool is_one_byte, bool dot_output = false) { |
| 526 v8::HandleScope scope(CcTest::isolate()); | 527 v8::HandleScope scope(CcTest::isolate()); |
| 527 Zone zone(CcTest::i_isolate()); | 528 Zone zone; |
| 528 RegExpNode* node = Compile(input, multiline, unicode, is_one_byte, &zone); | 529 RegExpNode* node = Compile(input, multiline, unicode, is_one_byte, &zone); |
| 529 USE(node); | 530 USE(node); |
| 530 #ifdef DEBUG | 531 #ifdef DEBUG |
| 531 if (dot_output) { | 532 if (dot_output) { |
| 532 RegExpEngine::DotPrint(input, node, false); | 533 RegExpEngine::DotPrint(input, node, false); |
| 533 } | 534 } |
| 534 #endif // DEBUG | 535 #endif // DEBUG |
| 535 } | 536 } |
| 536 | 537 |
| 537 | 538 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 555 const int TestConfig::kNoKey = 0; | 556 const int TestConfig::kNoKey = 0; |
| 556 | 557 |
| 557 | 558 |
| 558 static unsigned PseudoRandom(int i, int j) { | 559 static unsigned PseudoRandom(int i, int j) { |
| 559 return ~(~((i * 781) ^ (j * 329))); | 560 return ~(~((i * 781) ^ (j * 329))); |
| 560 } | 561 } |
| 561 | 562 |
| 562 | 563 |
| 563 TEST(SplayTreeSimple) { | 564 TEST(SplayTreeSimple) { |
| 564 static const unsigned kLimit = 1000; | 565 static const unsigned kLimit = 1000; |
| 565 Zone zone(CcTest::i_isolate()); | 566 Zone zone; |
| 566 ZoneSplayTree<TestConfig> tree(&zone); | 567 ZoneSplayTree<TestConfig> tree(&zone); |
| 567 bool seen[kLimit]; | 568 bool seen[kLimit]; |
| 568 for (unsigned i = 0; i < kLimit; i++) seen[i] = false; | 569 for (unsigned i = 0; i < kLimit; i++) seen[i] = false; |
| 569 #define CHECK_MAPS_EQUAL() do { \ | 570 #define CHECK_MAPS_EQUAL() do { \ |
| 570 for (unsigned k = 0; k < kLimit; k++) \ | 571 for (unsigned k = 0; k < kLimit; k++) \ |
| 571 CHECK_EQ(seen[k], tree.Find(k, &loc)); \ | 572 CHECK_EQ(seen[k], tree.Find(k, &loc)); \ |
| 572 } while (false) | 573 } while (false) |
| 573 for (int i = 0; i < 50; i++) { | 574 for (int i = 0; i < 50; i++) { |
| 574 for (int j = 0; j < 50; j++) { | 575 for (int j = 0; j < 50; j++) { |
| 575 unsigned next = PseudoRandom(i, j) % kLimit; | 576 unsigned next = PseudoRandom(i, j) % kLimit; |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 622 Vector<uc16> range(ranges[i], 2 * kRangeSize); | 623 Vector<uc16> range(ranges[i], 2 * kRangeSize); |
| 623 for (int j = 0; j < 2 * kRangeSize; j++) { | 624 for (int j = 0; j < 2 * kRangeSize; j++) { |
| 624 range[j] = PseudoRandom(i + 25, j + 87) % kLimit; | 625 range[j] = PseudoRandom(i + 25, j + 87) % kLimit; |
| 625 } | 626 } |
| 626 range.Sort(); | 627 range.Sort(); |
| 627 for (int j = 1; j < 2 * kRangeSize; j++) { | 628 for (int j = 1; j < 2 * kRangeSize; j++) { |
| 628 CHECK(range[j-1] <= range[j]); | 629 CHECK(range[j-1] <= range[j]); |
| 629 } | 630 } |
| 630 } | 631 } |
| 631 // Enter test data into dispatch table. | 632 // Enter test data into dispatch table. |
| 632 Zone zone(CcTest::i_isolate()); | 633 Zone zone; |
| 633 DispatchTable table(&zone); | 634 DispatchTable table(&zone); |
| 634 for (int i = 0; i < kRangeCount; i++) { | 635 for (int i = 0; i < kRangeCount; i++) { |
| 635 uc16* range = ranges[i]; | 636 uc16* range = ranges[i]; |
| 636 for (int j = 0; j < 2 * kRangeSize; j += 2) | 637 for (int j = 0; j < 2 * kRangeSize; j += 2) |
| 637 table.AddRange(CharacterRange(range[j], range[j + 1]), i, &zone); | 638 table.AddRange(CharacterRange(range[j], range[j + 1]), i, &zone); |
| 638 } | 639 } |
| 639 // Check that the table looks as we would expect | 640 // Check that the table looks as we would expect |
| 640 for (int p = 0; p < kLimit; p++) { | 641 for (int p = 0; p < kLimit; p++) { |
| 641 OutSet* outs = table.Get(p); | 642 OutSet* outs = table.Get(p); |
| 642 for (int j = 0; j < kRangeCount; j++) { | 643 for (int j = 0; j < kRangeCount; j++) { |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 734 0, | 735 0, |
| 735 CcTest::i_isolate()); | 736 CcTest::i_isolate()); |
| 736 } | 737 } |
| 737 | 738 |
| 738 | 739 |
| 739 TEST(MacroAssemblerNativeSuccess) { | 740 TEST(MacroAssemblerNativeSuccess) { |
| 740 v8::V8::Initialize(); | 741 v8::V8::Initialize(); |
| 741 ContextInitializer initializer; | 742 ContextInitializer initializer; |
| 742 Isolate* isolate = CcTest::i_isolate(); | 743 Isolate* isolate = CcTest::i_isolate(); |
| 743 Factory* factory = isolate->factory(); | 744 Factory* factory = isolate->factory(); |
| 744 Zone zone(isolate); | 745 Zone zone; |
| 745 | 746 |
| 746 ArchRegExpMacroAssembler m(NativeRegExpMacroAssembler::LATIN1, 4, &zone); | 747 ArchRegExpMacroAssembler m(isolate, &zone, NativeRegExpMacroAssembler::LATIN1, |
| 748 4); |
| 747 | 749 |
| 748 m.Succeed(); | 750 m.Succeed(); |
| 749 | 751 |
| 750 Handle<String> source = factory->NewStringFromStaticChars(""); | 752 Handle<String> source = factory->NewStringFromStaticChars(""); |
| 751 Handle<Object> code_object = m.GetCode(source); | 753 Handle<Object> code_object = m.GetCode(source); |
| 752 Handle<Code> code = Handle<Code>::cast(code_object); | 754 Handle<Code> code = Handle<Code>::cast(code_object); |
| 753 | 755 |
| 754 int captures[4] = {42, 37, 87, 117}; | 756 int captures[4] = {42, 37, 87, 117}; |
| 755 Handle<String> input = factory->NewStringFromStaticChars("foofoo"); | 757 Handle<String> input = factory->NewStringFromStaticChars("foofoo"); |
| 756 Handle<SeqOneByteString> seq_input = Handle<SeqOneByteString>::cast(input); | 758 Handle<SeqOneByteString> seq_input = Handle<SeqOneByteString>::cast(input); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 771 CHECK_EQ(-1, captures[2]); | 773 CHECK_EQ(-1, captures[2]); |
| 772 CHECK_EQ(-1, captures[3]); | 774 CHECK_EQ(-1, captures[3]); |
| 773 } | 775 } |
| 774 | 776 |
| 775 | 777 |
| 776 TEST(MacroAssemblerNativeSimple) { | 778 TEST(MacroAssemblerNativeSimple) { |
| 777 v8::V8::Initialize(); | 779 v8::V8::Initialize(); |
| 778 ContextInitializer initializer; | 780 ContextInitializer initializer; |
| 779 Isolate* isolate = CcTest::i_isolate(); | 781 Isolate* isolate = CcTest::i_isolate(); |
| 780 Factory* factory = isolate->factory(); | 782 Factory* factory = isolate->factory(); |
| 781 Zone zone(isolate); | 783 Zone zone; |
| 782 | 784 |
| 783 ArchRegExpMacroAssembler m(NativeRegExpMacroAssembler::LATIN1, 4, &zone); | 785 ArchRegExpMacroAssembler m(isolate, &zone, NativeRegExpMacroAssembler::LATIN1, |
| 786 4); |
| 784 | 787 |
| 785 Label fail, backtrack; | 788 Label fail, backtrack; |
| 786 m.PushBacktrack(&fail); | 789 m.PushBacktrack(&fail); |
| 787 m.CheckNotAtStart(NULL); | 790 m.CheckNotAtStart(NULL); |
| 788 m.LoadCurrentCharacter(2, NULL); | 791 m.LoadCurrentCharacter(2, NULL); |
| 789 m.CheckNotCharacter('o', NULL); | 792 m.CheckNotCharacter('o', NULL); |
| 790 m.LoadCurrentCharacter(1, NULL, false); | 793 m.LoadCurrentCharacter(1, NULL, false); |
| 791 m.CheckNotCharacter('o', NULL); | 794 m.CheckNotCharacter('o', NULL); |
| 792 m.LoadCurrentCharacter(0, NULL, false); | 795 m.LoadCurrentCharacter(0, NULL, false); |
| 793 m.CheckNotCharacter('f', NULL); | 796 m.CheckNotCharacter('f', NULL); |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 837 | 840 |
| 838 CHECK_EQ(NativeRegExpMacroAssembler::FAILURE, result); | 841 CHECK_EQ(NativeRegExpMacroAssembler::FAILURE, result); |
| 839 } | 842 } |
| 840 | 843 |
| 841 | 844 |
| 842 TEST(MacroAssemblerNativeSimpleUC16) { | 845 TEST(MacroAssemblerNativeSimpleUC16) { |
| 843 v8::V8::Initialize(); | 846 v8::V8::Initialize(); |
| 844 ContextInitializer initializer; | 847 ContextInitializer initializer; |
| 845 Isolate* isolate = CcTest::i_isolate(); | 848 Isolate* isolate = CcTest::i_isolate(); |
| 846 Factory* factory = isolate->factory(); | 849 Factory* factory = isolate->factory(); |
| 847 Zone zone(isolate); | 850 Zone zone; |
| 848 | 851 |
| 849 ArchRegExpMacroAssembler m(NativeRegExpMacroAssembler::UC16, 4, &zone); | 852 ArchRegExpMacroAssembler m(isolate, &zone, NativeRegExpMacroAssembler::UC16, |
| 853 4); |
| 850 | 854 |
| 851 Label fail, backtrack; | 855 Label fail, backtrack; |
| 852 m.PushBacktrack(&fail); | 856 m.PushBacktrack(&fail); |
| 853 m.CheckNotAtStart(NULL); | 857 m.CheckNotAtStart(NULL); |
| 854 m.LoadCurrentCharacter(2, NULL); | 858 m.LoadCurrentCharacter(2, NULL); |
| 855 m.CheckNotCharacter('o', NULL); | 859 m.CheckNotCharacter('o', NULL); |
| 856 m.LoadCurrentCharacter(1, NULL, false); | 860 m.LoadCurrentCharacter(1, NULL, false); |
| 857 m.CheckNotCharacter('o', NULL); | 861 m.CheckNotCharacter('o', NULL); |
| 858 m.LoadCurrentCharacter(0, NULL, false); | 862 m.LoadCurrentCharacter(0, NULL, false); |
| 859 m.CheckNotCharacter('f', NULL); | 863 m.CheckNotCharacter('f', NULL); |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 909 | 913 |
| 910 CHECK_EQ(NativeRegExpMacroAssembler::FAILURE, result); | 914 CHECK_EQ(NativeRegExpMacroAssembler::FAILURE, result); |
| 911 } | 915 } |
| 912 | 916 |
| 913 | 917 |
| 914 TEST(MacroAssemblerNativeBacktrack) { | 918 TEST(MacroAssemblerNativeBacktrack) { |
| 915 v8::V8::Initialize(); | 919 v8::V8::Initialize(); |
| 916 ContextInitializer initializer; | 920 ContextInitializer initializer; |
| 917 Isolate* isolate = CcTest::i_isolate(); | 921 Isolate* isolate = CcTest::i_isolate(); |
| 918 Factory* factory = isolate->factory(); | 922 Factory* factory = isolate->factory(); |
| 919 Zone zone(isolate); | 923 Zone zone; |
| 920 | 924 |
| 921 ArchRegExpMacroAssembler m(NativeRegExpMacroAssembler::LATIN1, 0, &zone); | 925 ArchRegExpMacroAssembler m(isolate, &zone, NativeRegExpMacroAssembler::LATIN1, |
| 926 0); |
| 922 | 927 |
| 923 Label fail; | 928 Label fail; |
| 924 Label backtrack; | 929 Label backtrack; |
| 925 m.LoadCurrentCharacter(10, &fail); | 930 m.LoadCurrentCharacter(10, &fail); |
| 926 m.Succeed(); | 931 m.Succeed(); |
| 927 m.Bind(&fail); | 932 m.Bind(&fail); |
| 928 m.PushBacktrack(&backtrack); | 933 m.PushBacktrack(&backtrack); |
| 929 m.LoadCurrentCharacter(10, NULL); | 934 m.LoadCurrentCharacter(10, NULL); |
| 930 m.Succeed(); | 935 m.Succeed(); |
| 931 m.Bind(&backtrack); | 936 m.Bind(&backtrack); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 949 | 954 |
| 950 CHECK_EQ(NativeRegExpMacroAssembler::FAILURE, result); | 955 CHECK_EQ(NativeRegExpMacroAssembler::FAILURE, result); |
| 951 } | 956 } |
| 952 | 957 |
| 953 | 958 |
| 954 TEST(MacroAssemblerNativeBackReferenceLATIN1) { | 959 TEST(MacroAssemblerNativeBackReferenceLATIN1) { |
| 955 v8::V8::Initialize(); | 960 v8::V8::Initialize(); |
| 956 ContextInitializer initializer; | 961 ContextInitializer initializer; |
| 957 Isolate* isolate = CcTest::i_isolate(); | 962 Isolate* isolate = CcTest::i_isolate(); |
| 958 Factory* factory = isolate->factory(); | 963 Factory* factory = isolate->factory(); |
| 959 Zone zone(isolate); | 964 Zone zone; |
| 960 | 965 |
| 961 ArchRegExpMacroAssembler m(NativeRegExpMacroAssembler::LATIN1, 4, &zone); | 966 ArchRegExpMacroAssembler m(isolate, &zone, NativeRegExpMacroAssembler::LATIN1, |
| 967 4); |
| 962 | 968 |
| 963 m.WriteCurrentPositionToRegister(0, 0); | 969 m.WriteCurrentPositionToRegister(0, 0); |
| 964 m.AdvanceCurrentPosition(2); | 970 m.AdvanceCurrentPosition(2); |
| 965 m.WriteCurrentPositionToRegister(1, 0); | 971 m.WriteCurrentPositionToRegister(1, 0); |
| 966 Label nomatch; | 972 Label nomatch; |
| 967 m.CheckNotBackReference(0, &nomatch); | 973 m.CheckNotBackReference(0, &nomatch); |
| 968 m.Fail(); | 974 m.Fail(); |
| 969 m.Bind(&nomatch); | 975 m.Bind(&nomatch); |
| 970 m.AdvanceCurrentPosition(2); | 976 m.AdvanceCurrentPosition(2); |
| 971 Label missing_match; | 977 Label missing_match; |
| (...skipping 26 matching lines...) Expand all Loading... |
| 998 CHECK_EQ(6, output[2]); | 1004 CHECK_EQ(6, output[2]); |
| 999 CHECK_EQ(-1, output[3]); | 1005 CHECK_EQ(-1, output[3]); |
| 1000 } | 1006 } |
| 1001 | 1007 |
| 1002 | 1008 |
| 1003 TEST(MacroAssemblerNativeBackReferenceUC16) { | 1009 TEST(MacroAssemblerNativeBackReferenceUC16) { |
| 1004 v8::V8::Initialize(); | 1010 v8::V8::Initialize(); |
| 1005 ContextInitializer initializer; | 1011 ContextInitializer initializer; |
| 1006 Isolate* isolate = CcTest::i_isolate(); | 1012 Isolate* isolate = CcTest::i_isolate(); |
| 1007 Factory* factory = isolate->factory(); | 1013 Factory* factory = isolate->factory(); |
| 1008 Zone zone(isolate); | 1014 Zone zone; |
| 1009 | 1015 |
| 1010 ArchRegExpMacroAssembler m(NativeRegExpMacroAssembler::UC16, 4, &zone); | 1016 ArchRegExpMacroAssembler m(isolate, &zone, NativeRegExpMacroAssembler::UC16, |
| 1017 4); |
| 1011 | 1018 |
| 1012 m.WriteCurrentPositionToRegister(0, 0); | 1019 m.WriteCurrentPositionToRegister(0, 0); |
| 1013 m.AdvanceCurrentPosition(2); | 1020 m.AdvanceCurrentPosition(2); |
| 1014 m.WriteCurrentPositionToRegister(1, 0); | 1021 m.WriteCurrentPositionToRegister(1, 0); |
| 1015 Label nomatch; | 1022 Label nomatch; |
| 1016 m.CheckNotBackReference(0, &nomatch); | 1023 m.CheckNotBackReference(0, &nomatch); |
| 1017 m.Fail(); | 1024 m.Fail(); |
| 1018 m.Bind(&nomatch); | 1025 m.Bind(&nomatch); |
| 1019 m.AdvanceCurrentPosition(2); | 1026 m.AdvanceCurrentPosition(2); |
| 1020 Label missing_match; | 1027 Label missing_match; |
| (...skipping 29 matching lines...) Expand all Loading... |
| 1050 CHECK_EQ(-1, output[3]); | 1057 CHECK_EQ(-1, output[3]); |
| 1051 } | 1058 } |
| 1052 | 1059 |
| 1053 | 1060 |
| 1054 | 1061 |
| 1055 TEST(MacroAssemblernativeAtStart) { | 1062 TEST(MacroAssemblernativeAtStart) { |
| 1056 v8::V8::Initialize(); | 1063 v8::V8::Initialize(); |
| 1057 ContextInitializer initializer; | 1064 ContextInitializer initializer; |
| 1058 Isolate* isolate = CcTest::i_isolate(); | 1065 Isolate* isolate = CcTest::i_isolate(); |
| 1059 Factory* factory = isolate->factory(); | 1066 Factory* factory = isolate->factory(); |
| 1060 Zone zone(isolate); | 1067 Zone zone; |
| 1061 | 1068 |
| 1062 ArchRegExpMacroAssembler m(NativeRegExpMacroAssembler::LATIN1, 0, &zone); | 1069 ArchRegExpMacroAssembler m(isolate, &zone, NativeRegExpMacroAssembler::LATIN1, |
| 1070 0); |
| 1063 | 1071 |
| 1064 Label not_at_start, newline, fail; | 1072 Label not_at_start, newline, fail; |
| 1065 m.CheckNotAtStart(¬_at_start); | 1073 m.CheckNotAtStart(¬_at_start); |
| 1066 // Check that prevchar = '\n' and current = 'f'. | 1074 // Check that prevchar = '\n' and current = 'f'. |
| 1067 m.CheckCharacter('\n', &newline); | 1075 m.CheckCharacter('\n', &newline); |
| 1068 m.Bind(&fail); | 1076 m.Bind(&fail); |
| 1069 m.Fail(); | 1077 m.Fail(); |
| 1070 m.Bind(&newline); | 1078 m.Bind(&newline); |
| 1071 m.LoadCurrentCharacter(0, &fail); | 1079 m.LoadCurrentCharacter(0, &fail); |
| 1072 m.CheckNotCharacter('f', &fail); | 1080 m.CheckNotCharacter('f', &fail); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1109 | 1117 |
| 1110 CHECK_EQ(NativeRegExpMacroAssembler::SUCCESS, result); | 1118 CHECK_EQ(NativeRegExpMacroAssembler::SUCCESS, result); |
| 1111 } | 1119 } |
| 1112 | 1120 |
| 1113 | 1121 |
| 1114 TEST(MacroAssemblerNativeBackRefNoCase) { | 1122 TEST(MacroAssemblerNativeBackRefNoCase) { |
| 1115 v8::V8::Initialize(); | 1123 v8::V8::Initialize(); |
| 1116 ContextInitializer initializer; | 1124 ContextInitializer initializer; |
| 1117 Isolate* isolate = CcTest::i_isolate(); | 1125 Isolate* isolate = CcTest::i_isolate(); |
| 1118 Factory* factory = isolate->factory(); | 1126 Factory* factory = isolate->factory(); |
| 1119 Zone zone(isolate); | 1127 Zone zone; |
| 1120 | 1128 |
| 1121 ArchRegExpMacroAssembler m(NativeRegExpMacroAssembler::LATIN1, 4, &zone); | 1129 ArchRegExpMacroAssembler m(isolate, &zone, NativeRegExpMacroAssembler::LATIN1, |
| 1130 4); |
| 1122 | 1131 |
| 1123 Label fail, succ; | 1132 Label fail, succ; |
| 1124 | 1133 |
| 1125 m.WriteCurrentPositionToRegister(0, 0); | 1134 m.WriteCurrentPositionToRegister(0, 0); |
| 1126 m.WriteCurrentPositionToRegister(2, 0); | 1135 m.WriteCurrentPositionToRegister(2, 0); |
| 1127 m.AdvanceCurrentPosition(3); | 1136 m.AdvanceCurrentPosition(3); |
| 1128 m.WriteCurrentPositionToRegister(3, 0); | 1137 m.WriteCurrentPositionToRegister(3, 0); |
| 1129 m.CheckNotBackReferenceIgnoreCase(2, &fail); // Match "AbC". | 1138 m.CheckNotBackReferenceIgnoreCase(2, &fail); // Match "AbC". |
| 1130 m.CheckNotBackReferenceIgnoreCase(2, &fail); // Match "ABC". | 1139 m.CheckNotBackReferenceIgnoreCase(2, &fail); // Match "ABC". |
| 1131 Label expected_fail; | 1140 Label expected_fail; |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1167 CHECK_EQ(3, output[3]); | 1176 CHECK_EQ(3, output[3]); |
| 1168 } | 1177 } |
| 1169 | 1178 |
| 1170 | 1179 |
| 1171 | 1180 |
| 1172 TEST(MacroAssemblerNativeRegisters) { | 1181 TEST(MacroAssemblerNativeRegisters) { |
| 1173 v8::V8::Initialize(); | 1182 v8::V8::Initialize(); |
| 1174 ContextInitializer initializer; | 1183 ContextInitializer initializer; |
| 1175 Isolate* isolate = CcTest::i_isolate(); | 1184 Isolate* isolate = CcTest::i_isolate(); |
| 1176 Factory* factory = isolate->factory(); | 1185 Factory* factory = isolate->factory(); |
| 1177 Zone zone(isolate); | 1186 Zone zone; |
| 1178 | 1187 |
| 1179 ArchRegExpMacroAssembler m(NativeRegExpMacroAssembler::LATIN1, 6, &zone); | 1188 ArchRegExpMacroAssembler m(isolate, &zone, NativeRegExpMacroAssembler::LATIN1, |
| 1189 6); |
| 1180 | 1190 |
| 1181 uc16 foo_chars[3] = {'f', 'o', 'o'}; | 1191 uc16 foo_chars[3] = {'f', 'o', 'o'}; |
| 1182 Vector<const uc16> foo(foo_chars, 3); | 1192 Vector<const uc16> foo(foo_chars, 3); |
| 1183 | 1193 |
| 1184 enum registers { out1, out2, out3, out4, out5, out6, sp, loop_cnt }; | 1194 enum registers { out1, out2, out3, out4, out5, out6, sp, loop_cnt }; |
| 1185 Label fail; | 1195 Label fail; |
| 1186 Label backtrack; | 1196 Label backtrack; |
| 1187 m.WriteCurrentPositionToRegister(out1, 0); // Output: [0] | 1197 m.WriteCurrentPositionToRegister(out1, 0); // Output: [0] |
| 1188 m.PushRegister(out1, RegExpMacroAssembler::kNoStackLimitCheck); | 1198 m.PushRegister(out1, RegExpMacroAssembler::kNoStackLimitCheck); |
| 1189 m.PushBacktrack(&backtrack); | 1199 m.PushBacktrack(&backtrack); |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1268 CHECK_EQ(9, output[4]); | 1278 CHECK_EQ(9, output[4]); |
| 1269 CHECK_EQ(-1, output[5]); | 1279 CHECK_EQ(-1, output[5]); |
| 1270 } | 1280 } |
| 1271 | 1281 |
| 1272 | 1282 |
| 1273 TEST(MacroAssemblerStackOverflow) { | 1283 TEST(MacroAssemblerStackOverflow) { |
| 1274 v8::V8::Initialize(); | 1284 v8::V8::Initialize(); |
| 1275 ContextInitializer initializer; | 1285 ContextInitializer initializer; |
| 1276 Isolate* isolate = CcTest::i_isolate(); | 1286 Isolate* isolate = CcTest::i_isolate(); |
| 1277 Factory* factory = isolate->factory(); | 1287 Factory* factory = isolate->factory(); |
| 1278 Zone zone(isolate); | 1288 Zone zone; |
| 1279 | 1289 |
| 1280 ArchRegExpMacroAssembler m(NativeRegExpMacroAssembler::LATIN1, 0, &zone); | 1290 ArchRegExpMacroAssembler m(isolate, &zone, NativeRegExpMacroAssembler::LATIN1, |
| 1291 0); |
| 1281 | 1292 |
| 1282 Label loop; | 1293 Label loop; |
| 1283 m.Bind(&loop); | 1294 m.Bind(&loop); |
| 1284 m.PushBacktrack(&loop); | 1295 m.PushBacktrack(&loop); |
| 1285 m.GoTo(&loop); | 1296 m.GoTo(&loop); |
| 1286 | 1297 |
| 1287 Handle<String> source = | 1298 Handle<String> source = |
| 1288 factory->NewStringFromStaticChars("<stack overflow test>"); | 1299 factory->NewStringFromStaticChars("<stack overflow test>"); |
| 1289 Handle<Object> code_object = m.GetCode(source); | 1300 Handle<Object> code_object = m.GetCode(source); |
| 1290 Handle<Code> code = Handle<Code>::cast(code_object); | 1301 Handle<Code> code = Handle<Code>::cast(code_object); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 1306 CHECK(isolate->has_pending_exception()); | 1317 CHECK(isolate->has_pending_exception()); |
| 1307 isolate->clear_pending_exception(); | 1318 isolate->clear_pending_exception(); |
| 1308 } | 1319 } |
| 1309 | 1320 |
| 1310 | 1321 |
| 1311 TEST(MacroAssemblerNativeLotsOfRegisters) { | 1322 TEST(MacroAssemblerNativeLotsOfRegisters) { |
| 1312 v8::V8::Initialize(); | 1323 v8::V8::Initialize(); |
| 1313 ContextInitializer initializer; | 1324 ContextInitializer initializer; |
| 1314 Isolate* isolate = CcTest::i_isolate(); | 1325 Isolate* isolate = CcTest::i_isolate(); |
| 1315 Factory* factory = isolate->factory(); | 1326 Factory* factory = isolate->factory(); |
| 1316 Zone zone(isolate); | 1327 Zone zone; |
| 1317 | 1328 |
| 1318 ArchRegExpMacroAssembler m(NativeRegExpMacroAssembler::LATIN1, 2, &zone); | 1329 ArchRegExpMacroAssembler m(isolate, &zone, NativeRegExpMacroAssembler::LATIN1, |
| 1330 2); |
| 1319 | 1331 |
| 1320 // At least 2048, to ensure the allocated space for registers | 1332 // At least 2048, to ensure the allocated space for registers |
| 1321 // span one full page. | 1333 // span one full page. |
| 1322 const int large_number = 8000; | 1334 const int large_number = 8000; |
| 1323 m.WriteCurrentPositionToRegister(large_number, 42); | 1335 m.WriteCurrentPositionToRegister(large_number, 42); |
| 1324 m.WriteCurrentPositionToRegister(0, 0); | 1336 m.WriteCurrentPositionToRegister(0, 0); |
| 1325 m.WriteCurrentPositionToRegister(1, 1); | 1337 m.WriteCurrentPositionToRegister(1, 1); |
| 1326 Label done; | 1338 Label done; |
| 1327 m.CheckNotBackReference(0, &done); // Performs a system-stack push. | 1339 m.CheckNotBackReference(0, &done); // Performs a system-stack push. |
| 1328 m.Bind(&done); | 1340 m.Bind(&done); |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1420 CHECK_EQ(42, captures[0]); | 1432 CHECK_EQ(42, captures[0]); |
| 1421 } | 1433 } |
| 1422 | 1434 |
| 1423 #endif // V8_INTERPRETED_REGEXP | 1435 #endif // V8_INTERPRETED_REGEXP |
| 1424 | 1436 |
| 1425 | 1437 |
| 1426 TEST(AddInverseToTable) { | 1438 TEST(AddInverseToTable) { |
| 1427 static const int kLimit = 1000; | 1439 static const int kLimit = 1000; |
| 1428 static const int kRangeCount = 16; | 1440 static const int kRangeCount = 16; |
| 1429 for (int t = 0; t < 10; t++) { | 1441 for (int t = 0; t < 10; t++) { |
| 1430 Zone zone(CcTest::i_isolate()); | 1442 Zone zone; |
| 1431 ZoneList<CharacterRange>* ranges = | 1443 ZoneList<CharacterRange>* ranges = |
| 1432 new(&zone) ZoneList<CharacterRange>(kRangeCount, &zone); | 1444 new(&zone) ZoneList<CharacterRange>(kRangeCount, &zone); |
| 1433 for (int i = 0; i < kRangeCount; i++) { | 1445 for (int i = 0; i < kRangeCount; i++) { |
| 1434 int from = PseudoRandom(t + 87, i + 25) % kLimit; | 1446 int from = PseudoRandom(t + 87, i + 25) % kLimit; |
| 1435 int to = from + (PseudoRandom(i + 87, t + 25) % (kLimit / 20)); | 1447 int to = from + (PseudoRandom(i + 87, t + 25) % (kLimit / 20)); |
| 1436 if (to > kLimit) to = kLimit; | 1448 if (to > kLimit) to = kLimit; |
| 1437 ranges->Add(CharacterRange(from, to), &zone); | 1449 ranges->Add(CharacterRange(from, to), &zone); |
| 1438 } | 1450 } |
| 1439 DispatchTable table(&zone); | 1451 DispatchTable table(&zone); |
| 1440 DispatchTableConstructor cons(&table, false, &zone); | 1452 DispatchTableConstructor cons(&table, false, &zone); |
| 1441 cons.set_choice_index(0); | 1453 cons.set_choice_index(0); |
| 1442 cons.AddInverse(ranges); | 1454 cons.AddInverse(ranges); |
| 1443 for (int i = 0; i < kLimit; i++) { | 1455 for (int i = 0; i < kLimit; i++) { |
| 1444 bool is_on = false; | 1456 bool is_on = false; |
| 1445 for (int j = 0; !is_on && j < kRangeCount; j++) | 1457 for (int j = 0; !is_on && j < kRangeCount; j++) |
| 1446 is_on = ranges->at(j).Contains(i); | 1458 is_on = ranges->at(j).Contains(i); |
| 1447 OutSet* set = table.Get(i); | 1459 OutSet* set = table.Get(i); |
| 1448 CHECK_EQ(is_on, set->Get(0) == false); | 1460 CHECK_EQ(is_on, set->Get(0) == false); |
| 1449 } | 1461 } |
| 1450 } | 1462 } |
| 1451 Zone zone(CcTest::i_isolate()); | 1463 Zone zone; |
| 1452 ZoneList<CharacterRange>* ranges = | 1464 ZoneList<CharacterRange>* ranges = |
| 1453 new(&zone) ZoneList<CharacterRange>(1, &zone); | 1465 new(&zone) ZoneList<CharacterRange>(1, &zone); |
| 1454 ranges->Add(CharacterRange(0xFFF0, 0xFFFE), &zone); | 1466 ranges->Add(CharacterRange(0xFFF0, 0xFFFE), &zone); |
| 1455 DispatchTable table(&zone); | 1467 DispatchTable table(&zone); |
| 1456 DispatchTableConstructor cons(&table, false, &zone); | 1468 DispatchTableConstructor cons(&table, false, &zone); |
| 1457 cons.set_choice_index(0); | 1469 cons.set_choice_index(0); |
| 1458 cons.AddInverse(ranges); | 1470 cons.AddInverse(ranges); |
| 1459 CHECK(!table.Get(0xFFFE)->Get(0)); | 1471 CHECK(!table.Get(0xFFFE)->Get(0)); |
| 1460 CHECK(table.Get(0xFFFF)->Get(0)); | 1472 CHECK(table.Get(0xFFFF)->Get(0)); |
| 1461 } | 1473 } |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1552 unibrow::uchar chars2[unibrow::Ecma262UnCanonicalize::kMaxWidth]; | 1564 unibrow::uchar chars2[unibrow::Ecma262UnCanonicalize::kMaxWidth]; |
| 1553 int length2 = un_canonicalize.get(chars[j], '\0', chars2); | 1565 int length2 = un_canonicalize.get(chars[j], '\0', chars2); |
| 1554 CHECK_EQ(length, length2); | 1566 CHECK_EQ(length, length2); |
| 1555 for (int k = 0; k < length; k++) | 1567 for (int k = 0; k < length; k++) |
| 1556 CHECK_EQ(static_cast<int>(chars[k]), static_cast<int>(chars2[k])); | 1568 CHECK_EQ(static_cast<int>(chars[k]), static_cast<int>(chars2[k])); |
| 1557 } | 1569 } |
| 1558 } | 1570 } |
| 1559 } | 1571 } |
| 1560 | 1572 |
| 1561 | 1573 |
| 1562 static void TestRangeCaseIndependence(CharacterRange input, | 1574 static void TestRangeCaseIndependence(Isolate* isolate, CharacterRange input, |
| 1563 Vector<CharacterRange> expected) { | 1575 Vector<CharacterRange> expected) { |
| 1564 Zone zone(CcTest::i_isolate()); | 1576 Zone zone; |
| 1565 int count = expected.length(); | 1577 int count = expected.length(); |
| 1566 ZoneList<CharacterRange>* list = | 1578 ZoneList<CharacterRange>* list = |
| 1567 new(&zone) ZoneList<CharacterRange>(count, &zone); | 1579 new(&zone) ZoneList<CharacterRange>(count, &zone); |
| 1568 input.AddCaseEquivalents(list, false, &zone); | 1580 input.AddCaseEquivalents(isolate, &zone, list, false); |
| 1569 CHECK_EQ(count, list->length()); | 1581 CHECK_EQ(count, list->length()); |
| 1570 for (int i = 0; i < list->length(); i++) { | 1582 for (int i = 0; i < list->length(); i++) { |
| 1571 CHECK_EQ(expected[i].from(), list->at(i).from()); | 1583 CHECK_EQ(expected[i].from(), list->at(i).from()); |
| 1572 CHECK_EQ(expected[i].to(), list->at(i).to()); | 1584 CHECK_EQ(expected[i].to(), list->at(i).to()); |
| 1573 } | 1585 } |
| 1574 } | 1586 } |
| 1575 | 1587 |
| 1576 | 1588 |
| 1577 static void TestSimpleRangeCaseIndependence(CharacterRange input, | 1589 static void TestSimpleRangeCaseIndependence(Isolate* isolate, |
| 1590 CharacterRange input, |
| 1578 CharacterRange expected) { | 1591 CharacterRange expected) { |
| 1579 EmbeddedVector<CharacterRange, 1> vector; | 1592 EmbeddedVector<CharacterRange, 1> vector; |
| 1580 vector[0] = expected; | 1593 vector[0] = expected; |
| 1581 TestRangeCaseIndependence(input, vector); | 1594 TestRangeCaseIndependence(isolate, input, vector); |
| 1582 } | 1595 } |
| 1583 | 1596 |
| 1584 | 1597 |
| 1585 TEST(CharacterRangeCaseIndependence) { | 1598 TEST(CharacterRangeCaseIndependence) { |
| 1586 TestSimpleRangeCaseIndependence(CharacterRange::Singleton('a'), | 1599 Isolate* isolate = CcTest::i_isolate(); |
| 1600 TestSimpleRangeCaseIndependence(isolate, CharacterRange::Singleton('a'), |
| 1587 CharacterRange::Singleton('A')); | 1601 CharacterRange::Singleton('A')); |
| 1588 TestSimpleRangeCaseIndependence(CharacterRange::Singleton('z'), | 1602 TestSimpleRangeCaseIndependence(isolate, CharacterRange::Singleton('z'), |
| 1589 CharacterRange::Singleton('Z')); | 1603 CharacterRange::Singleton('Z')); |
| 1590 TestSimpleRangeCaseIndependence(CharacterRange('a', 'z'), | 1604 TestSimpleRangeCaseIndependence(isolate, CharacterRange('a', 'z'), |
| 1591 CharacterRange('A', 'Z')); | 1605 CharacterRange('A', 'Z')); |
| 1592 TestSimpleRangeCaseIndependence(CharacterRange('c', 'f'), | 1606 TestSimpleRangeCaseIndependence(isolate, CharacterRange('c', 'f'), |
| 1593 CharacterRange('C', 'F')); | 1607 CharacterRange('C', 'F')); |
| 1594 TestSimpleRangeCaseIndependence(CharacterRange('a', 'b'), | 1608 TestSimpleRangeCaseIndependence(isolate, CharacterRange('a', 'b'), |
| 1595 CharacterRange('A', 'B')); | 1609 CharacterRange('A', 'B')); |
| 1596 TestSimpleRangeCaseIndependence(CharacterRange('y', 'z'), | 1610 TestSimpleRangeCaseIndependence(isolate, CharacterRange('y', 'z'), |
| 1597 CharacterRange('Y', 'Z')); | 1611 CharacterRange('Y', 'Z')); |
| 1598 TestSimpleRangeCaseIndependence(CharacterRange('a' - 1, 'z' + 1), | 1612 TestSimpleRangeCaseIndependence(isolate, CharacterRange('a' - 1, 'z' + 1), |
| 1599 CharacterRange('A', 'Z')); | 1613 CharacterRange('A', 'Z')); |
| 1600 TestSimpleRangeCaseIndependence(CharacterRange('A', 'Z'), | 1614 TestSimpleRangeCaseIndependence(isolate, CharacterRange('A', 'Z'), |
| 1601 CharacterRange('a', 'z')); | 1615 CharacterRange('a', 'z')); |
| 1602 TestSimpleRangeCaseIndependence(CharacterRange('C', 'F'), | 1616 TestSimpleRangeCaseIndependence(isolate, CharacterRange('C', 'F'), |
| 1603 CharacterRange('c', 'f')); | 1617 CharacterRange('c', 'f')); |
| 1604 TestSimpleRangeCaseIndependence(CharacterRange('A' - 1, 'Z' + 1), | 1618 TestSimpleRangeCaseIndependence(isolate, CharacterRange('A' - 1, 'Z' + 1), |
| 1605 CharacterRange('a', 'z')); | 1619 CharacterRange('a', 'z')); |
| 1606 // Here we need to add [l-z] to complete the case independence of | 1620 // Here we need to add [l-z] to complete the case independence of |
| 1607 // [A-Za-z] but we expect [a-z] to be added since we always add a | 1621 // [A-Za-z] but we expect [a-z] to be added since we always add a |
| 1608 // whole block at a time. | 1622 // whole block at a time. |
| 1609 TestSimpleRangeCaseIndependence(CharacterRange('A', 'k'), | 1623 TestSimpleRangeCaseIndependence(isolate, CharacterRange('A', 'k'), |
| 1610 CharacterRange('a', 'z')); | 1624 CharacterRange('a', 'z')); |
| 1611 } | 1625 } |
| 1612 | 1626 |
| 1613 | 1627 |
| 1614 static bool InClass(uc16 c, ZoneList<CharacterRange>* ranges) { | 1628 static bool InClass(uc16 c, ZoneList<CharacterRange>* ranges) { |
| 1615 if (ranges == NULL) | 1629 if (ranges == NULL) |
| 1616 return false; | 1630 return false; |
| 1617 for (int i = 0; i < ranges->length(); i++) { | 1631 for (int i = 0; i < ranges->length(); i++) { |
| 1618 CharacterRange range = ranges->at(i); | 1632 CharacterRange range = ranges->at(i); |
| 1619 if (range.from() <= c && c <= range.to()) | 1633 if (range.from() <= c && c <= range.to()) |
| 1620 return true; | 1634 return true; |
| 1621 } | 1635 } |
| 1622 return false; | 1636 return false; |
| 1623 } | 1637 } |
| 1624 | 1638 |
| 1625 | 1639 |
| 1626 TEST(CharClassDifference) { | 1640 TEST(CharClassDifference) { |
| 1627 Zone zone(CcTest::i_isolate()); | 1641 Zone zone; |
| 1628 ZoneList<CharacterRange>* base = | 1642 ZoneList<CharacterRange>* base = |
| 1629 new(&zone) ZoneList<CharacterRange>(1, &zone); | 1643 new(&zone) ZoneList<CharacterRange>(1, &zone); |
| 1630 base->Add(CharacterRange::Everything(), &zone); | 1644 base->Add(CharacterRange::Everything(), &zone); |
| 1631 Vector<const int> overlay = CharacterRange::GetWordBounds(); | 1645 Vector<const int> overlay = CharacterRange::GetWordBounds(); |
| 1632 ZoneList<CharacterRange>* included = NULL; | 1646 ZoneList<CharacterRange>* included = NULL; |
| 1633 ZoneList<CharacterRange>* excluded = NULL; | 1647 ZoneList<CharacterRange>* excluded = NULL; |
| 1634 CharacterRange::Split(base, overlay, &included, &excluded, &zone); | 1648 CharacterRange::Split(base, overlay, &included, &excluded, &zone); |
| 1635 for (int i = 0; i < (1 << 16); i++) { | 1649 for (int i = 0; i < (1 << 16); i++) { |
| 1636 bool in_base = InClass(i, base); | 1650 bool in_base = InClass(i, base); |
| 1637 if (in_base) { | 1651 if (in_base) { |
| 1638 bool in_overlay = false; | 1652 bool in_overlay = false; |
| 1639 for (int j = 0; !in_overlay && j < overlay.length(); j += 2) { | 1653 for (int j = 0; !in_overlay && j < overlay.length(); j += 2) { |
| 1640 if (overlay[j] <= i && i < overlay[j+1]) | 1654 if (overlay[j] <= i && i < overlay[j+1]) |
| 1641 in_overlay = true; | 1655 in_overlay = true; |
| 1642 } | 1656 } |
| 1643 CHECK_EQ(in_overlay, InClass(i, included)); | 1657 CHECK_EQ(in_overlay, InClass(i, included)); |
| 1644 CHECK_EQ(!in_overlay, InClass(i, excluded)); | 1658 CHECK_EQ(!in_overlay, InClass(i, excluded)); |
| 1645 } else { | 1659 } else { |
| 1646 CHECK(!InClass(i, included)); | 1660 CHECK(!InClass(i, included)); |
| 1647 CHECK(!InClass(i, excluded)); | 1661 CHECK(!InClass(i, excluded)); |
| 1648 } | 1662 } |
| 1649 } | 1663 } |
| 1650 } | 1664 } |
| 1651 | 1665 |
| 1652 | 1666 |
| 1653 TEST(CanonicalizeCharacterSets) { | 1667 TEST(CanonicalizeCharacterSets) { |
| 1654 Zone zone(CcTest::i_isolate()); | 1668 Zone zone; |
| 1655 ZoneList<CharacterRange>* list = | 1669 ZoneList<CharacterRange>* list = |
| 1656 new(&zone) ZoneList<CharacterRange>(4, &zone); | 1670 new(&zone) ZoneList<CharacterRange>(4, &zone); |
| 1657 CharacterSet set(list); | 1671 CharacterSet set(list); |
| 1658 | 1672 |
| 1659 list->Add(CharacterRange(10, 20), &zone); | 1673 list->Add(CharacterRange(10, 20), &zone); |
| 1660 list->Add(CharacterRange(30, 40), &zone); | 1674 list->Add(CharacterRange(30, 40), &zone); |
| 1661 list->Add(CharacterRange(50, 60), &zone); | 1675 list->Add(CharacterRange(50, 60), &zone); |
| 1662 set.Canonicalize(); | 1676 set.Canonicalize(); |
| 1663 DCHECK_EQ(3, list->length()); | 1677 DCHECK_EQ(3, list->length()); |
| 1664 DCHECK_EQ(10, list->at(0).from()); | 1678 DCHECK_EQ(10, list->at(0).from()); |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1705 list->Add(CharacterRange(21, 30), &zone); | 1719 list->Add(CharacterRange(21, 30), &zone); |
| 1706 list->Add(CharacterRange(20, 20), &zone); | 1720 list->Add(CharacterRange(20, 20), &zone); |
| 1707 set.Canonicalize(); | 1721 set.Canonicalize(); |
| 1708 DCHECK_EQ(1, list->length()); | 1722 DCHECK_EQ(1, list->length()); |
| 1709 DCHECK_EQ(10, list->at(0).from()); | 1723 DCHECK_EQ(10, list->at(0).from()); |
| 1710 DCHECK_EQ(30, list->at(0).to()); | 1724 DCHECK_EQ(30, list->at(0).to()); |
| 1711 } | 1725 } |
| 1712 | 1726 |
| 1713 | 1727 |
| 1714 TEST(CharacterRangeMerge) { | 1728 TEST(CharacterRangeMerge) { |
| 1715 Zone zone(CcTest::i_isolate()); | 1729 Zone zone; |
| 1716 ZoneList<CharacterRange> l1(4, &zone); | 1730 ZoneList<CharacterRange> l1(4, &zone); |
| 1717 ZoneList<CharacterRange> l2(4, &zone); | 1731 ZoneList<CharacterRange> l2(4, &zone); |
| 1718 // Create all combinations of intersections of ranges, both singletons and | 1732 // Create all combinations of intersections of ranges, both singletons and |
| 1719 // longer. | 1733 // longer. |
| 1720 | 1734 |
| 1721 int offset = 0; | 1735 int offset = 0; |
| 1722 | 1736 |
| 1723 // The five kinds of singleton intersections: | 1737 // The five kinds of singleton intersections: |
| 1724 // X | 1738 // X |
| 1725 // Y - outside before | 1739 // Y - outside before |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1794 | 1808 |
| 1795 ZoneList<CharacterRange> first_only(4, &zone); | 1809 ZoneList<CharacterRange> first_only(4, &zone); |
| 1796 ZoneList<CharacterRange> second_only(4, &zone); | 1810 ZoneList<CharacterRange> second_only(4, &zone); |
| 1797 ZoneList<CharacterRange> both(4, &zone); | 1811 ZoneList<CharacterRange> both(4, &zone); |
| 1798 } | 1812 } |
| 1799 | 1813 |
| 1800 | 1814 |
| 1801 TEST(Graph) { | 1815 TEST(Graph) { |
| 1802 Execute("\\b\\w+\\b", false, true, true); | 1816 Execute("\\b\\w+\\b", false, true, true); |
| 1803 } | 1817 } |
| OLD | NEW |