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 Target; | 10 import '../target/targets.dart' show Target; |
11 import '../type_algebra.dart'; | 11 import '../type_algebra.dart'; |
12 | 12 |
13 void transformLibraries( | 13 void transformLibraries(Target targetInfo, CoreTypes coreTypes, |
14 Target targetInfo, CoreTypes coreTypes, List<Library> libraries) { | 14 ClassHierarchy hierarchy, List<Library> libraries) { |
15 new MixinFullResolution(targetInfo, coreTypes).transform(libraries); | 15 new MixinFullResolution(targetInfo, coreTypes, hierarchy) |
16 .transform(libraries); | |
16 } | 17 } |
17 | 18 |
18 /// Replaces all mixin applications with regular classes, cloning all fields | 19 /// Replaces all mixin applications with regular classes, cloning all fields |
19 /// and procedures from the mixed-in class, cloning all constructors from the | 20 /// and procedures from the mixed-in class, cloning all constructors from the |
20 /// base class. | 21 /// base class. |
21 /// | 22 /// |
22 /// Super calls (as well as super initializer invocations) are also resolved | 23 /// Super calls (as well as super initializer invocations) are also resolved |
23 /// to their targets in this pass. | 24 /// to their targets in this pass. |
24 class MixinFullResolution { | 25 class MixinFullResolution { |
25 final Target targetInfo; | 26 final Target targetInfo; |
27 final CoreTypes coreTypes; | |
26 | 28 |
27 final CoreTypes coreTypes; | 29 /// The [ClassHierarchy] that should be used after applying this transformer. |
30 /// If any class was updated, in general we need to create a new | |
31 /// [ClassHierarchy] instance, with new dispatch targets; or at least let | |
32 /// the existing instance know that some of its dispatch tables are not | |
33 /// valid anymore. | |
ahe
2017/06/01 11:38:29
This is a good practical work around for a complex
| |
28 ClassHierarchy hierarchy; | 34 ClassHierarchy hierarchy; |
29 | 35 |
30 MixinFullResolution(this.targetInfo, this.coreTypes); | 36 MixinFullResolution(this.targetInfo, this.coreTypes, this.hierarchy); |
31 | 37 |
32 /// Transform the given new [libraries]. It is expected that all other | 38 /// Transform the given new [libraries]. It is expected that all other |
33 /// libraries have already been transformed. | 39 /// libraries have already been transformed. |
34 void transform(List<Library> libraries) { | 40 void transform(List<Library> libraries) { |
35 if (libraries.isEmpty) return; | 41 if (libraries.isEmpty) return; |
36 | 42 |
37 var transformedClasses = new Set<Class>(); | 43 var transformedClasses = new Set<Class>(); |
38 | 44 |
39 // Desugar all mixin application classes by copying in fields/methods from | 45 // Desugar all mixin application classes by copying in fields/methods from |
40 // the mixin and constructors from the base class. | 46 // the mixin and constructors from the base class. |
41 var processedClasses = new Set<Class>(); | 47 var processedClasses = new Set<Class>(); |
42 for (var library in libraries) { | 48 for (var library in libraries) { |
43 if (library.isExternal) continue; | 49 if (library.isExternal) continue; |
44 | 50 |
45 for (var class_ in library.classes) { | 51 for (var class_ in library.classes) { |
46 transformClass(libraries, processedClasses, transformedClasses, class_); | 52 transformClass(libraries, processedClasses, transformedClasses, class_); |
47 } | 53 } |
48 } | 54 } |
49 | 55 |
50 // TODO(scheglov) Remove "program" once we switch to creating "hierarchy" | 56 // If there are transformed classes, we need to update hierarchy. |
51 // and "coreTypes" outside and passing into the transformers. | 57 if (transformedClasses.isNotEmpty) { |
52 var program = libraries.first.enclosingProgram; | 58 var program = libraries.first.enclosingProgram; |
53 hierarchy = new ClassHierarchy(program); | 59 hierarchy = new ClosedWorldClassHierarchy(program); |
60 } | |
54 | 61 |
55 // Resolve all super call expressions and super initializers. | 62 // Resolve all super call expressions and super initializers. |
56 for (var library in libraries) { | 63 for (var library in libraries) { |
57 if (library.isExternal) continue; | 64 if (library.isExternal) continue; |
58 | 65 |
59 for (var class_ in library.classes) { | 66 for (var class_ in library.classes) { |
60 final bool hasTransformedSuperclass = | 67 final bool hasTransformedSuperclass = |
61 transformedClasses.contains(class_.superclass); | 68 transformedClasses.contains(class_.superclass); |
62 | 69 |
63 for (var procedure in class_.procedures) { | 70 for (var procedure in class_.procedures) { |
(...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
343 return null; | 350 return null; |
344 } | 351 } |
345 } | 352 } |
346 | 353 |
347 throw new Exception( | 354 throw new Exception( |
348 'Could not find a generative constructor named "${constructor.name}" ' | 355 'Could not find a generative constructor named "${constructor.name}" ' |
349 'in lookup class "${lookupClass.name}"!'); | 356 'in lookup class "${lookupClass.name}"!'); |
350 } | 357 } |
351 } | 358 } |
352 } | 359 } |
OLD | NEW |