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 /// Defines the front-end API for converting source code to Dart Kernel objects. | 5 /// Defines the front-end API for converting source code to Dart Kernel objects. |
6 library front_end.kernel_generator; | 6 library front_end.kernel_generator; |
7 | 7 |
8 import 'dart:async' show Future; | 8 import 'dart:async' show Future; |
9 import 'dart:async'; | 9 import 'dart:async'; |
10 | 10 |
11 import 'package:kernel/kernel.dart' show Program; | 11 import 'package:kernel/kernel.dart' show Program; |
12 | 12 |
13 import 'compiler_options.dart'; | 13 import 'compiler_options.dart'; |
14 import 'src/base/processed_options.dart'; | 14 import 'src/base/processed_options.dart'; |
15 import 'src/fasta/fasta_codes.dart'; | 15 import 'src/fasta/fasta_codes.dart'; |
| 16 import 'src/fasta/compiler_context.dart'; |
| 17 import 'src/fasta/severity.dart'; |
16 import 'src/kernel_generator_impl.dart'; | 18 import 'src/kernel_generator_impl.dart'; |
17 | 19 |
18 /// Generates a kernel representation of the program whose main library is in | 20 /// Generates a kernel representation of the program whose main library is in |
19 /// the given [source]. | 21 /// the given [source]. |
20 /// | 22 /// |
21 /// Intended for whole program (non-modular) compilation. | 23 /// Intended for whole program (non-modular) compilation. |
22 /// | 24 /// |
23 /// Given the Uri of a file containing a program's `main` method, this function | 25 /// Given the Uri of a file containing a program's `main` method, this function |
24 /// follows `import`, `export`, and `part` declarations to discover the whole | 26 /// follows `import`, `export`, and `part` declarations to discover the whole |
25 /// program, and converts the result to Dart Kernel format. | 27 /// program, and converts the result to Dart Kernel format. |
26 /// | 28 /// |
27 /// If `compileSdk` in [options] is true, the generated program will include | 29 /// If `compileSdk` in [options] is true, the generated program will include |
28 /// code for the SDK. | 30 /// code for the SDK. |
29 /// | 31 /// |
30 /// If summaries are provided in [options], the compiler will use them instead | 32 /// If summaries are provided in [options], the compiler will use them instead |
31 /// of compiling the libraries contained in those summaries. This is useful, for | 33 /// of compiling the libraries contained in those summaries. This is useful, for |
32 /// example, when compiling for platforms that already embed those sources (like | 34 /// example, when compiling for platforms that already embed those sources (like |
33 /// the sdk in the standalone VM). | 35 /// the sdk in the standalone VM). |
34 /// | 36 /// |
35 /// The input [source] is expected to be a script with a main method, otherwise | 37 /// The input [source] is expected to be a script with a main method, otherwise |
36 /// an error is reported. | 38 /// an error is reported. |
37 // TODO(sigmund): rename to kernelForScript? | 39 // TODO(sigmund): rename to kernelForScript? |
38 Future<Program> kernelForProgram(Uri source, CompilerOptions options) async { | 40 Future<Program> kernelForProgram(Uri source, CompilerOptions options) async { |
39 var pOptions = new ProcessedOptions(options, false, [source]); | 41 var pOptions = new ProcessedOptions(options, false, [source]); |
40 var program = (await generateKernel(pOptions))?.program; | 42 return await CompilerContext.runWithOptions(pOptions, (context) async { |
41 if (program == null) return null; | 43 var program = (await generateKernelInternal())?.program; |
| 44 if (program == null) return null; |
42 | 45 |
43 if (program.mainMethod == null) { | 46 if (program.mainMethod == null) { |
44 pOptions.reportMessage(messageMissingMain.withLocation(source, -1)); | 47 context.options |
45 return null; | 48 .report(messageMissingMain.withLocation(source, -1), Severity.error); |
46 } | 49 return null; |
47 | 50 } |
48 return program; | 51 return program; |
| 52 }); |
49 } | 53 } |
50 | 54 |
51 /// Generates a kernel representation for a build unit containing [sources]. | 55 /// Generates a kernel representation for a build unit containing [sources]. |
52 /// | 56 /// |
53 /// A build unit is a collection of libraries that are compiled together. | 57 /// A build unit is a collection of libraries that are compiled together. |
54 /// Libraries in the build unit may depend on each other and may have | 58 /// Libraries in the build unit may depend on each other and may have |
55 /// dependencies to libraries in other build units. Unlinke library | 59 /// dependencies to libraries in other build units. Unlinke library |
56 /// dependencies, build unit dependencies must be acyclic. | 60 /// dependencies, build unit dependencies must be acyclic. |
57 /// | 61 /// |
58 /// This API is intended for modular compilation. Dependencies to other build | 62 /// This API is intended for modular compilation. Dependencies to other build |
(...skipping 16 matching lines...) Expand all Loading... |
75 /// is not permitted to refer to a part file declared in another build unit). | 79 /// is not permitted to refer to a part file declared in another build unit). |
76 /// | 80 /// |
77 /// The return value is a [Program] object with no main method set. The | 81 /// The return value is a [Program] object with no main method set. The |
78 /// [Program] includes external libraries for those libraries loaded through | 82 /// [Program] includes external libraries for those libraries loaded through |
79 /// summaries. | 83 /// summaries. |
80 Future<Program> kernelForBuildUnit( | 84 Future<Program> kernelForBuildUnit( |
81 List<Uri> sources, CompilerOptions options) async { | 85 List<Uri> sources, CompilerOptions options) async { |
82 return (await generateKernel(new ProcessedOptions(options, true, sources))) | 86 return (await generateKernel(new ProcessedOptions(options, true, sources))) |
83 ?.program; | 87 ?.program; |
84 } | 88 } |
OLD | NEW |