OLD | NEW |
1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 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 2704 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2715 if (depth < 0) return this; | 2715 if (depth < 0) return this; |
2716 if (info()->visited) return this; | 2716 if (info()->visited) return this; |
2717 VisitMarker marker(info()); | 2717 VisitMarker marker(info()); |
2718 int choice_count = alternatives_->length(); | 2718 int choice_count = alternatives_->length(); |
2719 int surviving = 0; | 2719 int surviving = 0; |
2720 RegExpNode* survivor = NULL; | 2720 RegExpNode* survivor = NULL; |
2721 for (int i = 0; i < choice_count; i++) { | 2721 for (int i = 0; i < choice_count; i++) { |
2722 GuardedAlternative alternative = alternatives_->at(i); | 2722 GuardedAlternative alternative = alternatives_->at(i); |
2723 RegExpNode* replacement = alternative.node()->FilterASCII(depth - 1); | 2723 RegExpNode* replacement = alternative.node()->FilterASCII(depth - 1); |
2724 ASSERT(replacement != this); // No missing EMPTY_MATCH_CHECK. | 2724 ASSERT(replacement != this); // No missing EMPTY_MATCH_CHECK. |
2725 alternatives_->at(i).set_node(replacement); | |
2726 if (replacement != NULL) { | 2725 if (replacement != NULL) { |
| 2726 alternatives_->at(i).set_node(replacement); |
2727 surviving++; | 2727 surviving++; |
2728 survivor = replacement; | 2728 survivor = replacement; |
2729 } | 2729 } |
2730 } | 2730 } |
2731 if (surviving < 2) return set_replacement(survivor); | 2731 if (surviving < 2) return set_replacement(survivor); |
2732 | 2732 |
2733 set_replacement(this); | 2733 set_replacement(this); |
2734 if (surviving == choice_count) { | 2734 if (surviving == choice_count) { |
2735 return this; | 2735 return this; |
2736 } | 2736 } |
2737 // Only some of the nodes survived the filtering. We need to rebuild the | 2737 // Only some of the nodes survived the filtering. We need to rebuild the |
2738 // alternatives list. | 2738 // alternatives list. |
2739 ZoneList<GuardedAlternative>* new_alternatives = | 2739 ZoneList<GuardedAlternative>* new_alternatives = |
2740 new ZoneList<GuardedAlternative>(surviving); | 2740 new ZoneList<GuardedAlternative>(surviving); |
2741 for (int i = 0; i < choice_count; i++) { | 2741 for (int i = 0; i < choice_count; i++) { |
2742 GuardedAlternative alternative = alternatives_->at(i); | 2742 RegExpNode* replacement = |
2743 if (alternative.node() != NULL) { | 2743 alternatives_->at(i).node()->FilterASCII(depth - 1); |
2744 new_alternatives->Add(alternative); | 2744 if (replacement != NULL) { |
| 2745 alternatives_->at(i).set_node(replacement); |
| 2746 new_alternatives->Add(alternatives_->at(i)); |
2745 } | 2747 } |
2746 } | 2748 } |
2747 alternatives_ = new_alternatives; | 2749 alternatives_ = new_alternatives; |
2748 return this; | 2750 return this; |
2749 } | 2751 } |
2750 | 2752 |
2751 | 2753 |
2752 RegExpNode* NegativeLookaheadChoiceNode::FilterASCII(int depth) { | 2754 RegExpNode* NegativeLookaheadChoiceNode::FilterASCII(int depth) { |
2753 if (info()->replacement_calculated) return replacement(); | 2755 if (info()->replacement_calculated) return replacement(); |
2754 if (depth < 0) return this; | 2756 if (depth < 0) return this; |
(...skipping 3070 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5825 // at the start of input. | 5827 // at the start of input. |
5826 ChoiceNode* first_step_node = new ChoiceNode(2); | 5828 ChoiceNode* first_step_node = new ChoiceNode(2); |
5827 first_step_node->AddAlternative(GuardedAlternative(captured_body)); | 5829 first_step_node->AddAlternative(GuardedAlternative(captured_body)); |
5828 first_step_node->AddAlternative(GuardedAlternative( | 5830 first_step_node->AddAlternative(GuardedAlternative( |
5829 new TextNode(new RegExpCharacterClass('*'), loop_node))); | 5831 new TextNode(new RegExpCharacterClass('*'), loop_node))); |
5830 node = first_step_node; | 5832 node = first_step_node; |
5831 } else { | 5833 } else { |
5832 node = loop_node; | 5834 node = loop_node; |
5833 } | 5835 } |
5834 } | 5836 } |
5835 if (is_ascii) node = node->FilterASCII(RegExpCompiler::kMaxRecursion); | 5837 if (is_ascii) { |
| 5838 node = node->FilterASCII(RegExpCompiler::kMaxRecursion); |
| 5839 // Do it again to propagate the new nodes to places where they were not |
| 5840 // put because they had not been calculated yet. |
| 5841 if (node != NULL) node = node->FilterASCII(RegExpCompiler::kMaxRecursion); |
| 5842 } |
5836 | 5843 |
5837 if (node == NULL) node = new EndNode(EndNode::BACKTRACK); | 5844 if (node == NULL) node = new EndNode(EndNode::BACKTRACK); |
5838 data->node = node; | 5845 data->node = node; |
5839 Analysis analysis(ignore_case, is_ascii); | 5846 Analysis analysis(ignore_case, is_ascii); |
5840 analysis.EnsureAnalyzed(node); | 5847 analysis.EnsureAnalyzed(node); |
5841 if (analysis.has_failed()) { | 5848 if (analysis.has_failed()) { |
5842 const char* error_message = analysis.error_message(); | 5849 const char* error_message = analysis.error_message(); |
5843 return CompilationResult(error_message); | 5850 return CompilationResult(error_message); |
5844 } | 5851 } |
5845 | 5852 |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5877 } | 5884 } |
5878 | 5885 |
5879 return compiler.Assemble(¯o_assembler, | 5886 return compiler.Assemble(¯o_assembler, |
5880 node, | 5887 node, |
5881 data->capture_count, | 5888 data->capture_count, |
5882 pattern); | 5889 pattern); |
5883 } | 5890 } |
5884 | 5891 |
5885 | 5892 |
5886 }} // namespace v8::internal | 5893 }} // namespace v8::internal |
OLD | NEW |