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

Side by Side Diff: src/jsregexp.cc

Issue 10831: Regexp bugfixes (Closed)
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
« no previous file with comments | « src/jsregexp.h ('k') | test/cctest/test-regexp.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 1449 matching lines...) Expand 10 before | Expand all | Expand 10 after
1460 // the range we're adding. 1460 // the range we're adding.
1461 ZoneSplayTree<Config>::Locator loc; 1461 ZoneSplayTree<Config>::Locator loc;
1462 ASSERT_RESULT(tree()->Insert(right.from(), &loc)); 1462 ASSERT_RESULT(tree()->Insert(right.from(), &loc));
1463 loc.set_value(Entry(right.from(), 1463 loc.set_value(Entry(right.from(),
1464 right.to(), 1464 right.to(),
1465 entry->out_set())); 1465 entry->out_set()));
1466 } 1466 }
1467 } 1467 }
1468 while (current.is_valid()) { 1468 while (current.is_valid()) {
1469 if (tree()->FindLeastGreaterThan(current.from(), &loc) && 1469 if (tree()->FindLeastGreaterThan(current.from(), &loc) &&
1470 (loc.value().from() <= current.to())) { 1470 (loc.value().from() <= current.to()) &&
1471 (loc.value().to() >= current.from())) {
1471 Entry* entry = &loc.value(); 1472 Entry* entry = &loc.value();
1472 // We have overlap. If there is space between the start point of 1473 // We have overlap. If there is space between the start point of
1473 // the range we're adding and where the overlapping range starts 1474 // the range we're adding and where the overlapping range starts
1474 // then we have to add a range covering just that space. 1475 // then we have to add a range covering just that space.
1475 if (current.from() < entry->from()) { 1476 if (current.from() < entry->from()) {
1476 ZoneSplayTree<Config>::Locator ins; 1477 ZoneSplayTree<Config>::Locator ins;
1477 ASSERT_RESULT(tree()->Insert(current.from(), &ins)); 1478 ASSERT_RESULT(tree()->Insert(current.from(), &ins));
1478 ins.set_value(Entry(current.from(), 1479 ins.set_value(Entry(current.from(),
1479 entry->from() - 1, 1480 entry->from() - 1,
1480 empty()->Extend(value))); 1481 empty()->Extend(value)));
1481 current.set_from(entry->from()); 1482 current.set_from(entry->from());
1482 } 1483 }
1483 ASSERT_EQ(current.from(), entry->from()); 1484 ASSERT_EQ(current.from(), entry->from());
1484 // If the overlapping range extends beyond the one we want to add 1485 // If the overlapping range extends beyond the one we want to add
1485 // we have to snap the right part off and add it separately. 1486 // we have to snap the right part off and add it separately.
1486 if (entry->to() > current.to()) { 1487 if (entry->to() > current.to()) {
1487 ZoneSplayTree<Config>::Locator ins; 1488 ZoneSplayTree<Config>::Locator ins;
1488 ASSERT_RESULT(tree()->Insert(current.to() + 1, &ins)); 1489 ASSERT_RESULT(tree()->Insert(current.to() + 1, &ins));
1489 ins.set_value(Entry(current.to() + 1, 1490 ins.set_value(Entry(current.to() + 1,
1490 entry->to(), 1491 entry->to(),
1491 entry->out_set())); 1492 entry->out_set()));
1492 entry->set_to(current.to()); 1493 entry->set_to(current.to());
1493 } 1494 }
1494 ASSERT(entry->to() <= current.to()); 1495 ASSERT(entry->to() <= current.to());
1495 // The overlapping range is now completely contained by the range 1496 // The overlapping range is now completely contained by the range
1496 // we're adding so we can just update it and move the start point 1497 // we're adding so we can just update it and move the start point
1497 // of the range we're adding just past it. 1498 // of the range we're adding just past it.
1498 entry->AddValue(value); 1499 entry->AddValue(value);
1500 // Bail out if the last interval ended at 0xFFFF since otherwise
1501 // adding 1 will wrap around to 0.
1502 if (entry->to() == 0xFFFF)
1503 break;
1504 ASSERT(entry->to() + 1 > current.from());
1499 current.set_from(entry->to() + 1); 1505 current.set_from(entry->to() + 1);
1500 } else { 1506 } else {
1501 // There is no overlap so we can just add the range 1507 // There is no overlap so we can just add the range
1502 ZoneSplayTree<Config>::Locator ins; 1508 ZoneSplayTree<Config>::Locator ins;
1503 ASSERT_RESULT(tree()->Insert(current.from(), &ins)); 1509 ASSERT_RESULT(tree()->Insert(current.from(), &ins));
1504 ins.set_value(Entry(current.from(), 1510 ins.set_value(Entry(current.from(),
1505 current.to(), 1511 current.to(),
1506 empty()->Extend(value))); 1512 empty()->Extend(value)));
1507 break; 1513 break;
1508 } 1514 }
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
1629 1635
1630 1636
1631 void Analysis::VisitAction(ActionNode* that) { 1637 void Analysis::VisitAction(ActionNode* that) {
1632 Analyze(that->on_success()); 1638 Analyze(that->on_success());
1633 } 1639 }
1634 1640
1635 1641
1636 RegExpNode* RegExpCompiler::Compile(RegExpTree* tree, 1642 RegExpNode* RegExpCompiler::Compile(RegExpTree* tree,
1637 RegExpNode* on_success, 1643 RegExpNode* on_success,
1638 RegExpNode* on_failure) { 1644 RegExpNode* on_failure) {
1639 RegExpNode* node = tree->ToNode(this, on_success, on_failure); 1645 return tree->ToNode(this, on_success, on_failure);
1640 Analysis analysis(this);
1641 analysis.Analyze(node);
1642 return node;
1643 } 1646 }
1644 1647
1645 1648
1646 RegExpNode* RegExpEngine::Compile(RegExpParseResult* input) { 1649 RegExpNode* RegExpEngine::Compile(RegExpParseResult* input) {
1647 RegExpCompiler compiler(input->capture_count); 1650 RegExpCompiler compiler(input->capture_count);
1648 RegExpNode* node = compiler.Compile(input->tree, 1651 RegExpNode* node = compiler.Compile(input->tree,
1649 EndNode::GetAccept(), 1652 EndNode::GetAccept(),
1650 EndNode::GetBacktrack()); 1653 EndNode::GetBacktrack());
1654 Analysis analysis(&compiler);
1655 analysis.Analyze(node);
1651 return node; 1656 return node;
1652 } 1657 }
1653 1658
1654 1659
1655 }} // namespace v8::internal 1660 }} // namespace v8::internal
OLDNEW
« no previous file with comments | « src/jsregexp.h ('k') | test/cctest/test-regexp.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698