OLD | NEW |
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 #include "src/ast.h" | 5 #include "src/ast.h" |
6 | 6 |
7 #include <cmath> // For isfinite. | 7 #include <cmath> // For isfinite. |
8 #include "src/builtins.h" | 8 #include "src/builtins.h" |
9 #include "src/code-stubs.h" | 9 #include "src/code-stubs.h" |
10 #include "src/contexts.h" | 10 #include "src/contexts.h" |
(...skipping 832 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
843 Interval RegExpAlternative::CaptureRegisters() { | 843 Interval RegExpAlternative::CaptureRegisters() { |
844 return ListCaptureRegisters(nodes()); | 844 return ListCaptureRegisters(nodes()); |
845 } | 845 } |
846 | 846 |
847 | 847 |
848 Interval RegExpDisjunction::CaptureRegisters() { | 848 Interval RegExpDisjunction::CaptureRegisters() { |
849 return ListCaptureRegisters(alternatives()); | 849 return ListCaptureRegisters(alternatives()); |
850 } | 850 } |
851 | 851 |
852 | 852 |
853 Interval RegExpLookahead::CaptureRegisters() { | 853 Interval RegExpLookaround::CaptureRegisters() { |
854 return body()->CaptureRegisters(); | 854 return body()->CaptureRegisters(); |
855 } | 855 } |
856 | 856 |
857 | 857 |
858 Interval RegExpCapture::CaptureRegisters() { | 858 Interval RegExpCapture::CaptureRegisters() { |
859 Interval self(StartRegister(index()), EndRegister(index())); | 859 Interval self(StartRegister(index()), EndRegister(index())); |
860 return self.Union(body()->CaptureRegisters()); | 860 return self.Union(body()->CaptureRegisters()); |
861 } | 861 } |
862 | 862 |
863 | 863 |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
911 bool RegExpDisjunction::IsAnchoredAtEnd() { | 911 bool RegExpDisjunction::IsAnchoredAtEnd() { |
912 ZoneList<RegExpTree*>* alternatives = this->alternatives(); | 912 ZoneList<RegExpTree*>* alternatives = this->alternatives(); |
913 for (int i = 0; i < alternatives->length(); i++) { | 913 for (int i = 0; i < alternatives->length(); i++) { |
914 if (!alternatives->at(i)->IsAnchoredAtEnd()) | 914 if (!alternatives->at(i)->IsAnchoredAtEnd()) |
915 return false; | 915 return false; |
916 } | 916 } |
917 return true; | 917 return true; |
918 } | 918 } |
919 | 919 |
920 | 920 |
921 bool RegExpLookahead::IsAnchoredAtStart() { | 921 bool RegExpLookaround::IsAnchoredAtStart() { |
922 return is_positive() && body()->IsAnchoredAtStart(); | 922 return is_positive() && read_direction() == READ_FORWARD && |
| 923 body()->IsAnchoredAtStart(); |
923 } | 924 } |
924 | 925 |
925 | 926 |
926 bool RegExpCapture::IsAnchoredAtStart() { | 927 bool RegExpCapture::IsAnchoredAtStart() { |
927 return body()->IsAnchoredAtStart(); | 928 return body()->IsAnchoredAtStart(); |
928 } | 929 } |
929 | 930 |
930 | 931 |
931 bool RegExpCapture::IsAnchoredAtEnd() { | 932 bool RegExpCapture::IsAnchoredAtEnd() { |
932 return body()->IsAnchoredAtEnd(); | 933 return body()->IsAnchoredAtEnd(); |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1061 | 1062 |
1062 | 1063 |
1063 void* RegExpUnparser::VisitCapture(RegExpCapture* that, void* data) { | 1064 void* RegExpUnparser::VisitCapture(RegExpCapture* that, void* data) { |
1064 os_ << "(^ "; | 1065 os_ << "(^ "; |
1065 that->body()->Accept(this, data); | 1066 that->body()->Accept(this, data); |
1066 os_ << ")"; | 1067 os_ << ")"; |
1067 return NULL; | 1068 return NULL; |
1068 } | 1069 } |
1069 | 1070 |
1070 | 1071 |
1071 void* RegExpUnparser::VisitLookahead(RegExpLookahead* that, void* data) { | 1072 void* RegExpUnparser::VisitLookaround(RegExpLookaround* that, void* data) { |
1072 os_ << "(-> " << (that->is_positive() ? "+ " : "- "); | 1073 os_ << "("; |
| 1074 os_ << (that->read_direction() == RegExpTree::READ_FORWARD ? "->" : "<-"); |
| 1075 os_ << (that->is_positive() ? " + " : " - "); |
1073 that->body()->Accept(this, data); | 1076 that->body()->Accept(this, data); |
1074 os_ << ")"; | 1077 os_ << ")"; |
1075 return NULL; | 1078 return NULL; |
1076 } | 1079 } |
1077 | 1080 |
1078 | 1081 |
1079 void* RegExpUnparser::VisitBackReference(RegExpBackReference* that, | 1082 void* RegExpUnparser::VisitBackReference(RegExpBackReference* that, |
1080 void* data) { | 1083 void* data) { |
1081 os_ << "(<- " << that->index() << ")"; | 1084 os_ << "(<- " << that->index() << ")"; |
1082 return NULL; | 1085 return NULL; |
1083 } | 1086 } |
1084 | 1087 |
1085 | 1088 |
1086 void* RegExpUnparser::VisitEmpty(RegExpEmpty* that, void* data) { | 1089 void* RegExpUnparser::VisitEmpty(RegExpEmpty* that, void* data) { |
1087 os_ << '%'; | 1090 os_ << '%'; |
1088 return NULL; | 1091 return NULL; |
1089 } | 1092 } |
1090 | 1093 |
1091 | 1094 |
1092 std::ostream& RegExpTree::Print(std::ostream& os, Zone* zone) { // NOLINT | 1095 std::ostream& RegExpTree::Print(std::ostream& os, Zone* zone) { // NOLINT |
1093 RegExpUnparser unparser(os, zone); | 1096 RegExpUnparser unparser(os, zone); |
1094 Accept(&unparser, NULL); | 1097 Accept(&unparser, NULL); |
1095 return os; | 1098 return os; |
1096 } | 1099 } |
1097 | 1100 |
1098 | 1101 |
1099 RegExpDisjunction::RegExpDisjunction(ZoneList<RegExpTree*>* alternatives) | 1102 RegExpDisjunction::RegExpDisjunction(ZoneList<RegExpTree*>* alternatives, |
1100 : alternatives_(alternatives) { | 1103 ReadDirection read_direction) |
| 1104 : RegExpTree(read_direction), alternatives_(alternatives) { |
1101 DCHECK(alternatives->length() > 1); | 1105 DCHECK(alternatives->length() > 1); |
1102 RegExpTree* first_alternative = alternatives->at(0); | 1106 RegExpTree* first_alternative = alternatives->at(0); |
1103 min_match_ = first_alternative->min_match(); | 1107 min_match_ = first_alternative->min_match(); |
1104 max_match_ = first_alternative->max_match(); | 1108 max_match_ = first_alternative->max_match(); |
1105 for (int i = 1; i < alternatives->length(); i++) { | 1109 for (int i = 1; i < alternatives->length(); i++) { |
1106 RegExpTree* alternative = alternatives->at(i); | 1110 RegExpTree* alternative = alternatives->at(i); |
1107 min_match_ = Min(min_match_, alternative->min_match()); | 1111 min_match_ = Min(min_match_, alternative->min_match()); |
1108 max_match_ = Max(max_match_, alternative->max_match()); | 1112 max_match_ = Max(max_match_, alternative->max_match()); |
1109 } | 1113 } |
1110 } | 1114 } |
1111 | 1115 |
1112 | 1116 |
1113 static int IncreaseBy(int previous, int increase) { | 1117 static int IncreaseBy(int previous, int increase) { |
1114 if (RegExpTree::kInfinity - previous < increase) { | 1118 if (RegExpTree::kInfinity - previous < increase) { |
1115 return RegExpTree::kInfinity; | 1119 return RegExpTree::kInfinity; |
1116 } else { | 1120 } else { |
1117 return previous + increase; | 1121 return previous + increase; |
1118 } | 1122 } |
1119 } | 1123 } |
1120 | 1124 |
1121 RegExpAlternative::RegExpAlternative(ZoneList<RegExpTree*>* nodes) | 1125 RegExpAlternative::RegExpAlternative(ZoneList<RegExpTree*>* nodes, |
1122 : nodes_(nodes) { | 1126 ReadDirection read_direction) |
| 1127 : RegExpTree(read_direction), nodes_(nodes) { |
1123 DCHECK(nodes->length() > 1); | 1128 DCHECK(nodes->length() > 1); |
1124 min_match_ = 0; | 1129 min_match_ = 0; |
1125 max_match_ = 0; | 1130 max_match_ = 0; |
1126 for (int i = 0; i < nodes->length(); i++) { | 1131 for (int i = 0; i < nodes->length(); i++) { |
1127 RegExpTree* node = nodes->at(i); | 1132 RegExpTree* node = nodes->at(i); |
1128 int node_min_match = node->min_match(); | 1133 int node_min_match = node->min_match(); |
1129 min_match_ = IncreaseBy(min_match_, node_min_match); | 1134 min_match_ = IncreaseBy(min_match_, node_min_match); |
1130 int node_max_match = node->max_match(); | 1135 int node_max_match = node->max_match(); |
1131 max_match_ = IncreaseBy(max_match_, node_max_match); | 1136 max_match_ = IncreaseBy(max_match_, node_max_match); |
1132 } | 1137 } |
(...skipping 19 matching lines...) Expand all Loading... |
1152 bool Literal::Match(void* literal1, void* literal2) { | 1157 bool Literal::Match(void* literal1, void* literal2) { |
1153 const AstValue* x = static_cast<Literal*>(literal1)->raw_value(); | 1158 const AstValue* x = static_cast<Literal*>(literal1)->raw_value(); |
1154 const AstValue* y = static_cast<Literal*>(literal2)->raw_value(); | 1159 const AstValue* y = static_cast<Literal*>(literal2)->raw_value(); |
1155 return (x->IsString() && y->IsString() && x->AsString() == y->AsString()) || | 1160 return (x->IsString() && y->IsString() && x->AsString() == y->AsString()) || |
1156 (x->IsNumber() && y->IsNumber() && x->AsNumber() == y->AsNumber()); | 1161 (x->IsNumber() && y->IsNumber() && x->AsNumber() == y->AsNumber()); |
1157 } | 1162 } |
1158 | 1163 |
1159 | 1164 |
1160 } // namespace internal | 1165 } // namespace internal |
1161 } // namespace v8 | 1166 } // namespace v8 |
OLD | NEW |