| 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, IOSink; | 9 import 'dart:io' show File, IOSink; |
| 10 | 10 |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 50 import '../source/source_loader.dart' show SourceLoader; | 50 import '../source/source_loader.dart' show SourceLoader; |
| 51 | 51 |
| 52 import '../source/source_class_builder.dart' show SourceClassBuilder; | 52 import '../source/source_class_builder.dart' show SourceClassBuilder; |
| 53 | 53 |
| 54 import '../target_implementation.dart' show TargetImplementation; | 54 import '../target_implementation.dart' show TargetImplementation; |
| 55 | 55 |
| 56 import '../translate_uri.dart' show TranslateUri; | 56 import '../translate_uri.dart' show TranslateUri; |
| 57 | 57 |
| 58 import '../dill/dill_target.dart' show DillTarget; | 58 import '../dill/dill_target.dart' show DillTarget; |
| 59 | 59 |
| 60 import '../ast_kind.dart' show AstKind; | |
| 61 | |
| 62 import '../errors.dart' | 60 import '../errors.dart' |
| 63 show InputError, internalError, reportCrash, resetCrashReporting; | 61 show InputError, internalError, reportCrash, resetCrashReporting; |
| 64 | 62 |
| 65 import '../util/relativize.dart' show relativizeUri; | 63 import '../util/relativize.dart' show relativizeUri; |
| 66 | 64 |
| 67 import '../compiler_context.dart' show CompilerContext; | 65 import '../compiler_context.dart' show CompilerContext; |
| 68 | 66 |
| 69 import 'kernel_builder.dart' | 67 import 'kernel_builder.dart' |
| 70 show | 68 show |
| 71 Builder, | 69 Builder, |
| (...skipping 20 matching lines...) Expand all Loading... |
| 92 Program program; | 90 Program program; |
| 93 | 91 |
| 94 final List errors = []; | 92 final List errors = []; |
| 95 | 93 |
| 96 KernelTarget(DillTarget dillTarget, TranslateUri uriTranslator, | 94 KernelTarget(DillTarget dillTarget, TranslateUri uriTranslator, |
| 97 [Map<String, Source> uriToSource]) | 95 [Map<String, Source> uriToSource]) |
| 98 : dillTarget = dillTarget, | 96 : dillTarget = dillTarget, |
| 99 uriToSource = uriToSource ?? CompilerContext.current.uriToSource, | 97 uriToSource = uriToSource ?? CompilerContext.current.uriToSource, |
| 100 super(dillTarget.ticker, uriTranslator) { | 98 super(dillTarget.ticker, uriTranslator) { |
| 101 resetCrashReporting(); | 99 resetCrashReporting(); |
| 102 loader = new SourceLoader<Library>(this); | 100 loader = createLoader(); |
| 103 } | 101 } |
| 104 | 102 |
| 103 SourceLoader<Library> createLoader() => new SourceLoader<Library>(this); |
| 104 |
| 105 void addLineStarts(Uri uri, List<int> lineStarts) { | 105 void addLineStarts(Uri uri, List<int> lineStarts) { |
| 106 String fileUri = relativizeUri(uri); | 106 String fileUri = relativizeUri(uri); |
| 107 uriToSource[fileUri] = new Source(lineStarts, fileUri); | 107 uriToSource[fileUri] = new Source(lineStarts, fileUri); |
| 108 } | 108 } |
| 109 | 109 |
| 110 void read(Uri uri) { | 110 void read(Uri uri) { |
| 111 loader.read(uri); | 111 loader.read(uri); |
| 112 } | 112 } |
| 113 | 113 |
| 114 LibraryBuilder createLibraryBuilder(Uri uri, Uri fileUri) { | 114 LibraryBuilder createLibraryBuilder(Uri uri, Uri fileUri) { |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 198 String message = error.format(); | 198 String message = error.format(); |
| 199 print(message); | 199 print(message); |
| 200 errors.add(message); | 200 errors.add(message); |
| 201 } | 201 } |
| 202 program = erroneousProgram(isFullProgram); | 202 program = erroneousProgram(isFullProgram); |
| 203 return uri == null | 203 return uri == null |
| 204 ? new Future<Program>.value(program) | 204 ? new Future<Program>.value(program) |
| 205 : writeLinkedProgram(uri, program, isFullProgram: isFullProgram); | 205 : writeLinkedProgram(uri, program, isFullProgram: isFullProgram); |
| 206 } | 206 } |
| 207 | 207 |
| 208 Future<Program> writeProgram(Uri uri, AstKind astKind) async { | 208 Future<Program> writeProgram(Uri uri) async { |
| 209 if (loader.first == null) return null; | 209 if (loader.first == null) return null; |
| 210 if (errors.isNotEmpty) { | 210 if (errors.isNotEmpty) { |
| 211 return handleInputError(uri, null, isFullProgram: true); | 211 return handleInputError(uri, null, isFullProgram: true); |
| 212 } | 212 } |
| 213 try { | 213 try { |
| 214 if (astKind == AstKind.Analyzer) { | 214 loader.computeHierarchy(program); |
| 215 loader.buildElementStore(); | 215 await loader.buildBodies(); |
| 216 } else { | |
| 217 loader.computeHierarchy(program); | |
| 218 } | |
| 219 await loader.buildBodies(astKind); | |
| 220 loader.finishStaticInvocations(); | 216 loader.finishStaticInvocations(); |
| 221 finishAllConstructors(); | 217 finishAllConstructors(); |
| 222 loader.finishNativeMethods(); | 218 loader.finishNativeMethods(); |
| 223 transformMixinApplications(); | 219 transformMixinApplications(); |
| 224 // TODO(ahe): Don't call this from two different places. | 220 // TODO(ahe): Don't call this from two different places. |
| 225 setup_builtin_library.transformProgram(program); | 221 setup_builtin_library.transformProgram(program); |
| 226 errors.addAll(loader.collectCompileTimeErrors().map((e) => e.format())); | 222 errors.addAll(loader.collectCompileTimeErrors().map((e) => e.format())); |
| 227 if (errors.isNotEmpty) { | 223 if (errors.isNotEmpty) { |
| 228 return handleInputError(uri, null, isFullProgram: true); | 224 return handleInputError(uri, null, isFullProgram: true); |
| 229 } | 225 } |
| (...skipping 353 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 583 } | 579 } |
| 584 for (Constructor constructor in superclass.constructors) { | 580 for (Constructor constructor in superclass.constructors) { |
| 585 if (constructor.name.name.isEmpty) { | 581 if (constructor.name.name.isEmpty) { |
| 586 return constructor.function.requiredParameterCount == 0 | 582 return constructor.function.requiredParameterCount == 0 |
| 587 ? constructor | 583 ? constructor |
| 588 : null; | 584 : null; |
| 589 } | 585 } |
| 590 } | 586 } |
| 591 return null; | 587 return null; |
| 592 } | 588 } |
| OLD | NEW |