| OLD | NEW |
| 1 // Copyright 2016 the V8 project authors. All rights reserved. | 1 // Copyright 2016 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef V8_REGEXP_REGEXP_AST_H_ | 5 #ifndef V8_REGEXP_REGEXP_AST_H_ |
| 6 #define V8_REGEXP_REGEXP_AST_H_ | 6 #define V8_REGEXP_REGEXP_AST_H_ |
| 7 | 7 |
| 8 #include "src/objects.h" | 8 #include "src/objects.h" |
| 9 #include "src/utils.h" | 9 #include "src/utils.h" |
| 10 #include "src/zone-containers.h" |
| 10 #include "src/zone.h" | 11 #include "src/zone.h" |
| 11 | 12 |
| 12 namespace v8 { | 13 namespace v8 { |
| 13 namespace internal { | 14 namespace internal { |
| 14 | 15 |
| 15 #define FOR_EACH_REG_EXP_TREE_TYPE(VISIT) \ | 16 #define FOR_EACH_REG_EXP_TREE_TYPE(VISIT) \ |
| 16 VISIT(Disjunction) \ | 17 VISIT(Disjunction) \ |
| 17 VISIT(Alternative) \ | 18 VISIT(Alternative) \ |
| 18 VISIT(Assertion) \ | 19 VISIT(Assertion) \ |
| 19 VISIT(CharacterClass) \ | 20 VISIT(CharacterClass) \ |
| (...skipping 385 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 405 int min_; | 406 int min_; |
| 406 int max_; | 407 int max_; |
| 407 int min_match_; | 408 int min_match_; |
| 408 int max_match_; | 409 int max_match_; |
| 409 QuantifierType quantifier_type_; | 410 QuantifierType quantifier_type_; |
| 410 }; | 411 }; |
| 411 | 412 |
| 412 | 413 |
| 413 class RegExpCapture final : public RegExpTree { | 414 class RegExpCapture final : public RegExpTree { |
| 414 public: | 415 public: |
| 415 explicit RegExpCapture(int index) : body_(NULL), index_(index) {} | 416 explicit RegExpCapture(int index) |
| 417 : body_(NULL), index_(index), name_(nullptr) {} |
| 416 void* Accept(RegExpVisitor* visitor, void* data) override; | 418 void* Accept(RegExpVisitor* visitor, void* data) override; |
| 417 RegExpNode* ToNode(RegExpCompiler* compiler, RegExpNode* on_success) override; | 419 RegExpNode* ToNode(RegExpCompiler* compiler, RegExpNode* on_success) override; |
| 418 static RegExpNode* ToNode(RegExpTree* body, int index, | 420 static RegExpNode* ToNode(RegExpTree* body, int index, |
| 419 RegExpCompiler* compiler, RegExpNode* on_success); | 421 RegExpCompiler* compiler, RegExpNode* on_success); |
| 420 RegExpCapture* AsCapture() override; | 422 RegExpCapture* AsCapture() override; |
| 421 bool IsAnchoredAtStart() override; | 423 bool IsAnchoredAtStart() override; |
| 422 bool IsAnchoredAtEnd() override; | 424 bool IsAnchoredAtEnd() override; |
| 423 Interval CaptureRegisters() override; | 425 Interval CaptureRegisters() override; |
| 424 bool IsCapture() override; | 426 bool IsCapture() override; |
| 425 int min_match() override { return body_->min_match(); } | 427 int min_match() override { return body_->min_match(); } |
| 426 int max_match() override { return body_->max_match(); } | 428 int max_match() override { return body_->max_match(); } |
| 427 RegExpTree* body() { return body_; } | 429 RegExpTree* body() { return body_; } |
| 428 void set_body(RegExpTree* body) { body_ = body; } | 430 void set_body(RegExpTree* body) { body_ = body; } |
| 429 int index() { return index_; } | 431 int index() { return index_; } |
| 432 const ZoneVector<uc16>* name() const { return name_; } |
| 433 void set_name(const ZoneVector<uc16>* name) { name_ = name; } |
| 430 static int StartRegister(int index) { return index * 2; } | 434 static int StartRegister(int index) { return index * 2; } |
| 431 static int EndRegister(int index) { return index * 2 + 1; } | 435 static int EndRegister(int index) { return index * 2 + 1; } |
| 432 | 436 |
| 433 private: | 437 private: |
| 434 RegExpTree* body_; | 438 RegExpTree* body_; |
| 435 int index_; | 439 int index_; |
| 440 const ZoneVector<uc16>* name_; |
| 436 }; | 441 }; |
| 437 | 442 |
| 438 | 443 |
| 439 class RegExpLookaround final : public RegExpTree { | 444 class RegExpLookaround final : public RegExpTree { |
| 440 public: | 445 public: |
| 441 enum Type { LOOKAHEAD, LOOKBEHIND }; | 446 enum Type { LOOKAHEAD, LOOKBEHIND }; |
| 442 | 447 |
| 443 RegExpLookaround(RegExpTree* body, bool is_positive, int capture_count, | 448 RegExpLookaround(RegExpTree* body, bool is_positive, int capture_count, |
| 444 int capture_from, Type type) | 449 int capture_from, Type type) |
| 445 : body_(body), | 450 : body_(body), |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 482 RegExpTree* body_; | 487 RegExpTree* body_; |
| 483 bool is_positive_; | 488 bool is_positive_; |
| 484 int capture_count_; | 489 int capture_count_; |
| 485 int capture_from_; | 490 int capture_from_; |
| 486 Type type_; | 491 Type type_; |
| 487 }; | 492 }; |
| 488 | 493 |
| 489 | 494 |
| 490 class RegExpBackReference final : public RegExpTree { | 495 class RegExpBackReference final : public RegExpTree { |
| 491 public: | 496 public: |
| 492 explicit RegExpBackReference(RegExpCapture* capture) : capture_(capture) {} | 497 RegExpBackReference() : capture_(nullptr), name_(nullptr) {} |
| 498 explicit RegExpBackReference(RegExpCapture* capture) |
| 499 : capture_(capture), name_(nullptr) {} |
| 493 void* Accept(RegExpVisitor* visitor, void* data) override; | 500 void* Accept(RegExpVisitor* visitor, void* data) override; |
| 494 RegExpNode* ToNode(RegExpCompiler* compiler, RegExpNode* on_success) override; | 501 RegExpNode* ToNode(RegExpCompiler* compiler, RegExpNode* on_success) override; |
| 495 RegExpBackReference* AsBackReference() override; | 502 RegExpBackReference* AsBackReference() override; |
| 496 bool IsBackReference() override; | 503 bool IsBackReference() override; |
| 497 int min_match() override { return 0; } | 504 int min_match() override { return 0; } |
| 498 // The back reference may be recursive, e.g. /(\2)(\1)/. To avoid infinite | 505 // The back reference may be recursive, e.g. /(\2)(\1)/. To avoid infinite |
| 499 // recursion, we give up. Ignorance is bliss. | 506 // recursion, we give up. Ignorance is bliss. |
| 500 int max_match() override { return kInfinity; } | 507 int max_match() override { return kInfinity; } |
| 501 int index() { return capture_->index(); } | 508 int index() { return capture_->index(); } |
| 502 RegExpCapture* capture() { return capture_; } | 509 RegExpCapture* capture() { return capture_; } |
| 510 void set_capture(RegExpCapture* capture) { capture_ = capture; } |
| 511 const ZoneVector<uc16>* name() const { return name_; } |
| 512 void set_name(const ZoneVector<uc16>* name) { name_ = name; } |
| 503 | 513 |
| 504 private: | 514 private: |
| 505 RegExpCapture* capture_; | 515 RegExpCapture* capture_; |
| 516 const ZoneVector<uc16>* name_; |
| 506 }; | 517 }; |
| 507 | 518 |
| 508 | 519 |
| 509 class RegExpEmpty final : public RegExpTree { | 520 class RegExpEmpty final : public RegExpTree { |
| 510 public: | 521 public: |
| 511 RegExpEmpty() {} | 522 RegExpEmpty() {} |
| 512 void* Accept(RegExpVisitor* visitor, void* data) override; | 523 void* Accept(RegExpVisitor* visitor, void* data) override; |
| 513 RegExpNode* ToNode(RegExpCompiler* compiler, RegExpNode* on_success) override; | 524 RegExpNode* ToNode(RegExpCompiler* compiler, RegExpNode* on_success) override; |
| 514 RegExpEmpty* AsEmpty() override; | 525 RegExpEmpty* AsEmpty() override; |
| 515 bool IsEmpty() override; | 526 bool IsEmpty() override; |
| 516 int min_match() override { return 0; } | 527 int min_match() override { return 0; } |
| 517 int max_match() override { return 0; } | 528 int max_match() override { return 0; } |
| 518 }; | 529 }; |
| 519 | 530 |
| 520 } // namespace internal | 531 } // namespace internal |
| 521 } // namespace v8 | 532 } // namespace v8 |
| 522 | 533 |
| 523 #endif // V8_REGEXP_REGEXP_AST_H_ | 534 #endif // V8_REGEXP_REGEXP_AST_H_ |
| OLD | NEW |