| 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-types.h" | 9 #include "src/ast/ast-types.h" |
| 10 #include "src/ast/ast-value-factory.h" | 10 #include "src/ast/ast-value-factory.h" |
| (...skipping 1381 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1392 int properties_count() const { return boilerplate_properties_; } | 1392 int properties_count() const { return boilerplate_properties_; } |
| 1393 ZoneList<Property*>* properties() const { return properties_; } | 1393 ZoneList<Property*>* properties() const { return properties_; } |
| 1394 bool fast_elements() const { return FastElementsField::decode(bit_field_); } | 1394 bool fast_elements() const { return FastElementsField::decode(bit_field_); } |
| 1395 bool may_store_doubles() const { | 1395 bool may_store_doubles() const { |
| 1396 return MayStoreDoublesField::decode(bit_field_); | 1396 return MayStoreDoublesField::decode(bit_field_); |
| 1397 } | 1397 } |
| 1398 bool has_elements() const { return HasElementsField::decode(bit_field_); } | 1398 bool has_elements() const { return HasElementsField::decode(bit_field_); } |
| 1399 bool has_shallow_properties() const { | 1399 bool has_shallow_properties() const { |
| 1400 return depth() == 1 && !has_elements() && !may_store_doubles(); | 1400 return depth() == 1 && !has_elements() && !may_store_doubles(); |
| 1401 } | 1401 } |
| 1402 bool has_rest_property() const { |
| 1403 return HasRestPropertyField::decode(bit_field_); |
| 1404 } |
| 1402 | 1405 |
| 1403 // Decide if a property should be in the object boilerplate. | 1406 // Decide if a property should be in the object boilerplate. |
| 1404 static bool IsBoilerplateProperty(Property* property); | 1407 static bool IsBoilerplateProperty(Property* property); |
| 1405 | 1408 |
| 1406 // Populate the constant properties fixed array. | 1409 // Populate the constant properties fixed array. |
| 1407 void BuildConstantProperties(Isolate* isolate); | 1410 void BuildConstantProperties(Isolate* isolate); |
| 1408 | 1411 |
| 1409 // Mark all computed expressions that are bound to a key that | 1412 // Mark all computed expressions that are bound to a key that |
| 1410 // is shadowed by a later occurrence of the same key. For the | 1413 // is shadowed by a later occurrence of the same key. For the |
| 1411 // marked expressions, no store code is emitted. | 1414 // marked expressions, no store code is emitted. |
| (...skipping 11 matching lines...) Expand all Loading... |
| 1423 if (disable_mementos) { | 1426 if (disable_mementos) { |
| 1424 flags |= kDisableMementos; | 1427 flags |= kDisableMementos; |
| 1425 } | 1428 } |
| 1426 return flags; | 1429 return flags; |
| 1427 } | 1430 } |
| 1428 | 1431 |
| 1429 enum Flags { | 1432 enum Flags { |
| 1430 kNoFlags = 0, | 1433 kNoFlags = 0, |
| 1431 kFastElements = 1, | 1434 kFastElements = 1, |
| 1432 kShallowProperties = 1 << 1, | 1435 kShallowProperties = 1 << 1, |
| 1433 kDisableMementos = 1 << 2 | 1436 kDisableMementos = 1 << 2, |
| 1437 kHasRestProperty = 1 << 3 |
| 1434 }; | 1438 }; |
| 1435 | 1439 |
| 1436 struct Accessors: public ZoneObject { | 1440 struct Accessors: public ZoneObject { |
| 1437 Accessors() : getter(NULL), setter(NULL), bailout_id(BailoutId::None()) {} | 1441 Accessors() : getter(NULL), setter(NULL), bailout_id(BailoutId::None()) {} |
| 1438 ObjectLiteralProperty* getter; | 1442 ObjectLiteralProperty* getter; |
| 1439 ObjectLiteralProperty* setter; | 1443 ObjectLiteralProperty* setter; |
| 1440 BailoutId bailout_id; | 1444 BailoutId bailout_id; |
| 1441 }; | 1445 }; |
| 1442 | 1446 |
| 1443 BailoutId CreateLiteralId() const { return BailoutId(local_id(0)); } | 1447 BailoutId CreateLiteralId() const { return BailoutId(local_id(0)); } |
| 1444 | 1448 |
| 1445 // Return an AST id for a property that is used in simulate instructions. | 1449 // Return an AST id for a property that is used in simulate instructions. |
| 1446 BailoutId GetIdForPropertySet(int i) { return BailoutId(local_id(i + 1)); } | 1450 BailoutId GetIdForPropertySet(int i) { return BailoutId(local_id(i + 1)); } |
| 1447 | 1451 |
| 1448 // Unlike other AST nodes, this number of bailout IDs allocated for an | 1452 // Unlike other AST nodes, this number of bailout IDs allocated for an |
| 1449 // ObjectLiteral can vary, so num_ids() is not a static method. | 1453 // ObjectLiteral can vary, so num_ids() is not a static method. |
| 1450 int num_ids() const { return parent_num_ids() + 1 + properties()->length(); } | 1454 int num_ids() const { return parent_num_ids() + 1 + properties()->length(); } |
| 1451 | 1455 |
| 1452 // Object literals need one feedback slot for each non-trivial value, as well | 1456 // Object literals need one feedback slot for each non-trivial value, as well |
| 1453 // as some slots for home objects. | 1457 // as some slots for home objects. |
| 1454 void AssignFeedbackVectorSlots(Isolate* isolate, FeedbackVectorSpec* spec, | 1458 void AssignFeedbackVectorSlots(Isolate* isolate, FeedbackVectorSpec* spec, |
| 1455 FeedbackVectorSlotCache* cache); | 1459 FeedbackVectorSlotCache* cache); |
| 1456 | 1460 |
| 1457 private: | 1461 private: |
| 1458 friend class AstNodeFactory; | 1462 friend class AstNodeFactory; |
| 1459 | 1463 |
| 1460 ObjectLiteral(ZoneList<Property*>* properties, int literal_index, | 1464 ObjectLiteral(ZoneList<Property*>* properties, int literal_index, |
| 1461 uint32_t boilerplate_properties, int pos) | 1465 uint32_t boilerplate_properties, int pos, |
| 1466 bool has_rest_property) |
| 1462 : MaterializedLiteral(literal_index, pos, kObjectLiteral), | 1467 : MaterializedLiteral(literal_index, pos, kObjectLiteral), |
| 1463 boilerplate_properties_(boilerplate_properties), | 1468 boilerplate_properties_(boilerplate_properties), |
| 1464 properties_(properties) { | 1469 properties_(properties) { |
| 1465 bit_field_ |= FastElementsField::encode(false) | | 1470 bit_field_ |= FastElementsField::encode(false) | |
| 1466 HasElementsField::encode(false) | | 1471 HasElementsField::encode(false) | |
| 1467 MayStoreDoublesField::encode(false); | 1472 MayStoreDoublesField::encode(false) | |
| 1473 HasRestPropertyField::encode(has_rest_property); |
| 1468 } | 1474 } |
| 1469 | 1475 |
| 1470 static int parent_num_ids() { return MaterializedLiteral::num_ids(); } | 1476 static int parent_num_ids() { return MaterializedLiteral::num_ids(); } |
| 1471 int local_id(int n) const { return base_id() + parent_num_ids() + n; } | 1477 int local_id(int n) const { return base_id() + parent_num_ids() + n; } |
| 1472 | 1478 |
| 1473 uint32_t boilerplate_properties_; | 1479 uint32_t boilerplate_properties_; |
| 1474 Handle<FixedArray> constant_properties_; | 1480 Handle<FixedArray> constant_properties_; |
| 1475 ZoneList<Property*>* properties_; | 1481 ZoneList<Property*>* properties_; |
| 1476 | 1482 |
| 1477 class FastElementsField | 1483 class FastElementsField |
| 1478 : public BitField<bool, MaterializedLiteral::kNextBitFieldIndex, 1> {}; | 1484 : public BitField<bool, MaterializedLiteral::kNextBitFieldIndex, 1> {}; |
| 1479 class HasElementsField : public BitField<bool, FastElementsField::kNext, 1> { | 1485 class HasElementsField : public BitField<bool, FastElementsField::kNext, 1> { |
| 1480 }; | 1486 }; |
| 1481 class MayStoreDoublesField | 1487 class MayStoreDoublesField |
| 1482 : public BitField<bool, HasElementsField::kNext, 1> {}; | 1488 : public BitField<bool, HasElementsField::kNext, 1> {}; |
| 1489 class HasRestPropertyField |
| 1490 : public BitField<bool, MayStoreDoublesField::kNext, 1> {}; |
| 1483 }; | 1491 }; |
| 1484 | 1492 |
| 1485 | 1493 |
| 1486 // A map from property names to getter/setter pairs allocated in the zone. | 1494 // A map from property names to getter/setter pairs allocated in the zone. |
| 1487 class AccessorTable | 1495 class AccessorTable |
| 1488 : public base::TemplateHashMap<Literal, ObjectLiteral::Accessors, | 1496 : public base::TemplateHashMap<Literal, ObjectLiteral::Accessors, |
| 1489 bool (*)(void*, void*), | 1497 bool (*)(void*, void*), |
| 1490 ZoneAllocationPolicy> { | 1498 ZoneAllocationPolicy> { |
| 1491 public: | 1499 public: |
| 1492 explicit AccessorTable(Zone* zone) | 1500 explicit AccessorTable(Zone* zone) |
| (...skipping 1807 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3300 Literal* NewUndefinedLiteral(int pos) { | 3308 Literal* NewUndefinedLiteral(int pos) { |
| 3301 return new (zone_) Literal(ast_value_factory_->NewUndefined(), pos); | 3309 return new (zone_) Literal(ast_value_factory_->NewUndefined(), pos); |
| 3302 } | 3310 } |
| 3303 | 3311 |
| 3304 Literal* NewTheHoleLiteral(int pos) { | 3312 Literal* NewTheHoleLiteral(int pos) { |
| 3305 return new (zone_) Literal(ast_value_factory_->NewTheHole(), pos); | 3313 return new (zone_) Literal(ast_value_factory_->NewTheHole(), pos); |
| 3306 } | 3314 } |
| 3307 | 3315 |
| 3308 ObjectLiteral* NewObjectLiteral( | 3316 ObjectLiteral* NewObjectLiteral( |
| 3309 ZoneList<ObjectLiteral::Property*>* properties, int literal_index, | 3317 ZoneList<ObjectLiteral::Property*>* properties, int literal_index, |
| 3310 uint32_t boilerplate_properties, int pos) { | 3318 uint32_t boilerplate_properties, int pos, bool has_rest_property) { |
| 3311 return new (zone_) | 3319 return new (zone_) |
| 3312 ObjectLiteral(properties, literal_index, boilerplate_properties, pos); | 3320 ObjectLiteral(properties, literal_index, boilerplate_properties, pos, |
| 3321 has_rest_property); |
| 3313 } | 3322 } |
| 3314 | 3323 |
| 3315 ObjectLiteral::Property* NewObjectLiteralProperty( | 3324 ObjectLiteral::Property* NewObjectLiteralProperty( |
| 3316 Expression* key, Expression* value, ObjectLiteralProperty::Kind kind, | 3325 Expression* key, Expression* value, ObjectLiteralProperty::Kind kind, |
| 3317 bool is_computed_name) { | 3326 bool is_computed_name) { |
| 3318 return new (zone_) | 3327 return new (zone_) |
| 3319 ObjectLiteral::Property(key, value, kind, is_computed_name); | 3328 ObjectLiteral::Property(key, value, kind, is_computed_name); |
| 3320 } | 3329 } |
| 3321 | 3330 |
| 3322 ObjectLiteral::Property* NewObjectLiteralProperty(Expression* key, | 3331 ObjectLiteral::Property* NewObjectLiteralProperty(Expression* key, |
| (...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3617 : NULL; \ | 3626 : NULL; \ |
| 3618 } | 3627 } |
| 3619 AST_NODE_LIST(DECLARE_NODE_FUNCTIONS) | 3628 AST_NODE_LIST(DECLARE_NODE_FUNCTIONS) |
| 3620 #undef DECLARE_NODE_FUNCTIONS | 3629 #undef DECLARE_NODE_FUNCTIONS |
| 3621 | 3630 |
| 3622 | 3631 |
| 3623 } // namespace internal | 3632 } // namespace internal |
| 3624 } // namespace v8 | 3633 } // namespace v8 |
| 3625 | 3634 |
| 3626 #endif // V8_AST_AST_H_ | 3635 #endif // V8_AST_AST_H_ |
| OLD | NEW |