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/compiler.h" |
7 #include "vm/exceptions.h" | 8 #include "vm/exceptions.h" |
8 #include "vm/native_entry.h" | 9 #include "vm/native_entry.h" |
9 #include "vm/object.h" | 10 #include "vm/object.h" |
| 11 #include "vm/regexp_parser.h" |
10 | 12 |
11 #include "lib/regexp_jsc.h" | 13 #include "lib/regexp_jsc.h" |
12 | 14 |
13 namespace dart { | 15 namespace dart { |
14 | 16 |
| 17 DECLARE_FLAG(bool, trace_irregexp); |
| 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(); |
| 29 |
| 30 #if defined(USE_JSCRE) |
24 return Jscre::Compile(pattern, multi_line, ignore_case); | 31 return Jscre::Compile(pattern, multi_line, ignore_case); |
| 32 #else |
| 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 JSRegExp& regexp = JSRegExp::Handle( |
| 43 isolate, RegExpEngine::New(isolate, pattern, multi_line, ignore_case)); |
| 44 |
| 45 return regexp.raw(); |
| 46 #endif |
25 } | 47 } |
26 | 48 |
27 | 49 |
28 DEFINE_NATIVE_ENTRY(JSSyntaxRegExp_getPattern, 1) { | 50 DEFINE_NATIVE_ENTRY(JSSyntaxRegExp_getPattern, 1) { |
29 const JSRegExp& regexp = JSRegExp::CheckedHandle(arguments->NativeArgAt(0)); | 51 const JSRegExp& regexp = JSRegExp::CheckedHandle(arguments->NativeArgAt(0)); |
30 ASSERT(!regexp.IsNull()); | 52 ASSERT(!regexp.IsNull()); |
31 return regexp.pattern(); | 53 return regexp.pattern(); |
32 } | 54 } |
33 | 55 |
34 | 56 |
(...skipping 26 matching lines...) Expand all Loading... |
61 Exceptions::ThrowByType(Exceptions::kFormat, args); | 83 Exceptions::ThrowByType(Exceptions::kFormat, args); |
62 return Object::null(); | 84 return Object::null(); |
63 } | 85 } |
64 | 86 |
65 | 87 |
66 DEFINE_NATIVE_ENTRY(JSSyntaxRegExp_ExecuteMatch, 3) { | 88 DEFINE_NATIVE_ENTRY(JSSyntaxRegExp_ExecuteMatch, 3) { |
67 const JSRegExp& regexp = JSRegExp::CheckedHandle(arguments->NativeArgAt(0)); | 89 const JSRegExp& regexp = JSRegExp::CheckedHandle(arguments->NativeArgAt(0)); |
68 ASSERT(!regexp.IsNull()); | 90 ASSERT(!regexp.IsNull()); |
69 GET_NON_NULL_NATIVE_ARGUMENT(String, str, arguments->NativeArgAt(1)); | 91 GET_NON_NULL_NATIVE_ARGUMENT(String, str, arguments->NativeArgAt(1)); |
70 GET_NON_NULL_NATIVE_ARGUMENT(Smi, start_index, arguments->NativeArgAt(2)); | 92 GET_NON_NULL_NATIVE_ARGUMENT(Smi, start_index, arguments->NativeArgAt(2)); |
| 93 |
| 94 #if defined(USE_JSCRE) |
71 return Jscre::Execute(regexp, str, start_index.Value()); | 95 return Jscre::Execute(regexp, str, start_index.Value()); |
| 96 #else |
| 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); |
| 106 #endif |
72 } | 107 } |
73 | 108 |
74 } // namespace dart | 109 } // namespace dart |
OLD | NEW |