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

Side by Side Diff: src/jsregexp.h

Issue 43075: * Reapply revisions 1383, 1384, 1391, 1398, 1401, 1402,... (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: Created 11 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 | Annotate | Revision Log
« no previous file with comments | « src/factory.cc ('k') | src/jsregexp.cc » ('j') | src/jsregexp.cc » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2006-2008 the V8 project authors. All rights reserved. 1 // Copyright 2006-2008 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 bool* has_pending_exception); 44 bool* has_pending_exception);
45 45
46 // Returns a string representation of a regular expression. 46 // Returns a string representation of a regular expression.
47 // Implements RegExp.prototype.toString, see ECMA-262 section 15.10.6.4. 47 // Implements RegExp.prototype.toString, see ECMA-262 section 15.10.6.4.
48 // This function calls the garbage collector if necessary. 48 // This function calls the garbage collector if necessary.
49 static Handle<String> ToString(Handle<Object> value); 49 static Handle<String> ToString(Handle<Object> value);
50 50
51 // Parses the RegExp pattern and prepares the JSRegExp object with 51 // Parses the RegExp pattern and prepares the JSRegExp object with
52 // generic data and choice of implementation - as well as what 52 // generic data and choice of implementation - as well as what
53 // the implementation wants to store in the data field. 53 // the implementation wants to store in the data field.
54 // Returns false if compilation fails.
54 static Handle<Object> Compile(Handle<JSRegExp> re, 55 static Handle<Object> Compile(Handle<JSRegExp> re,
55 Handle<String> pattern, 56 Handle<String> pattern,
56 Handle<String> flags); 57 Handle<String> flags);
57 58
58 // See ECMA-262 section 15.10.6.2. 59 // See ECMA-262 section 15.10.6.2.
59 // This function calls the garbage collector if necessary. 60 // This function calls the garbage collector if necessary.
60 static Handle<Object> Exec(Handle<JSRegExp> regexp, 61 static Handle<Object> Exec(Handle<JSRegExp> regexp,
61 Handle<String> subject, 62 Handle<String> subject,
62 Handle<Object> index); 63 int index,
64 Handle<JSArray> lastMatchInfo);
63 65
64 // Call RegExp.prototyp.exec(string) in a loop. 66 // Call RegExp.prototyp.exec(string) in a loop.
65 // Used by String.prototype.match and String.prototype.replace. 67 // Used by String.prototype.match and String.prototype.replace.
66 // This function calls the garbage collector if necessary. 68 // This function calls the garbage collector if necessary.
67 static Handle<Object> ExecGlobal(Handle<JSRegExp> regexp, 69 static Handle<Object> ExecGlobal(Handle<JSRegExp> regexp,
68 Handle<String> subject); 70 Handle<String> subject,
71 Handle<JSArray> lastMatchInfo);
69 72
70 // Prepares a JSRegExp object with Irregexp-specific data. 73 // Prepares a JSRegExp object with Irregexp-specific data.
71 static Handle<Object> IrregexpPrepare(Handle<JSRegExp> re, 74 static void IrregexpPrepare(Handle<JSRegExp> re,
72 Handle<String> pattern, 75 Handle<String> pattern,
73 JSRegExp::Flags flags); 76 JSRegExp::Flags flags,
77 int capture_register_count);
74 78
75 79
76 static Handle<Object> AtomCompile(Handle<JSRegExp> re, 80 static void AtomCompile(Handle<JSRegExp> re,
77 Handle<String> pattern, 81 Handle<String> pattern,
78 JSRegExp::Flags flags, 82 JSRegExp::Flags flags,
79 Handle<String> match_pattern); 83 Handle<String> match_pattern);
80 static Handle<Object> AtomExec(Handle<JSRegExp> regexp, 84 static Handle<Object> AtomExec(Handle<JSRegExp> regexp,
81 Handle<String> subject, 85 Handle<String> subject,
82 Handle<Object> index); 86 int index,
87 Handle<JSArray> lastMatchInfo);
83 88
84 static Handle<Object> AtomExecGlobal(Handle<JSRegExp> regexp, 89 static Handle<Object> AtomExecGlobal(Handle<JSRegExp> regexp,
85 Handle<String> subject); 90 Handle<String> subject,
91 Handle<JSArray> lastMatchInfo);
86 92
87 // Execute an Irregexp bytecode pattern. 93 // Execute an Irregexp bytecode pattern.
88 static Handle<Object> IrregexpExec(Handle<JSRegExp> regexp, 94 static Handle<Object> IrregexpExec(Handle<JSRegExp> regexp,
89 Handle<String> subject, 95 Handle<String> subject,
90 Handle<Object> index); 96 int index,
97 Handle<JSArray> lastMatchInfo);
91 98
92 static Handle<Object> IrregexpExecGlobal(Handle<JSRegExp> regexp, 99 static Handle<Object> IrregexpExecGlobal(Handle<JSRegExp> regexp,
93 Handle<String> subject); 100 Handle<String> subject,
101 Handle<JSArray> lastMatchInfo);
94 102
95 static void NewSpaceCollectionPrologue(); 103 static void NewSpaceCollectionPrologue();
96 static void OldSpaceCollectionPrologue(); 104 static void OldSpaceCollectionPrologue();
97 105
98 // Converts a source string to a 16 bit flat string. The string 106 // Converts a source string to a 16 bit flat string. The string
99 // will be either sequential or it will be a SlicedString backed 107 // will be either sequential or it will be a SlicedString backed
100 // by a flat string. 108 // by a flat string.
101 static Handle<String> StringToTwoByte(Handle<String> pattern); 109 static Handle<String> StringToTwoByte(Handle<String> pattern);
102 static Handle<String> CachedStringToTwoByte(Handle<String> pattern); 110 static Handle<String> CachedStringToTwoByte(Handle<String> pattern);
103 111
104 static const int kIrregexpImplementationIndex = 0; 112 // Offsets in the lastMatchInfo array.
105 static const int kIrregexpNumberOfCapturesIndex = 1; 113 static const int kLastCaptureCount = 0;
106 static const int kIrregexpNumberOfRegistersIndex = 2; 114 static const int kLastSubject = 1;
107 static const int kIrregexpCodeIndex = 3; 115 static const int kLastInput = 2;
108 static const int kIrregexpDataLength = 4; 116 static const int kFirstCapture = 1;
117 static const int kLastMatchOverhead = 3;
118 static int GetCapture(FixedArray* array, int index) {
Mads Ager (chromium) 2009/03/11 13:49:17 This is a general comment on this code. Don't let
Erik Corry 2009/03/11 14:01:06 Changed here, left alone other places in the file.
119 return Smi::cast(array->get(index + kFirstCapture))->value();
120 }
121 static void SetLastCaptureCount(FixedArray* array, int to) {
122 array->set(kLastCaptureCount, Smi::FromInt(to));
123 }
124 static void SetLastSubject(FixedArray* array, String* to) {
125 int capture_count = GetLastCaptureCount(array);
126 array->set(capture_count + kLastSubject, to);
127 }
128 static void SetLastInput(FixedArray* array, String* to) {
129 int capture_count = GetLastCaptureCount(array);
130 array->set(capture_count + kLastInput, to);
131 }
132 static void SetCapture(FixedArray* array, int index, int to) {
133 array->set(index + kFirstCapture, Smi::FromInt(to));
134 }
109 135
110 private: 136 private:
111 static String* last_ascii_string_; 137 static String* last_ascii_string_;
112 static String* two_byte_cached_string_; 138 static String* two_byte_cached_string_;
113 139
114 static int IrregexpNumberOfCaptures(Handle<FixedArray> re); 140 static bool EnsureCompiledIrregexp(Handle<JSRegExp> re, bool is_ascii);
115 static int IrregexpNumberOfRegisters(Handle<FixedArray> re); 141
116 static Handle<ByteArray> IrregexpByteCode(Handle<FixedArray> re); 142 static int IrregexpMaxRegisterCount(FixedArray* re);
117 static Handle<Code> IrregexpNativeCode(Handle<FixedArray> re); 143 static void SetIrregexpMaxRegisterCount(FixedArray* re, int value);
144 static int IrregexpNumberOfCaptures(FixedArray* re);
145 static int IrregexpNumberOfRegisters(FixedArray* re);
146 static ByteArray* IrregexpByteCode(FixedArray* re, bool is_ascii);
147 static Code* IrregexpNativeCode(FixedArray* re, bool is_ascii);
118 148
119 // On a successful match, the result is a JSArray containing 149 // On a successful match, the result is a JSArray containing
120 // captured positions. On a failure, the result is the null value. 150 // captured positions. On a failure, the result is the null value.
121 // Returns an empty handle in case of an exception. 151 // Returns an empty handle in case of an exception.
122 static Handle<Object> IrregexpExecOnce(Handle<FixedArray> regexp, 152 static Handle<Object> IrregexpExecOnce(Handle<FixedArray> regexp,
123 int num_captures, 153 int num_captures,
154 Handle<JSArray> lastMatchInfo,
124 Handle<String> subject16, 155 Handle<String> subject16,
125 int previous_index, 156 int previous_index,
126 int* ovector, 157 int* ovector,
127 int ovector_length); 158 int ovector_length);
128 159
129 // Set the subject cache. The previous string buffer is not deleted, so the 160 // Set the subject cache. The previous string buffer is not deleted, so the
130 // caller should ensure that it doesn't leak. 161 // caller should ensure that it doesn't leak.
131 static void SetSubjectCache(String* subject, 162 static void SetSubjectCache(String* subject,
132 char* utf8_subject, 163 char* utf8_subject,
133 int uft8_length, 164 int uft8_length,
134 int character_position, 165 int character_position,
135 int utf8_position); 166 int utf8_position);
136 167
168 // Used to access the lastMatchInfo array.
169 static int GetLastCaptureCount(FixedArray* array) {
170 return Smi::cast(array->get(kLastCaptureCount))->value();
171 }
137 // A one element cache of the last utf8_subject string and its length. The 172 // A one element cache of the last utf8_subject string and its length. The
138 // subject JS String object is cached in the heap. We also cache a 173 // subject JS String object is cached in the heap. We also cache a
139 // translation between position and utf8 position. 174 // translation between position and utf8 position.
140 static char* utf8_subject_cache_; 175 static char* utf8_subject_cache_;
141 static int utf8_length_cache_; 176 static int utf8_length_cache_;
142 static int utf8_position_; 177 static int utf8_position_;
143 static int character_position_; 178 static int character_position_;
144 }; 179 };
145 180
146 181
(...skipping 1165 matching lines...) Expand 10 before | Expand all | Expand 10 after
1312 RegExpNode* node; 1347 RegExpNode* node;
1313 bool simple; 1348 bool simple;
1314 bool contains_anchor; 1349 bool contains_anchor;
1315 Handle<String> error; 1350 Handle<String> error;
1316 int capture_count; 1351 int capture_count;
1317 }; 1352 };
1318 1353
1319 1354
1320 class RegExpEngine: public AllStatic { 1355 class RegExpEngine: public AllStatic {
1321 public: 1356 public:
1322 static Handle<FixedArray> Compile(RegExpCompileData* input, 1357 struct CompilationResult {
1323 bool ignore_case, 1358 explicit CompilationResult(const char* error_message)
1324 bool multiline, 1359 : error_message(error_message),
1325 Handle<String> pattern, 1360 code(Heap::the_hole_value()),
1326 bool is_ascii); 1361 num_registers(0) {}
1362 CompilationResult(Object* code, int registers)
1363 : error_message(NULL),
1364 code(code),
1365 num_registers(registers) {}
1366 const char* error_message;
1367 Object* code;
1368 int num_registers;
1369 };
1370
1371 static CompilationResult Compile(RegExpCompileData* input,
1372 bool ignore_case,
1373 bool multiline,
1374 Handle<String> pattern,
1375 bool is_ascii);
1327 1376
1328 static void DotPrint(const char* label, RegExpNode* node, bool ignore_case); 1377 static void DotPrint(const char* label, RegExpNode* node, bool ignore_case);
1329 }; 1378 };
1330 1379
1331 1380
1332 } } // namespace v8::internal 1381 } } // namespace v8::internal
1333 1382
1334 #endif // V8_JSREGEXP_H_ 1383 #endif // V8_JSREGEXP_H_
OLDNEW
« no previous file with comments | « src/factory.cc ('k') | src/jsregexp.cc » ('j') | src/jsregexp.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698