| 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" |
| 11 #include "src/ast-value-factory.h" | 11 #include "src/ast-value-factory.h" |
| 12 #include "src/bailout-reason.h" | 12 #include "src/bailout-reason.h" |
| 13 #include "src/factory.h" | 13 #include "src/factory.h" |
| 14 #include "src/feedback-slots.h" | |
| 15 #include "src/interface.h" | 14 #include "src/interface.h" |
| 16 #include "src/isolate.h" | 15 #include "src/isolate.h" |
| 17 #include "src/jsregexp.h" | 16 #include "src/jsregexp.h" |
| 18 #include "src/list-inl.h" | 17 #include "src/list-inl.h" |
| 19 #include "src/runtime/runtime.h" | 18 #include "src/runtime/runtime.h" |
| 20 #include "src/small-pointer-list.h" | 19 #include "src/small-pointer-list.h" |
| 21 #include "src/smart-pointers.h" | 20 #include "src/smart-pointers.h" |
| 22 #include "src/token.h" | 21 #include "src/token.h" |
| 23 #include "src/types.h" | 22 #include "src/types.h" |
| 24 #include "src/utils.h" | 23 #include "src/utils.h" |
| (...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 226 return Is##type() ? reinterpret_cast<const type*>(this) : NULL; \ | 225 return Is##type() ? reinterpret_cast<const type*>(this) : NULL; \ |
| 227 } | 226 } |
| 228 AST_NODE_LIST(DECLARE_NODE_FUNCTIONS) | 227 AST_NODE_LIST(DECLARE_NODE_FUNCTIONS) |
| 229 #undef DECLARE_NODE_FUNCTIONS | 228 #undef DECLARE_NODE_FUNCTIONS |
| 230 | 229 |
| 231 virtual TargetCollector* AsTargetCollector() { return NULL; } | 230 virtual TargetCollector* AsTargetCollector() { return NULL; } |
| 232 virtual BreakableStatement* AsBreakableStatement() { return NULL; } | 231 virtual BreakableStatement* AsBreakableStatement() { return NULL; } |
| 233 virtual IterationStatement* AsIterationStatement() { return NULL; } | 232 virtual IterationStatement* AsIterationStatement() { return NULL; } |
| 234 virtual MaterializedLiteral* AsMaterializedLiteral() { return NULL; } | 233 virtual MaterializedLiteral* AsMaterializedLiteral() { return NULL; } |
| 235 | 234 |
| 235 // The interface for feedback slots, with default no-op implementations for |
| 236 // node types which don't actually have this. Note that this is conceptually |
| 237 // not really nice, but multiple inheritance would introduce yet another |
| 238 // vtable entry per node, something we don't want for space reasons. |
| 239 static const int kInvalidFeedbackSlot = -1; |
| 240 virtual int ComputeFeedbackSlotCount() { |
| 241 UNREACHABLE(); |
| 242 return 0; |
| 243 } |
| 244 virtual void SetFirstFeedbackSlot(int slot) { UNREACHABLE(); } |
| 245 |
| 236 protected: | 246 protected: |
| 237 // Some nodes re-use bailout IDs for type feedback. | 247 // Some nodes re-use bailout IDs for type feedback. |
| 238 static TypeFeedbackId reuse(BailoutId id) { | 248 static TypeFeedbackId reuse(BailoutId id) { |
| 239 return TypeFeedbackId(id.ToInt()); | 249 return TypeFeedbackId(id.ToInt()); |
| 240 } | 250 } |
| 241 | 251 |
| 242 | 252 |
| 243 private: | 253 private: |
| 244 // Hidden to prevent accidental usage. It would have to load the | 254 // Hidden to prevent accidental usage. It would have to load the |
| 245 // current zone from the TLS. | 255 // current zone from the TLS. |
| (...skipping 661 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 907 : IterationStatement(zone, labels, pos, id_gen), | 917 : IterationStatement(zone, labels, pos, id_gen), |
| 908 each_(NULL), | 918 each_(NULL), |
| 909 subject_(NULL) {} | 919 subject_(NULL) {} |
| 910 | 920 |
| 911 private: | 921 private: |
| 912 Expression* each_; | 922 Expression* each_; |
| 913 Expression* subject_; | 923 Expression* subject_; |
| 914 }; | 924 }; |
| 915 | 925 |
| 916 | 926 |
| 917 class ForInStatement FINAL : public ForEachStatement, | 927 class ForInStatement FINAL : public ForEachStatement { |
| 918 public FeedbackSlotInterface { | |
| 919 public: | 928 public: |
| 920 DECLARE_NODE_TYPE(ForInStatement) | 929 DECLARE_NODE_TYPE(ForInStatement) |
| 921 | 930 |
| 922 Expression* enumerable() const { | 931 Expression* enumerable() const { |
| 923 return subject(); | 932 return subject(); |
| 924 } | 933 } |
| 925 | 934 |
| 926 // Type feedback information. | 935 // Type feedback information. |
| 927 virtual int ComputeFeedbackSlotCount() { return 1; } | 936 virtual int ComputeFeedbackSlotCount() { return 1; } |
| 928 virtual void SetFirstFeedbackSlot(int slot) { for_in_feedback_slot_ = slot; } | 937 virtual void SetFirstFeedbackSlot(int slot) { for_in_feedback_slot_ = slot; } |
| (...skipping 692 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1621 values_(values), | 1630 values_(values), |
| 1622 first_element_id_(id_gen->ReserveIdRange(values->length())) {} | 1631 first_element_id_(id_gen->ReserveIdRange(values->length())) {} |
| 1623 | 1632 |
| 1624 private: | 1633 private: |
| 1625 Handle<FixedArray> constant_elements_; | 1634 Handle<FixedArray> constant_elements_; |
| 1626 ZoneList<Expression*>* values_; | 1635 ZoneList<Expression*>* values_; |
| 1627 const BailoutId first_element_id_; | 1636 const BailoutId first_element_id_; |
| 1628 }; | 1637 }; |
| 1629 | 1638 |
| 1630 | 1639 |
| 1631 class VariableProxy FINAL : public Expression, public FeedbackSlotInterface { | 1640 class VariableProxy FINAL : public Expression { |
| 1632 public: | 1641 public: |
| 1633 DECLARE_NODE_TYPE(VariableProxy) | 1642 DECLARE_NODE_TYPE(VariableProxy) |
| 1634 | 1643 |
| 1635 virtual bool IsValidReferenceExpression() const OVERRIDE { | 1644 virtual bool IsValidReferenceExpression() const OVERRIDE { |
| 1636 return var_ == NULL ? true : var_->IsValidReference(); | 1645 return var_ == NULL ? true : var_->IsValidReference(); |
| 1637 } | 1646 } |
| 1638 | 1647 |
| 1639 bool IsArguments() const { return var_ != NULL && var_->is_arguments(); } | 1648 bool IsArguments() const { return var_ != NULL && var_->is_arguments(); } |
| 1640 | 1649 |
| 1641 Handle<String> name() const { return name_->string(); } | 1650 Handle<String> name() const { return name_->string(); } |
| (...skipping 23 matching lines...) Expand all Loading... |
| 1665 | 1674 |
| 1666 const AstRawString* name_; | 1675 const AstRawString* name_; |
| 1667 Variable* var_; // resolved variable, or NULL | 1676 Variable* var_; // resolved variable, or NULL |
| 1668 bool is_this_; | 1677 bool is_this_; |
| 1669 bool is_assigned_; | 1678 bool is_assigned_; |
| 1670 Interface* interface_; | 1679 Interface* interface_; |
| 1671 int variable_feedback_slot_; | 1680 int variable_feedback_slot_; |
| 1672 }; | 1681 }; |
| 1673 | 1682 |
| 1674 | 1683 |
| 1675 class Property FINAL : public Expression, public FeedbackSlotInterface { | 1684 class Property FINAL : public Expression { |
| 1676 public: | 1685 public: |
| 1677 DECLARE_NODE_TYPE(Property) | 1686 DECLARE_NODE_TYPE(Property) |
| 1678 | 1687 |
| 1679 virtual bool IsValidReferenceExpression() const OVERRIDE { return true; } | 1688 virtual bool IsValidReferenceExpression() const OVERRIDE { return true; } |
| 1680 | 1689 |
| 1681 Expression* obj() const { return obj_; } | 1690 Expression* obj() const { return obj_; } |
| 1682 Expression* key() const { return key_; } | 1691 Expression* key() const { return key_; } |
| 1683 | 1692 |
| 1684 BailoutId LoadId() const { return load_id_; } | 1693 BailoutId LoadId() const { return load_id_; } |
| 1685 | 1694 |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1734 const BailoutId load_id_; | 1743 const BailoutId load_id_; |
| 1735 int property_feedback_slot_; | 1744 int property_feedback_slot_; |
| 1736 | 1745 |
| 1737 SmallMapList receiver_types_; | 1746 SmallMapList receiver_types_; |
| 1738 bool is_for_call_ : 1; | 1747 bool is_for_call_ : 1; |
| 1739 bool is_uninitialized_ : 1; | 1748 bool is_uninitialized_ : 1; |
| 1740 bool is_string_access_ : 1; | 1749 bool is_string_access_ : 1; |
| 1741 }; | 1750 }; |
| 1742 | 1751 |
| 1743 | 1752 |
| 1744 class Call FINAL : public Expression, public FeedbackSlotInterface { | 1753 class Call FINAL : public Expression { |
| 1745 public: | 1754 public: |
| 1746 DECLARE_NODE_TYPE(Call) | 1755 DECLARE_NODE_TYPE(Call) |
| 1747 | 1756 |
| 1748 Expression* expression() const { return expression_; } | 1757 Expression* expression() const { return expression_; } |
| 1749 ZoneList<Expression*>* arguments() const { return arguments_; } | 1758 ZoneList<Expression*>* arguments() const { return arguments_; } |
| 1750 | 1759 |
| 1751 // Type feedback information. | 1760 // Type feedback information. |
| 1752 virtual int ComputeFeedbackSlotCount() { return 1; } | 1761 virtual int ComputeFeedbackSlotCount() { return 1; } |
| 1753 virtual void SetFirstFeedbackSlot(int slot) { | 1762 virtual void SetFirstFeedbackSlot(int slot) { |
| 1754 call_feedback_slot_ = slot; | 1763 call_feedback_slot_ = slot; |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1837 Handle<AllocationSite> allocation_site_; | 1846 Handle<AllocationSite> allocation_site_; |
| 1838 int call_feedback_slot_; | 1847 int call_feedback_slot_; |
| 1839 | 1848 |
| 1840 const BailoutId return_id_; | 1849 const BailoutId return_id_; |
| 1841 // TODO(jarin) Only allocate the bailout id for the POSSIBLY_EVAL_CALL and | 1850 // TODO(jarin) Only allocate the bailout id for the POSSIBLY_EVAL_CALL and |
| 1842 // LOOKUP_SLOT_CALL types. | 1851 // LOOKUP_SLOT_CALL types. |
| 1843 const BailoutId eval_or_lookup_id_; | 1852 const BailoutId eval_or_lookup_id_; |
| 1844 }; | 1853 }; |
| 1845 | 1854 |
| 1846 | 1855 |
| 1847 class CallNew FINAL : public Expression, public FeedbackSlotInterface { | 1856 class CallNew FINAL : public Expression { |
| 1848 public: | 1857 public: |
| 1849 DECLARE_NODE_TYPE(CallNew) | 1858 DECLARE_NODE_TYPE(CallNew) |
| 1850 | 1859 |
| 1851 Expression* expression() const { return expression_; } | 1860 Expression* expression() const { return expression_; } |
| 1852 ZoneList<Expression*>* arguments() const { return arguments_; } | 1861 ZoneList<Expression*>* arguments() const { return arguments_; } |
| 1853 | 1862 |
| 1854 // Type feedback information. | 1863 // Type feedback information. |
| 1855 virtual int ComputeFeedbackSlotCount() { | 1864 virtual int ComputeFeedbackSlotCount() { |
| 1856 return FLAG_pretenuring_call_new ? 2 : 1; | 1865 return FLAG_pretenuring_call_new ? 2 : 1; |
| 1857 } | 1866 } |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1900 int callnew_feedback_slot_; | 1909 int callnew_feedback_slot_; |
| 1901 | 1910 |
| 1902 const BailoutId return_id_; | 1911 const BailoutId return_id_; |
| 1903 }; | 1912 }; |
| 1904 | 1913 |
| 1905 | 1914 |
| 1906 // The CallRuntime class does not represent any official JavaScript | 1915 // The CallRuntime class does not represent any official JavaScript |
| 1907 // language construct. Instead it is used to call a C or JS function | 1916 // language construct. Instead it is used to call a C or JS function |
| 1908 // with a set of arguments. This is used from the builtins that are | 1917 // with a set of arguments. This is used from the builtins that are |
| 1909 // implemented in JavaScript (see "v8natives.js"). | 1918 // implemented in JavaScript (see "v8natives.js"). |
| 1910 class CallRuntime FINAL : public Expression, public FeedbackSlotInterface { | 1919 class CallRuntime FINAL : public Expression { |
| 1911 public: | 1920 public: |
| 1912 DECLARE_NODE_TYPE(CallRuntime) | 1921 DECLARE_NODE_TYPE(CallRuntime) |
| 1913 | 1922 |
| 1914 Handle<String> name() const { return raw_name_->string(); } | 1923 Handle<String> name() const { return raw_name_->string(); } |
| 1915 const AstRawString* raw_name() const { return raw_name_; } | 1924 const AstRawString* raw_name() const { return raw_name_; } |
| 1916 const Runtime::Function* function() const { return function_; } | 1925 const Runtime::Function* function() const { return function_; } |
| 1917 ZoneList<Expression*>* arguments() const { return arguments_; } | 1926 ZoneList<Expression*>* arguments() const { return arguments_; } |
| 1918 bool is_jsruntime() const { return function_ == NULL; } | 1927 bool is_jsruntime() const { return function_ == NULL; } |
| 1919 | 1928 |
| 1920 // Type feedback information. | 1929 // Type feedback information. |
| (...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2216 BinaryOperation* binary_operation_; | 2225 BinaryOperation* binary_operation_; |
| 2217 const BailoutId assignment_id_; | 2226 const BailoutId assignment_id_; |
| 2218 | 2227 |
| 2219 bool is_uninitialized_ : 1; | 2228 bool is_uninitialized_ : 1; |
| 2220 KeyedAccessStoreMode store_mode_ : 5; // Windows treats as signed, | 2229 KeyedAccessStoreMode store_mode_ : 5; // Windows treats as signed, |
| 2221 // must have extra bit. | 2230 // must have extra bit. |
| 2222 SmallMapList receiver_types_; | 2231 SmallMapList receiver_types_; |
| 2223 }; | 2232 }; |
| 2224 | 2233 |
| 2225 | 2234 |
| 2226 class Yield FINAL : public Expression, public FeedbackSlotInterface { | 2235 class Yield FINAL : public Expression { |
| 2227 public: | 2236 public: |
| 2228 DECLARE_NODE_TYPE(Yield) | 2237 DECLARE_NODE_TYPE(Yield) |
| 2229 | 2238 |
| 2230 enum Kind { | 2239 enum Kind { |
| 2231 kInitial, // The initial yield that returns the unboxed generator object. | 2240 kInitial, // The initial yield that returns the unboxed generator object. |
| 2232 kSuspend, // A normal yield: { value: EXPRESSION, done: false } | 2241 kSuspend, // A normal yield: { value: EXPRESSION, done: false } |
| 2233 kDelegating, // A yield*. | 2242 kDelegating, // A yield*. |
| 2234 kFinal // A return: { value: EXPRESSION, done: true } | 2243 kFinal // A return: { value: EXPRESSION, done: true } |
| 2235 }; | 2244 }; |
| 2236 | 2245 |
| (...skipping 794 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3031 | 3040 |
| 3032 void increase_node_count() { properties_.add_node_count(1); } | 3041 void increase_node_count() { properties_.add_node_count(1); } |
| 3033 void add_flag(AstPropertiesFlag flag) { properties_.flags()->Add(flag); } | 3042 void add_flag(AstPropertiesFlag flag) { properties_.flags()->Add(flag); } |
| 3034 void set_dont_crankshaft_reason(BailoutReason reason) { | 3043 void set_dont_crankshaft_reason(BailoutReason reason) { |
| 3035 dont_crankshaft_reason_ = reason; | 3044 dont_crankshaft_reason_ = reason; |
| 3036 } | 3045 } |
| 3037 void set_dont_turbofan_reason(BailoutReason reason) { | 3046 void set_dont_turbofan_reason(BailoutReason reason) { |
| 3038 dont_turbofan_reason_ = reason; | 3047 dont_turbofan_reason_ = reason; |
| 3039 } | 3048 } |
| 3040 | 3049 |
| 3041 void add_slot_node(FeedbackSlotInterface* slot_node) { | 3050 void add_slot_node(AstNode* slot_node) { |
| 3042 int count = slot_node->ComputeFeedbackSlotCount(); | 3051 int count = slot_node->ComputeFeedbackSlotCount(); |
| 3043 if (count > 0) { | 3052 if (count > 0) { |
| 3044 slot_node->SetFirstFeedbackSlot(properties_.feedback_slots()); | 3053 slot_node->SetFirstFeedbackSlot(properties_.feedback_slots()); |
| 3045 properties_.increase_feedback_slots(count); | 3054 properties_.increase_feedback_slots(count); |
| 3046 } | 3055 } |
| 3047 } | 3056 } |
| 3048 | 3057 |
| 3049 AstProperties properties_; | 3058 AstProperties properties_; |
| 3050 BailoutReason dont_crankshaft_reason_; | 3059 BailoutReason dont_crankshaft_reason_; |
| 3051 BailoutReason dont_turbofan_reason_; | 3060 BailoutReason dont_turbofan_reason_; |
| (...skipping 492 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3544 Zone* zone_; | 3553 Zone* zone_; |
| 3545 Visitor visitor_; | 3554 Visitor visitor_; |
| 3546 AstValueFactory* ast_value_factory_; | 3555 AstValueFactory* ast_value_factory_; |
| 3547 AstNode::IdGen* id_gen_; | 3556 AstNode::IdGen* id_gen_; |
| 3548 }; | 3557 }; |
| 3549 | 3558 |
| 3550 | 3559 |
| 3551 } } // namespace v8::internal | 3560 } } // namespace v8::internal |
| 3552 | 3561 |
| 3553 #endif // V8_AST_H_ | 3562 #endif // V8_AST_H_ |
| OLD | NEW |