| OLD | NEW |
| 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 1433 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1444 return ActionNode::StoreRegister(reg_ctr, 0, center); | 1444 return ActionNode::StoreRegister(reg_ctr, 0, center); |
| 1445 } else { | 1445 } else { |
| 1446 return center; | 1446 return center; |
| 1447 } | 1447 } |
| 1448 } | 1448 } |
| 1449 | 1449 |
| 1450 | 1450 |
| 1451 RegExpNode* RegExpAssertion::ToNode(RegExpCompiler* compiler, | 1451 RegExpNode* RegExpAssertion::ToNode(RegExpCompiler* compiler, |
| 1452 RegExpNode* on_success, | 1452 RegExpNode* on_success, |
| 1453 RegExpNode* on_failure) { | 1453 RegExpNode* on_failure) { |
| 1454 NodeInfo info; |
| 1454 switch (type()) { | 1455 switch (type()) { |
| 1455 case START_OF_LINE: | 1456 case START_OF_LINE: |
| 1456 on_success->info()->follows_newline_interest = true; | 1457 info.follows_newline_interest = true; |
| 1457 break; | 1458 break; |
| 1458 case START_OF_INPUT: | 1459 case START_OF_INPUT: |
| 1459 on_success->info()->follows_start_interest = true; | 1460 info.follows_start_interest = true; |
| 1460 break; | 1461 break; |
| 1461 case BOUNDARY: case NON_BOUNDARY: | 1462 case BOUNDARY: case NON_BOUNDARY: |
| 1462 on_success->info()->follows_word_interest = true; | 1463 info.follows_word_interest = true; |
| 1463 break; | 1464 break; |
| 1464 case END_OF_LINE: case END_OF_INPUT: | 1465 case END_OF_LINE: case END_OF_INPUT: |
| 1465 // This is wrong but has the effect of making the compiler abort. | 1466 // This is wrong but has the effect of making the compiler abort. |
| 1466 on_success->info()->follows_start_interest = true; | 1467 info.follows_start_interest = true; |
| 1467 } | 1468 } |
| 1468 return on_success; | 1469 return on_success->PropagateInterest(&info); |
| 1469 } | 1470 } |
| 1470 | 1471 |
| 1471 | 1472 |
| 1472 RegExpNode* RegExpBackreference::ToNode(RegExpCompiler* compiler, | 1473 RegExpNode* RegExpBackreference::ToNode(RegExpCompiler* compiler, |
| 1473 RegExpNode* on_success, | 1474 RegExpNode* on_success, |
| 1474 RegExpNode* on_failure) { | 1475 RegExpNode* on_failure) { |
| 1475 return new BackreferenceNode(RegExpCapture::StartRegister(index()), | 1476 return new BackreferenceNode(RegExpCapture::StartRegister(index()), |
| 1476 RegExpCapture::EndRegister(index()), | 1477 RegExpCapture::EndRegister(index()), |
| 1477 on_success, | 1478 on_success, |
| 1478 on_failure); | 1479 on_failure); |
| (...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1632 case '.': | 1633 case '.': |
| 1633 ranges->Add(CharacterRange::Everything()); | 1634 ranges->Add(CharacterRange::Everything()); |
| 1634 break; | 1635 break; |
| 1635 default: | 1636 default: |
| 1636 UNREACHABLE(); | 1637 UNREACHABLE(); |
| 1637 } | 1638 } |
| 1638 } | 1639 } |
| 1639 | 1640 |
| 1640 | 1641 |
| 1641 // ------------------------------------------------------------------- | 1642 // ------------------------------------------------------------------- |
| 1643 // Interest propagation |
| 1644 |
| 1645 |
| 1646 RegExpNode* RegExpNode::GetSibling(NodeInfo* info) { |
| 1647 for (int i = 0; i < siblings_.length(); i++) { |
| 1648 RegExpNode* sibling = siblings_.Get(i); |
| 1649 if (sibling->info()->SameInterests(info)) |
| 1650 return sibling; |
| 1651 } |
| 1652 return NULL; |
| 1653 } |
| 1654 |
| 1655 |
| 1656 template <class C> |
| 1657 static RegExpNode* PropagateToEndpoint(C* node, NodeInfo* info) { |
| 1658 RegExpNode* sibling = node->GetSibling(info); |
| 1659 if (sibling != NULL) return sibling; |
| 1660 node->EnsureSiblings(); |
| 1661 sibling = new C(*node); |
| 1662 sibling->info()->AdoptInterests(info); |
| 1663 node->AddSibling(sibling); |
| 1664 return sibling; |
| 1665 } |
| 1666 |
| 1667 |
| 1668 RegExpNode* ActionNode::PropagateInterest(NodeInfo* info) { |
| 1669 RegExpNode* sibling = GetSibling(info); |
| 1670 if (sibling != NULL) return sibling; |
| 1671 EnsureSiblings(); |
| 1672 ActionNode* action = new ActionNode(*this); |
| 1673 action->set_on_success(action->on_success()->PropagateInterest(info)); |
| 1674 action->info()->AdoptInterests(info); |
| 1675 AddSibling(action); |
| 1676 return action; |
| 1677 } |
| 1678 |
| 1679 |
| 1680 RegExpNode* ChoiceNode::PropagateInterest(NodeInfo* info) { |
| 1681 RegExpNode* sibling = GetSibling(info); |
| 1682 if (sibling != NULL) return sibling; |
| 1683 EnsureSiblings(); |
| 1684 ChoiceNode* choice = new ChoiceNode(*this); |
| 1685 ZoneList<GuardedAlternative>* old_alternatives = alternatives(); |
| 1686 int count = old_alternatives->length(); |
| 1687 choice->alternatives_ = new ZoneList<GuardedAlternative>(count); |
| 1688 for (int i = 0; i < count; i++) { |
| 1689 GuardedAlternative alternative = old_alternatives->at(i); |
| 1690 alternative.set_node(alternative.node()->PropagateInterest(info)); |
| 1691 choice->alternatives()->Add(alternative); |
| 1692 } |
| 1693 choice->info()->AdoptInterests(info); |
| 1694 AddSibling(choice); |
| 1695 return choice; |
| 1696 } |
| 1697 |
| 1698 |
| 1699 RegExpNode* EndNode::PropagateInterest(NodeInfo* info) { |
| 1700 return PropagateToEndpoint(this, info); |
| 1701 } |
| 1702 |
| 1703 |
| 1704 RegExpNode* BackreferenceNode::PropagateInterest(NodeInfo* info) { |
| 1705 return PropagateToEndpoint(this, info); |
| 1706 } |
| 1707 |
| 1708 |
| 1709 RegExpNode* TextNode::PropagateInterest(NodeInfo* info) { |
| 1710 return PropagateToEndpoint(this, info); |
| 1711 } |
| 1712 |
| 1713 |
| 1714 // ------------------------------------------------------------------- |
| 1642 // Splay tree | 1715 // Splay tree |
| 1643 | 1716 |
| 1644 | 1717 |
| 1645 OutSet* OutSet::Extend(unsigned value) { | 1718 OutSet* OutSet::Extend(unsigned value) { |
| 1646 if (Get(value)) | 1719 if (Get(value)) |
| 1647 return this; | 1720 return this; |
| 1648 if (successors() != NULL) { | 1721 if (successors() != NULL) { |
| 1649 for (int i = 0; i < successors()->length(); i++) { | 1722 for (int i = 0; i < successors()->length(); i++) { |
| 1650 OutSet* successor = successors()->at(i); | 1723 OutSet* successor = successors()->at(i); |
| 1651 if (successor->Get(value)) | 1724 if (successor->Get(value)) |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1808 | 1881 |
| 1809 void Analysis::VisitText(TextNode* that) { | 1882 void Analysis::VisitText(TextNode* that) { |
| 1810 EnsureAnalyzed(that->on_success()); | 1883 EnsureAnalyzed(that->on_success()); |
| 1811 EnsureAnalyzed(that->on_failure()); | 1884 EnsureAnalyzed(that->on_failure()); |
| 1812 } | 1885 } |
| 1813 | 1886 |
| 1814 | 1887 |
| 1815 void Analysis::VisitAction(ActionNode* that) { | 1888 void Analysis::VisitAction(ActionNode* that) { |
| 1816 RegExpNode* next = that->on_success(); | 1889 RegExpNode* next = that->on_success(); |
| 1817 EnsureAnalyzed(next); | 1890 EnsureAnalyzed(next); |
| 1818 that->info()->propagate_newline = next->info()->propagate_newline; | 1891 that->info()->determine_newline = next->info()->prev_determine_newline(); |
| 1819 that->info()->propagate_word = next->info()->propagate_word; | 1892 that->info()->determine_word = next->info()->prev_determine_word(); |
| 1820 that->info()->propagate_start = next->info()->propagate_start; | 1893 that->info()->determine_start = next->info()->prev_determine_start(); |
| 1821 } | 1894 } |
| 1822 | 1895 |
| 1823 | 1896 |
| 1824 void Analysis::VisitChoice(ChoiceNode* that) { | 1897 void Analysis::VisitChoice(ChoiceNode* that) { |
| 1825 NodeInfo* info = that->info(); | 1898 NodeInfo* info = that->info(); |
| 1826 for (int i = 0; i < that->alternatives()->length(); i++) { | 1899 for (int i = 0; i < that->alternatives()->length(); i++) { |
| 1827 RegExpNode* node = that->alternatives()->at(i).node(); | 1900 RegExpNode* node = that->alternatives()->at(i).node(); |
| 1828 EnsureAnalyzed(node); | 1901 EnsureAnalyzed(node); |
| 1829 info->propagate_newline |= node->info()->propagate_newline; | 1902 info->determine_newline |= node->info()->prev_determine_newline(); |
| 1830 info->propagate_word |= node->info()->propagate_word; | 1903 info->determine_word |= node->info()->prev_determine_word(); |
| 1831 info->propagate_start |= node->info()->propagate_start; | 1904 info->determine_start |= node->info()->prev_determine_start(); |
| 1832 } | 1905 } |
| 1833 if (!that->table_calculated()) { | 1906 if (!that->table_calculated()) { |
| 1834 DispatchTableConstructor cons(that->table()); | 1907 DispatchTableConstructor cons(that->table()); |
| 1835 cons.BuildTable(that); | 1908 cons.BuildTable(that); |
| 1836 } | 1909 } |
| 1837 EnsureAnalyzed(that->on_failure()); | 1910 EnsureAnalyzed(that->on_failure()); |
| 1838 } | 1911 } |
| 1839 | 1912 |
| 1840 | 1913 |
| 1841 void Analysis::VisitBackreference(BackreferenceNode* that) { | 1914 void Analysis::VisitBackreference(BackreferenceNode* that) { |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1992 } | 2065 } |
| 1993 | 2066 |
| 1994 RegExpMacroAssembler::RegExpMacroAssembler() { | 2067 RegExpMacroAssembler::RegExpMacroAssembler() { |
| 1995 } | 2068 } |
| 1996 | 2069 |
| 1997 RegExpMacroAssembler::~RegExpMacroAssembler() { | 2070 RegExpMacroAssembler::~RegExpMacroAssembler() { |
| 1998 } | 2071 } |
| 1999 | 2072 |
| 2000 | 2073 |
| 2001 }} // namespace v8::internal | 2074 }} // namespace v8::internal |
| OLD | NEW |