OLD | NEW |
1 // Copyright 2006-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2008 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 24 matching lines...) Expand all Loading... |
35 | 35 |
36 | 36 |
37 class AstOptimizer: public AstVisitor { | 37 class AstOptimizer: public AstVisitor { |
38 public: | 38 public: |
39 explicit AstOptimizer() { | 39 explicit AstOptimizer() { |
40 } | 40 } |
41 | 41 |
42 void Optimize(ZoneList<Statement*>* statements); | 42 void Optimize(ZoneList<Statement*>* statements); |
43 | 43 |
44 private: | 44 private: |
| 45 // Used for loop condition analysis. Cleared before visiting a loop |
| 46 // condition, set when a function literal is visited. |
| 47 bool has_function_literal_; |
| 48 |
45 // Helpers | 49 // Helpers |
46 void OptimizeArguments(ZoneList<Expression*>* arguments); | 50 void OptimizeArguments(ZoneList<Expression*>* arguments); |
47 | 51 |
48 // Node visitors. | 52 // Node visitors. |
49 #define DEF_VISIT(type) \ | 53 #define DEF_VISIT(type) \ |
50 virtual void Visit##type(type* node); | 54 virtual void Visit##type(type* node); |
51 NODE_LIST(DEF_VISIT) | 55 NODE_LIST(DEF_VISIT) |
52 #undef DEF_VISIT | 56 #undef DEF_VISIT |
53 | 57 |
54 DISALLOW_COPY_AND_ASSIGN(AstOptimizer); | 58 DISALLOW_COPY_AND_ASSIGN(AstOptimizer); |
(...skipping 27 matching lines...) Expand all Loading... |
82 | 86 |
83 void AstOptimizer::VisitIfStatement(IfStatement* node) { | 87 void AstOptimizer::VisitIfStatement(IfStatement* node) { |
84 Visit(node->condition()); | 88 Visit(node->condition()); |
85 Visit(node->then_statement()); | 89 Visit(node->then_statement()); |
86 if (node->HasElseStatement()) { | 90 if (node->HasElseStatement()) { |
87 Visit(node->else_statement()); | 91 Visit(node->else_statement()); |
88 } | 92 } |
89 } | 93 } |
90 | 94 |
91 | 95 |
92 | |
93 | |
94 void AstOptimizer::VisitLoopStatement(LoopStatement* node) { | 96 void AstOptimizer::VisitLoopStatement(LoopStatement* node) { |
95 if (node->init() != NULL) { | 97 if (node->init() != NULL) { |
96 Visit(node->init()); | 98 Visit(node->init()); |
97 } | 99 } |
98 if (node->cond() != NULL) { | 100 if (node->cond() != NULL) { |
| 101 has_function_literal_ = false; |
99 Visit(node->cond()); | 102 Visit(node->cond()); |
| 103 node->has_function_literal_ = has_function_literal_; |
100 } | 104 } |
101 if (node->body() != NULL) { | 105 if (node->body() != NULL) { |
102 Visit(node->body()); | 106 Visit(node->body()); |
103 } | 107 } |
104 if (node->next() != NULL) { | 108 if (node->next() != NULL) { |
105 Visit(node->next()); | 109 Visit(node->next()); |
106 } | 110 } |
107 } | 111 } |
108 | 112 |
109 | 113 |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
175 } | 179 } |
176 | 180 |
177 | 181 |
178 void AstOptimizer::VisitDebuggerStatement(DebuggerStatement* node) { | 182 void AstOptimizer::VisitDebuggerStatement(DebuggerStatement* node) { |
179 USE(node); | 183 USE(node); |
180 } | 184 } |
181 | 185 |
182 | 186 |
183 void AstOptimizer::VisitFunctionLiteral(FunctionLiteral* node) { | 187 void AstOptimizer::VisitFunctionLiteral(FunctionLiteral* node) { |
184 USE(node); | 188 USE(node); |
| 189 has_function_literal_ = true; |
185 } | 190 } |
186 | 191 |
187 | 192 |
188 void AstOptimizer::VisitFunctionBoilerplateLiteral( | 193 void AstOptimizer::VisitFunctionBoilerplateLiteral( |
189 FunctionBoilerplateLiteral* node) { | 194 FunctionBoilerplateLiteral* node) { |
190 USE(node); | 195 USE(node); |
191 } | 196 } |
192 | 197 |
193 | 198 |
194 void AstOptimizer::VisitConditional(Conditional* node) { | 199 void AstOptimizer::VisitConditional(Conditional* node) { |
(...skipping 601 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
796 if (optimizer.HasStackOverflow()) { | 801 if (optimizer.HasStackOverflow()) { |
797 return false; | 802 return false; |
798 } | 803 } |
799 } | 804 } |
800 } | 805 } |
801 return true; | 806 return true; |
802 } | 807 } |
803 | 808 |
804 | 809 |
805 } } // namespace v8::internal | 810 } } // namespace v8::internal |
OLD | NEW |