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 |
11 import 'package:front_end/file_system.dart'; | 11 import 'package:front_end/file_system.dart'; |
12 import 'package:kernel/ast.dart' | 12 import 'package:kernel/ast.dart' |
13 show | 13 show |
14 Arguments, | 14 Arguments, |
15 AsyncMarker, | 15 AsyncMarker, |
16 CanonicalName, | |
16 Class, | 17 Class, |
17 Constructor, | 18 Constructor, |
18 DartType, | 19 DartType, |
19 DynamicType, | 20 DynamicType, |
20 EmptyStatement, | 21 EmptyStatement, |
21 Expression, | 22 Expression, |
22 ExpressionStatement, | 23 ExpressionStatement, |
23 Field, | 24 Field, |
24 FieldInitializer, | 25 FieldInitializer, |
25 FunctionNode, | 26 FunctionNode, |
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
223 String message = error.format(); | 224 String message = error.format(); |
224 print(message); | 225 print(message); |
225 errors.add(message); | 226 errors.add(message); |
226 } | 227 } |
227 program = erroneousProgram(isFullProgram); | 228 program = erroneousProgram(isFullProgram); |
228 return uri == null | 229 return uri == null |
229 ? new Future<Program>.value(program) | 230 ? new Future<Program>.value(program) |
230 : writeLinkedProgram(uri, program, isFullProgram: isFullProgram); | 231 : writeLinkedProgram(uri, program, isFullProgram: isFullProgram); |
231 } | 232 } |
232 | 233 |
233 Future<Program> writeOutline(Uri uri) async { | 234 Future<Program> writeOutline(Uri uri, {CanonicalName nameRoot}) async { |
234 if (loader.first == null) return null; | 235 if (loader.first == null) return null; |
235 try { | 236 try { |
236 loader.createTypeInferenceEngine(); | 237 loader.createTypeInferenceEngine(); |
237 await loader.buildOutlines(); | 238 await loader.buildOutlines(); |
238 loader.coreLibrary | 239 loader.coreLibrary |
239 .becomeCoreLibrary(const DynamicType(), const VoidType()); | 240 .becomeCoreLibrary(const DynamicType(), const VoidType()); |
240 dynamicType.bind(loader.coreLibrary["dynamic"]); | 241 dynamicType.bind(loader.coreLibrary["dynamic"]); |
241 loader.resolveParts(); | 242 loader.resolveParts(); |
242 loader.computeLibraryScopes(); | 243 loader.computeLibraryScopes(); |
243 loader.resolveTypes(); | 244 loader.resolveTypes(); |
244 loader.checkSemantics(); | 245 loader.checkSemantics(); |
245 loader.buildProgram(); | 246 loader.buildProgram(); |
246 List<SourceClassBuilder> sourceClasses = collectAllSourceClasses(); | 247 List<SourceClassBuilder> sourceClasses = collectAllSourceClasses(); |
247 installDefaultSupertypes(); | 248 installDefaultSupertypes(); |
248 installDefaultConstructors(sourceClasses); | 249 installDefaultConstructors(sourceClasses); |
249 loader.resolveConstructors(); | 250 loader.resolveConstructors(); |
250 loader.finishTypeVariables(objectClassBuilder); | 251 loader.finishTypeVariables(objectClassBuilder); |
251 program = link(new List<Library>.from(loader.libraries)); | 252 program = |
253 link(new List<Library>.from(loader.libraries), nameRoot: nameRoot); | |
252 loader.computeHierarchy(program); | 254 loader.computeHierarchy(program); |
253 loader.checkOverrides(sourceClasses); | 255 loader.checkOverrides(sourceClasses); |
254 loader.prepareInitializerInference(); | 256 loader.prepareInitializerInference(); |
255 loader.performInitializerInference(); | 257 loader.performInitializerInference(); |
256 if (uri == null) return program; | 258 if (uri == null) return program; |
257 return await writeLinkedProgram(uri, program, isFullProgram: false); | 259 return await writeLinkedProgram(uri, program, isFullProgram: false); |
258 } on InputError catch (e) { | 260 } on InputError catch (e) { |
259 return handleInputError(uri, e, isFullProgram: false); | 261 return handleInputError(uri, e, isFullProgram: false); |
260 } catch (e, s) { | 262 } catch (e, s) { |
261 return reportCrash(e, s, loader?.currentUriForCrashReporting); | 263 return reportCrash(e, s, loader?.currentUriForCrashReporting); |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
361 library.addBuilder(mainBuilder.name, mainBuilder, -1); | 363 library.addBuilder(mainBuilder.name, mainBuilder, -1); |
362 mainBuilder.body = new ExpressionStatement( | 364 mainBuilder.body = new ExpressionStatement( |
363 new Throw(new StringLiteral("${errors.join('\n')}"))); | 365 new Throw(new StringLiteral("${errors.join('\n')}"))); |
364 } | 366 } |
365 library.build(loader.coreLibrary); | 367 library.build(loader.coreLibrary); |
366 return link(<Library>[library.library]); | 368 return link(<Library>[library.library]); |
367 } | 369 } |
368 | 370 |
369 /// Creates a program by combining [libraries] with the libraries of | 371 /// Creates a program by combining [libraries] with the libraries of |
370 /// `dillTarget.loader.program`. | 372 /// `dillTarget.loader.program`. |
371 Program link(List<Library> libraries) { | 373 Program link(List<Library> libraries, {CanonicalName nameRoot}) { |
372 Map<String, Source> uriToSource = | 374 Map<String, Source> uriToSource = |
373 new Map<String, Source>.from(this.uriToSource); | 375 new Map<String, Source>.from(this.uriToSource); |
374 | 376 |
375 final Program binary = dillTarget.loader.program; | 377 libraries.addAll(dillTarget.loader.libraries); |
376 if (binary != null) { | 378 // TODO(scheglov) Should we also somehow update `uriToSource`? |
377 libraries.addAll(binary.libraries); | 379 // uriToSource.addAll(binary.uriToSource); |
ahe
2017/05/15 09:08:44
Yes. You need to update uriToSource. Otherwise the
| |
378 uriToSource.addAll(binary.uriToSource); | |
379 } | |
380 | 380 |
381 // TODO(ahe): Remove this line. Kernel seems to generate a default line map | 381 // TODO(ahe): Remove this line. Kernel seems to generate a default line map |
382 // that used when there's no fileUri on an element. Instead, ensure all | 382 // that used when there's no fileUri on an element. Instead, ensure all |
383 // elements have a fileUri. | 383 // elements have a fileUri. |
384 uriToSource[""] = new Source(<int>[0], const <int>[]); | 384 uriToSource[""] = new Source(<int>[0], const <int>[]); |
385 Program program = new Program(libraries, uriToSource); | 385 Program program = new Program( |
386 nameRoot: nameRoot, libraries: libraries, uriToSource: uriToSource); | |
386 if (loader.first != null) { | 387 if (loader.first != null) { |
387 Builder builder = loader.first.lookup("main", -1, null); | 388 Builder builder = loader.first.lookup("main", -1, null); |
388 if (builder is KernelProcedureBuilder) { | 389 if (builder is KernelProcedureBuilder) { |
389 program.mainMethod = builder.procedure; | 390 program.mainMethod = builder.procedure; |
390 } | 391 } |
391 } | 392 } |
392 if (errors.isEmpty || dillTarget.isLoaded) { | 393 if (errors.isEmpty || dillTarget.isLoaded) { |
393 runLinkTransformations(program); | 394 runLinkTransformations(program); |
394 } | 395 } |
395 ticker.logMs("Linked program"); | 396 ticker.logMs("Linked program"); |
(...skipping 322 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
718 } | 719 } |
719 for (Constructor constructor in superclass.constructors) { | 720 for (Constructor constructor in superclass.constructors) { |
720 if (constructor.name.name.isEmpty) { | 721 if (constructor.name.name.isEmpty) { |
721 return constructor.function.requiredParameterCount == 0 | 722 return constructor.function.requiredParameterCount == 0 |
722 ? constructor | 723 ? constructor |
723 : null; | 724 : null; |
724 } | 725 } |
725 } | 726 } |
726 return null; | 727 return null; |
727 } | 728 } |
OLD | NEW |