Reviewers: Erik Corry, Description: Fixed a bug in graph conversion and one in dispatch table construction.
Please review this at http://codereview.chromium.org/10831 Affected files: M src/jsregexp.h M src/jsregexp.cc M test/cctest/test-regexp.cc Index: src/jsregexp.cc diff --git a/src/jsregexp.cc b/src/jsregexp.cc index 6187df921ea40816d9e16e5bb941c3367b3970ee..633be24f8eaa0b869c51f34ff1a44590543fa0b1 100644 --- a/src/jsregexp.cc +++ b/src/jsregexp.cc @@ -1467,7 +1467,8 @@ void DispatchTable::AddRange(CharacterRange full_range, int value) { } while (current.is_valid()) { if (tree()->FindLeastGreaterThan(current.from(), &loc) && - (loc.value().from() <= current.to())) { + (loc.value().from() <= current.to()) && + (loc.value().to() >= current.from())) { Entry* entry = &loc.value(); // We have overlap. If there is space between the start point of // the range we're adding and where the overlapping range starts @@ -1496,6 +1497,11 @@ void DispatchTable::AddRange(CharacterRange full_range, int value) { // we're adding so we can just update it and move the start point // of the range we're adding just past it. entry->AddValue(value); + // Bail out if the last interval ended at 0xFFFF since otherwise + // adding 1 will wrap around to 0. + if (entry->to() == 0xFFFF) + break; + ASSERT(entry->to() + 1 > current.from()); current.set_from(entry->to() + 1); } else { // There is no overlap so we can just add the range @@ -1636,10 +1642,7 @@ void Analysis::VisitAction(ActionNode* that) { RegExpNode* RegExpCompiler::Compile(RegExpTree* tree, RegExpNode* on_success, RegExpNode* on_failure) { - RegExpNode* node = tree->ToNode(this, on_success, on_failure); - Analysis analysis(this); - analysis.Analyze(node); - return node; + return tree->ToNode(this, on_success, on_failure); } @@ -1648,6 +1651,8 @@ RegExpNode* RegExpEngine::Compile(RegExpParseResult* input) { RegExpNode* node = compiler.Compile(input->tree, EndNode::GetAccept(), EndNode::GetBacktrack()); + Analysis analysis(&compiler); + analysis.Analyze(node); return node; } Index: src/jsregexp.h diff --git a/src/jsregexp.h b/src/jsregexp.h index 10176dc41e483d574f475a989163d6e8fac745e6..f4741cb860b0e7aa4ef0ad99ef53bbc289c2b379 100644 --- a/src/jsregexp.h +++ b/src/jsregexp.h @@ -287,7 +287,7 @@ class OutSet: public ZoneObject { ZoneList<OutSet*>* successors() { return successors_; } OutSet(uint32_t first, ZoneList<unsigned>* remaining) - : first_(first), remaining_(remaining) { } + : first_(first), remaining_(remaining), successors_(NULL) { } uint32_t first_; ZoneList<unsigned>* remaining_; ZoneList<OutSet*>* successors_; @@ -301,7 +301,7 @@ class DispatchTable { class Entry { public: Entry() - : from_(0), to_(0) { } + : from_(0), to_(0), out_set_(NULL) { } Entry(uc16 from, uc16 to, OutSet* out_set) : from_(from), to_(to), out_set_(out_set) { } uc16 from() { return from_; } Index: test/cctest/test-regexp.cc diff --git a/test/cctest/test-regexp.cc b/test/cctest/test-regexp.cc index 6e8587fec171cd86f62a4f9e889403f841d7620b..0b97f4110975cf2e49e5f35cdee6ccd193a565d3 100644 --- a/test/cctest/test-regexp.cc +++ b/test/cctest/test-regexp.cc @@ -349,9 +349,9 @@ static void Execute(const char* input, TEST(Execution) { V8::Initialize(NULL); - // Execute(".*?(?:a[bc]d|e[fg]h)", "xxxabbegh"); - // Execute(".*?(?:a[bc]d|e[fg]h)", "xxxabbefh"); - // Execute(".*?(?:a[bc]d|e[fg]h)", "xxxabbefd"); + Execute(".*?(?:a[bc]d|e[fg]h)", "xxxabbegh"); + Execute(".*?(?:a[bc]d|e[fg]h)", "xxxabbefh"); + Execute(".*?(?:a[bc]d|e[fg]h)", "xxxabbefd"); } @@ -626,5 +626,5 @@ TEST(AddInverseToTable) { TEST(Graph) { - Execute("([^a]|\\w)", "", true); + Execute(".*?a", "", true); } --~--~---------~--~----~------------~-------~--~----~ v8-dev mailing list v8-dev@googlegroups.com http://groups.google.com/group/v8-dev -~----------~----~----~----~------~----~------~--~---