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) | |
| 25 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 | |
| 26 } | 47 } |
| 27 | 48 |
| 28 | 49 |
| 29 DEFINE_NATIVE_ENTRY(JSSyntaxRegExp_getPattern, 1) { | 50 DEFINE_NATIVE_ENTRY(JSSyntaxRegExp_getPattern, 1) { |
| 30 const JSRegExp& regexp = JSRegExp::CheckedHandle(arguments->NativeArgAt(0)); | 51 const JSRegExp& regexp = JSRegExp::CheckedHandle(arguments->NativeArgAt(0)); |
| 31 ASSERT(!regexp.IsNull()); | 52 ASSERT(!regexp.IsNull()); |
| 32 return regexp.pattern(); | 53 return regexp.pattern(); |
| 33 } | 54 } |
| 34 | 55 |
| 35 | 56 |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 63 return Object::null(); | 84 return Object::null(); |
| 64 } | 85 } |
| 65 | 86 |
| 66 | 87 |
| 67 DEFINE_NATIVE_ENTRY(JSSyntaxRegExp_ExecuteMatch, 3) { | 88 DEFINE_NATIVE_ENTRY(JSSyntaxRegExp_ExecuteMatch, 3) { |
| 68 const JSRegExp& regexp = JSRegExp::CheckedHandle(arguments->NativeArgAt(0)); | 89 const JSRegExp& regexp = JSRegExp::CheckedHandle(arguments->NativeArgAt(0)); |
| 69 ASSERT(!regexp.IsNull()); | 90 ASSERT(!regexp.IsNull()); |
| 70 GET_NON_NULL_NATIVE_ARGUMENT(String, str, arguments->NativeArgAt(1)); | 91 GET_NON_NULL_NATIVE_ARGUMENT(String, str, arguments->NativeArgAt(1)); |
| 71 GET_NON_NULL_NATIVE_ARGUMENT(Smi, start_index, arguments->NativeArgAt(2)); | 92 GET_NON_NULL_NATIVE_ARGUMENT(Smi, start_index, arguments->NativeArgAt(2)); |
| 72 | 93 |
| 73 // The irregexp parser runs alongside the jscre parser while the port is | 94 #if defined(USE_JSCRE) |
| 74 // still in progress. When done, it will replace jscre completely. | 95 return Jscre::Execute(regexp, str, start_index.Value()); |
| 75 const String& pattern = String::Handle(regexp.pattern()); | 96 #else |
| 76 RegExpCompileData compileData; | 97 // This function is intrinsified. See Intrinsifier::JSRegExp_ExecuteMatch. |
| 77 if (RegExpParser::ParseRegExp(pattern, regexp.is_multi_line(), | 98 const intptr_t cid = str.GetClassId(); |
| 78 &compileData)) { | 99 |
| 79 RegExpEngine::Compile(&compileData, | 100 // Retrieve the cached function. |
| 80 regexp.is_ignore_case(), | 101 Function& fn = Function::Handle(regexp.function(cid)); |
|
Florian Schneider
2014/10/01 17:04:15
const Function&
jgruber1
2014/10/03 18:59:53
Done.
| |
| 81 regexp.is_global(), // A Dart regexp is always global | 102 ASSERT(!fn.IsNull()); |
| 82 regexp.is_multi_line(), | 103 |
| 83 pattern, | 104 if (fn.CurrentCode() == StubCode::LazyCompile_entry()->code()) { |
|
Florian Schneider
2014/10/01 17:04:14
In the instrinc assembly code you check
(sample_s
jgruber1
2014/10/03 18:59:53
Done.
| |
| 84 str, | 105 // Set the sample subject now that we have it. |
| 85 str.IsOneByteString()); | 106 regexp.set_sample_subject(cid, str); |
| 86 #ifdef DEBUG | 107 #ifdef DEBUG |
|
Vyacheslav Egorov (Google)
2014/10/01 20:13:21
Empty #ifdef ?
jgruber1
2014/10/03 18:59:53
Done.
| |
| 87 RegExpEngine::DotPrint(pattern.ToCString(), | |
| 88 compileData.node, | |
| 89 regexp.is_ignore_case()); | |
| 90 #endif | 108 #endif |
| 91 } | 109 } |
| 92 | 110 |
| 93 return Jscre::Execute(regexp, str, start_index.Value()); | 111 // And finally call the generated code. |
| 112 return IRRegExpMacroAssembler::Execute(fn, str, start_index, isolate); | |
| 113 #endif | |
| 94 } | 114 } |
| 95 | 115 |
| 96 } // namespace dart | 116 } // namespace dart |
| OLD | NEW |