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/resolution.dart' show Resolution; | 7 import 'common/resolution.dart' show Resolution; |
8 import 'common/tasks.dart' show CompilerTask, Measurer; | 8 import 'common/tasks.dart' show CompilerTask, Measurer; |
9 import 'common.dart'; | 9 import 'common.dart'; |
10 import 'compiler.dart' show Compiler; | 10 import 'compiler.dart' show Compiler; |
(...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
272 reporter.reportErrorMessage( | 272 reporter.reportErrorMessage( |
273 node, MessageKind.TYPE_VARIABLE_FROM_METHOD_NOT_REIFIED); | 273 node, MessageKind.TYPE_VARIABLE_FROM_METHOD_NOT_REIFIED); |
274 } | 274 } |
275 } else { | 275 } else { |
276 // We need to throw an exception at runtime. | 276 // We need to throw an exception at runtime. |
277 expression = null; | 277 expression = null; |
278 } | 278 } |
279 } else { | 279 } else { |
280 ResolutionDartType constantType = value.getType(commonElements); | 280 ResolutionDartType constantType = value.getType(commonElements); |
281 if (!constantSystem.isSubtype( | 281 if (!constantSystem.isSubtype( |
282 compiler.types, constantType, elementType)) { | 282 compiler.resolution.types, constantType, elementType)) { |
283 if (isConst) { | 283 if (isConst) { |
284 reporter.reportErrorMessage(node, MessageKind.NOT_ASSIGNABLE, | 284 reporter.reportErrorMessage(node, MessageKind.NOT_ASSIGNABLE, |
285 {'fromType': constantType, 'toType': elementType}); | 285 {'fromType': constantType, 'toType': elementType}); |
286 } else { | 286 } else { |
287 // If the field cannot be lazily initialized, we will throw | 287 // If the field cannot be lazily initialized, we will throw |
288 // the exception at runtime. | 288 // the exception at runtime. |
289 expression = null; | 289 expression = null; |
290 } | 290 } |
291 } | 291 } |
292 } | 292 } |
(...skipping 915 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1208 } | 1208 } |
1209 return super.visitSend(send); | 1209 return super.visitSend(send); |
1210 } | 1210 } |
1211 | 1211 |
1212 void potentiallyCheckType(TypedElement element, AstConstant constant) { | 1212 void potentiallyCheckType(TypedElement element, AstConstant constant) { |
1213 if (compiler.options.enableTypeAssertions) { | 1213 if (compiler.options.enableTypeAssertions) { |
1214 ResolutionDartType elementType = | 1214 ResolutionDartType elementType = |
1215 element.type.substByContext(constructedType); | 1215 element.type.substByContext(constructedType); |
1216 ResolutionDartType constantType = constant.value.getType(commonElements); | 1216 ResolutionDartType constantType = constant.value.getType(commonElements); |
1217 if (!constantSystem.isSubtype( | 1217 if (!constantSystem.isSubtype( |
1218 compiler.types, constantType, elementType)) { | 1218 compiler.resolution.types, constantType, elementType)) { |
1219 reporter.withCurrentElement(constant.element, () { | 1219 reporter.withCurrentElement(constant.element, () { |
1220 reporter.reportErrorMessage(constant.node, MessageKind.NOT_ASSIGNABLE, | 1220 reporter.reportErrorMessage(constant.node, MessageKind.NOT_ASSIGNABLE, |
1221 {'fromType': constantType, 'toType': elementType}); | 1221 {'fromType': constantType, 'toType': elementType}); |
1222 }); | 1222 }); |
1223 } | 1223 } |
1224 } | 1224 } |
1225 } | 1225 } |
1226 | 1226 |
1227 void updateFieldValue(Node node, TypedElement element, AstConstant constant) { | 1227 void updateFieldValue(Node node, TypedElement element, AstConstant constant) { |
1228 potentiallyCheckType(element, constant); | 1228 potentiallyCheckType(element, constant); |
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1473 @override | 1473 @override |
1474 ConstantExpression getFieldConstant(FieldElement field) { | 1474 ConstantExpression getFieldConstant(FieldElement field) { |
1475 return field.constant; | 1475 return field.constant; |
1476 } | 1476 } |
1477 | 1477 |
1478 @override | 1478 @override |
1479 ConstantExpression getLocalConstant(LocalVariableElement local) { | 1479 ConstantExpression getLocalConstant(LocalVariableElement local) { |
1480 return local.constant; | 1480 return local.constant; |
1481 } | 1481 } |
1482 } | 1482 } |
OLD | NEW |