Index: pkg/compiler/lib/src/options.dart |
diff --git a/pkg/compiler/lib/compiler_new.dart b/pkg/compiler/lib/src/options.dart |
similarity index 75% |
copy from pkg/compiler/lib/compiler_new.dart |
copy to pkg/compiler/lib/src/options.dart |
index fa405da5323bd51b157feb77d11e7bff8084f30e..e6d915bb7f644b7087a02afa8269076ef2452da8 100644 |
--- a/pkg/compiler/lib/compiler_new.dart |
+++ b/pkg/compiler/lib/src/options.dart |
@@ -1,100 +1,53 @@ |
-// Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file |
+// Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file |
// for details. All rights reserved. Use of this source code is governed by a |
// BSD-style license that can be found in the LICENSE file. |
-/// New Compiler API. This API is under construction, use only internally or |
-/// in unittests. |
+library dart2js.src.options; |
-library compiler_new; |
+import 'commandline_options.dart' show Flags; |
+import '../compiler.dart' show PackagesDiscoveryProvider; |
-import 'dart:async'; |
-import 'src/apiimpl.dart'; |
-import 'src/commandline_options.dart'; |
-import 'src/diagnostics/diagnostic_listener.dart' show DiagnosticOptions; |
+/// Options used for parsing. |
+/// |
+/// Use this to conditionally support certain constructs, e.g., |
+/// experimental ones. |
+abstract class ParserOptions { |
+ const ParserOptions(); |
-import 'compiler.dart' show Diagnostic, PackagesDiscoveryProvider; |
-export 'compiler.dart' show Diagnostic, PackagesDiscoveryProvider; |
+ /// Support conditional directives, e.g., configurable imports. |
+ bool get enableConditionalDirectives; |
+} |
-// Unless explicitly allowed, passing `null` for any argument to the |
-// methods of library will result in an Error being thrown. |
+/// Options used for controlling diagnostic messages. |
+abstract class DiagnosticOptions { |
+ const DiagnosticOptions(); |
-/// Interface for providing the compiler with input. That is, Dart source files, |
-/// package config files, etc. |
-abstract class CompilerInput { |
- /// Returns a future that completes to the source corresponding to [uri]. |
- /// If an exception occurs, the future completes with this exception. |
- /// |
- /// The source can be represented either as a [:List<int>:] of UTF-8 bytes or |
- /// as a [String]. |
- /// |
- /// The following text is non-normative: |
- /// |
- /// It is recommended to return a UTF-8 encoded list of bytes because the |
- /// scanner is more efficient in this case. In either case, the data structure |
- /// is expected to hold a zero element at the last position. If this is not |
- /// the case, the entire data structure is copied before scanning. |
- Future/*<String | List<int>>*/ readFromUri(Uri uri); |
-} |
+ /// If `true`, warnings cause the compilation to fail. |
+ bool get fatalWarnings; |
-/// Interface for producing output from the compiler. That is, JavaScript target |
-/// files, source map files, dump info files, etc. |
-abstract class CompilerOutput { |
- /// Returns an [EventSink] that will serve as compiler output for the given |
- /// component. |
- /// |
- /// Components are identified by [name] and [extension]. By convention, |
- /// the empty string [:"":] will represent the main script |
- /// (corresponding to the script parameter of [compile]) even if the |
- /// main script is a library. For libraries that are compiled |
- /// separately, the library name is used. |
- /// |
- /// At least the following extensions can be expected: |
- /// |
- /// * "js" for JavaScript output. |
- /// * "js.map" for source maps. |
- /// * "dart" for Dart output. |
- /// * "dart.map" for source maps. |
- /// |
- /// As more features are added to the compiler, new names and |
- /// extensions may be introduced. |
- EventSink<String> createEventSink(String name, String extension); |
-} |
+ /// Emit terse diagnostics without howToFix. |
+ bool get terseDiagnostics; |
-/// Interface for receiving diagnostic message from the compiler. That is, |
-/// errors, warnings, hints, etc. |
-abstract class CompilerDiagnostics { |
- /// Invoked by the compiler to report diagnostics. If [uri] is `null`, so are |
- /// [begin] and [end]. No other arguments may be `null`. If [uri] is not |
- /// `null`, neither are [begin] and [end]. [uri] indicates the compilation |
- /// unit from where the diagnostic originates. [begin] and [end] are |
- /// zero-based character offsets from the beginning of the compilation unit. |
- /// [message] is the diagnostic message, and [kind] indicates indicates what |
- /// kind of diagnostic it is. |
- /// |
- /// Experimental: [code] gives access to an id for the messages. Currently it |
- /// is the [Message] used to create the diagnostic, if available, from which |
- /// the [MessageKind] is accessible. |
- void report( |
- var code, Uri uri, int begin, int end, String text, Diagnostic kind); |
-} |
+ /// If `true`, warnings are not reported. |
+ bool get suppressWarnings; |
-/// Information resulting from the compilation. |
-class CompilationResult { |
- /// `true` if the compilation succeeded, that is, compilation didn't fail due |
- /// to compile-time errors and/or internal errors. |
- final bool isSuccess; |
+ /// If `true`, hints are not reported. |
+ bool get suppressHints; |
- /// The compiler object used for the compilation. |
- /// |
- /// Note: The type of [compiler] is implementation dependent and may vary. |
- /// Use only for debugging and testing. |
- final compiler; |
+ /// Returns `true` if warnings and hints are shown for all packages. |
+ bool get showAllPackageWarnings; |
+ |
+ /// Returns `true` if warnings and hints are hidden for all packages. |
+ bool get hidePackageWarnings; |
- CompilationResult(this.compiler, {this.isSuccess: true}); |
+ /// Returns `true` if warnings should be should for [uri]. |
+ bool showPackageWarningsFor(Uri uri); |
} |
-/// Object for passing options to the compiler. |
-class CompilerOptions { |
+/// Object for passing options to the compiler. Superclasses are used to select |
+/// subsets of these options, enabling each part of the compiler to depend on |
+/// as few as possible. |
+class CompilerOptions implements DiagnosticOptions, ParserOptions { |
/// The entry point of the application that is being compiled. |
final Uri entryPoint; |
@@ -161,9 +114,22 @@ class CompilerOptions { |
// TODO(sigmund): negate, so all flags are positive |
final bool disableInlining; |
- /// Several options to configure diagnostic messages. |
- // TODO(sigmund): should we simply embed those options here? |
- final DiagnosticOptions diagnosticOptions; |
+ /// Diagnostic option: If `true`, warnings cause the compilation to fail. |
+ final bool fatalWarnings; |
+ |
+ /// Diagnostic option: Emit terse diagnostics without howToFix. |
+ final bool terseDiagnostics; |
+ |
+ /// Diagnostic option: If `true`, warnings are not reported. |
+ final bool suppressWarnings; |
+ |
+ /// Diagnostic option: If `true`, hints are not reported. |
+ final bool suppressHints; |
+ |
+ /// Diagnostic option: List of packages for which warnings and hints are |
+ /// reported. If `null`, no package warnings or hints are reported. If |
+ /// empty, all warnings and hints are reported. |
+ final List<String> _shownPackageWarnings; |
/// Whether to disable global type inference. |
final bool disableTypeInference; |
@@ -256,7 +222,6 @@ class CompilerOptions { |
/// during each phase and a time-breakdown between phases at the end. |
final bool verbose; |
- |
// ------------------------------------------------- |
// Options for deprecated features |
// ------------------------------------------------- |
@@ -300,13 +265,12 @@ class CompilerOptions { |
options, '--build-id=', _UNDETERMINED_BUILD_ID), |
dart2dartMultiFile: _hasOption(options, '--output-type=dart-multi'), |
deferredMapUri: _extractUriOption(options, '--deferred-map='), |
- diagnosticOptions: new DiagnosticOptions( |
- suppressWarnings: _hasOption(options, Flags.suppressWarnings), |
- fatalWarnings: _hasOption(options, Flags.fatalWarnings), |
- suppressHints: _hasOption(options, Flags.suppressHints), |
- terseDiagnostics: _hasOption(options, Flags.terse), |
- shownPackageWarnings: |
- _extractOptionalCsvOption(options, Flags.showPackageWarnings)), |
+ fatalWarnings: _hasOption(options, Flags.fatalWarnings), |
+ terseDiagnostics: _hasOption(options, Flags.terse), |
+ suppressWarnings: _hasOption(options, Flags.suppressWarnings), |
+ suppressHints: _hasOption(options, Flags.suppressHints), |
+ shownPackageWarnings: |
+ _extractOptionalCsvOption(options, Flags.showPackageWarnings), |
disableInlining: _hasOption(options, Flags.disableInlining), |
disableTypeInference: _hasOption(options, Flags.disableTypeInference), |
dumpInfo: _hasOption(options, Flags.dumpInfo), |
@@ -328,8 +292,8 @@ class CompilerOptions { |
hasIncrementalSupport: _forceIncrementalSupport || |
_hasOption(options, Flags.incrementalSupport), |
outputUri: _extractUriOption(options, '--out='), |
- platformConfigUri: _resolvePlatformConfigFromOptions( |
- libraryRoot, options), |
+ platformConfigUri: |
+ _resolvePlatformConfigFromOptions(libraryRoot, options), |
preserveComments: _hasOption(options, Flags.preserveComments), |
preserveUris: _hasOption(options, Flags.preserveUris), |
sourceMapUri: _extractUriOption(options, '--source-map='), |
@@ -370,7 +334,11 @@ class CompilerOptions { |
String buildId: _UNDETERMINED_BUILD_ID, |
bool dart2dartMultiFile: false, |
Uri deferredMapUri: null, |
- DiagnosticOptions diagnosticOptions: const DiagnosticOptions(), |
+ bool fatalWarnings: false, |
+ bool terseDiagnostics: false, |
+ bool suppressWarnings: false, |
+ bool suppressHints: false, |
+ List<String> shownPackageWarnings: null, |
bool disableInlining: false, |
bool disableTypeInference: false, |
bool dumpInfo: false, |
@@ -435,7 +403,11 @@ class CompilerOptions { |
buildId: buildId, |
dart2dartMultiFile: dart2dartMultiFile, |
deferredMapUri: deferredMapUri, |
- diagnosticOptions: diagnosticOptions, |
+ fatalWarnings: fatalWarnings, |
+ terseDiagnostics: terseDiagnostics, |
+ suppressWarnings: suppressWarnings, |
+ suppressHints: suppressHints, |
+ shownPackageWarnings: shownPackageWarnings, |
disableInlining: disableInlining || hasIncrementalSupport, |
disableTypeInference: disableTypeInference || !emitJavaScript, |
dumpInfo: dumpInfo, |
@@ -451,8 +423,9 @@ class CompilerOptions { |
generateSourceMap: generateSourceMap, |
hasIncrementalSupport: hasIncrementalSupport, |
outputUri: outputUri, |
- platformConfigUri: platformConfigUri ?? _resolvePlatformConfig( |
- libraryRoot, null, !emitJavaScript, const []), |
+ platformConfigUri: platformConfigUri ?? |
+ _resolvePlatformConfig( |
+ libraryRoot, null, !emitJavaScript, const []), |
preserveComments: preserveComments, |
preserveUris: preserveUris, |
sourceMapUri: sourceMapUri, |
@@ -480,7 +453,11 @@ class CompilerOptions { |
this.buildId: _UNDETERMINED_BUILD_ID, |
this.dart2dartMultiFile: false, |
this.deferredMapUri: null, |
- this.diagnosticOptions: null, |
+ this.fatalWarnings: false, |
+ this.terseDiagnostics: false, |
+ this.suppressWarnings: false, |
+ this.suppressHints: false, |
+ List<String> shownPackageWarnings: null, |
this.disableInlining: false, |
this.disableTypeInference: false, |
this.dumpInfo: false, |
@@ -510,41 +487,28 @@ class CompilerOptions { |
this.useFrequencyNamer: false, |
this.useNewSourceInfo: false, |
this.useStartupEmitter: false, |
- this.verbose: false}); |
-} |
+ this.verbose: false}) |
+ : _shownPackageWarnings = shownPackageWarnings; |
-/// Returns a future that completes to a [CompilationResult] when the Dart |
-/// sources in [options] have been compiled. |
-/// |
-/// The generated compiler output is obtained by providing a [compilerOutput]. |
-/// |
-/// If the compilation fails, the future's `CompilationResult.isSuccess` is |
-/// `false` and [CompilerDiagnostics.report] on [compilerDiagnostics] |
-/// is invoked at least once with `kind == Diagnostic.ERROR` or |
-/// `kind == Diagnostic.CRASH`. |
-Future<CompilationResult> compile( |
- CompilerOptions compilerOptions, |
- CompilerInput compilerInput, |
- CompilerDiagnostics compilerDiagnostics, |
- CompilerOutput compilerOutput) { |
- if (compilerOptions == null) { |
- throw new ArgumentError("compilerOptions must be non-null"); |
- } |
- if (compilerInput == null) { |
- throw new ArgumentError("compilerInput must be non-null"); |
- } |
- if (compilerDiagnostics == null) { |
- throw new ArgumentError("compilerDiagnostics must be non-null"); |
- } |
- if (compilerOutput == null) { |
- throw new ArgumentError("compilerOutput must be non-null"); |
+ /// Returns `true` if warnings and hints are shown for all packages. |
+ bool get showAllPackageWarnings { |
+ return _shownPackageWarnings != null && _shownPackageWarnings.isEmpty; |
} |
- CompilerImpl compiler = new CompilerImpl( |
- compilerInput, compilerOutput, compilerDiagnostics, compilerOptions); |
- return compiler.run(compilerOptions.entryPoint).then((bool success) { |
- return new CompilationResult(compiler, isSuccess: success); |
- }); |
+ /// Returns `true` if warnings and hints are hidden for all packages. |
+ bool get hidePackageWarnings => _shownPackageWarnings == null; |
+ |
+ /// Returns `true` if warnings should be should for [uri]. |
+ bool showPackageWarningsFor(Uri uri) { |
+ if (showAllPackageWarnings) { |
+ return true; |
+ } |
+ if (_shownPackageWarnings != null) { |
+ return uri.scheme == 'package' && |
+ _shownPackageWarnings.contains(uri.pathSegments.first); |
+ } |
+ return false; |
+ } |
} |
String _extractStringOption( |
@@ -572,6 +536,10 @@ List<String> _extractCsvOption(List<String> options, String prefix) { |
return const <String>[]; |
} |
+bool _hasOption(List<String> options, String option) { |
+ return options.indexOf(option) >= 0; |
+} |
+ |
/// Extract list of comma separated values provided for [flag]. Returns an |
/// empty list if [option] contain [flag] without arguments. Returns `null` if |
/// [option] doesn't contain [flag] with or without arguments. |
@@ -588,15 +556,8 @@ List<String> _extractOptionalCsvOption(List<String> options, String flag) { |
return null; |
} |
-Uri _resolvePlatformConfigFromOptions(Uri libraryRoot, List<String> options) { |
- return _resolvePlatformConfig(libraryRoot, |
- _extractStringOption(options, "--platform-config=", null), |
- _hasOption(options, '--output-type=dart'), |
- _extractCsvOption(options, '--categories=')); |
-} |
- |
-Uri _resolvePlatformConfig(Uri libraryRoot, |
- String platformConfigPath, bool isDart2Dart, Iterable<String> categories) { |
+Uri _resolvePlatformConfig(Uri libraryRoot, String platformConfigPath, |
+ bool isDart2Dart, Iterable<String> categories) { |
if (platformConfigPath != null) { |
return libraryRoot.resolve(platformConfigPath); |
} else if (isDart2Dart) { |
@@ -617,8 +578,12 @@ Uri _resolvePlatformConfig(Uri libraryRoot, |
} |
} |
-bool _hasOption(List<String> options, String option) { |
- return options.indexOf(option) >= 0; |
+Uri _resolvePlatformConfigFromOptions(Uri libraryRoot, List<String> options) { |
+ return _resolvePlatformConfig( |
+ libraryRoot, |
+ _extractStringOption(options, "--platform-config=", null), |
+ _hasOption(options, '--output-type=dart'), |
+ _extractCsvOption(options, '--categories=')); |
} |
/// Locations of the platform descriptor files relative to the library root. |