OLD | NEW |
1 // Copyright 2010 the V8 project authors. All rights reserved. | 1 // Copyright 2010 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 380 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
391 Interval self(StartRegister(index()), EndRegister(index())); | 391 Interval self(StartRegister(index()), EndRegister(index())); |
392 return self.Union(body()->CaptureRegisters()); | 392 return self.Union(body()->CaptureRegisters()); |
393 } | 393 } |
394 | 394 |
395 | 395 |
396 Interval RegExpQuantifier::CaptureRegisters() { | 396 Interval RegExpQuantifier::CaptureRegisters() { |
397 return body()->CaptureRegisters(); | 397 return body()->CaptureRegisters(); |
398 } | 398 } |
399 | 399 |
400 | 400 |
401 bool RegExpAssertion::IsAnchored() { | 401 bool RegExpAssertion::IsAnchoredAtStart() { |
402 return type() == RegExpAssertion::START_OF_INPUT; | 402 return type() == RegExpAssertion::START_OF_INPUT; |
403 } | 403 } |
404 | 404 |
405 | 405 |
406 bool RegExpAlternative::IsAnchored() { | 406 bool RegExpAssertion::IsAnchoredAtEnd() { |
| 407 return type() == RegExpAssertion::END_OF_INPUT; |
| 408 } |
| 409 |
| 410 |
| 411 bool RegExpAlternative::IsAnchoredAtStart() { |
407 ZoneList<RegExpTree*>* nodes = this->nodes(); | 412 ZoneList<RegExpTree*>* nodes = this->nodes(); |
408 for (int i = 0; i < nodes->length(); i++) { | 413 for (int i = 0; i < nodes->length(); i++) { |
409 RegExpTree* node = nodes->at(i); | 414 RegExpTree* node = nodes->at(i); |
410 if (node->IsAnchored()) { return true; } | 415 if (node->IsAnchoredAtStart()) { return true; } |
411 if (node->max_match() > 0) { return false; } | 416 if (node->max_match() > 0) { return false; } |
412 } | 417 } |
413 return false; | 418 return false; |
414 } | 419 } |
415 | 420 |
416 | 421 |
417 bool RegExpDisjunction::IsAnchored() { | 422 bool RegExpAlternative::IsAnchoredAtEnd() { |
| 423 ZoneList<RegExpTree*>* nodes = this->nodes(); |
| 424 for (int i = nodes->length() - 1; i >= 0; i--) { |
| 425 RegExpTree* node = nodes->at(i); |
| 426 if (node->IsAnchoredAtEnd()) { return true; } |
| 427 if (node->max_match() > 0) { return false; } |
| 428 } |
| 429 return false; |
| 430 } |
| 431 |
| 432 |
| 433 bool RegExpDisjunction::IsAnchoredAtStart() { |
418 ZoneList<RegExpTree*>* alternatives = this->alternatives(); | 434 ZoneList<RegExpTree*>* alternatives = this->alternatives(); |
419 for (int i = 0; i < alternatives->length(); i++) { | 435 for (int i = 0; i < alternatives->length(); i++) { |
420 if (!alternatives->at(i)->IsAnchored()) | 436 if (!alternatives->at(i)->IsAnchoredAtStart()) |
421 return false; | 437 return false; |
422 } | 438 } |
423 return true; | 439 return true; |
424 } | 440 } |
425 | 441 |
426 | 442 |
427 bool RegExpLookahead::IsAnchored() { | 443 bool RegExpDisjunction::IsAnchoredAtEnd() { |
428 return is_positive() && body()->IsAnchored(); | 444 ZoneList<RegExpTree*>* alternatives = this->alternatives(); |
| 445 for (int i = 0; i < alternatives->length(); i++) { |
| 446 if (!alternatives->at(i)->IsAnchoredAtEnd()) |
| 447 return false; |
| 448 } |
| 449 return true; |
429 } | 450 } |
430 | 451 |
431 | 452 |
432 bool RegExpCapture::IsAnchored() { | 453 bool RegExpLookahead::IsAnchoredAtStart() { |
433 return body()->IsAnchored(); | 454 return is_positive() && body()->IsAnchoredAtStart(); |
434 } | 455 } |
435 | 456 |
436 | 457 |
| 458 bool RegExpCapture::IsAnchoredAtStart() { |
| 459 return body()->IsAnchoredAtStart(); |
| 460 } |
| 461 |
| 462 |
| 463 bool RegExpCapture::IsAnchoredAtEnd() { |
| 464 return body()->IsAnchoredAtEnd(); |
| 465 } |
| 466 |
| 467 |
437 // Convert regular expression trees to a simple sexp representation. | 468 // Convert regular expression trees to a simple sexp representation. |
438 // This representation should be different from the input grammar | 469 // This representation should be different from the input grammar |
439 // in as many cases as possible, to make it more difficult for incorrect | 470 // in as many cases as possible, to make it more difficult for incorrect |
440 // parses to look as correct ones which is likely if the input and | 471 // parses to look as correct ones which is likely if the input and |
441 // output formats are alike. | 472 // output formats are alike. |
442 class RegExpUnparser: public RegExpVisitor { | 473 class RegExpUnparser: public RegExpVisitor { |
443 public: | 474 public: |
444 RegExpUnparser(); | 475 RegExpUnparser(); |
445 void VisitCharacterRange(CharacterRange that); | 476 void VisitCharacterRange(CharacterRange that); |
446 SmartPointer<const char> ToString() { return stream_.ToCString(); } | 477 SmartPointer<const char> ToString() { return stream_.ToCString(); } |
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
642 cond_(NULL), | 673 cond_(NULL), |
643 may_have_function_literal_(true) { | 674 may_have_function_literal_(true) { |
644 } | 675 } |
645 | 676 |
646 | 677 |
647 CaseClause::CaseClause(Expression* label, ZoneList<Statement*>* statements) | 678 CaseClause::CaseClause(Expression* label, ZoneList<Statement*>* statements) |
648 : label_(label), statements_(statements) { | 679 : label_(label), statements_(statements) { |
649 } | 680 } |
650 | 681 |
651 } } // namespace v8::internal | 682 } } // namespace v8::internal |
OLD | NEW |