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-value-factory.h" | 9 #include "src/ast/ast-value-factory.h" |
10 #include "src/ast/modules.h" | 10 #include "src/ast/modules.h" |
(...skipping 772 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
783 }; | 783 }; |
784 | 784 |
785 | 785 |
786 class ForEachStatement : public IterationStatement { | 786 class ForEachStatement : public IterationStatement { |
787 public: | 787 public: |
788 enum VisitMode { | 788 enum VisitMode { |
789 ENUMERATE, // for (each in subject) body; | 789 ENUMERATE, // for (each in subject) body; |
790 ITERATE // for (each of subject) body; | 790 ITERATE // for (each of subject) body; |
791 }; | 791 }; |
792 | 792 |
793 void Initialize(Expression* each, Expression* subject, Statement* body) { | 793 using IterationStatement::Initialize; |
794 IterationStatement::Initialize(body); | |
795 each_ = each; | |
796 subject_ = subject; | |
797 } | |
798 | |
799 Expression* each() const { return each_; } | |
800 Expression* subject() const { return subject_; } | |
801 | |
802 void set_each(Expression* e) { each_ = e; } | |
803 void set_subject(Expression* e) { subject_ = e; } | |
804 | 794 |
805 static const char* VisitModeString(VisitMode mode) { | 795 static const char* VisitModeString(VisitMode mode) { |
806 return mode == ITERATE ? "for-of" : "for-in"; | 796 return mode == ITERATE ? "for-of" : "for-in"; |
807 } | 797 } |
808 | 798 |
809 protected: | 799 protected: |
810 ForEachStatement(Zone* zone, ZoneList<const AstRawString*>* labels, int pos) | 800 ForEachStatement(Zone* zone, ZoneList<const AstRawString*>* labels, int pos) |
811 : IterationStatement(zone, labels, pos), each_(NULL), subject_(NULL) {} | 801 : IterationStatement(zone, labels, pos) {} |
812 | |
813 private: | |
814 Expression* each_; | |
815 Expression* subject_; | |
816 }; | 802 }; |
817 | 803 |
818 | 804 |
819 class ForInStatement final : public ForEachStatement { | 805 class ForInStatement final : public ForEachStatement { |
820 public: | 806 public: |
821 DECLARE_NODE_TYPE(ForInStatement) | 807 DECLARE_NODE_TYPE(ForInStatement) |
822 | 808 |
| 809 void Initialize(Expression* each, Expression* subject, Statement* body) { |
| 810 ForEachStatement::Initialize(body); |
| 811 each_ = each; |
| 812 subject_ = subject; |
| 813 } |
| 814 |
823 Expression* enumerable() const { | 815 Expression* enumerable() const { |
824 return subject(); | 816 return subject(); |
825 } | 817 } |
826 | 818 |
| 819 Expression* each() const { return each_; } |
| 820 Expression* subject() const { return subject_; } |
| 821 |
| 822 void set_each(Expression* e) { each_ = e; } |
| 823 void set_subject(Expression* e) { subject_ = e; } |
| 824 |
827 // Type feedback information. | 825 // Type feedback information. |
828 void AssignFeedbackVectorSlots(Isolate* isolate, FeedbackVectorSpec* spec, | 826 void AssignFeedbackVectorSlots(Isolate* isolate, FeedbackVectorSpec* spec, |
829 FeedbackVectorSlotCache* cache) override; | 827 FeedbackVectorSlotCache* cache) override; |
830 FeedbackVectorSlot EachFeedbackSlot() const { return each_slot_; } | 828 FeedbackVectorSlot EachFeedbackSlot() const { return each_slot_; } |
831 FeedbackVectorSlot ForInFeedbackSlot() { | 829 FeedbackVectorSlot ForInFeedbackSlot() { |
832 DCHECK(!for_in_feedback_slot_.IsInvalid()); | 830 DCHECK(!for_in_feedback_slot_.IsInvalid()); |
833 return for_in_feedback_slot_; | 831 return for_in_feedback_slot_; |
834 } | 832 } |
835 | 833 |
836 enum ForInType { FAST_FOR_IN, SLOW_FOR_IN }; | 834 enum ForInType { FAST_FOR_IN, SLOW_FOR_IN }; |
837 ForInType for_in_type() const { return for_in_type_; } | 835 ForInType for_in_type() const { return for_in_type_; } |
838 void set_for_in_type(ForInType type) { for_in_type_ = type; } | 836 void set_for_in_type(ForInType type) { for_in_type_ = type; } |
839 | 837 |
840 static int num_ids() { return parent_num_ids() + 6; } | 838 static int num_ids() { return parent_num_ids() + 6; } |
841 BailoutId BodyId() const { return BailoutId(local_id(0)); } | 839 BailoutId BodyId() const { return BailoutId(local_id(0)); } |
842 BailoutId EnumId() const { return BailoutId(local_id(1)); } | 840 BailoutId EnumId() const { return BailoutId(local_id(1)); } |
843 BailoutId ToObjectId() const { return BailoutId(local_id(2)); } | 841 BailoutId ToObjectId() const { return BailoutId(local_id(2)); } |
844 BailoutId PrepareId() const { return BailoutId(local_id(3)); } | 842 BailoutId PrepareId() const { return BailoutId(local_id(3)); } |
845 BailoutId FilterId() const { return BailoutId(local_id(4)); } | 843 BailoutId FilterId() const { return BailoutId(local_id(4)); } |
846 BailoutId AssignmentId() const { return BailoutId(local_id(5)); } | 844 BailoutId AssignmentId() const { return BailoutId(local_id(5)); } |
847 BailoutId ContinueId() const override { return EntryId(); } | 845 BailoutId ContinueId() const override { return EntryId(); } |
848 BailoutId StackCheckId() const override { return BodyId(); } | 846 BailoutId StackCheckId() const override { return BodyId(); } |
849 | 847 |
850 protected: | 848 protected: |
851 ForInStatement(Zone* zone, ZoneList<const AstRawString*>* labels, int pos) | 849 ForInStatement(Zone* zone, ZoneList<const AstRawString*>* labels, int pos) |
852 : ForEachStatement(zone, labels, pos), for_in_type_(SLOW_FOR_IN) {} | 850 : ForEachStatement(zone, labels, pos), |
| 851 each_(nullptr), |
| 852 subject_(nullptr), |
| 853 for_in_type_(SLOW_FOR_IN) {} |
853 static int parent_num_ids() { return ForEachStatement::num_ids(); } | 854 static int parent_num_ids() { return ForEachStatement::num_ids(); } |
854 | 855 |
855 private: | 856 private: |
856 int local_id(int n) const { return base_id() + parent_num_ids() + n; } | 857 int local_id(int n) const { return base_id() + parent_num_ids() + n; } |
857 | 858 |
| 859 Expression* each_; |
| 860 Expression* subject_; |
858 ForInType for_in_type_; | 861 ForInType for_in_type_; |
859 FeedbackVectorSlot each_slot_; | 862 FeedbackVectorSlot each_slot_; |
860 FeedbackVectorSlot for_in_feedback_slot_; | 863 FeedbackVectorSlot for_in_feedback_slot_; |
861 }; | 864 }; |
862 | 865 |
863 | 866 |
864 class ForOfStatement final : public ForEachStatement { | 867 class ForOfStatement final : public ForEachStatement { |
865 public: | 868 public: |
866 DECLARE_NODE_TYPE(ForOfStatement) | 869 DECLARE_NODE_TYPE(ForOfStatement) |
867 | 870 |
868 void Initialize(Expression* each, | 871 void Initialize(Statement* body, Variable* iterator, |
869 Expression* subject, | 872 Expression* assign_iterator, Expression* next_result, |
870 Statement* body, | 873 Expression* result_done, Expression* assign_each) { |
871 Variable* iterator, | 874 ForEachStatement::Initialize(body); |
872 Expression* assign_iterator, | |
873 Expression* next_result, | |
874 Expression* result_done, | |
875 Expression* assign_each) { | |
876 ForEachStatement::Initialize(each, subject, body); | |
877 iterator_ = iterator; | 875 iterator_ = iterator; |
878 assign_iterator_ = assign_iterator; | 876 assign_iterator_ = assign_iterator; |
879 next_result_ = next_result; | 877 next_result_ = next_result; |
880 result_done_ = result_done; | 878 result_done_ = result_done; |
881 assign_each_ = assign_each; | 879 assign_each_ = assign_each; |
882 } | 880 } |
883 | 881 |
884 Expression* iterable() const { | |
885 return subject(); | |
886 } | |
887 | |
888 Variable* iterator() const { | 882 Variable* iterator() const { |
889 return iterator_; | 883 return iterator_; |
890 } | 884 } |
891 | 885 |
892 // iterator = subject[Symbol.iterator]() | 886 // iterator = subject[Symbol.iterator]() |
893 Expression* assign_iterator() const { | 887 Expression* assign_iterator() const { |
894 return assign_iterator_; | 888 return assign_iterator_; |
895 } | 889 } |
896 | 890 |
897 // result = iterator.next() // with type check | 891 // result = iterator.next() // with type check |
(...skipping 2660 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3558 : NULL; \ | 3552 : NULL; \ |
3559 } | 3553 } |
3560 AST_NODE_LIST(DECLARE_NODE_FUNCTIONS) | 3554 AST_NODE_LIST(DECLARE_NODE_FUNCTIONS) |
3561 #undef DECLARE_NODE_FUNCTIONS | 3555 #undef DECLARE_NODE_FUNCTIONS |
3562 | 3556 |
3563 | 3557 |
3564 } // namespace internal | 3558 } // namespace internal |
3565 } // namespace v8 | 3559 } // namespace v8 |
3566 | 3560 |
3567 #endif // V8_AST_AST_H_ | 3561 #endif // V8_AST_AST_H_ |
OLD | NEW |