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:typed_data' show Uint8List; | 9 import 'dart:typed_data' show Uint8List; |
10 | 10 |
11 import 'package:front_end/file_system.dart'; | |
12 import 'package:front_end/src/base/instrumentation.dart' show Instrumentation; | |
13 | |
14 import 'package:front_end/src/fasta/kernel/kernel_shadow_ast.dart' | |
15 show KernelTypeInferenceEngine; | |
16 | |
17 import 'package:front_end/src/fasta/kernel/kernel_target.dart' | |
18 show KernelTarget; | |
19 | |
20 import 'package:front_end/src/fasta/type_inference/type_inference_engine.dart' | |
21 show TypeInferenceEngine; | |
22 | |
23 import 'package:kernel/ast.dart' show Arguments, Expression, Program; | 11 import 'package:kernel/ast.dart' show Arguments, Expression, Program; |
24 | 12 |
25 import 'package:kernel/class_hierarchy.dart' show ClassHierarchy; | 13 import 'package:kernel/class_hierarchy.dart' show ClassHierarchy; |
26 | 14 |
27 import 'package:kernel/core_types.dart' show CoreTypes; | 15 import 'package:kernel/core_types.dart' show CoreTypes; |
28 | 16 |
29 import 'package:kernel/src/incremental_class_hierarchy.dart' | 17 import 'package:kernel/src/incremental_class_hierarchy.dart' |
30 show IncrementalClassHierarchy; | 18 show IncrementalClassHierarchy; |
31 | 19 |
| 20 import '../../../file_system.dart'; |
| 21 |
| 22 import '../../base/instrumentation.dart' show Instrumentation; |
| 23 |
32 import '../builder/builder.dart' | 24 import '../builder/builder.dart' |
33 show | 25 show |
34 Builder, | 26 Builder, |
35 ClassBuilder, | 27 ClassBuilder, |
36 EnumBuilder, | 28 EnumBuilder, |
37 LibraryBuilder, | 29 LibraryBuilder, |
38 NamedTypeBuilder, | 30 NamedTypeBuilder, |
39 TypeBuilder; | 31 TypeBuilder; |
40 | 32 |
41 import '../compiler_context.dart' show CompilerContext; | 33 import '../compiler_context.dart' show CompilerContext; |
42 | 34 |
43 import '../deprecated_problems.dart' show deprecated_inputError; | 35 import '../deprecated_problems.dart' show deprecated_inputError; |
44 | 36 |
45 import '../export.dart' show Export; | 37 import '../export.dart' show Export; |
46 | 38 |
| 39 import '../fasta_codes.dart' |
| 40 show |
| 41 templateCyclicClassHierarchy, |
| 42 templateExtendingEnum, |
| 43 templateExtendingRestricted, |
| 44 templateIllegalMixin, |
| 45 templateIllegalMixinDueToConstructors, |
| 46 templateIllegalMixinDueToConstructorsCause; |
| 47 |
| 48 import '../kernel/kernel_shadow_ast.dart' show KernelTypeInferenceEngine; |
| 49 |
| 50 import '../kernel/kernel_target.dart' show KernelTarget; |
| 51 |
47 import '../loader.dart' show Loader; | 52 import '../loader.dart' show Loader; |
48 | 53 |
49 import '../parser/class_member_parser.dart' show ClassMemberParser; | 54 import '../parser/class_member_parser.dart' show ClassMemberParser; |
50 | 55 |
51 import '../scanner.dart' show ErrorToken, ScannerResult, Token, scan; | 56 import '../scanner.dart' show ErrorToken, ScannerResult, Token, scan; |
52 | 57 |
| 58 import '../type_inference/type_inference_engine.dart' show TypeInferenceEngine; |
| 59 |
53 import 'diet_listener.dart' show DietListener; | 60 import 'diet_listener.dart' show DietListener; |
54 | 61 |
55 import 'diet_parser.dart' show DietParser; | 62 import 'diet_parser.dart' show DietParser; |
56 | 63 |
57 import 'outline_builder.dart' show OutlineBuilder; | 64 import 'outline_builder.dart' show OutlineBuilder; |
58 | 65 |
59 import 'source_class_builder.dart' show SourceClassBuilder; | 66 import 'source_class_builder.dart' show SourceClassBuilder; |
60 | 67 |
61 import 'source_library_builder.dart' show SourceLibraryBuilder; | 68 import 'source_library_builder.dart' show SourceLibraryBuilder; |
62 | 69 |
(...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 } |
368 String involvedString = | 375 String involvedString = |
369 involved.map((c) => c.fullNameForErrors).join("', '"); | 376 involved.map((c) => c.fullNameForErrors).join("', '"); |
370 cls.deprecated_addCompileTimeError( | 377 cls.addCompileTimeError( |
371 cls.charOffset, | 378 templateCyclicClassHierarchy.withArguments( |
372 "'${cls.fullNameForErrors}' is a supertype of itself via " | 379 cls.fullNameForErrors, involvedString), |
373 "'$involvedString'."); | 380 cls.charOffset); |
374 } | 381 } |
375 }); | 382 }); |
376 ticker.logMs("Found cycles"); | 383 ticker.logMs("Found cycles"); |
377 Set<ClassBuilder> blackListedClasses = new Set<ClassBuilder>.from([ | 384 Set<ClassBuilder> blackListedClasses = new Set<ClassBuilder>.from([ |
378 coreLibrary["bool"], | 385 coreLibrary["bool"], |
379 coreLibrary["int"], | 386 coreLibrary["int"], |
380 coreLibrary["num"], | 387 coreLibrary["num"], |
381 coreLibrary["double"], | 388 coreLibrary["double"], |
382 coreLibrary["String"], | 389 coreLibrary["String"], |
383 ]); | 390 ]); |
384 for (ClassBuilder cls in allClasses) { | 391 for (ClassBuilder cls in allClasses) { |
385 if (cls.library.loader != this) continue; | 392 if (cls.library.loader != this) continue; |
386 Set<ClassBuilder> directSupertypes = new Set<ClassBuilder>(); | 393 Set<ClassBuilder> directSupertypes = new Set<ClassBuilder>(); |
387 target.addDirectSupertype(cls, directSupertypes); | 394 target.addDirectSupertype(cls, directSupertypes); |
388 for (ClassBuilder supertype in directSupertypes) { | 395 for (ClassBuilder supertype in directSupertypes) { |
389 if (supertype is EnumBuilder) { | 396 if (supertype is EnumBuilder) { |
390 cls.deprecated_addCompileTimeError( | 397 cls.addCompileTimeError( |
391 cls.charOffset, | 398 templateExtendingEnum.withArguments(supertype.name), |
392 "'${supertype.name}' is an enum and can't be extended or " | 399 cls.charOffset); |
393 "implemented."); | |
394 } else if (!cls.library.mayImplementRestrictedTypes && | 400 } else if (!cls.library.mayImplementRestrictedTypes && |
395 blackListedClasses.contains(supertype)) { | 401 blackListedClasses.contains(supertype)) { |
396 cls.deprecated_addCompileTimeError( | 402 cls.addCompileTimeError( |
397 cls.charOffset, | 403 templateExtendingRestricted.withArguments(supertype.name), |
398 "'${supertype.name}' is restricted and can't be extended or " | 404 cls.charOffset); |
399 "implemented."); | |
400 } | 405 } |
401 } | 406 } |
402 TypeBuilder mixedInType = cls.mixedInType; | 407 TypeBuilder mixedInType = cls.mixedInType; |
403 if (mixedInType != null) { | 408 if (mixedInType != null) { |
404 bool isClassBuilder = false; | 409 bool isClassBuilder = false; |
405 if (mixedInType is NamedTypeBuilder) { | 410 if (mixedInType is NamedTypeBuilder) { |
406 var builder = mixedInType.builder; | 411 var builder = mixedInType.builder; |
407 if (builder is ClassBuilder) { | 412 if (builder is ClassBuilder) { |
408 isClassBuilder = true; | 413 isClassBuilder = true; |
409 for (Builder constructory in builder.constructors.local.values) { | 414 for (Builder constructory in builder.constructors.local.values) { |
410 if (constructory.isConstructor && !constructory.isSynthetic) { | 415 if (constructory.isConstructor && !constructory.isSynthetic) { |
411 cls.deprecated_addCompileTimeError( | 416 cls.addCompileTimeError( |
412 cls.charOffset, | 417 templateIllegalMixinDueToConstructors |
413 "Can't use '${builder.fullNameForErrors}' as a mixin " | 418 .withArguments(builder.fullNameForErrors), |
414 "because it has constructors."); | 419 cls.charOffset); |
415 builder.deprecated_addCompileTimeError( | 420 builder.addCompileTimeError( |
416 constructory.charOffset, | 421 templateIllegalMixinDueToConstructorsCause |
417 "This constructor prevents using " | 422 .withArguments(builder.fullNameForErrors), |
418 "'${builder.fullNameForErrors}' as a mixin."); | 423 constructory.charOffset); |
419 } | 424 } |
420 } | 425 } |
421 } | 426 } |
422 } | 427 } |
423 if (!isClassBuilder) { | 428 if (!isClassBuilder) { |
424 cls.deprecated_addCompileTimeError(cls.charOffset, | 429 cls.addCompileTimeError( |
425 "The type '${mixedInType.fullNameForErrors}' can't be mixed in."); | 430 templateIllegalMixin.withArguments(mixedInType.fullNameForErrors), |
| 431 cls.charOffset); |
426 } | 432 } |
427 } | 433 } |
428 } | 434 } |
429 ticker.logMs("Checked restricted supertypes"); | 435 ticker.logMs("Checked restricted supertypes"); |
430 } | 436 } |
431 | 437 |
432 void buildProgram() { | 438 void buildProgram() { |
433 builders.forEach((Uri uri, LibraryBuilder library) { | 439 builders.forEach((Uri uri, LibraryBuilder library) { |
434 if (library is SourceLibraryBuilder) { | 440 if (library is SourceLibraryBuilder) { |
435 libraries.add(library.build(coreLibrary)); | 441 libraries.add(library.build(coreLibrary)); |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
516 | 522 |
517 Expression throwCompileConstantError(Expression error) { | 523 Expression throwCompileConstantError(Expression error) { |
518 return target.backendTarget.throwCompileConstantError(coreTypes, error); | 524 return target.backendTarget.throwCompileConstantError(coreTypes, error); |
519 } | 525 } |
520 | 526 |
521 Expression deprecated_buildCompileTimeError(String message, int offset) { | 527 Expression deprecated_buildCompileTimeError(String message, int offset) { |
522 return target.backendTarget | 528 return target.backendTarget |
523 .buildCompileTimeError(coreTypes, message, offset); | 529 .buildCompileTimeError(coreTypes, message, offset); |
524 } | 530 } |
525 } | 531 } |
OLD | NEW |