OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 #include "platform/assert.h" | 5 #include "platform/assert.h" |
6 #include "vm/bootstrap_natives.h" | 6 #include "vm/bootstrap_natives.h" |
7 #include "vm/exceptions.h" | 7 #include "vm/exceptions.h" |
8 #include "vm/native_entry.h" | 8 #include "vm/native_entry.h" |
9 #include "vm/object.h" | 9 #include "vm/object.h" |
| 10 #include "vm/regexp_parser.h" |
10 | 11 |
11 #include "lib/regexp_jsc.h" | 12 #include "lib/regexp_jsc.h" |
12 | 13 |
13 namespace dart { | 14 namespace dart { |
14 | 15 |
| 16 DECLARE_FLAG(bool, trace_irregexp); |
| 17 DEFINE_FLAG(bool, use_jscre, false, "Use the JSCRE regular expression engine"); |
| 18 |
| 19 |
15 DEFINE_NATIVE_ENTRY(JSSyntaxRegExp_factory, 4) { | 20 DEFINE_NATIVE_ENTRY(JSSyntaxRegExp_factory, 4) { |
16 ASSERT(TypeArguments::CheckedHandle(arguments->NativeArgAt(0)).IsNull()); | 21 ASSERT(TypeArguments::CheckedHandle(arguments->NativeArgAt(0)).IsNull()); |
17 GET_NON_NULL_NATIVE_ARGUMENT(String, pattern, arguments->NativeArgAt(1)); | 22 GET_NON_NULL_NATIVE_ARGUMENT(String, pattern, arguments->NativeArgAt(1)); |
18 GET_NON_NULL_NATIVE_ARGUMENT( | 23 GET_NON_NULL_NATIVE_ARGUMENT( |
19 Instance, handle_multi_line, arguments->NativeArgAt(2)); | 24 Instance, handle_multi_line, arguments->NativeArgAt(2)); |
20 GET_NON_NULL_NATIVE_ARGUMENT( | 25 GET_NON_NULL_NATIVE_ARGUMENT( |
21 Instance, handle_case_sensitive, arguments->NativeArgAt(3)); | 26 Instance, handle_case_sensitive, arguments->NativeArgAt(3)); |
22 bool ignore_case = handle_case_sensitive.raw() != Bool::True().raw(); | 27 bool ignore_case = handle_case_sensitive.raw() != Bool::True().raw(); |
23 bool multi_line = handle_multi_line.raw() == Bool::True().raw(); | 28 bool multi_line = handle_multi_line.raw() == Bool::True().raw(); |
24 return Jscre::Compile(pattern, multi_line, ignore_case); | 29 |
| 30 if (FLAG_use_jscre) { |
| 31 return Jscre::Compile(pattern, multi_line, ignore_case); |
| 32 } |
| 33 // Parse the pattern once in order to throw any format exceptions within |
| 34 // the factory constructor. It is parsed again upon compilation. |
| 35 RegExpCompileData compileData; |
| 36 if (!RegExpParser::ParseRegExp(pattern, multi_line, &compileData)) { |
| 37 // Parsing failures throw an exception. |
| 38 UNREACHABLE(); |
| 39 } |
| 40 |
| 41 // Create a JSRegExp object containing only the initial parameters. |
| 42 return RegExpEngine::CreateJSRegExp(isolate, |
| 43 pattern, |
| 44 multi_line, |
| 45 ignore_case); |
25 } | 46 } |
26 | 47 |
27 | 48 |
28 DEFINE_NATIVE_ENTRY(JSSyntaxRegExp_getPattern, 1) { | 49 DEFINE_NATIVE_ENTRY(JSSyntaxRegExp_getPattern, 1) { |
29 const JSRegExp& regexp = JSRegExp::CheckedHandle(arguments->NativeArgAt(0)); | 50 const JSRegExp& regexp = JSRegExp::CheckedHandle(arguments->NativeArgAt(0)); |
30 ASSERT(!regexp.IsNull()); | 51 ASSERT(!regexp.IsNull()); |
31 return regexp.pattern(); | 52 return regexp.pattern(); |
32 } | 53 } |
33 | 54 |
34 | 55 |
(...skipping 26 matching lines...) Expand all Loading... |
61 Exceptions::ThrowByType(Exceptions::kFormat, args); | 82 Exceptions::ThrowByType(Exceptions::kFormat, args); |
62 return Object::null(); | 83 return Object::null(); |
63 } | 84 } |
64 | 85 |
65 | 86 |
66 DEFINE_NATIVE_ENTRY(JSSyntaxRegExp_ExecuteMatch, 3) { | 87 DEFINE_NATIVE_ENTRY(JSSyntaxRegExp_ExecuteMatch, 3) { |
67 const JSRegExp& regexp = JSRegExp::CheckedHandle(arguments->NativeArgAt(0)); | 88 const JSRegExp& regexp = JSRegExp::CheckedHandle(arguments->NativeArgAt(0)); |
68 ASSERT(!regexp.IsNull()); | 89 ASSERT(!regexp.IsNull()); |
69 GET_NON_NULL_NATIVE_ARGUMENT(String, str, arguments->NativeArgAt(1)); | 90 GET_NON_NULL_NATIVE_ARGUMENT(String, str, arguments->NativeArgAt(1)); |
70 GET_NON_NULL_NATIVE_ARGUMENT(Smi, start_index, arguments->NativeArgAt(2)); | 91 GET_NON_NULL_NATIVE_ARGUMENT(Smi, start_index, arguments->NativeArgAt(2)); |
71 return Jscre::Execute(regexp, str, start_index.Value()); | 92 |
| 93 if (FLAG_use_jscre) { |
| 94 return Jscre::Execute(regexp, str, start_index.Value()); |
| 95 } |
| 96 |
| 97 // This function is intrinsified. See Intrinsifier::JSRegExp_ExecuteMatch. |
| 98 const intptr_t cid = str.GetClassId(); |
| 99 |
| 100 // Retrieve the cached function. |
| 101 const Function& fn = Function::Handle(regexp.function(cid)); |
| 102 ASSERT(!fn.IsNull()); |
| 103 |
| 104 // And finally call the generated code. |
| 105 return IRRegExpMacroAssembler::Execute(fn, str, start_index, isolate); |
72 } | 106 } |
73 | 107 |
74 } // namespace dart | 108 } // namespace dart |
OLD | NEW |