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 | 4 |
5 library fasta.kernel_mixin_application_builder; | 5 library fasta.kernel_mixin_application_builder; |
6 | 6 |
7 import 'package:kernel/ast.dart' show | 7 import 'package:kernel/ast.dart' show |
8 InterfaceType, | 8 InterfaceType, |
9 Supertype, | 9 Supertype, |
10 setParents; | 10 setParents; |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
57 KernelTypeBuilder s = this.supertype; | 57 KernelTypeBuilder s = this.supertype; |
58 for (KernelTypeBuilder builder in mixins) { | 58 for (KernelTypeBuilder builder in mixins) { |
59 s = applyMixin(s, builder); | 59 s = applyMixin(s, builder); |
60 } | 60 } |
61 builtType = s.buildSupertype(); | 61 builtType = s.buildSupertype(); |
62 return builtType; | 62 return builtType; |
63 } | 63 } |
64 | 64 |
65 TypeBuilder applyMixin(TypeBuilder supertype, TypeBuilder mixin) { | 65 TypeBuilder applyMixin(TypeBuilder supertype, TypeBuilder mixin) { |
66 KernelLibraryBuilder library = this.library.partOfLibrary ?? this.library; | 66 KernelLibraryBuilder library = this.library.partOfLibrary ?? this.library; |
| 67 List<KernelTypeBuilder> typeArguments; |
67 List<TypeVariableBuilder> newTypeVariables; | 68 List<TypeVariableBuilder> newTypeVariables; |
68 List<KernelTypeBuilder> typeArguments; | |
69 if (typeVariables != null) { | 69 if (typeVariables != null) { |
| 70 assert(subclassName != null); |
70 newTypeVariables = library.copyTypeVariables(typeVariables); | 71 newTypeVariables = library.copyTypeVariables(typeVariables); |
71 Map<TypeVariableBuilder, TypeBuilder> substitution = | 72 Map<TypeVariableBuilder, TypeBuilder> substitution = |
72 <TypeVariableBuilder, TypeBuilder>{}; | 73 <TypeVariableBuilder, TypeBuilder>{}; |
73 typeArguments = <KernelTypeBuilder>[]; | 74 typeArguments = <KernelTypeBuilder>[]; |
74 for (int i = 0; i < typeVariables.length; i++) { | 75 for (int i = 0; i < typeVariables.length; i++) { |
75 substitution[typeVariables[i]] = newTypeVariables[i].asTypeBuilder(); | 76 substitution[typeVariables[i]] = newTypeVariables[i].asTypeBuilder(); |
76 typeArguments.add(typeVariables[i].asTypeBuilder()); | 77 typeArguments.add(typeVariables[i].asTypeBuilder()); |
77 } | 78 } |
78 supertype = supertype.subst(substitution); | 79 supertype = supertype.subst(substitution); |
79 mixin = mixin.subst(substitution); | 80 mixin = mixin.subst(substitution); |
80 } | 81 } |
81 // To reduce diff against dartk, we create a different name for mixin | 82 // To reduce diff against dartk, we create a different name for mixin |
82 // applications that have free type variables. We do this by setting | 83 // applications that have free type variables. We do this by setting |
83 // [subclassName] when setting typeVariables. | 84 // [subclassName] when setting typeVariables. |
84 String name = subclassName != null | 85 String name = subclassName != null |
85 ? "${subclassName}^${mixin.name}" | 86 ? "${subclassName}^${mixin.name}" |
86 : "${supertype.name}&${mixin.name}"; | 87 : "${supertype.name}&${mixin.name}"; |
87 SourceClassBuilder cls = new SourceClassBuilder(null, abstractMask, name, | 88 |
88 newTypeVariables, supertype, null, <String, Builder>{}, library, | 89 SourceClassBuilder cls = |
89 <ConstructorReferenceBuilder>[], charOffset, null, mixin); | 90 library.mixinApplicationClasses.putIfAbsent(name, () { |
90 library.addImplementationBuilder(name, cls, charOffset); | 91 SourceClassBuilder cls = new SourceClassBuilder( |
91 if (newTypeVariables != null) { | 92 null, |
92 for (KernelTypeVariableBuilder t in newTypeVariables) { | 93 abstractMask, |
93 cls.cls.typeParameters.add(t.parameter); | 94 name, |
| 95 newTypeVariables, |
| 96 supertype, |
| 97 null, |
| 98 <String, Builder>{}, |
| 99 library, |
| 100 <ConstructorReferenceBuilder>[], |
| 101 charOffset, |
| 102 null, |
| 103 mixin); |
| 104 library.addImplementationBuilder(name, cls, charOffset); |
| 105 if (newTypeVariables != null) { |
| 106 for (KernelTypeVariableBuilder t in newTypeVariables) { |
| 107 cls.cls.typeParameters.add(t.parameter); |
| 108 } |
| 109 setParents(cls.cls.typeParameters, cls.cls); |
94 } | 110 } |
95 setParents(cls.cls.typeParameters, cls.cls); | 111 return cls; |
96 } | 112 }); |
97 return new KernelNamedTypeBuilder(name, typeArguments, charOffset, | 113 return new KernelNamedTypeBuilder( |
98 library.fileUri) | 114 name, typeArguments, charOffset, library.fileUri)..builder = cls; |
99 ..builder = cls; | |
100 } | 115 } |
101 } | 116 } |
OLD | NEW |