Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(215)

Side by Side Diff: runtime/lib/regexp.cc

Issue 1815333002: Simpler regex names: (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: sync Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | runtime/lib/regexp_patch.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #include "vm/regexp_parser.h"
11 #include "vm/regexp_assembler_ir.h" 11 #include "vm/regexp_assembler_ir.h"
12 #include "vm/regexp_assembler_bytecode.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 DECLARE_FLAG(bool, trace_irregexp); 17 DECLARE_FLAG(bool, trace_irregexp);
18 18
19 19
20 DEFINE_NATIVE_ENTRY(JSSyntaxRegExp_factory, 4) { 20 DEFINE_NATIVE_ENTRY(RegExp_factory, 4) {
21 ASSERT(TypeArguments::CheckedHandle(arguments->NativeArgAt(0)).IsNull()); 21 ASSERT(TypeArguments::CheckedHandle(arguments->NativeArgAt(0)).IsNull());
22 GET_NON_NULL_NATIVE_ARGUMENT(String, pattern, arguments->NativeArgAt(1)); 22 GET_NON_NULL_NATIVE_ARGUMENT(String, pattern, arguments->NativeArgAt(1));
23 GET_NON_NULL_NATIVE_ARGUMENT( 23 GET_NON_NULL_NATIVE_ARGUMENT(
24 Instance, handle_multi_line, arguments->NativeArgAt(2)); 24 Instance, handle_multi_line, arguments->NativeArgAt(2));
25 GET_NON_NULL_NATIVE_ARGUMENT( 25 GET_NON_NULL_NATIVE_ARGUMENT(
26 Instance, handle_case_sensitive, arguments->NativeArgAt(3)); 26 Instance, handle_case_sensitive, arguments->NativeArgAt(3));
27 bool ignore_case = handle_case_sensitive.raw() != Bool::True().raw(); 27 bool ignore_case = handle_case_sensitive.raw() != Bool::True().raw();
28 bool multi_line = handle_multi_line.raw() == Bool::True().raw(); 28 bool multi_line = handle_multi_line.raw() == Bool::True().raw();
29 29
30 // Parse the pattern once in order to throw any format exceptions within 30 // Parse the pattern once in order to throw any format exceptions within
31 // the factory constructor. It is parsed again upon compilation. 31 // the factory constructor. It is parsed again upon compilation.
32 RegExpCompileData compileData; 32 RegExpCompileData compileData;
33 if (!RegExpParser::ParseRegExp(pattern, multi_line, &compileData)) { 33 if (!RegExpParser::ParseRegExp(pattern, multi_line, &compileData)) {
34 // Parsing failures throw an exception. 34 // Parsing failures throw an exception.
35 UNREACHABLE(); 35 UNREACHABLE();
36 } 36 }
37 37
38 // Create a JSRegExp object containing only the initial parameters. 38 // Create a RegExp object containing only the initial parameters.
39 return RegExpEngine::CreateJSRegExp(zone, 39 return RegExpEngine::CreateRegExp(zone,
40 pattern, 40 pattern,
41 multi_line, 41 multi_line,
42 ignore_case); 42 ignore_case);
43 } 43 }
44 44
45 45
46 DEFINE_NATIVE_ENTRY(JSSyntaxRegExp_getPattern, 1) { 46 DEFINE_NATIVE_ENTRY(RegExp_getPattern, 1) {
47 const JSRegExp& regexp = JSRegExp::CheckedHandle(arguments->NativeArgAt(0)); 47 const RegExp& regexp = RegExp::CheckedHandle(arguments->NativeArgAt(0));
48 ASSERT(!regexp.IsNull()); 48 ASSERT(!regexp.IsNull());
49 return regexp.pattern(); 49 return regexp.pattern();
50 } 50 }
51 51
52 52
53 DEFINE_NATIVE_ENTRY(JSSyntaxRegExp_getIsMultiLine, 1) { 53 DEFINE_NATIVE_ENTRY(RegExp_getIsMultiLine, 1) {
54 const JSRegExp& regexp = JSRegExp::CheckedHandle(arguments->NativeArgAt(0)); 54 const RegExp& regexp = RegExp::CheckedHandle(arguments->NativeArgAt(0));
55 ASSERT(!regexp.IsNull()); 55 ASSERT(!regexp.IsNull());
56 return Bool::Get(regexp.is_multi_line()).raw(); 56 return Bool::Get(regexp.is_multi_line()).raw();
57 } 57 }
58 58
59 59
60 DEFINE_NATIVE_ENTRY(JSSyntaxRegExp_getIsCaseSensitive, 1) { 60 DEFINE_NATIVE_ENTRY(RegExp_getIsCaseSensitive, 1) {
61 const JSRegExp& regexp = JSRegExp::CheckedHandle(arguments->NativeArgAt(0)); 61 const RegExp& regexp = RegExp::CheckedHandle(arguments->NativeArgAt(0));
62 ASSERT(!regexp.IsNull()); 62 ASSERT(!regexp.IsNull());
63 return Bool::Get(!regexp.is_ignore_case()).raw(); 63 return Bool::Get(!regexp.is_ignore_case()).raw();
64 } 64 }
65 65
66 66
67 DEFINE_NATIVE_ENTRY(JSSyntaxRegExp_getGroupCount, 1) { 67 DEFINE_NATIVE_ENTRY(RegExp_getGroupCount, 1) {
68 const JSRegExp& regexp = JSRegExp::CheckedHandle(arguments->NativeArgAt(0)); 68 const RegExp& regexp = RegExp::CheckedHandle(arguments->NativeArgAt(0));
69 ASSERT(!regexp.IsNull()); 69 ASSERT(!regexp.IsNull());
70 if (regexp.is_initialized()) { 70 if (regexp.is_initialized()) {
71 return regexp.num_bracket_expressions(); 71 return regexp.num_bracket_expressions();
72 } 72 }
73 const String& pattern = String::Handle(regexp.pattern()); 73 const String& pattern = String::Handle(regexp.pattern());
74 const String& errmsg = String::Handle( 74 const String& errmsg = String::Handle(
75 String::New("Regular expression is not initialized yet. ")); 75 String::New("Regular expression is not initialized yet. "));
76 const String& message = String::Handle(String::Concat(errmsg, pattern)); 76 const String& message = String::Handle(String::Concat(errmsg, pattern));
77 const Array& args = Array::Handle(Array::New(1)); 77 const Array& args = Array::Handle(Array::New(1));
78 args.SetAt(0, message); 78 args.SetAt(0, message);
79 Exceptions::ThrowByType(Exceptions::kFormat, args); 79 Exceptions::ThrowByType(Exceptions::kFormat, args);
80 return Object::null(); 80 return Object::null();
81 } 81 }
82 82
83 83
84 DEFINE_NATIVE_ENTRY(JSSyntaxRegExp_ExecuteMatch, 3) { 84 DEFINE_NATIVE_ENTRY(RegExp_ExecuteMatch, 3) {
85 // This function is intrinsified. See Intrinsifier::JSRegExp_ExecuteMatch. 85 // This function is intrinsified. See Intrinsifier::RegExp_ExecuteMatch.
86 const JSRegExp& regexp = JSRegExp::CheckedHandle(arguments->NativeArgAt(0)); 86 const RegExp& regexp = RegExp::CheckedHandle(arguments->NativeArgAt(0));
87 ASSERT(!regexp.IsNull()); 87 ASSERT(!regexp.IsNull());
88 GET_NON_NULL_NATIVE_ARGUMENT(String, subject, arguments->NativeArgAt(1)); 88 GET_NON_NULL_NATIVE_ARGUMENT(String, subject, arguments->NativeArgAt(1));
89 GET_NON_NULL_NATIVE_ARGUMENT(Smi, start_index, arguments->NativeArgAt(2)); 89 GET_NON_NULL_NATIVE_ARGUMENT(Smi, start_index, arguments->NativeArgAt(2));
90 90
91 if (FLAG_interpret_irregexp || FLAG_precompiled_runtime) { 91 if (FLAG_interpret_irregexp || FLAG_precompiled_runtime) {
92 return BytecodeRegExpMacroAssembler::Interpret(regexp, subject, start_index, 92 return BytecodeRegExpMacroAssembler::Interpret(regexp, subject, start_index,
93 zone); 93 zone);
94 } 94 }
95 95
96 return IRRegExpMacroAssembler::Execute(regexp, subject, start_index, zone); 96 return IRRegExpMacroAssembler::Execute(regexp, subject, start_index, zone);
97 } 97 }
98 98
99 } // namespace dart 99 } // namespace dart
OLDNEW
« no previous file with comments | « no previous file | runtime/lib/regexp_patch.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698