Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(71)

Side by Side Diff: pkg/compiler/lib/compiler_new.dart

Issue 1803303002: Move all flags to CompilerOptions (first step to stop passing the compiler to (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « pkg/compiler/lib/compiler.dart ('k') | pkg/compiler/lib/src/apiimpl.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2015, 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 /// New Compiler API. This API is under construction, use only internally or 5 /// New Compiler API. This API is under construction, use only internally or
6 /// in unittests. 6 /// in unittests.
7 7
8 library compiler_new; 8 library compiler_new;
9 9
10 import 'dart:async'; 10 import 'dart:async';
11 import 'src/apiimpl.dart'; 11 import 'src/apiimpl.dart';
12 import 'src/commandline_options.dart';
13 import 'src/diagnostics/diagnostic_listener.dart' show DiagnosticOptions;
14
12 import 'compiler.dart' show Diagnostic, PackagesDiscoveryProvider; 15 import 'compiler.dart' show Diagnostic, PackagesDiscoveryProvider;
13 export 'compiler.dart' show Diagnostic, PackagesDiscoveryProvider; 16 export 'compiler.dart' show Diagnostic, PackagesDiscoveryProvider;
14 17
15 // Unless explicitly allowed, passing `null` for any argument to the 18 // Unless explicitly allowed, passing `null` for any argument to the
16 // methods of library will result in an Error being thrown. 19 // methods of library will result in an Error being thrown.
17 20
18 /// Interface for providing the compiler with input. That is, Dart source files, 21 /// Interface for providing the compiler with input. That is, Dart source files,
19 /// package config files, etc. 22 /// package config files, etc.
20 abstract class CompilerInput { 23 abstract class CompilerInput {
21 /// Returns a future that completes to the source corresponding to [uri]. 24 /// Returns a future that completes to the source corresponding to [uri].
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 /// [begin] and [end]. No other arguments may be `null`. If [uri] is not 67 /// [begin] and [end]. No other arguments may be `null`. If [uri] is not
65 /// `null`, neither are [begin] and [end]. [uri] indicates the compilation 68 /// `null`, neither are [begin] and [end]. [uri] indicates the compilation
66 /// unit from where the diagnostic originates. [begin] and [end] are 69 /// unit from where the diagnostic originates. [begin] and [end] are
67 /// zero-based character offsets from the beginning of the compilation unit. 70 /// zero-based character offsets from the beginning of the compilation unit.
68 /// [message] is the diagnostic message, and [kind] indicates indicates what 71 /// [message] is the diagnostic message, and [kind] indicates indicates what
69 /// kind of diagnostic it is. 72 /// kind of diagnostic it is.
70 /// 73 ///
71 /// Experimental: [code] gives access to an id for the messages. Currently it 74 /// Experimental: [code] gives access to an id for the messages. Currently it
72 /// is the [Message] used to create the diagnostic, if available, from which 75 /// is the [Message] used to create the diagnostic, if available, from which
73 /// the [MessageKind] is accessible. 76 /// the [MessageKind] is accessible.
74 void report(var code, 77 void report(
75 Uri uri, int begin, int end, String text, Diagnostic kind); 78 var code, Uri uri, int begin, int end, String text, Diagnostic kind);
76 } 79 }
77 80
78 /// Information resulting from the compilation. 81 /// Information resulting from the compilation.
79 class CompilationResult { 82 class CompilationResult {
80 /// `true` if the compilation succeeded, that is, compilation didn't fail due 83 /// `true` if the compilation succeeded, that is, compilation didn't fail due
81 /// to compile-time errors and/or internal errors. 84 /// to compile-time errors and/or internal errors.
82 final bool isSuccess; 85 final bool isSuccess;
83 86
84 /// The compiler object used for the compilation. 87 /// The compiler object used for the compilation.
85 /// 88 ///
86 /// Note: The type of [compiler] is implementation dependent and may vary. 89 /// Note: The type of [compiler] is implementation dependent and may vary.
87 /// Use only for debugging and testing. 90 /// Use only for debugging and testing.
88 final compiler; 91 final compiler;
89 92
90 CompilationResult(this.compiler, {this.isSuccess: true}); 93 CompilationResult(this.compiler, {this.isSuccess: true});
91 } 94 }
92 95
93 /// Object for passing options to the compiler. 96 /// Object for passing options to the compiler.
94 class CompilerOptions { 97 class CompilerOptions {
98 /// The entry point of the application that is being compiled.
95 final Uri entryPoint; 99 final Uri entryPoint;
100
101 /// Root location where SDK libraries are found.
96 final Uri libraryRoot; 102 final Uri libraryRoot;
103
104 /// Package root location.
105 ///
106 /// If not null then [packageConfig] should be null.
97 final Uri packageRoot; 107 final Uri packageRoot;
108
109 /// Location of the package configuration file.
110 ///
111 /// If not null then [packageRoot] should be null.
98 final Uri packageConfig; 112 final Uri packageConfig;
113
114 // TODO(sigmund): Move out of here, maybe to CompilerInput. Options should not
115 // hold code, just configuration options.
99 final PackagesDiscoveryProvider packagesDiscoveryProvider; 116 final PackagesDiscoveryProvider packagesDiscoveryProvider;
100 final List<String> options; 117
118 /// Resolved constant "environment" values passed to the compiler via the `-D`
119 /// flags.
101 final Map<String, dynamic> environment; 120 final Map<String, dynamic> environment;
102 121
122 /// Whether we allow mocking compilation of libraries such as dart:io and
123 /// dart:html for unit testing purposes.
124 final bool allowMockCompilation;
125
126 /// Whether the native extension syntax is supported by the frontend.
127 final bool allowNativeExtensions;
128
129 /// Whether to resolve all functions in the program, not just those reachable
130 /// from main. This implies [analyzeOnly] is true as well.
131 final bool analyzeAll;
132
133 /// Whether to disable tree-shaking for the main script. This marks all
134 /// functions in the main script as reachable (not just a function named
135 /// `main`).
136 // TODO(sigmund): rename. The current name seems to indicate that only the
137 // main function is retained, which is the opposite of what this does.
138 final bool analyzeMain;
139
140 /// Whether to run the compiler just for the purpose of analysis. That is, to
141 /// run resolution and type-checking alone, but otherwise do not generate any
142 /// code.
143 final bool analyzeOnly;
144
145 /// Whether to skip analysis of method bodies and field initializers. Implies
146 /// [analyzeOnly].
147 final bool analyzeSignaturesOnly;
148
149 /// ID associated with this sdk build.
150 final String buildId;
151
152 /// Whether there is a build-id available so we can use it on error messages
153 /// and in the emitted output of the compiler.
154 bool get hasBuildId => buildId != _UNDETERMINED_BUILD_ID;
155
156 /// Location where to generate a map containing details of how deferred
157 /// libraries are subdivided.
158 final Uri deferredMapUri;
159
160 /// Whether to disable inlining during the backend optimizations.
161 // TODO(sigmund): negate, so all flags are positive
162 final bool disableInlining;
163
164 /// Several options to configure diagnostic messages.
165 // TODO(sigmund): should we simply embed those options here?
166 final DiagnosticOptions diagnosticOptions;
167
168 /// Whether to disable global type inference.
169 final bool disableTypeInference;
170
171 /// Whether to emit a .json file with a summary of the information used by the
172 /// compiler during optimization. This includes resolution details,
173 /// dependencies between elements, results of type inference, and the output
174 /// code for each function.
175 final bool dumpInfo;
176
177 /// Whether we allow passing an extra argument to `assert`, containing a
178 /// reason for why an assertion fails. (experimental)
179 final bool enableAssertMessage;
180
181 /// Whether to enable the experimental conditional directives feature.
182 final bool enableConditionalDirectives;
183
184 /// Whether the user specified a flag to allow the use of dart:mirrors. This
185 /// silences a warning produced by the compiler.
186 final bool enableExperimentalMirrors;
187
188 /// Whether to enable minification
189 // TODO(sigmund): rename to minify
190 final bool enableMinification;
191
192 /// Whether to model which native classes are live based on annotations on the
193 /// core libraries. If false, all native classes will be included by default.
194 final bool enableNativeLiveTypeAnalysis;
195
196 /// Whether to generate code containing checked-mode assignability checks.
197 final bool enableTypeAssertions;
198
199 /// Whether to generate code containing user's `assert` statements.
200 final bool enableUserAssertions;
201
202 /// Whether to generate output even when there are compile-time errors.
203 final bool generateCodeWithCompileTimeErrors;
204
205 /// Whether to generate a source-map file together with the output program.
206 final bool generateSourceMap;
207
208 /// Whether some values are cached for reuse in incremental compilation.
209 /// Incremental compilation allows calling `Compiler.run` more than once
210 /// (experimental).
211 final bool hasIncrementalSupport;
212
213 /// URI of the main output if the compiler is generating source maps.
214 final Uri outputUri;
215
216 /// Location of the platform configuration file.
217 final Uri platformConfigUri;
218
219 /// Whether to emit URIs in the reflection metadata.
220 final bool preserveUris;
221
222 /// URI where the compiler should generate the output source map file.
223 final Uri sourceMapUri;
224
225 /// The compiler is run from the build bot.
226 final bool testMode;
227
228 /// Whether to trust JS-interop annotations. (experimental)
229 final bool trustJSInteropTypeAnnotations;
230
231 /// Whether to trust primitive types during inference and optimizations.
232 final bool trustPrimitives;
233
234 /// Whether to trust type annotations during inference and optimizations.
235 final bool trustTypeAnnotations;
236
237 /// Whether to generate code compliant with content security policy (CSP).
238 final bool useContentSecurityPolicy;
239
240 /// Use the experimental CPS based backend.
241 final bool useCpsIr;
242
243 /// When obfuscating for minification, whether to use the frequency of a name
244 /// as an heuristic to pick shorter names.
245 final bool useFrequencyNamer;
246
247 /// Whether to use the new source-information implementation for source-maps.
248 /// (experimental)
249 final bool useNewSourceInfo;
250
251 /// Whether the user requested to use the fast startup emitter. The full
252 /// emitter might still be used if the program uses dart:mirrors.
253 final bool useStartupEmitter;
254
255 /// Enable verbose printing during compilation. Includes progress messages
256 /// during each phase and a time-breakdown between phases at the end.
257 final bool verbose;
258
259
260 // -------------------------------------------------
261 // Options for deprecated features
262 // -------------------------------------------------
263 // TODO(sigmund): delete these as we delete the underlying features
264
265 /// Whether to preserve comments while scanning (only use for dart:mirrors).
266 final bool preserveComments;
267
268 /// Whether to emit JavaScript (false enables dart2dart).
269 final bool emitJavaScript;
270
271 /// When using dart2dart, whether to use the multi file format.
272 final bool dart2dartMultiFile;
273
274 /// Strip option used by dart2dart.
275 final List<String> strips;
276
277 /// Create an options object by parsing flags from [options].
278 factory CompilerOptions.parse(
279 {Uri entryPoint,
280 Uri libraryRoot,
281 Uri packageRoot,
282 Uri packageConfig,
283 PackagesDiscoveryProvider packagesDiscoveryProvider,
284 Map<String, dynamic> environment: const <String, dynamic>{},
285 List<String> options}) {
286 return new CompilerOptions(
287 entryPoint: entryPoint,
288 libraryRoot: libraryRoot,
289 packageRoot: packageRoot,
290 packageConfig: packageConfig,
291 packagesDiscoveryProvider: packagesDiscoveryProvider,
292 environment: environment,
293 allowMockCompilation: _hasOption(options, Flags.allowMockCompilation),
294 allowNativeExtensions: _hasOption(options, Flags.allowNativeExtensions),
295 analyzeAll: _hasOption(options, Flags.analyzeAll),
296 analyzeMain: _hasOption(options, Flags.analyzeMain),
297 analyzeOnly: _hasOption(options, Flags.analyzeOnly),
298 analyzeSignaturesOnly: _hasOption(options, Flags.analyzeSignaturesOnly),
299 buildId: _extractStringOption(
300 options, '--build-id=', _UNDETERMINED_BUILD_ID),
301 dart2dartMultiFile: _hasOption(options, '--output-type=dart-multi'),
302 deferredMapUri: _extractUriOption(options, '--deferred-map='),
303 diagnosticOptions: new DiagnosticOptions(
304 suppressWarnings: _hasOption(options, Flags.suppressWarnings),
305 fatalWarnings: _hasOption(options, Flags.fatalWarnings),
306 suppressHints: _hasOption(options, Flags.suppressHints),
307 terseDiagnostics: _hasOption(options, Flags.terse),
308 shownPackageWarnings:
309 _extractOptionalCsvOption(options, Flags.showPackageWarnings)),
310 disableInlining: _hasOption(options, Flags.disableInlining),
311 disableTypeInference: _hasOption(options, Flags.disableTypeInference),
312 dumpInfo: _hasOption(options, Flags.dumpInfo),
313 emitJavaScript: !(_hasOption(options, '--output-type=dart') ||
314 _hasOption(options, '--output-type=dart-multi')),
315 enableAssertMessage: _hasOption(options, Flags.enableAssertMessage),
316 enableConditionalDirectives:
317 _hasOption(options, Flags.conditionalDirectives),
318 enableExperimentalMirrors:
319 _hasOption(options, Flags.enableExperimentalMirrors),
320 enableMinification: _hasOption(options, Flags.minify),
321 enableNativeLiveTypeAnalysis:
322 !_hasOption(options, Flags.disableNativeLiveTypeAnalysis),
323 enableTypeAssertions: _hasOption(options, Flags.enableCheckedMode),
324 enableUserAssertions: _hasOption(options, Flags.enableCheckedMode),
325 generateCodeWithCompileTimeErrors:
326 _hasOption(options, Flags.generateCodeWithCompileTimeErrors),
327 generateSourceMap: !_hasOption(options, Flags.noSourceMaps),
328 hasIncrementalSupport: _forceIncrementalSupport ||
329 _hasOption(options, Flags.incrementalSupport),
330 outputUri: _extractUriOption(options, '--out='),
331 platformConfigUri: _resolvePlatformConfigFromOptions(
332 libraryRoot, options),
333 preserveComments: _hasOption(options, Flags.preserveComments),
334 preserveUris: _hasOption(options, Flags.preserveUris),
335 sourceMapUri: _extractUriOption(options, '--source-map='),
336 strips: _extractCsvOption(options, '--force-strip='),
337 testMode: _hasOption(options, Flags.testMode),
338 trustJSInteropTypeAnnotations:
339 _hasOption(options, Flags.trustJSInteropTypeAnnotations),
340 trustPrimitives: _hasOption(options, Flags.trustPrimitives),
341 trustTypeAnnotations: _hasOption(options, Flags.trustTypeAnnotations),
342 useContentSecurityPolicy:
343 _hasOption(options, Flags.useContentSecurityPolicy),
344 useCpsIr: _hasOption(options, Flags.useCpsIr),
345 useFrequencyNamer:
346 !_hasOption(options, Flags.noFrequencyBasedMinification),
347 useNewSourceInfo: _hasOption(options, Flags.useNewSourceInfo),
348 useStartupEmitter: _hasOption(options, Flags.fastStartup),
349 verbose: _hasOption(options, Flags.verbose));
350 }
351
103 /// Creates an option object for the compiler. 352 /// Creates an option object for the compiler.
104 // TODO(johnniwinther): Expand comment when [options] are explicit as named 353 ///
105 // arguments. 354 /// This validates and normalizes dependent options to be consistent. For
355 /// example, if [analyzeAll] is true, the resulting options object will also
356 /// have [analyzeOnly] as true.
106 factory CompilerOptions( 357 factory CompilerOptions(
107 {Uri entryPoint, 358 {Uri entryPoint,
108 Uri libraryRoot, 359 Uri libraryRoot,
109 Uri packageRoot, 360 Uri packageRoot,
110 Uri packageConfig, 361 Uri packageConfig,
111 PackagesDiscoveryProvider packagesDiscoveryProvider, 362 PackagesDiscoveryProvider packagesDiscoveryProvider,
112 List<String> options: const <String>[], 363 Map<String, dynamic> environment: const <String, dynamic>{},
113 Map<String, dynamic> environment: const <String, dynamic>{}}) { 364 bool allowMockCompilation: false,
114 if (entryPoint == null) { 365 bool allowNativeExtensions: false,
115 throw new ArgumentError("entryPoint must be non-null"); 366 bool analyzeAll: false,
367 bool analyzeMain: false,
368 bool analyzeOnly: false,
369 bool analyzeSignaturesOnly: false,
370 String buildId: _UNDETERMINED_BUILD_ID,
371 bool dart2dartMultiFile: false,
372 Uri deferredMapUri: null,
373 DiagnosticOptions diagnosticOptions: const DiagnosticOptions(),
374 bool disableInlining: false,
375 bool disableTypeInference: false,
376 bool dumpInfo: false,
377 bool emitJavaScript: true,
378 bool enableAssertMessage: false,
379 bool enableConditionalDirectives: false,
380 bool enableExperimentalMirrors: false,
381 bool enableMinification: false,
382 bool enableNativeLiveTypeAnalysis: true,
383 bool enableTypeAssertions: false,
384 bool enableUserAssertions: false,
385 bool generateCodeWithCompileTimeErrors: false,
386 bool generateSourceMap: true,
387 bool hasIncrementalSupport: false,
388 Uri outputUri: null,
389 Uri platformConfigUri: null,
390 bool preserveComments: false,
391 bool preserveUris: false,
392 Uri sourceMapUri: null,
393 List<String> strips: const [],
394 bool testMode: false,
395 bool trustJSInteropTypeAnnotations: false,
396 bool trustPrimitives: false,
397 bool trustTypeAnnotations: false,
398 bool useContentSecurityPolicy: false,
399 bool useCpsIr: false,
400 bool useFrequencyNamer: true,
401 bool useNewSourceInfo: false,
402 bool useStartupEmitter: false,
403 bool verbose: false}) {
404 // TODO(sigmund): should entrypoint be here? should we validate it is not
405 // null? In unittests we use the same compiler to analyze or build multiple
406 // entrypoints.
407 if (libraryRoot == null) {
408 throw new ArgumentError("[libraryRoot] is null.");
116 } 409 }
117 if (!libraryRoot.path.endsWith("/")) { 410 if (!libraryRoot.path.endsWith("/")) {
118 throw new ArgumentError("libraryRoot must end with a /"); 411 throw new ArgumentError("[libraryRoot] must end with a /");
412 }
413 if (packageRoot != null && packageConfig != null) {
414 throw new ArgumentError("Only one of [packageRoot] or [packageConfig] "
415 "may be given.");
119 } 416 }
120 if (packageRoot != null && !packageRoot.path.endsWith("/")) { 417 if (packageRoot != null && !packageRoot.path.endsWith("/")) {
121 throw new ArgumentError("packageRoot must end with a /"); 418 throw new ArgumentError("[packageRoot] must end with a /");
122 } 419 }
123 return new CompilerOptions._( 420 if (!analyzeOnly) {
124 entryPoint, 421 if (allowNativeExtensions) {
125 libraryRoot, 422 throw new ArgumentError(
126 packageRoot, 423 "${Flags.allowNativeExtensions} is only supported in combination "
127 packageConfig, 424 "with ${Flags.analyzeOnly}");
128 packagesDiscoveryProvider, 425 }
129 options, 426 }
130 environment); 427 return new CompilerOptions._(entryPoint, libraryRoot, packageRoot,
428 packageConfig, packagesDiscoveryProvider, environment,
429 allowMockCompilation: allowMockCompilation,
430 allowNativeExtensions: allowNativeExtensions,
431 analyzeAll: analyzeAll,
432 analyzeMain: analyzeMain,
433 analyzeOnly: analyzeOnly || analyzeSignaturesOnly || analyzeAll,
434 analyzeSignaturesOnly: analyzeSignaturesOnly,
435 buildId: buildId,
436 dart2dartMultiFile: dart2dartMultiFile,
437 deferredMapUri: deferredMapUri,
438 diagnosticOptions: diagnosticOptions,
439 disableInlining: disableInlining || hasIncrementalSupport,
440 disableTypeInference: disableTypeInference || !emitJavaScript,
441 dumpInfo: dumpInfo,
442 emitJavaScript: emitJavaScript,
443 enableAssertMessage: enableAssertMessage,
444 enableConditionalDirectives: enableConditionalDirectives,
445 enableExperimentalMirrors: enableExperimentalMirrors,
446 enableMinification: enableMinification,
447 enableNativeLiveTypeAnalysis: enableNativeLiveTypeAnalysis,
448 enableTypeAssertions: enableTypeAssertions,
449 enableUserAssertions: enableUserAssertions,
450 generateCodeWithCompileTimeErrors: generateCodeWithCompileTimeErrors,
451 generateSourceMap: generateSourceMap,
452 hasIncrementalSupport: hasIncrementalSupport,
453 outputUri: outputUri,
454 platformConfigUri: platformConfigUri ?? _resolvePlatformConfig(
455 libraryRoot, null, !emitJavaScript, const []),
456 preserveComments: preserveComments,
457 preserveUris: preserveUris,
458 sourceMapUri: sourceMapUri,
459 strips: strips,
460 testMode: testMode,
461 trustJSInteropTypeAnnotations: trustJSInteropTypeAnnotations,
462 trustPrimitives: trustPrimitives,
463 trustTypeAnnotations: trustTypeAnnotations,
464 useContentSecurityPolicy: useContentSecurityPolicy,
465 useCpsIr: useCpsIr,
466 useFrequencyNamer: useFrequencyNamer,
467 useNewSourceInfo: useNewSourceInfo,
468 useStartupEmitter: useStartupEmitter,
469 verbose: verbose);
131 } 470 }
132 471
133 CompilerOptions._( 472 CompilerOptions._(this.entryPoint, this.libraryRoot, this.packageRoot,
134 this.entryPoint, 473 this.packageConfig, this.packagesDiscoveryProvider, this.environment,
135 this.libraryRoot, 474 {this.allowMockCompilation: false,
136 this.packageRoot, 475 this.allowNativeExtensions: false,
137 this.packageConfig, 476 this.analyzeAll: false,
138 this.packagesDiscoveryProvider, 477 this.analyzeMain: false,
139 this.options, 478 this.analyzeOnly: false,
140 this.environment); 479 this.analyzeSignaturesOnly: false,
480 this.buildId: _UNDETERMINED_BUILD_ID,
481 this.dart2dartMultiFile: false,
482 this.deferredMapUri: null,
483 this.diagnosticOptions: null,
484 this.disableInlining: false,
485 this.disableTypeInference: false,
486 this.dumpInfo: false,
487 this.emitJavaScript: true,
488 this.enableAssertMessage: false,
489 this.enableConditionalDirectives: false,
490 this.enableExperimentalMirrors: false,
491 this.enableMinification: false,
492 this.enableNativeLiveTypeAnalysis: false,
493 this.enableTypeAssertions: false,
494 this.enableUserAssertions: false,
495 this.generateCodeWithCompileTimeErrors: false,
496 this.generateSourceMap: true,
497 this.hasIncrementalSupport: false,
498 this.outputUri: null,
499 this.platformConfigUri: null,
500 this.preserveComments: false,
501 this.preserveUris: false,
502 this.sourceMapUri: null,
503 this.strips: const [],
504 this.testMode: false,
505 this.trustJSInteropTypeAnnotations: false,
506 this.trustPrimitives: false,
507 this.trustTypeAnnotations: false,
508 this.useContentSecurityPolicy: false,
509 this.useCpsIr: false,
510 this.useFrequencyNamer: false,
511 this.useNewSourceInfo: false,
512 this.useStartupEmitter: false,
513 this.verbose: false});
141 } 514 }
142 515
143 /// Returns a future that completes to a [CompilationResult] when the Dart 516 /// Returns a future that completes to a [CompilationResult] when the Dart
144 /// sources in [options] have been compiled. 517 /// sources in [options] have been compiled.
145 /// 518 ///
146 /// The generated compiler output is obtained by providing a [compilerOutput]. 519 /// The generated compiler output is obtained by providing a [compilerOutput].
147 /// 520 ///
148 /// If the compilation fails, the future's `CompilationResult.isSuccess` is 521 /// If the compilation fails, the future's `CompilationResult.isSuccess` is
149 /// `false` and [CompilerDiagnostics.report] on [compilerDiagnostics] 522 /// `false` and [CompilerDiagnostics.report] on [compilerDiagnostics]
150 /// is invoked at least once with `kind == Diagnostic.ERROR` or 523 /// is invoked at least once with `kind == Diagnostic.ERROR` or
151 /// `kind == Diagnostic.CRASH`. 524 /// `kind == Diagnostic.CRASH`.
152 Future<CompilationResult> compile( 525 Future<CompilationResult> compile(
153 CompilerOptions compilerOptions, 526 CompilerOptions compilerOptions,
154 CompilerInput compilerInput, 527 CompilerInput compilerInput,
155 CompilerDiagnostics compilerDiagnostics, 528 CompilerDiagnostics compilerDiagnostics,
156 CompilerOutput compilerOutput) { 529 CompilerOutput compilerOutput) {
157
158 if (compilerOptions == null) { 530 if (compilerOptions == null) {
159 throw new ArgumentError("compilerOptions must be non-null"); 531 throw new ArgumentError("compilerOptions must be non-null");
160 } 532 }
161 if (compilerInput == null) { 533 if (compilerInput == null) {
162 throw new ArgumentError("compilerInput must be non-null"); 534 throw new ArgumentError("compilerInput must be non-null");
163 } 535 }
164 if (compilerDiagnostics == null) { 536 if (compilerDiagnostics == null) {
165 throw new ArgumentError("compilerDiagnostics must be non-null"); 537 throw new ArgumentError("compilerDiagnostics must be non-null");
166 } 538 }
167 if (compilerOutput == null) { 539 if (compilerOutput == null) {
168 throw new ArgumentError("compilerOutput must be non-null"); 540 throw new ArgumentError("compilerOutput must be non-null");
169 } 541 }
170 542
171 CompilerImpl compiler = new CompilerImpl( 543 CompilerImpl compiler = new CompilerImpl(
172 compilerInput, 544 compilerInput, compilerOutput, compilerDiagnostics, compilerOptions);
173 compilerOutput,
174 compilerDiagnostics,
175 compilerOptions.libraryRoot,
176 compilerOptions.packageRoot,
177 compilerOptions.options,
178 compilerOptions.environment,
179 compilerOptions.packageConfig,
180 compilerOptions.packagesDiscoveryProvider);
181 return compiler.run(compilerOptions.entryPoint).then((bool success) { 545 return compiler.run(compilerOptions.entryPoint).then((bool success) {
182 return new CompilationResult(compiler, isSuccess: success); 546 return new CompilationResult(compiler, isSuccess: success);
183 }); 547 });
184 } 548 }
549
550 String _extractStringOption(
551 List<String> options, String prefix, String defaultValue) {
552 for (String option in options) {
553 if (option.startsWith(prefix)) {
554 return option.substring(prefix.length);
555 }
556 }
557 return defaultValue;
558 }
559
560 Uri _extractUriOption(List<String> options, String prefix) {
561 var option = _extractStringOption(options, prefix, null);
562 return (option == null) ? null : Uri.parse(option);
563 }
564
565 // CSV: Comma separated values.
566 List<String> _extractCsvOption(List<String> options, String prefix) {
567 for (String option in options) {
568 if (option.startsWith(prefix)) {
569 return option.substring(prefix.length).split(',');
570 }
571 }
572 return const <String>[];
573 }
574
575 /// Extract list of comma separated values provided for [flag]. Returns an
576 /// empty list if [option] contain [flag] without arguments. Returns `null` if
577 /// [option] doesn't contain [flag] with or without arguments.
578 List<String> _extractOptionalCsvOption(List<String> options, String flag) {
579 String prefix = '$flag=';
580 for (String option in options) {
581 if (option == flag) {
582 return const <String>[];
583 }
584 if (option.startsWith(flag)) {
585 return option.substring(prefix.length).split(',');
586 }
587 }
588 return null;
589 }
590
591 Uri _resolvePlatformConfigFromOptions(Uri libraryRoot, List<String> options) {
592 return _resolvePlatformConfig(libraryRoot,
593 _extractStringOption(options, "--platform-config=", null),
594 _hasOption(options, '--output-type=dart'),
595 _extractCsvOption(options, '--categories='));
596 }
597
598 Uri _resolvePlatformConfig(Uri libraryRoot,
599 String platformConfigPath, bool isDart2Dart, Iterable<String> categories) {
600 if (platformConfigPath != null) {
601 return libraryRoot.resolve(platformConfigPath);
602 } else if (isDart2Dart) {
603 return libraryRoot.resolve(_dart2dartPlatform);
604 } else {
605 if (categories.length == 0) {
606 return libraryRoot.resolve(_clientPlatform);
607 }
608 assert(categories.length <= 2);
609 if (categories.contains("Client")) {
610 if (categories.contains("Server")) {
611 return libraryRoot.resolve(_sharedPlatform);
612 }
613 return libraryRoot.resolve(_clientPlatform);
614 }
615 assert(categories.contains("Server"));
616 return libraryRoot.resolve(_serverPlatform);
617 }
618 }
619
620 bool _hasOption(List<String> options, String option) {
621 return options.indexOf(option) >= 0;
622 }
623
624 /// Locations of the platform descriptor files relative to the library root.
625 const String _clientPlatform = "lib/dart_client.platform";
626 const String _serverPlatform = "lib/dart_server.platform";
627 const String _sharedPlatform = "lib/dart_shared.platform";
628 const String _dart2dartPlatform = "lib/dart2dart.platform";
629
630 const String _UNDETERMINED_BUILD_ID = "build number could not be determined";
631 const bool _forceIncrementalSupport =
632 const bool.fromEnvironment('DART2JS_EXPERIMENTAL_INCREMENTAL_SUPPORT');
OLDNEW
« no previous file with comments | « pkg/compiler/lib/compiler.dart ('k') | pkg/compiler/lib/src/apiimpl.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698