| OLD | NEW |
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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.resolution.constructors; | 5 library dart2js.resolution.constructors; |
| 6 | 6 |
| 7 import '../common.dart'; | 7 import '../common.dart'; |
| 8 import '../compiler.dart' show | 8 import '../compiler.dart' show |
| 9 Compiler; | 9 Compiler; |
| 10 import '../constants/constructors.dart' show | 10 import '../constants/constructors.dart' show |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 116 } else if (!target.isInstanceMember) { | 116 } else if (!target.isInstanceMember) { |
| 117 reporter.reportErrorMessage( | 117 reporter.reportErrorMessage( |
| 118 selector, MessageKind.INIT_STATIC_FIELD, {'fieldName': name}); | 118 selector, MessageKind.INIT_STATIC_FIELD, {'fieldName': name}); |
| 119 } else { | 119 } else { |
| 120 field = target; | 120 field = target; |
| 121 } | 121 } |
| 122 } else { | 122 } else { |
| 123 reporter.reportErrorMessage( | 123 reporter.reportErrorMessage( |
| 124 init, MessageKind.INVALID_RECEIVER_IN_INITIALIZER); | 124 init, MessageKind.INVALID_RECEIVER_IN_INITIALIZER); |
| 125 } | 125 } |
| 126 registry.useElement(init, target); | 126 if (target != null) { |
| 127 registry.registerStaticUse(target); | 127 registry.useElement(init, target); |
| 128 checkForDuplicateInitializers(target, init); | 128 registry.registerStaticUse(target); |
| 129 checkForDuplicateInitializers(target, init); |
| 130 } |
| 129 // Resolve initializing value. | 131 // Resolve initializing value. |
| 130 ResolutionResult result = visitor.visitInStaticContext( | 132 ResolutionResult result = visitor.visitInStaticContext( |
| 131 init.arguments.head, | 133 init.arguments.head, |
| 132 inConstantInitializer: isConst); | 134 inConstantInitializer: isConst); |
| 133 if (isConst) { | 135 if (isConst) { |
| 134 if (result.isConstant && field != null) { | 136 if (result.isConstant && field != null) { |
| 135 // TODO(johnniwinther): Report error if `result.constant` is `null`. | 137 // TODO(johnniwinther): Report error if `result.constant` is `null`. |
| 136 fieldInitializers[field] = result.constant; | 138 fieldInitializers[field] = result.constant; |
| 137 } else { | 139 } else { |
| 138 isValidAsConstant = false; | 140 isValidAsConstant = false; |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 172 constructor.library, lookupTarget, constructorSelector.name); | 174 constructor.library, lookupTarget, constructorSelector.name); |
| 173 | 175 |
| 174 final bool isImplicitSuperCall = false; | 176 final bool isImplicitSuperCall = false; |
| 175 final String className = lookupTarget.name; | 177 final String className = lookupTarget.name; |
| 176 verifyThatConstructorMatchesCall(calledConstructor, | 178 verifyThatConstructorMatchesCall(calledConstructor, |
| 177 argumentsResult.callStructure, | 179 argumentsResult.callStructure, |
| 178 isImplicitSuperCall, | 180 isImplicitSuperCall, |
| 179 call, | 181 call, |
| 180 className, | 182 className, |
| 181 constructorSelector); | 183 constructorSelector); |
| 182 | 184 if (calledConstructor != null) { |
| 183 registry.useElement(call, calledConstructor); | 185 registry.useElement(call, calledConstructor); |
| 184 registry.registerStaticUse(calledConstructor); | 186 registry.registerStaticUse(calledConstructor); |
| 187 } |
| 185 if (isConst) { | 188 if (isConst) { |
| 186 if (isValidAsConstant && | 189 if (isValidAsConstant && |
| 187 calledConstructor.isConst && | 190 calledConstructor.isConst && |
| 188 argumentsResult.isValidAsConstant) { | 191 argumentsResult.isValidAsConstant) { |
| 189 CallStructure callStructure = argumentsResult.callStructure; | 192 CallStructure callStructure = argumentsResult.callStructure; |
| 190 List<ConstantExpression> arguments = argumentsResult.constantArguments; | 193 List<ConstantExpression> arguments = argumentsResult.constantArguments; |
| 191 return new ConstantResult( | 194 return new ConstantResult( |
| 192 call, | 195 call, |
| 193 new ConstructedConstantExpression( | 196 new ConstructedConstantExpression( |
| 194 targetType, | 197 targetType, |
| (...skipping 26 matching lines...) Expand all Loading... |
| 221 constructorSelector.name); | 224 constructorSelector.name); |
| 222 | 225 |
| 223 final String className = lookupTarget.name; | 226 final String className = lookupTarget.name; |
| 224 final bool isImplicitSuperCall = true; | 227 final bool isImplicitSuperCall = true; |
| 225 verifyThatConstructorMatchesCall(calledConstructor, | 228 verifyThatConstructorMatchesCall(calledConstructor, |
| 226 CallStructure.NO_ARGS, | 229 CallStructure.NO_ARGS, |
| 227 isImplicitSuperCall, | 230 isImplicitSuperCall, |
| 228 functionNode, | 231 functionNode, |
| 229 className, | 232 className, |
| 230 constructorSelector); | 233 constructorSelector); |
| 231 registry.registerImplicitSuperCall(calledConstructor); | 234 if (calledConstructor != null) { |
| 232 registry.registerStaticUse(calledConstructor); | 235 registry.registerImplicitSuperCall(calledConstructor); |
| 236 registry.registerStaticUse(calledConstructor); |
| 237 } |
| 233 | 238 |
| 234 if (isConst && isValidAsConstant) { | 239 if (isConst && isValidAsConstant) { |
| 235 return new ConstructedConstantExpression( | 240 return new ConstructedConstantExpression( |
| 236 targetType, | 241 targetType, |
| 237 calledConstructor, | 242 calledConstructor, |
| 238 CallStructure.NO_ARGS, | 243 CallStructure.NO_ARGS, |
| 239 const <ConstantExpression>[]); | 244 const <ConstantExpression>[]); |
| 240 } | 245 } |
| 241 } | 246 } |
| 242 return null; | 247 return null; |
| (...skipping 507 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 750 // constructors. | 755 // constructors. |
| 751 return null; | 756 return null; |
| 752 } | 757 } |
| 753 // TODO(johnniwinther): Use [Name] for lookup. | 758 // TODO(johnniwinther): Use [Name] for lookup. |
| 754 ConstructorElement constructor = cls.lookupConstructor(constructorName); | 759 ConstructorElement constructor = cls.lookupConstructor(constructorName); |
| 755 if (constructor != null) { | 760 if (constructor != null) { |
| 756 constructor = constructor.declaration; | 761 constructor = constructor.declaration; |
| 757 } | 762 } |
| 758 return constructor; | 763 return constructor; |
| 759 } | 764 } |
| OLD | NEW |