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 2677 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2688 // | ` | 2688 // | ` |
2689 // | (x) | 2689 // | (x) |
2690 // v ^ | 2690 // v ^ |
2691 // (r=0)-->(?)---/ [if r < t] | 2691 // (r=0)-->(?)---/ [if r < t] |
2692 // | | 2692 // | |
2693 // [if r >= f] \----> ... | 2693 // [if r >= f] \----> ... |
2694 // | 2694 // |
2695 // | 2695 // |
2696 // TODO(someone): clear captures on repetition and handle empty | 2696 // TODO(someone): clear captures on repetition and handle empty |
2697 // matches. | 2697 // matches. |
2698 | |
2699 // 15.10.2.5 RepeatMatcher algorithm. | |
2700 // The parser has already eliminated the case where max is 0. In the case | |
2701 // where max_match is zero the parser has removed the quantifier if min was | |
2702 // > 0 and removed the atom if min was 0. See AddQuantifierToAtom. | |
2703 | |
2704 // If we know that we cannot match zero length then things are a little | |
2705 // simpler since we don't need to make the special zero length match check | |
2706 // from step 2.1. If the min and max are small we can unroll a little in | |
2707 // this case. | |
2708 if (max == 0) return on_success; // This can happen due to recursion. | |
2709 if (body->min_match() > 0) { | |
2710 if (min > 0 && min <= 3) { | |
Lasse Reichstein
2008/12/18 12:34:17
static const int kMaxUnrollRepetition = 3;
| |
2711 int new_max = (max == kInfinity) ? max : max - min; | |
2712 // Recurse once to get the loop or optional matches after the fixed ones. | |
2713 RegExpNode* answer = | |
2714 ToNode(0, new_max, is_greedy, body, compiler, on_success); | |
2715 // Unroll the forced matches from 0 to min. This can cause chains of | |
2716 // TextNodes (which the parser does not generate). | |
Lasse Reichstein
2008/12/18 12:34:17
Will these chains of text nodes normalied at a lat
| |
2717 for (int i = 0; i < min; i++) { | |
2718 answer = body->ToNode(compiler, answer); | |
2719 } | |
2720 return answer; | |
2721 } | |
2722 if (max <= 3) { | |
Lasse Reichstein
2008/12/18 12:34:17
Same constant, or another?
| |
2723 ASSERT(min == 0); | |
2724 // Unroll the optional matches up to max. | |
2725 RegExpNode* answer = on_success; | |
2726 for (int i = 0; i < max; i++) { | |
2727 ChoiceNode* alternation = new ChoiceNode(2); | |
2728 if (is_greedy) { | |
2729 alternation->AddAlternative(GuardedAlternative(body->ToNode(compiler, answer))); | |
2730 alternation->AddAlternative(GuardedAlternative(on_success)); | |
2731 } else { | |
2732 alternation->AddAlternative(GuardedAlternative(on_success)); | |
2733 alternation->AddAlternative(GuardedAlternative(body->ToNode(compiler, answer))); | |
2734 } | |
2735 answer = alternation; | |
2736 } | |
2737 return answer; | |
2738 } | |
2739 } | |
2698 bool has_min = min > 0; | 2740 bool has_min = min > 0; |
2699 bool has_max = max < RegExpTree::kInfinity; | 2741 bool has_max = max < RegExpTree::kInfinity; |
2700 bool needs_counter = has_min || has_max; | 2742 bool needs_counter = has_min || has_max; |
2701 int reg_ctr = needs_counter ? compiler->AllocateRegister() : -1; | 2743 int reg_ctr = needs_counter ? compiler->AllocateRegister() : -1; |
2702 LoopChoiceNode* center = new LoopChoiceNode(); | 2744 LoopChoiceNode* center = new LoopChoiceNode(); |
2703 RegExpNode* loop_return = needs_counter | 2745 RegExpNode* loop_return = needs_counter |
2704 ? static_cast<RegExpNode*>(ActionNode::IncrementRegister(reg_ctr, center)) | 2746 ? static_cast<RegExpNode*>(ActionNode::IncrementRegister(reg_ctr, center)) |
2705 : static_cast<RegExpNode*>(center); | 2747 : static_cast<RegExpNode*>(center); |
2706 RegExpNode* body_node = body->ToNode(compiler, loop_return); | 2748 RegExpNode* body_node = body->ToNode(compiler, loop_return); |
2707 GuardedAlternative body_alt(body_node); | 2749 GuardedAlternative body_alt(body_node); |
(...skipping 1184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3892 EmbeddedVector<byte, 1024> codes; | 3934 EmbeddedVector<byte, 1024> codes; |
3893 RegExpMacroAssemblerIrregexp macro_assembler(codes); | 3935 RegExpMacroAssemblerIrregexp macro_assembler(codes); |
3894 return compiler.Assemble(¯o_assembler, | 3936 return compiler.Assemble(¯o_assembler, |
3895 node, | 3937 node, |
3896 data->capture_count, | 3938 data->capture_count, |
3897 pattern); | 3939 pattern); |
3898 } | 3940 } |
3899 | 3941 |
3900 | 3942 |
3901 }} // namespace v8::internal | 3943 }} // namespace v8::internal |
OLD | NEW |