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 1505 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1516 | 1516 |
1517 | 1517 |
1518 class RegExpTree: public ZoneObject { | 1518 class RegExpTree: public ZoneObject { |
1519 public: | 1519 public: |
1520 static const int kInfinity = kMaxInt; | 1520 static const int kInfinity = kMaxInt; |
1521 virtual ~RegExpTree() { } | 1521 virtual ~RegExpTree() { } |
1522 virtual void* Accept(RegExpVisitor* visitor, void* data) = 0; | 1522 virtual void* Accept(RegExpVisitor* visitor, void* data) = 0; |
1523 virtual RegExpNode* ToNode(RegExpCompiler* compiler, | 1523 virtual RegExpNode* ToNode(RegExpCompiler* compiler, |
1524 RegExpNode* on_success) = 0; | 1524 RegExpNode* on_success) = 0; |
1525 virtual bool IsTextElement() { return false; } | 1525 virtual bool IsTextElement() { return false; } |
1526 virtual bool IsAnchored() { return false; } | 1526 virtual bool IsAnchoredAtStart() { return false; } |
| 1527 virtual bool IsAnchoredAtEnd() { return false; } |
1527 virtual int min_match() = 0; | 1528 virtual int min_match() = 0; |
1528 virtual int max_match() = 0; | 1529 virtual int max_match() = 0; |
1529 // Returns the interval of registers used for captures within this | 1530 // Returns the interval of registers used for captures within this |
1530 // expression. | 1531 // expression. |
1531 virtual Interval CaptureRegisters() { return Interval::Empty(); } | 1532 virtual Interval CaptureRegisters() { return Interval::Empty(); } |
1532 virtual void AppendToText(RegExpText* text); | 1533 virtual void AppendToText(RegExpText* text); |
1533 SmartPointer<const char> ToString(); | 1534 SmartPointer<const char> ToString(); |
1534 #define MAKE_ASTYPE(Name) \ | 1535 #define MAKE_ASTYPE(Name) \ |
1535 virtual RegExp##Name* As##Name(); \ | 1536 virtual RegExp##Name* As##Name(); \ |
1536 virtual bool Is##Name(); | 1537 virtual bool Is##Name(); |
1537 FOR_EACH_REG_EXP_TREE_TYPE(MAKE_ASTYPE) | 1538 FOR_EACH_REG_EXP_TREE_TYPE(MAKE_ASTYPE) |
1538 #undef MAKE_ASTYPE | 1539 #undef MAKE_ASTYPE |
1539 }; | 1540 }; |
1540 | 1541 |
1541 | 1542 |
1542 class RegExpDisjunction: public RegExpTree { | 1543 class RegExpDisjunction: public RegExpTree { |
1543 public: | 1544 public: |
1544 explicit RegExpDisjunction(ZoneList<RegExpTree*>* alternatives); | 1545 explicit RegExpDisjunction(ZoneList<RegExpTree*>* alternatives); |
1545 virtual void* Accept(RegExpVisitor* visitor, void* data); | 1546 virtual void* Accept(RegExpVisitor* visitor, void* data); |
1546 virtual RegExpNode* ToNode(RegExpCompiler* compiler, | 1547 virtual RegExpNode* ToNode(RegExpCompiler* compiler, |
1547 RegExpNode* on_success); | 1548 RegExpNode* on_success); |
1548 virtual RegExpDisjunction* AsDisjunction(); | 1549 virtual RegExpDisjunction* AsDisjunction(); |
1549 virtual Interval CaptureRegisters(); | 1550 virtual Interval CaptureRegisters(); |
1550 virtual bool IsDisjunction(); | 1551 virtual bool IsDisjunction(); |
1551 virtual bool IsAnchored(); | 1552 virtual bool IsAnchoredAtStart(); |
| 1553 virtual bool IsAnchoredAtEnd(); |
1552 virtual int min_match() { return min_match_; } | 1554 virtual int min_match() { return min_match_; } |
1553 virtual int max_match() { return max_match_; } | 1555 virtual int max_match() { return max_match_; } |
1554 ZoneList<RegExpTree*>* alternatives() { return alternatives_; } | 1556 ZoneList<RegExpTree*>* alternatives() { return alternatives_; } |
1555 private: | 1557 private: |
1556 ZoneList<RegExpTree*>* alternatives_; | 1558 ZoneList<RegExpTree*>* alternatives_; |
1557 int min_match_; | 1559 int min_match_; |
1558 int max_match_; | 1560 int max_match_; |
1559 }; | 1561 }; |
1560 | 1562 |
1561 | 1563 |
1562 class RegExpAlternative: public RegExpTree { | 1564 class RegExpAlternative: public RegExpTree { |
1563 public: | 1565 public: |
1564 explicit RegExpAlternative(ZoneList<RegExpTree*>* nodes); | 1566 explicit RegExpAlternative(ZoneList<RegExpTree*>* nodes); |
1565 virtual void* Accept(RegExpVisitor* visitor, void* data); | 1567 virtual void* Accept(RegExpVisitor* visitor, void* data); |
1566 virtual RegExpNode* ToNode(RegExpCompiler* compiler, | 1568 virtual RegExpNode* ToNode(RegExpCompiler* compiler, |
1567 RegExpNode* on_success); | 1569 RegExpNode* on_success); |
1568 virtual RegExpAlternative* AsAlternative(); | 1570 virtual RegExpAlternative* AsAlternative(); |
1569 virtual Interval CaptureRegisters(); | 1571 virtual Interval CaptureRegisters(); |
1570 virtual bool IsAlternative(); | 1572 virtual bool IsAlternative(); |
1571 virtual bool IsAnchored(); | 1573 virtual bool IsAnchoredAtStart(); |
| 1574 virtual bool IsAnchoredAtEnd(); |
1572 virtual int min_match() { return min_match_; } | 1575 virtual int min_match() { return min_match_; } |
1573 virtual int max_match() { return max_match_; } | 1576 virtual int max_match() { return max_match_; } |
1574 ZoneList<RegExpTree*>* nodes() { return nodes_; } | 1577 ZoneList<RegExpTree*>* nodes() { return nodes_; } |
1575 private: | 1578 private: |
1576 ZoneList<RegExpTree*>* nodes_; | 1579 ZoneList<RegExpTree*>* nodes_; |
1577 int min_match_; | 1580 int min_match_; |
1578 int max_match_; | 1581 int max_match_; |
1579 }; | 1582 }; |
1580 | 1583 |
1581 | 1584 |
1582 class RegExpAssertion: public RegExpTree { | 1585 class RegExpAssertion: public RegExpTree { |
1583 public: | 1586 public: |
1584 enum Type { | 1587 enum Type { |
1585 START_OF_LINE, | 1588 START_OF_LINE, |
1586 START_OF_INPUT, | 1589 START_OF_INPUT, |
1587 END_OF_LINE, | 1590 END_OF_LINE, |
1588 END_OF_INPUT, | 1591 END_OF_INPUT, |
1589 BOUNDARY, | 1592 BOUNDARY, |
1590 NON_BOUNDARY | 1593 NON_BOUNDARY |
1591 }; | 1594 }; |
1592 explicit RegExpAssertion(Type type) : type_(type) { } | 1595 explicit RegExpAssertion(Type type) : type_(type) { } |
1593 virtual void* Accept(RegExpVisitor* visitor, void* data); | 1596 virtual void* Accept(RegExpVisitor* visitor, void* data); |
1594 virtual RegExpNode* ToNode(RegExpCompiler* compiler, | 1597 virtual RegExpNode* ToNode(RegExpCompiler* compiler, |
1595 RegExpNode* on_success); | 1598 RegExpNode* on_success); |
1596 virtual RegExpAssertion* AsAssertion(); | 1599 virtual RegExpAssertion* AsAssertion(); |
1597 virtual bool IsAssertion(); | 1600 virtual bool IsAssertion(); |
1598 virtual bool IsAnchored(); | 1601 virtual bool IsAnchoredAtStart(); |
| 1602 virtual bool IsAnchoredAtEnd(); |
1599 virtual int min_match() { return 0; } | 1603 virtual int min_match() { return 0; } |
1600 virtual int max_match() { return 0; } | 1604 virtual int max_match() { return 0; } |
1601 Type type() { return type_; } | 1605 Type type() { return type_; } |
1602 private: | 1606 private: |
1603 Type type_; | 1607 Type type_; |
1604 }; | 1608 }; |
1605 | 1609 |
1606 | 1610 |
1607 class CharacterSet BASE_EMBEDDED { | 1611 class CharacterSet BASE_EMBEDDED { |
1608 public: | 1612 public: |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1761 explicit RegExpCapture(RegExpTree* body, int index) | 1765 explicit RegExpCapture(RegExpTree* body, int index) |
1762 : body_(body), index_(index) { } | 1766 : body_(body), index_(index) { } |
1763 virtual void* Accept(RegExpVisitor* visitor, void* data); | 1767 virtual void* Accept(RegExpVisitor* visitor, void* data); |
1764 virtual RegExpNode* ToNode(RegExpCompiler* compiler, | 1768 virtual RegExpNode* ToNode(RegExpCompiler* compiler, |
1765 RegExpNode* on_success); | 1769 RegExpNode* on_success); |
1766 static RegExpNode* ToNode(RegExpTree* body, | 1770 static RegExpNode* ToNode(RegExpTree* body, |
1767 int index, | 1771 int index, |
1768 RegExpCompiler* compiler, | 1772 RegExpCompiler* compiler, |
1769 RegExpNode* on_success); | 1773 RegExpNode* on_success); |
1770 virtual RegExpCapture* AsCapture(); | 1774 virtual RegExpCapture* AsCapture(); |
1771 virtual bool IsAnchored(); | 1775 virtual bool IsAnchoredAtStart(); |
| 1776 virtual bool IsAnchoredAtEnd(); |
1772 virtual Interval CaptureRegisters(); | 1777 virtual Interval CaptureRegisters(); |
1773 virtual bool IsCapture(); | 1778 virtual bool IsCapture(); |
1774 virtual int min_match() { return body_->min_match(); } | 1779 virtual int min_match() { return body_->min_match(); } |
1775 virtual int max_match() { return body_->max_match(); } | 1780 virtual int max_match() { return body_->max_match(); } |
1776 RegExpTree* body() { return body_; } | 1781 RegExpTree* body() { return body_; } |
1777 int index() { return index_; } | 1782 int index() { return index_; } |
1778 static int StartRegister(int index) { return index * 2; } | 1783 static int StartRegister(int index) { return index * 2; } |
1779 static int EndRegister(int index) { return index * 2 + 1; } | 1784 static int EndRegister(int index) { return index * 2 + 1; } |
1780 private: | 1785 private: |
1781 RegExpTree* body_; | 1786 RegExpTree* body_; |
(...skipping 11 matching lines...) Expand all Loading... |
1793 is_positive_(is_positive), | 1798 is_positive_(is_positive), |
1794 capture_count_(capture_count), | 1799 capture_count_(capture_count), |
1795 capture_from_(capture_from) { } | 1800 capture_from_(capture_from) { } |
1796 | 1801 |
1797 virtual void* Accept(RegExpVisitor* visitor, void* data); | 1802 virtual void* Accept(RegExpVisitor* visitor, void* data); |
1798 virtual RegExpNode* ToNode(RegExpCompiler* compiler, | 1803 virtual RegExpNode* ToNode(RegExpCompiler* compiler, |
1799 RegExpNode* on_success); | 1804 RegExpNode* on_success); |
1800 virtual RegExpLookahead* AsLookahead(); | 1805 virtual RegExpLookahead* AsLookahead(); |
1801 virtual Interval CaptureRegisters(); | 1806 virtual Interval CaptureRegisters(); |
1802 virtual bool IsLookahead(); | 1807 virtual bool IsLookahead(); |
1803 virtual bool IsAnchored(); | 1808 virtual bool IsAnchoredAtStart(); |
1804 virtual int min_match() { return 0; } | 1809 virtual int min_match() { return 0; } |
1805 virtual int max_match() { return 0; } | 1810 virtual int max_match() { return 0; } |
1806 RegExpTree* body() { return body_; } | 1811 RegExpTree* body() { return body_; } |
1807 bool is_positive() { return is_positive_; } | 1812 bool is_positive() { return is_positive_; } |
1808 int capture_count() { return capture_count_; } | 1813 int capture_count() { return capture_count_; } |
1809 int capture_from() { return capture_from_; } | 1814 int capture_from() { return capture_from_; } |
1810 private: | 1815 private: |
1811 RegExpTree* body_; | 1816 RegExpTree* body_; |
1812 bool is_positive_; | 1817 bool is_positive_; |
1813 int capture_count_; | 1818 int capture_count_; |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1881 AST_NODE_LIST(DEF_VISIT) | 1886 AST_NODE_LIST(DEF_VISIT) |
1882 #undef DEF_VISIT | 1887 #undef DEF_VISIT |
1883 | 1888 |
1884 private: | 1889 private: |
1885 bool stack_overflow_; | 1890 bool stack_overflow_; |
1886 }; | 1891 }; |
1887 | 1892 |
1888 } } // namespace v8::internal | 1893 } } // namespace v8::internal |
1889 | 1894 |
1890 #endif // V8_AST_H_ | 1895 #endif // V8_AST_H_ |
OLD | NEW |