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 1196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1207 class ThisFunction: public Expression { | 1207 class ThisFunction: public Expression { |
1208 public: | 1208 public: |
1209 virtual void Accept(AstVisitor* v); | 1209 virtual void Accept(AstVisitor* v); |
1210 }; | 1210 }; |
1211 | 1211 |
1212 | 1212 |
1213 // ---------------------------------------------------------------------------- | 1213 // ---------------------------------------------------------------------------- |
1214 // Regular expressions | 1214 // Regular expressions |
1215 | 1215 |
1216 | 1216 |
| 1217 class RegExpVisitor BASE_EMBEDDED { |
| 1218 public: |
| 1219 virtual ~RegExpVisitor() { } |
| 1220 #define MAKE_CASE(Name) \ |
| 1221 virtual void* Visit##Name(RegExp##Name*, void* data) = 0; |
| 1222 FOR_EACH_REG_EXP_TREE_TYPE(MAKE_CASE) |
| 1223 #undef MAKE_CASE |
| 1224 }; |
| 1225 |
| 1226 |
1217 class RegExpTree: public ZoneObject { | 1227 class RegExpTree: public ZoneObject { |
1218 public: | 1228 public: |
1219 static const int kInfinity = kMaxInt; | 1229 static const int kInfinity = kMaxInt; |
1220 virtual ~RegExpTree() { } | 1230 virtual ~RegExpTree() { } |
1221 virtual void* Accept(RegExpVisitor* visitor, void* data) = 0; | 1231 virtual void* Accept(RegExpVisitor* visitor, void* data) = 0; |
1222 virtual RegExpNode* ToNode(RegExpCompiler* compiler, | 1232 virtual RegExpNode* ToNode(RegExpCompiler* compiler, |
1223 RegExpNode* on_success) = 0; | 1233 RegExpNode* on_success) = 0; |
1224 virtual bool IsTextElement() { return false; } | 1234 virtual bool IsTextElement() { return false; } |
1225 virtual int min_match() = 0; | 1235 virtual int min_match() = 0; |
1226 virtual int max_match() = 0; | 1236 virtual int max_match() = 0; |
| 1237 // Returns the interval of registers used for captures within this |
| 1238 // expression. |
| 1239 virtual Interval CaptureRegisters() { return Interval::Empty(); } |
1227 virtual void AppendToText(RegExpText* text); | 1240 virtual void AppendToText(RegExpText* text); |
1228 SmartPointer<const char> ToString(); | 1241 SmartPointer<const char> ToString(); |
1229 #define MAKE_ASTYPE(Name) \ | 1242 #define MAKE_ASTYPE(Name) \ |
1230 virtual RegExp##Name* As##Name(); \ | 1243 virtual RegExp##Name* As##Name(); \ |
1231 virtual bool Is##Name(); | 1244 virtual bool Is##Name(); |
1232 FOR_EACH_REG_EXP_TREE_TYPE(MAKE_ASTYPE) | 1245 FOR_EACH_REG_EXP_TREE_TYPE(MAKE_ASTYPE) |
1233 #undef MAKE_ASTYPE | 1246 #undef MAKE_ASTYPE |
1234 }; | 1247 }; |
1235 | 1248 |
1236 | 1249 |
1237 class RegExpDisjunction: public RegExpTree { | 1250 class RegExpDisjunction: public RegExpTree { |
1238 public: | 1251 public: |
1239 explicit RegExpDisjunction(ZoneList<RegExpTree*>* alternatives); | 1252 explicit RegExpDisjunction(ZoneList<RegExpTree*>* alternatives); |
1240 virtual void* Accept(RegExpVisitor* visitor, void* data); | 1253 virtual void* Accept(RegExpVisitor* visitor, void* data); |
1241 virtual RegExpNode* ToNode(RegExpCompiler* compiler, | 1254 virtual RegExpNode* ToNode(RegExpCompiler* compiler, |
1242 RegExpNode* on_success); | 1255 RegExpNode* on_success); |
1243 virtual RegExpDisjunction* AsDisjunction(); | 1256 virtual RegExpDisjunction* AsDisjunction(); |
| 1257 virtual Interval CaptureRegisters(); |
1244 virtual bool IsDisjunction(); | 1258 virtual bool IsDisjunction(); |
1245 virtual int min_match() { return min_match_; } | 1259 virtual int min_match() { return min_match_; } |
1246 virtual int max_match() { return max_match_; } | 1260 virtual int max_match() { return max_match_; } |
1247 ZoneList<RegExpTree*>* alternatives() { return alternatives_; } | 1261 ZoneList<RegExpTree*>* alternatives() { return alternatives_; } |
1248 private: | 1262 private: |
1249 ZoneList<RegExpTree*>* alternatives_; | 1263 ZoneList<RegExpTree*>* alternatives_; |
1250 int min_match_; | 1264 int min_match_; |
1251 int max_match_; | 1265 int max_match_; |
1252 }; | 1266 }; |
1253 | 1267 |
1254 | 1268 |
1255 class RegExpAlternative: public RegExpTree { | 1269 class RegExpAlternative: public RegExpTree { |
1256 public: | 1270 public: |
1257 explicit RegExpAlternative(ZoneList<RegExpTree*>* nodes); | 1271 explicit RegExpAlternative(ZoneList<RegExpTree*>* nodes); |
1258 virtual void* Accept(RegExpVisitor* visitor, void* data); | 1272 virtual void* Accept(RegExpVisitor* visitor, void* data); |
1259 virtual RegExpNode* ToNode(RegExpCompiler* compiler, | 1273 virtual RegExpNode* ToNode(RegExpCompiler* compiler, |
1260 RegExpNode* on_success); | 1274 RegExpNode* on_success); |
1261 virtual RegExpAlternative* AsAlternative(); | 1275 virtual RegExpAlternative* AsAlternative(); |
| 1276 virtual Interval CaptureRegisters(); |
1262 virtual bool IsAlternative(); | 1277 virtual bool IsAlternative(); |
1263 virtual int min_match() { return min_match_; } | 1278 virtual int min_match() { return min_match_; } |
1264 virtual int max_match() { return max_match_; } | 1279 virtual int max_match() { return max_match_; } |
1265 ZoneList<RegExpTree*>* nodes() { return nodes_; } | 1280 ZoneList<RegExpTree*>* nodes() { return nodes_; } |
1266 private: | 1281 private: |
1267 ZoneList<RegExpTree*>* nodes_; | 1282 ZoneList<RegExpTree*>* nodes_; |
1268 int min_match_; | 1283 int min_match_; |
1269 int max_match_; | 1284 int max_match_; |
1270 }; | 1285 }; |
1271 | 1286 |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1416 virtual void* Accept(RegExpVisitor* visitor, void* data); | 1431 virtual void* Accept(RegExpVisitor* visitor, void* data); |
1417 virtual RegExpNode* ToNode(RegExpCompiler* compiler, | 1432 virtual RegExpNode* ToNode(RegExpCompiler* compiler, |
1418 RegExpNode* on_success); | 1433 RegExpNode* on_success); |
1419 static RegExpNode* ToNode(int min, | 1434 static RegExpNode* ToNode(int min, |
1420 int max, | 1435 int max, |
1421 bool is_greedy, | 1436 bool is_greedy, |
1422 RegExpTree* body, | 1437 RegExpTree* body, |
1423 RegExpCompiler* compiler, | 1438 RegExpCompiler* compiler, |
1424 RegExpNode* on_success); | 1439 RegExpNode* on_success); |
1425 virtual RegExpQuantifier* AsQuantifier(); | 1440 virtual RegExpQuantifier* AsQuantifier(); |
| 1441 virtual Interval CaptureRegisters(); |
1426 virtual bool IsQuantifier(); | 1442 virtual bool IsQuantifier(); |
1427 virtual int min_match() { return min_match_; } | 1443 virtual int min_match() { return min_match_; } |
1428 virtual int max_match() { return max_match_; } | 1444 virtual int max_match() { return max_match_; } |
1429 int min() { return min_; } | 1445 int min() { return min_; } |
1430 int max() { return max_; } | 1446 int max() { return max_; } |
1431 bool is_greedy() { return is_greedy_; } | 1447 bool is_greedy() { return is_greedy_; } |
1432 RegExpTree* body() { return body_; } | 1448 RegExpTree* body() { return body_; } |
1433 private: | 1449 private: |
1434 int min_; | 1450 int min_; |
1435 int max_; | 1451 int max_; |
(...skipping 15 matching lines...) Expand all Loading... |
1451 explicit RegExpCapture(RegExpTree* body, int index) | 1467 explicit RegExpCapture(RegExpTree* body, int index) |
1452 : body_(body), index_(index), available_(CAPTURE_AVAILABLE) { } | 1468 : body_(body), index_(index), available_(CAPTURE_AVAILABLE) { } |
1453 virtual void* Accept(RegExpVisitor* visitor, void* data); | 1469 virtual void* Accept(RegExpVisitor* visitor, void* data); |
1454 virtual RegExpNode* ToNode(RegExpCompiler* compiler, | 1470 virtual RegExpNode* ToNode(RegExpCompiler* compiler, |
1455 RegExpNode* on_success); | 1471 RegExpNode* on_success); |
1456 static RegExpNode* ToNode(RegExpTree* body, | 1472 static RegExpNode* ToNode(RegExpTree* body, |
1457 int index, | 1473 int index, |
1458 RegExpCompiler* compiler, | 1474 RegExpCompiler* compiler, |
1459 RegExpNode* on_success); | 1475 RegExpNode* on_success); |
1460 virtual RegExpCapture* AsCapture(); | 1476 virtual RegExpCapture* AsCapture(); |
| 1477 virtual Interval CaptureRegisters(); |
1461 virtual bool IsCapture(); | 1478 virtual bool IsCapture(); |
1462 virtual int min_match() { return body_->min_match(); } | 1479 virtual int min_match() { return body_->min_match(); } |
1463 virtual int max_match() { return body_->max_match(); } | 1480 virtual int max_match() { return body_->max_match(); } |
1464 RegExpTree* body() { return body_; } | 1481 RegExpTree* body() { return body_; } |
1465 int index() { return index_; } | 1482 int index() { return index_; } |
1466 inline CaptureAvailability available() { return available_; } | 1483 inline CaptureAvailability available() { return available_; } |
1467 inline void set_available(CaptureAvailability availability) { | 1484 inline void set_available(CaptureAvailability availability) { |
1468 available_ = availability; | 1485 available_ = availability; |
1469 } | 1486 } |
1470 static int StartRegister(int index) { return index * 2; } | 1487 static int StartRegister(int index) { return index * 2; } |
1471 static int EndRegister(int index) { return index * 2 + 1; } | 1488 static int EndRegister(int index) { return index * 2 + 1; } |
1472 private: | 1489 private: |
1473 RegExpTree* body_; | 1490 RegExpTree* body_; |
1474 int index_; | 1491 int index_; |
1475 CaptureAvailability available_; | 1492 CaptureAvailability available_; |
1476 }; | 1493 }; |
1477 | 1494 |
1478 | 1495 |
1479 class RegExpLookahead: public RegExpTree { | 1496 class RegExpLookahead: public RegExpTree { |
1480 public: | 1497 public: |
1481 RegExpLookahead(RegExpTree* body, bool is_positive) | 1498 RegExpLookahead(RegExpTree* body, bool is_positive) |
1482 : body_(body), | 1499 : body_(body), |
1483 is_positive_(is_positive) { } | 1500 is_positive_(is_positive) { } |
1484 virtual void* Accept(RegExpVisitor* visitor, void* data); | 1501 virtual void* Accept(RegExpVisitor* visitor, void* data); |
1485 virtual RegExpNode* ToNode(RegExpCompiler* compiler, | 1502 virtual RegExpNode* ToNode(RegExpCompiler* compiler, |
1486 RegExpNode* on_success); | 1503 RegExpNode* on_success); |
1487 virtual RegExpLookahead* AsLookahead(); | 1504 virtual RegExpLookahead* AsLookahead(); |
| 1505 virtual Interval CaptureRegisters(); |
1488 virtual bool IsLookahead(); | 1506 virtual bool IsLookahead(); |
1489 virtual int min_match() { return 0; } | 1507 virtual int min_match() { return 0; } |
1490 virtual int max_match() { return 0; } | 1508 virtual int max_match() { return 0; } |
1491 RegExpTree* body() { return body_; } | 1509 RegExpTree* body() { return body_; } |
1492 bool is_positive() { return is_positive_; } | 1510 bool is_positive() { return is_positive_; } |
1493 private: | 1511 private: |
1494 RegExpTree* body_; | 1512 RegExpTree* body_; |
1495 bool is_positive_; | 1513 bool is_positive_; |
1496 }; | 1514 }; |
1497 | 1515 |
(...skipping 25 matching lines...) Expand all Loading... |
1523 virtual RegExpEmpty* AsEmpty(); | 1541 virtual RegExpEmpty* AsEmpty(); |
1524 virtual bool IsEmpty(); | 1542 virtual bool IsEmpty(); |
1525 virtual int min_match() { return 0; } | 1543 virtual int min_match() { return 0; } |
1526 virtual int max_match() { return 0; } | 1544 virtual int max_match() { return 0; } |
1527 static RegExpEmpty* GetInstance() { return &kInstance; } | 1545 static RegExpEmpty* GetInstance() { return &kInstance; } |
1528 private: | 1546 private: |
1529 static RegExpEmpty kInstance; | 1547 static RegExpEmpty kInstance; |
1530 }; | 1548 }; |
1531 | 1549 |
1532 | 1550 |
1533 class RegExpVisitor BASE_EMBEDDED { | |
1534 public: | |
1535 virtual ~RegExpVisitor() { } | |
1536 #define MAKE_CASE(Name) \ | |
1537 virtual void* Visit##Name(RegExp##Name*, void* data) = 0; | |
1538 FOR_EACH_REG_EXP_TREE_TYPE(MAKE_CASE) | |
1539 #undef MAKE_CASE | |
1540 }; | |
1541 | |
1542 | |
1543 // ---------------------------------------------------------------------------- | 1551 // ---------------------------------------------------------------------------- |
1544 // Basic visitor | 1552 // Basic visitor |
1545 // - leaf node visitors are abstract. | 1553 // - leaf node visitors are abstract. |
1546 | 1554 |
1547 class AstVisitor BASE_EMBEDDED { | 1555 class AstVisitor BASE_EMBEDDED { |
1548 public: | 1556 public: |
1549 AstVisitor() : stack_overflow_(false) { } | 1557 AstVisitor() : stack_overflow_(false) { } |
1550 virtual ~AstVisitor() { } | 1558 virtual ~AstVisitor() { } |
1551 | 1559 |
1552 // Dispatch | 1560 // Dispatch |
(...skipping 25 matching lines...) Expand all Loading... |
1578 #undef DEF_VISIT | 1586 #undef DEF_VISIT |
1579 | 1587 |
1580 private: | 1588 private: |
1581 bool stack_overflow_; | 1589 bool stack_overflow_; |
1582 }; | 1590 }; |
1583 | 1591 |
1584 | 1592 |
1585 } } // namespace v8::internal | 1593 } } // namespace v8::internal |
1586 | 1594 |
1587 #endif // V8_AST_H_ | 1595 #endif // V8_AST_H_ |
OLD | NEW |