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 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
65 #include "ia32/regexp-macro-assembler-ia32.h" | 65 #include "ia32/regexp-macro-assembler-ia32.h" |
66 #endif | 66 #endif |
67 #endif // V8_INTERPRETED_REGEXP | 67 #endif // V8_INTERPRETED_REGEXP |
68 | 68 |
69 using namespace v8::internal; | 69 using namespace v8::internal; |
70 | 70 |
71 | 71 |
72 static bool CheckParse(const char* input) { | 72 static bool CheckParse(const char* input) { |
73 V8::Initialize(NULL); | 73 V8::Initialize(NULL); |
74 v8::HandleScope scope(v8::Isolate::GetCurrent()); | 74 v8::HandleScope scope(v8::Isolate::GetCurrent()); |
75 ZoneScope zone_scope(Isolate::Current()->runtime_zone(), DELETE_ON_EXIT); | 75 ZoneScope zone_scope(Isolate::Current()->runtime_zone()); |
76 FlatStringReader reader(Isolate::Current(), CStrVector(input)); | 76 FlatStringReader reader(Isolate::Current(), CStrVector(input)); |
77 RegExpCompileData result; | 77 RegExpCompileData result; |
78 return v8::internal::RegExpParser::ParseRegExp( | 78 return v8::internal::RegExpParser::ParseRegExp( |
79 &reader, false, &result, Isolate::Current()->runtime_zone()); | 79 &reader, false, &result, Isolate::Current()->runtime_zone()); |
80 } | 80 } |
81 | 81 |
82 | 82 |
83 static SmartArrayPointer<const char> Parse(const char* input) { | 83 static SmartArrayPointer<const char> Parse(const char* input) { |
84 V8::Initialize(NULL); | 84 V8::Initialize(NULL); |
85 v8::HandleScope scope(v8::Isolate::GetCurrent()); | 85 v8::HandleScope scope(v8::Isolate::GetCurrent()); |
86 ZoneScope zone_scope(Isolate::Current()->runtime_zone(), DELETE_ON_EXIT); | 86 ZoneScope zone_scope(Isolate::Current()->runtime_zone()); |
87 FlatStringReader reader(Isolate::Current(), CStrVector(input)); | 87 FlatStringReader reader(Isolate::Current(), CStrVector(input)); |
88 RegExpCompileData result; | 88 RegExpCompileData result; |
89 CHECK(v8::internal::RegExpParser::ParseRegExp( | 89 CHECK(v8::internal::RegExpParser::ParseRegExp( |
90 &reader, false, &result, Isolate::Current()->runtime_zone())); | 90 &reader, false, &result, Isolate::Current()->runtime_zone())); |
91 CHECK(result.tree != NULL); | 91 CHECK(result.tree != NULL); |
92 CHECK(result.error.is_null()); | 92 CHECK(result.error.is_null()); |
93 SmartArrayPointer<const char> output = | 93 SmartArrayPointer<const char> output = |
94 result.tree->ToString(Isolate::Current()->runtime_zone()); | 94 result.tree->ToString(Isolate::Current()->runtime_zone()); |
95 return output; | 95 return output; |
96 } | 96 } |
97 | 97 |
98 static bool CheckSimple(const char* input) { | 98 static bool CheckSimple(const char* input) { |
99 V8::Initialize(NULL); | 99 V8::Initialize(NULL); |
100 v8::HandleScope scope(v8::Isolate::GetCurrent()); | 100 v8::HandleScope scope(v8::Isolate::GetCurrent()); |
101 ZoneScope zone_scope(Isolate::Current()->runtime_zone(), DELETE_ON_EXIT); | 101 ZoneScope zone_scope(Isolate::Current()->runtime_zone()); |
102 FlatStringReader reader(Isolate::Current(), CStrVector(input)); | 102 FlatStringReader reader(Isolate::Current(), CStrVector(input)); |
103 RegExpCompileData result; | 103 RegExpCompileData result; |
104 CHECK(v8::internal::RegExpParser::ParseRegExp( | 104 CHECK(v8::internal::RegExpParser::ParseRegExp( |
105 &reader, false, &result, Isolate::Current()->runtime_zone())); | 105 &reader, false, &result, Isolate::Current()->runtime_zone())); |
106 CHECK(result.tree != NULL); | 106 CHECK(result.tree != NULL); |
107 CHECK(result.error.is_null()); | 107 CHECK(result.error.is_null()); |
108 return result.simple; | 108 return result.simple; |
109 } | 109 } |
110 | 110 |
111 struct MinMaxPair { | 111 struct MinMaxPair { |
112 int min_match; | 112 int min_match; |
113 int max_match; | 113 int max_match; |
114 }; | 114 }; |
115 | 115 |
116 static MinMaxPair CheckMinMaxMatch(const char* input) { | 116 static MinMaxPair CheckMinMaxMatch(const char* input) { |
117 V8::Initialize(NULL); | 117 V8::Initialize(NULL); |
118 v8::HandleScope scope(v8::Isolate::GetCurrent()); | 118 v8::HandleScope scope(v8::Isolate::GetCurrent()); |
119 ZoneScope zone_scope(Isolate::Current()->runtime_zone(), DELETE_ON_EXIT); | 119 ZoneScope zone_scope(Isolate::Current()->runtime_zone()); |
120 FlatStringReader reader(Isolate::Current(), CStrVector(input)); | 120 FlatStringReader reader(Isolate::Current(), CStrVector(input)); |
121 RegExpCompileData result; | 121 RegExpCompileData result; |
122 CHECK(v8::internal::RegExpParser::ParseRegExp( | 122 CHECK(v8::internal::RegExpParser::ParseRegExp( |
123 &reader, false, &result, Isolate::Current()->runtime_zone())); | 123 &reader, false, &result, Isolate::Current()->runtime_zone())); |
124 CHECK(result.tree != NULL); | 124 CHECK(result.tree != NULL); |
125 CHECK(result.error.is_null()); | 125 CHECK(result.error.is_null()); |
126 int min_match = result.tree->min_match(); | 126 int min_match = result.tree->min_match(); |
127 int max_match = result.tree->max_match(); | 127 int max_match = result.tree->max_match(); |
128 MinMaxPair pair = { min_match, max_match }; | 128 MinMaxPair pair = { min_match, max_match }; |
129 return pair; | 129 return pair; |
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
382 CHECK_PARSE_EQ("[A-Z$-][x]", "(! [A-Z $ -] [x])"); | 382 CHECK_PARSE_EQ("[A-Z$-][x]", "(! [A-Z $ -] [x])"); |
383 CHECK_PARSE_EQ("a{3,4*}", "(: 'a{3,' (# 0 - g '4') '}')"); | 383 CHECK_PARSE_EQ("a{3,4*}", "(: 'a{3,' (# 0 - g '4') '}')"); |
384 CHECK_PARSE_EQ("{", "'{'"); | 384 CHECK_PARSE_EQ("{", "'{'"); |
385 CHECK_PARSE_EQ("a|", "(| 'a' %)"); | 385 CHECK_PARSE_EQ("a|", "(| 'a' %)"); |
386 } | 386 } |
387 | 387 |
388 static void ExpectError(const char* input, | 388 static void ExpectError(const char* input, |
389 const char* expected) { | 389 const char* expected) { |
390 V8::Initialize(NULL); | 390 V8::Initialize(NULL); |
391 v8::HandleScope scope(v8::Isolate::GetCurrent()); | 391 v8::HandleScope scope(v8::Isolate::GetCurrent()); |
392 ZoneScope zone_scope(Isolate::Current()->runtime_zone(), DELETE_ON_EXIT); | 392 ZoneScope zone_scope(Isolate::Current()->runtime_zone()); |
393 FlatStringReader reader(Isolate::Current(), CStrVector(input)); | 393 FlatStringReader reader(Isolate::Current(), CStrVector(input)); |
394 RegExpCompileData result; | 394 RegExpCompileData result; |
395 CHECK(!v8::internal::RegExpParser::ParseRegExp( | 395 CHECK(!v8::internal::RegExpParser::ParseRegExp( |
396 &reader, false, &result, Isolate::Current()->runtime_zone())); | 396 &reader, false, &result, Isolate::Current()->runtime_zone())); |
397 CHECK(result.tree == NULL); | 397 CHECK(result.tree == NULL); |
398 CHECK(!result.error.is_null()); | 398 CHECK(!result.error.is_null()); |
399 SmartArrayPointer<char> str = result.error->ToCString(ALLOW_NULLS); | 399 SmartArrayPointer<char> str = result.error->ToCString(ALLOW_NULLS); |
400 CHECK_EQ(expected, *str); | 400 CHECK_EQ(expected, *str); |
401 } | 401 } |
402 | 402 |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
466 return !IsWhiteSpace(c); | 466 return !IsWhiteSpace(c); |
467 } | 467 } |
468 | 468 |
469 | 469 |
470 static bool NotWord(uc16 c) { | 470 static bool NotWord(uc16 c) { |
471 return !IsRegExpWord(c); | 471 return !IsRegExpWord(c); |
472 } | 472 } |
473 | 473 |
474 | 474 |
475 static void TestCharacterClassEscapes(uc16 c, bool (pred)(uc16 c)) { | 475 static void TestCharacterClassEscapes(uc16 c, bool (pred)(uc16 c)) { |
476 ZoneScope scope(Isolate::Current()->runtime_zone(), DELETE_ON_EXIT); | 476 ZoneScope scope(Isolate::Current()->runtime_zone()); |
477 Zone* zone = Isolate::Current()->runtime_zone(); | 477 Zone* zone = Isolate::Current()->runtime_zone(); |
478 ZoneList<CharacterRange>* ranges = | 478 ZoneList<CharacterRange>* ranges = |
479 new(zone) ZoneList<CharacterRange>(2, zone); | 479 new(zone) ZoneList<CharacterRange>(2, zone); |
480 CharacterRange::AddClassEscape(c, ranges, zone); | 480 CharacterRange::AddClassEscape(c, ranges, zone); |
481 for (unsigned i = 0; i < (1 << 16); i++) { | 481 for (unsigned i = 0; i < (1 << 16); i++) { |
482 bool in_class = false; | 482 bool in_class = false; |
483 for (int j = 0; !in_class && j < ranges->length(); j++) { | 483 for (int j = 0; !in_class && j < ranges->length(); j++) { |
484 CharacterRange& range = ranges->at(j); | 484 CharacterRange& range = ranges->at(j); |
485 in_class = (range.from() <= i && i <= range.to()); | 485 in_class = (range.from() <= i && i <= range.to()); |
486 } | 486 } |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
524 isolate->runtime_zone()); | 524 isolate->runtime_zone()); |
525 return compile_data.node; | 525 return compile_data.node; |
526 } | 526 } |
527 | 527 |
528 | 528 |
529 static void Execute(const char* input, | 529 static void Execute(const char* input, |
530 bool multiline, | 530 bool multiline, |
531 bool is_ascii, | 531 bool is_ascii, |
532 bool dot_output = false) { | 532 bool dot_output = false) { |
533 v8::HandleScope scope(v8::Isolate::GetCurrent()); | 533 v8::HandleScope scope(v8::Isolate::GetCurrent()); |
534 ZoneScope zone_scope(Isolate::Current()->runtime_zone(), DELETE_ON_EXIT); | 534 ZoneScope zone_scope(Isolate::Current()->runtime_zone()); |
535 RegExpNode* node = Compile(input, multiline, is_ascii); | 535 RegExpNode* node = Compile(input, multiline, is_ascii); |
536 USE(node); | 536 USE(node); |
537 #ifdef DEBUG | 537 #ifdef DEBUG |
538 if (dot_output) { | 538 if (dot_output) { |
539 RegExpEngine::DotPrint(input, node, false); | 539 RegExpEngine::DotPrint(input, node, false); |
540 exit(0); | 540 exit(0); |
541 } | 541 } |
542 #endif // DEBUG | 542 #endif // DEBUG |
543 } | 543 } |
544 | 544 |
(...skipping 19 matching lines...) Expand all Loading... |
564 | 564 |
565 | 565 |
566 static unsigned PseudoRandom(int i, int j) { | 566 static unsigned PseudoRandom(int i, int j) { |
567 return ~(~((i * 781) ^ (j * 329))); | 567 return ~(~((i * 781) ^ (j * 329))); |
568 } | 568 } |
569 | 569 |
570 | 570 |
571 TEST(SplayTreeSimple) { | 571 TEST(SplayTreeSimple) { |
572 v8::internal::V8::Initialize(NULL); | 572 v8::internal::V8::Initialize(NULL); |
573 static const unsigned kLimit = 1000; | 573 static const unsigned kLimit = 1000; |
574 ZoneScope zone_scope(Isolate::Current()->runtime_zone(), DELETE_ON_EXIT); | 574 ZoneScope zone_scope(Isolate::Current()->runtime_zone()); |
575 ZoneSplayTree<TestConfig> tree(Isolate::Current()->runtime_zone()); | 575 ZoneSplayTree<TestConfig> tree(Isolate::Current()->runtime_zone()); |
576 bool seen[kLimit]; | 576 bool seen[kLimit]; |
577 for (unsigned i = 0; i < kLimit; i++) seen[i] = false; | 577 for (unsigned i = 0; i < kLimit; i++) seen[i] = false; |
578 #define CHECK_MAPS_EQUAL() do { \ | 578 #define CHECK_MAPS_EQUAL() do { \ |
579 for (unsigned k = 0; k < kLimit; k++) \ | 579 for (unsigned k = 0; k < kLimit; k++) \ |
580 CHECK_EQ(seen[k], tree.Find(k, &loc)); \ | 580 CHECK_EQ(seen[k], tree.Find(k, &loc)); \ |
581 } while (false) | 581 } while (false) |
582 for (int i = 0; i < 50; i++) { | 582 for (int i = 0; i < 50; i++) { |
583 for (int j = 0; j < 50; j++) { | 583 for (int j = 0; j < 50; j++) { |
584 unsigned next = PseudoRandom(i, j) % kLimit; | 584 unsigned next = PseudoRandom(i, j) % kLimit; |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
632 Vector<uc16> range(ranges[i], 2 * kRangeSize); | 632 Vector<uc16> range(ranges[i], 2 * kRangeSize); |
633 for (int j = 0; j < 2 * kRangeSize; j++) { | 633 for (int j = 0; j < 2 * kRangeSize; j++) { |
634 range[j] = PseudoRandom(i + 25, j + 87) % kLimit; | 634 range[j] = PseudoRandom(i + 25, j + 87) % kLimit; |
635 } | 635 } |
636 range.Sort(); | 636 range.Sort(); |
637 for (int j = 1; j < 2 * kRangeSize; j++) { | 637 for (int j = 1; j < 2 * kRangeSize; j++) { |
638 CHECK(range[j-1] <= range[j]); | 638 CHECK(range[j-1] <= range[j]); |
639 } | 639 } |
640 } | 640 } |
641 // Enter test data into dispatch table. | 641 // Enter test data into dispatch table. |
642 ZoneScope zone_scope(Isolate::Current()->runtime_zone(), DELETE_ON_EXIT); | 642 ZoneScope zone_scope(Isolate::Current()->runtime_zone()); |
643 DispatchTable table(Isolate::Current()->runtime_zone()); | 643 DispatchTable table(Isolate::Current()->runtime_zone()); |
644 for (int i = 0; i < kRangeCount; i++) { | 644 for (int i = 0; i < kRangeCount; i++) { |
645 uc16* range = ranges[i]; | 645 uc16* range = ranges[i]; |
646 for (int j = 0; j < 2 * kRangeSize; j += 2) | 646 for (int j = 0; j < 2 * kRangeSize; j += 2) |
647 table.AddRange(CharacterRange(range[j], range[j + 1]), i, | 647 table.AddRange(CharacterRange(range[j], range[j + 1]), i, |
648 Isolate::Current()->runtime_zone()); | 648 Isolate::Current()->runtime_zone()); |
649 } | 649 } |
650 // Check that the table looks as we would expect | 650 // Check that the table looks as we would expect |
651 for (int p = 0; p < kLimit; p++) { | 651 for (int p = 0; p < kLimit; p++) { |
652 OutSet* outs = table.Get(p); | 652 OutSet* outs = table.Get(p); |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
702 typedef RegExpMacroAssemblerARM ArchRegExpMacroAssembler; | 702 typedef RegExpMacroAssemblerARM ArchRegExpMacroAssembler; |
703 #elif V8_TARGET_ARCH_MIPS | 703 #elif V8_TARGET_ARCH_MIPS |
704 typedef RegExpMacroAssemblerMIPS ArchRegExpMacroAssembler; | 704 typedef RegExpMacroAssemblerMIPS ArchRegExpMacroAssembler; |
705 #endif | 705 #endif |
706 | 706 |
707 class ContextInitializer { | 707 class ContextInitializer { |
708 public: | 708 public: |
709 ContextInitializer() | 709 ContextInitializer() |
710 : scope_(v8::Isolate::GetCurrent()), | 710 : scope_(v8::Isolate::GetCurrent()), |
711 env_(v8::Context::New(v8::Isolate::GetCurrent())), | 711 env_(v8::Context::New(v8::Isolate::GetCurrent())), |
712 zone_(Isolate::Current()->runtime_zone(), DELETE_ON_EXIT) { | 712 zone_(Isolate::Current()->runtime_zone()) { |
713 env_->Enter(); | 713 env_->Enter(); |
714 } | 714 } |
715 ~ContextInitializer() { | 715 ~ContextInitializer() { |
716 env_->Exit(); | 716 env_->Exit(); |
717 } | 717 } |
718 private: | 718 private: |
719 v8::HandleScope scope_; | 719 v8::HandleScope scope_; |
720 v8::Handle<v8::Context> env_; | 720 v8::Handle<v8::Context> env_; |
721 v8::internal::ZoneScope zone_; | 721 v8::internal::ZoneScope zone_; |
722 }; | 722 }; |
(...skipping 698 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1421 } | 1421 } |
1422 | 1422 |
1423 #endif // V8_INTERPRETED_REGEXP | 1423 #endif // V8_INTERPRETED_REGEXP |
1424 | 1424 |
1425 | 1425 |
1426 TEST(AddInverseToTable) { | 1426 TEST(AddInverseToTable) { |
1427 v8::internal::V8::Initialize(NULL); | 1427 v8::internal::V8::Initialize(NULL); |
1428 static const int kLimit = 1000; | 1428 static const int kLimit = 1000; |
1429 static const int kRangeCount = 16; | 1429 static const int kRangeCount = 16; |
1430 for (int t = 0; t < 10; t++) { | 1430 for (int t = 0; t < 10; t++) { |
1431 ZoneScope zone_scope(Isolate::Current()->runtime_zone(), DELETE_ON_EXIT); | 1431 ZoneScope zone_scope(Isolate::Current()->runtime_zone()); |
1432 Zone* zone = Isolate::Current()->runtime_zone(); | 1432 Zone* zone = Isolate::Current()->runtime_zone(); |
1433 ZoneList<CharacterRange>* ranges = | 1433 ZoneList<CharacterRange>* ranges = |
1434 new(zone) | 1434 new(zone) |
1435 ZoneList<CharacterRange>(kRangeCount, zone); | 1435 ZoneList<CharacterRange>(kRangeCount, zone); |
1436 for (int i = 0; i < kRangeCount; i++) { | 1436 for (int i = 0; i < kRangeCount; i++) { |
1437 int from = PseudoRandom(t + 87, i + 25) % kLimit; | 1437 int from = PseudoRandom(t + 87, i + 25) % kLimit; |
1438 int to = from + (PseudoRandom(i + 87, t + 25) % (kLimit / 20)); | 1438 int to = from + (PseudoRandom(i + 87, t + 25) % (kLimit / 20)); |
1439 if (to > kLimit) to = kLimit; | 1439 if (to > kLimit) to = kLimit; |
1440 ranges->Add(CharacterRange(from, to), zone); | 1440 ranges->Add(CharacterRange(from, to), zone); |
1441 } | 1441 } |
1442 DispatchTable table(zone); | 1442 DispatchTable table(zone); |
1443 DispatchTableConstructor cons(&table, false, | 1443 DispatchTableConstructor cons(&table, false, |
1444 Isolate::Current()->runtime_zone()); | 1444 Isolate::Current()->runtime_zone()); |
1445 cons.set_choice_index(0); | 1445 cons.set_choice_index(0); |
1446 cons.AddInverse(ranges); | 1446 cons.AddInverse(ranges); |
1447 for (int i = 0; i < kLimit; i++) { | 1447 for (int i = 0; i < kLimit; i++) { |
1448 bool is_on = false; | 1448 bool is_on = false; |
1449 for (int j = 0; !is_on && j < kRangeCount; j++) | 1449 for (int j = 0; !is_on && j < kRangeCount; j++) |
1450 is_on = ranges->at(j).Contains(i); | 1450 is_on = ranges->at(j).Contains(i); |
1451 OutSet* set = table.Get(i); | 1451 OutSet* set = table.Get(i); |
1452 CHECK_EQ(is_on, set->Get(0) == false); | 1452 CHECK_EQ(is_on, set->Get(0) == false); |
1453 } | 1453 } |
1454 } | 1454 } |
1455 ZoneScope zone_scope(Isolate::Current()->runtime_zone(), DELETE_ON_EXIT); | 1455 ZoneScope zone_scope(Isolate::Current()->runtime_zone()); |
1456 Zone* zone = Isolate::Current()->runtime_zone(); | 1456 Zone* zone = Isolate::Current()->runtime_zone(); |
1457 ZoneList<CharacterRange>* ranges = | 1457 ZoneList<CharacterRange>* ranges = |
1458 new(zone) ZoneList<CharacterRange>(1, zone); | 1458 new(zone) ZoneList<CharacterRange>(1, zone); |
1459 ranges->Add(CharacterRange(0xFFF0, 0xFFFE), zone); | 1459 ranges->Add(CharacterRange(0xFFF0, 0xFFFE), zone); |
1460 DispatchTable table(zone); | 1460 DispatchTable table(zone); |
1461 DispatchTableConstructor cons(&table, false, | 1461 DispatchTableConstructor cons(&table, false, |
1462 Isolate::Current()->runtime_zone()); | 1462 Isolate::Current()->runtime_zone()); |
1463 cons.set_choice_index(0); | 1463 cons.set_choice_index(0); |
1464 cons.AddInverse(ranges); | 1464 cons.AddInverse(ranges); |
1465 CHECK(!table.Get(0xFFFE)->Get(0)); | 1465 CHECK(!table.Get(0xFFFE)->Get(0)); |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1560 CHECK_EQ(length, length2); | 1560 CHECK_EQ(length, length2); |
1561 for (int k = 0; k < length; k++) | 1561 for (int k = 0; k < length; k++) |
1562 CHECK_EQ(static_cast<int>(chars[k]), static_cast<int>(chars2[k])); | 1562 CHECK_EQ(static_cast<int>(chars[k]), static_cast<int>(chars2[k])); |
1563 } | 1563 } |
1564 } | 1564 } |
1565 } | 1565 } |
1566 | 1566 |
1567 | 1567 |
1568 static void TestRangeCaseIndependence(CharacterRange input, | 1568 static void TestRangeCaseIndependence(CharacterRange input, |
1569 Vector<CharacterRange> expected) { | 1569 Vector<CharacterRange> expected) { |
1570 ZoneScope zone_scope(Isolate::Current()->runtime_zone(), DELETE_ON_EXIT); | 1570 ZoneScope zone_scope(Isolate::Current()->runtime_zone()); |
1571 Zone* zone = Isolate::Current()->runtime_zone(); | 1571 Zone* zone = Isolate::Current()->runtime_zone(); |
1572 int count = expected.length(); | 1572 int count = expected.length(); |
1573 ZoneList<CharacterRange>* list = | 1573 ZoneList<CharacterRange>* list = |
1574 new(zone) ZoneList<CharacterRange>(count, zone); | 1574 new(zone) ZoneList<CharacterRange>(count, zone); |
1575 input.AddCaseEquivalents(list, false, zone); | 1575 input.AddCaseEquivalents(list, false, zone); |
1576 CHECK_EQ(count, list->length()); | 1576 CHECK_EQ(count, list->length()); |
1577 for (int i = 0; i < list->length(); i++) { | 1577 for (int i = 0; i < list->length(); i++) { |
1578 CHECK_EQ(expected[i].from(), list->at(i).from()); | 1578 CHECK_EQ(expected[i].from(), list->at(i).from()); |
1579 CHECK_EQ(expected[i].to(), list->at(i).to()); | 1579 CHECK_EQ(expected[i].to(), list->at(i).to()); |
1580 } | 1580 } |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1626 CharacterRange range = ranges->at(i); | 1626 CharacterRange range = ranges->at(i); |
1627 if (range.from() <= c && c <= range.to()) | 1627 if (range.from() <= c && c <= range.to()) |
1628 return true; | 1628 return true; |
1629 } | 1629 } |
1630 return false; | 1630 return false; |
1631 } | 1631 } |
1632 | 1632 |
1633 | 1633 |
1634 TEST(CharClassDifference) { | 1634 TEST(CharClassDifference) { |
1635 v8::internal::V8::Initialize(NULL); | 1635 v8::internal::V8::Initialize(NULL); |
1636 ZoneScope zone_scope(Isolate::Current()->runtime_zone(), DELETE_ON_EXIT); | 1636 ZoneScope zone_scope(Isolate::Current()->runtime_zone()); |
1637 Zone* zone = Isolate::Current()->runtime_zone(); | 1637 Zone* zone = Isolate::Current()->runtime_zone(); |
1638 ZoneList<CharacterRange>* base = | 1638 ZoneList<CharacterRange>* base = |
1639 new(zone) ZoneList<CharacterRange>(1, zone); | 1639 new(zone) ZoneList<CharacterRange>(1, zone); |
1640 base->Add(CharacterRange::Everything(), zone); | 1640 base->Add(CharacterRange::Everything(), zone); |
1641 Vector<const int> overlay = CharacterRange::GetWordBounds(); | 1641 Vector<const int> overlay = CharacterRange::GetWordBounds(); |
1642 ZoneList<CharacterRange>* included = NULL; | 1642 ZoneList<CharacterRange>* included = NULL; |
1643 ZoneList<CharacterRange>* excluded = NULL; | 1643 ZoneList<CharacterRange>* excluded = NULL; |
1644 CharacterRange::Split(base, overlay, &included, &excluded, | 1644 CharacterRange::Split(base, overlay, &included, &excluded, |
1645 Isolate::Current()->runtime_zone()); | 1645 Isolate::Current()->runtime_zone()); |
1646 for (int i = 0; i < (1 << 16); i++) { | 1646 for (int i = 0; i < (1 << 16); i++) { |
1647 bool in_base = InClass(i, base); | 1647 bool in_base = InClass(i, base); |
1648 if (in_base) { | 1648 if (in_base) { |
1649 bool in_overlay = false; | 1649 bool in_overlay = false; |
1650 for (int j = 0; !in_overlay && j < overlay.length(); j += 2) { | 1650 for (int j = 0; !in_overlay && j < overlay.length(); j += 2) { |
1651 if (overlay[j] <= i && i < overlay[j+1]) | 1651 if (overlay[j] <= i && i < overlay[j+1]) |
1652 in_overlay = true; | 1652 in_overlay = true; |
1653 } | 1653 } |
1654 CHECK_EQ(in_overlay, InClass(i, included)); | 1654 CHECK_EQ(in_overlay, InClass(i, included)); |
1655 CHECK_EQ(!in_overlay, InClass(i, excluded)); | 1655 CHECK_EQ(!in_overlay, InClass(i, excluded)); |
1656 } else { | 1656 } else { |
1657 CHECK(!InClass(i, included)); | 1657 CHECK(!InClass(i, included)); |
1658 CHECK(!InClass(i, excluded)); | 1658 CHECK(!InClass(i, excluded)); |
1659 } | 1659 } |
1660 } | 1660 } |
1661 } | 1661 } |
1662 | 1662 |
1663 | 1663 |
1664 TEST(CanonicalizeCharacterSets) { | 1664 TEST(CanonicalizeCharacterSets) { |
1665 v8::internal::V8::Initialize(NULL); | 1665 v8::internal::V8::Initialize(NULL); |
1666 ZoneScope scope(Isolate::Current()->runtime_zone(), DELETE_ON_EXIT); | 1666 ZoneScope scope(Isolate::Current()->runtime_zone()); |
1667 Zone* zone = Isolate::Current()->runtime_zone(); | 1667 Zone* zone = Isolate::Current()->runtime_zone(); |
1668 ZoneList<CharacterRange>* list = | 1668 ZoneList<CharacterRange>* list = |
1669 new(zone) ZoneList<CharacterRange>(4, zone); | 1669 new(zone) ZoneList<CharacterRange>(4, zone); |
1670 CharacterSet set(list); | 1670 CharacterSet set(list); |
1671 | 1671 |
1672 list->Add(CharacterRange(10, 20), zone); | 1672 list->Add(CharacterRange(10, 20), zone); |
1673 list->Add(CharacterRange(30, 40), zone); | 1673 list->Add(CharacterRange(30, 40), zone); |
1674 list->Add(CharacterRange(50, 60), zone); | 1674 list->Add(CharacterRange(50, 60), zone); |
1675 set.Canonicalize(); | 1675 set.Canonicalize(); |
1676 ASSERT_EQ(3, list->length()); | 1676 ASSERT_EQ(3, list->length()); |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1719 list->Add(CharacterRange(20, 20), zone); | 1719 list->Add(CharacterRange(20, 20), zone); |
1720 set.Canonicalize(); | 1720 set.Canonicalize(); |
1721 ASSERT_EQ(1, list->length()); | 1721 ASSERT_EQ(1, list->length()); |
1722 ASSERT_EQ(10, list->at(0).from()); | 1722 ASSERT_EQ(10, list->at(0).from()); |
1723 ASSERT_EQ(30, list->at(0).to()); | 1723 ASSERT_EQ(30, list->at(0).to()); |
1724 } | 1724 } |
1725 | 1725 |
1726 | 1726 |
1727 TEST(CharacterRangeMerge) { | 1727 TEST(CharacterRangeMerge) { |
1728 v8::internal::V8::Initialize(NULL); | 1728 v8::internal::V8::Initialize(NULL); |
1729 ZoneScope zone_scope(Isolate::Current()->runtime_zone(), DELETE_ON_EXIT); | 1729 ZoneScope zone_scope(Isolate::Current()->runtime_zone()); |
1730 ZoneList<CharacterRange> l1(4, Isolate::Current()->runtime_zone()); | 1730 ZoneList<CharacterRange> l1(4, Isolate::Current()->runtime_zone()); |
1731 ZoneList<CharacterRange> l2(4, Isolate::Current()->runtime_zone()); | 1731 ZoneList<CharacterRange> l2(4, Isolate::Current()->runtime_zone()); |
1732 Zone* zone = Isolate::Current()->runtime_zone(); | 1732 Zone* zone = Isolate::Current()->runtime_zone(); |
1733 // Create all combinations of intersections of ranges, both singletons and | 1733 // Create all combinations of intersections of ranges, both singletons and |
1734 // longer. | 1734 // longer. |
1735 | 1735 |
1736 int offset = 0; | 1736 int offset = 0; |
1737 | 1737 |
1738 // The five kinds of singleton intersections: | 1738 // The five kinds of singleton intersections: |
1739 // X | 1739 // X |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1810 ZoneList<CharacterRange> first_only(4, Isolate::Current()->runtime_zone()); | 1810 ZoneList<CharacterRange> first_only(4, Isolate::Current()->runtime_zone()); |
1811 ZoneList<CharacterRange> second_only(4, Isolate::Current()->runtime_zone()); | 1811 ZoneList<CharacterRange> second_only(4, Isolate::Current()->runtime_zone()); |
1812 ZoneList<CharacterRange> both(4, Isolate::Current()->runtime_zone()); | 1812 ZoneList<CharacterRange> both(4, Isolate::Current()->runtime_zone()); |
1813 } | 1813 } |
1814 | 1814 |
1815 | 1815 |
1816 TEST(Graph) { | 1816 TEST(Graph) { |
1817 V8::Initialize(NULL); | 1817 V8::Initialize(NULL); |
1818 Execute("\\b\\w+\\b", false, true, true); | 1818 Execute("\\b\\w+\\b", false, true, true); |
1819 } | 1819 } |
OLD | NEW |