Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(246)

Side by Side Diff: src/ast/ast.h

Issue 2620943002: [ESnext] Implement Object Rest (Closed)
Patch Set: fix nits Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | src/bootstrapper.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 depth field and flags. 1409 // Populate the depth field and flags.
1407 void InitDepthAndFlags(); 1410 void InitDepthAndFlags();
1408 1411
1409 // Get the constant properties fixed array, populating it if necessary. 1412 // Get the constant properties fixed array, populating it if necessary.
1410 Handle<FixedArray> GetOrBuildConstantProperties(Isolate* isolate) { 1413 Handle<FixedArray> GetOrBuildConstantProperties(Isolate* isolate) {
1411 if (constant_properties_.is_null()) { 1414 if (constant_properties_.is_null()) {
(...skipping 22 matching lines...) Expand all
1434 if (disable_mementos) { 1437 if (disable_mementos) {
1435 flags |= kDisableMementos; 1438 flags |= kDisableMementos;
1436 } 1439 }
1437 return flags; 1440 return flags;
1438 } 1441 }
1439 1442
1440 enum Flags { 1443 enum Flags {
1441 kNoFlags = 0, 1444 kNoFlags = 0,
1442 kFastElements = 1, 1445 kFastElements = 1,
1443 kShallowProperties = 1 << 1, 1446 kShallowProperties = 1 << 1,
1444 kDisableMementos = 1 << 2 1447 kDisableMementos = 1 << 2,
1448 kHasRestProperty = 1 << 3,
1445 }; 1449 };
1446 1450
1447 struct Accessors: public ZoneObject { 1451 struct Accessors: public ZoneObject {
1448 Accessors() : getter(NULL), setter(NULL), bailout_id(BailoutId::None()) {} 1452 Accessors() : getter(NULL), setter(NULL), bailout_id(BailoutId::None()) {}
1449 ObjectLiteralProperty* getter; 1453 ObjectLiteralProperty* getter;
1450 ObjectLiteralProperty* setter; 1454 ObjectLiteralProperty* setter;
1451 BailoutId bailout_id; 1455 BailoutId bailout_id;
1452 }; 1456 };
1453 1457
1454 BailoutId CreateLiteralId() const { return BailoutId(local_id(0)); } 1458 BailoutId CreateLiteralId() const { return BailoutId(local_id(0)); }
1455 1459
1456 // Return an AST id for a property that is used in simulate instructions. 1460 // Return an AST id for a property that is used in simulate instructions.
1457 BailoutId GetIdForPropertySet(int i) { return BailoutId(local_id(i + 1)); } 1461 BailoutId GetIdForPropertySet(int i) { return BailoutId(local_id(i + 1)); }
1458 1462
1459 // Unlike other AST nodes, this number of bailout IDs allocated for an 1463 // Unlike other AST nodes, this number of bailout IDs allocated for an
1460 // ObjectLiteral can vary, so num_ids() is not a static method. 1464 // ObjectLiteral can vary, so num_ids() is not a static method.
1461 int num_ids() const { return parent_num_ids() + 1 + properties()->length(); } 1465 int num_ids() const { return parent_num_ids() + 1 + properties()->length(); }
1462 1466
1463 // Object literals need one feedback slot for each non-trivial value, as well 1467 // Object literals need one feedback slot for each non-trivial value, as well
1464 // as some slots for home objects. 1468 // as some slots for home objects.
1465 void AssignFeedbackVectorSlots(FeedbackVectorSpec* spec, 1469 void AssignFeedbackVectorSlots(FeedbackVectorSpec* spec,
1466 FeedbackVectorSlotCache* cache); 1470 FeedbackVectorSlotCache* cache);
1467 1471
1468 private: 1472 private:
1469 friend class AstNodeFactory; 1473 friend class AstNodeFactory;
1470 1474
1471 ObjectLiteral(ZoneList<Property*>* properties, int literal_index, 1475 ObjectLiteral(ZoneList<Property*>* properties, int literal_index,
1472 uint32_t boilerplate_properties, int pos) 1476 uint32_t boilerplate_properties, int pos,
1477 bool has_rest_property)
1473 : MaterializedLiteral(literal_index, pos, kObjectLiteral), 1478 : MaterializedLiteral(literal_index, pos, kObjectLiteral),
1474 boilerplate_properties_(boilerplate_properties), 1479 boilerplate_properties_(boilerplate_properties),
1475 properties_(properties) { 1480 properties_(properties) {
1476 bit_field_ |= FastElementsField::encode(false) | 1481 bit_field_ |= FastElementsField::encode(false) |
1477 HasElementsField::encode(false) | 1482 HasElementsField::encode(false) |
1478 MayStoreDoublesField::encode(false); 1483 MayStoreDoublesField::encode(false) |
1484 HasRestPropertyField::encode(has_rest_property);
1479 } 1485 }
1480 1486
1481 static int parent_num_ids() { return MaterializedLiteral::num_ids(); } 1487 static int parent_num_ids() { return MaterializedLiteral::num_ids(); }
1482 int local_id(int n) const { return base_id() + parent_num_ids() + n; } 1488 int local_id(int n) const { return base_id() + parent_num_ids() + n; }
1483 1489
1484 uint32_t boilerplate_properties_; 1490 uint32_t boilerplate_properties_;
1485 Handle<FixedArray> constant_properties_; 1491 Handle<FixedArray> constant_properties_;
1486 ZoneList<Property*>* properties_; 1492 ZoneList<Property*>* properties_;
1487 1493
1488 class FastElementsField 1494 class FastElementsField
1489 : public BitField<bool, MaterializedLiteral::kNextBitFieldIndex, 1> {}; 1495 : public BitField<bool, MaterializedLiteral::kNextBitFieldIndex, 1> {};
1490 class HasElementsField : public BitField<bool, FastElementsField::kNext, 1> { 1496 class HasElementsField : public BitField<bool, FastElementsField::kNext, 1> {
1491 }; 1497 };
1492 class MayStoreDoublesField 1498 class MayStoreDoublesField
1493 : public BitField<bool, HasElementsField::kNext, 1> {}; 1499 : public BitField<bool, HasElementsField::kNext, 1> {};
1500 class HasRestPropertyField
1501 : public BitField<bool, MayStoreDoublesField::kNext, 1> {};
1494 }; 1502 };
1495 1503
1496 1504
1497 // A map from property names to getter/setter pairs allocated in the zone. 1505 // A map from property names to getter/setter pairs allocated in the zone.
1498 class AccessorTable 1506 class AccessorTable
1499 : public base::TemplateHashMap<Literal, ObjectLiteral::Accessors, 1507 : public base::TemplateHashMap<Literal, ObjectLiteral::Accessors,
1500 bool (*)(void*, void*), 1508 bool (*)(void*, void*),
1501 ZoneAllocationPolicy> { 1509 ZoneAllocationPolicy> {
1502 public: 1510 public:
1503 explicit AccessorTable(Zone* zone) 1511 explicit AccessorTable(Zone* zone)
(...skipping 1818 matching lines...) Expand 10 before | Expand all | Expand 10 after
3322 Literal* NewUndefinedLiteral(int pos) { 3330 Literal* NewUndefinedLiteral(int pos) {
3323 return new (zone_) Literal(ast_value_factory_->NewUndefined(), pos); 3331 return new (zone_) Literal(ast_value_factory_->NewUndefined(), pos);
3324 } 3332 }
3325 3333
3326 Literal* NewTheHoleLiteral(int pos) { 3334 Literal* NewTheHoleLiteral(int pos) {
3327 return new (zone_) Literal(ast_value_factory_->NewTheHole(), pos); 3335 return new (zone_) Literal(ast_value_factory_->NewTheHole(), pos);
3328 } 3336 }
3329 3337
3330 ObjectLiteral* NewObjectLiteral( 3338 ObjectLiteral* NewObjectLiteral(
3331 ZoneList<ObjectLiteral::Property*>* properties, int literal_index, 3339 ZoneList<ObjectLiteral::Property*>* properties, int literal_index,
3332 uint32_t boilerplate_properties, int pos) { 3340 uint32_t boilerplate_properties, int pos, bool has_rest_property) {
3333 return new (zone_) 3341 return new (zone_)
3334 ObjectLiteral(properties, literal_index, boilerplate_properties, pos); 3342 ObjectLiteral(properties, literal_index, boilerplate_properties, pos,
3343 has_rest_property);
3335 } 3344 }
3336 3345
3337 ObjectLiteral::Property* NewObjectLiteralProperty( 3346 ObjectLiteral::Property* NewObjectLiteralProperty(
3338 Expression* key, Expression* value, ObjectLiteralProperty::Kind kind, 3347 Expression* key, Expression* value, ObjectLiteralProperty::Kind kind,
3339 bool is_computed_name) { 3348 bool is_computed_name) {
3340 return new (zone_) 3349 return new (zone_)
3341 ObjectLiteral::Property(key, value, kind, is_computed_name); 3350 ObjectLiteral::Property(key, value, kind, is_computed_name);
3342 } 3351 }
3343 3352
3344 ObjectLiteral::Property* NewObjectLiteralProperty(Expression* key, 3353 ObjectLiteral::Property* NewObjectLiteralProperty(Expression* key,
(...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after
3639 : NULL; \ 3648 : NULL; \
3640 } 3649 }
3641 AST_NODE_LIST(DECLARE_NODE_FUNCTIONS) 3650 AST_NODE_LIST(DECLARE_NODE_FUNCTIONS)
3642 #undef DECLARE_NODE_FUNCTIONS 3651 #undef DECLARE_NODE_FUNCTIONS
3643 3652
3644 3653
3645 } // namespace internal 3654 } // namespace internal
3646 } // namespace v8 3655 } // namespace v8
3647 3656
3648 #endif // V8_AST_AST_H_ 3657 #endif // V8_AST_AST_H_
OLDNEW
« no previous file with comments | « no previous file | src/bootstrapper.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698