| 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 'common.dart'; | 7 import 'common.dart'; |
| 8 import 'common/resolution.dart' show Resolution; | 8 import 'common/resolution.dart' show Resolution; |
| 9 import 'common/tasks.dart' show CompilerTask; | 9 import 'common/tasks.dart' show CompilerTask; |
| 10 import 'compiler.dart' show Compiler; | 10 import 'compiler.dart' show Compiler; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 import 'tree/tree.dart'; | 22 import 'tree/tree.dart'; |
| 23 import 'util/util.dart' show Link; | 23 import 'util/util.dart' show Link; |
| 24 import 'universe/call_structure.dart' show CallStructure; | 24 import 'universe/call_structure.dart' show CallStructure; |
| 25 | 25 |
| 26 /// A [ConstantEnvironment] provides access for constants compiled for variable | 26 /// A [ConstantEnvironment] provides access for constants compiled for variable |
| 27 /// initializers. | 27 /// initializers. |
| 28 abstract class ConstantEnvironment { | 28 abstract class ConstantEnvironment { |
| 29 /// The [ConstantSystem] used by this environment. | 29 /// The [ConstantSystem] used by this environment. |
| 30 ConstantSystem get constantSystem; | 30 ConstantSystem get constantSystem; |
| 31 | 31 |
| 32 /// Returns `true` if a value has been computed for [expression]. |
| 33 bool hasConstantValue(ConstantExpression expression); |
| 34 |
| 32 /// Returns the constant value computed for [expression]. | 35 /// Returns the constant value computed for [expression]. |
| 33 // TODO(johnniwinther): Support directly evaluation of [expression]. | 36 // TODO(johnniwinther): Support directly evaluation of [expression]. |
| 34 ConstantValue getConstantValue(ConstantExpression expression); | 37 ConstantValue getConstantValue(ConstantExpression expression); |
| 35 | 38 |
| 36 /// Returns the constant value for the initializer of [element]. | 39 /// Returns the constant value for the initializer of [element]. |
| 37 @deprecated | 40 @deprecated |
| 38 ConstantValue getConstantValueForVariable(VariableElement element); | 41 ConstantValue getConstantValueForVariable(VariableElement element); |
| 39 } | 42 } |
| 40 | 43 |
| 41 /// A class that can compile and provide constants for variables, nodes and | 44 /// A class that can compile and provide constants for variables, nodes and |
| (...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 280 this, definitions, compiler, | 283 this, definitions, compiler, |
| 281 isConst: isConst); | 284 isConst: isConst); |
| 282 AstConstant constant = evaluator.evaluate(node); | 285 AstConstant constant = evaluator.evaluate(node); |
| 283 if (constant != null) { | 286 if (constant != null) { |
| 284 cacheConstantValue(constant.expression, constant.value); | 287 cacheConstantValue(constant.expression, constant.value); |
| 285 return constant.expression; | 288 return constant.expression; |
| 286 } | 289 } |
| 287 return null; | 290 return null; |
| 288 } | 291 } |
| 289 | 292 |
| 293 bool hasConstantValue(ConstantExpression expression) { |
| 294 return constantValueMap.containsKey(expression); |
| 295 } |
| 296 |
| 290 ConstantValue getConstantValue(ConstantExpression expression) { | 297 ConstantValue getConstantValue(ConstantExpression expression) { |
| 291 return constantValueMap[expression]; | 298 return constantValueMap[expression]; |
| 292 } | 299 } |
| 293 | 300 |
| 294 ConstantExpression compileNode(Node node, TreeElements elements, | 301 ConstantExpression compileNode(Node node, TreeElements elements, |
| 295 {bool enforceConst: true}) { | 302 {bool enforceConst: true}) { |
| 296 return compileNodeWithDefinitions(node, elements, isConst: enforceConst); | 303 return compileNodeWithDefinitions(node, elements, isConst: enforceConst); |
| 297 } | 304 } |
| 298 | 305 |
| 299 ConstantExpression compileMetadata( | 306 ConstantExpression compileMetadata( |
| (...skipping 1035 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1335 class _CompilerEnvironment implements Environment { | 1342 class _CompilerEnvironment implements Environment { |
| 1336 final Compiler compiler; | 1343 final Compiler compiler; |
| 1337 | 1344 |
| 1338 _CompilerEnvironment(this.compiler); | 1345 _CompilerEnvironment(this.compiler); |
| 1339 | 1346 |
| 1340 @override | 1347 @override |
| 1341 String readFromEnvironment(String name) { | 1348 String readFromEnvironment(String name) { |
| 1342 return compiler.fromEnvironment(name); | 1349 return compiler.fromEnvironment(name); |
| 1343 } | 1350 } |
| 1344 } | 1351 } |
| OLD | NEW |