| 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_AST_H_ | 5 #ifndef V8_AST_AST_H_ |
| 6 #define V8_AST_AST_H_ | 6 #define V8_AST_AST_H_ |
| 7 | 7 |
| 8 #include "src/assembler.h" | 8 #include "src/assembler.h" |
| 9 #include "src/ast/ast-value-factory.h" | 9 #include "src/ast/ast-value-factory.h" |
| 10 #include "src/ast/modules.h" | 10 #include "src/ast/modules.h" |
| (...skipping 1432 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1443 | 1443 |
| 1444 DECLARE_NODE_TYPE(ObjectLiteral) | 1444 DECLARE_NODE_TYPE(ObjectLiteral) |
| 1445 | 1445 |
| 1446 Handle<FixedArray> constant_properties() const { | 1446 Handle<FixedArray> constant_properties() const { |
| 1447 return constant_properties_; | 1447 return constant_properties_; |
| 1448 } | 1448 } |
| 1449 int properties_count() const { return constant_properties_->length() / 2; } | 1449 int properties_count() const { return constant_properties_->length() / 2; } |
| 1450 ZoneList<Property*>* properties() const { return properties_; } | 1450 ZoneList<Property*>* properties() const { return properties_; } |
| 1451 bool fast_elements() const { return fast_elements_; } | 1451 bool fast_elements() const { return fast_elements_; } |
| 1452 bool may_store_doubles() const { return may_store_doubles_; } | 1452 bool may_store_doubles() const { return may_store_doubles_; } |
| 1453 bool has_function() const { return has_function_; } | |
| 1454 bool has_elements() const { return has_elements_; } | 1453 bool has_elements() const { return has_elements_; } |
| 1455 bool has_shallow_properties() const { | 1454 bool has_shallow_properties() const { |
| 1456 return depth() == 1 && !has_elements() && !may_store_doubles(); | 1455 return depth() == 1 && !has_elements() && !may_store_doubles(); |
| 1457 } | 1456 } |
| 1458 | 1457 |
| 1459 // Decide if a property should be in the object boilerplate. | 1458 // Decide if a property should be in the object boilerplate. |
| 1460 static bool IsBoilerplateProperty(Property* property); | 1459 static bool IsBoilerplateProperty(Property* property); |
| 1461 | 1460 |
| 1462 // Populate the constant properties fixed array. | 1461 // Populate the constant properties fixed array. |
| 1463 void BuildConstantProperties(Isolate* isolate); | 1462 void BuildConstantProperties(Isolate* isolate); |
| 1464 | 1463 |
| 1465 // Mark all computed expressions that are bound to a key that | 1464 // Mark all computed expressions that are bound to a key that |
| 1466 // is shadowed by a later occurrence of the same key. For the | 1465 // is shadowed by a later occurrence of the same key. For the |
| 1467 // marked expressions, no store code is emitted. | 1466 // marked expressions, no store code is emitted. |
| 1468 void CalculateEmitStore(Zone* zone); | 1467 void CalculateEmitStore(Zone* zone); |
| 1469 | 1468 |
| 1470 // Assemble bitfield of flags for the CreateObjectLiteral helper. | 1469 // Assemble bitfield of flags for the CreateObjectLiteral helper. |
| 1471 int ComputeFlags(bool disable_mementos = false) const { | 1470 int ComputeFlags(bool disable_mementos = false) const { |
| 1472 int flags = fast_elements() ? kFastElements : kNoFlags; | 1471 int flags = fast_elements() ? kFastElements : kNoFlags; |
| 1473 flags |= has_function() ? kHasFunction : kNoFlags; | |
| 1474 if (has_shallow_properties()) { | 1472 if (has_shallow_properties()) { |
| 1475 flags |= kShallowProperties; | 1473 flags |= kShallowProperties; |
| 1476 } | 1474 } |
| 1477 if (disable_mementos) { | 1475 if (disable_mementos) { |
| 1478 flags |= kDisableMementos; | 1476 flags |= kDisableMementos; |
| 1479 } | 1477 } |
| 1480 return flags; | 1478 return flags; |
| 1481 } | 1479 } |
| 1482 | 1480 |
| 1483 enum Flags { | 1481 enum Flags { |
| 1484 kNoFlags = 0, | 1482 kNoFlags = 0, |
| 1485 kFastElements = 1, | 1483 kFastElements = 1, |
| 1486 kHasFunction = 1 << 1, | 1484 kShallowProperties = 1 << 1, |
| 1487 kShallowProperties = 1 << 2, | 1485 kDisableMementos = 1 << 2 |
| 1488 kDisableMementos = 1 << 3 | |
| 1489 }; | 1486 }; |
| 1490 | 1487 |
| 1491 struct Accessors: public ZoneObject { | 1488 struct Accessors: public ZoneObject { |
| 1492 Accessors() : getter(NULL), setter(NULL) {} | 1489 Accessors() : getter(NULL), setter(NULL) {} |
| 1493 ObjectLiteralProperty* getter; | 1490 ObjectLiteralProperty* getter; |
| 1494 ObjectLiteralProperty* setter; | 1491 ObjectLiteralProperty* setter; |
| 1495 }; | 1492 }; |
| 1496 | 1493 |
| 1497 BailoutId CreateLiteralId() const { return BailoutId(local_id(0)); } | 1494 BailoutId CreateLiteralId() const { return BailoutId(local_id(0)); } |
| 1498 | 1495 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 1510 return parent_num_ids() + 1 + 2 * properties()->length(); | 1507 return parent_num_ids() + 1 + 2 * properties()->length(); |
| 1511 } | 1508 } |
| 1512 | 1509 |
| 1513 // Object literals need one feedback slot for each non-trivial value, as well | 1510 // Object literals need one feedback slot for each non-trivial value, as well |
| 1514 // as some slots for home objects. | 1511 // as some slots for home objects. |
| 1515 void AssignFeedbackVectorSlots(Isolate* isolate, FeedbackVectorSpec* spec, | 1512 void AssignFeedbackVectorSlots(Isolate* isolate, FeedbackVectorSpec* spec, |
| 1516 FeedbackVectorSlotCache* cache) override; | 1513 FeedbackVectorSlotCache* cache) override; |
| 1517 | 1514 |
| 1518 protected: | 1515 protected: |
| 1519 ObjectLiteral(Zone* zone, ZoneList<Property*>* properties, int literal_index, | 1516 ObjectLiteral(Zone* zone, ZoneList<Property*>* properties, int literal_index, |
| 1520 int boilerplate_properties, bool has_function, int pos) | 1517 int boilerplate_properties, int pos) |
| 1521 : MaterializedLiteral(zone, literal_index, pos), | 1518 : MaterializedLiteral(zone, literal_index, pos), |
| 1522 properties_(properties), | 1519 properties_(properties), |
| 1523 boilerplate_properties_(boilerplate_properties), | 1520 boilerplate_properties_(boilerplate_properties), |
| 1524 fast_elements_(false), | 1521 fast_elements_(false), |
| 1525 has_elements_(false), | 1522 has_elements_(false), |
| 1526 may_store_doubles_(false), | 1523 may_store_doubles_(false) {} |
| 1527 has_function_(has_function) {} | |
| 1528 static int parent_num_ids() { return MaterializedLiteral::num_ids(); } | 1524 static int parent_num_ids() { return MaterializedLiteral::num_ids(); } |
| 1529 | 1525 |
| 1530 private: | 1526 private: |
| 1531 int local_id(int n) const { return base_id() + parent_num_ids() + n; } | 1527 int local_id(int n) const { return base_id() + parent_num_ids() + n; } |
| 1532 Handle<FixedArray> constant_properties_; | 1528 Handle<FixedArray> constant_properties_; |
| 1533 ZoneList<Property*>* properties_; | 1529 ZoneList<Property*>* properties_; |
| 1534 int boilerplate_properties_; | 1530 int boilerplate_properties_; |
| 1535 bool fast_elements_; | 1531 bool fast_elements_; |
| 1536 bool has_elements_; | 1532 bool has_elements_; |
| 1537 bool may_store_doubles_; | 1533 bool may_store_doubles_; |
| 1538 bool has_function_; | |
| 1539 FeedbackVectorSlot slot_; | 1534 FeedbackVectorSlot slot_; |
| 1540 }; | 1535 }; |
| 1541 | 1536 |
| 1542 | 1537 |
| 1543 // A map from property names to getter/setter pairs allocated in the zone. | 1538 // A map from property names to getter/setter pairs allocated in the zone. |
| 1544 class AccessorTable : public TemplateHashMap<Literal, ObjectLiteral::Accessors, | 1539 class AccessorTable : public TemplateHashMap<Literal, ObjectLiteral::Accessors, |
| 1545 ZoneAllocationPolicy> { | 1540 ZoneAllocationPolicy> { |
| 1546 public: | 1541 public: |
| 1547 explicit AccessorTable(Zone* zone) | 1542 explicit AccessorTable(Zone* zone) |
| 1548 : TemplateHashMap<Literal, ObjectLiteral::Accessors, | 1543 : TemplateHashMap<Literal, ObjectLiteral::Accessors, |
| (...skipping 1656 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3205 | 3200 |
| 3206 Literal* NewTheHoleLiteral(int pos) { | 3201 Literal* NewTheHoleLiteral(int pos) { |
| 3207 return new (local_zone_) | 3202 return new (local_zone_) |
| 3208 Literal(local_zone_, ast_value_factory_->NewTheHole(), pos); | 3203 Literal(local_zone_, ast_value_factory_->NewTheHole(), pos); |
| 3209 } | 3204 } |
| 3210 | 3205 |
| 3211 ObjectLiteral* NewObjectLiteral( | 3206 ObjectLiteral* NewObjectLiteral( |
| 3212 ZoneList<ObjectLiteral::Property*>* properties, | 3207 ZoneList<ObjectLiteral::Property*>* properties, |
| 3213 int literal_index, | 3208 int literal_index, |
| 3214 int boilerplate_properties, | 3209 int boilerplate_properties, |
| 3215 bool has_function, | |
| 3216 int pos) { | 3210 int pos) { |
| 3217 return new (local_zone_) | 3211 return new (local_zone_) ObjectLiteral( |
| 3218 ObjectLiteral(local_zone_, properties, literal_index, | 3212 local_zone_, properties, literal_index, boilerplate_properties, pos); |
| 3219 boilerplate_properties, has_function, pos); | |
| 3220 } | 3213 } |
| 3221 | 3214 |
| 3222 ObjectLiteral::Property* NewObjectLiteralProperty( | 3215 ObjectLiteral::Property* NewObjectLiteralProperty( |
| 3223 Expression* key, Expression* value, ObjectLiteralProperty::Kind kind, | 3216 Expression* key, Expression* value, ObjectLiteralProperty::Kind kind, |
| 3224 bool is_static, bool is_computed_name) { | 3217 bool is_static, bool is_computed_name) { |
| 3225 return new (local_zone_) | 3218 return new (local_zone_) |
| 3226 ObjectLiteral::Property(key, value, kind, is_static, is_computed_name); | 3219 ObjectLiteral::Property(key, value, kind, is_static, is_computed_name); |
| 3227 } | 3220 } |
| 3228 | 3221 |
| 3229 ObjectLiteral::Property* NewObjectLiteralProperty(Expression* key, | 3222 ObjectLiteral::Property* NewObjectLiteralProperty(Expression* key, |
| (...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3520 : NULL; \ | 3513 : NULL; \ |
| 3521 } | 3514 } |
| 3522 AST_NODE_LIST(DECLARE_NODE_FUNCTIONS) | 3515 AST_NODE_LIST(DECLARE_NODE_FUNCTIONS) |
| 3523 #undef DECLARE_NODE_FUNCTIONS | 3516 #undef DECLARE_NODE_FUNCTIONS |
| 3524 | 3517 |
| 3525 | 3518 |
| 3526 } // namespace internal | 3519 } // namespace internal |
| 3527 } // namespace v8 | 3520 } // namespace v8 |
| 3528 | 3521 |
| 3529 #endif // V8_AST_AST_H_ | 3522 #endif // V8_AST_AST_H_ |
| OLD | NEW |