| OLD | NEW |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 library code_generator; | 5 library code_generator; |
| 6 | 6 |
| 7 import 'glue.dart'; | 7 import 'glue.dart'; |
| 8 | 8 |
| 9 import '../../closure.dart' show | 9 import '../../closure.dart' show |
| 10 ClosureClassElement; | 10 ClosureClassElement; |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 114 | 114 |
| 115 // Check that node is an assignment to a local variable. | 115 // Check that node is an assignment to a local variable. |
| 116 if (node is! js.ExpressionStatement) break; | 116 if (node is! js.ExpressionStatement) break; |
| 117 js.ExpressionStatement stmt = node; | 117 js.ExpressionStatement stmt = node; |
| 118 if (stmt.expression is! js.Assignment) break; | 118 if (stmt.expression is! js.Assignment) break; |
| 119 js.Assignment assign = stmt.expression; | 119 js.Assignment assign = stmt.expression; |
| 120 if (assign.leftHandSide is! js.VariableUse) break; | 120 if (assign.leftHandSide is! js.VariableUse) break; |
| 121 if (assign.op != null) break; // Compound assignment. | 121 if (assign.op != null) break; // Compound assignment. |
| 122 js.VariableUse use = assign.leftHandSide; | 122 js.VariableUse use = assign.leftHandSide; |
| 123 | 123 |
| 124 // Do not touch non-local variables. |
| 125 if (!usedVariableNames.contains(use.name)) break; |
| 126 |
| 124 // We cannot declare a variable more than once. | 127 // We cannot declare a variable more than once. |
| 125 if (!declaredVariables.add(use.name)) break; | 128 if (!declaredVariables.add(use.name)) break; |
| 126 | 129 |
| 127 js.VariableInitialization jsVariable = new js.VariableInitialization( | 130 js.VariableInitialization jsVariable = new js.VariableInitialization( |
| 128 new js.VariableDeclaration(use.name), | 131 new js.VariableDeclaration(use.name), |
| 129 assign.value); | 132 assign.value); |
| 130 jsVariables.add(jsVariable); | 133 jsVariables.add(jsVariable); |
| 131 | 134 |
| 132 ++accumulatorIndex; | 135 ++accumulatorIndex; |
| 133 } | 136 } |
| 134 | 137 |
| 135 // If the last statement is a for loop with an initializer expression, try | 138 // If the last statement is a for loop with an initializer expression, try |
| 136 // to pull that expression into an initializer as well. | 139 // to pull that expression into an initializer as well. |
| 137 pullFromForLoop: | 140 pullFromForLoop: |
| 138 if (accumulatorIndex < accumulator.length && | 141 if (accumulatorIndex < accumulator.length && |
| 139 accumulator[accumulatorIndex] is js.For) { | 142 accumulator[accumulatorIndex] is js.For) { |
| 140 js.For forLoop = accumulator[accumulatorIndex]; | 143 js.For forLoop = accumulator[accumulatorIndex]; |
| 141 if (forLoop.init is! js.Assignment) break pullFromForLoop; | 144 if (forLoop.init is! js.Assignment) break pullFromForLoop; |
| 142 js.Assignment assign = forLoop.init; | 145 js.Assignment assign = forLoop.init; |
| 143 if (assign.leftHandSide is! js.VariableUse) break pullFromForLoop; | 146 if (assign.leftHandSide is! js.VariableUse) break pullFromForLoop; |
| 144 if (assign.op != null) break pullFromForLoop; // Compound assignment. | 147 if (assign.op != null) break pullFromForLoop; // Compound assignment. |
| 145 js.VariableUse use = assign.leftHandSide; | 148 js.VariableUse use = assign.leftHandSide; |
| 146 | 149 |
| 150 // Do not touch non-local variables. |
| 151 if (!usedVariableNames.contains(use.name)) break pullFromForLoop; |
| 152 |
| 147 // We cannot declare a variable more than once. | 153 // We cannot declare a variable more than once. |
| 148 if (!declaredVariables.add(use.name)) break pullFromForLoop; | 154 if (!declaredVariables.add(use.name)) break pullFromForLoop; |
| 149 | 155 |
| 150 js.VariableInitialization jsVariable = new js.VariableInitialization( | 156 js.VariableInitialization jsVariable = new js.VariableInitialization( |
| 151 new js.VariableDeclaration(use.name), | 157 new js.VariableDeclaration(use.name), |
| 152 assign.value); | 158 assign.value); |
| 153 jsVariables.add(jsVariable); | 159 jsVariables.add(jsVariable); |
| 154 | 160 |
| 155 // Remove the initializer from the for loop. | 161 // Remove the initializer from the for loop. |
| 156 accumulator[accumulatorIndex] = | 162 accumulator[accumulatorIndex] = |
| (...skipping 1074 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1231 void registerDefaultParameterValues(ExecutableElement element) { | 1237 void registerDefaultParameterValues(ExecutableElement element) { |
| 1232 if (element is! FunctionElement) return; | 1238 if (element is! FunctionElement) return; |
| 1233 FunctionElement function = element; | 1239 FunctionElement function = element; |
| 1234 if (function.isStatic) return; // Defaults are inlined at call sites. | 1240 if (function.isStatic) return; // Defaults are inlined at call sites. |
| 1235 function.functionSignature.forEachOptionalParameter((param) { | 1241 function.functionSignature.forEachOptionalParameter((param) { |
| 1236 ConstantValue constant = glue.getDefaultParameterValue(param); | 1242 ConstantValue constant = glue.getDefaultParameterValue(param); |
| 1237 registry.registerCompileTimeConstant(constant); | 1243 registry.registerCompileTimeConstant(constant); |
| 1238 }); | 1244 }); |
| 1239 } | 1245 } |
| 1240 } | 1246 } |
| OLD | NEW |