| 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 1175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1186 | 1186 |
| 1187 | 1187 |
| 1188 TextElement TextElement::CharClass( | 1188 TextElement TextElement::CharClass( |
| 1189 RegExpCharacterClass* char_class) { | 1189 RegExpCharacterClass* char_class) { |
| 1190 TextElement result = TextElement(CHAR_CLASS); | 1190 TextElement result = TextElement(CHAR_CLASS); |
| 1191 result.data.u_char_class = char_class; | 1191 result.data.u_char_class = char_class; |
| 1192 return result; | 1192 return result; |
| 1193 } | 1193 } |
| 1194 | 1194 |
| 1195 | 1195 |
| 1196 int TextElement::length() { |
| 1197 if (type == ATOM) { |
| 1198 return data.u_atom->length(); |
| 1199 } else { |
| 1200 ASSERT(type == CHAR_CLASS); |
| 1201 return 1; |
| 1202 } |
| 1203 } |
| 1204 |
| 1205 |
| 1196 DispatchTable* ChoiceNode::GetTable(bool ignore_case) { | 1206 DispatchTable* ChoiceNode::GetTable(bool ignore_case) { |
| 1197 if (table_ == NULL) { | 1207 if (table_ == NULL) { |
| 1198 table_ = new DispatchTable(); | 1208 table_ = new DispatchTable(); |
| 1199 DispatchTableConstructor cons(table_, ignore_case); | 1209 DispatchTableConstructor cons(table_, ignore_case); |
| 1200 cons.BuildTable(this); | 1210 cons.BuildTable(this); |
| 1201 } | 1211 } |
| 1202 return table_; | 1212 return table_; |
| 1203 } | 1213 } |
| 1204 | 1214 |
| 1205 | 1215 |
| (...skipping 1454 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2660 // | (x) | 2670 // | (x) |
| 2661 // v ^ | 2671 // v ^ |
| 2662 // (r=0)-->(?)---/ [if r < t] | 2672 // (r=0)-->(?)---/ [if r < t] |
| 2663 // | | 2673 // | |
| 2664 // [if r >= f] \----> ... | 2674 // [if r >= f] \----> ... |
| 2665 // | 2675 // |
| 2666 // | 2676 // |
| 2667 // TODO(someone): clear captures on repetition and handle empty | 2677 // TODO(someone): clear captures on repetition and handle empty |
| 2668 // matches. | 2678 // matches. |
| 2669 bool has_min = min > 0; | 2679 bool has_min = min > 0; |
| 2670 bool has_max = max < RegExpQuantifier::kInfinity; | 2680 bool has_max = max < RegExpTree::kInfinity; |
| 2671 bool needs_counter = has_min || has_max; | 2681 bool needs_counter = has_min || has_max; |
| 2672 int reg_ctr = needs_counter ? compiler->AllocateRegister() : -1; | 2682 int reg_ctr = needs_counter ? compiler->AllocateRegister() : -1; |
| 2673 ChoiceNode* center = new LoopChoiceNode(2); | 2683 ChoiceNode* center = new LoopChoiceNode(2); |
| 2674 RegExpNode* loop_return = needs_counter | 2684 RegExpNode* loop_return = needs_counter |
| 2675 ? static_cast<RegExpNode*>(ActionNode::IncrementRegister(reg_ctr, center)) | 2685 ? static_cast<RegExpNode*>(ActionNode::IncrementRegister(reg_ctr, center)) |
| 2676 : static_cast<RegExpNode*>(center); | 2686 : static_cast<RegExpNode*>(center); |
| 2677 RegExpNode* body_node = body->ToNode(compiler, loop_return); | 2687 RegExpNode* body_node = body->ToNode(compiler, loop_return); |
| 2678 GuardedAlternative body_alt(body_node); | 2688 GuardedAlternative body_alt(body_node); |
| 2679 if (has_max) { | 2689 if (has_max) { |
| 2680 Guard* body_guard = new Guard(reg_ctr, Guard::LT, max); | 2690 Guard* body_guard = new Guard(reg_ctr, Guard::LT, max); |
| (...skipping 1096 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3777 RegExpNode* captured_body = RegExpCapture::ToNode(data->tree, | 3787 RegExpNode* captured_body = RegExpCapture::ToNode(data->tree, |
| 3778 0, | 3788 0, |
| 3779 &compiler, | 3789 &compiler, |
| 3780 compiler.accept()); | 3790 compiler.accept()); |
| 3781 // Add a .*? at the beginning, outside the body capture. | 3791 // Add a .*? at the beginning, outside the body capture. |
| 3782 // Note: We could choose to not add this if the regexp is anchored at | 3792 // Note: We could choose to not add this if the regexp is anchored at |
| 3783 // the start of the input but I'm not sure how best to do that and | 3793 // the start of the input but I'm not sure how best to do that and |
| 3784 // since we don't even handle ^ yet I'm saving that optimization for | 3794 // since we don't even handle ^ yet I'm saving that optimization for |
| 3785 // later. | 3795 // later. |
| 3786 RegExpNode* node = RegExpQuantifier::ToNode(0, | 3796 RegExpNode* node = RegExpQuantifier::ToNode(0, |
| 3787 RegExpQuantifier::kInfinity, | 3797 RegExpTree::kInfinity, |
| 3788 false, | 3798 false, |
| 3789 new RegExpCharacterClass('*'), | 3799 new RegExpCharacterClass('*'), |
| 3790 &compiler, | 3800 &compiler, |
| 3791 captured_body); | 3801 captured_body); |
| 3792 AssertionPropagation analysis(ignore_case); | 3802 AssertionPropagation analysis(ignore_case); |
| 3793 analysis.EnsureAnalyzed(node); | 3803 analysis.EnsureAnalyzed(node); |
| 3794 | 3804 |
| 3795 NodeInfo info = *node->info(); | 3805 NodeInfo info = *node->info(); |
| 3796 data->has_lookbehind = info.HasLookbehind(); | 3806 data->has_lookbehind = info.HasLookbehind(); |
| 3797 if (data->has_lookbehind) { | 3807 if (data->has_lookbehind) { |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3847 EmbeddedVector<byte, 1024> codes; | 3857 EmbeddedVector<byte, 1024> codes; |
| 3848 RegExpMacroAssemblerIrregexp macro_assembler(codes); | 3858 RegExpMacroAssemblerIrregexp macro_assembler(codes); |
| 3849 return compiler.Assemble(¯o_assembler, | 3859 return compiler.Assemble(¯o_assembler, |
| 3850 node, | 3860 node, |
| 3851 data->capture_count, | 3861 data->capture_count, |
| 3852 pattern); | 3862 pattern); |
| 3853 } | 3863 } |
| 3854 | 3864 |
| 3855 | 3865 |
| 3856 }} // namespace v8::internal | 3866 }} // namespace v8::internal |
| OLD | NEW |