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