| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 compiler; | 5 library compiler; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 import 'package:package_config/packages.dart'; | |
| 9 import 'src/apiimpl.dart'; | 8 import 'src/apiimpl.dart'; |
| 10 | 9 |
| 11 // Unless explicitly allowed, passing [:null:] for any argument to the | 10 // Unless explicitly allowed, passing [:null:] for any argument to the |
| 12 // methods of library will result in an Error being thrown. | 11 // methods of library will result in an Error being thrown. |
| 13 | 12 |
| 14 /** | 13 /** |
| 15 * Returns a future that completes to the source corresponding to [uri]. | 14 * Returns a future that completes to the source corresponding to [uri]. |
| 16 * If an exception occurs, the future completes with this exception. | 15 * If an exception occurs, the future completes with this exception. |
| 17 * | 16 * |
| 18 * The source can be represented either as a [:List<int>:] of UTF-8 bytes or as | 17 * The source can be represented either as a [:List<int>:] of UTF-8 bytes or as |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 52 */ | 51 */ |
| 53 typedef EventSink<String> CompilerOutputProvider(String name, | 52 typedef EventSink<String> CompilerOutputProvider(String name, |
| 54 String extension); | 53 String extension); |
| 55 | 54 |
| 56 /** | 55 /** |
| 57 * Invoked by the compiler to report diagnostics. If [uri] is | 56 * Invoked by the compiler to report diagnostics. If [uri] is |
| 58 * [:null:], so are [begin] and [end]. No other arguments may be | 57 * [:null:], so are [begin] and [end]. No other arguments may be |
| 59 * [:null:]. If [uri] is not [:null:], neither are [begin] and | 58 * [:null:]. If [uri] is not [:null:], neither are [begin] and |
| 60 * [end]. [uri] indicates the compilation unit from where the | 59 * [end]. [uri] indicates the compilation unit from where the |
| 61 * diagnostic originates. [begin] and [end] are zero-based character | 60 * diagnostic originates. [begin] and [end] are zero-based character |
| 62 * offsets from the beginning of the compilation unit. [message] is the | 61 * offsets from the beginning of the compilaton unit. [message] is the |
| 63 * diagnostic message, and [kind] indicates indicates what kind of | 62 * diagnostic message, and [kind] indicates indicates what kind of |
| 64 * diagnostic it is. | 63 * diagnostic it is. |
| 65 */ | 64 */ |
| 66 typedef void DiagnosticHandler(Uri uri, int begin, int end, | 65 typedef void DiagnosticHandler(Uri uri, int begin, int end, |
| 67 String message, Diagnostic kind); | 66 String message, Diagnostic kind); |
| 68 | 67 |
| 69 /** | |
| 70 * Provides a package lookup mechanism in the case that no package root or | |
| 71 * package resolution configuration file are explicitly specified. | |
| 72 */ | |
| 73 typedef Future<Packages> PackagesDiscoveryProvider(Uri uri); | |
| 74 | |
| 75 /// Information resulting from the compilation. | 68 /// Information resulting from the compilation. |
| 76 class CompilationResult { | 69 class CompilationResult { |
| 77 /// `true` if the compilation succeeded, that is, compilation didn't fail due | 70 /// `true` if the compilation succeeded, that is, compilation didn't fail due |
| 78 /// to compile-time errors and/or internal errors. | 71 /// to compile-time errors and/or internal errors. |
| 79 final bool isSuccess; | 72 final bool isSuccess; |
| 80 | 73 |
| 81 /// The compiler object used for the compilation. | 74 /// The compiler object used for the compilation. |
| 82 /// | 75 /// |
| 83 /// Note: The type of [compiler] is implementation dependent and may vary. | 76 /// Note: The type of [compiler] is implementation dependent and may vary. |
| 84 /// Use only for debugging and testing. | 77 /// Use only for debugging and testing. |
| (...skipping 18 matching lines...) Expand all Loading... |
| 103 * of libraries. | 96 * of libraries. |
| 104 */ | 97 */ |
| 105 Future<CompilationResult> compile( | 98 Future<CompilationResult> compile( |
| 106 Uri script, | 99 Uri script, |
| 107 Uri libraryRoot, | 100 Uri libraryRoot, |
| 108 Uri packageRoot, | 101 Uri packageRoot, |
| 109 CompilerInputProvider inputProvider, | 102 CompilerInputProvider inputProvider, |
| 110 DiagnosticHandler handler, | 103 DiagnosticHandler handler, |
| 111 [List<String> options = const [], | 104 [List<String> options = const [], |
| 112 CompilerOutputProvider outputProvider, | 105 CompilerOutputProvider outputProvider, |
| 113 Map<String, dynamic> environment = const {}, | 106 Map<String, dynamic> environment = const {}]) { |
| 114 Uri packageConfig, | |
| 115 PackagesDiscoveryProvider packagesDiscoveryProvider]) { | |
| 116 if (!libraryRoot.path.endsWith("/")) { | 107 if (!libraryRoot.path.endsWith("/")) { |
| 117 throw new ArgumentError("libraryRoot must end with a /"); | 108 throw new ArgumentError("libraryRoot must end with a /"); |
| 118 } | 109 } |
| 119 if (packageRoot != null && !packageRoot.path.endsWith("/")) { | 110 if (packageRoot != null && !packageRoot.path.endsWith("/")) { |
| 120 throw new ArgumentError("packageRoot must end with a /"); | 111 throw new ArgumentError("packageRoot must end with a /"); |
| 121 } | 112 } |
| 122 // TODO(ahe): Consider completing the future with an exception if | 113 // TODO(ahe): Consider completing the future with an exception if |
| 123 // code is null. | 114 // code is null. |
| 124 Compiler compiler = new Compiler(inputProvider, | 115 Compiler compiler = new Compiler(inputProvider, |
| 125 outputProvider, | 116 outputProvider, |
| 126 handler, | 117 handler, |
| 127 libraryRoot, | 118 libraryRoot, |
| 128 packageRoot, | 119 packageRoot, |
| 129 options, | 120 options, |
| 130 environment, | 121 environment); |
| 131 packageConfig, | |
| 132 packagesDiscoveryProvider); | |
| 133 return compiler.run(script).then((bool success) { | 122 return compiler.run(script).then((bool success) { |
| 134 return new CompilationResult(compiler, isSuccess: success); | 123 return new CompilationResult(compiler, isSuccess: success); |
| 135 }); | 124 }); |
| 136 } | 125 } |
| 137 | 126 |
| 138 /** | 127 /** |
| 139 * Kind of diagnostics that the compiler can report. | 128 * Kind of diagnostics that the compiler can report. |
| 140 */ | 129 */ |
| 141 class Diagnostic { | 130 class Diagnostic { |
| 142 /** | 131 /** |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 200 final String name; | 189 final String name; |
| 201 | 190 |
| 202 /** | 191 /** |
| 203 * This constructor is not private to support user-defined | 192 * This constructor is not private to support user-defined |
| 204 * diagnostic kinds. | 193 * diagnostic kinds. |
| 205 */ | 194 */ |
| 206 const Diagnostic(this.ordinal, this.name); | 195 const Diagnostic(this.ordinal, this.name); |
| 207 | 196 |
| 208 String toString() => name; | 197 String toString() => name; |
| 209 } | 198 } |
| OLD | NEW |