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

Side by Side Diff: src/ast.h

Issue 7193007: Refix issue 1472. The previous fix worked for the example in the bug (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: '' Created 9 years, 6 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | src/ast.cc » ('j') | src/jsregexp.cc » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2011 the V8 project authors. All rights reserved. 1 // Copyright 2011 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 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
203 // code generation. 203 // code generation.
204 kUninitialized, 204 kUninitialized,
205 // Evaluated for its side effects. 205 // Evaluated for its side effects.
206 kEffect, 206 kEffect,
207 // Evaluated for its value (and side effects). 207 // Evaluated for its value (and side effects).
208 kValue, 208 kValue,
209 // Evaluated for control flow (and side effects). 209 // Evaluated for control flow (and side effects).
210 kTest 210 kTest
211 }; 211 };
212 212
213 Expression() : id_(GetNextId()), test_id_(GetNextId()) {} 213 Expression() : id_(GetNextId()), test_id_(GetNextId()) {}
Lasse Reichstein 2011/06/17 07:18:49 What's the test_id for?
Erik Corry 2011/06/17 07:31:14 Don't know.
214 214
215 virtual int position() const { 215 virtual int position() const {
216 UNREACHABLE(); 216 UNREACHABLE();
217 return 0; 217 return 0;
218 } 218 }
219 219
220 virtual Expression* AsExpression() { return this; } 220 virtual Expression* AsExpression() { return this; }
221 221
222 virtual bool IsTrivial() { return false; } 222 virtual bool IsTrivial() { return false; }
223 virtual bool IsValidLeftHandSide() { return false; } 223 virtual bool IsValidLeftHandSide() { return false; }
(...skipping 1520 matching lines...) Expand 10 before | Expand all | Expand 10 after
1744 #define MAKE_CASE(Name) \ 1744 #define MAKE_CASE(Name) \
1745 virtual void* Visit##Name(RegExp##Name*, void* data) = 0; 1745 virtual void* Visit##Name(RegExp##Name*, void* data) = 0;
1746 FOR_EACH_REG_EXP_TREE_TYPE(MAKE_CASE) 1746 FOR_EACH_REG_EXP_TREE_TYPE(MAKE_CASE)
1747 #undef MAKE_CASE 1747 #undef MAKE_CASE
1748 }; 1748 };
1749 1749
1750 1750
1751 class RegExpTree: public ZoneObject { 1751 class RegExpTree: public ZoneObject {
1752 public: 1752 public:
1753 static const int kInfinity = kMaxInt; 1753 static const int kInfinity = kMaxInt;
1754 RegExpTree() : contains_expanded_quantifier_(false) { }
1755 virtual ~RegExpTree() { } 1754 virtual ~RegExpTree() { }
1756 virtual void* Accept(RegExpVisitor* visitor, void* data) = 0; 1755 virtual void* Accept(RegExpVisitor* visitor, void* data) = 0;
1757 virtual RegExpNode* ToNode(RegExpCompiler* compiler, 1756 virtual RegExpNode* ToNode(RegExpCompiler* compiler,
1758 RegExpNode* on_success) = 0; 1757 RegExpNode* on_success) = 0;
1759 virtual bool IsTextElement() { return false; } 1758 virtual bool IsTextElement() { return false; }
1760 virtual bool IsAnchoredAtStart() { return false; } 1759 virtual bool IsAnchoredAtStart() { return false; }
1761 virtual bool IsAnchoredAtEnd() { return false; } 1760 virtual bool IsAnchoredAtEnd() { return false; }
1762 virtual int min_match() = 0; 1761 virtual int min_match() = 0;
1763 virtual int max_match() = 0; 1762 virtual int max_match() = 0;
1764 virtual bool ContainsExpandedQuantifier() {
1765 return contains_expanded_quantifier_;
1766 }
1767 void set_contains_expanded_quantifier(bool value) {
1768 contains_expanded_quantifier_ = value;
1769 }
1770 // Returns the interval of registers used for captures within this 1763 // Returns the interval of registers used for captures within this
1771 // expression. 1764 // expression.
1772 virtual Interval CaptureRegisters() { return Interval::Empty(); } 1765 virtual Interval CaptureRegisters() { return Interval::Empty(); }
1773 virtual void AppendToText(RegExpText* text); 1766 virtual void AppendToText(RegExpText* text);
1774 SmartPointer<const char> ToString(); 1767 SmartPointer<const char> ToString();
1775 #define MAKE_ASTYPE(Name) \ 1768 #define MAKE_ASTYPE(Name) \
1776 virtual RegExp##Name* As##Name(); \ 1769 virtual RegExp##Name* As##Name(); \
1777 virtual bool Is##Name(); 1770 virtual bool Is##Name();
1778 FOR_EACH_REG_EXP_TREE_TYPE(MAKE_ASTYPE) 1771 FOR_EACH_REG_EXP_TREE_TYPE(MAKE_ASTYPE)
1779 #undef MAKE_ASTYPE 1772 #undef MAKE_ASTYPE
1780
1781 protected:
1782 bool contains_expanded_quantifier_;
1783 }; 1773 };
1784 1774
1785 1775
1786 class RegExpDisjunction: public RegExpTree { 1776 class RegExpDisjunction: public RegExpTree {
1787 public: 1777 public:
1788 explicit RegExpDisjunction(ZoneList<RegExpTree*>* alternatives); 1778 explicit RegExpDisjunction(ZoneList<RegExpTree*>* alternatives);
1789 virtual void* Accept(RegExpVisitor* visitor, void* data); 1779 virtual void* Accept(RegExpVisitor* visitor, void* data);
1790 virtual RegExpNode* ToNode(RegExpCompiler* compiler, 1780 virtual RegExpNode* ToNode(RegExpCompiler* compiler,
1791 RegExpNode* on_success); 1781 RegExpNode* on_success);
1792 virtual RegExpDisjunction* AsDisjunction(); 1782 virtual RegExpDisjunction* AsDisjunction();
1793 virtual Interval CaptureRegisters(); 1783 virtual Interval CaptureRegisters();
1794 virtual bool IsDisjunction(); 1784 virtual bool IsDisjunction();
1795 virtual bool IsAnchoredAtStart(); 1785 virtual bool IsAnchoredAtStart();
1796 virtual bool IsAnchoredAtEnd(); 1786 virtual bool IsAnchoredAtEnd();
1797 virtual int min_match() { return min_match_; } 1787 virtual int min_match() { return min_match_; }
1798 virtual int max_match() { return max_match_; } 1788 virtual int max_match() { return max_match_; }
1799 virtual bool ContainsExpandedQuantifier();
1800 ZoneList<RegExpTree*>* alternatives() { return alternatives_; } 1789 ZoneList<RegExpTree*>* alternatives() { return alternatives_; }
1801 private: 1790 private:
1802 ZoneList<RegExpTree*>* alternatives_; 1791 ZoneList<RegExpTree*>* alternatives_;
1803 int min_match_; 1792 int min_match_;
1804 int max_match_; 1793 int max_match_;
1805 }; 1794 };
1806 1795
1807 1796
1808 class RegExpAlternative: public RegExpTree { 1797 class RegExpAlternative: public RegExpTree {
1809 public: 1798 public:
1810 explicit RegExpAlternative(ZoneList<RegExpTree*>* nodes); 1799 explicit RegExpAlternative(ZoneList<RegExpTree*>* nodes);
1811 virtual void* Accept(RegExpVisitor* visitor, void* data); 1800 virtual void* Accept(RegExpVisitor* visitor, void* data);
1812 virtual RegExpNode* ToNode(RegExpCompiler* compiler, 1801 virtual RegExpNode* ToNode(RegExpCompiler* compiler,
1813 RegExpNode* on_success); 1802 RegExpNode* on_success);
1814 virtual RegExpAlternative* AsAlternative(); 1803 virtual RegExpAlternative* AsAlternative();
1815 virtual Interval CaptureRegisters(); 1804 virtual Interval CaptureRegisters();
1816 virtual bool IsAlternative(); 1805 virtual bool IsAlternative();
1817 virtual bool IsAnchoredAtStart(); 1806 virtual bool IsAnchoredAtStart();
1818 virtual bool IsAnchoredAtEnd(); 1807 virtual bool IsAnchoredAtEnd();
1819 virtual int min_match() { return min_match_; } 1808 virtual int min_match() { return min_match_; }
1820 virtual int max_match() { return max_match_; } 1809 virtual int max_match() { return max_match_; }
1821 virtual bool ContainsExpandedQuantifier();
1822 ZoneList<RegExpTree*>* nodes() { return nodes_; } 1810 ZoneList<RegExpTree*>* nodes() { return nodes_; }
1823 private: 1811 private:
1824 ZoneList<RegExpTree*>* nodes_; 1812 ZoneList<RegExpTree*>* nodes_;
1825 int min_match_; 1813 int min_match_;
1826 int max_match_; 1814 int max_match_;
1827 }; 1815 };
1828 1816
1829 1817
1830 class RegExpAssertion: public RegExpTree { 1818 class RegExpAssertion: public RegExpTree {
1831 public: 1819 public:
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
1961 1949
1962 1950
1963 class RegExpQuantifier: public RegExpTree { 1951 class RegExpQuantifier: public RegExpTree {
1964 public: 1952 public:
1965 enum Type { GREEDY, NON_GREEDY, POSSESSIVE }; 1953 enum Type { GREEDY, NON_GREEDY, POSSESSIVE };
1966 RegExpQuantifier(int min, int max, Type type, RegExpTree* body) 1954 RegExpQuantifier(int min, int max, Type type, RegExpTree* body)
1967 : body_(body), 1955 : body_(body),
1968 min_(min), 1956 min_(min),
1969 max_(max), 1957 max_(max),
1970 min_match_(min * body->min_match()), 1958 min_match_(min * body->min_match()),
1971 type_(type), 1959 type_(type) {
1972 contains_expanded_quantifier_(false) {
1973 if (max > 0 && body->max_match() > kInfinity / max) { 1960 if (max > 0 && body->max_match() > kInfinity / max) {
1974 max_match_ = kInfinity; 1961 max_match_ = kInfinity;
1975 } else { 1962 } else {
1976 max_match_ = max * body->max_match(); 1963 max_match_ = max * body->max_match();
1977 } 1964 }
1978 } 1965 }
1979 virtual void* Accept(RegExpVisitor* visitor, void* data); 1966 virtual void* Accept(RegExpVisitor* visitor, void* data);
1980 virtual RegExpNode* ToNode(RegExpCompiler* compiler, 1967 virtual RegExpNode* ToNode(RegExpCompiler* compiler,
1981 RegExpNode* on_success); 1968 RegExpNode* on_success);
1982 static RegExpNode* ToNode(int min, 1969 static RegExpNode* ToNode(int min,
1983 int max, 1970 int max,
1984 bool is_greedy, 1971 bool is_greedy,
1985 RegExpTree* body, 1972 RegExpTree* body,
1986 RegExpCompiler* compiler, 1973 RegExpCompiler* compiler,
1987 RegExpNode* on_success, 1974 RegExpNode* on_success,
1988 bool not_at_start = false); 1975 bool not_at_start = false);
1989 virtual RegExpQuantifier* AsQuantifier(); 1976 virtual RegExpQuantifier* AsQuantifier();
1990 virtual Interval CaptureRegisters(); 1977 virtual Interval CaptureRegisters();
1991 virtual bool IsQuantifier(); 1978 virtual bool IsQuantifier();
1992 virtual int min_match() { return min_match_; } 1979 virtual int min_match() { return min_match_; }
1993 virtual int max_match() { return max_match_; } 1980 virtual int max_match() { return max_match_; }
1994 virtual bool ContainsExpandedQuantifier() {
1995 return contains_expanded_quantifier_ || body_->ContainsExpandedQuantifier();
1996 }
1997 int min() { return min_; } 1981 int min() { return min_; }
1998 int max() { return max_; } 1982 int max() { return max_; }
1999 bool is_possessive() { return type_ == POSSESSIVE; } 1983 bool is_possessive() { return type_ == POSSESSIVE; }
2000 bool is_non_greedy() { return type_ == NON_GREEDY; } 1984 bool is_non_greedy() { return type_ == NON_GREEDY; }
2001 bool is_greedy() { return type_ == GREEDY; } 1985 bool is_greedy() { return type_ == GREEDY; }
2002 RegExpTree* body() { return body_; } 1986 RegExpTree* body() { return body_; }
2003 1987
2004 private: 1988 private:
2005 RegExpTree* body_; 1989 RegExpTree* body_;
2006 int min_; 1990 int min_;
2007 int max_; 1991 int max_;
2008 int min_match_; 1992 int min_match_;
2009 int max_match_; 1993 int max_match_;
2010 Type type_; 1994 Type type_;
2011 bool contains_expanded_quantifier_;
2012 }; 1995 };
2013 1996
2014 1997
2015 class RegExpCapture: public RegExpTree { 1998 class RegExpCapture: public RegExpTree {
2016 public: 1999 public:
2017 explicit RegExpCapture(RegExpTree* body, int index) 2000 explicit RegExpCapture(RegExpTree* body, int index)
2018 : body_(body), index_(index) { } 2001 : body_(body), index_(index) { }
2019 virtual void* Accept(RegExpVisitor* visitor, void* data); 2002 virtual void* Accept(RegExpVisitor* visitor, void* data);
2020 virtual RegExpNode* ToNode(RegExpCompiler* compiler, 2003 virtual RegExpNode* ToNode(RegExpCompiler* compiler,
2021 RegExpNode* on_success); 2004 RegExpNode* on_success);
2022 static RegExpNode* ToNode(RegExpTree* body, 2005 static RegExpNode* ToNode(RegExpTree* body,
2023 int index, 2006 int index,
2024 RegExpCompiler* compiler, 2007 RegExpCompiler* compiler,
2025 RegExpNode* on_success); 2008 RegExpNode* on_success);
2026 virtual RegExpCapture* AsCapture(); 2009 virtual RegExpCapture* AsCapture();
2027 virtual bool IsAnchoredAtStart(); 2010 virtual bool IsAnchoredAtStart();
2028 virtual bool IsAnchoredAtEnd(); 2011 virtual bool IsAnchoredAtEnd();
2029 virtual Interval CaptureRegisters(); 2012 virtual Interval CaptureRegisters();
2030 virtual bool IsCapture(); 2013 virtual bool IsCapture();
2031 virtual int min_match() { return body_->min_match(); } 2014 virtual int min_match() { return body_->min_match(); }
2032 virtual int max_match() { return body_->max_match(); } 2015 virtual int max_match() { return body_->max_match(); }
2033 virtual bool ContainsExpandedQuantifier() {
2034 return contains_expanded_quantifier_ || body_->ContainsExpandedQuantifier();
2035 }
2036 RegExpTree* body() { return body_; } 2016 RegExpTree* body() { return body_; }
2037 int index() { return index_; } 2017 int index() { return index_; }
2038 static int StartRegister(int index) { return index * 2; } 2018 static int StartRegister(int index) { return index * 2; }
2039 static int EndRegister(int index) { return index * 2 + 1; } 2019 static int EndRegister(int index) { return index * 2 + 1; }
2040 2020
2041 private: 2021 private:
2042 RegExpTree* body_; 2022 RegExpTree* body_;
2043 int index_; 2023 int index_;
2044 }; 2024 };
2045 2025
(...skipping 11 matching lines...) Expand all
2057 2037
2058 virtual void* Accept(RegExpVisitor* visitor, void* data); 2038 virtual void* Accept(RegExpVisitor* visitor, void* data);
2059 virtual RegExpNode* ToNode(RegExpCompiler* compiler, 2039 virtual RegExpNode* ToNode(RegExpCompiler* compiler,
2060 RegExpNode* on_success); 2040 RegExpNode* on_success);
2061 virtual RegExpLookahead* AsLookahead(); 2041 virtual RegExpLookahead* AsLookahead();
2062 virtual Interval CaptureRegisters(); 2042 virtual Interval CaptureRegisters();
2063 virtual bool IsLookahead(); 2043 virtual bool IsLookahead();
2064 virtual bool IsAnchoredAtStart(); 2044 virtual bool IsAnchoredAtStart();
2065 virtual int min_match() { return 0; } 2045 virtual int min_match() { return 0; }
2066 virtual int max_match() { return 0; } 2046 virtual int max_match() { return 0; }
2067 virtual bool ContainsExpandedQuantifier() {
2068 return contains_expanded_quantifier_ || body_->ContainsExpandedQuantifier();
2069 }
2070 RegExpTree* body() { return body_; } 2047 RegExpTree* body() { return body_; }
2071 bool is_positive() { return is_positive_; } 2048 bool is_positive() { return is_positive_; }
2072 int capture_count() { return capture_count_; } 2049 int capture_count() { return capture_count_; }
2073 int capture_from() { return capture_from_; } 2050 int capture_from() { return capture_from_; }
2074 2051
2075 private: 2052 private:
2076 RegExpTree* body_; 2053 RegExpTree* body_;
2077 bool is_positive_; 2054 bool is_positive_;
2078 int capture_count_; 2055 int capture_count_;
2079 int capture_from_; 2056 int capture_from_;
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
2155 2132
2156 private: 2133 private:
2157 Isolate* isolate_; 2134 Isolate* isolate_;
2158 bool stack_overflow_; 2135 bool stack_overflow_;
2159 }; 2136 };
2160 2137
2161 2138
2162 } } // namespace v8::internal 2139 } } // namespace v8::internal
2163 2140
2164 #endif // V8_AST_H_ 2141 #endif // V8_AST_H_
OLDNEW
« no previous file with comments | « no previous file | src/ast.cc » ('j') | src/jsregexp.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698