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 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 81 V(IfStatement) \ | 81 V(IfStatement) \ |
| 82 V(ContinueStatement) \ | 82 V(ContinueStatement) \ |
| 83 V(BreakStatement) \ | 83 V(BreakStatement) \ |
| 84 V(ReturnStatement) \ | 84 V(ReturnStatement) \ |
| 85 V(WithStatement) \ | 85 V(WithStatement) \ |
| 86 V(SwitchStatement) \ | 86 V(SwitchStatement) \ |
| 87 V(DoWhileStatement) \ | 87 V(DoWhileStatement) \ |
| 88 V(WhileStatement) \ | 88 V(WhileStatement) \ |
| 89 V(ForStatement) \ | 89 V(ForStatement) \ |
| 90 V(ForInStatement) \ | 90 V(ForInStatement) \ |
| 91 V(ForOfStatement) \ | |
| 91 V(TryCatchStatement) \ | 92 V(TryCatchStatement) \ |
| 92 V(TryFinallyStatement) \ | 93 V(TryFinallyStatement) \ |
| 93 V(DebuggerStatement) | 94 V(DebuggerStatement) |
| 94 | 95 |
| 95 #define EXPRESSION_NODE_LIST(V) \ | 96 #define EXPRESSION_NODE_LIST(V) \ |
| 96 V(FunctionLiteral) \ | 97 V(FunctionLiteral) \ |
| 97 V(SharedFunctionInfoLiteral) \ | 98 V(SharedFunctionInfoLiteral) \ |
| 98 V(Conditional) \ | 99 V(Conditional) \ |
| 99 V(VariableProxy) \ | 100 V(VariableProxy) \ |
| 100 V(Literal) \ | 101 V(Literal) \ |
| (...skipping 741 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 842 Expression* cond_; | 843 Expression* cond_; |
| 843 Statement* next_; | 844 Statement* next_; |
| 844 // True if there is a function literal subexpression in the condition. | 845 // True if there is a function literal subexpression in the condition. |
| 845 bool may_have_function_literal_; | 846 bool may_have_function_literal_; |
| 846 Variable* loop_variable_; | 847 Variable* loop_variable_; |
| 847 const BailoutId continue_id_; | 848 const BailoutId continue_id_; |
| 848 const BailoutId body_id_; | 849 const BailoutId body_id_; |
| 849 }; | 850 }; |
| 850 | 851 |
| 851 | 852 |
| 852 class ForInStatement: public IterationStatement { | 853 class ForEachStatement: public IterationStatement { |
| 853 public: | 854 public: |
| 854 DECLARE_NODE_TYPE(ForInStatement) | 855 enum VisitMode { |
| 856 ENUMERATE, // for (each in subject) body; | |
| 857 ITERATE // for (each of subject) body; | |
| 858 }; | |
| 855 | 859 |
| 856 void Initialize(Expression* each, Expression* enumerable, Statement* body) { | 860 void Initialize(Expression* each, |
|
rossberg
2013/06/06 10:32:33
Nit: doesn't this fit on one line?
wingo
2013/06/06 14:09:51
Ah, yep. Artifact from a previous patch; fixed.
| |
| 861 Expression* subject, | |
| 862 Statement* body) { | |
| 857 IterationStatement::Initialize(body); | 863 IterationStatement::Initialize(body); |
| 858 each_ = each; | 864 each_ = each; |
| 859 enumerable_ = enumerable; | 865 subject_ = subject; |
| 860 } | 866 } |
| 861 | 867 |
| 862 Expression* each() const { return each_; } | 868 Expression* each() const { return each_; } |
| 863 Expression* enumerable() const { return enumerable_; } | 869 Expression* subject() const { return subject_; } |
| 864 | 870 |
| 865 virtual BailoutId ContinueId() const { return EntryId(); } | 871 virtual BailoutId ContinueId() const { return EntryId(); } |
| 866 virtual BailoutId StackCheckId() const { return body_id_; } | 872 virtual BailoutId StackCheckId() const { return body_id_; } |
| 867 BailoutId BodyId() const { return body_id_; } | 873 BailoutId BodyId() const { return body_id_; } |
| 868 BailoutId PrepareId() const { return prepare_id_; } | 874 BailoutId PrepareId() const { return prepare_id_; } |
| 869 | 875 |
| 870 TypeFeedbackId ForInFeedbackId() const { return reuse(PrepareId()); } | |
| 871 | |
| 872 protected: | 876 protected: |
| 873 ForInStatement(Isolate* isolate, ZoneStringList* labels) | 877 ForEachStatement(Isolate* isolate, ZoneStringList* labels) |
| 874 : IterationStatement(isolate, labels), | 878 : IterationStatement(isolate, labels), |
| 875 each_(NULL), | 879 each_(NULL), |
| 876 enumerable_(NULL), | 880 subject_(NULL), |
| 877 body_id_(GetNextId(isolate)), | 881 body_id_(GetNextId(isolate)), |
| 878 prepare_id_(GetNextId(isolate)) { | 882 prepare_id_(GetNextId(isolate)) { |
| 879 } | 883 } |
| 880 | 884 |
| 881 private: | 885 private: |
| 882 Expression* each_; | 886 Expression* each_; |
| 883 Expression* enumerable_; | 887 Expression* subject_; |
| 884 const BailoutId body_id_; | 888 const BailoutId body_id_; |
| 885 const BailoutId prepare_id_; | 889 const BailoutId prepare_id_; |
| 886 }; | 890 }; |
| 887 | 891 |
| 888 | 892 |
| 893 class ForInStatement: public ForEachStatement { | |
| 894 public: | |
| 895 DECLARE_NODE_TYPE(ForInStatement) | |
| 896 | |
| 897 Expression* enumerable() const { | |
| 898 return subject(); | |
| 899 } | |
| 900 | |
| 901 TypeFeedbackId ForInFeedbackId() const { return reuse(PrepareId()); } | |
| 902 | |
| 903 protected: | |
| 904 ForInStatement(Isolate* isolate, ZoneStringList* labels) | |
| 905 : ForEachStatement(isolate, labels) { | |
| 906 } | |
| 907 }; | |
| 908 | |
| 909 | |
| 910 class ForOfStatement: public ForEachStatement { | |
| 911 public: | |
| 912 DECLARE_NODE_TYPE(ForOfStatement) | |
| 913 | |
| 914 Expression* iterable() const { | |
| 915 return subject(); | |
| 916 } | |
| 917 | |
| 918 protected: | |
| 919 ForOfStatement(Isolate* isolate, ZoneStringList* labels) | |
| 920 : ForEachStatement(isolate, labels) { | |
| 921 } | |
| 922 }; | |
| 923 | |
| 924 | |
| 889 class ExpressionStatement: public Statement { | 925 class ExpressionStatement: public Statement { |
| 890 public: | 926 public: |
| 891 DECLARE_NODE_TYPE(ExpressionStatement) | 927 DECLARE_NODE_TYPE(ExpressionStatement) |
| 892 | 928 |
| 893 void set_expression(Expression* e) { expression_ = e; } | 929 void set_expression(Expression* e) { expression_ = e; } |
| 894 Expression* expression() const { return expression_; } | 930 Expression* expression() const { return expression_; } |
| 895 | 931 |
| 896 protected: | 932 protected: |
| 897 explicit ExpressionStatement(Expression* expression) | 933 explicit ExpressionStatement(Expression* expression) |
| 898 : expression_(expression) { } | 934 : expression_(expression) { } |
| (...skipping 1880 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2779 } | 2815 } |
| 2780 | 2816 |
| 2781 #define STATEMENT_WITH_LABELS(NodeType) \ | 2817 #define STATEMENT_WITH_LABELS(NodeType) \ |
| 2782 NodeType* New##NodeType(ZoneStringList* labels) { \ | 2818 NodeType* New##NodeType(ZoneStringList* labels) { \ |
| 2783 NodeType* stmt = new(zone_) NodeType(isolate_, labels); \ | 2819 NodeType* stmt = new(zone_) NodeType(isolate_, labels); \ |
| 2784 VISIT_AND_RETURN(NodeType, stmt); \ | 2820 VISIT_AND_RETURN(NodeType, stmt); \ |
| 2785 } | 2821 } |
| 2786 STATEMENT_WITH_LABELS(DoWhileStatement) | 2822 STATEMENT_WITH_LABELS(DoWhileStatement) |
| 2787 STATEMENT_WITH_LABELS(WhileStatement) | 2823 STATEMENT_WITH_LABELS(WhileStatement) |
| 2788 STATEMENT_WITH_LABELS(ForStatement) | 2824 STATEMENT_WITH_LABELS(ForStatement) |
| 2789 STATEMENT_WITH_LABELS(ForInStatement) | |
| 2790 STATEMENT_WITH_LABELS(SwitchStatement) | 2825 STATEMENT_WITH_LABELS(SwitchStatement) |
| 2791 #undef STATEMENT_WITH_LABELS | 2826 #undef STATEMENT_WITH_LABELS |
| 2792 | 2827 |
| 2828 ForEachStatement* NewForEachStatement(ForEachStatement::VisitMode visit_mode, | |
| 2829 ZoneStringList* labels) { | |
| 2830 switch (visit_mode) { | |
| 2831 case ForEachStatement::ENUMERATE: { | |
| 2832 ForInStatement* stmt = new(zone_) ForInStatement(isolate_, labels); | |
| 2833 VISIT_AND_RETURN(ForInStatement, stmt); | |
| 2834 } | |
| 2835 case ForEachStatement::ITERATE: { | |
| 2836 ForOfStatement* stmt = new(zone_) ForOfStatement(isolate_, labels); | |
| 2837 VISIT_AND_RETURN(ForOfStatement, stmt); | |
| 2838 } | |
| 2839 default: | |
|
Michael Starzinger
2013/06/06 09:36:36
Please avoid default cases in switches over enums.
wingo
2013/06/06 14:09:51
Fixed as per Sven's recommendation. I think it wa
| |
| 2840 UNREACHABLE(); | |
| 2841 return NULL; | |
| 2842 } | |
| 2843 } | |
| 2844 | |
| 2793 ModuleStatement* NewModuleStatement(VariableProxy* proxy, Block* body) { | 2845 ModuleStatement* NewModuleStatement(VariableProxy* proxy, Block* body) { |
| 2794 ModuleStatement* stmt = new(zone_) ModuleStatement(proxy, body); | 2846 ModuleStatement* stmt = new(zone_) ModuleStatement(proxy, body); |
| 2795 VISIT_AND_RETURN(ModuleStatement, stmt) | 2847 VISIT_AND_RETURN(ModuleStatement, stmt) |
| 2796 } | 2848 } |
| 2797 | 2849 |
| 2798 ExpressionStatement* NewExpressionStatement(Expression* expression) { | 2850 ExpressionStatement* NewExpressionStatement(Expression* expression) { |
| 2799 ExpressionStatement* stmt = new(zone_) ExpressionStatement(expression); | 2851 ExpressionStatement* stmt = new(zone_) ExpressionStatement(expression); |
| 2800 VISIT_AND_RETURN(ExpressionStatement, stmt) | 2852 VISIT_AND_RETURN(ExpressionStatement, stmt) |
| 2801 } | 2853 } |
| 2802 | 2854 |
| (...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3064 private: | 3116 private: |
| 3065 Isolate* isolate_; | 3117 Isolate* isolate_; |
| 3066 Zone* zone_; | 3118 Zone* zone_; |
| 3067 Visitor visitor_; | 3119 Visitor visitor_; |
| 3068 }; | 3120 }; |
| 3069 | 3121 |
| 3070 | 3122 |
| 3071 } } // namespace v8::internal | 3123 } } // namespace v8::internal |
| 3072 | 3124 |
| 3073 #endif // V8_AST_H_ | 3125 #endif // V8_AST_H_ |
| OLD | NEW |