| 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 | 7 import 'dart:async' show |
| 8 Future; | 8 Future; |
| 9 | 9 |
| 10 import 'dart:io' show | 10 import 'dart:io' show |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 68 | 68 |
| 69 import '../ast_kind.dart' show | 69 import '../ast_kind.dart' show |
| 70 AstKind; | 70 AstKind; |
| 71 | 71 |
| 72 import '../errors.dart' show | 72 import '../errors.dart' show |
| 73 InputError, | 73 InputError, |
| 74 internalError, | 74 internalError, |
| 75 reportCrash, | 75 reportCrash, |
| 76 resetCrashReporting; | 76 resetCrashReporting; |
| 77 | 77 |
| 78 import '../util/relativize.dart' show |
| 79 relativizeUri; |
| 80 |
| 81 import '../compiler_context.dart' show |
| 82 CompilerContext; |
| 83 |
| 78 import 'kernel_builder.dart' show | 84 import 'kernel_builder.dart' show |
| 79 Builder, | 85 Builder, |
| 80 ClassBuilder, | 86 ClassBuilder, |
| 81 DynamicTypeBuilder, | 87 DynamicTypeBuilder, |
| 82 InvalidTypeBuilder, | 88 InvalidTypeBuilder, |
| 83 KernelClassBuilder, | 89 KernelClassBuilder, |
| 84 KernelLibraryBuilder, | 90 KernelLibraryBuilder, |
| 85 KernelNamedTypeBuilder, | 91 KernelNamedTypeBuilder, |
| 86 KernelProcedureBuilder, | 92 KernelProcedureBuilder, |
| 87 LibraryBuilder, | 93 LibraryBuilder, |
| 88 MixinApplicationBuilder, | 94 MixinApplicationBuilder, |
| 89 NamedMixinApplicationBuilder, | 95 NamedMixinApplicationBuilder, |
| 90 NamedTypeBuilder, | 96 NamedTypeBuilder, |
| 91 TypeBuilder; | 97 TypeBuilder; |
| 92 | 98 |
| 93 class KernelTarget extends TargetImplementation { | 99 class KernelTarget extends TargetImplementation { |
| 94 final DillTarget dillTarget; | 100 final DillTarget dillTarget; |
| 101 |
| 102 /// Shared with [CompilerContext]. |
| 103 final Map<String, Source> uriToSource; |
| 104 |
| 95 SourceLoader<Library> loader; | 105 SourceLoader<Library> loader; |
| 96 Program program; | 106 Program program; |
| 97 | 107 |
| 98 final List errors = []; | 108 final List errors = []; |
| 99 | 109 |
| 100 KernelTarget(DillTarget dillTarget, TranslateUri uriTranslator) | 110 KernelTarget(DillTarget dillTarget, TranslateUri uriTranslator, |
| 111 [Map<String, Source> uriToSource]) |
| 101 : dillTarget = dillTarget, | 112 : dillTarget = dillTarget, |
| 113 uriToSource = uriToSource ?? CompilerContext.current.uriToSource, |
| 102 super(dillTarget.ticker, uriTranslator) { | 114 super(dillTarget.ticker, uriTranslator) { |
| 103 resetCrashReporting(); | 115 resetCrashReporting(); |
| 104 loader = new SourceLoader<Library>(this); | 116 loader = new SourceLoader<Library>(this); |
| 105 } | 117 } |
| 106 | 118 |
| 119 void addLineStarts(Uri uri, List<int> lineStarts) { |
| 120 String fileUri = relativizeUri(uri); |
| 121 uriToSource[fileUri] = new Source(lineStarts, fileUri); |
| 122 } |
| 123 |
| 107 void read(Uri uri) { | 124 void read(Uri uri) { |
| 108 loader.read(uri); | 125 loader.read(uri); |
| 109 } | 126 } |
| 110 | 127 |
| 111 LibraryBuilder createLibraryBuilder(Uri uri, Uri fileUri) { | 128 LibraryBuilder createLibraryBuilder(Uri uri, Uri fileUri) { |
| 112 if (dillTarget.isLoaded) { | 129 if (dillTarget.isLoaded) { |
| 113 var builder = dillTarget.loader.builders[uri]; | 130 var builder = dillTarget.loader.builders[uri]; |
| 114 if (builder != null) { | 131 if (builder != null) { |
| 115 return builder; | 132 return builder; |
| 116 } | 133 } |
| (...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 310 // that used when there's no fileUri on an element. Instead, ensure all | 327 // that used when there's no fileUri on an element. Instead, ensure all |
| 311 // elements have a fileUri. | 328 // elements have a fileUri. |
| 312 uriToSource[""] = new Source(<int>[0], ""); | 329 uriToSource[""] = new Source(<int>[0], ""); |
| 313 Program program = new Program(libraries, uriToSource); | 330 Program program = new Program(libraries, uriToSource); |
| 314 if (loader.first != null) { | 331 if (loader.first != null) { |
| 315 Builder builder = loader.first.members["main"]; | 332 Builder builder = loader.first.members["main"]; |
| 316 if (builder is KernelProcedureBuilder) { | 333 if (builder is KernelProcedureBuilder) { |
| 317 program.mainMethod = builder.procedure; | 334 program.mainMethod = builder.procedure; |
| 318 } | 335 } |
| 319 } | 336 } |
| 320 setup_builtin_library.transformProgram(program); | 337 if (errors.isEmpty || dillTarget.isLoaded) { |
| 338 setup_builtin_library.transformProgram(program); |
| 339 } |
| 321 ticker.logMs("Linked program"); | 340 ticker.logMs("Linked program"); |
| 322 return program; | 341 return program; |
| 323 } | 342 } |
| 324 | 343 |
| 325 Future<Program> writeLinkedProgram(Uri uri, Program program, | 344 Future<Program> writeLinkedProgram(Uri uri, Program program, |
| 326 {bool isFullProgram}) async { | 345 {bool isFullProgram}) async { |
| 327 File output = new File.fromUri(uri); | 346 File output = new File.fromUri(uri); |
| 328 IOSink sink = output.openWrite(); | 347 IOSink sink = output.openWrite(); |
| 329 try { | 348 try { |
| 330 new BinaryPrinter(sink).writeProgramFile(program); | 349 new BinaryPrinter(sink).writeProgramFile(program); |
| (...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 581 superclass = superclass.superclass; | 600 superclass = superclass.superclass; |
| 582 } | 601 } |
| 583 for (Constructor constructor in superclass.constructors) { | 602 for (Constructor constructor in superclass.constructors) { |
| 584 if (constructor.name.name.isEmpty) { | 603 if (constructor.name.name.isEmpty) { |
| 585 return constructor.function.requiredParameterCount == 0 ? | 604 return constructor.function.requiredParameterCount == 0 ? |
| 586 constructor : null; | 605 constructor : null; |
| 587 } | 606 } |
| 588 } | 607 } |
| 589 return null; | 608 return null; |
| 590 } | 609 } |
| OLD | NEW |