Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(444)

Side by Side Diff: pkg/kernel/lib/transformations/mixin_full_resolution.dart

Issue 2671653003: Split the Kernel transformations into modular and global ones (Closed)
Patch Set: Revert inadvertent change Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 13 matching lines...) Expand all
24 ClassHierarchy hierarchy; 24 ClassHierarchy hierarchy;
25 CoreTypes coreTypes; 25 CoreTypes coreTypes;
26 26
27 void transform(Program program) { 27 void transform(Program program) {
28 var transformedClasses = new Set<Class>(); 28 var transformedClasses = new Set<Class>();
29 29
30 // Desugar all mixin application classes by copying in fields/methods from 30 // Desugar all mixin application classes by copying in fields/methods from
31 // the mixin and constructors from the base class. 31 // the mixin and constructors from the base class.
32 var processedClasses = new Set<Class>(); 32 var processedClasses = new Set<Class>();
33 for (var library in program.libraries) { 33 for (var library in program.libraries) {
34 if (library.isExternal) continue;
35
34 for (var class_ in library.classes) { 36 for (var class_ in library.classes) {
35 transformClass(processedClasses, transformedClasses, class_); 37 transformClass(processedClasses, transformedClasses, class_);
36 } 38 }
37 } 39 }
38 40
39 hierarchy = new ClassHierarchy(program); 41 hierarchy = new ClassHierarchy(program);
40 coreTypes = new CoreTypes(program); 42 coreTypes = new CoreTypes(program);
41 43
42 // Resolve all super call expressions and super initializers. 44 // Resolve all super call expressions and super initializers.
43 for (var library in program.libraries) { 45 for (var library in program.libraries) {
46 if (library.isExternal) continue;
47
44 for (var class_ in library.classes) { 48 for (var class_ in library.classes) {
45 final bool hasTransformedSuperclass = 49 final bool hasTransformedSuperclass =
46 transformedClasses.contains(class_.superclass); 50 transformedClasses.contains(class_.superclass);
47 51
48 for (var procedure in class_.procedures) { 52 for (var procedure in class_.procedures) {
49 if (procedure.containsSuperCalls) { 53 if (procedure.containsSuperCalls) {
50 new SuperCallResolutionTransformer( 54 new SuperCallResolutionTransformer(
51 hierarchy, coreTypes, class_.superclass) 55 hierarchy, coreTypes, class_.superclass)
52 .visit(procedure); 56 .visit(procedure);
53 } 57 }
(...skipping 21 matching lines...) Expand all
75 79
76 // Ensure super classes have been transformed before this class. 80 // Ensure super classes have been transformed before this class.
77 if (class_.superclass != null) { 81 if (class_.superclass != null) {
78 transformClass(processedClasses, transformedClasses, class_.superclass); 82 transformClass(processedClasses, transformedClasses, class_.superclass);
79 } 83 }
80 84
81 // If this is not a mixin application we don't need to make forwarding 85 // If this is not a mixin application we don't need to make forwarding
82 // constructors in this class. 86 // constructors in this class.
83 if (!class_.isMixinApplication) return; 87 if (!class_.isMixinApplication) return;
84 88
89 if (class_.mixedInClass.level != ClassLevel.Body) {
90 throw new Exception(
91 'Class "${class_.name}" mixes in "${class_.mixedInClass.name}" from'
92 ' an external library. Did you forget --link?');
93 }
94
85 transformedClasses.add(class_); 95 transformedClasses.add(class_);
86 96
87 // Clone fields and methods from the mixin class. 97 // Clone fields and methods from the mixin class.
88 var substitution = getSubstitutionMap(class_.mixedInType); 98 var substitution = getSubstitutionMap(class_.mixedInType);
89 var cloner = new CloneVisitor(typeSubstitution: substitution); 99 var cloner = new CloneVisitor(typeSubstitution: substitution);
90 for (var field in class_.mixin.fields) { 100 for (var field in class_.mixin.fields) {
91 class_.addMember(cloner.clone(field)); 101 class_.addMember(cloner.clone(field));
92 } 102 }
93 for (var procedure in class_.mixin.procedures) { 103 for (var procedure in class_.mixin.procedures) {
94 class_.addMember(cloner.clone(procedure)); 104 class_.addMember(cloner.clone(procedure));
(...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after
360 return null; 370 return null;
361 } 371 }
362 } 372 }
363 373
364 throw new Exception( 374 throw new Exception(
365 'Could not find a generative constructor named "${constructor.name}" ' 375 'Could not find a generative constructor named "${constructor.name}" '
366 'in lookup class "${lookupClass.name}"!'); 376 'in lookup class "${lookupClass.name}"!');
367 } 377 }
368 } 378 }
369 } 379 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698