| 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 '../common/resolution.dart' show Feature; | 8 import '../common/resolution.dart' show Feature; |
| 9 import '../compiler.dart' show Compiler; | 9 import '../compiler.dart' show Compiler; |
| 10 import '../constants/constructors.dart' | 10 import '../constants/constructors.dart' |
| (...skipping 406 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 417 return null; | 417 return null; |
| 418 } | 418 } |
| 419 } else { | 419 } else { |
| 420 reporter.reportErrorMessage(link.head, MessageKind.INVALID_INITIALIZER); | 420 reporter.reportErrorMessage(link.head, MessageKind.INVALID_INITIALIZER); |
| 421 } | 421 } |
| 422 } | 422 } |
| 423 if (!resolvedSuper) { | 423 if (!resolvedSuper) { |
| 424 constructorInvocation = resolveImplicitSuperConstructorSend(); | 424 constructorInvocation = resolveImplicitSuperConstructorSend(); |
| 425 } | 425 } |
| 426 if (isConst && isValidAsConstant) { | 426 if (isConst && isValidAsConstant) { |
| 427 constructor.constantConstructor = new GenerativeConstantConstructor( | 427 constructor.enclosingClass.forEachInstanceField((_, FieldElement field) { |
| 428 constructor.enclosingClass.thisType, | 428 if (!fieldInitializers.containsKey(field)) { |
| 429 defaultValues, | 429 visitor.resolution.ensureResolved(field); |
| 430 fieldInitializers, | 430 // TODO(johnniwinther): Report error if `field.constant` is `null`. |
| 431 constructorInvocation); | 431 if (field.constant != null) { |
| 432 fieldInitializers[field] = field.constant; |
| 433 } else { |
| 434 isValidAsConstant = false; |
| 435 } |
| 436 } |
| 437 }); |
| 438 if (isValidAsConstant) { |
| 439 constructor.constantConstructor = new GenerativeConstantConstructor( |
| 440 constructor.enclosingClass.thisType, |
| 441 defaultValues, |
| 442 fieldInitializers, |
| 443 constructorInvocation); |
| 444 } |
| 432 } | 445 } |
| 433 return null; // If there was no redirection always return null. | 446 return null; // If there was no redirection always return null. |
| 434 } | 447 } |
| 435 } | 448 } |
| 436 | 449 |
| 437 class ConstructorResolver extends CommonResolverVisitor<ConstructorResult> { | 450 class ConstructorResolver extends CommonResolverVisitor<ConstructorResult> { |
| 438 final ResolverVisitor resolver; | 451 final ResolverVisitor resolver; |
| 439 final bool inConstContext; | 452 final bool inConstContext; |
| 440 | 453 |
| 441 ConstructorResolver(Compiler compiler, this.resolver, | 454 ConstructorResolver(Compiler compiler, this.resolver, |
| (...skipping 408 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 850 // constructors. | 863 // constructors. |
| 851 return null; | 864 return null; |
| 852 } | 865 } |
| 853 // TODO(johnniwinther): Use [Name] for lookup. | 866 // TODO(johnniwinther): Use [Name] for lookup. |
| 854 ConstructorElement constructor = cls.lookupConstructor(constructorName); | 867 ConstructorElement constructor = cls.lookupConstructor(constructorName); |
| 855 if (constructor != null) { | 868 if (constructor != null) { |
| 856 constructor = constructor.declaration; | 869 constructor = constructor.declaration; |
| 857 } | 870 } |
| 858 return constructor; | 871 return constructor; |
| 859 } | 872 } |
| OLD | NEW |