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 library dart2js.compile_time_constant_evaluator; | 5 library dart2js.compile_time_constant_evaluator; |
6 | 6 |
7 import 'constant_system_dart.dart'; | 7 import 'constant_system_dart.dart'; |
8 import 'constants/constant_system.dart'; | 8 import 'constants/constant_system.dart'; |
9 import 'constants/expressions.dart'; | 9 import 'constants/expressions.dart'; |
10 import 'constants/values.dart'; | 10 import 'constants/values.dart'; |
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
241 if (expression != null) { | 241 if (expression != null) { |
242 initialVariableValues[element.declaration] = expression; | 242 initialVariableValues[element.declaration] = expression; |
243 } else { | 243 } else { |
244 assert(invariant(element, !isConst, | 244 assert(invariant(element, !isConst, |
245 message: "Variable $element does not compile to a constant.")); | 245 message: "Variable $element does not compile to a constant.")); |
246 } | 246 } |
247 pendingVariables.remove(element); | 247 pendingVariables.remove(element); |
248 return expression; | 248 return expression; |
249 } | 249 } |
250 | 250 |
| 251 void cacheConstantValue(ConstantExpression expression, ConstantValue value) { |
| 252 constantValueMap[expression] = value; |
| 253 } |
| 254 |
251 ConstantExpression compileNodeWithDefinitions(Node node, | 255 ConstantExpression compileNodeWithDefinitions(Node node, |
252 TreeElements definitions, | 256 TreeElements definitions, |
253 {bool isConst: true}) { | 257 {bool isConst: true}) { |
254 assert(node != null); | 258 assert(node != null); |
255 CompileTimeConstantEvaluator evaluator = new CompileTimeConstantEvaluator( | 259 CompileTimeConstantEvaluator evaluator = new CompileTimeConstantEvaluator( |
256 this, definitions, compiler, isConst: isConst); | 260 this, definitions, compiler, isConst: isConst); |
257 AstConstant constant = evaluator.evaluate(node); | 261 AstConstant constant = evaluator.evaluate(node); |
258 if (constant != null) { | 262 if (constant != null) { |
259 constantValueMap[constant.expression] = constant.value; | 263 cacheConstantValue(constant.expression, constant.value); |
260 return constant.expression; | 264 return constant.expression; |
261 } | 265 } |
262 return null; | 266 return null; |
263 } | 267 } |
264 | 268 |
265 ConstantValue getConstantValue(ConstantExpression expression) { | 269 ConstantValue getConstantValue(ConstantExpression expression) { |
266 return constantValueMap[expression]; | 270 return constantValueMap[expression]; |
267 } | 271 } |
268 | 272 |
269 ConstantExpression compileNode(Node node, TreeElements elements, | 273 ConstantExpression compileNode(Node node, TreeElements elements, |
(...skipping 25 matching lines...) Expand all Loading... |
295 : super(compiler, const DartConstantSystem()); | 299 : super(compiler, const DartConstantSystem()); |
296 | 300 |
297 ConstantExpression getConstantForNode(Node node, TreeElements definitions) { | 301 ConstantExpression getConstantForNode(Node node, TreeElements definitions) { |
298 return definitions.getConstant(node); | 302 return definitions.getConstant(node); |
299 } | 303 } |
300 | 304 |
301 ConstantExpression compileNodeWithDefinitions(Node node, | 305 ConstantExpression compileNodeWithDefinitions(Node node, |
302 TreeElements definitions, | 306 TreeElements definitions, |
303 {bool isConst: true}) { | 307 {bool isConst: true}) { |
304 ConstantExpression constant = definitions.getConstant(node); | 308 ConstantExpression constant = definitions.getConstant(node); |
305 if (constant != null) { | 309 if (constant != null && getConstantValue(constant) != null) { |
306 return constant; | 310 return constant; |
307 } | 311 } |
308 constant = | 312 constant = |
309 super.compileNodeWithDefinitions(node, definitions, isConst: isConst); | 313 super.compileNodeWithDefinitions(node, definitions, isConst: isConst); |
310 if (constant != null) { | 314 if (constant != null) { |
311 definitions.setConstant(node, constant); | 315 definitions.setConstant(node, constant); |
312 } | 316 } |
313 return constant; | 317 return constant; |
314 } | 318 } |
315 } | 319 } |
(...skipping 1011 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1327 // TODO(johnniwinther): Return a [NonConstantValue] instead. | 1331 // TODO(johnniwinther): Return a [NonConstantValue] instead. |
1328 new ErroneousConstantExpression(), new NullConstantValue()); | 1332 new ErroneousConstantExpression(), new NullConstantValue()); |
1329 } | 1333 } |
1330 | 1334 |
1331 // TODO(johnniwinther): Avoid the need for this hack. | 1335 // TODO(johnniwinther): Avoid the need for this hack. |
1332 TreeElements _analyzeElementEagerly(Compiler compiler, AstElement element) { | 1336 TreeElements _analyzeElementEagerly(Compiler compiler, AstElement element) { |
1333 WorldImpact worldImpact = compiler.analyzeElement(element.declaration); | 1337 WorldImpact worldImpact = compiler.analyzeElement(element.declaration); |
1334 compiler.enqueuer.resolution.applyImpact(element.declaration, worldImpact); | 1338 compiler.enqueuer.resolution.applyImpact(element.declaration, worldImpact); |
1335 return element.resolvedAst.elements; | 1339 return element.resolvedAst.elements; |
1336 } | 1340 } |
OLD | NEW |