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 Future; | 7 import 'dart:async' show Future; |
8 | 8 |
9 import 'dart:io' show File; | 9 import 'dart:io' show File; |
10 | 10 |
(...skipping 22 matching lines...) Expand all Loading... |
33 Program, | 33 Program, |
34 Source, | 34 Source, |
35 StringLiteral, | 35 StringLiteral, |
36 SuperInitializer, | 36 SuperInitializer, |
37 Throw, | 37 Throw, |
38 TypeParameter, | 38 TypeParameter, |
39 VariableDeclaration, | 39 VariableDeclaration, |
40 VariableGet, | 40 VariableGet, |
41 VoidType; | 41 VoidType; |
42 | 42 |
43 import 'package:kernel/transformations/erasure.dart' show Erasure; | |
44 | |
45 import 'package:kernel/transformations/continuation.dart' as transformAsync; | |
46 | |
47 import 'package:kernel/transformations/mixin_full_resolution.dart' as mix; | |
48 | |
49 import 'package:kernel/type_algebra.dart' show substitute; | 43 import 'package:kernel/type_algebra.dart' show substitute; |
50 | 44 |
51 import '../source/source_loader.dart' show SourceLoader; | 45 import '../source/source_loader.dart' show SourceLoader; |
52 | 46 |
53 import '../source/source_class_builder.dart' show SourceClassBuilder; | 47 import '../source/source_class_builder.dart' show SourceClassBuilder; |
54 | 48 |
55 import '../target_implementation.dart' show TargetImplementation; | 49 import '../target_implementation.dart' show TargetImplementation; |
56 | 50 |
57 import '../translate_uri.dart' show TranslateUri; | 51 import '../translate_uri.dart' show TranslateUri; |
58 | 52 |
(...skipping 23 matching lines...) Expand all Loading... |
82 TypeVariableBuilder; | 76 TypeVariableBuilder; |
83 | 77 |
84 import 'verifier.dart' show verifyProgram; | 78 import 'verifier.dart' show verifyProgram; |
85 import 'kernel_outline_shaker.dart' | 79 import 'kernel_outline_shaker.dart' |
86 show trimProgram, RetainedDataBuilder, RootsMarker; | 80 show trimProgram, RetainedDataBuilder, RootsMarker; |
87 | 81 |
88 class KernelTarget extends TargetImplementation { | 82 class KernelTarget extends TargetImplementation { |
89 /// The [FileSystem] which should be used to access files. | 83 /// The [FileSystem] which should be used to access files. |
90 final FileSystem fileSystem; | 84 final FileSystem fileSystem; |
91 | 85 |
92 final bool strongMode; | |
93 | |
94 final DillTarget dillTarget; | 86 final DillTarget dillTarget; |
95 | 87 |
96 /// Shared with [CompilerContext]. | 88 /// Shared with [CompilerContext]. |
97 final Map<String, Source> uriToSource; | 89 final Map<String, Source> uriToSource; |
98 | 90 |
99 SourceLoader<Library> loader; | 91 SourceLoader<Library> loader; |
100 | 92 |
101 Program program; | 93 Program program; |
102 | 94 |
103 final List<String> errors = <String>[]; | 95 final List<String> errors = <String>[]; |
104 | 96 |
105 final TypeBuilder dynamicType = | 97 final TypeBuilder dynamicType = |
106 new KernelNamedTypeBuilder("dynamic", null, -1, null); | 98 new KernelNamedTypeBuilder("dynamic", null, -1, null); |
107 | 99 |
108 KernelTarget(this.fileSystem, DillTarget dillTarget, | 100 bool get strongMode => backendTarget.strongMode; |
109 TranslateUri uriTranslator, this.strongMode, | 101 |
| 102 KernelTarget( |
| 103 this.fileSystem, DillTarget dillTarget, TranslateUri uriTranslator, |
110 [Map<String, Source> uriToSource]) | 104 [Map<String, Source> uriToSource]) |
111 : dillTarget = dillTarget, | 105 : dillTarget = dillTarget, |
112 uriToSource = uriToSource ?? CompilerContext.current.uriToSource, | 106 uriToSource = uriToSource ?? CompilerContext.current.uriToSource, |
113 super(dillTarget.ticker, uriTranslator, dillTarget.backendTarget) { | 107 super(dillTarget.ticker, uriTranslator, dillTarget.backendTarget) { |
114 resetCrashReporting(); | 108 resetCrashReporting(); |
115 loader = createLoader(); | 109 loader = createLoader(); |
116 } | 110 } |
117 | 111 |
118 void addError(file, int charOffset, String message) { | 112 void addError(file, int charOffset, String message) { |
119 Uri uri = file is String ? Uri.parse(file) : file; | 113 Uri uri = file is String ? Uri.parse(file) : file; |
(...skipping 528 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
648 initializer.parent = constructor; | 642 initializer.parent = constructor; |
649 constructor.initializers.insert(0, initializer); | 643 constructor.initializers.insert(0, initializer); |
650 } | 644 } |
651 } | 645 } |
652 }); | 646 }); |
653 } | 647 } |
654 | 648 |
655 /// Run all transformations that are needed when building a program for the | 649 /// Run all transformations that are needed when building a program for the |
656 /// first time. | 650 /// first time. |
657 void runBuildTransformations() { | 651 void runBuildTransformations() { |
658 transformMixinApplications(); | 652 backendTarget.performModularTransformationsOnLibraries( |
659 otherTransformations(); | 653 loader.coreTypes, loader.hierarchy, loader.libraries, |
660 } | 654 logger: (String msg) => ticker.logMs(msg)); |
661 | 655 backendTarget.performGlobalTransformations(loader.coreTypes, program, |
662 void transformMixinApplications() { | 656 logger: (String msg) => ticker.logMs(msg)); |
663 mix.transformLibraries( | |
664 backendTarget, loader.coreTypes, loader.hierarchy, loader.libraries); | |
665 ticker.logMs("Transformed mixin applications"); | |
666 } | |
667 | |
668 void otherTransformations() { | |
669 if (!strongMode) { | |
670 // TODO(ahe): Don't generate type variables in the first place. | |
671 program.accept(new Erasure()); | |
672 ticker.logMs("Erased type variables in generic methods"); | |
673 } | |
674 if (errors.isEmpty && loader.collectCompileTimeErrors().isEmpty) { | |
675 // TODO(kmillikin): Make this run on a per-method basis. | |
676 transformAsync.transformLibraries(loader.coreTypes, loader.libraries); | |
677 } | |
678 ticker.logMs("Transformed async methods"); | |
679 } | 657 } |
680 | 658 |
681 void verify() { | 659 void verify() { |
682 var verifyErrors = verifyProgram(program); | 660 var verifyErrors = verifyProgram(program); |
683 errors.addAll(verifyErrors.map((error) => '$error')); | 661 errors.addAll(verifyErrors.map((error) => '$error')); |
684 ticker.logMs("Verified program"); | 662 ticker.logMs("Verified program"); |
685 } | 663 } |
686 | 664 |
687 /// Tree-shakes most code from the [dillTarget] by visiting all other | 665 /// Tree-shakes most code from the [dillTarget] by visiting all other |
688 /// libraries in [program] and marking the APIs from the [dillTarget] | 666 /// libraries in [program] and marking the APIs from the [dillTarget] |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
722 } | 700 } |
723 for (Constructor constructor in superclass.constructors) { | 701 for (Constructor constructor in superclass.constructors) { |
724 if (constructor.name.name.isEmpty) { | 702 if (constructor.name.name.isEmpty) { |
725 return constructor.function.requiredParameterCount == 0 | 703 return constructor.function.requiredParameterCount == 0 |
726 ? constructor | 704 ? constructor |
727 : null; | 705 : null; |
728 } | 706 } |
729 } | 707 } |
730 return null; | 708 return null; |
731 } | 709 } |
OLD | NEW |