| OLD | NEW |
| 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, 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 library kernel.transformations.mixin_full_resolution; | 4 library kernel.transformations.mixin_full_resolution; |
| 5 | 5 |
| 6 import '../ast.dart'; | 6 import '../ast.dart'; |
| 7 import '../class_hierarchy.dart'; | 7 import '../class_hierarchy.dart'; |
| 8 import '../clone.dart'; | 8 import '../clone.dart'; |
| 9 import '../core_types.dart'; | 9 import '../core_types.dart'; |
| 10 import '../type_algebra.dart'; | 10 import '../type_algebra.dart'; |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 88 var substitution = getSubstitutionMap(class_.mixedInType); | 88 var substitution = getSubstitutionMap(class_.mixedInType); |
| 89 var cloner = new CloneVisitor(typeSubstitution: substitution); | 89 var cloner = new CloneVisitor(typeSubstitution: substitution); |
| 90 for (var field in class_.mixin.fields) { | 90 for (var field in class_.mixin.fields) { |
| 91 class_.addMember(cloner.clone(field)); | 91 class_.addMember(cloner.clone(field)); |
| 92 } | 92 } |
| 93 for (var procedure in class_.mixin.procedures) { | 93 for (var procedure in class_.mixin.procedures) { |
| 94 class_.addMember(cloner.clone(procedure)); | 94 class_.addMember(cloner.clone(procedure)); |
| 95 } | 95 } |
| 96 // For each generative constructor in the superclass we make a | 96 // For each generative constructor in the superclass we make a |
| 97 // corresponding forwarding constructor in the subclass. | 97 // corresponding forwarding constructor in the subclass. |
| 98 var superclassSubstitution = getSubstitutionMap(class_.supertype); | 98 // Named mixin applications already have constructors, so only build the |
| 99 var superclassCloner = | 99 // constructors for anonymous mixin applications. |
| 100 new CloneVisitor(typeSubstitution: superclassSubstitution); | 100 if (class_.constructors.isEmpty) { |
| 101 for (var superclassConstructor in class_.superclass.constructors) { | 101 var superclassSubstitution = getSubstitutionMap(class_.supertype); |
| 102 var forwardingConstructor = | 102 var superclassCloner = |
| 103 buildForwardingConstructor(superclassCloner, superclassConstructor); | 103 new CloneVisitor(typeSubstitution: superclassSubstitution); |
| 104 class_.constructors.add(forwardingConstructor..parent = class_); | 104 for (var superclassConstructor in class_.superclass.constructors) { |
| 105 var forwardingConstructor = |
| 106 buildForwardingConstructor(superclassCloner, superclassConstructor); |
| 107 class_.constructors.add(forwardingConstructor..parent = class_); |
| 108 } |
| 105 } | 109 } |
| 106 | 110 |
| 107 // This class implements the mixin type. | 111 // This class implements the mixin type. |
| 108 class_.implementedTypes.add(class_.mixedInType); | 112 class_.implementedTypes.add(class_.mixedInType); |
| 109 | 113 |
| 110 // This class is now a normal class. | 114 // This class is now a normal class. |
| 111 class_.mixedInType = null; | 115 class_.mixedInType = null; |
| 112 } | 116 } |
| 113 | 117 |
| 114 Constructor buildForwardingConstructor( | 118 Constructor buildForwardingConstructor( |
| (...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 355 return; | 359 return; |
| 356 } | 360 } |
| 357 } | 361 } |
| 358 | 362 |
| 359 throw new Exception( | 363 throw new Exception( |
| 360 'Could not find a generative constructor named "${constructor.name}" ' | 364 'Could not find a generative constructor named "${constructor.name}" ' |
| 361 'in lookup class "${lookupClass.name}"!'); | 365 'in lookup class "${lookupClass.name}"!'); |
| 362 } | 366 } |
| 363 } | 367 } |
| 364 } | 368 } |
| OLD | NEW |