| 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 10 matching lines...) Expand all Loading... |
| 21 FieldElementX, | 21 FieldElementX, |
| 22 InitializingFormalElementX, | 22 InitializingFormalElementX, |
| 23 ParameterElementX; | 23 ParameterElementX; |
| 24 import '../tree/tree.dart'; | 24 import '../tree/tree.dart'; |
| 25 import '../util/util.dart' show | 25 import '../util/util.dart' show |
| 26 Link; | 26 Link; |
| 27 import '../universe/call_structure.dart' show | 27 import '../universe/call_structure.dart' show |
| 28 CallStructure; | 28 CallStructure; |
| 29 import '../universe/selector.dart' show | 29 import '../universe/selector.dart' show |
| 30 Selector; | 30 Selector; |
| 31 import '../universe/use.dart' show |
| 32 StaticUse; |
| 31 | 33 |
| 32 import 'members.dart' show | 34 import 'members.dart' show |
| 33 lookupInScope, | 35 lookupInScope, |
| 34 ResolverVisitor; | 36 ResolverVisitor; |
| 35 import 'registry.dart' show | 37 import 'registry.dart' show |
| 36 ResolutionRegistry; | 38 ResolutionRegistry; |
| 37 import 'resolution_common.dart' show | 39 import 'resolution_common.dart' show |
| 38 CommonResolverVisitor; | 40 CommonResolverVisitor; |
| 39 import 'resolution_result.dart'; | 41 import 'resolution_result.dart'; |
| 40 | 42 |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 118 selector, MessageKind.INIT_STATIC_FIELD, {'fieldName': name}); | 120 selector, MessageKind.INIT_STATIC_FIELD, {'fieldName': name}); |
| 119 } else { | 121 } else { |
| 120 field = target; | 122 field = target; |
| 121 } | 123 } |
| 122 } else { | 124 } else { |
| 123 reporter.reportErrorMessage( | 125 reporter.reportErrorMessage( |
| 124 init, MessageKind.INVALID_RECEIVER_IN_INITIALIZER); | 126 init, MessageKind.INVALID_RECEIVER_IN_INITIALIZER); |
| 125 } | 127 } |
| 126 if (target != null) { | 128 if (target != null) { |
| 127 registry.useElement(init, target); | 129 registry.useElement(init, target); |
| 128 registry.registerStaticUse(target); | 130 if (!target.isMalformed) { |
| 131 registry.registerStaticUse(new StaticUse.fieldInit(target)); |
| 132 } |
| 129 checkForDuplicateInitializers(target, init); | 133 checkForDuplicateInitializers(target, init); |
| 130 } | 134 } |
| 131 // Resolve initializing value. | 135 // Resolve initializing value. |
| 132 ResolutionResult result = visitor.visitInStaticContext( | 136 ResolutionResult result = visitor.visitInStaticContext( |
| 133 init.arguments.head, | 137 init.arguments.head, |
| 134 inConstantInitializer: isConst); | 138 inConstantInitializer: isConst); |
| 135 if (isConst) { | 139 if (isConst) { |
| 136 if (result.isConstant && field != null) { | 140 if (result.isConstant && field != null) { |
| 137 // TODO(johnniwinther): Report error if `result.constant` is `null`. | 141 // TODO(johnniwinther): Report error if `result.constant` is `null`. |
| 138 fieldInitializers[field] = result.constant; | 142 fieldInitializers[field] = result.constant; |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 176 final bool isImplicitSuperCall = false; | 180 final bool isImplicitSuperCall = false; |
| 177 final String className = lookupTarget.name; | 181 final String className = lookupTarget.name; |
| 178 verifyThatConstructorMatchesCall(calledConstructor, | 182 verifyThatConstructorMatchesCall(calledConstructor, |
| 179 argumentsResult.callStructure, | 183 argumentsResult.callStructure, |
| 180 isImplicitSuperCall, | 184 isImplicitSuperCall, |
| 181 call, | 185 call, |
| 182 className, | 186 className, |
| 183 constructorSelector); | 187 constructorSelector); |
| 184 if (calledConstructor != null) { | 188 if (calledConstructor != null) { |
| 185 registry.useElement(call, calledConstructor); | 189 registry.useElement(call, calledConstructor); |
| 186 registry.registerStaticUse(calledConstructor); | 190 registry.registerStaticUse( |
| 191 new StaticUse.superConstructorInvoke( |
| 192 calledConstructor, argumentsResult.callStructure)); |
| 187 } | 193 } |
| 188 if (isConst) { | 194 if (isConst) { |
| 189 if (isValidAsConstant && | 195 if (isValidAsConstant && |
| 190 calledConstructor.isConst && | 196 calledConstructor.isConst && |
| 191 argumentsResult.isValidAsConstant) { | 197 argumentsResult.isValidAsConstant) { |
| 192 CallStructure callStructure = argumentsResult.callStructure; | 198 CallStructure callStructure = argumentsResult.callStructure; |
| 193 List<ConstantExpression> arguments = argumentsResult.constantArguments; | 199 List<ConstantExpression> arguments = argumentsResult.constantArguments; |
| 194 return new ConstantResult( | 200 return new ConstantResult( |
| 195 call, | 201 call, |
| 196 new ConstructedConstantExpression( | 202 new ConstructedConstantExpression( |
| (...skipping 28 matching lines...) Expand all Loading... |
| 225 | 231 |
| 226 final String className = lookupTarget.name; | 232 final String className = lookupTarget.name; |
| 227 final bool isImplicitSuperCall = true; | 233 final bool isImplicitSuperCall = true; |
| 228 verifyThatConstructorMatchesCall(calledConstructor, | 234 verifyThatConstructorMatchesCall(calledConstructor, |
| 229 CallStructure.NO_ARGS, | 235 CallStructure.NO_ARGS, |
| 230 isImplicitSuperCall, | 236 isImplicitSuperCall, |
| 231 functionNode, | 237 functionNode, |
| 232 className, | 238 className, |
| 233 constructorSelector); | 239 constructorSelector); |
| 234 if (calledConstructor != null) { | 240 if (calledConstructor != null) { |
| 235 registry.registerImplicitSuperCall(calledConstructor); | 241 registry.registerStaticUse( |
| 242 new StaticUse.constructorInvoke( |
| 243 calledConstructor, constructorSelector.callStructure)); |
| 236 } | 244 } |
| 237 | 245 |
| 238 if (isConst && isValidAsConstant) { | 246 if (isConst && isValidAsConstant) { |
| 239 return new ConstructedConstantExpression( | 247 return new ConstructedConstantExpression( |
| 240 targetType, | 248 targetType, |
| 241 calledConstructor, | 249 calledConstructor, |
| 242 CallStructure.NO_ARGS, | 250 CallStructure.NO_ARGS, |
| 243 const <ConstantExpression>[]); | 251 const <ConstantExpression>[]); |
| 244 } | 252 } |
| 245 } | 253 } |
| (...skipping 507 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 753 // constructors. | 761 // constructors. |
| 754 return null; | 762 return null; |
| 755 } | 763 } |
| 756 // TODO(johnniwinther): Use [Name] for lookup. | 764 // TODO(johnniwinther): Use [Name] for lookup. |
| 757 ConstructorElement constructor = cls.lookupConstructor(constructorName); | 765 ConstructorElement constructor = cls.lookupConstructor(constructorName); |
| 758 if (constructor != null) { | 766 if (constructor != null) { |
| 759 constructor = constructor.declaration; | 767 constructor = constructor.declaration; |
| 760 } | 768 } |
| 761 return constructor; | 769 return constructor; |
| 762 } | 770 } |
| OLD | NEW |