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 430 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
441 return null; | 441 return null; |
442 } | 442 } |
443 } else { | 443 } else { |
444 reporter.reportErrorMessage(link.head, MessageKind.INVALID_INITIALIZER); | 444 reporter.reportErrorMessage(link.head, MessageKind.INVALID_INITIALIZER); |
445 } | 445 } |
446 } | 446 } |
447 if (!resolvedSuper) { | 447 if (!resolvedSuper) { |
448 constructorInvocation = resolveImplicitSuperConstructorSend(); | 448 constructorInvocation = resolveImplicitSuperConstructorSend(); |
449 } | 449 } |
450 if (isConst && isValidAsConstant) { | 450 if (isConst && isValidAsConstant) { |
451 constructor.constantConstructor = new GenerativeConstantConstructor( | 451 constructor.enclosingClass.forEachInstanceField((_, FieldElement field) { |
452 constructor.enclosingClass.thisType, | 452 if (!fieldInitializers.containsKey(field)) { |
453 defaultValues, | 453 visitor.resolution.ensureResolved(field); |
454 fieldInitializers, | 454 // TODO(johnniwinther): Report error if `field.constant` is `null`. |
455 constructorInvocation); | 455 if (field.constant != null) { |
| 456 fieldInitializers[field] = field.constant; |
| 457 } else { |
| 458 isValidAsConstant = false; |
| 459 } |
| 460 } |
| 461 }); |
| 462 if (isValidAsConstant) { |
| 463 constructor.constantConstructor = new GenerativeConstantConstructor( |
| 464 constructor.enclosingClass.thisType, |
| 465 defaultValues, |
| 466 fieldInitializers, |
| 467 constructorInvocation); |
| 468 } |
456 } | 469 } |
457 visitor.scope = oldScope; | 470 visitor.scope = oldScope; |
458 return null; // If there was no redirection always return null. | 471 return null; // If there was no redirection always return null. |
459 } | 472 } |
460 } | 473 } |
461 | 474 |
462 class ConstructorResolver extends CommonResolverVisitor<ConstructorResult> { | 475 class ConstructorResolver extends CommonResolverVisitor<ConstructorResult> { |
463 final ResolverVisitor resolver; | 476 final ResolverVisitor resolver; |
464 final bool inConstContext; | 477 final bool inConstContext; |
465 | 478 |
(...skipping 409 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
875 // constructors. | 888 // constructors. |
876 return null; | 889 return null; |
877 } | 890 } |
878 // TODO(johnniwinther): Use [Name] for lookup. | 891 // TODO(johnniwinther): Use [Name] for lookup. |
879 ConstructorElement constructor = cls.lookupConstructor(constructorName); | 892 ConstructorElement constructor = cls.lookupConstructor(constructorName); |
880 if (constructor != null) { | 893 if (constructor != null) { |
881 constructor = constructor.declaration; | 894 constructor = constructor.declaration; |
882 } | 895 } |
883 return constructor; | 896 return constructor; |
884 } | 897 } |
OLD | NEW |