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 | |
18 | |
15 DEFINE_NATIVE_ENTRY(JSSyntaxRegExp_factory, 4) { | 19 DEFINE_NATIVE_ENTRY(JSSyntaxRegExp_factory, 4) { |
16 ASSERT(TypeArguments::CheckedHandle(arguments->NativeArgAt(0)).IsNull()); | 20 ASSERT(TypeArguments::CheckedHandle(arguments->NativeArgAt(0)).IsNull()); |
17 GET_NON_NULL_NATIVE_ARGUMENT(String, pattern, arguments->NativeArgAt(1)); | 21 GET_NON_NULL_NATIVE_ARGUMENT(String, pattern, arguments->NativeArgAt(1)); |
18 GET_NON_NULL_NATIVE_ARGUMENT( | 22 GET_NON_NULL_NATIVE_ARGUMENT( |
19 Instance, handle_multi_line, arguments->NativeArgAt(2)); | 23 Instance, handle_multi_line, arguments->NativeArgAt(2)); |
20 GET_NON_NULL_NATIVE_ARGUMENT( | 24 GET_NON_NULL_NATIVE_ARGUMENT( |
21 Instance, handle_case_sensitive, arguments->NativeArgAt(3)); | 25 Instance, handle_case_sensitive, arguments->NativeArgAt(3)); |
22 bool ignore_case = handle_case_sensitive.raw() != Bool::True().raw(); | 26 bool ignore_case = handle_case_sensitive.raw() != Bool::True().raw(); |
23 bool multi_line = handle_multi_line.raw() == Bool::True().raw(); | 27 bool multi_line = handle_multi_line.raw() == Bool::True().raw(); |
28 | |
29 #if defined(USE_JSCRE) | |
Ivan Posva
2014/10/31 07:32:37
Let's figure out whether this is even needed.
zerny-google
2014/10/31 11:54:26
Would it be of more value to replace this with a V
| |
24 return Jscre::Compile(pattern, multi_line, ignore_case); | 30 return Jscre::Compile(pattern, multi_line, ignore_case); |
31 #else | |
32 // Parse the pattern once in order to throw any format exceptions within | |
33 // the factory constructor. It is parsed again upon compilation. | |
34 RegExpCompileData compileData; | |
35 if (!RegExpParser::ParseRegExp(pattern, multi_line, &compileData)) { | |
36 // Parsing failures throw an exception. | |
37 UNREACHABLE(); | |
38 } | |
39 | |
40 // Create a JSRegExp object containing only the initial parameters. | |
41 return RegExpEngine::CreateJSRegExp(isolate, | |
42 pattern, | |
43 multi_line, | |
44 ignore_case); | |
45 #endif | |
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)); |
92 | |
93 #if defined(USE_JSCRE) | |
71 return Jscre::Execute(regexp, str, start_index.Value()); | 94 return Jscre::Execute(regexp, str, start_index.Value()); |
95 #else | |
96 // This function is intrinsified. See Intrinsifier::JSRegExp_ExecuteMatch. | |
97 const intptr_t cid = str.GetClassId(); | |
98 | |
99 // Retrieve the cached function. | |
100 const Function& fn = Function::Handle(regexp.function(cid)); | |
101 ASSERT(!fn.IsNull()); | |
102 | |
103 // And finally call the generated code. | |
104 return IRRegExpMacroAssembler::Execute(fn, str, start_index, isolate); | |
105 #endif | |
72 } | 106 } |
73 | 107 |
74 } // namespace dart | 108 } // namespace dart |
OLD | NEW |