| OLD | NEW |
| 1 // Copyright 2006-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2008 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 1191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1202 #define FORWARD_DECLARE(Name) class RegExp##Name; | 1202 #define FORWARD_DECLARE(Name) class RegExp##Name; |
| 1203 FOR_EACH_REG_EXP_NODE_TYPE(FORWARD_DECLARE) | 1203 FOR_EACH_REG_EXP_NODE_TYPE(FORWARD_DECLARE) |
| 1204 #undef FORWARD_DECLARE | 1204 #undef FORWARD_DECLARE |
| 1205 | 1205 |
| 1206 | 1206 |
| 1207 class RegExpTree: public ZoneObject { | 1207 class RegExpTree: public ZoneObject { |
| 1208 public: | 1208 public: |
| 1209 virtual ~RegExpTree() { } | 1209 virtual ~RegExpTree() { } |
| 1210 virtual void* Accept(RegExpVisitor* visitor, void* data) = 0; | 1210 virtual void* Accept(RegExpVisitor* visitor, void* data) = 0; |
| 1211 SmartPointer<char> ToString(); | 1211 SmartPointer<char> ToString(); |
| 1212 #define MAKE_ASTYPE(Name) virtual RegExp##Name* As##Name(); |
| 1213 FOR_EACH_REG_EXP_NODE_TYPE(MAKE_ASTYPE) |
| 1214 #undef MAKE_ASTYPE |
| 1212 }; | 1215 }; |
| 1213 | 1216 |
| 1214 | 1217 |
| 1215 class RegExpDisjunction: public RegExpTree { | 1218 class RegExpDisjunction: public RegExpTree { |
| 1216 public: | 1219 public: |
| 1217 explicit RegExpDisjunction(ZoneList<RegExpTree*>* nodes) : nodes_(nodes) { } | 1220 explicit RegExpDisjunction(ZoneList<RegExpTree*>* nodes) : nodes_(nodes) { } |
| 1218 virtual void* Accept(RegExpVisitor* visitor, void* data); | 1221 virtual void* Accept(RegExpVisitor* visitor, void* data); |
| 1222 virtual RegExpDisjunction* AsDisjunction(); |
| 1219 ZoneList<RegExpTree*>* nodes() { return nodes_; } | 1223 ZoneList<RegExpTree*>* nodes() { return nodes_; } |
| 1220 private: | 1224 private: |
| 1221 ZoneList<RegExpTree*>* nodes_; | 1225 ZoneList<RegExpTree*>* nodes_; |
| 1222 }; | 1226 }; |
| 1223 | 1227 |
| 1224 | 1228 |
| 1225 class RegExpAlternative: public RegExpTree { | 1229 class RegExpAlternative: public RegExpTree { |
| 1226 public: | 1230 public: |
| 1227 explicit RegExpAlternative(ZoneList<RegExpTree*>* nodes) : nodes_(nodes) { } | 1231 explicit RegExpAlternative(ZoneList<RegExpTree*>* nodes) : nodes_(nodes) { } |
| 1228 virtual void* Accept(RegExpVisitor* visitor, void* data); | 1232 virtual void* Accept(RegExpVisitor* visitor, void* data); |
| 1233 virtual RegExpAlternative* AsAlternative(); |
| 1229 ZoneList<RegExpTree*>* nodes() { return nodes_; } | 1234 ZoneList<RegExpTree*>* nodes() { return nodes_; } |
| 1230 private: | 1235 private: |
| 1231 ZoneList<RegExpTree*>* nodes_; | 1236 ZoneList<RegExpTree*>* nodes_; |
| 1232 }; | 1237 }; |
| 1233 | 1238 |
| 1234 | 1239 |
| 1235 class RegExpAssertion: public RegExpTree { | 1240 class RegExpAssertion: public RegExpTree { |
| 1236 public: | 1241 public: |
| 1237 enum Type { | 1242 enum Type { |
| 1238 START_OF_LINE, START_OF_INPUT, END_OF_LINE, END_OF_INPUT, | 1243 START_OF_LINE, START_OF_INPUT, END_OF_LINE, END_OF_INPUT, |
| 1239 BOUNDARY, NON_BOUNDARY | 1244 BOUNDARY, NON_BOUNDARY |
| 1240 }; | 1245 }; |
| 1241 explicit RegExpAssertion(Type type) : type_(type) { } | 1246 explicit RegExpAssertion(Type type) : type_(type) { } |
| 1242 virtual void* Accept(RegExpVisitor* visitor, void* data); | 1247 virtual void* Accept(RegExpVisitor* visitor, void* data); |
| 1248 virtual RegExpAssertion* AsAssertion(); |
| 1243 Type type() { return type_; } | 1249 Type type() { return type_; } |
| 1244 private: | 1250 private: |
| 1245 Type type_; | 1251 Type type_; |
| 1246 }; | 1252 }; |
| 1247 | 1253 |
| 1248 | 1254 |
| 1249 class CharacterRange { | 1255 class CharacterRange { |
| 1250 public: | 1256 public: |
| 1251 // For compatibility with the CHECK_OK macro | 1257 // For compatibility with the CHECK_OK macro |
| 1252 CharacterRange(void* null) { ASSERT_EQ(NULL, null); } //NOLINT | 1258 CharacterRange(void* null) { ASSERT_EQ(NULL, null); } //NOLINT |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1285 public: | 1291 public: |
| 1286 explicit RegExpCharacterClass(CharacterRange range) | 1292 explicit RegExpCharacterClass(CharacterRange range) |
| 1287 : ranges_(new ZoneList<CharacterRange>(1)), | 1293 : ranges_(new ZoneList<CharacterRange>(1)), |
| 1288 is_negated_(false) { | 1294 is_negated_(false) { |
| 1289 ranges_->Add(range); | 1295 ranges_->Add(range); |
| 1290 } | 1296 } |
| 1291 RegExpCharacterClass(ZoneList<CharacterRange>* ranges, bool is_negated) | 1297 RegExpCharacterClass(ZoneList<CharacterRange>* ranges, bool is_negated) |
| 1292 : ranges_(ranges), | 1298 : ranges_(ranges), |
| 1293 is_negated_(is_negated) { } | 1299 is_negated_(is_negated) { } |
| 1294 virtual void* Accept(RegExpVisitor* visitor, void* data); | 1300 virtual void* Accept(RegExpVisitor* visitor, void* data); |
| 1301 virtual RegExpCharacterClass* AsCharacterClass(); |
| 1295 ZoneList<CharacterRange>* ranges() { return ranges_; } | 1302 ZoneList<CharacterRange>* ranges() { return ranges_; } |
| 1296 bool is_negated() { return is_negated_; } | 1303 bool is_negated() { return is_negated_; } |
| 1297 private: | 1304 private: |
| 1298 ZoneList<CharacterRange>* ranges_; | 1305 ZoneList<CharacterRange>* ranges_; |
| 1299 bool is_negated_; | 1306 bool is_negated_; |
| 1300 }; | 1307 }; |
| 1301 | 1308 |
| 1302 | 1309 |
| 1303 class RegExpAtom: public RegExpTree { | 1310 class RegExpAtom: public RegExpTree { |
| 1304 public: | 1311 public: |
| 1305 explicit RegExpAtom(Vector<const uc16> data) : data_(data) { } | 1312 explicit RegExpAtom(Vector<const uc16> data) : data_(data) { } |
| 1306 virtual void* Accept(RegExpVisitor* visitor, void* data); | 1313 virtual void* Accept(RegExpVisitor* visitor, void* data); |
| 1314 virtual RegExpAtom* AsAtom(); |
| 1307 Vector<const uc16> data() { return data_; } | 1315 Vector<const uc16> data() { return data_; } |
| 1308 private: | 1316 private: |
| 1309 Vector<const uc16> data_; | 1317 Vector<const uc16> data_; |
| 1310 }; | 1318 }; |
| 1311 | 1319 |
| 1312 | 1320 |
| 1313 class RegExpQuantifier: public RegExpTree { | 1321 class RegExpQuantifier: public RegExpTree { |
| 1314 public: | 1322 public: |
| 1315 RegExpQuantifier(int min, int max, bool is_greedy, RegExpTree* body) | 1323 RegExpQuantifier(int min, int max, bool is_greedy, RegExpTree* body) |
| 1316 : min_(min), | 1324 : min_(min), |
| 1317 max_(max), | 1325 max_(max), |
| 1318 is_greedy_(is_greedy), | 1326 is_greedy_(is_greedy), |
| 1319 body_(body) { } | 1327 body_(body) { } |
| 1320 virtual void* Accept(RegExpVisitor* visitor, void* data); | 1328 virtual void* Accept(RegExpVisitor* visitor, void* data); |
| 1329 virtual RegExpQuantifier* AsQuantifier(); |
| 1321 int min() { return min_; } | 1330 int min() { return min_; } |
| 1322 int max() { return max_; } | 1331 int max() { return max_; } |
| 1323 bool is_greedy() { return is_greedy_; } | 1332 bool is_greedy() { return is_greedy_; } |
| 1324 RegExpTree* body() { return body_; } | 1333 RegExpTree* body() { return body_; } |
| 1325 // We just use a very large integer value as infinity because 1^31 | 1334 // We just use a very large integer value as infinity because 1^31 |
| 1326 // is infinite in practice. | 1335 // is infinite in practice. |
| 1327 static const int kInfinity = (1 << 31); | 1336 static const int kInfinity = (1 << 31); |
| 1328 private: | 1337 private: |
| 1329 int min_; | 1338 int min_; |
| 1330 int max_; | 1339 int max_; |
| 1331 bool is_greedy_; | 1340 bool is_greedy_; |
| 1332 RegExpTree* body_; | 1341 RegExpTree* body_; |
| 1333 }; | 1342 }; |
| 1334 | 1343 |
| 1335 | 1344 |
| 1336 class RegExpCapture: public RegExpTree { | 1345 class RegExpCapture: public RegExpTree { |
| 1337 public: | 1346 public: |
| 1338 explicit RegExpCapture(RegExpTree* body) | 1347 explicit RegExpCapture(RegExpTree* body) |
| 1339 : body_(body) { } | 1348 : body_(body) { } |
| 1340 virtual void* Accept(RegExpVisitor* visitor, void* data); | 1349 virtual void* Accept(RegExpVisitor* visitor, void* data); |
| 1350 virtual RegExpCapture* AsCapture(); |
| 1341 RegExpTree* body() { return body_; } | 1351 RegExpTree* body() { return body_; } |
| 1342 private: | 1352 private: |
| 1343 RegExpTree* body_; | 1353 RegExpTree* body_; |
| 1344 }; | 1354 }; |
| 1345 | 1355 |
| 1346 | 1356 |
| 1347 class RegExpLookahead: public RegExpTree { | 1357 class RegExpLookahead: public RegExpTree { |
| 1348 public: | 1358 public: |
| 1349 RegExpLookahead(RegExpTree* body, bool is_positive) | 1359 RegExpLookahead(RegExpTree* body, bool is_positive) |
| 1350 : body_(body), | 1360 : body_(body), |
| 1351 is_positive_(is_positive) { } | 1361 is_positive_(is_positive) { } |
| 1352 virtual void* Accept(RegExpVisitor* visitor, void* data); | 1362 virtual void* Accept(RegExpVisitor* visitor, void* data); |
| 1363 virtual RegExpLookahead* AsLookahead(); |
| 1353 RegExpTree* body() { return body_; } | 1364 RegExpTree* body() { return body_; } |
| 1354 bool is_positive() { return is_positive_; } | 1365 bool is_positive() { return is_positive_; } |
| 1355 private: | 1366 private: |
| 1356 RegExpTree* body_; | 1367 RegExpTree* body_; |
| 1357 bool is_positive_; | 1368 bool is_positive_; |
| 1358 }; | 1369 }; |
| 1359 | 1370 |
| 1360 | 1371 |
| 1361 class RegExpBackreference: public RegExpTree { | 1372 class RegExpBackreference: public RegExpTree { |
| 1362 public: | 1373 public: |
| 1363 explicit RegExpBackreference(int index) : index_(index) { } | 1374 explicit RegExpBackreference(int index) : index_(index) { } |
| 1364 virtual void* Accept(RegExpVisitor* visitor, void* data); | 1375 virtual void* Accept(RegExpVisitor* visitor, void* data); |
| 1376 virtual RegExpBackreference* AsBackreference(); |
| 1365 int index() { return index_; } | 1377 int index() { return index_; } |
| 1366 private: | 1378 private: |
| 1367 int index_; | 1379 int index_; |
| 1368 }; | 1380 }; |
| 1369 | 1381 |
| 1370 | 1382 |
| 1371 class RegExpEmpty: public RegExpTree { | 1383 class RegExpEmpty: public RegExpTree { |
| 1372 public: | 1384 public: |
| 1373 RegExpEmpty() { } | 1385 RegExpEmpty() { } |
| 1374 virtual void* Accept(RegExpVisitor* visitor, void* data); | 1386 virtual void* Accept(RegExpVisitor* visitor, void* data); |
| 1387 virtual RegExpEmpty* AsEmpty(); |
| 1375 static RegExpEmpty* GetInstance() { return &kInstance; } | 1388 static RegExpEmpty* GetInstance() { return &kInstance; } |
| 1376 private: | 1389 private: |
| 1377 static RegExpEmpty kInstance; | 1390 static RegExpEmpty kInstance; |
| 1378 }; | 1391 }; |
| 1379 | 1392 |
| 1380 | 1393 |
| 1381 class RegExpVisitor BASE_EMBEDDED { | 1394 class RegExpVisitor BASE_EMBEDDED { |
| 1382 public: | 1395 public: |
| 1383 virtual ~RegExpVisitor() { } | 1396 virtual ~RegExpVisitor() { } |
| 1384 #define MAKE_CASE(Name) \ | 1397 #define MAKE_CASE(Name) \ |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1426 #undef DEF_VISIT | 1439 #undef DEF_VISIT |
| 1427 | 1440 |
| 1428 private: | 1441 private: |
| 1429 bool stack_overflow_; | 1442 bool stack_overflow_; |
| 1430 }; | 1443 }; |
| 1431 | 1444 |
| 1432 | 1445 |
| 1433 } } // namespace v8::internal | 1446 } } // namespace v8::internal |
| 1434 | 1447 |
| 1435 #endif // V8_AST_H_ | 1448 #endif // V8_AST_H_ |
| OLD | NEW |