Chromium Code Reviews| 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 '../target/targets.dart' show NoneTarget, Target; | 10 import '../target/targets.dart' show Target; |
| 11 import '../type_algebra.dart'; | 11 import '../type_algebra.dart'; |
| 12 | 12 |
| 13 Program transformProgram(Program program) { | 13 void transformLibraries(Target targetInfo, List<Library> libraries) { |
| 14 new MixinFullResolution(new NoneTarget(null)).transform(program); | 14 new MixinFullResolution(targetInfo).transform(libraries); |
| 15 return program; | |
| 16 } | 15 } |
| 17 | 16 |
| 18 /// Replaces all mixin applications with regular classes, cloning all fields | 17 /// Replaces all mixin applications with regular classes, cloning all fields |
| 19 /// and procedures from the mixed-in class, cloning all constructors from the | 18 /// and procedures from the mixed-in class, cloning all constructors from the |
| 20 /// base class. | 19 /// base class. |
| 21 /// | 20 /// |
| 22 /// Super calls (as well as super initializer invocations) are also resolved | 21 /// Super calls (as well as super initializer invocations) are also resolved |
| 23 /// to their targets in this pass. | 22 /// to their targets in this pass. |
| 24 class MixinFullResolution { | 23 class MixinFullResolution { |
| 25 final Target targetInfo; | 24 final Target targetInfo; |
| 26 | 25 |
| 27 ClassHierarchy hierarchy; | 26 ClassHierarchy hierarchy; |
| 28 CoreTypes coreTypes; | 27 CoreTypes coreTypes; |
| 29 | 28 |
| 30 MixinFullResolution(this.targetInfo); | 29 MixinFullResolution(this.targetInfo); |
| 31 | 30 |
| 32 void transform(Program program) { | 31 void transform(List<Library> libraries) { |
| 32 if (libraries.isEmpty) return; | |
| 33 | |
| 33 var transformedClasses = new Set<Class>(); | 34 var transformedClasses = new Set<Class>(); |
| 34 | 35 |
| 35 // Desugar all mixin application classes by copying in fields/methods from | 36 // Desugar all mixin application classes by copying in fields/methods from |
| 36 // the mixin and constructors from the base class. | 37 // the mixin and constructors from the base class. |
| 37 var processedClasses = new Set<Class>(); | 38 var processedClasses = new Set<Class>(); |
| 38 for (var library in program.libraries) { | 39 for (var library in libraries) { |
| 39 if (library.isExternal) continue; | 40 if (library.isExternal) continue; |
| 40 | 41 |
| 41 for (var class_ in library.classes) { | 42 for (var class_ in library.classes) { |
| 42 transformClass(processedClasses, transformedClasses, class_); | 43 transformClass(processedClasses, transformedClasses, class_); |
| 43 } | 44 } |
| 44 } | 45 } |
| 45 | 46 |
| 47 var program = libraries.first.enclosingProgram; | |
|
Siggi Cherem (dart-lang)
2017/05/26 22:08:32
consider adding a TODO that this reference will be
scheglov
2017/05/30 04:20:15
Done.
| |
| 46 hierarchy = new ClassHierarchy(program); | 48 hierarchy = new ClassHierarchy(program); |
| 47 coreTypes = new CoreTypes(program); | 49 coreTypes = new CoreTypes(program); |
| 48 | 50 |
| 49 // Resolve all super call expressions and super initializers. | 51 // Resolve all super call expressions and super initializers. |
| 50 for (var library in program.libraries) { | 52 for (var library in libraries) { |
| 51 if (library.isExternal) continue; | 53 if (library.isExternal) continue; |
| 52 | 54 |
| 53 for (var class_ in library.classes) { | 55 for (var class_ in library.classes) { |
| 54 final bool hasTransformedSuperclass = | 56 final bool hasTransformedSuperclass = |
| 55 transformedClasses.contains(class_.superclass); | 57 transformedClasses.contains(class_.superclass); |
| 56 | 58 |
| 57 for (var procedure in class_.procedures) { | 59 for (var procedure in class_.procedures) { |
| 58 if (procedure.containsSuperCalls) { | 60 if (procedure.containsSuperCalls) { |
| 59 new SuperCallResolutionTransformer( | 61 new SuperCallResolutionTransformer( |
| 60 hierarchy, coreTypes, class_.superclass, targetInfo) | 62 hierarchy, coreTypes, class_.superclass, targetInfo) |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 78 | 80 |
| 79 transformClass(Set<Class> processedClasses, Set<Class> transformedClasses, | 81 transformClass(Set<Class> processedClasses, Set<Class> transformedClasses, |
| 80 Class class_) { | 82 Class class_) { |
| 81 // If this class was already handled then so were all classes up to the | 83 // If this class was already handled then so were all classes up to the |
| 82 // [Object] class. | 84 // [Object] class. |
| 83 if (!processedClasses.add(class_)) return; | 85 if (!processedClasses.add(class_)) return; |
| 84 | 86 |
| 85 // Ensure super classes have been transformed before this class. | 87 // Ensure super classes have been transformed before this class. |
| 86 if (class_.superclass != null && | 88 if (class_.superclass != null && |
| 87 class_.superclass.level.index >= ClassLevel.Mixin.index) { | 89 class_.superclass.level.index >= ClassLevel.Mixin.index) { |
| 88 transformClass(processedClasses, transformedClasses, class_.superclass); | 90 transformClass(processedClasses, transformedClasses, class_.superclass); |
|
ahe
2017/05/29 14:16:54
This method will also transform superclasses even
scheglov
2017/05/30 04:20:15
These libraries are new libraries to transform, wi
| |
| 89 } | 91 } |
| 90 | 92 |
| 91 // If this is not a mixin application we don't need to make forwarding | 93 // If this is not a mixin application we don't need to make forwarding |
| 92 // constructors in this class. | 94 // constructors in this class. |
| 93 if (!class_.isMixinApplication) return; | 95 if (!class_.isMixinApplication) return; |
|
ahe
2017/05/30 09:51:16
Could you add an assertion here that checks if cla
scheglov
2017/05/30 16:33:05
Done.
| |
| 94 | 96 |
| 95 if (class_.mixedInClass.level.index < ClassLevel.Mixin.index) { | 97 if (class_.mixedInClass.level.index < ClassLevel.Mixin.index) { |
| 96 throw new Exception( | 98 throw new Exception( |
| 97 'Class "${class_.name}" mixes in "${class_.mixedInClass.name}" from' | 99 'Class "${class_.name}" mixes in "${class_.mixedInClass.name}" from' |
| 98 ' an external library. Did you forget --link?'); | 100 ' an external library. Did you forget --link?'); |
| 99 } | 101 } |
| 100 | 102 |
| 101 transformedClasses.add(class_); | 103 transformedClasses.add(class_); |
| 102 | 104 |
| 103 // Clone fields and methods from the mixin class. | 105 // Clone fields and methods from the mixin class. |
| (...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 332 return null; | 334 return null; |
| 333 } | 335 } |
| 334 } | 336 } |
| 335 | 337 |
| 336 throw new Exception( | 338 throw new Exception( |
| 337 'Could not find a generative constructor named "${constructor.name}" ' | 339 'Could not find a generative constructor named "${constructor.name}" ' |
| 338 'in lookup class "${lookupClass.name}"!'); | 340 'in lookup class "${lookupClass.name}"!'); |
| 339 } | 341 } |
| 340 } | 342 } |
| 341 } | 343 } |
| OLD | NEW |