OLD | NEW |
1 // Copyright (c) 2015, 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 /// New Compiler API. This API is under construction, use only internally or | 5 library dart2js.src.options; |
6 /// in unittests. | |
7 | 6 |
8 library compiler_new; | 7 import 'commandline_options.dart' show Flags; |
| 8 import '../compiler.dart' show PackagesDiscoveryProvider; |
9 | 9 |
10 import 'dart:async'; | 10 /// Options used for parsing. |
11 import 'src/apiimpl.dart'; | 11 /// |
12 import 'src/commandline_options.dart'; | 12 /// Use this to conditionally support certain constructs, e.g., |
13 import 'src/diagnostics/diagnostic_listener.dart' show DiagnosticOptions; | 13 /// experimental ones. |
| 14 abstract class ParserOptions { |
| 15 const ParserOptions(); |
14 | 16 |
15 import 'compiler.dart' show Diagnostic, PackagesDiscoveryProvider; | 17 /// Support conditional directives, e.g., configurable imports. |
16 export 'compiler.dart' show Diagnostic, PackagesDiscoveryProvider; | 18 bool get enableConditionalDirectives; |
17 | |
18 // Unless explicitly allowed, passing `null` for any argument to the | |
19 // methods of library will result in an Error being thrown. | |
20 | |
21 /// Interface for providing the compiler with input. That is, Dart source files, | |
22 /// package config files, etc. | |
23 abstract class CompilerInput { | |
24 /// Returns a future that completes to the source corresponding to [uri]. | |
25 /// If an exception occurs, the future completes with this exception. | |
26 /// | |
27 /// The source can be represented either as a [:List<int>:] of UTF-8 bytes or | |
28 /// as a [String]. | |
29 /// | |
30 /// The following text is non-normative: | |
31 /// | |
32 /// It is recommended to return a UTF-8 encoded list of bytes because the | |
33 /// scanner is more efficient in this case. In either case, the data structure | |
34 /// is expected to hold a zero element at the last position. If this is not | |
35 /// the case, the entire data structure is copied before scanning. | |
36 Future/*<String | List<int>>*/ readFromUri(Uri uri); | |
37 } | 19 } |
38 | 20 |
39 /// Interface for producing output from the compiler. That is, JavaScript target | 21 /// Options used for controlling diagnostic messages. |
40 /// files, source map files, dump info files, etc. | 22 abstract class DiagnosticOptions { |
41 abstract class CompilerOutput { | 23 const DiagnosticOptions(); |
42 /// Returns an [EventSink] that will serve as compiler output for the given | 24 |
43 /// component. | 25 /// If `true`, warnings cause the compilation to fail. |
44 /// | 26 bool get fatalWarnings; |
45 /// Components are identified by [name] and [extension]. By convention, | 27 |
46 /// the empty string [:"":] will represent the main script | 28 /// Emit terse diagnostics without howToFix. |
47 /// (corresponding to the script parameter of [compile]) even if the | 29 bool get terseDiagnostics; |
48 /// main script is a library. For libraries that are compiled | 30 |
49 /// separately, the library name is used. | 31 /// If `true`, warnings are not reported. |
50 /// | 32 bool get suppressWarnings; |
51 /// At least the following extensions can be expected: | 33 |
52 /// | 34 /// If `true`, hints are not reported. |
53 /// * "js" for JavaScript output. | 35 bool get suppressHints; |
54 /// * "js.map" for source maps. | 36 |
55 /// * "dart" for Dart output. | 37 /// Returns `true` if warnings and hints are shown for all packages. |
56 /// * "dart.map" for source maps. | 38 bool get showAllPackageWarnings; |
57 /// | 39 |
58 /// As more features are added to the compiler, new names and | 40 /// Returns `true` if warnings and hints are hidden for all packages. |
59 /// extensions may be introduced. | 41 bool get hidePackageWarnings; |
60 EventSink<String> createEventSink(String name, String extension); | 42 |
| 43 /// Returns `true` if warnings should be should for [uri]. |
| 44 bool showPackageWarningsFor(Uri uri); |
61 } | 45 } |
62 | 46 |
63 /// Interface for receiving diagnostic message from the compiler. That is, | 47 /// Object for passing options to the compiler. Superclasses are used to select |
64 /// errors, warnings, hints, etc. | 48 /// subsets of these options, enabling each part of the compiler to depend on |
65 abstract class CompilerDiagnostics { | 49 /// as few as possible. |
66 /// Invoked by the compiler to report diagnostics. If [uri] is `null`, so are | 50 class CompilerOptions implements DiagnosticOptions, ParserOptions { |
67 /// [begin] and [end]. No other arguments may be `null`. If [uri] is not | |
68 /// `null`, neither are [begin] and [end]. [uri] indicates the compilation | |
69 /// unit from where the diagnostic originates. [begin] and [end] are | |
70 /// zero-based character offsets from the beginning of the compilation unit. | |
71 /// [message] is the diagnostic message, and [kind] indicates indicates what | |
72 /// kind of diagnostic it is. | |
73 /// | |
74 /// Experimental: [code] gives access to an id for the messages. Currently it | |
75 /// is the [Message] used to create the diagnostic, if available, from which | |
76 /// the [MessageKind] is accessible. | |
77 void report( | |
78 var code, Uri uri, int begin, int end, String text, Diagnostic kind); | |
79 } | |
80 | |
81 /// Information resulting from the compilation. | |
82 class CompilationResult { | |
83 /// `true` if the compilation succeeded, that is, compilation didn't fail due | |
84 /// to compile-time errors and/or internal errors. | |
85 final bool isSuccess; | |
86 | |
87 /// The compiler object used for the compilation. | |
88 /// | |
89 /// Note: The type of [compiler] is implementation dependent and may vary. | |
90 /// Use only for debugging and testing. | |
91 final compiler; | |
92 | |
93 CompilationResult(this.compiler, {this.isSuccess: true}); | |
94 } | |
95 | |
96 /// Object for passing options to the compiler. | |
97 class CompilerOptions { | |
98 /// The entry point of the application that is being compiled. | 51 /// The entry point of the application that is being compiled. |
99 final Uri entryPoint; | 52 final Uri entryPoint; |
100 | 53 |
101 /// Root location where SDK libraries are found. | 54 /// Root location where SDK libraries are found. |
102 final Uri libraryRoot; | 55 final Uri libraryRoot; |
103 | 56 |
104 /// Package root location. | 57 /// Package root location. |
105 /// | 58 /// |
106 /// If not null then [packageConfig] should be null. | 59 /// If not null then [packageConfig] should be null. |
107 final Uri packageRoot; | 60 final Uri packageRoot; |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
154 bool get hasBuildId => buildId != _UNDETERMINED_BUILD_ID; | 107 bool get hasBuildId => buildId != _UNDETERMINED_BUILD_ID; |
155 | 108 |
156 /// Location where to generate a map containing details of how deferred | 109 /// Location where to generate a map containing details of how deferred |
157 /// libraries are subdivided. | 110 /// libraries are subdivided. |
158 final Uri deferredMapUri; | 111 final Uri deferredMapUri; |
159 | 112 |
160 /// Whether to disable inlining during the backend optimizations. | 113 /// Whether to disable inlining during the backend optimizations. |
161 // TODO(sigmund): negate, so all flags are positive | 114 // TODO(sigmund): negate, so all flags are positive |
162 final bool disableInlining; | 115 final bool disableInlining; |
163 | 116 |
164 /// Several options to configure diagnostic messages. | 117 /// Diagnostic option: If `true`, warnings cause the compilation to fail. |
165 // TODO(sigmund): should we simply embed those options here? | 118 final bool fatalWarnings; |
166 final DiagnosticOptions diagnosticOptions; | 119 |
| 120 /// Diagnostic option: Emit terse diagnostics without howToFix. |
| 121 final bool terseDiagnostics; |
| 122 |
| 123 /// Diagnostic option: If `true`, warnings are not reported. |
| 124 final bool suppressWarnings; |
| 125 |
| 126 /// Diagnostic option: If `true`, hints are not reported. |
| 127 final bool suppressHints; |
| 128 |
| 129 /// Diagnostic option: List of packages for which warnings and hints are |
| 130 /// reported. If `null`, no package warnings or hints are reported. If |
| 131 /// empty, all warnings and hints are reported. |
| 132 final List<String> _shownPackageWarnings; |
167 | 133 |
168 /// Whether to disable global type inference. | 134 /// Whether to disable global type inference. |
169 final bool disableTypeInference; | 135 final bool disableTypeInference; |
170 | 136 |
171 /// Whether to emit a .json file with a summary of the information used by the | 137 /// Whether to emit a .json file with a summary of the information used by the |
172 /// compiler during optimization. This includes resolution details, | 138 /// compiler during optimization. This includes resolution details, |
173 /// dependencies between elements, results of type inference, and the output | 139 /// dependencies between elements, results of type inference, and the output |
174 /// code for each function. | 140 /// code for each function. |
175 final bool dumpInfo; | 141 final bool dumpInfo; |
176 | 142 |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
249 final bool useNewSourceInfo; | 215 final bool useNewSourceInfo; |
250 | 216 |
251 /// Whether the user requested to use the fast startup emitter. The full | 217 /// Whether the user requested to use the fast startup emitter. The full |
252 /// emitter might still be used if the program uses dart:mirrors. | 218 /// emitter might still be used if the program uses dart:mirrors. |
253 final bool useStartupEmitter; | 219 final bool useStartupEmitter; |
254 | 220 |
255 /// Enable verbose printing during compilation. Includes progress messages | 221 /// Enable verbose printing during compilation. Includes progress messages |
256 /// during each phase and a time-breakdown between phases at the end. | 222 /// during each phase and a time-breakdown between phases at the end. |
257 final bool verbose; | 223 final bool verbose; |
258 | 224 |
259 | |
260 // ------------------------------------------------- | 225 // ------------------------------------------------- |
261 // Options for deprecated features | 226 // Options for deprecated features |
262 // ------------------------------------------------- | 227 // ------------------------------------------------- |
263 // TODO(sigmund): delete these as we delete the underlying features | 228 // TODO(sigmund): delete these as we delete the underlying features |
264 | 229 |
265 /// Whether to preserve comments while scanning (only use for dart:mirrors). | 230 /// Whether to preserve comments while scanning (only use for dart:mirrors). |
266 final bool preserveComments; | 231 final bool preserveComments; |
267 | 232 |
268 /// Whether to emit JavaScript (false enables dart2dart). | 233 /// Whether to emit JavaScript (false enables dart2dart). |
269 final bool emitJavaScript; | 234 final bool emitJavaScript; |
(...skipping 23 matching lines...) Expand all Loading... |
293 allowMockCompilation: _hasOption(options, Flags.allowMockCompilation), | 258 allowMockCompilation: _hasOption(options, Flags.allowMockCompilation), |
294 allowNativeExtensions: _hasOption(options, Flags.allowNativeExtensions), | 259 allowNativeExtensions: _hasOption(options, Flags.allowNativeExtensions), |
295 analyzeAll: _hasOption(options, Flags.analyzeAll), | 260 analyzeAll: _hasOption(options, Flags.analyzeAll), |
296 analyzeMain: _hasOption(options, Flags.analyzeMain), | 261 analyzeMain: _hasOption(options, Flags.analyzeMain), |
297 analyzeOnly: _hasOption(options, Flags.analyzeOnly), | 262 analyzeOnly: _hasOption(options, Flags.analyzeOnly), |
298 analyzeSignaturesOnly: _hasOption(options, Flags.analyzeSignaturesOnly), | 263 analyzeSignaturesOnly: _hasOption(options, Flags.analyzeSignaturesOnly), |
299 buildId: _extractStringOption( | 264 buildId: _extractStringOption( |
300 options, '--build-id=', _UNDETERMINED_BUILD_ID), | 265 options, '--build-id=', _UNDETERMINED_BUILD_ID), |
301 dart2dartMultiFile: _hasOption(options, '--output-type=dart-multi'), | 266 dart2dartMultiFile: _hasOption(options, '--output-type=dart-multi'), |
302 deferredMapUri: _extractUriOption(options, '--deferred-map='), | 267 deferredMapUri: _extractUriOption(options, '--deferred-map='), |
303 diagnosticOptions: new DiagnosticOptions( | 268 fatalWarnings: _hasOption(options, Flags.fatalWarnings), |
304 suppressWarnings: _hasOption(options, Flags.suppressWarnings), | 269 terseDiagnostics: _hasOption(options, Flags.terse), |
305 fatalWarnings: _hasOption(options, Flags.fatalWarnings), | 270 suppressWarnings: _hasOption(options, Flags.suppressWarnings), |
306 suppressHints: _hasOption(options, Flags.suppressHints), | 271 suppressHints: _hasOption(options, Flags.suppressHints), |
307 terseDiagnostics: _hasOption(options, Flags.terse), | 272 shownPackageWarnings: |
308 shownPackageWarnings: | 273 _extractOptionalCsvOption(options, Flags.showPackageWarnings), |
309 _extractOptionalCsvOption(options, Flags.showPackageWarnings)), | |
310 disableInlining: _hasOption(options, Flags.disableInlining), | 274 disableInlining: _hasOption(options, Flags.disableInlining), |
311 disableTypeInference: _hasOption(options, Flags.disableTypeInference), | 275 disableTypeInference: _hasOption(options, Flags.disableTypeInference), |
312 dumpInfo: _hasOption(options, Flags.dumpInfo), | 276 dumpInfo: _hasOption(options, Flags.dumpInfo), |
313 emitJavaScript: !(_hasOption(options, '--output-type=dart') || | 277 emitJavaScript: !(_hasOption(options, '--output-type=dart') || |
314 _hasOption(options, '--output-type=dart-multi')), | 278 _hasOption(options, '--output-type=dart-multi')), |
315 enableAssertMessage: _hasOption(options, Flags.enableAssertMessage), | 279 enableAssertMessage: _hasOption(options, Flags.enableAssertMessage), |
316 enableConditionalDirectives: | 280 enableConditionalDirectives: |
317 _hasOption(options, Flags.conditionalDirectives), | 281 _hasOption(options, Flags.conditionalDirectives), |
318 enableExperimentalMirrors: | 282 enableExperimentalMirrors: |
319 _hasOption(options, Flags.enableExperimentalMirrors), | 283 _hasOption(options, Flags.enableExperimentalMirrors), |
320 enableMinification: _hasOption(options, Flags.minify), | 284 enableMinification: _hasOption(options, Flags.minify), |
321 enableNativeLiveTypeAnalysis: | 285 enableNativeLiveTypeAnalysis: |
322 !_hasOption(options, Flags.disableNativeLiveTypeAnalysis), | 286 !_hasOption(options, Flags.disableNativeLiveTypeAnalysis), |
323 enableTypeAssertions: _hasOption(options, Flags.enableCheckedMode), | 287 enableTypeAssertions: _hasOption(options, Flags.enableCheckedMode), |
324 enableUserAssertions: _hasOption(options, Flags.enableCheckedMode), | 288 enableUserAssertions: _hasOption(options, Flags.enableCheckedMode), |
325 generateCodeWithCompileTimeErrors: | 289 generateCodeWithCompileTimeErrors: |
326 _hasOption(options, Flags.generateCodeWithCompileTimeErrors), | 290 _hasOption(options, Flags.generateCodeWithCompileTimeErrors), |
327 generateSourceMap: !_hasOption(options, Flags.noSourceMaps), | 291 generateSourceMap: !_hasOption(options, Flags.noSourceMaps), |
328 hasIncrementalSupport: _forceIncrementalSupport || | 292 hasIncrementalSupport: _forceIncrementalSupport || |
329 _hasOption(options, Flags.incrementalSupport), | 293 _hasOption(options, Flags.incrementalSupport), |
330 outputUri: _extractUriOption(options, '--out='), | 294 outputUri: _extractUriOption(options, '--out='), |
331 platformConfigUri: _resolvePlatformConfigFromOptions( | 295 platformConfigUri: |
332 libraryRoot, options), | 296 _resolvePlatformConfigFromOptions(libraryRoot, options), |
333 preserveComments: _hasOption(options, Flags.preserveComments), | 297 preserveComments: _hasOption(options, Flags.preserveComments), |
334 preserveUris: _hasOption(options, Flags.preserveUris), | 298 preserveUris: _hasOption(options, Flags.preserveUris), |
335 sourceMapUri: _extractUriOption(options, '--source-map='), | 299 sourceMapUri: _extractUriOption(options, '--source-map='), |
336 strips: _extractCsvOption(options, '--force-strip='), | 300 strips: _extractCsvOption(options, '--force-strip='), |
337 testMode: _hasOption(options, Flags.testMode), | 301 testMode: _hasOption(options, Flags.testMode), |
338 trustJSInteropTypeAnnotations: | 302 trustJSInteropTypeAnnotations: |
339 _hasOption(options, Flags.trustJSInteropTypeAnnotations), | 303 _hasOption(options, Flags.trustJSInteropTypeAnnotations), |
340 trustPrimitives: _hasOption(options, Flags.trustPrimitives), | 304 trustPrimitives: _hasOption(options, Flags.trustPrimitives), |
341 trustTypeAnnotations: _hasOption(options, Flags.trustTypeAnnotations), | 305 trustTypeAnnotations: _hasOption(options, Flags.trustTypeAnnotations), |
342 useContentSecurityPolicy: | 306 useContentSecurityPolicy: |
(...skipping 20 matching lines...) Expand all Loading... |
363 Map<String, dynamic> environment: const <String, dynamic>{}, | 327 Map<String, dynamic> environment: const <String, dynamic>{}, |
364 bool allowMockCompilation: false, | 328 bool allowMockCompilation: false, |
365 bool allowNativeExtensions: false, | 329 bool allowNativeExtensions: false, |
366 bool analyzeAll: false, | 330 bool analyzeAll: false, |
367 bool analyzeMain: false, | 331 bool analyzeMain: false, |
368 bool analyzeOnly: false, | 332 bool analyzeOnly: false, |
369 bool analyzeSignaturesOnly: false, | 333 bool analyzeSignaturesOnly: false, |
370 String buildId: _UNDETERMINED_BUILD_ID, | 334 String buildId: _UNDETERMINED_BUILD_ID, |
371 bool dart2dartMultiFile: false, | 335 bool dart2dartMultiFile: false, |
372 Uri deferredMapUri: null, | 336 Uri deferredMapUri: null, |
373 DiagnosticOptions diagnosticOptions: const DiagnosticOptions(), | 337 bool fatalWarnings: false, |
| 338 bool terseDiagnostics: false, |
| 339 bool suppressWarnings: false, |
| 340 bool suppressHints: false, |
| 341 List<String> shownPackageWarnings: null, |
374 bool disableInlining: false, | 342 bool disableInlining: false, |
375 bool disableTypeInference: false, | 343 bool disableTypeInference: false, |
376 bool dumpInfo: false, | 344 bool dumpInfo: false, |
377 bool emitJavaScript: true, | 345 bool emitJavaScript: true, |
378 bool enableAssertMessage: false, | 346 bool enableAssertMessage: false, |
379 bool enableConditionalDirectives: false, | 347 bool enableConditionalDirectives: false, |
380 bool enableExperimentalMirrors: false, | 348 bool enableExperimentalMirrors: false, |
381 bool enableMinification: false, | 349 bool enableMinification: false, |
382 bool enableNativeLiveTypeAnalysis: true, | 350 bool enableNativeLiveTypeAnalysis: true, |
383 bool enableTypeAssertions: false, | 351 bool enableTypeAssertions: false, |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
428 packageConfig, packagesDiscoveryProvider, environment, | 396 packageConfig, packagesDiscoveryProvider, environment, |
429 allowMockCompilation: allowMockCompilation, | 397 allowMockCompilation: allowMockCompilation, |
430 allowNativeExtensions: allowNativeExtensions, | 398 allowNativeExtensions: allowNativeExtensions, |
431 analyzeAll: analyzeAll, | 399 analyzeAll: analyzeAll, |
432 analyzeMain: analyzeMain, | 400 analyzeMain: analyzeMain, |
433 analyzeOnly: analyzeOnly || analyzeSignaturesOnly || analyzeAll, | 401 analyzeOnly: analyzeOnly || analyzeSignaturesOnly || analyzeAll, |
434 analyzeSignaturesOnly: analyzeSignaturesOnly, | 402 analyzeSignaturesOnly: analyzeSignaturesOnly, |
435 buildId: buildId, | 403 buildId: buildId, |
436 dart2dartMultiFile: dart2dartMultiFile, | 404 dart2dartMultiFile: dart2dartMultiFile, |
437 deferredMapUri: deferredMapUri, | 405 deferredMapUri: deferredMapUri, |
438 diagnosticOptions: diagnosticOptions, | 406 fatalWarnings: fatalWarnings, |
| 407 terseDiagnostics: terseDiagnostics, |
| 408 suppressWarnings: suppressWarnings, |
| 409 suppressHints: suppressHints, |
| 410 shownPackageWarnings: shownPackageWarnings, |
439 disableInlining: disableInlining || hasIncrementalSupport, | 411 disableInlining: disableInlining || hasIncrementalSupport, |
440 disableTypeInference: disableTypeInference || !emitJavaScript, | 412 disableTypeInference: disableTypeInference || !emitJavaScript, |
441 dumpInfo: dumpInfo, | 413 dumpInfo: dumpInfo, |
442 emitJavaScript: emitJavaScript, | 414 emitJavaScript: emitJavaScript, |
443 enableAssertMessage: enableAssertMessage, | 415 enableAssertMessage: enableAssertMessage, |
444 enableConditionalDirectives: enableConditionalDirectives, | 416 enableConditionalDirectives: enableConditionalDirectives, |
445 enableExperimentalMirrors: enableExperimentalMirrors, | 417 enableExperimentalMirrors: enableExperimentalMirrors, |
446 enableMinification: enableMinification, | 418 enableMinification: enableMinification, |
447 enableNativeLiveTypeAnalysis: enableNativeLiveTypeAnalysis, | 419 enableNativeLiveTypeAnalysis: enableNativeLiveTypeAnalysis, |
448 enableTypeAssertions: enableTypeAssertions, | 420 enableTypeAssertions: enableTypeAssertions, |
449 enableUserAssertions: enableUserAssertions, | 421 enableUserAssertions: enableUserAssertions, |
450 generateCodeWithCompileTimeErrors: generateCodeWithCompileTimeErrors, | 422 generateCodeWithCompileTimeErrors: generateCodeWithCompileTimeErrors, |
451 generateSourceMap: generateSourceMap, | 423 generateSourceMap: generateSourceMap, |
452 hasIncrementalSupport: hasIncrementalSupport, | 424 hasIncrementalSupport: hasIncrementalSupport, |
453 outputUri: outputUri, | 425 outputUri: outputUri, |
454 platformConfigUri: platformConfigUri ?? _resolvePlatformConfig( | 426 platformConfigUri: platformConfigUri ?? |
455 libraryRoot, null, !emitJavaScript, const []), | 427 _resolvePlatformConfig( |
| 428 libraryRoot, null, !emitJavaScript, const []), |
456 preserveComments: preserveComments, | 429 preserveComments: preserveComments, |
457 preserveUris: preserveUris, | 430 preserveUris: preserveUris, |
458 sourceMapUri: sourceMapUri, | 431 sourceMapUri: sourceMapUri, |
459 strips: strips, | 432 strips: strips, |
460 testMode: testMode, | 433 testMode: testMode, |
461 trustJSInteropTypeAnnotations: trustJSInteropTypeAnnotations, | 434 trustJSInteropTypeAnnotations: trustJSInteropTypeAnnotations, |
462 trustPrimitives: trustPrimitives, | 435 trustPrimitives: trustPrimitives, |
463 trustTypeAnnotations: trustTypeAnnotations, | 436 trustTypeAnnotations: trustTypeAnnotations, |
464 useContentSecurityPolicy: useContentSecurityPolicy, | 437 useContentSecurityPolicy: useContentSecurityPolicy, |
465 useCpsIr: useCpsIr, | 438 useCpsIr: useCpsIr, |
466 useFrequencyNamer: useFrequencyNamer, | 439 useFrequencyNamer: useFrequencyNamer, |
467 useNewSourceInfo: useNewSourceInfo, | 440 useNewSourceInfo: useNewSourceInfo, |
468 useStartupEmitter: useStartupEmitter, | 441 useStartupEmitter: useStartupEmitter, |
469 verbose: verbose); | 442 verbose: verbose); |
470 } | 443 } |
471 | 444 |
472 CompilerOptions._(this.entryPoint, this.libraryRoot, this.packageRoot, | 445 CompilerOptions._(this.entryPoint, this.libraryRoot, this.packageRoot, |
473 this.packageConfig, this.packagesDiscoveryProvider, this.environment, | 446 this.packageConfig, this.packagesDiscoveryProvider, this.environment, |
474 {this.allowMockCompilation: false, | 447 {this.allowMockCompilation: false, |
475 this.allowNativeExtensions: false, | 448 this.allowNativeExtensions: false, |
476 this.analyzeAll: false, | 449 this.analyzeAll: false, |
477 this.analyzeMain: false, | 450 this.analyzeMain: false, |
478 this.analyzeOnly: false, | 451 this.analyzeOnly: false, |
479 this.analyzeSignaturesOnly: false, | 452 this.analyzeSignaturesOnly: false, |
480 this.buildId: _UNDETERMINED_BUILD_ID, | 453 this.buildId: _UNDETERMINED_BUILD_ID, |
481 this.dart2dartMultiFile: false, | 454 this.dart2dartMultiFile: false, |
482 this.deferredMapUri: null, | 455 this.deferredMapUri: null, |
483 this.diagnosticOptions: null, | 456 this.fatalWarnings: false, |
| 457 this.terseDiagnostics: false, |
| 458 this.suppressWarnings: false, |
| 459 this.suppressHints: false, |
| 460 List<String> shownPackageWarnings: null, |
484 this.disableInlining: false, | 461 this.disableInlining: false, |
485 this.disableTypeInference: false, | 462 this.disableTypeInference: false, |
486 this.dumpInfo: false, | 463 this.dumpInfo: false, |
487 this.emitJavaScript: true, | 464 this.emitJavaScript: true, |
488 this.enableAssertMessage: false, | 465 this.enableAssertMessage: false, |
489 this.enableConditionalDirectives: false, | 466 this.enableConditionalDirectives: false, |
490 this.enableExperimentalMirrors: false, | 467 this.enableExperimentalMirrors: false, |
491 this.enableMinification: false, | 468 this.enableMinification: false, |
492 this.enableNativeLiveTypeAnalysis: false, | 469 this.enableNativeLiveTypeAnalysis: false, |
493 this.enableTypeAssertions: false, | 470 this.enableTypeAssertions: false, |
494 this.enableUserAssertions: false, | 471 this.enableUserAssertions: false, |
495 this.generateCodeWithCompileTimeErrors: false, | 472 this.generateCodeWithCompileTimeErrors: false, |
496 this.generateSourceMap: true, | 473 this.generateSourceMap: true, |
497 this.hasIncrementalSupport: false, | 474 this.hasIncrementalSupport: false, |
498 this.outputUri: null, | 475 this.outputUri: null, |
499 this.platformConfigUri: null, | 476 this.platformConfigUri: null, |
500 this.preserveComments: false, | 477 this.preserveComments: false, |
501 this.preserveUris: false, | 478 this.preserveUris: false, |
502 this.sourceMapUri: null, | 479 this.sourceMapUri: null, |
503 this.strips: const [], | 480 this.strips: const [], |
504 this.testMode: false, | 481 this.testMode: false, |
505 this.trustJSInteropTypeAnnotations: false, | 482 this.trustJSInteropTypeAnnotations: false, |
506 this.trustPrimitives: false, | 483 this.trustPrimitives: false, |
507 this.trustTypeAnnotations: false, | 484 this.trustTypeAnnotations: false, |
508 this.useContentSecurityPolicy: false, | 485 this.useContentSecurityPolicy: false, |
509 this.useCpsIr: false, | 486 this.useCpsIr: false, |
510 this.useFrequencyNamer: false, | 487 this.useFrequencyNamer: false, |
511 this.useNewSourceInfo: false, | 488 this.useNewSourceInfo: false, |
512 this.useStartupEmitter: false, | 489 this.useStartupEmitter: false, |
513 this.verbose: false}); | 490 this.verbose: false}) |
514 } | 491 : _shownPackageWarnings = shownPackageWarnings; |
515 | 492 |
516 /// Returns a future that completes to a [CompilationResult] when the Dart | 493 /// Returns `true` if warnings and hints are shown for all packages. |
517 /// sources in [options] have been compiled. | 494 bool get showAllPackageWarnings { |
518 /// | 495 return _shownPackageWarnings != null && _shownPackageWarnings.isEmpty; |
519 /// The generated compiler output is obtained by providing a [compilerOutput]. | |
520 /// | |
521 /// If the compilation fails, the future's `CompilationResult.isSuccess` is | |
522 /// `false` and [CompilerDiagnostics.report] on [compilerDiagnostics] | |
523 /// is invoked at least once with `kind == Diagnostic.ERROR` or | |
524 /// `kind == Diagnostic.CRASH`. | |
525 Future<CompilationResult> compile( | |
526 CompilerOptions compilerOptions, | |
527 CompilerInput compilerInput, | |
528 CompilerDiagnostics compilerDiagnostics, | |
529 CompilerOutput compilerOutput) { | |
530 if (compilerOptions == null) { | |
531 throw new ArgumentError("compilerOptions must be non-null"); | |
532 } | |
533 if (compilerInput == null) { | |
534 throw new ArgumentError("compilerInput must be non-null"); | |
535 } | |
536 if (compilerDiagnostics == null) { | |
537 throw new ArgumentError("compilerDiagnostics must be non-null"); | |
538 } | |
539 if (compilerOutput == null) { | |
540 throw new ArgumentError("compilerOutput must be non-null"); | |
541 } | 496 } |
542 | 497 |
543 CompilerImpl compiler = new CompilerImpl( | 498 /// Returns `true` if warnings and hints are hidden for all packages. |
544 compilerInput, compilerOutput, compilerDiagnostics, compilerOptions); | 499 bool get hidePackageWarnings => _shownPackageWarnings == null; |
545 return compiler.run(compilerOptions.entryPoint).then((bool success) { | 500 |
546 return new CompilationResult(compiler, isSuccess: success); | 501 /// Returns `true` if warnings should be should for [uri]. |
547 }); | 502 bool showPackageWarningsFor(Uri uri) { |
| 503 if (showAllPackageWarnings) { |
| 504 return true; |
| 505 } |
| 506 if (_shownPackageWarnings != null) { |
| 507 return uri.scheme == 'package' && |
| 508 _shownPackageWarnings.contains(uri.pathSegments.first); |
| 509 } |
| 510 return false; |
| 511 } |
548 } | 512 } |
549 | 513 |
550 String _extractStringOption( | 514 String _extractStringOption( |
551 List<String> options, String prefix, String defaultValue) { | 515 List<String> options, String prefix, String defaultValue) { |
552 for (String option in options) { | 516 for (String option in options) { |
553 if (option.startsWith(prefix)) { | 517 if (option.startsWith(prefix)) { |
554 return option.substring(prefix.length); | 518 return option.substring(prefix.length); |
555 } | 519 } |
556 } | 520 } |
557 return defaultValue; | 521 return defaultValue; |
558 } | 522 } |
559 | 523 |
560 Uri _extractUriOption(List<String> options, String prefix) { | 524 Uri _extractUriOption(List<String> options, String prefix) { |
561 var option = _extractStringOption(options, prefix, null); | 525 var option = _extractStringOption(options, prefix, null); |
562 return (option == null) ? null : Uri.parse(option); | 526 return (option == null) ? null : Uri.parse(option); |
563 } | 527 } |
564 | 528 |
565 // CSV: Comma separated values. | 529 // CSV: Comma separated values. |
566 List<String> _extractCsvOption(List<String> options, String prefix) { | 530 List<String> _extractCsvOption(List<String> options, String prefix) { |
567 for (String option in options) { | 531 for (String option in options) { |
568 if (option.startsWith(prefix)) { | 532 if (option.startsWith(prefix)) { |
569 return option.substring(prefix.length).split(','); | 533 return option.substring(prefix.length).split(','); |
570 } | 534 } |
571 } | 535 } |
572 return const <String>[]; | 536 return const <String>[]; |
573 } | 537 } |
574 | 538 |
| 539 bool _hasOption(List<String> options, String option) { |
| 540 return options.indexOf(option) >= 0; |
| 541 } |
| 542 |
575 /// Extract list of comma separated values provided for [flag]. Returns an | 543 /// Extract list of comma separated values provided for [flag]. Returns an |
576 /// empty list if [option] contain [flag] without arguments. Returns `null` if | 544 /// empty list if [option] contain [flag] without arguments. Returns `null` if |
577 /// [option] doesn't contain [flag] with or without arguments. | 545 /// [option] doesn't contain [flag] with or without arguments. |
578 List<String> _extractOptionalCsvOption(List<String> options, String flag) { | 546 List<String> _extractOptionalCsvOption(List<String> options, String flag) { |
579 String prefix = '$flag='; | 547 String prefix = '$flag='; |
580 for (String option in options) { | 548 for (String option in options) { |
581 if (option == flag) { | 549 if (option == flag) { |
582 return const <String>[]; | 550 return const <String>[]; |
583 } | 551 } |
584 if (option.startsWith(flag)) { | 552 if (option.startsWith(flag)) { |
585 return option.substring(prefix.length).split(','); | 553 return option.substring(prefix.length).split(','); |
586 } | 554 } |
587 } | 555 } |
588 return null; | 556 return null; |
589 } | 557 } |
590 | 558 |
591 Uri _resolvePlatformConfigFromOptions(Uri libraryRoot, List<String> options) { | 559 Uri _resolvePlatformConfig(Uri libraryRoot, String platformConfigPath, |
592 return _resolvePlatformConfig(libraryRoot, | 560 bool isDart2Dart, Iterable<String> categories) { |
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) { | 561 if (platformConfigPath != null) { |
601 return libraryRoot.resolve(platformConfigPath); | 562 return libraryRoot.resolve(platformConfigPath); |
602 } else if (isDart2Dart) { | 563 } else if (isDart2Dart) { |
603 return libraryRoot.resolve(_dart2dartPlatform); | 564 return libraryRoot.resolve(_dart2dartPlatform); |
604 } else { | 565 } else { |
605 if (categories.length == 0) { | 566 if (categories.length == 0) { |
606 return libraryRoot.resolve(_clientPlatform); | 567 return libraryRoot.resolve(_clientPlatform); |
607 } | 568 } |
608 assert(categories.length <= 2); | 569 assert(categories.length <= 2); |
609 if (categories.contains("Client")) { | 570 if (categories.contains("Client")) { |
610 if (categories.contains("Server")) { | 571 if (categories.contains("Server")) { |
611 return libraryRoot.resolve(_sharedPlatform); | 572 return libraryRoot.resolve(_sharedPlatform); |
612 } | 573 } |
613 return libraryRoot.resolve(_clientPlatform); | 574 return libraryRoot.resolve(_clientPlatform); |
614 } | 575 } |
615 assert(categories.contains("Server")); | 576 assert(categories.contains("Server")); |
616 return libraryRoot.resolve(_serverPlatform); | 577 return libraryRoot.resolve(_serverPlatform); |
617 } | 578 } |
618 } | 579 } |
619 | 580 |
620 bool _hasOption(List<String> options, String option) { | 581 Uri _resolvePlatformConfigFromOptions(Uri libraryRoot, List<String> options) { |
621 return options.indexOf(option) >= 0; | 582 return _resolvePlatformConfig( |
| 583 libraryRoot, |
| 584 _extractStringOption(options, "--platform-config=", null), |
| 585 _hasOption(options, '--output-type=dart'), |
| 586 _extractCsvOption(options, '--categories=')); |
622 } | 587 } |
623 | 588 |
624 /// Locations of the platform descriptor files relative to the library root. | 589 /// Locations of the platform descriptor files relative to the library root. |
625 const String _clientPlatform = "lib/dart_client.platform"; | 590 const String _clientPlatform = "lib/dart_client.platform"; |
626 const String _serverPlatform = "lib/dart_server.platform"; | 591 const String _serverPlatform = "lib/dart_server.platform"; |
627 const String _sharedPlatform = "lib/dart_shared.platform"; | 592 const String _sharedPlatform = "lib/dart_shared.platform"; |
628 const String _dart2dartPlatform = "lib/dart2dart.platform"; | 593 const String _dart2dartPlatform = "lib/dart2dart.platform"; |
629 | 594 |
630 const String _UNDETERMINED_BUILD_ID = "build number could not be determined"; | 595 const String _UNDETERMINED_BUILD_ID = "build number could not be determined"; |
631 const bool _forceIncrementalSupport = | 596 const bool _forceIncrementalSupport = |
632 const bool.fromEnvironment('DART2JS_EXPERIMENTAL_INCREMENTAL_SUPPORT'); | 597 const bool.fromEnvironment('DART2JS_EXPERIMENTAL_INCREMENTAL_SUPPORT'); |
OLD | NEW |