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

Side by Side Diff: pkg/front_end/lib/src/fasta/source/source_loader.dart

Issue 2862223002: Rewrite mixin application handling in Fasta. (Closed)
Patch Set: Created 3 years, 7 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.source_loader; 5 library fasta.source_loader;
6 6
7 import 'dart:async' show Future; 7 import 'dart:async' show Future;
8 8
9 import 'dart:typed_data' show Uint8List; 9 import 'dart:typed_data' show Uint8List;
10 10
11 import 'package:front_end/src/base/instrumentation.dart' show Instrumentation; 11 import 'package:front_end/src/base/instrumentation.dart' show Instrumentation;
12 12
13 import 'package:front_end/src/fasta/kernel/kernel_shadow_ast.dart' 13 import 'package:front_end/src/fasta/kernel/kernel_shadow_ast.dart'
14 show KernelTypeInferrer; 14 show KernelTypeInferrer;
15 15
16 import 'package:front_end/src/fasta/kernel/kernel_target.dart' 16 import 'package:front_end/src/fasta/kernel/kernel_target.dart'
17 show KernelTarget; 17 show KernelTarget;
18 18
19 import 'package:kernel/ast.dart' show Program; 19 import 'package:kernel/ast.dart' show Program;
20 20
21 import 'package:kernel/class_hierarchy.dart' show ClassHierarchy; 21 import 'package:kernel/class_hierarchy.dart' show ClassHierarchy;
22 22
23 import 'package:kernel/core_types.dart' show CoreTypes; 23 import 'package:kernel/core_types.dart' show CoreTypes;
24 24
25 import '../builder/builder.dart' 25 import '../builder/builder.dart'
26 show Builder, ClassBuilder, EnumBuilder, LibraryBuilder; 26 show
27 Builder,
28 ClassBuilder,
29 EnumBuilder,
30 LibraryBuilder,
31 NamedTypeBuilder,
32 TypeBuilder;
27 33
28 import '../compiler_context.dart' show CompilerContext; 34 import '../compiler_context.dart' show CompilerContext;
29 35
30 import '../errors.dart' show inputError; 36 import '../errors.dart' show inputError;
31 37
32 import '../export.dart' show Export; 38 import '../export.dart' show Export;
33 39
34 import '../loader.dart' show Loader; 40 import '../loader.dart' show Loader;
35 41
36 import '../parser/class_member_parser.dart' show ClassMemberParser; 42 import '../parser/class_member_parser.dart' show ClassMemberParser;
(...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after
329 realCycles.forEach((ClassBuilder cls, Set<ClassBuilder> cycles) { 335 realCycles.forEach((ClassBuilder cls, Set<ClassBuilder> cycles) {
330 target.breakCycle(cls); 336 target.breakCycle(cls);
331 if (reported.add(cls)) { 337 if (reported.add(cls)) {
332 List<ClassBuilder> involved = <ClassBuilder>[]; 338 List<ClassBuilder> involved = <ClassBuilder>[];
333 for (ClassBuilder cls in cycles) { 339 for (ClassBuilder cls in cycles) {
334 if (realCycles.containsKey(cls)) { 340 if (realCycles.containsKey(cls)) {
335 involved.add(cls); 341 involved.add(cls);
336 reported.add(cls); 342 reported.add(cls);
337 } 343 }
338 } 344 }
345 String involvedString =
346 involved.map((c) => c.fullNameForErrors).join("', '");
339 cls.addCompileTimeError( 347 cls.addCompileTimeError(
340 cls.charOffset, 348 cls.charOffset,
341 "'${cls.name}' is a supertype of " 349 "'${cls.fullNameForErrors}' is a supertype of itself via "
342 "itself via '${involved.map((c) => c.name).join(' ')}'."); 350 "'$involvedString'.");
343 } 351 }
344 }); 352 });
345 ticker.logMs("Found cycles"); 353 ticker.logMs("Found cycles");
346 Set<ClassBuilder> blackListedClasses = new Set<ClassBuilder>.from([ 354 Set<ClassBuilder> blackListedClasses = new Set<ClassBuilder>.from([
347 coreLibrary["bool"], 355 coreLibrary["bool"],
348 coreLibrary["int"], 356 coreLibrary["int"],
349 coreLibrary["num"], 357 coreLibrary["num"],
350 coreLibrary["double"], 358 coreLibrary["double"],
351 coreLibrary["String"], 359 coreLibrary["String"],
352 ]); 360 ]);
353 for (ClassBuilder cls in allClasses) { 361 for (ClassBuilder cls in allClasses) {
362 if (cls.library.loader != this) continue;
354 Set<ClassBuilder> directSupertypes = new Set<ClassBuilder>(); 363 Set<ClassBuilder> directSupertypes = new Set<ClassBuilder>();
355 target.addDirectSupertype(cls, directSupertypes); 364 target.addDirectSupertype(cls, directSupertypes);
356 for (ClassBuilder supertype in directSupertypes) { 365 for (ClassBuilder supertype in directSupertypes) {
357 if (supertype is EnumBuilder) { 366 if (supertype is EnumBuilder) {
358 cls.addCompileTimeError( 367 cls.addCompileTimeError(
359 cls.charOffset, 368 cls.charOffset,
360 "'${supertype.name}' is an enum and can't be extended or " 369 "'${supertype.name}' is an enum and can't be extended or "
361 "implemented."); 370 "implemented.");
362 } else if (cls.library != coreLibrary && 371 } else if (cls.library != coreLibrary &&
363 blackListedClasses.contains(supertype)) { 372 blackListedClasses.contains(supertype)) {
364 cls.addCompileTimeError( 373 cls.addCompileTimeError(
365 cls.charOffset, 374 cls.charOffset,
366 "'${supertype.name}' is restricted and can't be extended or " 375 "'${supertype.name}' is restricted and can't be extended or "
367 "implemented."); 376 "implemented.");
368 } 377 }
369 } 378 }
379 TypeBuilder mixedInType = cls.mixedInType;
380 if (mixedInType != null) {
381 bool isClassBuilder = false;
382 if (mixedInType is NamedTypeBuilder) {
383 var builder = mixedInType.builder;
384 if (builder is ClassBuilder) {
385 isClassBuilder = true;
386 for (Builder constructory in builder.constructors.local.values) {
387 if (constructory.isConstructor && !constructory.isSynthetic) {
388 cls.addCompileTimeError(
389 cls.charOffset,
390 "Can't use '${builder.fullNameForErrors}' as a mixin "
391 "because it has constructors.");
392 builder.addCompileTimeError(
393 constructory.charOffset,
394 "This constructor prevents using "
395 "'${builder.fullNameForErrors}' as a mixin.");
396 }
397 }
398 }
399 }
400 if (!isClassBuilder) {
401 cls.addCompileTimeError(cls.charOffset,
402 "The type '${mixedInType.fullNameForErrors}' can't be mixed in.");
403 }
404 }
370 } 405 }
371 ticker.logMs("Checked restricted supertypes"); 406 ticker.logMs("Checked restricted supertypes");
372 } 407 }
373 408
374 void buildProgram() { 409 void buildProgram() {
375 builders.forEach((Uri uri, LibraryBuilder library) { 410 builders.forEach((Uri uri, LibraryBuilder library) {
376 if (library is SourceLibraryBuilder) { 411 if (library is SourceLibraryBuilder) {
377 libraries.add(library.build(coreLibrary)); 412 libraries.add(library.build(coreLibrary));
378 } 413 }
379 }); 414 });
(...skipping 10 matching lines...) Expand all
390 void checkOverrides(List<SourceClassBuilder> sourceClasses) { 425 void checkOverrides(List<SourceClassBuilder> sourceClasses) {
391 assert(hierarchy != null); 426 assert(hierarchy != null);
392 for (SourceClassBuilder builder in sourceClasses) { 427 for (SourceClassBuilder builder in sourceClasses) {
393 builder.checkOverrides(hierarchy); 428 builder.checkOverrides(hierarchy);
394 } 429 }
395 ticker.logMs("Checked overrides"); 430 ticker.logMs("Checked overrides");
396 } 431 }
397 432
398 List<Uri> getDependencies() => sourceBytes.keys.toList(); 433 List<Uri> getDependencies() => sourceBytes.keys.toList();
399 } 434 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698