OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef V8_AST_H_ | 5 #ifndef V8_AST_H_ |
6 #define V8_AST_H_ | 6 #define V8_AST_H_ |
7 | 7 |
8 #include "src/v8.h" | 8 #include "src/v8.h" |
9 | 9 |
10 #include "src/assembler.h" | 10 #include "src/assembler.h" |
(...skipping 1439 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1450 // for minimizing the work when constructing it at runtime. | 1450 // for minimizing the work when constructing it at runtime. |
1451 class ObjectLiteral FINAL : public MaterializedLiteral { | 1451 class ObjectLiteral FINAL : public MaterializedLiteral { |
1452 public: | 1452 public: |
1453 typedef ObjectLiteralProperty Property; | 1453 typedef ObjectLiteralProperty Property; |
1454 | 1454 |
1455 DECLARE_NODE_TYPE(ObjectLiteral) | 1455 DECLARE_NODE_TYPE(ObjectLiteral) |
1456 | 1456 |
1457 Handle<FixedArray> constant_properties() const { | 1457 Handle<FixedArray> constant_properties() const { |
1458 return constant_properties_; | 1458 return constant_properties_; |
1459 } | 1459 } |
| 1460 int properties_count() const { return constant_properties_->length() / 2; } |
1460 ZoneList<Property*>* properties() const { return properties_; } | 1461 ZoneList<Property*>* properties() const { return properties_; } |
1461 bool fast_elements() const { return fast_elements_; } | 1462 bool fast_elements() const { return fast_elements_; } |
1462 bool may_store_doubles() const { return may_store_doubles_; } | 1463 bool may_store_doubles() const { return may_store_doubles_; } |
1463 bool has_function() const { return has_function_; } | 1464 bool has_function() const { return has_function_; } |
| 1465 bool has_elements() const { return has_elements_; } |
1464 | 1466 |
1465 // Decide if a property should be in the object boilerplate. | 1467 // Decide if a property should be in the object boilerplate. |
1466 static bool IsBoilerplateProperty(Property* property); | 1468 static bool IsBoilerplateProperty(Property* property); |
1467 | 1469 |
1468 // Populate the constant properties fixed array. | 1470 // Populate the constant properties fixed array. |
1469 void BuildConstantProperties(Isolate* isolate); | 1471 void BuildConstantProperties(Isolate* isolate); |
1470 | 1472 |
1471 // Mark all computed expressions that are bound to a key that | 1473 // Mark all computed expressions that are bound to a key that |
1472 // is shadowed by a later occurrence of the same key. For the | 1474 // is shadowed by a later occurrence of the same key. For the |
1473 // marked expressions, no store code is emitted. | 1475 // marked expressions, no store code is emitted. |
1474 void CalculateEmitStore(Zone* zone); | 1476 void CalculateEmitStore(Zone* zone); |
1475 | 1477 |
1476 // Assemble bitfield of flags for the CreateObjectLiteral helper. | 1478 // Assemble bitfield of flags for the CreateObjectLiteral helper. |
1477 int ComputeFlags() const { | 1479 int ComputeFlags(bool disable_mementos = false) const { |
1478 int flags = fast_elements() ? kFastElements : kNoFlags; | 1480 int flags = fast_elements() ? kFastElements : kNoFlags; |
1479 flags |= has_function() ? kHasFunction : kNoFlags; | 1481 flags |= has_function() ? kHasFunction : kNoFlags; |
| 1482 if (disable_mementos) { |
| 1483 flags |= kDisableMementos; |
| 1484 } |
1480 return flags; | 1485 return flags; |
1481 } | 1486 } |
1482 | 1487 |
1483 enum Flags { | 1488 enum Flags { |
1484 kNoFlags = 0, | 1489 kNoFlags = 0, |
1485 kFastElements = 1, | 1490 kFastElements = 1, |
1486 kHasFunction = 1 << 1 | 1491 kHasFunction = 1 << 1, |
| 1492 kDisableMementos = 1 << 2 |
1487 }; | 1493 }; |
1488 | 1494 |
1489 struct Accessors: public ZoneObject { | 1495 struct Accessors: public ZoneObject { |
1490 Accessors() : getter(NULL), setter(NULL) {} | 1496 Accessors() : getter(NULL), setter(NULL) {} |
1491 Expression* getter; | 1497 Expression* getter; |
1492 Expression* setter; | 1498 Expression* setter; |
1493 }; | 1499 }; |
1494 | 1500 |
1495 BailoutId CreateLiteralId() const { return BailoutId(local_id(0)); } | 1501 BailoutId CreateLiteralId() const { return BailoutId(local_id(0)); } |
1496 | 1502 |
1497 // Return an AST id for a property that is used in simulate instructions. | 1503 // Return an AST id for a property that is used in simulate instructions. |
1498 BailoutId GetIdForProperty(int i) { return BailoutId(local_id(i + 1)); } | 1504 BailoutId GetIdForProperty(int i) { return BailoutId(local_id(i + 1)); } |
1499 | 1505 |
1500 // Unlike other AST nodes, this number of bailout IDs allocated for an | 1506 // Unlike other AST nodes, this number of bailout IDs allocated for an |
1501 // ObjectLiteral can vary, so num_ids() is not a static method. | 1507 // ObjectLiteral can vary, so num_ids() is not a static method. |
1502 int num_ids() const { return parent_num_ids() + 1 + properties()->length(); } | 1508 int num_ids() const { return parent_num_ids() + 1 + properties()->length(); } |
1503 | 1509 |
1504 protected: | 1510 protected: |
1505 ObjectLiteral(Zone* zone, ZoneList<Property*>* properties, int literal_index, | 1511 ObjectLiteral(Zone* zone, ZoneList<Property*>* properties, int literal_index, |
1506 int boilerplate_properties, bool has_function, int pos) | 1512 int boilerplate_properties, bool has_function, int pos) |
1507 : MaterializedLiteral(zone, literal_index, pos), | 1513 : MaterializedLiteral(zone, literal_index, pos), |
1508 properties_(properties), | 1514 properties_(properties), |
1509 boilerplate_properties_(boilerplate_properties), | 1515 boilerplate_properties_(boilerplate_properties), |
1510 fast_elements_(false), | 1516 fast_elements_(false), |
| 1517 has_elements_(false), |
1511 may_store_doubles_(false), | 1518 may_store_doubles_(false), |
1512 has_function_(has_function) {} | 1519 has_function_(has_function) {} |
1513 static int parent_num_ids() { return MaterializedLiteral::num_ids(); } | 1520 static int parent_num_ids() { return MaterializedLiteral::num_ids(); } |
1514 | 1521 |
1515 private: | 1522 private: |
1516 int local_id(int n) const { return base_id() + parent_num_ids() + n; } | 1523 int local_id(int n) const { return base_id() + parent_num_ids() + n; } |
1517 Handle<FixedArray> constant_properties_; | 1524 Handle<FixedArray> constant_properties_; |
1518 ZoneList<Property*>* properties_; | 1525 ZoneList<Property*>* properties_; |
1519 int boilerplate_properties_; | 1526 int boilerplate_properties_; |
1520 bool fast_elements_; | 1527 bool fast_elements_; |
| 1528 bool has_elements_; |
1521 bool may_store_doubles_; | 1529 bool may_store_doubles_; |
1522 bool has_function_; | 1530 bool has_function_; |
1523 }; | 1531 }; |
1524 | 1532 |
1525 | 1533 |
1526 // Node for capturing a regexp literal. | 1534 // Node for capturing a regexp literal. |
1527 class RegExpLiteral FINAL : public MaterializedLiteral { | 1535 class RegExpLiteral FINAL : public MaterializedLiteral { |
1528 public: | 1536 public: |
1529 DECLARE_NODE_TYPE(RegExpLiteral) | 1537 DECLARE_NODE_TYPE(RegExpLiteral) |
1530 | 1538 |
(...skipping 15 matching lines...) Expand all Loading... |
1546 }; | 1554 }; |
1547 | 1555 |
1548 | 1556 |
1549 // An array literal has a literals object that is used | 1557 // An array literal has a literals object that is used |
1550 // for minimizing the work when constructing it at runtime. | 1558 // for minimizing the work when constructing it at runtime. |
1551 class ArrayLiteral FINAL : public MaterializedLiteral { | 1559 class ArrayLiteral FINAL : public MaterializedLiteral { |
1552 public: | 1560 public: |
1553 DECLARE_NODE_TYPE(ArrayLiteral) | 1561 DECLARE_NODE_TYPE(ArrayLiteral) |
1554 | 1562 |
1555 Handle<FixedArray> constant_elements() const { return constant_elements_; } | 1563 Handle<FixedArray> constant_elements() const { return constant_elements_; } |
| 1564 ElementsKind constant_elements_kind() const { |
| 1565 DCHECK_EQ(2, constant_elements_->length()); |
| 1566 return static_cast<ElementsKind>( |
| 1567 Smi::cast(constant_elements_->get(0))->value()); |
| 1568 } |
| 1569 |
1556 ZoneList<Expression*>* values() const { return values_; } | 1570 ZoneList<Expression*>* values() const { return values_; } |
1557 | 1571 |
1558 BailoutId CreateLiteralId() const { return BailoutId(local_id(0)); } | 1572 BailoutId CreateLiteralId() const { return BailoutId(local_id(0)); } |
1559 | 1573 |
1560 // Return an AST id for an element that is used in simulate instructions. | 1574 // Return an AST id for an element that is used in simulate instructions. |
1561 BailoutId GetIdForElement(int i) { return BailoutId(local_id(i + 1)); } | 1575 BailoutId GetIdForElement(int i) { return BailoutId(local_id(i + 1)); } |
1562 | 1576 |
1563 // Unlike other AST nodes, this number of bailout IDs allocated for an | 1577 // Unlike other AST nodes, this number of bailout IDs allocated for an |
1564 // ArrayLiteral can vary, so num_ids() is not a static method. | 1578 // ArrayLiteral can vary, so num_ids() is not a static method. |
1565 int num_ids() const { return parent_num_ids() + 1 + values()->length(); } | 1579 int num_ids() const { return parent_num_ids() + 1 + values()->length(); } |
1566 | 1580 |
1567 // Populate the constant elements fixed array. | 1581 // Populate the constant elements fixed array. |
1568 void BuildConstantElements(Isolate* isolate); | 1582 void BuildConstantElements(Isolate* isolate); |
1569 | 1583 |
1570 // Assemble bitfield of flags for the CreateArrayLiteral helper. | 1584 // Assemble bitfield of flags for the CreateArrayLiteral helper. |
1571 int ComputeFlags() const { | 1585 int ComputeFlags(bool disable_mementos = false) const { |
1572 int flags = depth() == 1 ? kShallowElements : kNoFlags; | 1586 int flags = depth() == 1 ? kShallowElements : kNoFlags; |
1573 flags |= ArrayLiteral::kDisableMementos; | 1587 if (disable_mementos) { |
| 1588 flags |= kDisableMementos; |
| 1589 } |
1574 return flags; | 1590 return flags; |
1575 } | 1591 } |
1576 | 1592 |
1577 enum Flags { | 1593 enum Flags { |
1578 kNoFlags = 0, | 1594 kNoFlags = 0, |
1579 kShallowElements = 1, | 1595 kShallowElements = 1, |
1580 kDisableMementos = 1 << 1 | 1596 kDisableMementos = 1 << 1 |
1581 }; | 1597 }; |
1582 | 1598 |
1583 protected: | 1599 protected: |
(...skipping 1906 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3490 | 3506 |
3491 private: | 3507 private: |
3492 Zone* zone_; | 3508 Zone* zone_; |
3493 AstValueFactory* ast_value_factory_; | 3509 AstValueFactory* ast_value_factory_; |
3494 }; | 3510 }; |
3495 | 3511 |
3496 | 3512 |
3497 } } // namespace v8::internal | 3513 } } // namespace v8::internal |
3498 | 3514 |
3499 #endif // V8_AST_H_ | 3515 #endif // V8_AST_H_ |
OLD | NEW |