| 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" |
| (...skipping 373 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 384 // TODO(rossberg): this should move to its own AST node eventually. | 384 // TODO(rossberg): this should move to its own AST node eventually. |
| 385 virtual void RecordToBooleanTypeFeedback(TypeFeedbackOracle* oracle); | 385 virtual void RecordToBooleanTypeFeedback(TypeFeedbackOracle* oracle); |
| 386 byte to_boolean_types() const { return to_boolean_types_; } | 386 byte to_boolean_types() const { return to_boolean_types_; } |
| 387 | 387 |
| 388 BailoutId id() const { return BailoutId(base_id() + 0); } | 388 BailoutId id() const { return BailoutId(base_id() + 0); } |
| 389 TypeFeedbackId test_id() const { return TypeFeedbackId(base_id() + 1); } | 389 TypeFeedbackId test_id() const { return TypeFeedbackId(base_id() + 1); } |
| 390 | 390 |
| 391 protected: | 391 protected: |
| 392 Expression(Zone* zone, int pos, int num_ids_needed_by_subclass, IdGen* id_gen) | 392 Expression(Zone* zone, int pos, int num_ids_needed_by_subclass, IdGen* id_gen) |
| 393 : AstNode(pos), | 393 : AstNode(pos), |
| 394 base_id_( |
| 395 id_gen->ReserveIdRange(num_ids_needed_by_subclass + num_ids())), |
| 396 bounds_(Bounds::Unbounded(zone)), |
| 394 is_parenthesized_(false), | 397 is_parenthesized_(false), |
| 395 is_multi_parenthesized_(false), | 398 is_multi_parenthesized_(false) {} |
| 396 bounds_(Bounds::Unbounded(zone)), | |
| 397 base_id_( | |
| 398 id_gen->ReserveIdRange(num_ids_needed_by_subclass + num_ids())) {} | |
| 399 void set_to_boolean_types(byte types) { to_boolean_types_ = types; } | 399 void set_to_boolean_types(byte types) { to_boolean_types_ = types; } |
| 400 | 400 |
| 401 static int num_ids() { return 2; } | 401 static int num_ids() { return 2; } |
| 402 int base_id() const { return base_id_; } | 402 int base_id() const { return base_id_; } |
| 403 | 403 |
| 404 private: | 404 private: |
| 405 const int base_id_; |
| 406 Bounds bounds_; |
| 405 byte to_boolean_types_; | 407 byte to_boolean_types_; |
| 406 bool is_parenthesized_ : 1; | 408 bool is_parenthesized_ : 1; |
| 407 bool is_multi_parenthesized_ : 1; | 409 bool is_multi_parenthesized_ : 1; |
| 408 Bounds bounds_; | |
| 409 const int base_id_; | |
| 410 }; | 410 }; |
| 411 | 411 |
| 412 | 412 |
| 413 class BreakableStatement : public Statement { | 413 class BreakableStatement : public Statement { |
| 414 public: | 414 public: |
| 415 enum BreakableType { | 415 enum BreakableType { |
| 416 TARGET_FOR_ANONYMOUS, | 416 TARGET_FOR_ANONYMOUS, |
| 417 TARGET_FOR_NAMED_ONLY | 417 TARGET_FOR_NAMED_ONLY |
| 418 }; | 418 }; |
| 419 | 419 |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 504 | 504 |
| 505 class Declaration : public AstNode { | 505 class Declaration : public AstNode { |
| 506 public: | 506 public: |
| 507 VariableProxy* proxy() const { return proxy_; } | 507 VariableProxy* proxy() const { return proxy_; } |
| 508 VariableMode mode() const { return mode_; } | 508 VariableMode mode() const { return mode_; } |
| 509 Scope* scope() const { return scope_; } | 509 Scope* scope() const { return scope_; } |
| 510 virtual InitializationFlag initialization() const = 0; | 510 virtual InitializationFlag initialization() const = 0; |
| 511 virtual bool IsInlineable() const; | 511 virtual bool IsInlineable() const; |
| 512 | 512 |
| 513 protected: | 513 protected: |
| 514 Declaration(Zone* zone, | 514 Declaration(Zone* zone, VariableProxy* proxy, VariableMode mode, Scope* scope, |
| 515 VariableProxy* proxy, | |
| 516 VariableMode mode, | |
| 517 Scope* scope, | |
| 518 int pos) | 515 int pos) |
| 519 : AstNode(pos), | 516 : AstNode(pos), mode_(mode), proxy_(proxy), scope_(scope) { |
| 520 proxy_(proxy), | |
| 521 mode_(mode), | |
| 522 scope_(scope) { | |
| 523 DCHECK(IsDeclaredVariableMode(mode)); | 517 DCHECK(IsDeclaredVariableMode(mode)); |
| 524 } | 518 } |
| 525 | 519 |
| 526 private: | 520 private: |
| 521 VariableMode mode_; |
| 527 VariableProxy* proxy_; | 522 VariableProxy* proxy_; |
| 528 VariableMode mode_; | |
| 529 | 523 |
| 530 // Nested scope from which the declaration originated. | 524 // Nested scope from which the declaration originated. |
| 531 Scope* scope_; | 525 Scope* scope_; |
| 532 }; | 526 }; |
| 533 | 527 |
| 534 | 528 |
| 535 class VariableDeclaration FINAL : public Declaration { | 529 class VariableDeclaration FINAL : public Declaration { |
| 536 public: | 530 public: |
| 537 DECLARE_NODE_TYPE(VariableDeclaration) | 531 DECLARE_NODE_TYPE(VariableDeclaration) |
| 538 | 532 |
| (...skipping 1165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1704 } | 1698 } |
| 1705 | 1699 |
| 1706 FeedbackVectorSlot VariableFeedbackSlot() { return variable_feedback_slot_; } | 1700 FeedbackVectorSlot VariableFeedbackSlot() { return variable_feedback_slot_; } |
| 1707 | 1701 |
| 1708 protected: | 1702 protected: |
| 1709 VariableProxy(Zone* zone, Variable* var, int position, IdGen* id_gen); | 1703 VariableProxy(Zone* zone, Variable* var, int position, IdGen* id_gen); |
| 1710 | 1704 |
| 1711 VariableProxy(Zone* zone, const AstRawString* name, bool is_this, | 1705 VariableProxy(Zone* zone, const AstRawString* name, bool is_this, |
| 1712 Interface* interface, int position, IdGen* id_gen); | 1706 Interface* interface, int position, IdGen* id_gen); |
| 1713 | 1707 |
| 1708 bool is_this_ : 1; |
| 1709 bool is_assigned_ : 1; |
| 1710 bool is_resolved_ : 1; |
| 1711 FeedbackVectorSlot variable_feedback_slot_; |
| 1714 union { | 1712 union { |
| 1715 const AstRawString* raw_name_; // if !is_resolved_ | 1713 const AstRawString* raw_name_; // if !is_resolved_ |
| 1716 Variable* var_; // if is_resolved_ | 1714 Variable* var_; // if is_resolved_ |
| 1717 }; | 1715 }; |
| 1718 Interface* interface_; | 1716 Interface* interface_; |
| 1719 FeedbackVectorSlot variable_feedback_slot_; | |
| 1720 bool is_this_ : 1; | |
| 1721 bool is_assigned_ : 1; | |
| 1722 bool is_resolved_ : 1; | |
| 1723 }; | 1717 }; |
| 1724 | 1718 |
| 1725 | 1719 |
| 1726 class Property FINAL : public Expression { | 1720 class Property FINAL : public Expression { |
| 1727 public: | 1721 public: |
| 1728 DECLARE_NODE_TYPE(Property) | 1722 DECLARE_NODE_TYPE(Property) |
| 1729 | 1723 |
| 1730 virtual bool IsValidReferenceExpression() const OVERRIDE { return true; } | 1724 virtual bool IsValidReferenceExpression() const OVERRIDE { return true; } |
| 1731 | 1725 |
| 1732 Expression* obj() const { return obj_; } | 1726 Expression* obj() const { return obj_; } |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1766 property_feedback_slot_ = slot; | 1760 property_feedback_slot_ = slot; |
| 1767 } | 1761 } |
| 1768 | 1762 |
| 1769 FeedbackVectorSlot PropertyFeedbackSlot() const { | 1763 FeedbackVectorSlot PropertyFeedbackSlot() const { |
| 1770 return property_feedback_slot_; | 1764 return property_feedback_slot_; |
| 1771 } | 1765 } |
| 1772 | 1766 |
| 1773 protected: | 1767 protected: |
| 1774 Property(Zone* zone, Expression* obj, Expression* key, int pos, IdGen* id_gen) | 1768 Property(Zone* zone, Expression* obj, Expression* key, int pos, IdGen* id_gen) |
| 1775 : Expression(zone, pos, num_ids(), id_gen), | 1769 : Expression(zone, pos, num_ids(), id_gen), |
| 1776 obj_(obj), | |
| 1777 key_(key), | |
| 1778 property_feedback_slot_(FeedbackVectorSlot::Invalid()), | |
| 1779 is_for_call_(false), | 1770 is_for_call_(false), |
| 1780 is_uninitialized_(false), | 1771 is_uninitialized_(false), |
| 1781 is_string_access_(false) {} | 1772 is_string_access_(false), |
| 1773 property_feedback_slot_(FeedbackVectorSlot::Invalid()), |
| 1774 obj_(obj), |
| 1775 key_(key) {} |
| 1782 | 1776 |
| 1783 static int num_ids() { return 2; } | 1777 static int num_ids() { return 2; } |
| 1784 int base_id() const { return Expression::base_id() + Expression::num_ids(); } | 1778 int base_id() const { return Expression::base_id() + Expression::num_ids(); } |
| 1785 | 1779 |
| 1786 private: | 1780 private: |
| 1787 Expression* obj_; | |
| 1788 Expression* key_; | |
| 1789 FeedbackVectorSlot property_feedback_slot_; | |
| 1790 | |
| 1791 SmallMapList receiver_types_; | |
| 1792 bool is_for_call_ : 1; | 1781 bool is_for_call_ : 1; |
| 1793 bool is_uninitialized_ : 1; | 1782 bool is_uninitialized_ : 1; |
| 1794 bool is_string_access_ : 1; | 1783 bool is_string_access_ : 1; |
| 1784 FeedbackVectorSlot property_feedback_slot_; |
| 1785 Expression* obj_; |
| 1786 Expression* key_; |
| 1787 SmallMapList receiver_types_; |
| 1795 }; | 1788 }; |
| 1796 | 1789 |
| 1797 | 1790 |
| 1798 class Call FINAL : public Expression { | 1791 class Call FINAL : public Expression { |
| 1799 public: | 1792 public: |
| 1800 DECLARE_NODE_TYPE(Call) | 1793 DECLARE_NODE_TYPE(Call) |
| 1801 | 1794 |
| 1802 Expression* expression() const { return expression_; } | 1795 Expression* expression() const { return expression_; } |
| 1803 ZoneList<Expression*>* arguments() const { return arguments_; } | 1796 ZoneList<Expression*>* arguments() const { return arguments_; } |
| 1804 | 1797 |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1863 | 1856 |
| 1864 #ifdef DEBUG | 1857 #ifdef DEBUG |
| 1865 // Used to assert that the FullCodeGenerator records the return site. | 1858 // Used to assert that the FullCodeGenerator records the return site. |
| 1866 bool return_is_recorded_; | 1859 bool return_is_recorded_; |
| 1867 #endif | 1860 #endif |
| 1868 | 1861 |
| 1869 protected: | 1862 protected: |
| 1870 Call(Zone* zone, Expression* expression, ZoneList<Expression*>* arguments, | 1863 Call(Zone* zone, Expression* expression, ZoneList<Expression*>* arguments, |
| 1871 int pos, IdGen* id_gen) | 1864 int pos, IdGen* id_gen) |
| 1872 : Expression(zone, pos, num_ids(), id_gen), | 1865 : Expression(zone, pos, num_ids(), id_gen), |
| 1866 call_feedback_slot_(FeedbackVectorSlot::Invalid()), |
| 1873 expression_(expression), | 1867 expression_(expression), |
| 1874 arguments_(arguments), | 1868 arguments_(arguments) { |
| 1875 call_feedback_slot_(FeedbackVectorSlot::Invalid()) { | |
| 1876 if (expression->IsProperty()) { | 1869 if (expression->IsProperty()) { |
| 1877 expression->AsProperty()->mark_for_call(); | 1870 expression->AsProperty()->mark_for_call(); |
| 1878 } | 1871 } |
| 1879 } | 1872 } |
| 1880 | 1873 |
| 1881 static int num_ids() { return 2; } | 1874 static int num_ids() { return 2; } |
| 1882 int base_id() const { return Expression::base_id() + Expression::num_ids(); } | 1875 int base_id() const { return Expression::base_id() + Expression::num_ids(); } |
| 1883 | 1876 |
| 1884 private: | 1877 private: |
| 1878 FeedbackVectorSlot call_feedback_slot_; |
| 1885 Expression* expression_; | 1879 Expression* expression_; |
| 1886 ZoneList<Expression*>* arguments_; | 1880 ZoneList<Expression*>* arguments_; |
| 1887 Handle<JSFunction> target_; | 1881 Handle<JSFunction> target_; |
| 1888 Handle<Cell> cell_; | 1882 Handle<Cell> cell_; |
| 1889 Handle<AllocationSite> allocation_site_; | 1883 Handle<AllocationSite> allocation_site_; |
| 1890 FeedbackVectorSlot call_feedback_slot_; | |
| 1891 }; | 1884 }; |
| 1892 | 1885 |
| 1893 | 1886 |
| 1894 class CallNew FINAL : public Expression { | 1887 class CallNew FINAL : public Expression { |
| 1895 public: | 1888 public: |
| 1896 DECLARE_NODE_TYPE(CallNew) | 1889 DECLARE_NODE_TYPE(CallNew) |
| 1897 | 1890 |
| 1898 Expression* expression() const { return expression_; } | 1891 Expression* expression() const { return expression_; } |
| 1899 ZoneList<Expression*>* arguments() const { return arguments_; } | 1892 ZoneList<Expression*>* arguments() const { return arguments_; } |
| 1900 | 1893 |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2028 Expression* expression_; | 2021 Expression* expression_; |
| 2029 }; | 2022 }; |
| 2030 | 2023 |
| 2031 | 2024 |
| 2032 class BinaryOperation FINAL : public Expression { | 2025 class BinaryOperation FINAL : public Expression { |
| 2033 public: | 2026 public: |
| 2034 DECLARE_NODE_TYPE(BinaryOperation) | 2027 DECLARE_NODE_TYPE(BinaryOperation) |
| 2035 | 2028 |
| 2036 virtual bool ResultOverwriteAllowed() const OVERRIDE; | 2029 virtual bool ResultOverwriteAllowed() const OVERRIDE; |
| 2037 | 2030 |
| 2038 Token::Value op() const { return op_; } | 2031 Token::Value op() const { return static_cast<Token::Value>(op_); } |
| 2039 Expression* left() const { return left_; } | 2032 Expression* left() const { return left_; } |
| 2040 Expression* right() const { return right_; } | 2033 Expression* right() const { return right_; } |
| 2041 Handle<AllocationSite> allocation_site() const { return allocation_site_; } | 2034 Handle<AllocationSite> allocation_site() const { return allocation_site_; } |
| 2042 void set_allocation_site(Handle<AllocationSite> allocation_site) { | 2035 void set_allocation_site(Handle<AllocationSite> allocation_site) { |
| 2043 allocation_site_ = allocation_site; | 2036 allocation_site_ = allocation_site; |
| 2044 } | 2037 } |
| 2045 | 2038 |
| 2046 // The short-circuit logical operations need an AST ID for their | 2039 // The short-circuit logical operations need an AST ID for their |
| 2047 // right-hand subexpression. | 2040 // right-hand subexpression. |
| 2048 BailoutId RightId() const { return BailoutId(base_id() + 0); } | 2041 BailoutId RightId() const { return BailoutId(base_id() + 0); } |
| 2049 | 2042 |
| 2050 TypeFeedbackId BinaryOperationFeedbackId() const { | 2043 TypeFeedbackId BinaryOperationFeedbackId() const { |
| 2051 return TypeFeedbackId(base_id() + 1); | 2044 return TypeFeedbackId(base_id() + 1); |
| 2052 } | 2045 } |
| 2053 Maybe<int> fixed_right_arg() const { return fixed_right_arg_; } | 2046 Maybe<int> fixed_right_arg() const { |
| 2054 void set_fixed_right_arg(Maybe<int> arg) { fixed_right_arg_ = arg; } | 2047 return has_fixed_right_arg_ ? Maybe<int>(fixed_right_arg_value_) |
| 2048 : Maybe<int>(); |
| 2049 } |
| 2050 void set_fixed_right_arg(Maybe<int> arg) { |
| 2051 has_fixed_right_arg_ = arg.has_value; |
| 2052 if (arg.has_value) fixed_right_arg_value_ = arg.value; |
| 2053 } |
| 2055 | 2054 |
| 2056 virtual void RecordToBooleanTypeFeedback( | 2055 virtual void RecordToBooleanTypeFeedback( |
| 2057 TypeFeedbackOracle* oracle) OVERRIDE; | 2056 TypeFeedbackOracle* oracle) OVERRIDE; |
| 2058 | 2057 |
| 2059 protected: | 2058 protected: |
| 2060 BinaryOperation(Zone* zone, Token::Value op, Expression* left, | 2059 BinaryOperation(Zone* zone, Token::Value op, Expression* left, |
| 2061 Expression* right, int pos, IdGen* id_gen) | 2060 Expression* right, int pos, IdGen* id_gen) |
| 2062 : Expression(zone, pos, num_ids(), id_gen), | 2061 : Expression(zone, pos, num_ids(), id_gen), |
| 2063 op_(op), | 2062 op_(static_cast<byte>(op)), |
| 2064 left_(left), | 2063 left_(left), |
| 2065 right_(right) { | 2064 right_(right) { |
| 2066 DCHECK(Token::IsBinaryOp(op)); | 2065 DCHECK(Token::IsBinaryOp(op)); |
| 2067 } | 2066 } |
| 2068 | 2067 |
| 2069 static int num_ids() { return 2; } | 2068 static int num_ids() { return 2; } |
| 2070 int base_id() const { return Expression::base_id() + Expression::num_ids(); } | 2069 int base_id() const { return Expression::base_id() + Expression::num_ids(); } |
| 2071 | 2070 |
| 2072 private: | 2071 private: |
| 2073 Token::Value op_; | 2072 const byte op_; // actually Token::Value |
| 2073 // TODO(rossberg): the fixed arg should probably be represented as a Constant |
| 2074 // type for the RHS. Currenty it's actually a Maybe<int> |
| 2075 bool has_fixed_right_arg_; |
| 2076 int fixed_right_arg_value_; |
| 2074 Expression* left_; | 2077 Expression* left_; |
| 2075 Expression* right_; | 2078 Expression* right_; |
| 2076 Handle<AllocationSite> allocation_site_; | 2079 Handle<AllocationSite> allocation_site_; |
| 2077 | |
| 2078 // TODO(rossberg): the fixed arg should probably be represented as a Constant | |
| 2079 // type for the RHS. | |
| 2080 Maybe<int> fixed_right_arg_; | |
| 2081 }; | 2080 }; |
| 2082 | 2081 |
| 2083 | 2082 |
| 2084 class CountOperation FINAL : public Expression { | 2083 class CountOperation FINAL : public Expression { |
| 2085 public: | 2084 public: |
| 2086 DECLARE_NODE_TYPE(CountOperation) | 2085 DECLARE_NODE_TYPE(CountOperation) |
| 2087 | 2086 |
| 2088 bool is_prefix() const { return is_prefix_; } | 2087 bool is_prefix() const { return is_prefix_; } |
| 2089 bool is_postfix() const { return !is_prefix_; } | 2088 bool is_postfix() const { return !is_prefix_; } |
| 2090 | 2089 |
| (...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2264 template<class Visitor> | 2263 template<class Visitor> |
| 2265 void Init(Zone* zone, AstNodeFactory<Visitor>* factory) { | 2264 void Init(Zone* zone, AstNodeFactory<Visitor>* factory) { |
| 2266 DCHECK(Token::IsAssignmentOp(op_)); | 2265 DCHECK(Token::IsAssignmentOp(op_)); |
| 2267 if (is_compound()) { | 2266 if (is_compound()) { |
| 2268 binary_operation_ = factory->NewBinaryOperation( | 2267 binary_operation_ = factory->NewBinaryOperation( |
| 2269 binary_op(), target_, value_, position() + 1); | 2268 binary_op(), target_, value_, position() + 1); |
| 2270 } | 2269 } |
| 2271 } | 2270 } |
| 2272 | 2271 |
| 2273 private: | 2272 private: |
| 2273 bool is_uninitialized_ : 1; |
| 2274 IcCheckType key_type_ : 1; |
| 2275 KeyedAccessStoreMode store_mode_ : 5; // Windows treats as signed, |
| 2276 // must have extra bit. |
| 2274 Token::Value op_; | 2277 Token::Value op_; |
| 2275 Expression* target_; | 2278 Expression* target_; |
| 2276 Expression* value_; | 2279 Expression* value_; |
| 2277 BinaryOperation* binary_operation_; | 2280 BinaryOperation* binary_operation_; |
| 2278 bool is_uninitialized_ : 1; | |
| 2279 IcCheckType key_type_ : 1; | |
| 2280 KeyedAccessStoreMode store_mode_ : 5; // Windows treats as signed, | |
| 2281 // must have extra bit. | |
| 2282 SmallMapList receiver_types_; | 2281 SmallMapList receiver_types_; |
| 2283 }; | 2282 }; |
| 2284 | 2283 |
| 2285 | 2284 |
| 2286 class Yield FINAL : public Expression { | 2285 class Yield FINAL : public Expression { |
| 2287 public: | 2286 public: |
| 2288 DECLARE_NODE_TYPE(Yield) | 2287 DECLARE_NODE_TYPE(Yield) |
| 2289 | 2288 |
| 2290 enum Kind { | 2289 enum Kind { |
| 2291 kInitial, // The initial yield that returns the unboxed generator object. | 2290 kInitial, // The initial yield that returns the unboxed generator object. |
| (...skipping 1333 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3625 Zone* zone_; | 3624 Zone* zone_; |
| 3626 Visitor visitor_; | 3625 Visitor visitor_; |
| 3627 AstValueFactory* ast_value_factory_; | 3626 AstValueFactory* ast_value_factory_; |
| 3628 AstNode::IdGen* id_gen_; | 3627 AstNode::IdGen* id_gen_; |
| 3629 }; | 3628 }; |
| 3630 | 3629 |
| 3631 | 3630 |
| 3632 } } // namespace v8::internal | 3631 } } // namespace v8::internal |
| 3633 | 3632 |
| 3634 #endif // V8_AST_H_ | 3633 #endif // V8_AST_H_ |
| OLD | NEW |