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

Side by Side Diff: regexp2000/src/jsregexp.cc

Issue 9110: Experimental: Fixed bug in RegExp Parser. Added feature counting in parser. (Closed)
Patch Set: Merged changes to tip of experimental branch. Created 12 years, 1 month 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 | « regexp2000/src/jsregexp.h ('k') | regexp2000/src/list.h » ('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 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
197 Handle<String> flag_str) { 197 Handle<String> flag_str) {
198 JSRegExp::Flags flags = RegExpFlagsFromString(flag_str); 198 JSRegExp::Flags flags = RegExpFlagsFromString(flag_str);
199 Handle<FixedArray> cached = CompilationCache::LookupRegExp(pattern, flags); 199 Handle<FixedArray> cached = CompilationCache::LookupRegExp(pattern, flags);
200 bool in_cache = !cached.is_null(); 200 bool in_cache = !cached.is_null();
201 Handle<Object> result; 201 Handle<Object> result;
202 StringShape shape(*pattern); 202 StringShape shape(*pattern);
203 if (in_cache) { 203 if (in_cache) {
204 re->set_data(*cached); 204 re->set_data(*cached);
205 result = re; 205 result = re;
206 } else { 206 } else {
207 SafeStringInputBuffer buffer(pattern.location()); 207 SafeStringInputBuffer buffer(pattern.location());
208 Handle<String> error_text; 208 Handle<String> error_text;
209 RegExpTree* ast = ParseRegExp(&buffer, &error_text); 209 bool has_escapes;
210 RegExpTree* ast = ParseRegExp(&buffer, &error_text, &has_escapes);
210 if (!error_text.is_null()) { 211 if (!error_text.is_null()) {
211 // Throw an exception if we fail to parse the pattern. 212 // Throw an exception if we fail to parse the pattern.
212 return CreateRegExpException(re, pattern, error_text, "malformed_regexp"); 213 return CreateRegExpException(re, pattern, error_text, "malformed_regexp");
213 } 214 }
214 RegExpAtom* atom = ast->AsAtom(); 215 RegExpAtom* atom = ast->AsAtom();
215 if (atom != NULL && !flags.is_ignore_case()) { 216 if (atom != NULL && !flags.is_ignore_case()) {
216 Vector<const uc16> atom_pattern = atom->data(); 217 if (has_escapes) {
217 // Test if pattern equals atom_pattern and reuse pattern if it does. 218 Vector<const uc16> atom_pattern = atom->data();
218 Handle<String> atom_string = Factory::NewStringFromTwoByte(atom_pattern); 219 Handle<String> atom_string =
219 result = AtomCompile(re, atom_string, flags); 220 Factory::NewStringFromTwoByte(atom_pattern);
221 result = AtomCompile(re, pattern, flags, atom_string);
222 } else {
223 result = AtomCompile(re, pattern, flags, pattern);
224 }
220 } else { 225 } else {
221 result = JsrePrepare(re, pattern, flags); 226 result = JsrePrepare(re, pattern, flags);
222 } 227 }
223 Object* data = re->data(); 228 Object* data = re->data();
224 if (data->IsFixedArray()) { 229 if (data->IsFixedArray()) {
225 // If compilation succeeded then the data is set on the regexp 230 // If compilation succeeded then the data is set on the regexp
226 // and we can store it in the cache. 231 // and we can store it in the cache.
227 Handle<FixedArray> data(FixedArray::cast(re->data())); 232 Handle<FixedArray> data(FixedArray::cast(re->data()));
228 CompilationCache::PutRegExp(pattern, flags, data); 233 CompilationCache::PutRegExp(pattern, flags, data);
229 } 234 }
(...skipping 28 matching lines...) Expand all
258 return AtomExecGlobal(regexp, subject); 263 return AtomExecGlobal(regexp, subject);
259 default: 264 default:
260 UNREACHABLE(); 265 UNREACHABLE();
261 return Handle<Object>(); 266 return Handle<Object>();
262 } 267 }
263 } 268 }
264 269
265 270
266 Handle<Object> RegExpImpl::AtomCompile(Handle<JSRegExp> re, 271 Handle<Object> RegExpImpl::AtomCompile(Handle<JSRegExp> re,
267 Handle<String> pattern, 272 Handle<String> pattern,
268 JSRegExp::Flags flags) { 273 JSRegExp::Flags flags,
269 Factory::SetRegExpData(re, JSRegExp::ATOM, pattern, flags, pattern); 274 Handle<String> match_pattern) {
275 Factory::SetRegExpData(re, JSRegExp::ATOM, pattern, flags, match_pattern);
270 return re; 276 return re;
271 } 277 }
272 278
273 279
274 Handle<Object> RegExpImpl::AtomExec(Handle<JSRegExp> re, 280 Handle<Object> RegExpImpl::AtomExec(Handle<JSRegExp> re,
275 Handle<String> subject, 281 Handle<String> subject,
276 Handle<Object> index) { 282 Handle<Object> index) {
277 Handle<String> needle(String::cast(re->DataAt(JSRegExp::kAtomPatternIndex))); 283 Handle<String> needle(String::cast(re->DataAt(JSRegExp::kAtomPatternIndex)));
278 284
279 uint32_t start_index; 285 uint32_t start_index;
(...skipping 656 matching lines...) Expand 10 before | Expand all | Expand 10 after
936 for (int i = 0; i < elmc; i += 2) { 942 for (int i = 0; i < elmc; i += 2) {
937 ASSERT(last <= elmv[i] - 1); 943 ASSERT(last <= elmv[i] - 1);
938 ASSERT(elmv[i] <= elmv[i + 1]); 944 ASSERT(elmv[i] <= elmv[i + 1]);
939 ranges->Add(CharacterRange(last, elmv[i] - 1)); 945 ranges->Add(CharacterRange(last, elmv[i] - 1));
940 last = elmv[i + 1] + 1; 946 last = elmv[i + 1] + 1;
941 } 947 }
942 ranges->Add(CharacterRange(last, 0xFFFF)); 948 ranges->Add(CharacterRange(last, 0xFFFF));
943 } 949 }
944 950
945 951
946 void CharacterRange::AddClassEscape(uc16 type, ZoneList<CharacterRange>* ranges) { 952 void CharacterRange::AddClassEscape(uc16 type,
953 ZoneList<CharacterRange>* ranges) {
947 switch (type) { 954 switch (type) {
948 case 's': 955 case 's':
949 AddClass(kSpaceRanges, kSpaceRangeCount, ranges); 956 AddClass(kSpaceRanges, kSpaceRangeCount, ranges);
950 break; 957 break;
951 case 'S': 958 case 'S':
952 AddClassNegated(kSpaceRanges, kSpaceRangeCount, ranges); 959 AddClassNegated(kSpaceRanges, kSpaceRangeCount, ranges);
953 break; 960 break;
954 case 'w': 961 case 'w':
955 AddClass(kWordRanges, kWordRangeCount, ranges); 962 AddClass(kWordRanges, kWordRangeCount, ranges);
956 break; 963 break;
(...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after
1296 template 1303 template
1297 bool RegExpEngine::Execute<const char>(RegExpNode<const char>* start, 1304 bool RegExpEngine::Execute<const char>(RegExpNode<const char>* start,
1298 Vector<const char> input); 1305 Vector<const char> input);
1299 1306
1300 template 1307 template
1301 bool RegExpEngine::Execute<const uc16>(RegExpNode<const uc16>* start, 1308 bool RegExpEngine::Execute<const uc16>(RegExpNode<const uc16>* start,
1302 Vector<const uc16> input); 1309 Vector<const uc16> input);
1303 1310
1304 1311
1305 }} // namespace v8::internal 1312 }} // namespace v8::internal
OLDNEW
« no previous file with comments | « regexp2000/src/jsregexp.h ('k') | regexp2000/src/list.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698