| 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/kernel_generator_impl.dart'; | 16 import 'src/kernel_generator_impl.dart'; |
| 16 | 17 |
| 17 /// Generates a kernel representation of the program whose main library is in | 18 /// Generates a kernel representation of the program whose main library is in |
| 18 /// the given [source]. | 19 /// the given [source]. |
| 19 /// | 20 /// |
| 20 /// Intended for whole program (non-modular) compilation. | 21 /// Intended for whole program (non-modular) compilation. |
| 21 /// | 22 /// |
| 22 /// Given the Uri of a file containing a program's `main` method, this function | 23 /// Given the Uri of a file containing a program's `main` method, this function |
| 23 /// follows `import`, `export`, and `part` declarations to discover the whole | 24 /// follows `import`, `export`, and `part` declarations to discover the whole |
| 24 /// program, and converts the result to Dart Kernel format. | 25 /// program, and converts the result to Dart Kernel format. |
| 25 /// | 26 /// |
| 26 /// If `compileSdk` in [options] is true, the generated program will include | 27 /// If `compileSdk` in [options] is true, the generated program will include |
| 27 /// code for the SDK. | 28 /// code for the SDK. |
| 28 /// | 29 /// |
| 29 /// If summaries are provided in [options], the compiler will use them instead | 30 /// If summaries are provided in [options], the compiler will use them instead |
| 30 /// of compiling the libraries contained in those summaries. This is useful, for | 31 /// of compiling the libraries contained in those summaries. This is useful, for |
| 31 /// example, when compiling for platforms that already embed those sources (like | 32 /// example, when compiling for platforms that already embed those sources (like |
| 32 /// the sdk in the standalone VM). | 33 /// the sdk in the standalone VM). |
| 33 /// | 34 /// |
| 34 /// The input [source] is expected to be a script with a main method, otherwise | 35 /// The input [source] is expected to be a script with a main method, otherwise |
| 35 /// an error is reported. | 36 /// an error is reported. |
| 36 // TODO(sigmund): rename to kernelForScript? | 37 // TODO(sigmund): rename to kernelForScript? |
| 37 Future<Program> kernelForProgram(Uri source, CompilerOptions options) async { | 38 Future<Program> kernelForProgram(Uri source, CompilerOptions options) async { |
| 38 var pOptions = new ProcessedOptions(options, false, [source]); | 39 var pOptions = new ProcessedOptions(options, false, [source]); |
| 39 var program = (await generateKernel(pOptions))?.program; | 40 var program = (await generateKernel(pOptions))?.program; |
| 40 if (program == null) return null; | 41 if (program == null) return null; |
| 41 | 42 |
| 42 if (program.mainMethod == null) { | 43 if (program.mainMethod == null) { |
| 43 pOptions.reportError("No 'main' method found."); | 44 pOptions.reportMessage(messageMissingMain.withLocation(source, -1)); |
| 44 return null; | 45 return null; |
| 45 } | 46 } |
| 46 | 47 |
| 47 return program; | 48 return program; |
| 48 } | 49 } |
| 49 | 50 |
| 50 /// Generates a kernel representation for a build unit containing [sources]. | 51 /// Generates a kernel representation for a build unit containing [sources]. |
| 51 /// | 52 /// |
| 52 /// A build unit is a collection of libraries that are compiled together. | 53 /// A build unit is a collection of libraries that are compiled together. |
| 53 /// Libraries in the build unit may depend on each other and may have | 54 /// Libraries in the build unit may depend on each other and may have |
| (...skipping 20 matching lines...) Expand all Loading... |
| 74 /// is not permitted to refer to a part file declared in another build unit). | 75 /// is not permitted to refer to a part file declared in another build unit). |
| 75 /// | 76 /// |
| 76 /// The return value is a [Program] object with no main method set. The | 77 /// The return value is a [Program] object with no main method set. The |
| 77 /// [Program] includes external libraries for those libraries loaded through | 78 /// [Program] includes external libraries for those libraries loaded through |
| 78 /// summaries. | 79 /// summaries. |
| 79 Future<Program> kernelForBuildUnit( | 80 Future<Program> kernelForBuildUnit( |
| 80 List<Uri> sources, CompilerOptions options) async { | 81 List<Uri> sources, CompilerOptions options) async { |
| 81 return (await generateKernel(new ProcessedOptions(options, true, sources))) | 82 return (await generateKernel(new ProcessedOptions(options, true, sources))) |
| 82 ?.program; | 83 ?.program; |
| 83 } | 84 } |
| OLD | NEW |