| 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 /// A [ConstantEnvironment] provides access for constants compiled for variable | 7 /// A [ConstantEnvironment] provides access for constants compiled for variable |
| 8 /// initializers. | 8 /// initializers. |
| 9 abstract class ConstantEnvironment { | 9 abstract class ConstantEnvironment { |
| 10 /// Returns the constant for the initializer of [element]. | 10 /// Returns the constant for the initializer of [element]. |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 156 if (isConst) { | 156 if (isConst) { |
| 157 ErroneousElement element = elementType.element; | 157 ErroneousElement element = elementType.element; |
| 158 compiler.reportFatalError( | 158 compiler.reportFatalError( |
| 159 node, element.messageKind, element.messageArguments); | 159 node, element.messageKind, element.messageArguments); |
| 160 } else { | 160 } else { |
| 161 // We need to throw an exception at runtime. | 161 // We need to throw an exception at runtime. |
| 162 value = null; | 162 value = null; |
| 163 } | 163 } |
| 164 } else { | 164 } else { |
| 165 DartType constantType = value.value.getType(compiler.coreTypes); | 165 DartType constantType = value.value.getType(compiler.coreTypes); |
| 166 if (!constantSystem.isSubtype(compiler, | 166 if (!constantSystem.isSubtype(compiler.types, |
| 167 constantType, elementType)) { | 167 constantType, elementType)) { |
| 168 if (isConst) { | 168 if (isConst) { |
| 169 compiler.reportFatalError( | 169 compiler.reportFatalError( |
| 170 node, MessageKind.NOT_ASSIGNABLE, | 170 node, MessageKind.NOT_ASSIGNABLE, |
| 171 {'fromType': constantType, 'toType': elementType}); | 171 {'fromType': constantType, 'toType': elementType}); |
| 172 } else { | 172 } else { |
| 173 // If the field cannot be lazily initialized, we will throw | 173 // If the field cannot be lazily initialized, we will throw |
| 174 // the exception at runtime. | 174 // the exception at runtime. |
| 175 value = null; | 175 value = null; |
| 176 } | 176 } |
| (...skipping 726 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 903 } | 903 } |
| 904 return super.visitSend(send); | 904 return super.visitSend(send); |
| 905 } | 905 } |
| 906 | 906 |
| 907 void potentiallyCheckType(Node node, | 907 void potentiallyCheckType(Node node, |
| 908 TypedElement element, | 908 TypedElement element, |
| 909 AstConstant constant) { | 909 AstConstant constant) { |
| 910 if (compiler.enableTypeAssertions) { | 910 if (compiler.enableTypeAssertions) { |
| 911 DartType elementType = element.type.substByContext(constructedType); | 911 DartType elementType = element.type.substByContext(constructedType); |
| 912 DartType constantType = constant.value.getType(compiler.coreTypes); | 912 DartType constantType = constant.value.getType(compiler.coreTypes); |
| 913 if (!constantSystem.isSubtype(compiler, constantType, elementType)) { | 913 if (!constantSystem.isSubtype(compiler.types, |
| 914 constantType, elementType)) { |
| 914 compiler.withCurrentElement(constant.element, () { | 915 compiler.withCurrentElement(constant.element, () { |
| 915 compiler.reportFatalError( | 916 compiler.reportFatalError( |
| 916 constant.node, MessageKind.NOT_ASSIGNABLE, | 917 constant.node, MessageKind.NOT_ASSIGNABLE, |
| 917 {'fromType': constantType, 'toType': elementType}); | 918 {'fromType': constantType, 'toType': elementType}); |
| 918 }); | 919 }); |
| 919 } | 920 } |
| 920 } | 921 } |
| 921 } | 922 } |
| 922 | 923 |
| 923 void updateFieldValue(Node node, | 924 void updateFieldValue(Node node, |
| (...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1091 return new AstConstant( | 1092 return new AstConstant( |
| 1092 element, | 1093 element, |
| 1093 element.initializer != null ? element.initializer : element.node, | 1094 element.initializer != null ? element.initializer : element.node, |
| 1094 constant); | 1095 constant); |
| 1095 } | 1096 } |
| 1096 | 1097 |
| 1097 ConstantValue get value => expression.value; | 1098 ConstantValue get value => expression.value; |
| 1098 | 1099 |
| 1099 String toString() => expression.toString(); | 1100 String toString() => expression.toString(); |
| 1100 } | 1101 } |
| OLD | NEW |