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