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 865 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
876 }; | 876 }; |
877 | 877 |
878 | 878 |
879 class ForOfStatement final : public ForEachStatement { | 879 class ForOfStatement final : public ForEachStatement { |
880 public: | 880 public: |
881 DECLARE_NODE_TYPE(ForOfStatement) | 881 DECLARE_NODE_TYPE(ForOfStatement) |
882 | 882 |
883 void Initialize(Expression* each, | 883 void Initialize(Expression* each, |
884 Expression* subject, | 884 Expression* subject, |
885 Statement* body, | 885 Statement* body, |
886 Variable* iterator, | |
886 Expression* assign_iterator, | 887 Expression* assign_iterator, |
887 Expression* next_result, | 888 Expression* next_result, |
888 Expression* result_done, | 889 Expression* result_done, |
889 Expression* assign_each) { | 890 Expression* assign_each) { |
890 ForEachStatement::Initialize(each, subject, body); | 891 ForEachStatement::Initialize(each, subject, body); |
892 iterator_ = iterator; | |
891 assign_iterator_ = assign_iterator; | 893 assign_iterator_ = assign_iterator; |
892 next_result_ = next_result; | 894 next_result_ = next_result; |
893 result_done_ = result_done; | 895 result_done_ = result_done; |
894 assign_each_ = assign_each; | 896 assign_each_ = assign_each; |
895 } | 897 } |
896 | 898 |
897 Expression* iterable() const { | 899 Expression* iterable() const { |
898 return subject(); | 900 return subject(); |
899 } | 901 } |
900 | 902 |
903 Variable* iterator() const { | |
904 return iterator_; | |
905 } | |
906 | |
neis
2016/02/12 12:30:13
Instead of having iterator_, we could extract the
| |
901 // iterator = subject[Symbol.iterator]() | 907 // iterator = subject[Symbol.iterator]() |
902 Expression* assign_iterator() const { | 908 Expression* assign_iterator() const { |
903 return assign_iterator_; | 909 return assign_iterator_; |
904 } | 910 } |
905 | 911 |
906 // result = iterator.next() // with type check | 912 // result = iterator.next() // with type check |
907 Expression* next_result() const { | 913 Expression* next_result() const { |
908 return next_result_; | 914 return next_result_; |
909 } | 915 } |
910 | 916 |
(...skipping 14 matching lines...) Expand all Loading... | |
925 | 931 |
926 BailoutId ContinueId() const override { return EntryId(); } | 932 BailoutId ContinueId() const override { return EntryId(); } |
927 BailoutId StackCheckId() const override { return BackEdgeId(); } | 933 BailoutId StackCheckId() const override { return BackEdgeId(); } |
928 | 934 |
929 static int num_ids() { return parent_num_ids() + 1; } | 935 static int num_ids() { return parent_num_ids() + 1; } |
930 BailoutId BackEdgeId() const { return BailoutId(local_id(0)); } | 936 BailoutId BackEdgeId() const { return BailoutId(local_id(0)); } |
931 | 937 |
932 protected: | 938 protected: |
933 ForOfStatement(Zone* zone, ZoneList<const AstRawString*>* labels, int pos) | 939 ForOfStatement(Zone* zone, ZoneList<const AstRawString*>* labels, int pos) |
934 : ForEachStatement(zone, labels, pos), | 940 : ForEachStatement(zone, labels, pos), |
941 iterator_(NULL), | |
935 assign_iterator_(NULL), | 942 assign_iterator_(NULL), |
936 next_result_(NULL), | 943 next_result_(NULL), |
937 result_done_(NULL), | 944 result_done_(NULL), |
938 assign_each_(NULL) {} | 945 assign_each_(NULL) {} |
939 static int parent_num_ids() { return ForEachStatement::num_ids(); } | 946 static int parent_num_ids() { return ForEachStatement::num_ids(); } |
940 | 947 |
941 private: | 948 private: |
942 int local_id(int n) const { return base_id() + parent_num_ids() + n; } | 949 int local_id(int n) const { return base_id() + parent_num_ids() + n; } |
943 | 950 |
951 Variable* iterator_; | |
944 Expression* assign_iterator_; | 952 Expression* assign_iterator_; |
945 Expression* next_result_; | 953 Expression* next_result_; |
946 Expression* result_done_; | 954 Expression* result_done_; |
947 Expression* assign_each_; | 955 Expression* assign_each_; |
948 }; | 956 }; |
949 | 957 |
950 | 958 |
951 class ExpressionStatement final : public Statement { | 959 class ExpressionStatement final : public Statement { |
952 public: | 960 public: |
953 DECLARE_NODE_TYPE(ExpressionStatement) | 961 DECLARE_NODE_TYPE(ExpressionStatement) |
(...skipping 2558 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3512 // the parser-level zone. | 3520 // the parser-level zone. |
3513 Zone* parser_zone_; | 3521 Zone* parser_zone_; |
3514 AstValueFactory* ast_value_factory_; | 3522 AstValueFactory* ast_value_factory_; |
3515 }; | 3523 }; |
3516 | 3524 |
3517 | 3525 |
3518 } // namespace internal | 3526 } // namespace internal |
3519 } // namespace v8 | 3527 } // namespace v8 |
3520 | 3528 |
3521 #endif // V8_AST_AST_H_ | 3529 #endif // V8_AST_AST_H_ |
OLD | NEW |