| 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 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 71 V(DebuggerStatement) \ | 71 V(DebuggerStatement) \ |
| 72 V(FunctionLiteral) \ | 72 V(FunctionLiteral) \ |
| 73 V(FunctionBoilerplateLiteral) \ | 73 V(FunctionBoilerplateLiteral) \ |
| 74 V(Conditional) \ | 74 V(Conditional) \ |
| 75 V(Slot) \ | 75 V(Slot) \ |
| 76 V(VariableProxy) \ | 76 V(VariableProxy) \ |
| 77 V(Literal) \ | 77 V(Literal) \ |
| 78 V(RegExpLiteral) \ | 78 V(RegExpLiteral) \ |
| 79 V(ObjectLiteral) \ | 79 V(ObjectLiteral) \ |
| 80 V(ArrayLiteral) \ | 80 V(ArrayLiteral) \ |
| 81 V(CatchExtensionObject) \ |
| 81 V(Assignment) \ | 82 V(Assignment) \ |
| 82 V(Throw) \ | 83 V(Throw) \ |
| 83 V(Property) \ | 84 V(Property) \ |
| 84 V(Call) \ | 85 V(Call) \ |
| 85 V(CallEval) \ | 86 V(CallEval) \ |
| 86 V(CallNew) \ | 87 V(CallNew) \ |
| 87 V(CallRuntime) \ | 88 V(CallRuntime) \ |
| 88 V(UnaryOperation) \ | 89 V(UnaryOperation) \ |
| 89 V(CountOperation) \ | 90 V(CountOperation) \ |
| 90 V(BinaryOperation) \ | 91 V(BinaryOperation) \ |
| (...skipping 630 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 721 | 722 |
| 722 Handle<FixedArray> literals() const { return literals_; } | 723 Handle<FixedArray> literals() const { return literals_; } |
| 723 ZoneList<Expression*>* values() const { return values_; } | 724 ZoneList<Expression*>* values() const { return values_; } |
| 724 | 725 |
| 725 private: | 726 private: |
| 726 Handle<FixedArray> literals_; | 727 Handle<FixedArray> literals_; |
| 727 ZoneList<Expression*>* values_; | 728 ZoneList<Expression*>* values_; |
| 728 }; | 729 }; |
| 729 | 730 |
| 730 | 731 |
| 732 // Node for constructing a context extension object for a catch block. |
| 733 // The catch context extension object has one property, the catch |
| 734 // variable, which should be DontDelete. |
| 735 class CatchExtensionObject: public Expression { |
| 736 public: |
| 737 CatchExtensionObject(Literal* key, VariableProxy* value) |
| 738 : key_(key), value_(value) { |
| 739 } |
| 740 |
| 741 virtual void Accept(AstVisitor* v); |
| 742 |
| 743 Literal* key() const { return key_; } |
| 744 VariableProxy* value() const { return value_; } |
| 745 |
| 746 private: |
| 747 Literal* key_; |
| 748 VariableProxy* value_; |
| 749 }; |
| 750 |
| 751 |
| 731 class VariableProxy: public Expression { | 752 class VariableProxy: public Expression { |
| 732 public: | 753 public: |
| 733 virtual void Accept(AstVisitor* v); | 754 virtual void Accept(AstVisitor* v); |
| 734 | 755 |
| 735 // Type testing & conversion | 756 // Type testing & conversion |
| 736 virtual Property* AsProperty() { | 757 virtual Property* AsProperty() { |
| 737 return var_ == NULL ? NULL : var_->AsProperty(); | 758 return var_ == NULL ? NULL : var_->AsProperty(); |
| 738 } | 759 } |
| 739 virtual VariableProxy* AsVariableProxy() { return this; } | 760 virtual VariableProxy* AsVariableProxy() { return this; } |
| 740 | 761 |
| (...skipping 490 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1231 | 1252 |
| 1232 | 1253 |
| 1233 class RegExpTree: public ZoneObject { | 1254 class RegExpTree: public ZoneObject { |
| 1234 public: | 1255 public: |
| 1235 static const int kInfinity = kMaxInt; | 1256 static const int kInfinity = kMaxInt; |
| 1236 virtual ~RegExpTree() { } | 1257 virtual ~RegExpTree() { } |
| 1237 virtual void* Accept(RegExpVisitor* visitor, void* data) = 0; | 1258 virtual void* Accept(RegExpVisitor* visitor, void* data) = 0; |
| 1238 virtual RegExpNode* ToNode(RegExpCompiler* compiler, | 1259 virtual RegExpNode* ToNode(RegExpCompiler* compiler, |
| 1239 RegExpNode* on_success) = 0; | 1260 RegExpNode* on_success) = 0; |
| 1240 virtual bool IsTextElement() { return false; } | 1261 virtual bool IsTextElement() { return false; } |
| 1262 virtual bool IsAnchored() { return false; } |
| 1241 virtual int min_match() = 0; | 1263 virtual int min_match() = 0; |
| 1242 virtual int max_match() = 0; | 1264 virtual int max_match() = 0; |
| 1243 // Returns the interval of registers used for captures within this | 1265 // Returns the interval of registers used for captures within this |
| 1244 // expression. | 1266 // expression. |
| 1245 virtual Interval CaptureRegisters() { return Interval::Empty(); } | 1267 virtual Interval CaptureRegisters() { return Interval::Empty(); } |
| 1246 virtual void AppendToText(RegExpText* text); | 1268 virtual void AppendToText(RegExpText* text); |
| 1247 SmartPointer<const char> ToString(); | 1269 SmartPointer<const char> ToString(); |
| 1248 #define MAKE_ASTYPE(Name) \ | 1270 #define MAKE_ASTYPE(Name) \ |
| 1249 virtual RegExp##Name* As##Name(); \ | 1271 virtual RegExp##Name* As##Name(); \ |
| 1250 virtual bool Is##Name(); | 1272 virtual bool Is##Name(); |
| 1251 FOR_EACH_REG_EXP_TREE_TYPE(MAKE_ASTYPE) | 1273 FOR_EACH_REG_EXP_TREE_TYPE(MAKE_ASTYPE) |
| 1252 #undef MAKE_ASTYPE | 1274 #undef MAKE_ASTYPE |
| 1253 }; | 1275 }; |
| 1254 | 1276 |
| 1255 | 1277 |
| 1256 class RegExpDisjunction: public RegExpTree { | 1278 class RegExpDisjunction: public RegExpTree { |
| 1257 public: | 1279 public: |
| 1258 explicit RegExpDisjunction(ZoneList<RegExpTree*>* alternatives); | 1280 explicit RegExpDisjunction(ZoneList<RegExpTree*>* alternatives); |
| 1259 virtual void* Accept(RegExpVisitor* visitor, void* data); | 1281 virtual void* Accept(RegExpVisitor* visitor, void* data); |
| 1260 virtual RegExpNode* ToNode(RegExpCompiler* compiler, | 1282 virtual RegExpNode* ToNode(RegExpCompiler* compiler, |
| 1261 RegExpNode* on_success); | 1283 RegExpNode* on_success); |
| 1262 virtual RegExpDisjunction* AsDisjunction(); | 1284 virtual RegExpDisjunction* AsDisjunction(); |
| 1263 virtual Interval CaptureRegisters(); | 1285 virtual Interval CaptureRegisters(); |
| 1264 virtual bool IsDisjunction(); | 1286 virtual bool IsDisjunction(); |
| 1287 virtual bool IsAnchored(); |
| 1265 virtual int min_match() { return min_match_; } | 1288 virtual int min_match() { return min_match_; } |
| 1266 virtual int max_match() { return max_match_; } | 1289 virtual int max_match() { return max_match_; } |
| 1267 ZoneList<RegExpTree*>* alternatives() { return alternatives_; } | 1290 ZoneList<RegExpTree*>* alternatives() { return alternatives_; } |
| 1268 private: | 1291 private: |
| 1269 ZoneList<RegExpTree*>* alternatives_; | 1292 ZoneList<RegExpTree*>* alternatives_; |
| 1270 int min_match_; | 1293 int min_match_; |
| 1271 int max_match_; | 1294 int max_match_; |
| 1272 }; | 1295 }; |
| 1273 | 1296 |
| 1274 | 1297 |
| 1275 class RegExpAlternative: public RegExpTree { | 1298 class RegExpAlternative: public RegExpTree { |
| 1276 public: | 1299 public: |
| 1277 explicit RegExpAlternative(ZoneList<RegExpTree*>* nodes); | 1300 explicit RegExpAlternative(ZoneList<RegExpTree*>* nodes); |
| 1278 virtual void* Accept(RegExpVisitor* visitor, void* data); | 1301 virtual void* Accept(RegExpVisitor* visitor, void* data); |
| 1279 virtual RegExpNode* ToNode(RegExpCompiler* compiler, | 1302 virtual RegExpNode* ToNode(RegExpCompiler* compiler, |
| 1280 RegExpNode* on_success); | 1303 RegExpNode* on_success); |
| 1281 virtual RegExpAlternative* AsAlternative(); | 1304 virtual RegExpAlternative* AsAlternative(); |
| 1282 virtual Interval CaptureRegisters(); | 1305 virtual Interval CaptureRegisters(); |
| 1283 virtual bool IsAlternative(); | 1306 virtual bool IsAlternative(); |
| 1307 virtual bool IsAnchored(); |
| 1284 virtual int min_match() { return min_match_; } | 1308 virtual int min_match() { return min_match_; } |
| 1285 virtual int max_match() { return max_match_; } | 1309 virtual int max_match() { return max_match_; } |
| 1286 ZoneList<RegExpTree*>* nodes() { return nodes_; } | 1310 ZoneList<RegExpTree*>* nodes() { return nodes_; } |
| 1287 private: | 1311 private: |
| 1288 ZoneList<RegExpTree*>* nodes_; | 1312 ZoneList<RegExpTree*>* nodes_; |
| 1289 int min_match_; | 1313 int min_match_; |
| 1290 int max_match_; | 1314 int max_match_; |
| 1291 }; | 1315 }; |
| 1292 | 1316 |
| 1293 | 1317 |
| 1294 class RegExpAssertion: public RegExpTree { | 1318 class RegExpAssertion: public RegExpTree { |
| 1295 public: | 1319 public: |
| 1296 enum Type { | 1320 enum Type { |
| 1297 START_OF_LINE, | 1321 START_OF_LINE, |
| 1298 START_OF_INPUT, | 1322 START_OF_INPUT, |
| 1299 END_OF_LINE, | 1323 END_OF_LINE, |
| 1300 END_OF_INPUT, | 1324 END_OF_INPUT, |
| 1301 BOUNDARY, | 1325 BOUNDARY, |
| 1302 NON_BOUNDARY | 1326 NON_BOUNDARY |
| 1303 }; | 1327 }; |
| 1304 explicit RegExpAssertion(Type type) : type_(type) { } | 1328 explicit RegExpAssertion(Type type) : type_(type) { } |
| 1305 virtual void* Accept(RegExpVisitor* visitor, void* data); | 1329 virtual void* Accept(RegExpVisitor* visitor, void* data); |
| 1306 virtual RegExpNode* ToNode(RegExpCompiler* compiler, | 1330 virtual RegExpNode* ToNode(RegExpCompiler* compiler, |
| 1307 RegExpNode* on_success); | 1331 RegExpNode* on_success); |
| 1308 virtual RegExpAssertion* AsAssertion(); | 1332 virtual RegExpAssertion* AsAssertion(); |
| 1309 virtual bool IsAssertion(); | 1333 virtual bool IsAssertion(); |
| 1334 virtual bool IsAnchored(); |
| 1310 virtual int min_match() { return 0; } | 1335 virtual int min_match() { return 0; } |
| 1311 virtual int max_match() { return 0; } | 1336 virtual int max_match() { return 0; } |
| 1312 Type type() { return type_; } | 1337 Type type() { return type_; } |
| 1313 private: | 1338 private: |
| 1314 Type type_; | 1339 Type type_; |
| 1315 }; | 1340 }; |
| 1316 | 1341 |
| 1317 | 1342 |
| 1318 class CharacterSet BASE_EMBEDDED { | 1343 class CharacterSet BASE_EMBEDDED { |
| 1319 public: | 1344 public: |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1360 bool is_standard(); | 1385 bool is_standard(); |
| 1361 // Returns a value representing the standard character set if is_standard() | 1386 // Returns a value representing the standard character set if is_standard() |
| 1362 // returns true. | 1387 // returns true. |
| 1363 // Currently used values are: | 1388 // Currently used values are: |
| 1364 // s : unicode whitespace | 1389 // s : unicode whitespace |
| 1365 // S : unicode non-whitespace | 1390 // S : unicode non-whitespace |
| 1366 // w : ASCII word character (digit, letter, underscore) | 1391 // w : ASCII word character (digit, letter, underscore) |
| 1367 // W : non-ASCII word character | 1392 // W : non-ASCII word character |
| 1368 // d : ASCII digit | 1393 // d : ASCII digit |
| 1369 // D : non-ASCII digit | 1394 // D : non-ASCII digit |
| 1370 // . : non-unicode newline | 1395 // . : non-unicode non-newline |
| 1371 // * : All characters | 1396 // * : All characters |
| 1372 uc16 standard_type() { return set_.standard_set_type(); } | 1397 uc16 standard_type() { return set_.standard_set_type(); } |
| 1373 ZoneList<CharacterRange>* ranges() { return set_.ranges(); } | 1398 ZoneList<CharacterRange>* ranges() { return set_.ranges(); } |
| 1374 bool is_negated() { return is_negated_; } | 1399 bool is_negated() { return is_negated_; } |
| 1375 private: | 1400 private: |
| 1376 CharacterSet set_; | 1401 CharacterSet set_; |
| 1377 bool is_negated_; | 1402 bool is_negated_; |
| 1378 }; | 1403 }; |
| 1379 | 1404 |
| 1380 | 1405 |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1473 explicit RegExpCapture(RegExpTree* body, int index) | 1498 explicit RegExpCapture(RegExpTree* body, int index) |
| 1474 : body_(body), index_(index), available_(CAPTURE_AVAILABLE) { } | 1499 : body_(body), index_(index), available_(CAPTURE_AVAILABLE) { } |
| 1475 virtual void* Accept(RegExpVisitor* visitor, void* data); | 1500 virtual void* Accept(RegExpVisitor* visitor, void* data); |
| 1476 virtual RegExpNode* ToNode(RegExpCompiler* compiler, | 1501 virtual RegExpNode* ToNode(RegExpCompiler* compiler, |
| 1477 RegExpNode* on_success); | 1502 RegExpNode* on_success); |
| 1478 static RegExpNode* ToNode(RegExpTree* body, | 1503 static RegExpNode* ToNode(RegExpTree* body, |
| 1479 int index, | 1504 int index, |
| 1480 RegExpCompiler* compiler, | 1505 RegExpCompiler* compiler, |
| 1481 RegExpNode* on_success); | 1506 RegExpNode* on_success); |
| 1482 virtual RegExpCapture* AsCapture(); | 1507 virtual RegExpCapture* AsCapture(); |
| 1508 virtual bool IsAnchored(); |
| 1483 virtual Interval CaptureRegisters(); | 1509 virtual Interval CaptureRegisters(); |
| 1484 virtual bool IsCapture(); | 1510 virtual bool IsCapture(); |
| 1485 virtual int min_match() { return body_->min_match(); } | 1511 virtual int min_match() { return body_->min_match(); } |
| 1486 virtual int max_match() { return body_->max_match(); } | 1512 virtual int max_match() { return body_->max_match(); } |
| 1487 RegExpTree* body() { return body_; } | 1513 RegExpTree* body() { return body_; } |
| 1488 int index() { return index_; } | 1514 int index() { return index_; } |
| 1489 inline CaptureAvailability available() { return available_; } | 1515 inline CaptureAvailability available() { return available_; } |
| 1490 inline void set_available(CaptureAvailability availability) { | 1516 inline void set_available(CaptureAvailability availability) { |
| 1491 available_ = availability; | 1517 available_ = availability; |
| 1492 } | 1518 } |
| 1493 static int StartRegister(int index) { return index * 2; } | 1519 static int StartRegister(int index) { return index * 2; } |
| 1494 static int EndRegister(int index) { return index * 2 + 1; } | 1520 static int EndRegister(int index) { return index * 2 + 1; } |
| 1495 private: | 1521 private: |
| 1496 RegExpTree* body_; | 1522 RegExpTree* body_; |
| 1497 int index_; | 1523 int index_; |
| 1498 CaptureAvailability available_; | 1524 CaptureAvailability available_; |
| 1499 }; | 1525 }; |
| 1500 | 1526 |
| 1501 | 1527 |
| 1502 class RegExpLookahead: public RegExpTree { | 1528 class RegExpLookahead: public RegExpTree { |
| 1503 public: | 1529 public: |
| 1504 RegExpLookahead(RegExpTree* body, bool is_positive) | 1530 RegExpLookahead(RegExpTree* body, |
| 1531 bool is_positive, |
| 1532 int capture_count, |
| 1533 int capture_from) |
| 1505 : body_(body), | 1534 : body_(body), |
| 1506 is_positive_(is_positive) { } | 1535 is_positive_(is_positive), |
| 1536 capture_count_(capture_count), |
| 1537 capture_from_(capture_from) { } |
| 1538 |
| 1507 virtual void* Accept(RegExpVisitor* visitor, void* data); | 1539 virtual void* Accept(RegExpVisitor* visitor, void* data); |
| 1508 virtual RegExpNode* ToNode(RegExpCompiler* compiler, | 1540 virtual RegExpNode* ToNode(RegExpCompiler* compiler, |
| 1509 RegExpNode* on_success); | 1541 RegExpNode* on_success); |
| 1510 virtual RegExpLookahead* AsLookahead(); | 1542 virtual RegExpLookahead* AsLookahead(); |
| 1511 virtual Interval CaptureRegisters(); | 1543 virtual Interval CaptureRegisters(); |
| 1512 virtual bool IsLookahead(); | 1544 virtual bool IsLookahead(); |
| 1545 virtual bool IsAnchored(); |
| 1513 virtual int min_match() { return 0; } | 1546 virtual int min_match() { return 0; } |
| 1514 virtual int max_match() { return 0; } | 1547 virtual int max_match() { return 0; } |
| 1515 RegExpTree* body() { return body_; } | 1548 RegExpTree* body() { return body_; } |
| 1516 bool is_positive() { return is_positive_; } | 1549 bool is_positive() { return is_positive_; } |
| 1550 int capture_count() { return capture_count_; } |
| 1551 int capture_from() { return capture_from_; } |
| 1517 private: | 1552 private: |
| 1518 RegExpTree* body_; | 1553 RegExpTree* body_; |
| 1519 bool is_positive_; | 1554 bool is_positive_; |
| 1555 int capture_count_; |
| 1556 int capture_from_; |
| 1520 }; | 1557 }; |
| 1521 | 1558 |
| 1522 | 1559 |
| 1523 class RegExpBackReference: public RegExpTree { | 1560 class RegExpBackReference: public RegExpTree { |
| 1524 public: | 1561 public: |
| 1525 explicit RegExpBackReference(RegExpCapture* capture) | 1562 explicit RegExpBackReference(RegExpCapture* capture) |
| 1526 : capture_(capture) { } | 1563 : capture_(capture) { } |
| 1527 virtual void* Accept(RegExpVisitor* visitor, void* data); | 1564 virtual void* Accept(RegExpVisitor* visitor, void* data); |
| 1528 virtual RegExpNode* ToNode(RegExpCompiler* compiler, | 1565 virtual RegExpNode* ToNode(RegExpCompiler* compiler, |
| 1529 RegExpNode* on_success); | 1566 RegExpNode* on_success); |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1592 #undef DEF_VISIT | 1629 #undef DEF_VISIT |
| 1593 | 1630 |
| 1594 private: | 1631 private: |
| 1595 bool stack_overflow_; | 1632 bool stack_overflow_; |
| 1596 }; | 1633 }; |
| 1597 | 1634 |
| 1598 | 1635 |
| 1599 } } // namespace v8::internal | 1636 } } // namespace v8::internal |
| 1600 | 1637 |
| 1601 #endif // V8_AST_H_ | 1638 #endif // V8_AST_H_ |
| OLD | NEW |