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

Side by Side Diff: src/parser.cc

Issue 19539: Irregexp: Added derived knowledge of whether we are at the start of input. (Closed)
Patch Set: Fixed lint issues. Created 11 years, 10 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 | « src/jsregexp.cc ('k') | src/regexp-macro-assembler-ia32.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 514 matching lines...) Expand 10 before | Expand all | Expand 10 after
525 525
526 CharacterRange ParseClassAtom(uc16* char_class); 526 CharacterRange ParseClassAtom(uc16* char_class);
527 RegExpTree* ReportError(Vector<const char> message); 527 RegExpTree* ReportError(Vector<const char> message);
528 void Advance(); 528 void Advance();
529 void Advance(int dist); 529 void Advance(int dist);
530 void Reset(int pos); 530 void Reset(int pos);
531 531
532 // Reports whether the pattern might be used as a literal search string. 532 // Reports whether the pattern might be used as a literal search string.
533 // Only use if the result of the parse is a single atom node. 533 // Only use if the result of the parse is a single atom node.
534 bool simple(); 534 bool simple();
535 535 bool contains_anchor() { return contains_anchor_; }
536 void set_contains_anchor() { contains_anchor_ = true; }
536 int captures_started() { return captures_ == NULL ? 0 : captures_->length(); } 537 int captures_started() { return captures_ == NULL ? 0 : captures_->length(); }
537 int position() { return next_pos_ - 1; } 538 int position() { return next_pos_ - 1; }
538 bool failed() { return failed_; } 539 bool failed() { return failed_; }
539 540
540 static const int kMaxCaptures = 1 << 16; 541 static const int kMaxCaptures = 1 << 16;
541 static const uc32 kEndMarker = (1 << 21); 542 static const uc32 kEndMarker = (1 << 21);
542 private: 543 private:
543 544
544 uc32 current() { return current_; } 545 uc32 current() { return current_; }
545 bool has_more() { return has_more_; } 546 bool has_more() { return has_more_; }
546 bool has_next() { return next_pos_ < in()->length(); } 547 bool has_next() { return next_pos_ < in()->length(); }
547 uc32 Next(); 548 uc32 Next();
548 FlatStringReader* in() { return in_; } 549 FlatStringReader* in() { return in_; }
549 void ScanForCaptures(); 550 void ScanForCaptures();
550 bool CaptureAvailable(int index); 551 bool CaptureAvailable(int index);
551 uc32 current_; 552 uc32 current_;
552 bool has_more_; 553 bool has_more_;
553 bool multiline_; 554 bool multiline_;
554 int next_pos_; 555 int next_pos_;
555 FlatStringReader* in_; 556 FlatStringReader* in_;
556 Handle<String>* error_; 557 Handle<String>* error_;
557 bool simple_; 558 bool simple_;
559 bool contains_anchor_;
558 ZoneList<RegExpCapture*>* captures_; 560 ZoneList<RegExpCapture*>* captures_;
559 bool is_scanned_for_captures_; 561 bool is_scanned_for_captures_;
560 // The capture count is only valid after we have scanned for captures. 562 // The capture count is only valid after we have scanned for captures.
561 int capture_count_; 563 int capture_count_;
562 bool failed_; 564 bool failed_;
563 }; 565 };
564 566
565 567
566 // A temporary scope stores information during parsing, just like 568 // A temporary scope stores information during parsing, just like
567 // a plain scope. However, temporary scopes are not kept around 569 // a plain scope. However, temporary scopes are not kept around
(...skipping 2911 matching lines...) Expand 10 before | Expand all | Expand 10 after
3479 RegExpParser::RegExpParser(FlatStringReader* in, 3481 RegExpParser::RegExpParser(FlatStringReader* in,
3480 Handle<String>* error, 3482 Handle<String>* error,
3481 bool multiline) 3483 bool multiline)
3482 : current_(kEndMarker), 3484 : current_(kEndMarker),
3483 has_more_(true), 3485 has_more_(true),
3484 multiline_(multiline), 3486 multiline_(multiline),
3485 next_pos_(0), 3487 next_pos_(0),
3486 in_(in), 3488 in_(in),
3487 error_(error), 3489 error_(error),
3488 simple_(true), 3490 simple_(true),
3491 contains_anchor_(false),
3489 captures_(NULL), 3492 captures_(NULL),
3490 is_scanned_for_captures_(false), 3493 is_scanned_for_captures_(false),
3491 capture_count_(0), 3494 capture_count_(0),
3492 failed_(false) { 3495 failed_(false) {
3493 Advance(1); 3496 Advance(1);
3494 } 3497 }
3495 3498
3496 3499
3497 uc32 RegExpParser::Next() { 3500 uc32 RegExpParser::Next() {
3498 if (has_next()) { 3501 if (has_next()) {
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
3596 } 3599 }
3597 capture_start_index = capture_new_alt_start_index; 3600 capture_start_index = capture_new_alt_start_index;
3598 continue; 3601 continue;
3599 } 3602 }
3600 case '*': 3603 case '*':
3601 case '+': 3604 case '+':
3602 case '?': 3605 case '?':
3603 ReportError(CStrVector("Nothing to repeat") CHECK_FAILED); 3606 ReportError(CStrVector("Nothing to repeat") CHECK_FAILED);
3604 case '^': { 3607 case '^': {
3605 Advance(); 3608 Advance();
3606 RegExpAssertion::Type type = 3609 if (multiline_) {
3607 multiline_ ? RegExpAssertion::START_OF_LINE : 3610 builder.AddAssertion(
3608 RegExpAssertion::START_OF_INPUT; 3611 new RegExpAssertion(RegExpAssertion::START_OF_LINE));
3609 builder.AddAssertion(new RegExpAssertion(type)); 3612 } else {
3613 builder.AddAssertion(
3614 new RegExpAssertion(RegExpAssertion::START_OF_INPUT));
3615 set_contains_anchor();
3616 }
3610 continue; 3617 continue;
3611 } 3618 }
3612 case '$': { 3619 case '$': {
3613 Advance(); 3620 Advance();
3614 RegExpAssertion::Type type = 3621 RegExpAssertion::Type type =
3615 multiline_ ? RegExpAssertion::END_OF_LINE : 3622 multiline_ ? RegExpAssertion::END_OF_LINE :
3616 RegExpAssertion::END_OF_INPUT; 3623 RegExpAssertion::END_OF_INPUT;
3617 builder.AddAssertion(new RegExpAssertion(type)); 3624 builder.AddAssertion(new RegExpAssertion(type));
3618 continue; 3625 continue;
3619 } 3626 }
(...skipping 685 matching lines...) Expand 10 before | Expand all | Expand 10 after
4305 RegExpTree* tree = parser.ParsePattern(); 4312 RegExpTree* tree = parser.ParsePattern();
4306 if (parser.failed()) { 4313 if (parser.failed()) {
4307 ASSERT(tree == NULL); 4314 ASSERT(tree == NULL);
4308 ASSERT(!result->error.is_null()); 4315 ASSERT(!result->error.is_null());
4309 } else { 4316 } else {
4310 ASSERT(tree != NULL); 4317 ASSERT(tree != NULL);
4311 ASSERT(result->error.is_null()); 4318 ASSERT(result->error.is_null());
4312 result->tree = tree; 4319 result->tree = tree;
4313 int capture_count = parser.captures_started(); 4320 int capture_count = parser.captures_started();
4314 result->simple = tree->IsAtom() && parser.simple() && capture_count == 0; 4321 result->simple = tree->IsAtom() && parser.simple() && capture_count == 0;
4322 result->contains_anchor = parser.contains_anchor();
4315 result->capture_count = capture_count; 4323 result->capture_count = capture_count;
4316 } 4324 }
4317 return !parser.failed(); 4325 return !parser.failed();
4318 } 4326 }
4319 4327
4320 4328
4321 FunctionLiteral* MakeAST(bool compile_in_global_context, 4329 FunctionLiteral* MakeAST(bool compile_in_global_context,
4322 Handle<Script> script, 4330 Handle<Script> script,
4323 v8::Extension* extension, 4331 v8::Extension* extension,
4324 ScriptDataImpl* pre_data) { 4332 ScriptDataImpl* pre_data) {
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
4363 start_position, 4371 start_position,
4364 is_expression); 4372 is_expression);
4365 return result; 4373 return result;
4366 } 4374 }
4367 4375
4368 4376
4369 #undef NEW 4377 #undef NEW
4370 4378
4371 4379
4372 } } // namespace v8::internal 4380 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/jsregexp.cc ('k') | src/regexp-macro-assembler-ia32.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698