Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(110)

Side by Side Diff: test/cctest/test-regexp.cc

Issue 10830: * We want to be able to find atoms and character classes without advancing th... (Closed) Base URL: http://v8.googlecode.com/svn/branches/experimental/regexp2000/
Patch Set: Created 12 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 19 matching lines...) Expand all
30 #include <set> 30 #include <set>
31 31
32 #include "v8.h" 32 #include "v8.h"
33 33
34 #include "cctest.h" 34 #include "cctest.h"
35 #include "zone-inl.h" 35 #include "zone-inl.h"
36 #include "parser.h" 36 #include "parser.h"
37 #include "ast.h" 37 #include "ast.h"
38 #include "jsregexp-inl.h" 38 #include "jsregexp-inl.h"
39 #include "assembler-re2k.h" 39 #include "assembler-re2k.h"
40 #include "regexp-macro-assembler.h"
41 #include "regexp-macro-assembler-re2k.h"
40 #include "interpreter-re2k.h" 42 #include "interpreter-re2k.h"
41 43
42 44
43 using namespace v8::internal; 45 using namespace v8::internal;
44 46
45 47
46 static SmartPointer<char> Parse(const char* input) { 48 static SmartPointer<char> Parse(const char* input) {
47 v8::HandleScope scope; 49 v8::HandleScope scope;
48 unibrow::Utf8InputBuffer<> buffer(input, strlen(input)); 50 unibrow::Utf8InputBuffer<> buffer(input, strlen(input));
49 ZoneScope zone_scope(DELETE_ON_EXIT); 51 ZoneScope zone_scope(DELETE_ON_EXIT);
(...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after
336 RegExpParseResult result; 338 RegExpParseResult result;
337 if (!v8::internal::ParseRegExp(&buffer, &result)) 339 if (!v8::internal::ParseRegExp(&buffer, &result))
338 return; 340 return;
339 RegExpNode* node = RegExpEngine::Compile(&result); 341 RegExpNode* node = RegExpEngine::Compile(&result);
340 USE(node); 342 USE(node);
341 #ifdef DEBUG 343 #ifdef DEBUG
342 if (dot_output) { 344 if (dot_output) {
343 RegExpEngine::DotPrint(input, node); 345 RegExpEngine::DotPrint(input, node);
344 exit(0); 346 exit(0);
345 } 347 }
346 #endif // DEBUG 348 #endif // DEBUG
347 } 349 }
348 350
349 351
350 TEST(Execution) { 352 TEST(Execution) {
351 V8::Initialize(NULL); 353 V8::Initialize(NULL);
352 // Execute(".*?(?:a[bc]d|e[fg]h)", "xxxabbegh"); 354 // Execute(".*?(?:a[bc]d|e[fg]h)", "xxxabbegh");
353 // Execute(".*?(?:a[bc]d|e[fg]h)", "xxxabbefh"); 355 // Execute(".*?(?:a[bc]d|e[fg]h)", "xxxabbefh");
354 // Execute(".*?(?:a[bc]d|e[fg]h)", "xxxabbefd"); 356 // Execute(".*?(?:a[bc]d|e[fg]h)", "xxxabbefd");
355 } 357 }
356 358
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
483 } 485 }
484 486
485 487
486 TEST(Assembler) { 488 TEST(Assembler) {
487 V8::Initialize(NULL); 489 V8::Initialize(NULL);
488 byte codes[1024]; 490 byte codes[1024];
489 Re2kAssembler assembler(Vector<byte>(codes, 1024)); 491 Re2kAssembler assembler(Vector<byte>(codes, 1024));
490 #define __ assembler. 492 #define __ assembler.
491 Label advance; 493 Label advance;
492 Label look_for_foo; 494 Label look_for_foo;
495 Label fail;
493 __ GoTo(&look_for_foo); 496 __ GoTo(&look_for_foo);
494 __ Bind(&advance); 497 __ Bind(&advance);
495 __ AdvanceCP(); 498 __ AdvanceCP(1);
496 __ Bind(&look_for_foo); 499 __ Bind(&look_for_foo);
497 __ FailIfWithin(3); 500 __ LoadCurrentChar(0, &fail);
498 __ LoadCurrentChar(0);
499 __ CheckChar('f', &advance); 501 __ CheckChar('f', &advance);
500 __ LoadCurrentChar(1); 502 __ LoadCurrentChar(1, &fail);
501 __ CheckChar('o', &advance); 503 __ CheckChar('o', &advance);
502 __ LoadCurrentChar(2); 504 __ LoadCurrentChar(2, &fail);
503 __ CheckChar('o', &advance); 505 __ CheckChar('o', &advance);
504 __ SetRegisterToCurrentPosition(0); 506 __ SetRegisterToCurrentPosition(0);
505 __ SetRegisterToCurrentPosition(1, 2); 507 __ SetRegisterToCurrentPosition(1, 2);
506 __ Succeed(); 508 __ Succeed();
509 __ Bind(&fail);
510 __ Fail();
507 511
508 v8::HandleScope scope; 512 v8::HandleScope scope;
509 Handle<ByteArray> array = Factory::NewByteArray(assembler.length()); 513 Handle<ByteArray> array = Factory::NewByteArray(assembler.length());
510 assembler.Copy(array->GetDataStartAddress()); 514 assembler.Copy(array->GetDataStartAddress());
511 int captures[2]; 515 int captures[2];
512 516
513 Handle<String> f1 = 517 Handle<String> f1 =
514 Factory::NewStringFromAscii(CStrVector("Now is the time")); 518 Factory::NewStringFromAscii(CStrVector("Now is the time"));
515 CHECK(!Re2kInterpreter::Match(*array, *f1, captures, 0)); 519 CHECK(!Re2kInterpreter::Match(array, f1, captures, 0));
516 520
517 Handle<String> f2 = Factory::NewStringFromAscii(CStrVector("foo bar baz")); 521 Handle<String> f2 = Factory::NewStringFromAscii(CStrVector("foo bar baz"));
518 CHECK(Re2kInterpreter::Match(*array, *f2, captures, 0)); 522 CHECK(Re2kInterpreter::Match(array, f2, captures, 0));
519 CHECK_EQ(0, captures[0]); 523 CHECK_EQ(0, captures[0]);
520 CHECK_EQ(2, captures[1]); 524 CHECK_EQ(2, captures[1]);
521 525
522 Handle<String> f3 = Factory::NewStringFromAscii(CStrVector("tomfoolery")); 526 Handle<String> f3 = Factory::NewStringFromAscii(CStrVector("tomfoolery"));
523 CHECK(Re2kInterpreter::Match(*array, *f3, captures, 0)); 527 CHECK(Re2kInterpreter::Match(array, f3, captures, 0));
524 CHECK_EQ(3, captures[0]); 528 CHECK_EQ(3, captures[0]);
525 CHECK_EQ(5, captures[1]); 529 CHECK_EQ(5, captures[1]);
526 } 530 }
527 531
528 532
529 TEST(Assembler2) { 533 TEST(Assembler2) {
530 V8::Initialize(NULL); 534 V8::Initialize(NULL);
531 byte codes[1024]; 535 byte codes[1024];
532 Re2kAssembler assembler(Vector<byte>(codes, 1024)); 536 Re2kAssembler assembler(Vector<byte>(codes, 1024));
533 #define __ assembler. 537 #define __ assembler.
534 // /^.*foo/ 538 // /^.*foo/
535 Label more_dots; 539 Label more_dots;
536 Label unwind_dot; 540 Label unwind_dot;
537 Label failure; 541 Label failure;
538 Label foo; 542 Label foo;
539 Label foo_failed; 543 Label foo_failed;
540 Label dot_match; 544 Label dot_match;
541 // ^ 545 // ^
542 __ PushCurrentPosition(); 546 __ PushCurrentPosition();
543 __ PushRegister(0); 547 __ PushRegister(0);
544 __ SetRegisterToCurrentPosition(0); 548 __ SetRegisterToCurrentPosition(0);
545 __ PushBacktrack(&failure); 549 __ PushBacktrack(&failure);
546 __ GoTo(&dot_match); 550 __ GoTo(&dot_match);
547 // .* 551 // .*
548 __ Bind(&more_dots); 552 __ Bind(&more_dots);
549 __ AdvanceCP(); 553 __ AdvanceCP(1);
550 __ Bind(&dot_match); 554 __ Bind(&dot_match);
551 __ PushCurrentPosition(); 555 __ PushCurrentPosition();
552 __ PushBacktrack(&unwind_dot); 556 __ PushBacktrack(&unwind_dot);
553 __ LoadCurrentChar(); 557 __ LoadCurrentChar(0, &foo);
554 __ CheckNotEnd(&foo);
555 __ CheckChar('\n', &more_dots); 558 __ CheckChar('\n', &more_dots);
556 // foo 559 // foo
557 __ Bind(&foo); 560 __ Bind(&foo);
558 __ CheckChar('f', &foo_failed); 561 __ CheckChar('f', &foo_failed);
559 __ LoadCurrentChar(1); 562 __ LoadCurrentChar(1, &foo_failed);
560 __ CheckChar('o', &foo_failed); 563 __ CheckChar('o', &foo_failed);
561 __ LoadCurrentChar(2); 564 __ LoadCurrentChar(2, &foo_failed);
562 __ CheckChar('o', &foo_failed); 565 __ CheckChar('o', &foo_failed);
563 __ SetRegisterToCurrentPosition(1, 2); 566 __ SetRegisterToCurrentPosition(1, 2);
564 __ Succeed(); 567 __ Succeed();
565 __ Break(); 568 __ Break();
566 569
567 __ Bind(&foo_failed); 570 __ Bind(&foo_failed);
568 __ PopBacktrack(); 571 __ PopBacktrack();
569 __ Break(); 572 __ Break();
570 573
571 __ Bind(&unwind_dot); 574 __ Bind(&unwind_dot);
572 __ PopCurrentPosition(); 575 __ PopCurrentPosition();
573 __ LoadCurrentChar(); 576 __ LoadCurrentChar(0, &foo_failed);
574 __ GoTo(&foo); 577 __ GoTo(&foo);
575 578
576 __ Bind(&failure); 579 __ Bind(&failure);
577 __ PopRegister(0); 580 __ PopRegister(0);
578 __ PopCurrentPosition(); 581 __ PopCurrentPosition();
579 __ Fail(); 582 __ Fail();
580 583
581 v8::HandleScope scope; 584 v8::HandleScope scope;
582 Handle<ByteArray> array = Factory::NewByteArray(assembler.length()); 585 Handle<ByteArray> array = Factory::NewByteArray(assembler.length());
583 assembler.Copy(array->GetDataStartAddress()); 586 assembler.Copy(array->GetDataStartAddress());
584 int captures[2]; 587 int captures[2];
585 588
586 Handle<String> f1 = 589 Handle<String> f1 =
587 Factory::NewStringFromAscii(CStrVector("Now is the time")); 590 Factory::NewStringFromAscii(CStrVector("Now is the time"));
588 CHECK(!Re2kInterpreter::Match(*array, *f1, captures, 0)); 591 CHECK(!Re2kInterpreter::Match(array, f1, captures, 0));
589 592
590 Handle<String> f2 = Factory::NewStringFromAscii(CStrVector("foo bar baz")); 593 Handle<String> f2 = Factory::NewStringFromAscii(CStrVector("foo bar baz"));
591 CHECK(Re2kInterpreter::Match(*array, *f2, captures, 0)); 594 CHECK(Re2kInterpreter::Match(array, f2, captures, 0));
592 CHECK_EQ(0, captures[0]); 595 CHECK_EQ(0, captures[0]);
593 CHECK_EQ(2, captures[1]); 596 CHECK_EQ(2, captures[1]);
594 597
595 Handle<String> f3 = Factory::NewStringFromAscii(CStrVector("tomfoolery")); 598 Handle<String> f3 = Factory::NewStringFromAscii(CStrVector("tomfoolery"));
596 CHECK(Re2kInterpreter::Match(*array, *f3, captures, 0)); 599 CHECK(Re2kInterpreter::Match(array, f3, captures, 0));
597 CHECK_EQ(0, captures[0]); 600 CHECK_EQ(0, captures[0]);
598 CHECK_EQ(5, captures[1]); 601 CHECK_EQ(5, captures[1]);
599 602
600 Handle<String> f4 = 603 Handle<String> f4 =
601 Factory::NewStringFromAscii(CStrVector("football buffoonery")); 604 Factory::NewStringFromAscii(CStrVector("football buffoonery"));
602 CHECK(Re2kInterpreter::Match(*array, *f4, captures, 0)); 605 CHECK(Re2kInterpreter::Match(array, f4, captures, 0));
603 CHECK_EQ(0, captures[0]); 606 CHECK_EQ(0, captures[0]);
604 CHECK_EQ(14, captures[1]); 607 CHECK_EQ(14, captures[1]);
605 608
606 Handle<String> f5 = 609 Handle<String> f5 =
607 Factory::NewStringFromAscii(CStrVector("walking\nbarefoot")); 610 Factory::NewStringFromAscii(CStrVector("walking\nbarefoot"));
608 CHECK(!Re2kInterpreter::Match(*array, *f5, captures, 0)); 611 CHECK(!Re2kInterpreter::Match(array, f5, captures, 0));
612 }
613
614
615 TEST(MacroAssembler) {
616 V8::Initialize(NULL);
617 byte codes[1024];
618 Re2kAssembler assembler(Vector<byte>(codes, 1024));
619 RegExpMacroAssemblerRe2k m(&assembler);
620 // ^f(o)o.
621 Label fail, fail2, start;
622 uc16 foo_chars[3];
623 foo_chars[0] = 'f';
624 foo_chars[1] = 'o';
625 foo_chars[2] = 'o';
626 Vector<const uc16> foo(foo_chars, 3);
627 m.SetRegister(4, 42);
628 m.PushRegister(4);
629 m.AdvanceRegister(4, 42);
630 m.GoTo(&start);
631 m.Fail();
632 m.Bind(&start);
633 m.PushBacktrack(&fail2);
634 m.CheckCharacters(foo, 0, &fail);
635 m.WriteCurrentPositionToRegister(0);
636 m.PushCurrentPosition();
637 m.AdvanceCurrentPosition(3);
638 m.WriteCurrentPositionToRegister(1);
639 m.PopCurrentPosition();
640 m.AdvanceCurrentPosition(1);
641 m.WriteCurrentPositionToRegister(2);
642 m.AdvanceCurrentPosition(1);
643 m.WriteCurrentPositionToRegister(3);
644 m.Succeed();
645
646 m.Bind(&fail);
647 m.Backtrack();
648 m.Succeed();
649
650 m.Bind(&fail2);
651 m.PopRegister(0);
652 m.Fail();
653
654 v8::HandleScope scope;
655
656 Handle<ByteArray> array = Factory::NewByteArray(assembler.length());
657 assembler.Copy(array->GetDataStartAddress());
658 int captures[5];
659
660 Handle<String> f1 =
661 Factory::NewStringFromAscii(CStrVector("foobar"));
662 CHECK(Re2kInterpreter::Match(array, f1, captures, 0));
663 CHECK_EQ(0, captures[0]);
664 CHECK_EQ(3, captures[1]);
665 CHECK_EQ(1, captures[2]);
666 CHECK_EQ(2, captures[3]);
667 CHECK_EQ(84, captures[4]);
668
669 Handle<String> f2 =
670 Factory::NewStringFromAscii(CStrVector("barfoo"));
671 CHECK(!Re2kInterpreter::Match(array, f2, captures, 0));
672 CHECK_EQ(42, captures[0]);
609 } 673 }
610 674
611 675
612 TEST(AddInverseToTable) { 676 TEST(AddInverseToTable) {
613 static const int kLimit = 1000; 677 static const int kLimit = 1000;
614 static const int kRangeCount = 16; 678 static const int kRangeCount = 16;
615 ZoneScope zone_scope(DELETE_ON_EXIT); 679 ZoneScope zone_scope(DELETE_ON_EXIT);
616 ZoneList<CharacterRange>* range = new ZoneList<CharacterRange>(kRangeCount); 680 ZoneList<CharacterRange>* range = new ZoneList<CharacterRange>(kRangeCount);
617 for (int i = 0; i < kRangeCount; i++) { 681 for (int i = 0; i < kRangeCount; i++) {
618 int from = PseudoRandom(87, i + 25) % kLimit; 682 int from = PseudoRandom(87, i + 25) % kLimit;
619 int to = PseudoRandom(i + 87, 25) % (kLimit / 20); 683 int to = PseudoRandom(i + 87, 25) % (kLimit / 20);
620 if (to > kLimit) to = kLimit; 684 if (to > kLimit) to = kLimit;
621 range->Add(CharacterRange(from, to)); 685 range->Add(CharacterRange(from, to));
622 } 686 }
623 DispatchTable table; 687 DispatchTable table;
624 // CharacterClassNode::AddInverseToTable(range, &table, 0); 688 // CharacterClassNode::AddInverseToTable(range, &table, 0);
625 } 689 }
626 690
627 691
628 TEST(Graph) { 692 TEST(Graph) {
629 Execute("([^a]|\\w)", "", true); 693 Execute("([^a]|\\w)", "", true);
630 } 694 }
OLDNEW
« src/regexp-macro-assembler.h ('K') | « src/regexp-macro-assembler-re2k.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698