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

Side by Side Diff: pkg/front_end/lib/src/fasta/kernel/kernel_library_builder.dart

Issue 2691653003: Compute bounds of type variables. (Closed)
Patch Set: 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 4
5 library fasta.kernel_library_builder; 5 library fasta.kernel_library_builder;
6 6
7 import 'package:kernel/ast.dart'; 7 import 'package:kernel/ast.dart';
8 8
9 import 'package:kernel/clone.dart' show 9 import 'package:kernel/clone.dart' show
10 CloneVisitor; 10 CloneVisitor;
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
58 TypeVariableBuilder; 58 TypeVariableBuilder;
59 59
60 class KernelLibraryBuilder 60 class KernelLibraryBuilder
61 extends SourceLibraryBuilder<KernelTypeBuilder, Library> { 61 extends SourceLibraryBuilder<KernelTypeBuilder, Library> {
62 final Library library; 62 final Library library;
63 63
64 final List<Class> mixinApplicationClasses = <Class>[]; 64 final List<Class> mixinApplicationClasses = <Class>[];
65 65
66 final List<List> argumentsWithMissingDefaultValues = <List>[]; 66 final List<List> argumentsWithMissingDefaultValues = <List>[];
67 67
68 final List<KernelTypeVariableBuilder> boundlessTypeVariables =
69 <KernelTypeVariableBuilder>[];
70
68 KernelLibraryBuilder(Uri uri, Uri fileUri, Loader loader) 71 KernelLibraryBuilder(Uri uri, Uri fileUri, Loader loader)
69 : library = new Library(uri, fileUri: relativizeUri(fileUri)), 72 : library = new Library(uri, fileUri: relativizeUri(fileUri)),
70 super(loader, fileUri); 73 super(loader, fileUri);
71 74
72 Uri get uri => library.importUri; 75 Uri get uri => library.importUri;
73 76
74 KernelTypeBuilder addNamedType(String name, 77 KernelTypeBuilder addNamedType(String name,
75 List<KernelTypeBuilder> arguments, int charOffset) { 78 List<KernelTypeBuilder> arguments, int charOffset) {
76 KernelNamedTypeBuilder type = 79 KernelNamedTypeBuilder type =
77 new KernelNamedTypeBuilder(name, arguments, charOffset, fileUri); 80 new KernelNamedTypeBuilder(name, arguments, charOffset, fileUri);
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
194 197
195 KernelFormalParameterBuilder addFormalParameter( 198 KernelFormalParameterBuilder addFormalParameter(
196 List<MetadataBuilder> metadata, int modifiers, 199 List<MetadataBuilder> metadata, int modifiers,
197 KernelTypeBuilder type, String name, bool hasThis, int charOffset) { 200 KernelTypeBuilder type, String name, bool hasThis, int charOffset) {
198 return new KernelFormalParameterBuilder( 201 return new KernelFormalParameterBuilder(
199 metadata, modifiers, type, name, hasThis, this, charOffset); 202 metadata, modifiers, type, name, hasThis, this, charOffset);
200 } 203 }
201 204
202 KernelTypeVariableBuilder addTypeVariable(String name, 205 KernelTypeVariableBuilder addTypeVariable(String name,
203 KernelTypeBuilder bound, int charOffset) { 206 KernelTypeBuilder bound, int charOffset) {
204 return new KernelTypeVariableBuilder(name, this, charOffset, bound); 207 var builder = new KernelTypeVariableBuilder(name, this, charOffset, bound);
208 boundlessTypeVariables.add(builder);
209 return builder;
205 } 210 }
206 211
207 void buildBuilder(Builder builder) { 212 void buildBuilder(Builder builder) {
208 if (builder is SourceClassBuilder) { 213 if (builder is SourceClassBuilder) {
209 Class cls = builder.build(this); 214 Class cls = builder.build(this);
210 library.addClass(cls); 215 library.addClass(cls);
211 Class superclass = cls.superclass; 216 Class superclass = cls.superclass;
212 if (superclass != null && superclass.isMixinApplication) { 217 if (superclass != null && superclass.isMixinApplication) {
213 List<Class> mixinApplications = <Class>[]; 218 List<Class> mixinApplications = <Class>[];
214 mixinApplicationClasses.add(cls); 219 mixinApplicationClasses.add(cls);
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
304 return argumentsWithMissingDefaultValues.length; 309 return argumentsWithMissingDefaultValues.length;
305 } 310 }
306 311
307 List<TypeVariableBuilder> copyTypeVariables( 312 List<TypeVariableBuilder> copyTypeVariables(
308 List<TypeVariableBuilder> original) { 313 List<TypeVariableBuilder> original) {
309 List<TypeVariableBuilder> copy = <TypeVariableBuilder>[]; 314 List<TypeVariableBuilder> copy = <TypeVariableBuilder>[];
310 for (KernelTypeVariableBuilder variable in original) { 315 for (KernelTypeVariableBuilder variable in original) {
311 var newVariable = new KernelTypeVariableBuilder( 316 var newVariable = new KernelTypeVariableBuilder(
312 variable.name, this, variable.charOffset); 317 variable.name, this, variable.charOffset);
313 copy.add(newVariable); 318 copy.add(newVariable);
319 boundlessTypeVariables.add(newVariable);
314 } 320 }
315 Map<TypeVariableBuilder, TypeBuilder> substitution = 321 Map<TypeVariableBuilder, TypeBuilder> substitution =
316 <TypeVariableBuilder, TypeBuilder>{}; 322 <TypeVariableBuilder, TypeBuilder>{};
317 int i = 0; 323 int i = 0;
318 for (KernelTypeVariableBuilder variable in original) { 324 for (KernelTypeVariableBuilder variable in original) {
319 substitution[variable] = copy[i++].asTypeBuilder(); 325 substitution[variable] = copy[i++].asTypeBuilder();
320 } 326 }
321 i = 0; 327 i = 0;
322 for (KernelTypeVariableBuilder variable in original) { 328 for (KernelTypeVariableBuilder variable in original) {
323 copy[i++].bound = variable.bound?.subst(substitution); 329 copy[i++].bound = variable.bound?.subst(substitution);
324 } 330 }
325 return copy; 331 return copy;
326 } 332 }
333
334 int finishTypeVariables(ClassBuilder object) {
335 int count = boundlessTypeVariables.length;
336 for (KernelTypeVariableBuilder builder in boundlessTypeVariables) {
337 builder.finish(object);
338 }
339 boundlessTypeVariables.clear();
340 return count;
341 }
342
343 @override
344 void includePart(KernelLibraryBuilder part) {
345 super.includePart(part);
346 boundlessTypeVariables.addAll(part.boundlessTypeVariables);
347 mixinApplicationClasses.addAll(part.mixinApplicationClasses);
348 }
327 } 349 }
328 350
329 bool isConstructorName(String name, String className) { 351 bool isConstructorName(String name, String className) {
330 if (name.startsWith(className)) { 352 if (name.startsWith(className)) {
331 if (name.length == className.length) return true; 353 if (name.length == className.length) return true;
332 if (name.startsWith(".", className.length)) return true; 354 if (name.startsWith(".", className.length)) return true;
333 } 355 }
334 return false; 356 return false;
335 } 357 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698