| 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_assembler_bytecode.h" |
| 11 #include "vm/regexp_assembler_ir.h" |
| 10 #include "vm/regexp_parser.h" | 12 #include "vm/regexp_parser.h" |
| 11 #include "vm/regexp_assembler_ir.h" | |
| 12 #include "vm/regexp_assembler_bytecode.h" | |
| 13 #include "vm/thread.h" | 13 #include "vm/thread.h" |
| 14 | 14 |
| 15 namespace dart { | 15 namespace dart { |
| 16 | 16 |
| 17 DEFINE_NATIVE_ENTRY(RegExp_factory, 4) { | 17 DEFINE_NATIVE_ENTRY(RegExp_factory, 4) { |
| 18 ASSERT(TypeArguments::CheckedHandle(arguments->NativeArgAt(0)).IsNull()); | 18 ASSERT(TypeArguments::CheckedHandle(arguments->NativeArgAt(0)).IsNull()); |
| 19 GET_NON_NULL_NATIVE_ARGUMENT(String, pattern, arguments->NativeArgAt(1)); | 19 GET_NON_NULL_NATIVE_ARGUMENT(String, pattern, arguments->NativeArgAt(1)); |
| 20 GET_NON_NULL_NATIVE_ARGUMENT(Instance, handle_multi_line, | 20 GET_NON_NULL_NATIVE_ARGUMENT(Instance, handle_multi_line, |
| 21 arguments->NativeArgAt(2)); | 21 arguments->NativeArgAt(2)); |
| 22 GET_NON_NULL_NATIVE_ARGUMENT(Instance, handle_case_sensitive, | 22 GET_NON_NULL_NATIVE_ARGUMENT(Instance, handle_case_sensitive, |
| 23 arguments->NativeArgAt(3)); | 23 arguments->NativeArgAt(3)); |
| 24 bool ignore_case = handle_case_sensitive.raw() != Bool::True().raw(); | 24 bool ignore_case = handle_case_sensitive.raw() != Bool::True().raw(); |
| 25 bool multi_line = handle_multi_line.raw() == Bool::True().raw(); | 25 bool multi_line = handle_multi_line.raw() == Bool::True().raw(); |
| 26 | 26 |
| 27 // Parse the pattern once in order to throw any format exceptions within | 27 // Parse the pattern once in order to throw any format exceptions within |
| 28 // the factory constructor. It is parsed again upon compilation. | 28 // the factory constructor. It is parsed again upon compilation. |
| 29 RegExpCompileData compileData; | 29 RegExpCompileData compileData; |
| 30 if (!RegExpParser::ParseRegExp(pattern, multi_line, &compileData)) { | 30 if (!RegExpParser::ParseRegExp(pattern, multi_line, &compileData)) { |
| 31 // Parsing failures throw an exception. | 31 // Parsing failures throw an exception. |
| 32 UNREACHABLE(); | 32 UNREACHABLE(); |
| 33 } | 33 } |
| 34 | 34 |
| 35 // Create a RegExp object containing only the initial parameters. | 35 // Create a RegExp object containing only the initial parameters. |
| 36 return RegExpEngine::CreateRegExp(thread, pattern, multi_line, ignore_case); | 36 return RegExpEngine::CreateRegExp(thread, pattern, multi_line, ignore_case); |
| 37 } | 37 } |
| 38 | 38 |
| 39 | |
| 40 DEFINE_NATIVE_ENTRY(RegExp_getPattern, 1) { | 39 DEFINE_NATIVE_ENTRY(RegExp_getPattern, 1) { |
| 41 const RegExp& regexp = RegExp::CheckedHandle(arguments->NativeArgAt(0)); | 40 const RegExp& regexp = RegExp::CheckedHandle(arguments->NativeArgAt(0)); |
| 42 ASSERT(!regexp.IsNull()); | 41 ASSERT(!regexp.IsNull()); |
| 43 return regexp.pattern(); | 42 return regexp.pattern(); |
| 44 } | 43 } |
| 45 | 44 |
| 46 | |
| 47 DEFINE_NATIVE_ENTRY(RegExp_getIsMultiLine, 1) { | 45 DEFINE_NATIVE_ENTRY(RegExp_getIsMultiLine, 1) { |
| 48 const RegExp& regexp = RegExp::CheckedHandle(arguments->NativeArgAt(0)); | 46 const RegExp& regexp = RegExp::CheckedHandle(arguments->NativeArgAt(0)); |
| 49 ASSERT(!regexp.IsNull()); | 47 ASSERT(!regexp.IsNull()); |
| 50 return Bool::Get(regexp.is_multi_line()).raw(); | 48 return Bool::Get(regexp.is_multi_line()).raw(); |
| 51 } | 49 } |
| 52 | 50 |
| 53 | |
| 54 DEFINE_NATIVE_ENTRY(RegExp_getIsCaseSensitive, 1) { | 51 DEFINE_NATIVE_ENTRY(RegExp_getIsCaseSensitive, 1) { |
| 55 const RegExp& regexp = RegExp::CheckedHandle(arguments->NativeArgAt(0)); | 52 const RegExp& regexp = RegExp::CheckedHandle(arguments->NativeArgAt(0)); |
| 56 ASSERT(!regexp.IsNull()); | 53 ASSERT(!regexp.IsNull()); |
| 57 return Bool::Get(!regexp.is_ignore_case()).raw(); | 54 return Bool::Get(!regexp.is_ignore_case()).raw(); |
| 58 } | 55 } |
| 59 | 56 |
| 60 | |
| 61 DEFINE_NATIVE_ENTRY(RegExp_getGroupCount, 1) { | 57 DEFINE_NATIVE_ENTRY(RegExp_getGroupCount, 1) { |
| 62 const RegExp& regexp = RegExp::CheckedHandle(arguments->NativeArgAt(0)); | 58 const RegExp& regexp = RegExp::CheckedHandle(arguments->NativeArgAt(0)); |
| 63 ASSERT(!regexp.IsNull()); | 59 ASSERT(!regexp.IsNull()); |
| 64 if (regexp.is_initialized()) { | 60 if (regexp.is_initialized()) { |
| 65 return regexp.num_bracket_expressions(); | 61 return regexp.num_bracket_expressions(); |
| 66 } | 62 } |
| 67 const String& pattern = String::Handle(regexp.pattern()); | 63 const String& pattern = String::Handle(regexp.pattern()); |
| 68 const String& errmsg = String::Handle( | 64 const String& errmsg = String::Handle( |
| 69 String::New("Regular expression is not initialized yet. ")); | 65 String::New("Regular expression is not initialized yet. ")); |
| 70 const String& message = String::Handle(String::Concat(errmsg, pattern)); | 66 const String& message = String::Handle(String::Concat(errmsg, pattern)); |
| 71 const Array& args = Array::Handle(Array::New(1)); | 67 const Array& args = Array::Handle(Array::New(1)); |
| 72 args.SetAt(0, message); | 68 args.SetAt(0, message); |
| 73 Exceptions::ThrowByType(Exceptions::kFormat, args); | 69 Exceptions::ThrowByType(Exceptions::kFormat, args); |
| 74 return Object::null(); | 70 return Object::null(); |
| 75 } | 71 } |
| 76 | 72 |
| 77 | |
| 78 static RawObject* ExecuteMatch(Zone* zone, | 73 static RawObject* ExecuteMatch(Zone* zone, |
| 79 NativeArguments* arguments, | 74 NativeArguments* arguments, |
| 80 bool sticky) { | 75 bool sticky) { |
| 81 const RegExp& regexp = RegExp::CheckedHandle(arguments->NativeArgAt(0)); | 76 const RegExp& regexp = RegExp::CheckedHandle(arguments->NativeArgAt(0)); |
| 82 ASSERT(!regexp.IsNull()); | 77 ASSERT(!regexp.IsNull()); |
| 83 GET_NON_NULL_NATIVE_ARGUMENT(String, subject, arguments->NativeArgAt(1)); | 78 GET_NON_NULL_NATIVE_ARGUMENT(String, subject, arguments->NativeArgAt(1)); |
| 84 GET_NON_NULL_NATIVE_ARGUMENT(Smi, start_index, arguments->NativeArgAt(2)); | 79 GET_NON_NULL_NATIVE_ARGUMENT(Smi, start_index, arguments->NativeArgAt(2)); |
| 85 | 80 |
| 86 #if !defined(DART_PRECOMPILED_RUNTIME) | 81 #if !defined(DART_PRECOMPILED_RUNTIME) |
| 87 if (!FLAG_interpret_irregexp) { | 82 if (!FLAG_interpret_irregexp) { |
| 88 return IRRegExpMacroAssembler::Execute(regexp, subject, start_index, | 83 return IRRegExpMacroAssembler::Execute(regexp, subject, start_index, |
| 89 /*sticky=*/sticky, zone); | 84 /*sticky=*/sticky, zone); |
| 90 } | 85 } |
| 91 #endif | 86 #endif |
| 92 return BytecodeRegExpMacroAssembler::Interpret(regexp, subject, start_index, | 87 return BytecodeRegExpMacroAssembler::Interpret(regexp, subject, start_index, |
| 93 /*sticky=*/sticky, zone); | 88 /*sticky=*/sticky, zone); |
| 94 } | 89 } |
| 95 | 90 |
| 96 | |
| 97 DEFINE_NATIVE_ENTRY(RegExp_ExecuteMatch, 3) { | 91 DEFINE_NATIVE_ENTRY(RegExp_ExecuteMatch, 3) { |
| 98 // This function is intrinsified. See Intrinsifier::RegExp_ExecuteMatch. | 92 // This function is intrinsified. See Intrinsifier::RegExp_ExecuteMatch. |
| 99 return ExecuteMatch(zone, arguments, /*sticky=*/false); | 93 return ExecuteMatch(zone, arguments, /*sticky=*/false); |
| 100 } | 94 } |
| 101 | 95 |
| 102 | |
| 103 DEFINE_NATIVE_ENTRY(RegExp_ExecuteMatchSticky, 3) { | 96 DEFINE_NATIVE_ENTRY(RegExp_ExecuteMatchSticky, 3) { |
| 104 // This function is intrinsified. See Intrinsifier::RegExp_ExecuteMatchSticky. | 97 // This function is intrinsified. See Intrinsifier::RegExp_ExecuteMatchSticky. |
| 105 return ExecuteMatch(zone, arguments, /*sticky=*/true); | 98 return ExecuteMatch(zone, arguments, /*sticky=*/true); |
| 106 } | 99 } |
| 107 | 100 |
| 108 | |
| 109 } // namespace dart | 101 } // namespace dart |
| OLD | NEW |