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

Side by Side Diff: src/ast.h

Issue 1418963009: Experimental support for RegExp lookbehind. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: fixed test cases Created 5 years, 1 month 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 | « no previous file | src/ast.cc » ('j') | src/regexp/jsregexp.cc » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 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_AST_H_ 5 #ifndef V8_AST_H_
6 #define V8_AST_H_ 6 #define V8_AST_H_
7 7
8 #include "src/assembler.h" 8 #include "src/assembler.h"
9 #include "src/ast-value-factory.h" 9 #include "src/ast-value-factory.h"
10 #include "src/bailout-reason.h" 10 #include "src/bailout-reason.h"
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 112
113 class RegExpAlternative; 113 class RegExpAlternative;
114 class RegExpAssertion; 114 class RegExpAssertion;
115 class RegExpAtom; 115 class RegExpAtom;
116 class RegExpBackReference; 116 class RegExpBackReference;
117 class RegExpCapture; 117 class RegExpCapture;
118 class RegExpCharacterClass; 118 class RegExpCharacterClass;
119 class RegExpCompiler; 119 class RegExpCompiler;
120 class RegExpDisjunction; 120 class RegExpDisjunction;
121 class RegExpEmpty; 121 class RegExpEmpty;
122 class RegExpLookahead; 122 class RegExpLookaround;
123 class RegExpQuantifier; 123 class RegExpQuantifier;
124 class RegExpText; 124 class RegExpText;
125 125
126 #define DEF_FORWARD_DECLARATION(type) class type; 126 #define DEF_FORWARD_DECLARATION(type) class type;
127 AST_NODE_LIST(DEF_FORWARD_DECLARATION) 127 AST_NODE_LIST(DEF_FORWARD_DECLARATION)
128 #undef DEF_FORWARD_DECLARATION 128 #undef DEF_FORWARD_DECLARATION
129 129
130 130
131 // Typedef only introduced to avoid unreadable code. 131 // Typedef only introduced to avoid unreadable code.
132 typedef ZoneList<Handle<String>> ZoneStringList; 132 typedef ZoneList<Handle<String>> ZoneStringList;
(...skipping 2692 matching lines...) Expand 10 before | Expand all | Expand 10 after
2825 virtual ~RegExpVisitor() { } 2825 virtual ~RegExpVisitor() { }
2826 #define MAKE_CASE(Name) \ 2826 #define MAKE_CASE(Name) \
2827 virtual void* Visit##Name(RegExp##Name*, void* data) = 0; 2827 virtual void* Visit##Name(RegExp##Name*, void* data) = 0;
2828 FOR_EACH_REG_EXP_TREE_TYPE(MAKE_CASE) 2828 FOR_EACH_REG_EXP_TREE_TYPE(MAKE_CASE)
2829 #undef MAKE_CASE 2829 #undef MAKE_CASE
2830 }; 2830 };
2831 2831
2832 2832
2833 class RegExpTree : public ZoneObject { 2833 class RegExpTree : public ZoneObject {
2834 public: 2834 public:
2835 enum ReadDirection { READ_FORWARD, READ_BACKWARD };
2836
2835 static const int kInfinity = kMaxInt; 2837 static const int kInfinity = kMaxInt;
2838 explicit RegExpTree(ReadDirection read_direction)
2839 : read_direction_(read_direction) {}
2836 virtual ~RegExpTree() {} 2840 virtual ~RegExpTree() {}
2837 virtual void* Accept(RegExpVisitor* visitor, void* data) = 0; 2841 virtual void* Accept(RegExpVisitor* visitor, void* data) = 0;
2838 virtual RegExpNode* ToNode(RegExpCompiler* compiler, 2842 virtual RegExpNode* ToNode(RegExpCompiler* compiler,
2839 RegExpNode* on_success) = 0; 2843 RegExpNode* on_success) = 0;
2840 virtual bool IsTextElement() { return false; } 2844 virtual bool IsTextElement() { return false; }
2841 virtual bool IsAnchoredAtStart() { return false; } 2845 virtual bool IsAnchoredAtStart() { return false; }
2842 virtual bool IsAnchoredAtEnd() { return false; } 2846 virtual bool IsAnchoredAtEnd() { return false; }
2843 virtual int min_match() = 0; 2847 virtual int min_match() = 0;
2844 virtual int max_match() = 0; 2848 virtual int max_match() = 0;
2845 // Returns the interval of registers used for captures within this 2849 // Returns the interval of registers used for captures within this
2846 // expression. 2850 // expression.
2847 virtual Interval CaptureRegisters() { return Interval::Empty(); } 2851 virtual Interval CaptureRegisters() { return Interval::Empty(); }
2848 virtual void AppendToText(RegExpText* text, Zone* zone); 2852 virtual void AppendToText(RegExpText* text, Zone* zone);
2849 std::ostream& Print(std::ostream& os, Zone* zone); // NOLINT 2853 std::ostream& Print(std::ostream& os, Zone* zone); // NOLINT
2850 #define MAKE_ASTYPE(Name) \ 2854 #define MAKE_ASTYPE(Name) \
2851 virtual RegExp##Name* As##Name(); \ 2855 virtual RegExp##Name* As##Name(); \
2852 virtual bool Is##Name(); 2856 virtual bool Is##Name();
2853 FOR_EACH_REG_EXP_TREE_TYPE(MAKE_ASTYPE) 2857 FOR_EACH_REG_EXP_TREE_TYPE(MAKE_ASTYPE)
2854 #undef MAKE_ASTYPE 2858 #undef MAKE_ASTYPE
2859
2860 ReadDirection read_direction() const { return read_direction_; }
2861 bool read_backward() const { return read_direction_ == READ_BACKWARD; }
2862
2863 protected:
2864 ReadDirection read_direction_;
2855 }; 2865 };
2856 2866
2857 2867
2858 class RegExpDisjunction final : public RegExpTree { 2868 class RegExpDisjunction final : public RegExpTree {
2859 public: 2869 public:
2860 explicit RegExpDisjunction(ZoneList<RegExpTree*>* alternatives); 2870 RegExpDisjunction(ZoneList<RegExpTree*>* alternatives,
2871 ReadDirection read_direction);
2861 void* Accept(RegExpVisitor* visitor, void* data) override; 2872 void* Accept(RegExpVisitor* visitor, void* data) override;
2862 RegExpNode* ToNode(RegExpCompiler* compiler, RegExpNode* on_success) override; 2873 RegExpNode* ToNode(RegExpCompiler* compiler, RegExpNode* on_success) override;
2863 RegExpDisjunction* AsDisjunction() override; 2874 RegExpDisjunction* AsDisjunction() override;
2864 Interval CaptureRegisters() override; 2875 Interval CaptureRegisters() override;
2865 bool IsDisjunction() override; 2876 bool IsDisjunction() override;
2866 bool IsAnchoredAtStart() override; 2877 bool IsAnchoredAtStart() override;
2867 bool IsAnchoredAtEnd() override; 2878 bool IsAnchoredAtEnd() override;
2868 int min_match() override { return min_match_; } 2879 int min_match() override { return min_match_; }
2869 int max_match() override { return max_match_; } 2880 int max_match() override { return max_match_; }
2870 ZoneList<RegExpTree*>* alternatives() { return alternatives_; } 2881 ZoneList<RegExpTree*>* alternatives() { return alternatives_; }
2871 private: 2882 private:
2872 bool SortConsecutiveAtoms(RegExpCompiler* compiler); 2883 bool SortConsecutiveAtoms(RegExpCompiler* compiler);
2873 void RationalizeConsecutiveAtoms(RegExpCompiler* compiler); 2884 void RationalizeConsecutiveAtoms(RegExpCompiler* compiler);
2874 void FixSingleCharacterDisjunctions(RegExpCompiler* compiler); 2885 void FixSingleCharacterDisjunctions(RegExpCompiler* compiler);
2875 ZoneList<RegExpTree*>* alternatives_; 2886 ZoneList<RegExpTree*>* alternatives_;
2876 int min_match_; 2887 int min_match_;
2877 int max_match_; 2888 int max_match_;
2878 }; 2889 };
2879 2890
2880 2891
2881 class RegExpAlternative final : public RegExpTree { 2892 class RegExpAlternative final : public RegExpTree {
2882 public: 2893 public:
2883 explicit RegExpAlternative(ZoneList<RegExpTree*>* nodes); 2894 RegExpAlternative(ZoneList<RegExpTree*>* nodes, ReadDirection read_direction);
2884 void* Accept(RegExpVisitor* visitor, void* data) override; 2895 void* Accept(RegExpVisitor* visitor, void* data) override;
2885 RegExpNode* ToNode(RegExpCompiler* compiler, RegExpNode* on_success) override; 2896 RegExpNode* ToNode(RegExpCompiler* compiler, RegExpNode* on_success) override;
2886 RegExpAlternative* AsAlternative() override; 2897 RegExpAlternative* AsAlternative() override;
2887 Interval CaptureRegisters() override; 2898 Interval CaptureRegisters() override;
2888 bool IsAlternative() override; 2899 bool IsAlternative() override;
2889 bool IsAnchoredAtStart() override; 2900 bool IsAnchoredAtStart() override;
2890 bool IsAnchoredAtEnd() override; 2901 bool IsAnchoredAtEnd() override;
2891 int min_match() override { return min_match_; } 2902 int min_match() override { return min_match_; }
2892 int max_match() override { return max_match_; } 2903 int max_match() override { return max_match_; }
2893 ZoneList<RegExpTree*>* nodes() { return nodes_; } 2904 ZoneList<RegExpTree*>* nodes() { return nodes_; }
2894 private: 2905 private:
2895 ZoneList<RegExpTree*>* nodes_; 2906 ZoneList<RegExpTree*>* nodes_;
2896 int min_match_; 2907 int min_match_;
2897 int max_match_; 2908 int max_match_;
2898 }; 2909 };
2899 2910
2900 2911
2901 class RegExpAssertion final : public RegExpTree { 2912 class RegExpAssertion final : public RegExpTree {
2902 public: 2913 public:
2903 enum AssertionType { 2914 enum AssertionType {
2904 START_OF_LINE, 2915 START_OF_LINE,
2905 START_OF_INPUT, 2916 START_OF_INPUT,
2906 END_OF_LINE, 2917 END_OF_LINE,
2907 END_OF_INPUT, 2918 END_OF_INPUT,
2908 BOUNDARY, 2919 BOUNDARY,
2909 NON_BOUNDARY 2920 NON_BOUNDARY
2910 }; 2921 };
2911 explicit RegExpAssertion(AssertionType type) : assertion_type_(type) { } 2922 RegExpAssertion(AssertionType type, ReadDirection read_direction)
2923 : RegExpTree(read_direction), assertion_type_(type) {}
2912 void* Accept(RegExpVisitor* visitor, void* data) override; 2924 void* Accept(RegExpVisitor* visitor, void* data) override;
2913 RegExpNode* ToNode(RegExpCompiler* compiler, RegExpNode* on_success) override; 2925 RegExpNode* ToNode(RegExpCompiler* compiler, RegExpNode* on_success) override;
2914 RegExpAssertion* AsAssertion() override; 2926 RegExpAssertion* AsAssertion() override;
2915 bool IsAssertion() override; 2927 bool IsAssertion() override;
2916 bool IsAnchoredAtStart() override; 2928 bool IsAnchoredAtStart() override;
2917 bool IsAnchoredAtEnd() override; 2929 bool IsAnchoredAtEnd() override;
2918 int min_match() override { return 0; } 2930 int min_match() override { return 0; }
2919 int max_match() override { return 0; } 2931 int max_match() override { return 0; }
2920 AssertionType assertion_type() { return assertion_type_; } 2932 AssertionType assertion_type() { return assertion_type_; }
2921 private: 2933 private:
(...skipping 19 matching lines...) Expand all
2941 private: 2953 private:
2942 ZoneList<CharacterRange>* ranges_; 2954 ZoneList<CharacterRange>* ranges_;
2943 // If non-zero, the value represents a standard set (e.g., all whitespace 2955 // If non-zero, the value represents a standard set (e.g., all whitespace
2944 // characters) without having to expand the ranges. 2956 // characters) without having to expand the ranges.
2945 uc16 standard_set_type_; 2957 uc16 standard_set_type_;
2946 }; 2958 };
2947 2959
2948 2960
2949 class RegExpCharacterClass final : public RegExpTree { 2961 class RegExpCharacterClass final : public RegExpTree {
2950 public: 2962 public:
2951 RegExpCharacterClass(ZoneList<CharacterRange>* ranges, bool is_negated) 2963 RegExpCharacterClass(ZoneList<CharacterRange>* ranges, bool is_negated,
2952 : set_(ranges), 2964 ReadDirection read_direction)
2953 is_negated_(is_negated) { } 2965 : RegExpTree(read_direction), set_(ranges), is_negated_(is_negated) {}
2954 explicit RegExpCharacterClass(uc16 type) 2966 RegExpCharacterClass(uc16 type, ReadDirection read_direction)
2955 : set_(type), 2967 : RegExpTree(read_direction), set_(type), is_negated_(false) {}
2956 is_negated_(false) { }
2957 void* Accept(RegExpVisitor* visitor, void* data) override; 2968 void* Accept(RegExpVisitor* visitor, void* data) override;
2958 RegExpNode* ToNode(RegExpCompiler* compiler, RegExpNode* on_success) override; 2969 RegExpNode* ToNode(RegExpCompiler* compiler, RegExpNode* on_success) override;
2959 RegExpCharacterClass* AsCharacterClass() override; 2970 RegExpCharacterClass* AsCharacterClass() override;
2960 bool IsCharacterClass() override; 2971 bool IsCharacterClass() override;
2961 bool IsTextElement() override { return true; } 2972 bool IsTextElement() override { return true; }
2962 int min_match() override { return 1; } 2973 int min_match() override { return 1; }
2963 int max_match() override { return 1; } 2974 int max_match() override { return 1; }
2964 void AppendToText(RegExpText* text, Zone* zone) override; 2975 void AppendToText(RegExpText* text, Zone* zone) override;
2965 CharacterSet character_set() { return set_; } 2976 CharacterSet character_set() { return set_; }
2966 // TODO(lrn): Remove need for complex version if is_standard that 2977 // TODO(lrn): Remove need for complex version if is_standard that
(...skipping 15 matching lines...) Expand all
2982 bool is_negated() { return is_negated_; } 2993 bool is_negated() { return is_negated_; }
2983 2994
2984 private: 2995 private:
2985 CharacterSet set_; 2996 CharacterSet set_;
2986 bool is_negated_; 2997 bool is_negated_;
2987 }; 2998 };
2988 2999
2989 3000
2990 class RegExpAtom final : public RegExpTree { 3001 class RegExpAtom final : public RegExpTree {
2991 public: 3002 public:
2992 explicit RegExpAtom(Vector<const uc16> data) : data_(data) { } 3003 RegExpAtom(Vector<const uc16> data, ReadDirection read_direction)
3004 : RegExpTree(read_direction), data_(data) {}
2993 void* Accept(RegExpVisitor* visitor, void* data) override; 3005 void* Accept(RegExpVisitor* visitor, void* data) override;
2994 RegExpNode* ToNode(RegExpCompiler* compiler, RegExpNode* on_success) override; 3006 RegExpNode* ToNode(RegExpCompiler* compiler, RegExpNode* on_success) override;
2995 RegExpAtom* AsAtom() override; 3007 RegExpAtom* AsAtom() override;
2996 bool IsAtom() override; 3008 bool IsAtom() override;
2997 bool IsTextElement() override { return true; } 3009 bool IsTextElement() override { return true; }
2998 int min_match() override { return data_.length(); } 3010 int min_match() override { return data_.length(); }
2999 int max_match() override { return data_.length(); } 3011 int max_match() override { return data_.length(); }
3000 void AppendToText(RegExpText* text, Zone* zone) override; 3012 void AppendToText(RegExpText* text, Zone* zone) override;
3001 Vector<const uc16> data() { return data_; } 3013 Vector<const uc16> data() { return data_; }
3002 int length() { return data_.length(); } 3014 int length() { return data_.length(); }
3003 private: 3015 private:
3004 Vector<const uc16> data_; 3016 Vector<const uc16> data_;
3005 }; 3017 };
3006 3018
3007 3019
3008 class RegExpText final : public RegExpTree { 3020 class RegExpText final : public RegExpTree {
3009 public: 3021 public:
3010 explicit RegExpText(Zone* zone) : elements_(2, zone), length_(0) {} 3022 RegExpText(Zone* zone, ReadDirection read_direction)
3023 : RegExpTree(read_direction), elements_(2, zone), length_(0) {}
3011 void* Accept(RegExpVisitor* visitor, void* data) override; 3024 void* Accept(RegExpVisitor* visitor, void* data) override;
3012 RegExpNode* ToNode(RegExpCompiler* compiler, RegExpNode* on_success) override; 3025 RegExpNode* ToNode(RegExpCompiler* compiler, RegExpNode* on_success) override;
3013 RegExpText* AsText() override; 3026 RegExpText* AsText() override;
3014 bool IsText() override; 3027 bool IsText() override;
3015 bool IsTextElement() override { return true; } 3028 bool IsTextElement() override { return true; }
3016 int min_match() override { return length_; } 3029 int min_match() override { return length_; }
3017 int max_match() override { return length_; } 3030 int max_match() override { return length_; }
3018 void AppendToText(RegExpText* text, Zone* zone) override; 3031 void AppendToText(RegExpText* text, Zone* zone) override;
3019 void AddElement(TextElement elm, Zone* zone) { 3032 void AddElement(TextElement elm, Zone* zone) {
3020 elements_.Add(elm, zone); 3033 elements_.Add(elm, zone);
3021 length_ += elm.length(); 3034 length_ += elm.length();
3022 } 3035 }
3023 ZoneList<TextElement>* elements() { return &elements_; } 3036 ZoneList<TextElement>* elements() { return &elements_; }
3024 private: 3037 private:
3025 ZoneList<TextElement> elements_; 3038 ZoneList<TextElement> elements_;
3026 int length_; 3039 int length_;
3027 }; 3040 };
3028 3041
3029 3042
3030 class RegExpQuantifier final : public RegExpTree { 3043 class RegExpQuantifier final : public RegExpTree {
3031 public: 3044 public:
3032 enum QuantifierType { GREEDY, NON_GREEDY, POSSESSIVE }; 3045 enum QuantifierType { GREEDY, NON_GREEDY, POSSESSIVE };
3033 RegExpQuantifier(int min, int max, QuantifierType type, RegExpTree* body) 3046 RegExpQuantifier(int min, int max, QuantifierType type, RegExpTree* body,
3034 : body_(body), 3047 ReadDirection read_direction)
3048 : RegExpTree(read_direction),
3049 body_(body),
3035 min_(min), 3050 min_(min),
3036 max_(max), 3051 max_(max),
3037 min_match_(min * body->min_match()), 3052 min_match_(min * body->min_match()),
3038 quantifier_type_(type) { 3053 quantifier_type_(type) {
3039 if (max > 0 && body->max_match() > kInfinity / max) { 3054 if (max > 0 && body->max_match() > kInfinity / max) {
3040 max_match_ = kInfinity; 3055 max_match_ = kInfinity;
3041 } else { 3056 } else {
3042 max_match_ = max * body->max_match(); 3057 max_match_ = max * body->max_match();
3043 } 3058 }
3044 } 3059 }
(...skipping 23 matching lines...) Expand all
3068 int min_; 3083 int min_;
3069 int max_; 3084 int max_;
3070 int min_match_; 3085 int min_match_;
3071 int max_match_; 3086 int max_match_;
3072 QuantifierType quantifier_type_; 3087 QuantifierType quantifier_type_;
3073 }; 3088 };
3074 3089
3075 3090
3076 class RegExpCapture final : public RegExpTree { 3091 class RegExpCapture final : public RegExpTree {
3077 public: 3092 public:
3078 explicit RegExpCapture(RegExpTree* body, int index) 3093 explicit RegExpCapture(int index)
3079 : body_(body), index_(index) { } 3094 : RegExpTree(READ_FORWARD), body_(NULL), index_(index) {}
3080 void* Accept(RegExpVisitor* visitor, void* data) override; 3095 void* Accept(RegExpVisitor* visitor, void* data) override;
3081 RegExpNode* ToNode(RegExpCompiler* compiler, RegExpNode* on_success) override; 3096 RegExpNode* ToNode(RegExpCompiler* compiler, RegExpNode* on_success) override;
3082 static RegExpNode* ToNode(RegExpTree* body, 3097 static RegExpNode* ToNode(RegExpTree* body,
3083 int index, 3098 int index,
3084 RegExpCompiler* compiler, 3099 RegExpCompiler* compiler,
3085 RegExpNode* on_success); 3100 RegExpNode* on_success);
3086 RegExpCapture* AsCapture() override; 3101 RegExpCapture* AsCapture() override;
3087 bool IsAnchoredAtStart() override; 3102 bool IsAnchoredAtStart() override;
3088 bool IsAnchoredAtEnd() override; 3103 bool IsAnchoredAtEnd() override;
3089 Interval CaptureRegisters() override; 3104 Interval CaptureRegisters() override;
3090 bool IsCapture() override; 3105 bool IsCapture() override;
3091 int min_match() override { return body_->min_match(); } 3106 // If body_ is not yet set, the capture is back referenced but not parsed yet.
3092 int max_match() override { return body_->max_match(); } 3107 // In the ordinary case, nothing has been captured yet, so the back reference
3108 // must have the length 0.
3109 // If the back reference is inside a lookbehind, effectively making it a
3110 // forward reference, we return 0 since lookbehinds have a length of 0.
3111 int min_match() override { return body_ ? body_->min_match() : 0; }
3112 int max_match() override { return body_ ? body_->max_match() : 0; }
3093 RegExpTree* body() { return body_; } 3113 RegExpTree* body() { return body_; }
3114 void set_body(RegExpTree* body) { body_ = body; }
3115 void set_read_direction(ReadDirection read_direction) {
3116 read_direction_ = read_direction;
3117 }
3094 int index() { return index_; } 3118 int index() { return index_; }
3095 static int StartRegister(int index) { return index * 2; } 3119 static int StartRegister(int index) { return index * 2; }
3096 static int EndRegister(int index) { return index * 2 + 1; } 3120 static int EndRegister(int index) { return index * 2 + 1; }
3097 3121
3098 private: 3122 private:
3099 RegExpTree* body_; 3123 RegExpTree* body_;
3100 int index_; 3124 int index_;
3101 }; 3125 };
3102 3126
3103 3127
3104 class RegExpLookahead final : public RegExpTree { 3128 class RegExpLookaround final : public RegExpTree {
3105 public: 3129 public:
3106 RegExpLookahead(RegExpTree* body, 3130 RegExpLookaround(RegExpTree* body, bool is_positive, int capture_count,
3107 bool is_positive, 3131 int capture_from, ReadDirection read_direction)
3108 int capture_count, 3132 : RegExpTree(read_direction),
3109 int capture_from) 3133 body_(body),
3110 : body_(body),
3111 is_positive_(is_positive), 3134 is_positive_(is_positive),
3112 capture_count_(capture_count), 3135 capture_count_(capture_count),
3113 capture_from_(capture_from) { } 3136 capture_from_(capture_from) {}
3114 3137
3115 void* Accept(RegExpVisitor* visitor, void* data) override; 3138 void* Accept(RegExpVisitor* visitor, void* data) override;
3116 RegExpNode* ToNode(RegExpCompiler* compiler, RegExpNode* on_success) override; 3139 RegExpNode* ToNode(RegExpCompiler* compiler, RegExpNode* on_success) override;
3117 RegExpLookahead* AsLookahead() override; 3140 RegExpLookaround* AsLookaround() override;
3118 Interval CaptureRegisters() override; 3141 Interval CaptureRegisters() override;
3119 bool IsLookahead() override; 3142 bool IsLookaround() override;
3120 bool IsAnchoredAtStart() override; 3143 bool IsAnchoredAtStart() override;
3121 int min_match() override { return 0; } 3144 int min_match() override { return 0; }
3122 int max_match() override { return 0; } 3145 int max_match() override { return 0; }
3123 RegExpTree* body() { return body_; } 3146 RegExpTree* body() { return body_; }
3124 bool is_positive() { return is_positive_; } 3147 bool is_positive() { return is_positive_; }
3125 int capture_count() { return capture_count_; } 3148 int capture_count() { return capture_count_; }
3126 int capture_from() { return capture_from_; } 3149 int capture_from() { return capture_from_; }
3127 3150
3128 private: 3151 private:
3129 RegExpTree* body_; 3152 RegExpTree* body_;
3130 bool is_positive_; 3153 bool is_positive_;
3131 int capture_count_; 3154 int capture_count_;
3132 int capture_from_; 3155 int capture_from_;
3133 }; 3156 };
3134 3157
3135 3158
3136 class RegExpBackReference final : public RegExpTree { 3159 class RegExpBackReference final : public RegExpTree {
3137 public: 3160 public:
3138 explicit RegExpBackReference(RegExpCapture* capture) 3161 RegExpBackReference(RegExpCapture* capture, ReadDirection read_direction)
3139 : capture_(capture) { } 3162 : RegExpTree(read_direction), capture_(capture) {}
3140 void* Accept(RegExpVisitor* visitor, void* data) override; 3163 void* Accept(RegExpVisitor* visitor, void* data) override;
3141 RegExpNode* ToNode(RegExpCompiler* compiler, RegExpNode* on_success) override; 3164 RegExpNode* ToNode(RegExpCompiler* compiler, RegExpNode* on_success) override;
3142 RegExpBackReference* AsBackReference() override; 3165 RegExpBackReference* AsBackReference() override;
3143 bool IsBackReference() override; 3166 bool IsBackReference() override;
3144 int min_match() override { return 0; } 3167 int min_match() override { return 0; }
3145 int max_match() override { return capture_->max_match(); } 3168 int max_match() override { return capture_->max_match(); }
3146 int index() { return capture_->index(); } 3169 int index() { return capture_->index(); }
3147 RegExpCapture* capture() { return capture_; } 3170 RegExpCapture* capture() { return capture_; }
3148 private: 3171 private:
3149 RegExpCapture* capture_; 3172 RegExpCapture* capture_;
3150 }; 3173 };
3151 3174
3152 3175
3153 class RegExpEmpty final : public RegExpTree { 3176 class RegExpEmpty final : public RegExpTree {
3154 public: 3177 public:
3155 RegExpEmpty() { } 3178 RegExpEmpty() : RegExpTree(READ_FORWARD) {}
3156 void* Accept(RegExpVisitor* visitor, void* data) override; 3179 void* Accept(RegExpVisitor* visitor, void* data) override;
3157 RegExpNode* ToNode(RegExpCompiler* compiler, RegExpNode* on_success) override; 3180 RegExpNode* ToNode(RegExpCompiler* compiler, RegExpNode* on_success) override;
3158 RegExpEmpty* AsEmpty() override; 3181 RegExpEmpty* AsEmpty() override;
3159 bool IsEmpty() override; 3182 bool IsEmpty() override;
3160 int min_match() override { return 0; } 3183 int min_match() override { return 0; }
3161 int max_match() override { return 0; } 3184 int max_match() override { return 0; }
3162 }; 3185 };
3163 3186
3164 3187
3165 // ---------------------------------------------------------------------------- 3188 // ----------------------------------------------------------------------------
(...skipping 494 matching lines...) Expand 10 before | Expand all | Expand 10 after
3660 // the parser-level zone. 3683 // the parser-level zone.
3661 Zone* parser_zone_; 3684 Zone* parser_zone_;
3662 AstValueFactory* ast_value_factory_; 3685 AstValueFactory* ast_value_factory_;
3663 }; 3686 };
3664 3687
3665 3688
3666 } // namespace internal 3689 } // namespace internal
3667 } // namespace v8 3690 } // namespace v8
3668 3691
3669 #endif // V8_AST_H_ 3692 #endif // V8_AST_H_
OLDNEW
« no previous file with comments | « no previous file | src/ast.cc » ('j') | src/regexp/jsregexp.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698