Chromium Code Reviews| 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 1186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1197 VISIT(Assertion) \ | 1197 VISIT(Assertion) \ |
| 1198 VISIT(CharacterClass) \ | 1198 VISIT(CharacterClass) \ |
| 1199 VISIT(Atom) \ | 1199 VISIT(Atom) \ |
| 1200 VISIT(Quantifier) \ | 1200 VISIT(Quantifier) \ |
| 1201 VISIT(Capture) \ | 1201 VISIT(Capture) \ |
| 1202 VISIT(Lookahead) \ | 1202 VISIT(Lookahead) \ |
| 1203 VISIT(Backreference) \ | 1203 VISIT(Backreference) \ |
| 1204 VISIT(Empty) | 1204 VISIT(Empty) |
| 1205 | 1205 |
| 1206 | 1206 |
| 1207 class RegExpVisitor; | |
| 1208 template <typename Char> class RegExpNode; | |
| 1209 #define FORWARD_DECLARE(Name) class RegExp##Name; | 1207 #define FORWARD_DECLARE(Name) class RegExp##Name; |
| 1210 FOR_EACH_REG_EXP_NODE_TYPE(FORWARD_DECLARE) | 1208 FOR_EACH_REG_EXP_NODE_TYPE(FORWARD_DECLARE) |
| 1211 #undef FORWARD_DECLARE | 1209 #undef FORWARD_DECLARE |
| 1212 | 1210 |
| 1213 | 1211 |
| 1214 class RegExpTree: public ZoneObject { | 1212 class RegExpTree: public ZoneObject { |
| 1215 public: | 1213 public: |
| 1216 virtual ~RegExpTree() { } | 1214 virtual ~RegExpTree() { } |
| 1217 virtual void* Accept(RegExpVisitor* visitor, void* data) = 0; | 1215 virtual void* Accept(RegExpVisitor* visitor, void* data) = 0; |
| 1216 virtual RegExpNode* ToNode(RegExpCompiler* compiler, | |
|
Lasse Reichstein
2008/11/06 16:46:44
Could this be a Visitor instead?
Christian Plesner Hansen
2008/11/06 17:34:42
It used to be but when I wanted to add the on_fail
| |
| 1217 RegExpNode* on_success, | |
| 1218 RegExpNode* on_failure) = 0; | |
| 1218 SmartPointer<char> ToString(); | 1219 SmartPointer<char> ToString(); |
| 1219 #define MAKE_ASTYPE(Name) virtual RegExp##Name* As##Name(); | 1220 #define MAKE_ASTYPE(Name) virtual RegExp##Name* As##Name(); |
| 1220 FOR_EACH_REG_EXP_NODE_TYPE(MAKE_ASTYPE) | 1221 FOR_EACH_REG_EXP_NODE_TYPE(MAKE_ASTYPE) |
| 1221 #undef MAKE_ASTYPE | 1222 #undef MAKE_ASTYPE |
| 1222 }; | 1223 }; |
| 1223 | 1224 |
| 1224 | 1225 |
| 1225 class RegExpDisjunction: public RegExpTree { | 1226 class RegExpDisjunction: public RegExpTree { |
| 1226 public: | 1227 public: |
| 1227 explicit RegExpDisjunction(ZoneList<RegExpTree*>* nodes) : nodes_(nodes) { } | 1228 explicit RegExpDisjunction(ZoneList<RegExpTree*>* nodes) : nodes_(nodes) { } |
| 1228 virtual void* Accept(RegExpVisitor* visitor, void* data); | 1229 virtual void* Accept(RegExpVisitor* visitor, void* data); |
| 1230 virtual RegExpNode* ToNode(RegExpCompiler* compiler, | |
| 1231 RegExpNode* on_success, | |
| 1232 RegExpNode* on_failure); | |
| 1229 virtual RegExpDisjunction* AsDisjunction(); | 1233 virtual RegExpDisjunction* AsDisjunction(); |
| 1230 ZoneList<RegExpTree*>* nodes() { return nodes_; } | 1234 ZoneList<RegExpTree*>* nodes() { return nodes_; } |
| 1231 private: | 1235 private: |
| 1232 ZoneList<RegExpTree*>* nodes_; | 1236 ZoneList<RegExpTree*>* nodes_; |
| 1233 }; | 1237 }; |
| 1234 | 1238 |
| 1235 | 1239 |
| 1236 class RegExpAlternative: public RegExpTree { | 1240 class RegExpAlternative: public RegExpTree { |
| 1237 public: | 1241 public: |
| 1238 explicit RegExpAlternative(ZoneList<RegExpTree*>* nodes) : nodes_(nodes) { } | 1242 explicit RegExpAlternative(ZoneList<RegExpTree*>* nodes) : nodes_(nodes) { } |
| 1239 virtual void* Accept(RegExpVisitor* visitor, void* data); | 1243 virtual void* Accept(RegExpVisitor* visitor, void* data); |
| 1244 virtual RegExpNode* ToNode(RegExpCompiler* compiler, | |
| 1245 RegExpNode* on_success, | |
| 1246 RegExpNode* on_failure); | |
| 1240 virtual RegExpAlternative* AsAlternative(); | 1247 virtual RegExpAlternative* AsAlternative(); |
| 1241 ZoneList<RegExpTree*>* nodes() { return nodes_; } | 1248 ZoneList<RegExpTree*>* nodes() { return nodes_; } |
| 1242 private: | 1249 private: |
| 1243 ZoneList<RegExpTree*>* nodes_; | 1250 ZoneList<RegExpTree*>* nodes_; |
| 1244 }; | 1251 }; |
| 1245 | 1252 |
| 1246 | 1253 |
| 1247 class RegExpAssertion: public RegExpTree { | 1254 class RegExpAssertion: public RegExpTree { |
| 1248 public: | 1255 public: |
| 1249 enum Type { | 1256 enum Type { |
| 1250 START_OF_LINE, START_OF_INPUT, END_OF_LINE, END_OF_INPUT, | 1257 START_OF_LINE, START_OF_INPUT, END_OF_LINE, END_OF_INPUT, |
| 1251 BOUNDARY, NON_BOUNDARY | 1258 BOUNDARY, NON_BOUNDARY |
| 1252 }; | 1259 }; |
| 1253 explicit RegExpAssertion(Type type) : type_(type) { } | 1260 explicit RegExpAssertion(Type type) : type_(type) { } |
| 1254 virtual void* Accept(RegExpVisitor* visitor, void* data); | 1261 virtual void* Accept(RegExpVisitor* visitor, void* data); |
| 1262 virtual RegExpNode* ToNode(RegExpCompiler* compiler, | |
| 1263 RegExpNode* on_success, | |
| 1264 RegExpNode* on_failure); | |
| 1255 virtual RegExpAssertion* AsAssertion(); | 1265 virtual RegExpAssertion* AsAssertion(); |
| 1256 Type type() { return type_; } | 1266 Type type() { return type_; } |
| 1257 private: | 1267 private: |
| 1258 Type type_; | 1268 Type type_; |
| 1259 }; | 1269 }; |
| 1260 | 1270 |
| 1261 | 1271 |
| 1262 class RegExpCharacterClass: public RegExpTree { | 1272 class RegExpCharacterClass: public RegExpTree { |
| 1263 public: | 1273 public: |
| 1264 RegExpCharacterClass(ZoneList<CharacterRange>* ranges, bool is_negated) | 1274 RegExpCharacterClass(ZoneList<CharacterRange>* ranges, bool is_negated) |
| 1265 : ranges_(ranges), | 1275 : ranges_(ranges), |
| 1266 is_negated_(is_negated) { } | 1276 is_negated_(is_negated) { } |
| 1267 virtual void* Accept(RegExpVisitor* visitor, void* data); | 1277 virtual void* Accept(RegExpVisitor* visitor, void* data); |
| 1278 virtual RegExpNode* ToNode(RegExpCompiler* compiler, | |
| 1279 RegExpNode* on_success, | |
| 1280 RegExpNode* on_failure); | |
| 1268 virtual RegExpCharacterClass* AsCharacterClass(); | 1281 virtual RegExpCharacterClass* AsCharacterClass(); |
| 1269 ZoneList<CharacterRange>* ranges() { return ranges_; } | 1282 ZoneList<CharacterRange>* ranges() { return ranges_; } |
| 1270 bool is_negated() { return is_negated_; } | 1283 bool is_negated() { return is_negated_; } |
| 1271 private: | 1284 private: |
| 1272 ZoneList<CharacterRange>* ranges_; | 1285 ZoneList<CharacterRange>* ranges_; |
| 1273 bool is_negated_; | 1286 bool is_negated_; |
| 1274 }; | 1287 }; |
| 1275 | 1288 |
| 1276 | 1289 |
| 1277 class RegExpAtom: public RegExpTree { | 1290 class RegExpAtom: public RegExpTree { |
| 1278 public: | 1291 public: |
| 1279 explicit RegExpAtom(Vector<const uc16> data) : data_(data) { } | 1292 explicit RegExpAtom(Vector<const uc16> data) : data_(data) { } |
| 1280 virtual void* Accept(RegExpVisitor* visitor, void* data); | 1293 virtual void* Accept(RegExpVisitor* visitor, void* data); |
| 1294 virtual RegExpNode* ToNode(RegExpCompiler* compiler, | |
| 1295 RegExpNode* on_success, | |
| 1296 RegExpNode* on_failure); | |
| 1281 virtual RegExpAtom* AsAtom(); | 1297 virtual RegExpAtom* AsAtom(); |
| 1282 Vector<const uc16> data() { return data_; } | 1298 Vector<const uc16> data() { return data_; } |
| 1283 private: | 1299 private: |
| 1284 Vector<const uc16> data_; | 1300 Vector<const uc16> data_; |
| 1285 }; | 1301 }; |
| 1286 | 1302 |
| 1287 | 1303 |
| 1288 class RegExpQuantifier: public RegExpTree { | 1304 class RegExpQuantifier: public RegExpTree { |
| 1289 public: | 1305 public: |
| 1290 RegExpQuantifier(int min, int max, bool is_greedy, RegExpTree* body) | 1306 RegExpQuantifier(int min, int max, bool is_greedy, RegExpTree* body) |
| 1291 : min_(min), | 1307 : min_(min), |
| 1292 max_(max), | 1308 max_(max), |
| 1293 is_greedy_(is_greedy), | 1309 is_greedy_(is_greedy), |
| 1294 body_(body) { } | 1310 body_(body) { } |
| 1295 virtual void* Accept(RegExpVisitor* visitor, void* data); | 1311 virtual void* Accept(RegExpVisitor* visitor, void* data); |
| 1312 virtual RegExpNode* ToNode(RegExpCompiler* compiler, | |
| 1313 RegExpNode* on_success, | |
| 1314 RegExpNode* on_failure); | |
| 1296 virtual RegExpQuantifier* AsQuantifier(); | 1315 virtual RegExpQuantifier* AsQuantifier(); |
| 1297 int min() { return min_; } | 1316 int min() { return min_; } |
| 1298 int max() { return max_; } | 1317 int max() { return max_; } |
| 1299 bool is_greedy() { return is_greedy_; } | 1318 bool is_greedy() { return is_greedy_; } |
| 1300 RegExpTree* body() { return body_; } | 1319 RegExpTree* body() { return body_; } |
| 1301 // We just use a very large integer value as infinity because 2^30 | 1320 // We just use a very large integer value as infinity because 2^30 |
| 1302 // is infinite in practice. | 1321 // is infinite in practice. |
| 1303 static const int kInfinity = (1 << 30); | 1322 static const int kInfinity = (1 << 30); |
| 1304 private: | 1323 private: |
| 1305 int min_; | 1324 int min_; |
| 1306 int max_; | 1325 int max_; |
| 1307 bool is_greedy_; | 1326 bool is_greedy_; |
| 1308 RegExpTree* body_; | 1327 RegExpTree* body_; |
| 1309 }; | 1328 }; |
| 1310 | 1329 |
| 1311 | 1330 |
| 1312 class RegExpCapture: public RegExpTree { | 1331 class RegExpCapture: public RegExpTree { |
| 1313 public: | 1332 public: |
| 1314 explicit RegExpCapture(RegExpTree* body, int index) | 1333 explicit RegExpCapture(RegExpTree* body, int index) |
| 1315 : body_(body), index_(index) { } | 1334 : body_(body), index_(index) { } |
| 1316 virtual void* Accept(RegExpVisitor* visitor, void* data); | 1335 virtual void* Accept(RegExpVisitor* visitor, void* data); |
| 1336 virtual RegExpNode* ToNode(RegExpCompiler* compiler, | |
| 1337 RegExpNode* on_success, | |
| 1338 RegExpNode* on_failure); | |
| 1317 virtual RegExpCapture* AsCapture(); | 1339 virtual RegExpCapture* AsCapture(); |
| 1318 RegExpTree* body() { return body_; } | 1340 RegExpTree* body() { return body_; } |
| 1319 int index() { return index_; } | 1341 int index() { return index_; } |
| 1342 static int StartRegister(int index) { return (index - 1) * 2; } | |
| 1343 static int EndRegister(int index) { return (index - 1) * 2 + 1; } | |
| 1320 private: | 1344 private: |
| 1321 RegExpTree* body_; | 1345 RegExpTree* body_; |
| 1322 int index_; | 1346 int index_; |
| 1323 }; | 1347 }; |
| 1324 | 1348 |
| 1325 | 1349 |
| 1326 class RegExpLookahead: public RegExpTree { | 1350 class RegExpLookahead: public RegExpTree { |
| 1327 public: | 1351 public: |
| 1328 RegExpLookahead(RegExpTree* body, bool is_positive) | 1352 RegExpLookahead(RegExpTree* body, bool is_positive) |
| 1329 : body_(body), | 1353 : body_(body), |
| 1330 is_positive_(is_positive) { } | 1354 is_positive_(is_positive) { } |
| 1331 virtual void* Accept(RegExpVisitor* visitor, void* data); | 1355 virtual void* Accept(RegExpVisitor* visitor, void* data); |
| 1356 virtual RegExpNode* ToNode(RegExpCompiler* compiler, | |
| 1357 RegExpNode* on_success, | |
| 1358 RegExpNode* on_failure); | |
| 1332 virtual RegExpLookahead* AsLookahead(); | 1359 virtual RegExpLookahead* AsLookahead(); |
| 1333 RegExpTree* body() { return body_; } | 1360 RegExpTree* body() { return body_; } |
| 1334 bool is_positive() { return is_positive_; } | 1361 bool is_positive() { return is_positive_; } |
| 1335 private: | 1362 private: |
| 1336 RegExpTree* body_; | 1363 RegExpTree* body_; |
| 1337 bool is_positive_; | 1364 bool is_positive_; |
| 1338 }; | 1365 }; |
| 1339 | 1366 |
| 1340 | 1367 |
| 1341 class RegExpBackreference: public RegExpTree { | 1368 class RegExpBackreference: public RegExpTree { |
| 1342 public: | 1369 public: |
| 1343 explicit RegExpBackreference(int index) : index_(index) { } | 1370 explicit RegExpBackreference(int index) : index_(index) { } |
| 1344 virtual void* Accept(RegExpVisitor* visitor, void* data); | 1371 virtual void* Accept(RegExpVisitor* visitor, void* data); |
| 1372 virtual RegExpNode* ToNode(RegExpCompiler* compiler, | |
| 1373 RegExpNode* on_success, | |
| 1374 RegExpNode* on_failure); | |
| 1345 virtual RegExpBackreference* AsBackreference(); | 1375 virtual RegExpBackreference* AsBackreference(); |
| 1346 int index() { return index_; } | 1376 int index() { return index_; } |
| 1347 private: | 1377 private: |
| 1348 int index_; | 1378 int index_; |
| 1349 }; | 1379 }; |
| 1350 | 1380 |
| 1351 | 1381 |
| 1352 class RegExpEmpty: public RegExpTree { | 1382 class RegExpEmpty: public RegExpTree { |
| 1353 public: | 1383 public: |
| 1354 RegExpEmpty() { } | 1384 RegExpEmpty() { } |
| 1355 virtual void* Accept(RegExpVisitor* visitor, void* data); | 1385 virtual void* Accept(RegExpVisitor* visitor, void* data); |
| 1386 virtual RegExpNode* ToNode(RegExpCompiler* compiler, | |
| 1387 RegExpNode* on_success, | |
| 1388 RegExpNode* on_failure); | |
| 1356 virtual RegExpEmpty* AsEmpty(); | 1389 virtual RegExpEmpty* AsEmpty(); |
| 1357 static RegExpEmpty* GetInstance() { return &kInstance; } | 1390 static RegExpEmpty* GetInstance() { return &kInstance; } |
| 1358 private: | 1391 private: |
| 1359 static RegExpEmpty kInstance; | 1392 static RegExpEmpty kInstance; |
| 1360 }; | 1393 }; |
| 1361 | 1394 |
| 1362 | 1395 |
| 1363 class RegExpVisitor BASE_EMBEDDED { | 1396 class RegExpVisitor BASE_EMBEDDED { |
| 1364 public: | 1397 public: |
| 1365 virtual ~RegExpVisitor() { } | 1398 virtual ~RegExpVisitor() { } |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1408 #undef DEF_VISIT | 1441 #undef DEF_VISIT |
| 1409 | 1442 |
| 1410 private: | 1443 private: |
| 1411 bool stack_overflow_; | 1444 bool stack_overflow_; |
| 1412 }; | 1445 }; |
| 1413 | 1446 |
| 1414 | 1447 |
| 1415 } } // namespace v8::internal | 1448 } } // namespace v8::internal |
| 1416 | 1449 |
| 1417 #endif // V8_AST_H_ | 1450 #endif // V8_AST_H_ |
| OLD | NEW |