| 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.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:io'; | 9 import 'dart:io'; |
| 10 import 'dart:typed_data' show Uint8List; | 10 import 'dart:typed_data' show Uint8List; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 | 25 |
| 26 import 'package:front_end/src/fasta/type_inference/type_inference_engine.dart' | 26 import 'package:front_end/src/fasta/type_inference/type_inference_engine.dart' |
| 27 show TypeInferenceEngine; | 27 show TypeInferenceEngine; |
| 28 | 28 |
| 29 import 'package:kernel/ast.dart' show Program; | 29 import 'package:kernel/ast.dart' show Program; |
| 30 | 30 |
| 31 import 'package:kernel/class_hierarchy.dart' show ClassHierarchy; | 31 import 'package:kernel/class_hierarchy.dart' show ClassHierarchy; |
| 32 | 32 |
| 33 import 'package:kernel/core_types.dart' show CoreTypes; | 33 import 'package:kernel/core_types.dart' show CoreTypes; |
| 34 | 34 |
| 35 import '../builder/builder.dart' show Builder, ClassBuilder, LibraryBuilder; | 35 import '../builder/builder.dart' |
| 36 show |
| 37 Builder, |
| 38 ClassBuilder, |
| 39 EnumBuilder, |
| 40 LibraryBuilder, |
| 41 NamedTypeBuilder, |
| 42 TypeBuilder; |
| 36 | 43 |
| 37 import '../compiler_context.dart' show CompilerContext; | 44 import '../compiler_context.dart' show CompilerContext; |
| 38 | 45 |
| 39 import '../errors.dart' show inputError; | 46 import '../errors.dart' show inputError; |
| 40 | 47 |
| 41 import '../export.dart' show Export; | 48 import '../export.dart' show Export; |
| 42 | 49 |
| 43 import '../loader.dart' show Loader; | 50 import '../loader.dart' show Loader; |
| 44 | 51 |
| 45 import '../parser/class_member_parser.dart' show ClassMemberParser; | 52 import '../parser/class_member_parser.dart' show ClassMemberParser; |
| (...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 358 realCycles.forEach((ClassBuilder cls, Set<ClassBuilder> cycles) { | 365 realCycles.forEach((ClassBuilder cls, Set<ClassBuilder> cycles) { |
| 359 target.breakCycle(cls); | 366 target.breakCycle(cls); |
| 360 if (reported.add(cls)) { | 367 if (reported.add(cls)) { |
| 361 List<ClassBuilder> involved = <ClassBuilder>[]; | 368 List<ClassBuilder> involved = <ClassBuilder>[]; |
| 362 for (ClassBuilder cls in cycles) { | 369 for (ClassBuilder cls in cycles) { |
| 363 if (realCycles.containsKey(cls)) { | 370 if (realCycles.containsKey(cls)) { |
| 364 involved.add(cls); | 371 involved.add(cls); |
| 365 reported.add(cls); | 372 reported.add(cls); |
| 366 } | 373 } |
| 367 } | 374 } |
| 375 String involvedString = |
| 376 involved.map((c) => c.fullNameForErrors).join("', '"); |
| 368 cls.addCompileTimeError( | 377 cls.addCompileTimeError( |
| 369 cls.charOffset, | 378 cls.charOffset, |
| 370 "'${cls.name}' is a supertype of " | 379 "'${cls.fullNameForErrors}' is a supertype of itself via " |
| 371 "itself via '${involved.map((c) => c.name).join(' ')}'."); | 380 "'$involvedString'."); |
| 372 } | 381 } |
| 373 }); | 382 }); |
| 374 ticker.logMs("Found cycles"); | 383 ticker.logMs("Found cycles"); |
| 384 Set<ClassBuilder> blackListedClasses = new Set<ClassBuilder>.from([ |
| 385 coreLibrary["bool"], |
| 386 coreLibrary["int"], |
| 387 coreLibrary["num"], |
| 388 coreLibrary["double"], |
| 389 coreLibrary["String"], |
| 390 ]); |
| 391 for (ClassBuilder cls in allClasses) { |
| 392 if (cls.library.loader != this) continue; |
| 393 Set<ClassBuilder> directSupertypes = new Set<ClassBuilder>(); |
| 394 target.addDirectSupertype(cls, directSupertypes); |
| 395 for (ClassBuilder supertype in directSupertypes) { |
| 396 if (supertype is EnumBuilder) { |
| 397 cls.addCompileTimeError( |
| 398 cls.charOffset, |
| 399 "'${supertype.name}' is an enum and can't be extended or " |
| 400 "implemented."); |
| 401 } else if (cls.library != coreLibrary && |
| 402 blackListedClasses.contains(supertype)) { |
| 403 cls.addCompileTimeError( |
| 404 cls.charOffset, |
| 405 "'${supertype.name}' is restricted and can't be extended or " |
| 406 "implemented."); |
| 407 } |
| 408 } |
| 409 TypeBuilder mixedInType = cls.mixedInType; |
| 410 if (mixedInType != null) { |
| 411 bool isClassBuilder = false; |
| 412 if (mixedInType is NamedTypeBuilder) { |
| 413 var builder = mixedInType.builder; |
| 414 if (builder is ClassBuilder) { |
| 415 isClassBuilder = true; |
| 416 for (Builder constructory in builder.constructors.local.values) { |
| 417 if (constructory.isConstructor && !constructory.isSynthetic) { |
| 418 cls.addCompileTimeError( |
| 419 cls.charOffset, |
| 420 "Can't use '${builder.fullNameForErrors}' as a mixin " |
| 421 "because it has constructors."); |
| 422 builder.addCompileTimeError( |
| 423 constructory.charOffset, |
| 424 "This constructor prevents using " |
| 425 "'${builder.fullNameForErrors}' as a mixin."); |
| 426 } |
| 427 } |
| 428 } |
| 429 } |
| 430 if (!isClassBuilder) { |
| 431 cls.addCompileTimeError(cls.charOffset, |
| 432 "The type '${mixedInType.fullNameForErrors}' can't be mixed in."); |
| 433 } |
| 434 } |
| 435 } |
| 436 ticker.logMs("Checked restricted supertypes"); |
| 375 } | 437 } |
| 376 | 438 |
| 377 void buildProgram() { | 439 void buildProgram() { |
| 378 builders.forEach((Uri uri, LibraryBuilder library) { | 440 builders.forEach((Uri uri, LibraryBuilder library) { |
| 379 if (library is SourceLibraryBuilder) { | 441 if (library is SourceLibraryBuilder) { |
| 380 libraries.add(library.build(coreLibrary)); | 442 libraries.add(library.build(coreLibrary)); |
| 381 } | 443 } |
| 382 }); | 444 }); |
| 383 ticker.logMs("Built program"); | 445 ticker.logMs("Built program"); |
| 384 } | 446 } |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 420 /// Performs the second phase of top level initializer inference, which is to | 482 /// Performs the second phase of top level initializer inference, which is to |
| 421 /// visit fields and top level variables in topologically-sorted order and | 483 /// visit fields and top level variables in topologically-sorted order and |
| 422 /// assign their types. | 484 /// assign their types. |
| 423 void performInitializerInference() { | 485 void performInitializerInference() { |
| 424 typeInferenceEngine.finishTopLevel(); | 486 typeInferenceEngine.finishTopLevel(); |
| 425 ticker.logMs("Performed initializer inference"); | 487 ticker.logMs("Performed initializer inference"); |
| 426 } | 488 } |
| 427 | 489 |
| 428 List<Uri> getDependencies() => sourceBytes.keys.toList(); | 490 List<Uri> getDependencies() => sourceBytes.keys.toList(); |
| 429 } | 491 } |
| OLD | NEW |