| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 part of dart2js; | 5 part of dart2js; |
| 6 | 6 |
| 7 /** | 7 /** |
| 8 * The [ConstantHandler] keeps track of compile-time constants, | 8 * The [ConstantHandler] keeps track of compile-time constants, |
| 9 * initializations of global and static fields, and default values of | 9 * initializations of global and static fields, and default values of |
| 10 * optional parameters. | 10 * optional parameters. |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 142 /** | 142 /** |
| 143 * Returns the a compile-time constant if the variable could be compiled | 143 * Returns the a compile-time constant if the variable could be compiled |
| 144 * eagerly. Otherwise returns `null`. | 144 * eagerly. Otherwise returns `null`. |
| 145 */ | 145 */ |
| 146 Constant compileVariable(VariableElement element, {bool isConst: false}) { | 146 Constant compileVariable(VariableElement element, {bool isConst: false}) { |
| 147 return measure(() { | 147 return measure(() { |
| 148 if (initialVariableValues.containsKey(element)) { | 148 if (initialVariableValues.containsKey(element)) { |
| 149 Constant result = initialVariableValues[element]; | 149 Constant result = initialVariableValues[element]; |
| 150 return result; | 150 return result; |
| 151 } | 151 } |
| 152 return compiler.withCurrentElement(element, () { | 152 Element currentElement = element; |
| 153 TreeElements definitions = compiler.analyzeElement(element.declaration); | 153 if (element.isParameter() |
| 154 || element.isFieldParameter() |
| 155 || element.isVariable()) { |
| 156 currentElement = element.enclosingElement; |
| 157 } |
| 158 return compiler.withCurrentElement(currentElement, () { |
| 159 TreeElements definitions = |
| 160 compiler.analyzeElement(currentElement.declaration); |
| 154 Constant constant = compileVariableWithDefinitions( | 161 Constant constant = compileVariableWithDefinitions( |
| 155 element, definitions, isConst: isConst); | 162 element, definitions, isConst: isConst); |
| 156 return constant; | 163 return constant; |
| 157 }); | 164 }); |
| 158 }); | 165 }); |
| 159 } | 166 } |
| 160 | 167 |
| 161 /** | 168 /** |
| 162 * Returns the a compile-time constant if the variable could be compiled | 169 * Returns the a compile-time constant if the variable could be compiled |
| 163 * eagerly. If the variable needs to be initialized lazily returns `null`. | 170 * eagerly. If the variable needs to be initialized lazily returns `null`. |
| (...skipping 797 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 961 if (fieldValue == null) { | 968 if (fieldValue == null) { |
| 962 // Use the default value. | 969 // Use the default value. |
| 963 fieldValue = handler.compileConstant(field); | 970 fieldValue = handler.compileConstant(field); |
| 964 } | 971 } |
| 965 jsNewArguments.add(fieldValue); | 972 jsNewArguments.add(fieldValue); |
| 966 }, | 973 }, |
| 967 includeSuperAndInjectedMembers: true); | 974 includeSuperAndInjectedMembers: true); |
| 968 return jsNewArguments; | 975 return jsNewArguments; |
| 969 } | 976 } |
| 970 } | 977 } |
| OLD | NEW |