OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 1067 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1078 public: | 1078 public: |
1079 explicit RecursionCheck(RegExpCompiler* compiler) : compiler_(compiler) { | 1079 explicit RecursionCheck(RegExpCompiler* compiler) : compiler_(compiler) { |
1080 compiler->IncrementRecursionDepth(); | 1080 compiler->IncrementRecursionDepth(); |
1081 } | 1081 } |
1082 ~RecursionCheck() { compiler_->DecrementRecursionDepth(); } | 1082 ~RecursionCheck() { compiler_->DecrementRecursionDepth(); } |
1083 private: | 1083 private: |
1084 RegExpCompiler* compiler_; | 1084 RegExpCompiler* compiler_; |
1085 }; | 1085 }; |
1086 | 1086 |
1087 | 1087 |
1088 static RegExpEngine::CompilationResult IrregexpRegExpTooBig() { | 1088 static RegExpEngine::CompilationResult IrregexpRegExpTooBig(Isolate* isolate) { |
1089 return RegExpEngine::CompilationResult("RegExp too big"); | 1089 return RegExpEngine::CompilationResult(isolate, "RegExp too big"); |
1090 } | 1090 } |
1091 | 1091 |
1092 | 1092 |
1093 // Attempts to compile the regexp using an Irregexp code generator. Returns | 1093 // Attempts to compile the regexp using an Irregexp code generator. Returns |
1094 // a fixed array or a null handle depending on whether it succeeded. | 1094 // a fixed array or a null handle depending on whether it succeeded. |
1095 RegExpCompiler::RegExpCompiler(int capture_count, bool ignore_case, bool ascii, | 1095 RegExpCompiler::RegExpCompiler(int capture_count, bool ignore_case, bool ascii, |
1096 Zone* zone) | 1096 Zone* zone) |
1097 : next_register_(2 * (capture_count + 1)), | 1097 : next_register_(2 * (capture_count + 1)), |
1098 work_list_(NULL), | 1098 work_list_(NULL), |
1099 recursion_depth_(0), | 1099 recursion_depth_(0), |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1136 work_list_ = &work_list; | 1136 work_list_ = &work_list; |
1137 Label fail; | 1137 Label fail; |
1138 macro_assembler_->PushBacktrack(&fail); | 1138 macro_assembler_->PushBacktrack(&fail); |
1139 Trace new_trace; | 1139 Trace new_trace; |
1140 start->Emit(this, &new_trace); | 1140 start->Emit(this, &new_trace); |
1141 macro_assembler_->Bind(&fail); | 1141 macro_assembler_->Bind(&fail); |
1142 macro_assembler_->Fail(); | 1142 macro_assembler_->Fail(); |
1143 while (!work_list.is_empty()) { | 1143 while (!work_list.is_empty()) { |
1144 work_list.RemoveLast()->Emit(this, &new_trace); | 1144 work_list.RemoveLast()->Emit(this, &new_trace); |
1145 } | 1145 } |
1146 if (reg_exp_too_big_) return IrregexpRegExpTooBig(); | 1146 if (reg_exp_too_big_) return IrregexpRegExpTooBig(zone_->isolate()); |
1147 | 1147 |
1148 Handle<HeapObject> code = macro_assembler_->GetCode(pattern); | 1148 Handle<HeapObject> code = macro_assembler_->GetCode(pattern); |
1149 heap->IncreaseTotalRegexpCodeGenerated(code->Size()); | 1149 heap->IncreaseTotalRegexpCodeGenerated(code->Size()); |
1150 work_list_ = NULL; | 1150 work_list_ = NULL; |
1151 #ifdef DEBUG | 1151 #ifdef DEBUG |
1152 if (FLAG_print_code) { | 1152 if (FLAG_print_code) { |
1153 Handle<Code>::cast(code)->Disassemble(*pattern->ToCString()); | 1153 Handle<Code>::cast(code)->Disassemble(*pattern->ToCString()); |
1154 } | 1154 } |
1155 if (FLAG_trace_regexp_assembler) { | 1155 if (FLAG_trace_regexp_assembler) { |
1156 delete macro_assembler_; | 1156 delete macro_assembler_; |
(...skipping 4835 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5992 RegExpEngine::CompilationResult RegExpEngine::Compile( | 5992 RegExpEngine::CompilationResult RegExpEngine::Compile( |
5993 RegExpCompileData* data, | 5993 RegExpCompileData* data, |
5994 bool ignore_case, | 5994 bool ignore_case, |
5995 bool is_global, | 5995 bool is_global, |
5996 bool is_multiline, | 5996 bool is_multiline, |
5997 Handle<String> pattern, | 5997 Handle<String> pattern, |
5998 Handle<String> sample_subject, | 5998 Handle<String> sample_subject, |
5999 bool is_ascii, | 5999 bool is_ascii, |
6000 Zone* zone) { | 6000 Zone* zone) { |
6001 if ((data->capture_count + 1) * 2 - 1 > RegExpMacroAssembler::kMaxRegister) { | 6001 if ((data->capture_count + 1) * 2 - 1 > RegExpMacroAssembler::kMaxRegister) { |
6002 return IrregexpRegExpTooBig(); | 6002 return IrregexpRegExpTooBig(zone->isolate()); |
6003 } | 6003 } |
6004 RegExpCompiler compiler(data->capture_count, ignore_case, is_ascii, zone); | 6004 RegExpCompiler compiler(data->capture_count, ignore_case, is_ascii, zone); |
6005 | 6005 |
6006 // Sample some characters from the middle of the string. | 6006 // Sample some characters from the middle of the string. |
6007 static const int kSampleSize = 128; | 6007 static const int kSampleSize = 128; |
6008 | 6008 |
6009 FlattenString(sample_subject); | 6009 FlattenString(sample_subject); |
6010 int chars_sampled = 0; | 6010 int chars_sampled = 0; |
6011 int half_way = (sample_subject->length() - kSampleSize) / 2; | 6011 int half_way = (sample_subject->length() - kSampleSize) / 2; |
6012 for (int i = Max(0, half_way); | 6012 for (int i = Max(0, half_way); |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6056 node = node->FilterASCII(RegExpCompiler::kMaxRecursion, ignore_case); | 6056 node = node->FilterASCII(RegExpCompiler::kMaxRecursion, ignore_case); |
6057 } | 6057 } |
6058 } | 6058 } |
6059 | 6059 |
6060 if (node == NULL) node = new(zone) EndNode(EndNode::BACKTRACK, zone); | 6060 if (node == NULL) node = new(zone) EndNode(EndNode::BACKTRACK, zone); |
6061 data->node = node; | 6061 data->node = node; |
6062 Analysis analysis(ignore_case, is_ascii); | 6062 Analysis analysis(ignore_case, is_ascii); |
6063 analysis.EnsureAnalyzed(node); | 6063 analysis.EnsureAnalyzed(node); |
6064 if (analysis.has_failed()) { | 6064 if (analysis.has_failed()) { |
6065 const char* error_message = analysis.error_message(); | 6065 const char* error_message = analysis.error_message(); |
6066 return CompilationResult(error_message); | 6066 return CompilationResult(zone->isolate(), error_message); |
6067 } | 6067 } |
6068 | 6068 |
6069 // Create the correct assembler for the architecture. | 6069 // Create the correct assembler for the architecture. |
6070 #ifndef V8_INTERPRETED_REGEXP | 6070 #ifndef V8_INTERPRETED_REGEXP |
6071 // Native regexp implementation. | 6071 // Native regexp implementation. |
6072 | 6072 |
6073 NativeRegExpMacroAssembler::Mode mode = | 6073 NativeRegExpMacroAssembler::Mode mode = |
6074 is_ascii ? NativeRegExpMacroAssembler::ASCII | 6074 is_ascii ? NativeRegExpMacroAssembler::ASCII |
6075 : NativeRegExpMacroAssembler::UC16; | 6075 : NativeRegExpMacroAssembler::UC16; |
6076 | 6076 |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6111 } | 6111 } |
6112 | 6112 |
6113 return compiler.Assemble(¯o_assembler, | 6113 return compiler.Assemble(¯o_assembler, |
6114 node, | 6114 node, |
6115 data->capture_count, | 6115 data->capture_count, |
6116 pattern); | 6116 pattern); |
6117 } | 6117 } |
6118 | 6118 |
6119 | 6119 |
6120 }} // namespace v8::internal | 6120 }} // namespace v8::internal |
OLD | NEW |