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