Chromium Code Reviews| 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" |
| 10 #include "vm/regexp_parser.h" | 11 #include "vm/regexp_parser.h" |
| 11 | 12 |
| 12 #include "lib/regexp_jsc.h" | 13 #include "lib/regexp_jsc.h" |
| 13 | 14 |
| 14 namespace dart { | 15 namespace dart { |
| 15 | 16 |
| 17 DECLARE_FLAG(bool, trace_irregexp); | |
| 18 | |
| 19 | |
| 16 DEFINE_NATIVE_ENTRY(JSSyntaxRegExp_factory, 4) { | 20 DEFINE_NATIVE_ENTRY(JSSyntaxRegExp_factory, 4) { |
| 17 ASSERT(TypeArguments::CheckedHandle(arguments->NativeArgAt(0)).IsNull()); | 21 ASSERT(TypeArguments::CheckedHandle(arguments->NativeArgAt(0)).IsNull()); |
| 18 GET_NON_NULL_NATIVE_ARGUMENT(String, pattern, arguments->NativeArgAt(1)); | 22 GET_NON_NULL_NATIVE_ARGUMENT(String, pattern, arguments->NativeArgAt(1)); |
| 19 GET_NON_NULL_NATIVE_ARGUMENT( | 23 GET_NON_NULL_NATIVE_ARGUMENT( |
| 20 Instance, handle_multi_line, arguments->NativeArgAt(2)); | 24 Instance, handle_multi_line, arguments->NativeArgAt(2)); |
| 21 GET_NON_NULL_NATIVE_ARGUMENT( | 25 GET_NON_NULL_NATIVE_ARGUMENT( |
| 22 Instance, handle_case_sensitive, arguments->NativeArgAt(3)); | 26 Instance, handle_case_sensitive, arguments->NativeArgAt(3)); |
| 23 bool ignore_case = handle_case_sensitive.raw() != Bool::True().raw(); | 27 bool ignore_case = handle_case_sensitive.raw() != Bool::True().raw(); |
| 24 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) || \ | |
| 31 defined(TARGET_ARCH_MIPS) | |
| 25 return Jscre::Compile(pattern, multi_line, ignore_case); | 32 return Jscre::Compile(pattern, multi_line, ignore_case); |
| 33 #else | |
| 34 // Parse the pattern once in order to throw any format exceptions within | |
| 35 // the factory constructor. It is parsed again upon compilation. | |
| 36 RegExpCompileData compileData; | |
| 37 if (!RegExpParser::ParseRegExp(pattern, multi_line, &compileData)) { | |
| 38 // Parsing failures throw an exception. | |
| 39 UNREACHABLE(); | |
| 40 } | |
| 41 | |
| 42 // Create a JSRegExp object containing only the initial parameters. | |
| 43 JSRegExp& regexp = JSRegExp::Handle( | |
| 44 isolate, RegExpEngine::New(isolate, pattern, multi_line, ignore_case)); | |
| 45 | |
| 46 return regexp.raw(); | |
| 47 #endif | |
| 26 } | 48 } |
| 27 | 49 |
| 28 | 50 |
| 29 DEFINE_NATIVE_ENTRY(JSSyntaxRegExp_getPattern, 1) { | 51 DEFINE_NATIVE_ENTRY(JSSyntaxRegExp_getPattern, 1) { |
| 30 const JSRegExp& regexp = JSRegExp::CheckedHandle(arguments->NativeArgAt(0)); | 52 const JSRegExp& regexp = JSRegExp::CheckedHandle(arguments->NativeArgAt(0)); |
| 31 ASSERT(!regexp.IsNull()); | 53 ASSERT(!regexp.IsNull()); |
| 32 return regexp.pattern(); | 54 return regexp.pattern(); |
| 33 } | 55 } |
| 34 | 56 |
| 35 | 57 |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 63 return Object::null(); | 85 return Object::null(); |
| 64 } | 86 } |
| 65 | 87 |
| 66 | 88 |
| 67 DEFINE_NATIVE_ENTRY(JSSyntaxRegExp_ExecuteMatch, 3) { | 89 DEFINE_NATIVE_ENTRY(JSSyntaxRegExp_ExecuteMatch, 3) { |
| 68 const JSRegExp& regexp = JSRegExp::CheckedHandle(arguments->NativeArgAt(0)); | 90 const JSRegExp& regexp = JSRegExp::CheckedHandle(arguments->NativeArgAt(0)); |
| 69 ASSERT(!regexp.IsNull()); | 91 ASSERT(!regexp.IsNull()); |
| 70 GET_NON_NULL_NATIVE_ARGUMENT(String, str, arguments->NativeArgAt(1)); | 92 GET_NON_NULL_NATIVE_ARGUMENT(String, str, arguments->NativeArgAt(1)); |
| 71 GET_NON_NULL_NATIVE_ARGUMENT(Smi, start_index, arguments->NativeArgAt(2)); | 93 GET_NON_NULL_NATIVE_ARGUMENT(Smi, start_index, arguments->NativeArgAt(2)); |
| 72 | 94 |
| 73 // The irregexp parser runs alongside the jscre parser while the port is | 95 #if defined(USE_JSCRE) || \ |
| 74 // still in progress. When done, it will replace jscre completely. | 96 defined(TARGET_ARCH_MIPS) |
| 75 const String& pattern = String::Handle(regexp.pattern()); | |
| 76 RegExpCompileData compileData; | |
| 77 if (RegExpParser::ParseRegExp(pattern, regexp.is_multi_line(), | |
| 78 &compileData)) { | |
| 79 RegExpEngine::Compile(&compileData, | |
| 80 regexp.is_ignore_case(), | |
| 81 regexp.is_global(), // A Dart regexp is always global | |
| 82 regexp.is_multi_line(), | |
| 83 pattern, | |
| 84 str, | |
| 85 str.IsOneByteString()); | |
| 86 RegExpEngine::DotPrint(pattern.ToCString(), | |
| 87 compileData.node, | |
| 88 regexp.is_ignore_case()); | |
| 89 } | |
| 90 | |
| 91 return Jscre::Execute(regexp, str, start_index.Value()); | 97 return Jscre::Execute(regexp, str, start_index.Value()); |
| 98 #else | |
| 99 // This function is intrinsified. See Intrinsifier::JSRegExp_ExecuteMatch. | |
|
srdjan
2014/09/22 22:34:07
We occasionally run with --no-intrinsify. Will it
jgruber1
2014/09/23 10:58:46
Good point, I wasn't aware of that flag. Added bac
| |
| 100 UNREACHABLE(); | |
| 101 USE(&str); | |
| 102 USE(&start_index); | |
| 103 return Array::null(); | |
| 104 #endif | |
| 92 } | 105 } |
| 93 | 106 |
| 94 } // namespace dart | 107 } // namespace dart |
| OLD | NEW |