| 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 1728 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1739 '0', '9', 'A', 'Z', '_', '_', 'a', 'z' | 1739 '0', '9', 'A', 'Z', '_', '_', 'a', 'z' |
| 1740 }; | 1740 }; |
| 1741 | 1741 |
| 1742 | 1742 |
| 1743 static const int kDigitRangeCount = 2; | 1743 static const int kDigitRangeCount = 2; |
| 1744 static const uc16 kDigitRanges[kDigitRangeCount] = { | 1744 static const uc16 kDigitRanges[kDigitRangeCount] = { |
| 1745 '0', '9' | 1745 '0', '9' |
| 1746 }; | 1746 }; |
| 1747 | 1747 |
| 1748 | 1748 |
| 1749 static const int kLineTerminatorRangeCount = 6; |
| 1750 static const uc16 kLineTerminatorRanges[kLineTerminatorRangeCount] = { |
| 1751 0x000A, 0x000A, 0x000D, 0x000D, 0x2028, 0x2029 |
| 1752 }; |
| 1753 |
| 1754 |
| 1749 static void AddClass(const uc16* elmv, | 1755 static void AddClass(const uc16* elmv, |
| 1750 int elmc, | 1756 int elmc, |
| 1751 ZoneList<CharacterRange>* ranges) { | 1757 ZoneList<CharacterRange>* ranges) { |
| 1752 for (int i = 0; i < elmc; i += 2) { | 1758 for (int i = 0; i < elmc; i += 2) { |
| 1753 ASSERT(elmv[i] <= elmv[i + 1]); | 1759 ASSERT(elmv[i] <= elmv[i + 1]); |
| 1754 ranges->Add(CharacterRange(elmv[i], elmv[i + 1])); | 1760 ranges->Add(CharacterRange(elmv[i], elmv[i + 1])); |
| 1755 } | 1761 } |
| 1756 } | 1762 } |
| 1757 | 1763 |
| 1758 | 1764 |
| (...skipping 28 matching lines...) Expand all Loading... |
| 1787 case 'W': | 1793 case 'W': |
| 1788 AddClassNegated(kWordRanges, kWordRangeCount, ranges); | 1794 AddClassNegated(kWordRanges, kWordRangeCount, ranges); |
| 1789 break; | 1795 break; |
| 1790 case 'd': | 1796 case 'd': |
| 1791 AddClass(kDigitRanges, kDigitRangeCount, ranges); | 1797 AddClass(kDigitRanges, kDigitRangeCount, ranges); |
| 1792 break; | 1798 break; |
| 1793 case 'D': | 1799 case 'D': |
| 1794 AddClassNegated(kDigitRanges, kDigitRangeCount, ranges); | 1800 AddClassNegated(kDigitRanges, kDigitRangeCount, ranges); |
| 1795 break; | 1801 break; |
| 1796 case '.': | 1802 case '.': |
| 1803 AddClassNegated(kLineTerminatorRanges, |
| 1804 kLineTerminatorRangeCount, |
| 1805 ranges); |
| 1806 break; |
| 1807 // This is not a character range as defined by the spec but a |
| 1808 // convenient shorthand for a character class that matches any |
| 1809 // character. |
| 1810 case '*': |
| 1797 ranges->Add(CharacterRange::Everything()); | 1811 ranges->Add(CharacterRange::Everything()); |
| 1798 break; | 1812 break; |
| 1799 default: | 1813 default: |
| 1800 UNREACHABLE(); | 1814 UNREACHABLE(); |
| 1801 } | 1815 } |
| 1802 } | 1816 } |
| 1803 | 1817 |
| 1804 | 1818 |
| 1805 // ------------------------------------------------------------------- | 1819 // ------------------------------------------------------------------- |
| 1806 // Interest propagation | 1820 // Interest propagation |
| (...skipping 397 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2204 compiler.accept(), | 2218 compiler.accept(), |
| 2205 compiler.backtrack()); | 2219 compiler.backtrack()); |
| 2206 // Add a .*? at the beginning, outside the body capture. | 2220 // Add a .*? at the beginning, outside the body capture. |
| 2207 // Note: We could choose to not add this if the regexp is anchored at | 2221 // Note: We could choose to not add this if the regexp is anchored at |
| 2208 // the start of the input but I'm not sure how best to do that and | 2222 // the start of the input but I'm not sure how best to do that and |
| 2209 // since we don't even handle ^ yet I'm saving that optimization for | 2223 // since we don't even handle ^ yet I'm saving that optimization for |
| 2210 // later. | 2224 // later. |
| 2211 RegExpNode* node = RegExpQuantifier::ToNode(0, | 2225 RegExpNode* node = RegExpQuantifier::ToNode(0, |
| 2212 RegExpQuantifier::kInfinity, | 2226 RegExpQuantifier::kInfinity, |
| 2213 false, | 2227 false, |
| 2214 new RegExpCharacterClass('.'), | 2228 new RegExpCharacterClass('*'), |
| 2215 &compiler, | 2229 &compiler, |
| 2216 captured_body, | 2230 captured_body, |
| 2217 compiler.backtrack()); | 2231 compiler.backtrack()); |
| 2218 if (node_return != NULL) *node_return = node; | 2232 if (node_return != NULL) *node_return = node; |
| 2219 Analysis analysis; | 2233 Analysis analysis; |
| 2220 analysis.EnsureAnalyzed(node); | 2234 analysis.EnsureAnalyzed(node); |
| 2221 byte codes[1024]; | 2235 byte codes[1024]; |
| 2222 Re2kAssembler assembler(Vector<byte>(codes, 1024)); | 2236 Re2kAssembler assembler(Vector<byte>(codes, 1024)); |
| 2223 RegExpMacroAssemblerRe2k macro_assembler(&assembler); | 2237 RegExpMacroAssemblerRe2k macro_assembler(&assembler); |
| 2224 return compiler.Assemble(¯o_assembler, | 2238 return compiler.Assemble(¯o_assembler, |
| 2225 node, | 2239 node, |
| 2226 input->capture_count, | 2240 input->capture_count, |
| 2227 ignore_case); | 2241 ignore_case); |
| 2228 } | 2242 } |
| 2229 | 2243 |
| 2230 RegExpMacroAssembler::RegExpMacroAssembler() { | 2244 RegExpMacroAssembler::RegExpMacroAssembler() { |
| 2231 } | 2245 } |
| 2232 | 2246 |
| 2233 RegExpMacroAssembler::~RegExpMacroAssembler() { | 2247 RegExpMacroAssembler::~RegExpMacroAssembler() { |
| 2234 } | 2248 } |
| 2235 | 2249 |
| 2236 | 2250 |
| 2237 }} // namespace v8::internal | 2251 }} // namespace v8::internal |
| OLD | NEW |