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_target; | 5 library fasta.kernel_target; |
6 | 6 |
7 import 'dart:async' show | 7 import 'dart:async' show |
8 Future; | 8 Future; |
9 | 9 |
10 import 'dart:io' show | 10 import 'dart:io' show |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
75 import '../errors.dart' show | 75 import '../errors.dart' show |
76 InputError, | 76 InputError, |
77 internalError, | 77 internalError, |
78 reportCrash, | 78 reportCrash, |
79 resetCrashReporting; | 79 resetCrashReporting; |
80 | 80 |
81 import 'kernel_builder.dart' show | 81 import 'kernel_builder.dart' show |
82 Builder, | 82 Builder, |
83 ClassBuilder, | 83 ClassBuilder, |
84 DynamicTypeBuilder, | 84 DynamicTypeBuilder, |
85 InterfaceTypeBuilder, | |
86 InvalidTypeBuilder, | 85 InvalidTypeBuilder, |
87 KernelClassBuilder, | 86 KernelClassBuilder, |
88 KernelInterfaceTypeBuilder, | |
89 KernelLibraryBuilder, | 87 KernelLibraryBuilder, |
| 88 KernelNamedTypeBuilder, |
90 KernelProcedureBuilder, | 89 KernelProcedureBuilder, |
91 LibraryBuilder, | 90 LibraryBuilder, |
92 MixinApplicationBuilder, | 91 MixinApplicationBuilder, |
93 NamedMixinApplicationBuilder, | 92 NamedMixinApplicationBuilder, |
| 93 NamedTypeBuilder, |
94 TypeBuilder; | 94 TypeBuilder; |
95 | 95 |
96 class KernelSourceTarget extends TargetImplementation { | 96 class KernelTarget extends TargetImplementation { |
97 final DillTarget dillTarget; | 97 final DillTarget dillTarget; |
98 SourceLoader<Library> loader; | 98 SourceLoader<Library> loader; |
99 Program program; | 99 Program program; |
100 | 100 |
101 final List errors = []; | 101 final List errors = []; |
102 | 102 |
103 KernelSourceTarget(DillTarget dillTarget, TranslateUri uriTranslator) | 103 KernelTarget(DillTarget dillTarget, TranslateUri uriTranslator) |
104 : dillTarget = dillTarget, | 104 : dillTarget = dillTarget, |
105 super(dillTarget.ticker, uriTranslator) { | 105 super(dillTarget.ticker, uriTranslator) { |
106 resetCrashReporting(); | 106 resetCrashReporting(); |
107 loader = new SourceLoader<Library>(this); | 107 loader = new SourceLoader<Library>(this); |
108 } | 108 } |
109 | 109 |
110 void read(Uri uri) { | 110 void read(Uri uri) { |
111 loader.read(uri); | 111 loader.read(uri); |
112 } | 112 } |
113 | 113 |
114 LibraryBuilder createLibraryBuilder(Uri uri, Uri fileUri) { | 114 LibraryBuilder createLibraryBuilder(Uri uri, Uri fileUri) { |
115 if (dillTarget.isLoaded) { | 115 if (dillTarget.isLoaded) { |
116 var builder = dillTarget.loader.builders[uri]; | 116 var builder = dillTarget.loader.builders[uri]; |
117 if (builder != null) { | 117 if (builder != null) { |
118 return builder; | 118 return builder; |
119 } | 119 } |
120 } | 120 } |
121 return new KernelLibraryBuilder(uri, fileUri, loader); | 121 return new KernelLibraryBuilder(uri, fileUri, loader); |
122 } | 122 } |
123 | 123 |
124 void addDirectSupertype(ClassBuilder cls, Set<ClassBuilder> set) { | 124 void addDirectSupertype(ClassBuilder cls, Set<ClassBuilder> set) { |
125 if (cls == null) return; | 125 if (cls == null) return; |
126 TypeBuilder supertype = cls.supertype; | 126 TypeBuilder supertype = cls.supertype; |
127 add(InterfaceTypeBuilder type) { | 127 add(NamedTypeBuilder type) { |
128 Builder builder = type.builder; | 128 Builder builder = type.builder; |
129 if (builder is ClassBuilder) { | 129 if (builder is ClassBuilder) { |
130 set.add(builder); | 130 set.add(builder); |
131 } else if (builder is! InvalidTypeBuilder && | 131 } else if (builder is! InvalidTypeBuilder && |
132 builder is! DynamicTypeBuilder) { | 132 builder is! DynamicTypeBuilder) { |
133 internalError("Unhandled: ${builder.runtimeType}"); | 133 internalError("Unhandled: ${builder.runtimeType}"); |
134 } | 134 } |
135 } | 135 } |
136 if (supertype == null) { | 136 if (supertype == null) { |
137 // OK. | 137 // OK. |
138 } else if (supertype is MixinApplicationBuilder) { | 138 } else if (supertype is MixinApplicationBuilder) { |
139 add(supertype.supertype); | 139 add(supertype.supertype); |
140 for (InterfaceTypeBuilder t in supertype.mixins) { | 140 for (NamedTypeBuilder t in supertype.mixins) { |
141 add(t); | 141 add(t); |
142 } | 142 } |
143 } else if (supertype is InterfaceTypeBuilder) { | 143 } else if (supertype is NamedTypeBuilder) { |
144 add(supertype); | 144 add(supertype); |
145 } else { | 145 } else { |
146 internalError("Unhandled: ${supertype.runtimeType}"); | 146 internalError("Unhandled: ${supertype.runtimeType}"); |
147 } | 147 } |
148 if (cls.interfaces != null) { | 148 if (cls.interfaces != null) { |
149 for (InterfaceTypeBuilder t in cls.interfaces) { | 149 for (NamedTypeBuilder t in cls.interfaces) { |
150 add(t); | 150 add(t); |
151 } | 151 } |
152 } | 152 } |
153 } | 153 } |
154 | 154 |
155 List<ClassBuilder> collectAllClasses() { | 155 List<ClassBuilder> collectAllClasses() { |
156 List<ClassBuilder> result = <ClassBuilder>[]; | 156 List<ClassBuilder> result = <ClassBuilder>[]; |
157 loader.builders.forEach((Uri uri, LibraryBuilder library) { | 157 loader.builders.forEach((Uri uri, LibraryBuilder library) { |
158 library.members.forEach((String name, Builder member) { | 158 library.members.forEach((String name, Builder member) { |
159 if (member is KernelClassBuilder) { | 159 if (member is KernelClassBuilder) { |
(...skipping 28 matching lines...) Expand all Loading... |
188 } | 188 } |
189 }); | 189 }); |
190 return result; | 190 return result; |
191 } | 191 } |
192 | 192 |
193 void breakCycle(ClassBuilder builder) { | 193 void breakCycle(ClassBuilder builder) { |
194 Class cls = builder.target; | 194 Class cls = builder.target; |
195 cls.implementedTypes.clear(); | 195 cls.implementedTypes.clear(); |
196 cls.supertype = null; | 196 cls.supertype = null; |
197 cls.mixedInType = null; | 197 cls.mixedInType = null; |
198 builder.supertype = new KernelInterfaceTypeBuilder("Object", null) | 198 builder.supertype = new KernelNamedTypeBuilder("Object", null) |
199 ..builder = objectClassBuilder; | 199 ..builder = objectClassBuilder; |
200 builder.interfaces = null; | 200 builder.interfaces = null; |
201 } | 201 } |
202 | 202 |
203 Future<Program> handleInputError(Uri uri, InputError error, | 203 Future<Program> handleInputError(Uri uri, InputError error, |
204 {bool isFullProgram}) { | 204 {bool isFullProgram}) { |
205 if (error != null) { | 205 if (error != null) { |
206 String message = error.format(); | 206 String message = error.format(); |
207 print(message); | 207 print(message); |
208 errors.add(message); | 208 errors.add(message); |
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
391 /// >named q'i = [C/S]qi of the form q'i(ai1,...,aiki) : | 391 /// >named q'i = [C/S]qi of the form q'i(ai1,...,aiki) : |
392 /// >super(ai1,...,aiki);. | 392 /// >super(ai1,...,aiki);. |
393 Builder supertype = builder; | 393 Builder supertype = builder; |
394 while (supertype is NamedMixinApplicationBuilder) { | 394 while (supertype is NamedMixinApplicationBuilder) { |
395 NamedMixinApplicationBuilder named = supertype; | 395 NamedMixinApplicationBuilder named = supertype; |
396 TypeBuilder type = named.mixinApplication; | 396 TypeBuilder type = named.mixinApplication; |
397 if (type is MixinApplicationBuilder) { | 397 if (type is MixinApplicationBuilder) { |
398 MixinApplicationBuilder t = type; | 398 MixinApplicationBuilder t = type; |
399 type = t.supertype; | 399 type = t.supertype; |
400 } | 400 } |
401 if (type is InterfaceTypeBuilder) { | 401 if (type is NamedTypeBuilder) { |
402 supertype = type.builder; | 402 supertype = type.builder; |
403 } else { | 403 } else { |
404 internalError("Unhandled: ${type.runtimeType}"); | 404 internalError("Unhandled: ${type.runtimeType}"); |
405 } | 405 } |
406 } | 406 } |
407 if (supertype is KernelClassBuilder) { | 407 if (supertype is KernelClassBuilder) { |
408 for (Constructor constructor in supertype.cls.constructors) { | 408 for (Constructor constructor in supertype.cls.constructors) { |
409 builder.addSyntheticConstructor( | 409 builder.addSyntheticConstructor( |
410 makeMixinApplicationConstructor(builder.cls.mixin, constructor)); | 410 makeMixinApplicationConstructor(builder.cls.mixin, constructor)); |
411 } | 411 } |
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
587 superclass = superclass.superclass; | 587 superclass = superclass.superclass; |
588 } | 588 } |
589 for (Constructor constructor in superclass.constructors) { | 589 for (Constructor constructor in superclass.constructors) { |
590 if (constructor.name.name.isEmpty) { | 590 if (constructor.name.name.isEmpty) { |
591 return constructor.function.requiredParameterCount == 0 ? | 591 return constructor.function.requiredParameterCount == 0 ? |
592 constructor : null; | 592 constructor : null; |
593 } | 593 } |
594 } | 594 } |
595 return null; | 595 return null; |
596 } | 596 } |
OLD | NEW |