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 #include "src/regexp/regexp-parser.h" | 5 #include "src/regexp/regexp-parser.h" |
6 | 6 |
7 #include "src/char-predicates-inl.h" | 7 #include "src/char-predicates-inl.h" |
8 #include "src/factory.h" | 8 #include "src/factory.h" |
9 #include "src/isolate.h" | 9 #include "src/isolate.h" |
10 #include "src/objects-inl.h" | 10 #include "src/objects-inl.h" |
(...skipping 1055 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1066 | 1066 |
1067 void RegExpBuilder::AddTrailSurrogate(uc16 trail_surrogate) { | 1067 void RegExpBuilder::AddTrailSurrogate(uc16 trail_surrogate) { |
1068 DCHECK(unibrow::Utf16::IsTrailSurrogate(trail_surrogate)); | 1068 DCHECK(unibrow::Utf16::IsTrailSurrogate(trail_surrogate)); |
1069 if (pending_surrogate_ != kNoPendingSurrogate) { | 1069 if (pending_surrogate_ != kNoPendingSurrogate) { |
1070 uc16 lead_surrogate = pending_surrogate_; | 1070 uc16 lead_surrogate = pending_surrogate_; |
1071 pending_surrogate_ = kNoPendingSurrogate; | 1071 pending_surrogate_ = kNoPendingSurrogate; |
1072 DCHECK(unibrow::Utf16::IsLeadSurrogate(lead_surrogate)); | 1072 DCHECK(unibrow::Utf16::IsLeadSurrogate(lead_surrogate)); |
1073 uc32 combined = | 1073 uc32 combined = |
1074 unibrow::Utf16::CombineSurrogatePair(lead_surrogate, trail_surrogate); | 1074 unibrow::Utf16::CombineSurrogatePair(lead_surrogate, trail_surrogate); |
1075 if (NeedsDesugaringForIgnoreCase(combined)) { | 1075 if (NeedsDesugaringForIgnoreCase(combined)) { |
1076 AddCharacterClass(combined); | 1076 AddCharacterClassForDesugaring(combined); |
1077 } else { | 1077 } else { |
1078 ZoneList<uc16> surrogate_pair(2, zone()); | 1078 ZoneList<uc16> surrogate_pair(2, zone()); |
1079 surrogate_pair.Add(lead_surrogate, zone()); | 1079 surrogate_pair.Add(lead_surrogate, zone()); |
1080 surrogate_pair.Add(trail_surrogate, zone()); | 1080 surrogate_pair.Add(trail_surrogate, zone()); |
1081 RegExpAtom* atom = | 1081 RegExpAtom* atom = |
1082 new (zone()) RegExpAtom(surrogate_pair.ToConstVector()); | 1082 new (zone()) RegExpAtom(surrogate_pair.ToConstVector()); |
1083 AddAtom(atom); | 1083 AddAtom(atom); |
1084 } | 1084 } |
1085 } else { | 1085 } else { |
1086 pending_surrogate_ = trail_surrogate; | 1086 pending_surrogate_ = trail_surrogate; |
1087 FlushPendingSurrogate(); | 1087 FlushPendingSurrogate(); |
1088 } | 1088 } |
1089 } | 1089 } |
1090 | 1090 |
1091 | 1091 |
1092 void RegExpBuilder::FlushPendingSurrogate() { | 1092 void RegExpBuilder::FlushPendingSurrogate() { |
1093 if (pending_surrogate_ != kNoPendingSurrogate) { | 1093 if (pending_surrogate_ != kNoPendingSurrogate) { |
1094 DCHECK(unicode()); | 1094 DCHECK(unicode()); |
1095 uc32 c = pending_surrogate_; | 1095 uc32 c = pending_surrogate_; |
1096 pending_surrogate_ = kNoPendingSurrogate; | 1096 pending_surrogate_ = kNoPendingSurrogate; |
1097 AddCharacterClass(c); | 1097 AddCharacterClassForDesugaring(c); |
1098 } | 1098 } |
1099 } | 1099 } |
1100 | 1100 |
1101 | 1101 |
1102 void RegExpBuilder::FlushCharacters() { | 1102 void RegExpBuilder::FlushCharacters() { |
1103 FlushPendingSurrogate(); | 1103 FlushPendingSurrogate(); |
1104 pending_empty_ = false; | 1104 pending_empty_ = false; |
1105 if (characters_ != NULL) { | 1105 if (characters_ != NULL) { |
1106 RegExpTree* atom = new (zone()) RegExpAtom(characters_->ToConstVector()); | 1106 RegExpTree* atom = new (zone()) RegExpAtom(characters_->ToConstVector()); |
1107 characters_ = NULL; | 1107 characters_ = NULL; |
(...skipping 16 matching lines...) Expand all Loading... |
1124 terms_.Add(text, zone()); | 1124 terms_.Add(text, zone()); |
1125 } | 1125 } |
1126 text_.Clear(); | 1126 text_.Clear(); |
1127 } | 1127 } |
1128 | 1128 |
1129 | 1129 |
1130 void RegExpBuilder::AddCharacter(uc16 c) { | 1130 void RegExpBuilder::AddCharacter(uc16 c) { |
1131 FlushPendingSurrogate(); | 1131 FlushPendingSurrogate(); |
1132 pending_empty_ = false; | 1132 pending_empty_ = false; |
1133 if (NeedsDesugaringForIgnoreCase(c)) { | 1133 if (NeedsDesugaringForIgnoreCase(c)) { |
1134 AddCharacterClass(c); | 1134 AddCharacterClassForDesugaring(c); |
1135 } else { | 1135 } else { |
1136 if (characters_ == NULL) { | 1136 if (characters_ == NULL) { |
1137 characters_ = new (zone()) ZoneList<uc16>(4, zone()); | 1137 characters_ = new (zone()) ZoneList<uc16>(4, zone()); |
1138 } | 1138 } |
1139 characters_->Add(c, zone()); | 1139 characters_->Add(c, zone()); |
1140 LAST(ADD_CHAR); | 1140 LAST(ADD_CHAR); |
1141 } | 1141 } |
1142 } | 1142 } |
1143 | 1143 |
1144 | 1144 |
(...skipping 18 matching lines...) Expand all Loading... |
1163 void RegExpBuilder::AddCharacterClass(RegExpCharacterClass* cc) { | 1163 void RegExpBuilder::AddCharacterClass(RegExpCharacterClass* cc) { |
1164 if (NeedsDesugaringForUnicode(cc)) { | 1164 if (NeedsDesugaringForUnicode(cc)) { |
1165 // In unicode mode, character class needs to be desugared, so it | 1165 // In unicode mode, character class needs to be desugared, so it |
1166 // must be a standalone term instead of being part of a RegExpText. | 1166 // must be a standalone term instead of being part of a RegExpText. |
1167 AddTerm(cc); | 1167 AddTerm(cc); |
1168 } else { | 1168 } else { |
1169 AddAtom(cc); | 1169 AddAtom(cc); |
1170 } | 1170 } |
1171 } | 1171 } |
1172 | 1172 |
1173 | 1173 void RegExpBuilder::AddCharacterClassForDesugaring(uc32 c) { |
1174 void RegExpBuilder::AddCharacterClass(uc32 c) { | 1174 AddTerm(new (zone()) RegExpCharacterClass( |
1175 AddCharacterClass(new (zone()) RegExpCharacterClass( | |
1176 CharacterRange::List(zone(), CharacterRange::Singleton(c)), false)); | 1175 CharacterRange::List(zone(), CharacterRange::Singleton(c)), false)); |
1177 } | 1176 } |
1178 | 1177 |
1179 | 1178 |
1180 void RegExpBuilder::AddAtom(RegExpTree* term) { | 1179 void RegExpBuilder::AddAtom(RegExpTree* term) { |
1181 if (term->IsEmpty()) { | 1180 if (term->IsEmpty()) { |
1182 AddEmpty(); | 1181 AddEmpty(); |
1183 return; | 1182 return; |
1184 } | 1183 } |
1185 if (term->IsTextElement()) { | 1184 if (term->IsTextElement()) { |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1319 UNREACHABLE(); | 1318 UNREACHABLE(); |
1320 return; | 1319 return; |
1321 } | 1320 } |
1322 terms_.Add(new (zone()) RegExpQuantifier(min, max, quantifier_type, atom), | 1321 terms_.Add(new (zone()) RegExpQuantifier(min, max, quantifier_type, atom), |
1323 zone()); | 1322 zone()); |
1324 LAST(ADD_TERM); | 1323 LAST(ADD_TERM); |
1325 } | 1324 } |
1326 | 1325 |
1327 } // namespace internal | 1326 } // namespace internal |
1328 } // namespace v8 | 1327 } // namespace v8 |
OLD | NEW |