Chromium Code Reviews| 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/assembler.h" | 8 #include "src/assembler.h" |
| 9 #include "src/ast-value-factory.h" | 9 #include "src/ast-value-factory.h" |
| 10 #include "src/bailout-reason.h" | 10 #include "src/bailout-reason.h" |
| (...skipping 1381 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1392 Handle<Map> GetReceiverType() { return receiver_type_; } | 1392 Handle<Map> GetReceiverType() { return receiver_type_; } |
| 1393 | 1393 |
| 1394 bool IsCompileTimeValue(); | 1394 bool IsCompileTimeValue(); |
| 1395 | 1395 |
| 1396 void set_emit_store(bool emit_store); | 1396 void set_emit_store(bool emit_store); |
| 1397 bool emit_store(); | 1397 bool emit_store(); |
| 1398 | 1398 |
| 1399 bool is_static() const { return is_static_; } | 1399 bool is_static() const { return is_static_; } |
| 1400 bool is_computed_name() const { return is_computed_name_; } | 1400 bool is_computed_name() const { return is_computed_name_; } |
| 1401 | 1401 |
| 1402 FeedbackVectorICSlot GetSlot(int offset = 0) const { | |
| 1403 if (ic_slot_or_count_ == FeedbackVectorICSlot::Invalid().ToInt()) { | |
| 1404 return FeedbackVectorICSlot::Invalid(); | |
| 1405 } | |
| 1406 return FeedbackVectorICSlot(ic_slot_or_count_ + offset); | |
| 1407 } | |
| 1408 | |
| 1409 int ic_slot_count() const { | |
| 1410 if (ic_slot_or_count_ == FeedbackVectorICSlot::Invalid().ToInt()) { | |
| 1411 return 0; | |
| 1412 } | |
| 1413 return ic_slot_or_count_; | |
| 1414 } | |
| 1415 | |
| 1402 void set_receiver_type(Handle<Map> map) { receiver_type_ = map; } | 1416 void set_receiver_type(Handle<Map> map) { receiver_type_ = map; } |
| 1417 void set_ic_slot_count(int count) { | |
| 1418 // Should only be called once. | |
| 1419 DCHECK(ic_slot_or_count_ == FeedbackVectorICSlot::Invalid().ToInt()); | |
| 1420 if (count > 0) ic_slot_or_count_ = count; | |
| 1421 } | |
| 1422 | |
| 1423 int set_base_slot(int slot) { | |
| 1424 if (ic_slot_count() > 0) { | |
| 1425 int count = ic_slot_count(); | |
| 1426 ic_slot_or_count_ = slot; | |
| 1427 return count; | |
| 1428 } | |
| 1429 return 0; | |
| 1430 } | |
| 1403 | 1431 |
| 1404 protected: | 1432 protected: |
| 1405 friend class AstNodeFactory; | 1433 friend class AstNodeFactory; |
| 1406 | 1434 |
| 1407 ObjectLiteralProperty(Expression* key, Expression* value, Kind kind, | 1435 ObjectLiteralProperty(Expression* key, Expression* value, Kind kind, |
| 1408 bool is_static, bool is_computed_name); | 1436 bool is_static, bool is_computed_name); |
| 1409 ObjectLiteralProperty(AstValueFactory* ast_value_factory, Expression* key, | 1437 ObjectLiteralProperty(AstValueFactory* ast_value_factory, Expression* key, |
| 1410 Expression* value, bool is_static, | 1438 Expression* value, bool is_static, |
| 1411 bool is_computed_name); | 1439 bool is_computed_name); |
| 1412 | 1440 |
| 1413 private: | 1441 private: |
| 1414 Expression* key_; | 1442 Expression* key_; |
| 1415 Expression* value_; | 1443 Expression* value_; |
| 1444 int ic_slot_or_count_; | |
| 1416 Kind kind_; | 1445 Kind kind_; |
| 1417 bool emit_store_; | 1446 bool emit_store_; |
| 1418 bool is_static_; | 1447 bool is_static_; |
| 1419 bool is_computed_name_; | 1448 bool is_computed_name_; |
| 1420 Handle<Map> receiver_type_; | 1449 Handle<Map> receiver_type_; |
| 1421 }; | 1450 }; |
| 1422 | 1451 |
| 1423 | 1452 |
| 1424 // An object literal has a boilerplate object that is used | 1453 // An object literal has a boilerplate object that is used |
| 1425 // for minimizing the work when constructing it at runtime. | 1454 // for minimizing the work when constructing it at runtime. |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1470 kNoFlags = 0, | 1499 kNoFlags = 0, |
| 1471 kFastElements = 1, | 1500 kFastElements = 1, |
| 1472 kHasFunction = 1 << 1, | 1501 kHasFunction = 1 << 1, |
| 1473 kShallowProperties = 1 << 2, | 1502 kShallowProperties = 1 << 2, |
| 1474 kDisableMementos = 1 << 3, | 1503 kDisableMementos = 1 << 3, |
| 1475 kIsStrong = 1 << 4 | 1504 kIsStrong = 1 << 4 |
| 1476 }; | 1505 }; |
| 1477 | 1506 |
| 1478 struct Accessors: public ZoneObject { | 1507 struct Accessors: public ZoneObject { |
| 1479 Accessors() : getter(NULL), setter(NULL) {} | 1508 Accessors() : getter(NULL), setter(NULL) {} |
| 1480 Expression* getter; | 1509 // Expression* getter; |
| 1481 Expression* setter; | 1510 // Expression* setter; |
|
Michael Starzinger
2015/09/07 11:11:50
nit: Still look like a left-over.
mvstanton
2015/09/07 13:36:09
Done.
| |
| 1511 ObjectLiteralProperty* getter; | |
| 1512 ObjectLiteralProperty* setter; | |
| 1482 }; | 1513 }; |
| 1483 | 1514 |
| 1484 BailoutId CreateLiteralId() const { return BailoutId(local_id(0)); } | 1515 BailoutId CreateLiteralId() const { return BailoutId(local_id(0)); } |
| 1485 | 1516 |
| 1486 // Return an AST id for a property that is used in simulate instructions. | 1517 // Return an AST id for a property that is used in simulate instructions. |
| 1487 BailoutId GetIdForProperty(int i) { return BailoutId(local_id(i + 1)); } | 1518 BailoutId GetIdForProperty(int i) { return BailoutId(local_id(i + 1)); } |
| 1488 | 1519 |
| 1489 // Unlike other AST nodes, this number of bailout IDs allocated for an | 1520 // Unlike other AST nodes, this number of bailout IDs allocated for an |
| 1490 // ObjectLiteral can vary, so num_ids() is not a static method. | 1521 // ObjectLiteral can vary, so num_ids() is not a static method. |
| 1491 int num_ids() const { return parent_num_ids() + 1 + properties()->length(); } | 1522 int num_ids() const { return parent_num_ids() + 1 + properties()->length(); } |
| 1492 | 1523 |
| 1493 // Object literals need one feedback slot for each non-trivial value, as well | 1524 // Object literals need one feedback slot for each non-trivial value, as well |
| 1494 // as some slots for home objects. | 1525 // as some slots for home objects. |
| 1495 FeedbackVectorRequirements ComputeFeedbackRequirements( | 1526 FeedbackVectorRequirements ComputeFeedbackRequirements( |
| 1496 Isolate* isolate, const ICSlotCache* cache) override; | 1527 Isolate* isolate, const ICSlotCache* cache) override; |
| 1497 void SetFirstFeedbackICSlot(FeedbackVectorICSlot slot, | 1528 void SetFirstFeedbackICSlot(FeedbackVectorICSlot slot, |
| 1498 ICSlotCache* cache) override { | 1529 ICSlotCache* cache) override { |
| 1499 slot_ = slot; | 1530 slot_ = slot; |
| 1500 } | 1531 } |
| 1501 Code::Kind FeedbackICSlotKind(int index) override { return Code::STORE_IC; } | 1532 Code::Kind FeedbackICSlotKind(int index) override { return Code::STORE_IC; } |
| 1502 FeedbackVectorICSlot GetNthSlot(int n) const { | |
| 1503 return FeedbackVectorICSlot(slot_.ToInt() + n); | |
| 1504 } | |
| 1505 | 1533 |
| 1506 // If value needs a home object, returns a valid feedback vector ic slot | 1534 // After feedback slots were assigned, propagate information to the properties |
| 1507 // given by slot_index, and increments slot_index. | 1535 // which need it. |
| 1508 FeedbackVectorICSlot SlotForHomeObject(Expression* value, | 1536 void LayoutFeedbackSlots(); |
| 1509 int* slot_index) const; | |
| 1510 | |
| 1511 #ifdef DEBUG | |
| 1512 int slot_count() const { return slot_count_; } | |
| 1513 #endif | |
| 1514 | 1537 |
| 1515 protected: | 1538 protected: |
| 1516 ObjectLiteral(Zone* zone, ZoneList<Property*>* properties, int literal_index, | 1539 ObjectLiteral(Zone* zone, ZoneList<Property*>* properties, int literal_index, |
| 1517 int boilerplate_properties, bool has_function, bool is_strong, | 1540 int boilerplate_properties, bool has_function, bool is_strong, |
| 1518 int pos) | 1541 int pos) |
| 1519 : MaterializedLiteral(zone, literal_index, is_strong, pos), | 1542 : MaterializedLiteral(zone, literal_index, is_strong, pos), |
| 1520 properties_(properties), | 1543 properties_(properties), |
| 1521 boilerplate_properties_(boilerplate_properties), | 1544 boilerplate_properties_(boilerplate_properties), |
| 1522 fast_elements_(false), | 1545 fast_elements_(false), |
| 1523 has_elements_(false), | 1546 has_elements_(false), |
| 1524 may_store_doubles_(false), | 1547 may_store_doubles_(false), |
| 1525 has_function_(has_function), | 1548 has_function_(has_function), |
| 1526 #ifdef DEBUG | |
| 1527 slot_count_(0), | |
| 1528 #endif | |
| 1529 slot_(FeedbackVectorICSlot::Invalid()) { | 1549 slot_(FeedbackVectorICSlot::Invalid()) { |
| 1530 } | 1550 } |
| 1531 static int parent_num_ids() { return MaterializedLiteral::num_ids(); } | 1551 static int parent_num_ids() { return MaterializedLiteral::num_ids(); } |
| 1532 | 1552 |
| 1533 private: | 1553 private: |
| 1534 int local_id(int n) const { return base_id() + parent_num_ids() + n; } | 1554 int local_id(int n) const { return base_id() + parent_num_ids() + n; } |
| 1535 Handle<FixedArray> constant_properties_; | 1555 Handle<FixedArray> constant_properties_; |
| 1536 ZoneList<Property*>* properties_; | 1556 ZoneList<Property*>* properties_; |
| 1537 int boilerplate_properties_; | 1557 int boilerplate_properties_; |
| 1538 bool fast_elements_; | 1558 bool fast_elements_; |
| 1539 bool has_elements_; | 1559 bool has_elements_; |
| 1540 bool may_store_doubles_; | 1560 bool may_store_doubles_; |
| 1541 bool has_function_; | 1561 bool has_function_; |
| 1542 #ifdef DEBUG | |
| 1543 // slot_count_ helps validate that the logic to allocate ic slots and the | |
| 1544 // logic to use them are in sync. | |
| 1545 int slot_count_; | |
| 1546 #endif | |
| 1547 FeedbackVectorICSlot slot_; | 1562 FeedbackVectorICSlot slot_; |
| 1548 }; | 1563 }; |
| 1549 | 1564 |
| 1550 | 1565 |
| 1551 // Node for capturing a regexp literal. | 1566 // Node for capturing a regexp literal. |
| 1552 class RegExpLiteral final : public MaterializedLiteral { | 1567 class RegExpLiteral final : public MaterializedLiteral { |
| 1553 public: | 1568 public: |
| 1554 DECLARE_NODE_TYPE(RegExpLiteral) | 1569 DECLARE_NODE_TYPE(RegExpLiteral) |
| 1555 | 1570 |
| 1556 Handle<String> pattern() const { return pattern_->string(); } | 1571 Handle<String> pattern() const { return pattern_->string(); } |
| (...skipping 1150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2707 | 2722 |
| 2708 // Object literals need one feedback slot for each non-trivial value, as well | 2723 // Object literals need one feedback slot for each non-trivial value, as well |
| 2709 // as some slots for home objects. | 2724 // as some slots for home objects. |
| 2710 FeedbackVectorRequirements ComputeFeedbackRequirements( | 2725 FeedbackVectorRequirements ComputeFeedbackRequirements( |
| 2711 Isolate* isolate, const ICSlotCache* cache) override; | 2726 Isolate* isolate, const ICSlotCache* cache) override; |
| 2712 void SetFirstFeedbackICSlot(FeedbackVectorICSlot slot, | 2727 void SetFirstFeedbackICSlot(FeedbackVectorICSlot slot, |
| 2713 ICSlotCache* cache) override { | 2728 ICSlotCache* cache) override { |
| 2714 slot_ = slot; | 2729 slot_ = slot; |
| 2715 } | 2730 } |
| 2716 Code::Kind FeedbackICSlotKind(int index) override { return Code::STORE_IC; } | 2731 Code::Kind FeedbackICSlotKind(int index) override { return Code::STORE_IC; } |
| 2717 FeedbackVectorICSlot GetNthSlot(int n) const { | 2732 |
| 2718 return FeedbackVectorICSlot(slot_.ToInt() + n); | 2733 bool NeedsProxySlot() const { |
| 2734 return FLAG_vector_stores && scope() != NULL && | |
| 2735 class_variable_proxy()->var()->IsUnallocated(); | |
| 2719 } | 2736 } |
| 2720 | 2737 |
| 2721 // If value needs a home object, returns a valid feedback vector ic slot | 2738 FeedbackVectorICSlot ProxySlot() const { return slot_; } |
| 2722 // given by slot_index, and increments slot_index. | |
| 2723 FeedbackVectorICSlot SlotForHomeObject(Expression* value, | |
| 2724 int* slot_index) const; | |
| 2725 | 2739 |
| 2726 #ifdef DEBUG | 2740 // After feedback slots were assigned, propagate information to the properties |
| 2727 int slot_count() const { return slot_count_; } | 2741 // which need it. |
| 2728 #endif | 2742 void LayoutFeedbackSlots(); |
| 2729 | 2743 |
| 2730 protected: | 2744 protected: |
| 2731 ClassLiteral(Zone* zone, const AstRawString* name, Scope* scope, | 2745 ClassLiteral(Zone* zone, const AstRawString* name, Scope* scope, |
| 2732 VariableProxy* class_variable_proxy, Expression* extends, | 2746 VariableProxy* class_variable_proxy, Expression* extends, |
| 2733 FunctionLiteral* constructor, ZoneList<Property*>* properties, | 2747 FunctionLiteral* constructor, ZoneList<Property*>* properties, |
| 2734 int start_position, int end_position) | 2748 int start_position, int end_position) |
| 2735 : Expression(zone, start_position), | 2749 : Expression(zone, start_position), |
| 2736 raw_name_(name), | 2750 raw_name_(name), |
| 2737 scope_(scope), | 2751 scope_(scope), |
| 2738 class_variable_proxy_(class_variable_proxy), | 2752 class_variable_proxy_(class_variable_proxy), |
| 2739 extends_(extends), | 2753 extends_(extends), |
| 2740 constructor_(constructor), | 2754 constructor_(constructor), |
| 2741 properties_(properties), | 2755 properties_(properties), |
| 2742 end_position_(end_position), | 2756 end_position_(end_position), |
| 2743 #ifdef DEBUG | |
| 2744 slot_count_(0), | |
| 2745 #endif | |
| 2746 slot_(FeedbackVectorICSlot::Invalid()) { | 2757 slot_(FeedbackVectorICSlot::Invalid()) { |
| 2747 } | 2758 } |
| 2748 | 2759 |
| 2749 static int parent_num_ids() { return Expression::num_ids(); } | 2760 static int parent_num_ids() { return Expression::num_ids(); } |
| 2750 | 2761 |
| 2751 private: | 2762 private: |
| 2752 int local_id(int n) const { return base_id() + parent_num_ids() + n; } | 2763 int local_id(int n) const { return base_id() + parent_num_ids() + n; } |
| 2753 | 2764 |
| 2754 const AstRawString* raw_name_; | 2765 const AstRawString* raw_name_; |
| 2755 Scope* scope_; | 2766 Scope* scope_; |
| 2756 VariableProxy* class_variable_proxy_; | 2767 VariableProxy* class_variable_proxy_; |
| 2757 Expression* extends_; | 2768 Expression* extends_; |
| 2758 FunctionLiteral* constructor_; | 2769 FunctionLiteral* constructor_; |
| 2759 ZoneList<Property*>* properties_; | 2770 ZoneList<Property*>* properties_; |
| 2760 int end_position_; | 2771 int end_position_; |
| 2761 #ifdef DEBUG | |
| 2762 // slot_count_ helps validate that the logic to allocate ic slots and the | |
| 2763 // logic to use them are in sync. | |
| 2764 int slot_count_; | |
| 2765 #endif | |
| 2766 FeedbackVectorICSlot slot_; | 2772 FeedbackVectorICSlot slot_; |
| 2767 }; | 2773 }; |
| 2768 | 2774 |
| 2769 | 2775 |
| 2770 class NativeFunctionLiteral final : public Expression { | 2776 class NativeFunctionLiteral final : public Expression { |
| 2771 public: | 2777 public: |
| 2772 DECLARE_NODE_TYPE(NativeFunctionLiteral) | 2778 DECLARE_NODE_TYPE(NativeFunctionLiteral) |
| 2773 | 2779 |
| 2774 Handle<String> name() const { return name_->string(); } | 2780 Handle<String> name() const { return name_->string(); } |
| 2775 v8::Extension* extension() const { return extension_; } | 2781 v8::Extension* extension() const { return extension_; } |
| (...skipping 878 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3654 | 3660 |
| 3655 private: | 3661 private: |
| 3656 Zone* zone_; | 3662 Zone* zone_; |
| 3657 AstValueFactory* ast_value_factory_; | 3663 AstValueFactory* ast_value_factory_; |
| 3658 }; | 3664 }; |
| 3659 | 3665 |
| 3660 | 3666 |
| 3661 } } // namespace v8::internal | 3667 } } // namespace v8::internal |
| 3662 | 3668 |
| 3663 #endif // V8_AST_H_ | 3669 #endif // V8_AST_H_ |
| OLD | NEW |