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

Side by Side Diff: src/jsregexp.h

Issue 39186: Revert 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') | no next file with comments »
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.
55 static Handle<Object> Compile(Handle<JSRegExp> re, 54 static Handle<Object> Compile(Handle<JSRegExp> re,
56 Handle<String> pattern, 55 Handle<String> pattern,
57 Handle<String> flags); 56 Handle<String> flags);
58 57
59 // See ECMA-262 section 15.10.6.2. 58 // See ECMA-262 section 15.10.6.2.
60 // This function calls the garbage collector if necessary. 59 // This function calls the garbage collector if necessary.
61 static Handle<Object> Exec(Handle<JSRegExp> regexp, 60 static Handle<Object> Exec(Handle<JSRegExp> regexp,
62 Handle<String> subject, 61 Handle<String> subject,
63 int index, 62 Handle<Object> index);
64 Handle<JSArray> lastMatchInfo);
65 63
66 // Call RegExp.prototyp.exec(string) in a loop. 64 // Call RegExp.prototyp.exec(string) in a loop.
67 // Used by String.prototype.match and String.prototype.replace. 65 // Used by String.prototype.match and String.prototype.replace.
68 // This function calls the garbage collector if necessary. 66 // This function calls the garbage collector if necessary.
69 static Handle<Object> ExecGlobal(Handle<JSRegExp> regexp, 67 static Handle<Object> ExecGlobal(Handle<JSRegExp> regexp,
70 Handle<String> subject, 68 Handle<String> subject);
71 Handle<JSArray> lastMatchInfo);
72 69
73 // Prepares a JSRegExp object with Irregexp-specific data. 70 // Prepares a JSRegExp object with Irregexp-specific data.
74 static void IrregexpPrepare(Handle<JSRegExp> re, 71 static Handle<Object> IrregexpPrepare(Handle<JSRegExp> re,
75 Handle<String> pattern, 72 Handle<String> pattern,
76 JSRegExp::Flags flags, 73 JSRegExp::Flags flags);
77 int capture_register_count);
78 74
79 75
80 static void AtomCompile(Handle<JSRegExp> re, 76 static Handle<Object> AtomCompile(Handle<JSRegExp> re,
81 Handle<String> pattern, 77 Handle<String> pattern,
82 JSRegExp::Flags flags, 78 JSRegExp::Flags flags,
83 Handle<String> match_pattern); 79 Handle<String> match_pattern);
84 static Handle<Object> AtomExec(Handle<JSRegExp> regexp, 80 static Handle<Object> AtomExec(Handle<JSRegExp> regexp,
85 Handle<String> subject, 81 Handle<String> subject,
86 int index, 82 Handle<Object> index);
87 Handle<JSArray> lastMatchInfo);
88 83
89 static Handle<Object> AtomExecGlobal(Handle<JSRegExp> regexp, 84 static Handle<Object> AtomExecGlobal(Handle<JSRegExp> regexp,
90 Handle<String> subject, 85 Handle<String> subject);
91 Handle<JSArray> lastMatchInfo);
92 86
93 // Execute an Irregexp bytecode pattern. 87 // Execute an Irregexp bytecode pattern.
94 static Handle<Object> IrregexpExec(Handle<JSRegExp> regexp, 88 static Handle<Object> IrregexpExec(Handle<JSRegExp> regexp,
95 Handle<String> subject, 89 Handle<String> subject,
96 int index, 90 Handle<Object> index);
97 Handle<JSArray> lastMatchInfo);
98 91
99 static Handle<Object> IrregexpExecGlobal(Handle<JSRegExp> regexp, 92 static Handle<Object> IrregexpExecGlobal(Handle<JSRegExp> regexp,
100 Handle<String> subject, 93 Handle<String> subject);
101 Handle<JSArray> lastMatchInfo);
102 94
103 static void NewSpaceCollectionPrologue(); 95 static void NewSpaceCollectionPrologue();
104 static void OldSpaceCollectionPrologue(); 96 static void OldSpaceCollectionPrologue();
105 97
106 // Converts a source string to a 16 bit flat string. The string 98 // Converts a source string to a 16 bit flat string. The string
107 // will be either sequential or it will be a SlicedString backed 99 // will be either sequential or it will be a SlicedString backed
108 // by a flat string. 100 // by a flat string.
109 static Handle<String> StringToTwoByte(Handle<String> pattern); 101 static Handle<String> StringToTwoByte(Handle<String> pattern);
110 static Handle<String> CachedStringToTwoByte(Handle<String> pattern); 102 static Handle<String> CachedStringToTwoByte(Handle<String> pattern);
111 103
112 // Offsets in the lastMatchInfo array. 104 static const int kIrregexpImplementationIndex = 0;
113 static const int kLastCaptureCount = 0; 105 static const int kIrregexpNumberOfCapturesIndex = 1;
114 static const int kLastSubject = 1; 106 static const int kIrregexpNumberOfRegistersIndex = 2;
115 static const int kLastInput = 2; 107 static const int kIrregexpCodeIndex = 3;
116 static const int kFirstCapture = 1; 108 static const int kIrregexpDataLength = 4;
117 static const int kLastMatchOverhead = 3;
118 static int GetCapture(FixedArray* array, int index) {
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 }
135 109
136 private: 110 private:
137 static String* last_ascii_string_; 111 static String* last_ascii_string_;
138 static String* two_byte_cached_string_; 112 static String* two_byte_cached_string_;
139 113
140 static bool EnsureCompiledIrregexp(Handle<JSRegExp> re, bool is_ascii); 114 static int IrregexpNumberOfCaptures(Handle<FixedArray> re);
141 115 static int IrregexpNumberOfRegisters(Handle<FixedArray> re);
142 static int IrregexpMaxRegisterCount(FixedArray* re); 116 static Handle<ByteArray> IrregexpByteCode(Handle<FixedArray> re);
143 static void SetIrregexpMaxRegisterCount(FixedArray* re, int value); 117 static Handle<Code> IrregexpNativeCode(Handle<FixedArray> re);
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);
148 118
149 // On a successful match, the result is a JSArray containing 119 // On a successful match, the result is a JSArray containing
150 // captured positions. On a failure, the result is the null value. 120 // captured positions. On a failure, the result is the null value.
151 // Returns an empty handle in case of an exception. 121 // Returns an empty handle in case of an exception.
152 static Handle<Object> IrregexpExecOnce(Handle<FixedArray> regexp, 122 static Handle<Object> IrregexpExecOnce(Handle<FixedArray> regexp,
153 int num_captures, 123 int num_captures,
154 Handle<JSArray> lastMatchInfo,
155 Handle<String> subject16, 124 Handle<String> subject16,
156 int previous_index, 125 int previous_index,
157 int* ovector, 126 int* ovector,
158 int ovector_length); 127 int ovector_length);
159 128
160 // Set the subject cache. The previous string buffer is not deleted, so the 129 // Set the subject cache. The previous string buffer is not deleted, so the
161 // caller should ensure that it doesn't leak. 130 // caller should ensure that it doesn't leak.
162 static void SetSubjectCache(String* subject, 131 static void SetSubjectCache(String* subject,
163 char* utf8_subject, 132 char* utf8_subject,
164 int uft8_length, 133 int uft8_length,
165 int character_position, 134 int character_position,
166 int utf8_position); 135 int utf8_position);
167 136
168 // Used to access the lastMatchInfo array.
169 static int GetLastCaptureCount(FixedArray* array) {
170 return Smi::cast(array->get(kLastCaptureCount))->value();
171 }
172 // A one element cache of the last utf8_subject string and its length. The 137 // A one element cache of the last utf8_subject string and its length. The
173 // subject JS String object is cached in the heap. We also cache a 138 // subject JS String object is cached in the heap. We also cache a
174 // translation between position and utf8 position. 139 // translation between position and utf8 position.
175 static char* utf8_subject_cache_; 140 static char* utf8_subject_cache_;
176 static int utf8_length_cache_; 141 static int utf8_length_cache_;
177 static int utf8_position_; 142 static int utf8_position_;
178 static int character_position_; 143 static int character_position_;
179 }; 144 };
180 145
181 146
(...skipping 1165 matching lines...) Expand 10 before | Expand all | Expand 10 after
1347 RegExpNode* node; 1312 RegExpNode* node;
1348 bool simple; 1313 bool simple;
1349 bool contains_anchor; 1314 bool contains_anchor;
1350 Handle<String> error; 1315 Handle<String> error;
1351 int capture_count; 1316 int capture_count;
1352 }; 1317 };
1353 1318
1354 1319
1355 class RegExpEngine: public AllStatic { 1320 class RegExpEngine: public AllStatic {
1356 public: 1321 public:
1357 struct CompilationResult { 1322 static Handle<FixedArray> Compile(RegExpCompileData* input,
1358 explicit CompilationResult(const char* error_message) 1323 bool ignore_case,
1359 : error_message(error_message), 1324 bool multiline,
1360 code(Heap::the_hole_value()), 1325 Handle<String> pattern,
1361 num_registers(0) {} 1326 bool is_ascii);
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);
1376 1327
1377 static void DotPrint(const char* label, RegExpNode* node, bool ignore_case); 1328 static void DotPrint(const char* label, RegExpNode* node, bool ignore_case);
1378 }; 1329 };
1379 1330
1380 1331
1381 } } // namespace v8::internal 1332 } } // namespace v8::internal
1382 1333
1383 #endif // V8_JSREGEXP_H_ 1334 #endif // V8_JSREGEXP_H_
OLDNEW
« no previous file with comments | « src/factory.cc ('k') | src/jsregexp.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698