Repeats and fixes the changes landed & reverted as CL 1789553003.

When landed, CL 1789553003 turned out to cause bot failures because
some libraries outside the compiler are importing compiler libraries
which have been updated. For instance, the tests in 'compiler/dart2js'
depend on several internal elements of the 'dart2js' compiler.

This CL updates these external dependents to work with the modified
library structure and class APIs of the compiler. A small adjustment
was applied to 'dart2js_incremental' as well.

No further dependents are believed to exist: Grepping in sdk for
relevant imports does not reveal any further imports of any of the
libraries in the compiler where the "interface" has changed, and
external clients are not supported (that is, imports in arbitrary
github repositories may or may not break if they use the compiler
internals, but we do not support this type of dependency so we won't
do anything to protect them against that type of breakage).

R=johnniwinther@google.com

Review URL: https://codereview.chromium.org/1864433004 .
This commit is contained in:
Erik Ernst 2016-04-05 17:26:07 +02:00
parent e914716bb7
commit 586c43ac7e
33 changed files with 757 additions and 673 deletions

View file

@ -7,6 +7,7 @@ library compiler;
import 'dart:async';
import 'package:package_config/packages.dart';
import 'compiler_new.dart' as new_api;
import 'src/options.dart' show CompilerOptions;
import 'src/old_to_new_api.dart';
// Unless explicitly allowed, passing [:null:] for any argument to the
@ -115,7 +116,7 @@ Future<CompilationResult> compile(
Uri packageConfig,
PackagesDiscoveryProvider packagesDiscoveryProvider]) {
new_api.CompilerOptions compilerOptions = new new_api.CompilerOptions.parse(
CompilerOptions compilerOptions = new CompilerOptions.parse(
entryPoint: script,
libraryRoot: libraryRoot,
packageRoot: packageRoot,

View file

@ -9,10 +9,9 @@ library compiler_new;
import 'dart:async';
import 'src/apiimpl.dart';
import 'src/commandline_options.dart';
import 'src/diagnostics/diagnostic_listener.dart' show DiagnosticOptions;
import 'src/options.dart' show CompilerOptions;
import 'compiler.dart' show Diagnostic, PackagesDiscoveryProvider;
import 'compiler.dart' show Diagnostic;
export 'compiler.dart' show Diagnostic, PackagesDiscoveryProvider;
// Unless explicitly allowed, passing `null` for any argument to the
@ -93,426 +92,6 @@ class CompilationResult {
CompilationResult(this.compiler, {this.isSuccess: true});
}
/// Object for passing options to the compiler.
class CompilerOptions {
/// The entry point of the application that is being compiled.
final Uri entryPoint;
/// Root location where SDK libraries are found.
final Uri libraryRoot;
/// Package root location.
///
/// If not null then [packageConfig] should be null.
final Uri packageRoot;
/// Location of the package configuration file.
///
/// If not null then [packageRoot] should be null.
final Uri packageConfig;
// TODO(sigmund): Move out of here, maybe to CompilerInput. Options should not
// hold code, just configuration options.
final PackagesDiscoveryProvider packagesDiscoveryProvider;
/// Resolved constant "environment" values passed to the compiler via the `-D`
/// flags.
final Map<String, dynamic> environment;
/// Whether we allow mocking compilation of libraries such as dart:io and
/// dart:html for unit testing purposes.
final bool allowMockCompilation;
/// Whether the native extension syntax is supported by the frontend.
final bool allowNativeExtensions;
/// Whether to resolve all functions in the program, not just those reachable
/// from main. This implies [analyzeOnly] is true as well.
final bool analyzeAll;
/// Whether to disable tree-shaking for the main script. This marks all
/// functions in the main script as reachable (not just a function named
/// `main`).
// TODO(sigmund): rename. The current name seems to indicate that only the
// main function is retained, which is the opposite of what this does.
final bool analyzeMain;
/// Whether to run the compiler just for the purpose of analysis. That is, to
/// run resolution and type-checking alone, but otherwise do not generate any
/// code.
final bool analyzeOnly;
/// Whether to skip analysis of method bodies and field initializers. Implies
/// [analyzeOnly].
final bool analyzeSignaturesOnly;
/// ID associated with this sdk build.
final String buildId;
/// Whether there is a build-id available so we can use it on error messages
/// and in the emitted output of the compiler.
bool get hasBuildId => buildId != _UNDETERMINED_BUILD_ID;
/// Location where to generate a map containing details of how deferred
/// libraries are subdivided.
final Uri deferredMapUri;
/// Whether to disable inlining during the backend optimizations.
// 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;
/// Whether to disable global type inference.
final bool disableTypeInference;
/// Whether to emit a .json file with a summary of the information used by the
/// compiler during optimization. This includes resolution details,
/// dependencies between elements, results of type inference, and the output
/// code for each function.
final bool dumpInfo;
/// Whether we allow passing an extra argument to `assert`, containing a
/// reason for why an assertion fails. (experimental)
final bool enableAssertMessage;
/// Whether to enable the experimental conditional directives feature.
final bool enableConditionalDirectives;
/// Whether the user specified a flag to allow the use of dart:mirrors. This
/// silences a warning produced by the compiler.
final bool enableExperimentalMirrors;
/// Whether to enable minification
// TODO(sigmund): rename to minify
final bool enableMinification;
/// Whether to model which native classes are live based on annotations on the
/// core libraries. If false, all native classes will be included by default.
final bool enableNativeLiveTypeAnalysis;
/// Whether to generate code containing checked-mode assignability checks.
final bool enableTypeAssertions;
/// Whether to generate code containing user's `assert` statements.
final bool enableUserAssertions;
/// Whether to generate output even when there are compile-time errors.
final bool generateCodeWithCompileTimeErrors;
/// Whether to generate a source-map file together with the output program.
final bool generateSourceMap;
/// Whether some values are cached for reuse in incremental compilation.
/// Incremental compilation allows calling `Compiler.run` more than once
/// (experimental).
final bool hasIncrementalSupport;
/// URI of the main output if the compiler is generating source maps.
final Uri outputUri;
/// Location of the platform configuration file.
final Uri platformConfigUri;
/// Whether to emit URIs in the reflection metadata.
final bool preserveUris;
/// URI where the compiler should generate the output source map file.
final Uri sourceMapUri;
/// The compiler is run from the build bot.
final bool testMode;
/// Whether to trust JS-interop annotations. (experimental)
final bool trustJSInteropTypeAnnotations;
/// Whether to trust primitive types during inference and optimizations.
final bool trustPrimitives;
/// Whether to trust type annotations during inference and optimizations.
final bool trustTypeAnnotations;
/// Whether to generate code compliant with content security policy (CSP).
final bool useContentSecurityPolicy;
/// Use the experimental CPS based backend.
final bool useCpsIr;
/// When obfuscating for minification, whether to use the frequency of a name
/// as an heuristic to pick shorter names.
final bool useFrequencyNamer;
/// Whether to use the new source-information implementation for source-maps.
/// (experimental)
final bool useNewSourceInfo;
/// Whether the user requested to use the fast startup emitter. The full
/// emitter might still be used if the program uses dart:mirrors.
final bool useStartupEmitter;
/// Enable verbose printing during compilation. Includes progress messages
/// during each phase and a time-breakdown between phases at the end.
final bool verbose;
// -------------------------------------------------
// Options for deprecated features
// -------------------------------------------------
// TODO(sigmund): delete these as we delete the underlying features
/// Whether to preserve comments while scanning (only use for dart:mirrors).
final bool preserveComments;
/// Whether to emit JavaScript (false enables dart2dart).
final bool emitJavaScript;
/// When using dart2dart, whether to use the multi file format.
final bool dart2dartMultiFile;
/// Strip option used by dart2dart.
final List<String> strips;
/// Create an options object by parsing flags from [options].
factory CompilerOptions.parse(
{Uri entryPoint,
Uri libraryRoot,
Uri packageRoot,
Uri packageConfig,
PackagesDiscoveryProvider packagesDiscoveryProvider,
Map<String, dynamic> environment: const <String, dynamic>{},
List<String> options}) {
return new CompilerOptions(
entryPoint: entryPoint,
libraryRoot: libraryRoot,
packageRoot: packageRoot,
packageConfig: packageConfig,
packagesDiscoveryProvider: packagesDiscoveryProvider,
environment: environment,
allowMockCompilation: _hasOption(options, Flags.allowMockCompilation),
allowNativeExtensions: _hasOption(options, Flags.allowNativeExtensions),
analyzeAll: _hasOption(options, Flags.analyzeAll),
analyzeMain: _hasOption(options, Flags.analyzeMain),
analyzeOnly: _hasOption(options, Flags.analyzeOnly),
analyzeSignaturesOnly: _hasOption(options, Flags.analyzeSignaturesOnly),
buildId: _extractStringOption(
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)),
disableInlining: _hasOption(options, Flags.disableInlining),
disableTypeInference: _hasOption(options, Flags.disableTypeInference),
dumpInfo: _hasOption(options, Flags.dumpInfo),
emitJavaScript: !(_hasOption(options, '--output-type=dart') ||
_hasOption(options, '--output-type=dart-multi')),
enableAssertMessage: _hasOption(options, Flags.enableAssertMessage),
enableConditionalDirectives:
_hasOption(options, Flags.conditionalDirectives),
enableExperimentalMirrors:
_hasOption(options, Flags.enableExperimentalMirrors),
enableMinification: _hasOption(options, Flags.minify),
enableNativeLiveTypeAnalysis:
!_hasOption(options, Flags.disableNativeLiveTypeAnalysis),
enableTypeAssertions: _hasOption(options, Flags.enableCheckedMode),
enableUserAssertions: _hasOption(options, Flags.enableCheckedMode),
generateCodeWithCompileTimeErrors:
_hasOption(options, Flags.generateCodeWithCompileTimeErrors),
generateSourceMap: !_hasOption(options, Flags.noSourceMaps),
hasIncrementalSupport: _forceIncrementalSupport ||
_hasOption(options, Flags.incrementalSupport),
outputUri: _extractUriOption(options, '--out='),
platformConfigUri: _resolvePlatformConfigFromOptions(
libraryRoot, options),
preserveComments: _hasOption(options, Flags.preserveComments),
preserveUris: _hasOption(options, Flags.preserveUris),
sourceMapUri: _extractUriOption(options, '--source-map='),
strips: _extractCsvOption(options, '--force-strip='),
testMode: _hasOption(options, Flags.testMode),
trustJSInteropTypeAnnotations:
_hasOption(options, Flags.trustJSInteropTypeAnnotations),
trustPrimitives: _hasOption(options, Flags.trustPrimitives),
trustTypeAnnotations: _hasOption(options, Flags.trustTypeAnnotations),
useContentSecurityPolicy:
_hasOption(options, Flags.useContentSecurityPolicy),
useCpsIr: _hasOption(options, Flags.useCpsIr),
useFrequencyNamer:
!_hasOption(options, Flags.noFrequencyBasedMinification),
useNewSourceInfo: _hasOption(options, Flags.useNewSourceInfo),
useStartupEmitter: _hasOption(options, Flags.fastStartup),
verbose: _hasOption(options, Flags.verbose));
}
/// Creates an option object for the compiler.
///
/// This validates and normalizes dependent options to be consistent. For
/// example, if [analyzeAll] is true, the resulting options object will also
/// have [analyzeOnly] as true.
factory CompilerOptions(
{Uri entryPoint,
Uri libraryRoot,
Uri packageRoot,
Uri packageConfig,
PackagesDiscoveryProvider packagesDiscoveryProvider,
Map<String, dynamic> environment: const <String, dynamic>{},
bool allowMockCompilation: false,
bool allowNativeExtensions: false,
bool analyzeAll: false,
bool analyzeMain: false,
bool analyzeOnly: false,
bool analyzeSignaturesOnly: false,
String buildId: _UNDETERMINED_BUILD_ID,
bool dart2dartMultiFile: false,
Uri deferredMapUri: null,
DiagnosticOptions diagnosticOptions: const DiagnosticOptions(),
bool disableInlining: false,
bool disableTypeInference: false,
bool dumpInfo: false,
bool emitJavaScript: true,
bool enableAssertMessage: false,
bool enableConditionalDirectives: false,
bool enableExperimentalMirrors: false,
bool enableMinification: false,
bool enableNativeLiveTypeAnalysis: true,
bool enableTypeAssertions: false,
bool enableUserAssertions: false,
bool generateCodeWithCompileTimeErrors: false,
bool generateSourceMap: true,
bool hasIncrementalSupport: false,
Uri outputUri: null,
Uri platformConfigUri: null,
bool preserveComments: false,
bool preserveUris: false,
Uri sourceMapUri: null,
List<String> strips: const [],
bool testMode: false,
bool trustJSInteropTypeAnnotations: false,
bool trustPrimitives: false,
bool trustTypeAnnotations: false,
bool useContentSecurityPolicy: false,
bool useCpsIr: false,
bool useFrequencyNamer: true,
bool useNewSourceInfo: false,
bool useStartupEmitter: false,
bool verbose: false}) {
// TODO(sigmund): should entrypoint be here? should we validate it is not
// null? In unittests we use the same compiler to analyze or build multiple
// entrypoints.
if (libraryRoot == null) {
throw new ArgumentError("[libraryRoot] is null.");
}
if (!libraryRoot.path.endsWith("/")) {
throw new ArgumentError("[libraryRoot] must end with a /");
}
if (packageRoot != null && packageConfig != null) {
throw new ArgumentError("Only one of [packageRoot] or [packageConfig] "
"may be given.");
}
if (packageRoot != null && !packageRoot.path.endsWith("/")) {
throw new ArgumentError("[packageRoot] must end with a /");
}
if (!analyzeOnly) {
if (allowNativeExtensions) {
throw new ArgumentError(
"${Flags.allowNativeExtensions} is only supported in combination "
"with ${Flags.analyzeOnly}");
}
}
return new CompilerOptions._(entryPoint, libraryRoot, packageRoot,
packageConfig, packagesDiscoveryProvider, environment,
allowMockCompilation: allowMockCompilation,
allowNativeExtensions: allowNativeExtensions,
analyzeAll: analyzeAll,
analyzeMain: analyzeMain,
analyzeOnly: analyzeOnly || analyzeSignaturesOnly || analyzeAll,
analyzeSignaturesOnly: analyzeSignaturesOnly,
buildId: buildId,
dart2dartMultiFile: dart2dartMultiFile,
deferredMapUri: deferredMapUri,
diagnosticOptions: diagnosticOptions,
disableInlining: disableInlining || hasIncrementalSupport,
disableTypeInference: disableTypeInference || !emitJavaScript,
dumpInfo: dumpInfo,
emitJavaScript: emitJavaScript,
enableAssertMessage: enableAssertMessage,
enableConditionalDirectives: enableConditionalDirectives,
enableExperimentalMirrors: enableExperimentalMirrors,
enableMinification: enableMinification,
enableNativeLiveTypeAnalysis: enableNativeLiveTypeAnalysis,
enableTypeAssertions: enableTypeAssertions,
enableUserAssertions: enableUserAssertions,
generateCodeWithCompileTimeErrors: generateCodeWithCompileTimeErrors,
generateSourceMap: generateSourceMap,
hasIncrementalSupport: hasIncrementalSupport,
outputUri: outputUri,
platformConfigUri: platformConfigUri ?? _resolvePlatformConfig(
libraryRoot, null, !emitJavaScript, const []),
preserveComments: preserveComments,
preserveUris: preserveUris,
sourceMapUri: sourceMapUri,
strips: strips,
testMode: testMode,
trustJSInteropTypeAnnotations: trustJSInteropTypeAnnotations,
trustPrimitives: trustPrimitives,
trustTypeAnnotations: trustTypeAnnotations,
useContentSecurityPolicy: useContentSecurityPolicy,
useCpsIr: useCpsIr,
useFrequencyNamer: useFrequencyNamer,
useNewSourceInfo: useNewSourceInfo,
useStartupEmitter: useStartupEmitter,
verbose: verbose);
}
CompilerOptions._(this.entryPoint, this.libraryRoot, this.packageRoot,
this.packageConfig, this.packagesDiscoveryProvider, this.environment,
{this.allowMockCompilation: false,
this.allowNativeExtensions: false,
this.analyzeAll: false,
this.analyzeMain: false,
this.analyzeOnly: false,
this.analyzeSignaturesOnly: false,
this.buildId: _UNDETERMINED_BUILD_ID,
this.dart2dartMultiFile: false,
this.deferredMapUri: null,
this.diagnosticOptions: null,
this.disableInlining: false,
this.disableTypeInference: false,
this.dumpInfo: false,
this.emitJavaScript: true,
this.enableAssertMessage: false,
this.enableConditionalDirectives: false,
this.enableExperimentalMirrors: false,
this.enableMinification: false,
this.enableNativeLiveTypeAnalysis: false,
this.enableTypeAssertions: false,
this.enableUserAssertions: false,
this.generateCodeWithCompileTimeErrors: false,
this.generateSourceMap: true,
this.hasIncrementalSupport: false,
this.outputUri: null,
this.platformConfigUri: null,
this.preserveComments: false,
this.preserveUris: false,
this.sourceMapUri: null,
this.strips: const [],
this.testMode: false,
this.trustJSInteropTypeAnnotations: false,
this.trustPrimitives: false,
this.trustTypeAnnotations: false,
this.useContentSecurityPolicy: false,
this.useCpsIr: false,
this.useFrequencyNamer: false,
this.useNewSourceInfo: false,
this.useStartupEmitter: false,
this.verbose: false});
}
/// Returns a future that completes to a [CompilationResult] when the Dart
/// sources in [options] have been compiled.
///
@ -547,86 +126,3 @@ Future<CompilationResult> compile(
});
}
String _extractStringOption(
List<String> options, String prefix, String defaultValue) {
for (String option in options) {
if (option.startsWith(prefix)) {
return option.substring(prefix.length);
}
}
return defaultValue;
}
Uri _extractUriOption(List<String> options, String prefix) {
var option = _extractStringOption(options, prefix, null);
return (option == null) ? null : Uri.parse(option);
}
// CSV: Comma separated values.
List<String> _extractCsvOption(List<String> options, String prefix) {
for (String option in options) {
if (option.startsWith(prefix)) {
return option.substring(prefix.length).split(',');
}
}
return const <String>[];
}
/// 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.
List<String> _extractOptionalCsvOption(List<String> options, String flag) {
String prefix = '$flag=';
for (String option in options) {
if (option == flag) {
return const <String>[];
}
if (option.startsWith(flag)) {
return option.substring(prefix.length).split(',');
}
}
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) {
if (platformConfigPath != null) {
return libraryRoot.resolve(platformConfigPath);
} else if (isDart2Dart) {
return libraryRoot.resolve(_dart2dartPlatform);
} else {
if (categories.length == 0) {
return libraryRoot.resolve(_clientPlatform);
}
assert(categories.length <= 2);
if (categories.contains("Client")) {
if (categories.contains("Server")) {
return libraryRoot.resolve(_sharedPlatform);
}
return libraryRoot.resolve(_clientPlatform);
}
assert(categories.contains("Server"));
return libraryRoot.resolve(_serverPlatform);
}
}
bool _hasOption(List<String> options, String option) {
return options.indexOf(option) >= 0;
}
/// Locations of the platform descriptor files relative to the library root.
const String _clientPlatform = "lib/dart_client.platform";
const String _serverPlatform = "lib/dart_server.platform";
const String _sharedPlatform = "lib/dart_shared.platform";
const String _dart2dartPlatform = "lib/dart2dart.platform";
const String _UNDETERMINED_BUILD_ID = "build number could not be determined";
const bool _forceIncrementalSupport =
const bool.fromEnvironment('DART2JS_EXPERIMENTAL_INCREMENTAL_SUPPORT');

View file

@ -16,18 +16,17 @@ import 'package:package_config/src/util.dart' show
checkValidPackageUri;
import '../compiler_new.dart' as api;
import 'commandline_options.dart';
import 'common.dart';
import 'common/tasks.dart' show
GenericTask;
import 'compiler.dart';
import 'diagnostics/diagnostic_listener.dart' show
DiagnosticOptions;
import 'diagnostics/messages.dart' show
Message;
import 'elements/elements.dart' as elements;
import 'environment.dart';
import 'io/source_file.dart';
import 'options.dart' show
CompilerOptions;
import 'platform_configuration.dart' as platform_configuration;
import 'script.dart';
@ -52,7 +51,7 @@ class CompilerImpl extends Compiler {
Uri get libraryRoot => options.platformConfigUri.resolve(".");
CompilerImpl(this.provider, api.CompilerOutput outputProvider,
this.handler, api.CompilerOptions options)
this.handler, CompilerOptions options)
: super(options: options, outputProvider: outputProvider,
environment: new _Environment(options.environment)) {
_Environment env = environment;

View file

@ -29,6 +29,8 @@ import '../elements/elements.dart' show
TypeVariableElement;
import '../enqueue.dart' show
ResolutionEnqueuer;
import '../options.dart' show
ParserOptions;
import '../parser/element_listener.dart' show
ScannerOptions;
import '../tree/tree.dart' show
@ -228,4 +230,5 @@ abstract class Parsing {
void parsePatchClass(ClassElement cls);
measure(f());
ScannerOptions getScannerOptionsFor(Element element);
ParserOptions get parserOptions;
}

View file

@ -50,7 +50,7 @@ import 'dart_types.dart' show
import 'deferred_load.dart' show DeferredLoadTask, OutputUnit;
import 'diagnostics/code_location.dart';
import 'diagnostics/diagnostic_listener.dart' show
DiagnosticOptions;
DiagnosticReporter;
import 'diagnostics/invariant.dart' show
REPORT_EXCESS_RESOLUTION;
import 'diagnostics/messages.dart' show
@ -95,6 +95,10 @@ import 'common/names.dart' show
import 'null_compiler_output.dart' show
NullCompilerOutput,
NullSink;
import 'options.dart' show
CompilerOptions,
DiagnosticOptions,
ParserOptions;
import 'parser/diet_parser_task.dart' show
DietParserTask;
import 'parser/element_listener.dart' show
@ -191,7 +195,7 @@ abstract class Compiler implements LibraryLoaderListener {
new ResolutionRegistry(null, new TreeElementMapping(null));
/// Options provided from command-line arguments.
final api.CompilerOptions options;
final CompilerOptions options;
/**
* If true, stop compilation after type inference is complete. Used for
@ -356,19 +360,17 @@ abstract class Compiler implements LibraryLoaderListener {
compilationFailedInternal = value;
}
Compiler({api.CompilerOptions options,
Compiler({CompilerOptions options,
api.CompilerOutput outputProvider,
this.environment: const _EmptyEnvironment()})
: this.options = options,
this.cacheStrategy = new CacheStrategy(options.hasIncrementalSupport),
this.userOutputProvider = outputProvider == null
? const NullCompilerOutput() : outputProvider {
world = new World(this);
// TODO(johnniwinther): Initialize core types in [initializeCoreClasses] and
// make its field final.
_reporter = new _CompilerDiagnosticReporter(
this, options.diagnosticOptions);
_reporter = new _CompilerDiagnosticReporter(this, options);
_parsing = new _CompilerParsing(this);
_resolution = new _CompilerResolution(this);
_coreTypes = new _CompilerCoreTypes(_resolution);
@ -399,8 +401,7 @@ abstract class Compiler implements LibraryLoaderListener {
}
tasks = [
dietParser = new DietParserTask(
this, enableConditionalDirectives: options.enableConditionalDirectives),
dietParser = new DietParserTask(this, parsing.parserOptions),
scanner = createScannerTask(),
serialization = new SerializationTask(this),
libraryLoader = new LibraryLoaderTask(this,
@ -410,10 +411,8 @@ abstract class Compiler implements LibraryLoaderListener {
this.serialization,
this,
environment),
parser = new ParserTask(this,
enableConditionalDirectives: options.enableConditionalDirectives),
patchParser = new PatchParserTask(
this, enableConditionalDirectives: options.enableConditionalDirectives),
parser = new ParserTask(this, parsing.parserOptions),
patchParser = new PatchParserTask(this, parsing.parserOptions),
resolver = createResolverTask(),
closureToClassMapper = new closureMapping.ClosureTask(this),
checker = new TypeCheckerTask(this),
@ -2111,10 +2110,10 @@ class _CompilerParsing implements Parsing {
});
}
ScannerOptions getScannerOptionsFor(Element element) {
return new ScannerOptions(
canUseNative: compiler.backend.canLibraryUseNative(element.library));
}
ScannerOptions getScannerOptionsFor(Element element) =>
new ScannerOptions.from(compiler, element.library);
ParserOptions get parserOptions => compiler.options;
}
class GlobalDependencyRegistry extends EagerRegistry {

View file

@ -4,6 +4,8 @@
library dart2js.diagnostic_listener;
import '../options.dart' show
DiagnosticOptions;
import 'source_span.dart' show
SourceSpan;
import 'spannable.dart' show
@ -12,57 +14,9 @@ import '../elements/elements.dart' show
Element;
import 'messages.dart';
class DiagnosticOptions {
/// Emit terse diagnostics without howToFix.
final bool terseDiagnostics;
/// 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;
/// If `true`, warnings are not reported.
final bool suppressWarnings;
/// If `true`, warnings cause the compilation to fail.
final bool fatalWarnings;
/// If `true`, hints are not reported.
final bool suppressHints;
const DiagnosticOptions({
this.suppressWarnings: false,
this.fatalWarnings: false,
this.suppressHints: false,
this.terseDiagnostics: false,
List<String> shownPackageWarnings: null})
: _shownPackageWarnings = shownPackageWarnings;
/// Returns `true` if warnings and hints are shown for all packages.
bool get showAllPackageWarnings {
return _shownPackageWarnings != null && _shownPackageWarnings.isEmpty;
}
/// 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;
}
}
// TODO(johnniwinther): Rename and cleanup this interface. Add severity enum.
abstract class DiagnosticReporter {
DiagnosticOptions get options => const DiagnosticOptions();
DiagnosticOptions get options;
// TODO(karlklose): rename log to something like reportInfo.
void log(message);

View file

@ -9,7 +9,7 @@ import 'dart:async';
import 'source_mirrors.dart';
import 'dart2js_mirrors.dart' show Dart2JsMirrorSystem;
import '../../compiler.dart' as api;
import '../../compiler_new.dart' as new_api;
import '../options.dart' show CompilerOptions;
import '../apiimpl.dart' as apiimpl;
import '../compiler.dart' show Compiler;
import '../old_to_new_api.dart';
@ -59,7 +59,7 @@ Future<MirrorSystem> analyze(List<Uri> libraries,
new LegacyCompilerInput(inputProvider),
new LegacyCompilerOutput(),
new LegacyCompilerDiagnostics(internalDiagnosticHandler),
new new_api.CompilerOptions.parse(
new CompilerOptions.parse(
libraryRoot: libraryRoot,
packageRoot: packageRoot,
options: options,

View file

@ -0,0 +1,597 @@
// 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.
library dart2js.src.options;
import 'commandline_options.dart' show Flags;
import '../compiler.dart' show PackagesDiscoveryProvider;
/// Options used for parsing.
///
/// Use this to conditionally support certain constructs, e.g.,
/// experimental ones.
abstract class ParserOptions {
const ParserOptions();
/// Support conditional directives, e.g., configurable imports.
bool get enableConditionalDirectives;
}
/// Options used for controlling diagnostic messages.
abstract class DiagnosticOptions {
const DiagnosticOptions();
/// If `true`, warnings cause the compilation to fail.
bool get fatalWarnings;
/// Emit terse diagnostics without howToFix.
bool get terseDiagnostics;
/// If `true`, warnings are not reported.
bool get suppressWarnings;
/// If `true`, hints are not reported.
bool get suppressHints;
/// 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;
/// Returns `true` if warnings should be should for [uri].
bool showPackageWarningsFor(Uri uri);
}
/// 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;
/// Root location where SDK libraries are found.
final Uri libraryRoot;
/// Package root location.
///
/// If not null then [packageConfig] should be null.
final Uri packageRoot;
/// Location of the package configuration file.
///
/// If not null then [packageRoot] should be null.
final Uri packageConfig;
// TODO(sigmund): Move out of here, maybe to CompilerInput. Options should not
// hold code, just configuration options.
final PackagesDiscoveryProvider packagesDiscoveryProvider;
/// Resolved constant "environment" values passed to the compiler via the `-D`
/// flags.
final Map<String, dynamic> environment;
/// Whether we allow mocking compilation of libraries such as dart:io and
/// dart:html for unit testing purposes.
final bool allowMockCompilation;
/// Whether the native extension syntax is supported by the frontend.
final bool allowNativeExtensions;
/// Whether to resolve all functions in the program, not just those reachable
/// from main. This implies [analyzeOnly] is true as well.
final bool analyzeAll;
/// Whether to disable tree-shaking for the main script. This marks all
/// functions in the main script as reachable (not just a function named
/// `main`).
// TODO(sigmund): rename. The current name seems to indicate that only the
// main function is retained, which is the opposite of what this does.
final bool analyzeMain;
/// Whether to run the compiler just for the purpose of analysis. That is, to
/// run resolution and type-checking alone, but otherwise do not generate any
/// code.
final bool analyzeOnly;
/// Whether to skip analysis of method bodies and field initializers. Implies
/// [analyzeOnly].
final bool analyzeSignaturesOnly;
/// ID associated with this sdk build.
final String buildId;
/// Whether there is a build-id available so we can use it on error messages
/// and in the emitted output of the compiler.
bool get hasBuildId => buildId != _UNDETERMINED_BUILD_ID;
/// Location where to generate a map containing details of how deferred
/// libraries are subdivided.
final Uri deferredMapUri;
/// Whether to disable inlining during the backend optimizations.
// TODO(sigmund): negate, so all flags are positive
final bool disableInlining;
/// 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;
/// Whether to emit a .json file with a summary of the information used by the
/// compiler during optimization. This includes resolution details,
/// dependencies between elements, results of type inference, and the output
/// code for each function.
final bool dumpInfo;
/// Whether we allow passing an extra argument to `assert`, containing a
/// reason for why an assertion fails. (experimental)
final bool enableAssertMessage;
/// Whether to enable the experimental conditional directives feature.
final bool enableConditionalDirectives;
/// Whether the user specified a flag to allow the use of dart:mirrors. This
/// silences a warning produced by the compiler.
final bool enableExperimentalMirrors;
/// Whether to enable minification
// TODO(sigmund): rename to minify
final bool enableMinification;
/// Whether to model which native classes are live based on annotations on the
/// core libraries. If false, all native classes will be included by default.
final bool enableNativeLiveTypeAnalysis;
/// Whether to generate code containing checked-mode assignability checks.
final bool enableTypeAssertions;
/// Whether to generate code containing user's `assert` statements.
final bool enableUserAssertions;
/// Whether to generate output even when there are compile-time errors.
final bool generateCodeWithCompileTimeErrors;
/// Whether to generate a source-map file together with the output program.
final bool generateSourceMap;
/// Whether some values are cached for reuse in incremental compilation.
/// Incremental compilation allows calling `Compiler.run` more than once
/// (experimental).
final bool hasIncrementalSupport;
/// URI of the main output if the compiler is generating source maps.
final Uri outputUri;
/// Location of the platform configuration file.
final Uri platformConfigUri;
/// Whether to emit URIs in the reflection metadata.
final bool preserveUris;
/// URI where the compiler should generate the output source map file.
final Uri sourceMapUri;
/// The compiler is run from the build bot.
final bool testMode;
/// Whether to trust JS-interop annotations. (experimental)
final bool trustJSInteropTypeAnnotations;
/// Whether to trust primitive types during inference and optimizations.
final bool trustPrimitives;
/// Whether to trust type annotations during inference and optimizations.
final bool trustTypeAnnotations;
/// Whether to generate code compliant with content security policy (CSP).
final bool useContentSecurityPolicy;
/// Use the experimental CPS based backend.
final bool useCpsIr;
/// When obfuscating for minification, whether to use the frequency of a name
/// as an heuristic to pick shorter names.
final bool useFrequencyNamer;
/// Whether to use the new source-information implementation for source-maps.
/// (experimental)
final bool useNewSourceInfo;
/// Whether the user requested to use the fast startup emitter. The full
/// emitter might still be used if the program uses dart:mirrors.
final bool useStartupEmitter;
/// Enable verbose printing during compilation. Includes progress messages
/// during each phase and a time-breakdown between phases at the end.
final bool verbose;
// -------------------------------------------------
// Options for deprecated features
// -------------------------------------------------
// TODO(sigmund): delete these as we delete the underlying features
/// Whether to preserve comments while scanning (only use for dart:mirrors).
final bool preserveComments;
/// Whether to emit JavaScript (false enables dart2dart).
final bool emitJavaScript;
/// When using dart2dart, whether to use the multi file format.
final bool dart2dartMultiFile;
/// Strip option used by dart2dart.
final List<String> strips;
/// Create an options object by parsing flags from [options].
factory CompilerOptions.parse(
{Uri entryPoint,
Uri libraryRoot,
Uri packageRoot,
Uri packageConfig,
PackagesDiscoveryProvider packagesDiscoveryProvider,
Map<String, dynamic> environment: const <String, dynamic>{},
List<String> options}) {
return new CompilerOptions(
entryPoint: entryPoint,
libraryRoot: libraryRoot,
packageRoot: packageRoot,
packageConfig: packageConfig,
packagesDiscoveryProvider: packagesDiscoveryProvider,
environment: environment,
allowMockCompilation: _hasOption(options, Flags.allowMockCompilation),
allowNativeExtensions: _hasOption(options, Flags.allowNativeExtensions),
analyzeAll: _hasOption(options, Flags.analyzeAll),
analyzeMain: _hasOption(options, Flags.analyzeMain),
analyzeOnly: _hasOption(options, Flags.analyzeOnly),
analyzeSignaturesOnly: _hasOption(options, Flags.analyzeSignaturesOnly),
buildId: _extractStringOption(
options, '--build-id=', _UNDETERMINED_BUILD_ID),
dart2dartMultiFile: _hasOption(options, '--output-type=dart-multi'),
deferredMapUri: _extractUriOption(options, '--deferred-map='),
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),
emitJavaScript: !(_hasOption(options, '--output-type=dart') ||
_hasOption(options, '--output-type=dart-multi')),
enableAssertMessage: _hasOption(options, Flags.enableAssertMessage),
enableConditionalDirectives:
_hasOption(options, Flags.conditionalDirectives),
enableExperimentalMirrors:
_hasOption(options, Flags.enableExperimentalMirrors),
enableMinification: _hasOption(options, Flags.minify),
enableNativeLiveTypeAnalysis:
!_hasOption(options, Flags.disableNativeLiveTypeAnalysis),
enableTypeAssertions: _hasOption(options, Flags.enableCheckedMode),
enableUserAssertions: _hasOption(options, Flags.enableCheckedMode),
generateCodeWithCompileTimeErrors:
_hasOption(options, Flags.generateCodeWithCompileTimeErrors),
generateSourceMap: !_hasOption(options, Flags.noSourceMaps),
hasIncrementalSupport: _forceIncrementalSupport ||
_hasOption(options, Flags.incrementalSupport),
outputUri: _extractUriOption(options, '--out='),
platformConfigUri:
_resolvePlatformConfigFromOptions(libraryRoot, options),
preserveComments: _hasOption(options, Flags.preserveComments),
preserveUris: _hasOption(options, Flags.preserveUris),
sourceMapUri: _extractUriOption(options, '--source-map='),
strips: _extractCsvOption(options, '--force-strip='),
testMode: _hasOption(options, Flags.testMode),
trustJSInteropTypeAnnotations:
_hasOption(options, Flags.trustJSInteropTypeAnnotations),
trustPrimitives: _hasOption(options, Flags.trustPrimitives),
trustTypeAnnotations: _hasOption(options, Flags.trustTypeAnnotations),
useContentSecurityPolicy:
_hasOption(options, Flags.useContentSecurityPolicy),
useCpsIr: _hasOption(options, Flags.useCpsIr),
useFrequencyNamer:
!_hasOption(options, Flags.noFrequencyBasedMinification),
useNewSourceInfo: _hasOption(options, Flags.useNewSourceInfo),
useStartupEmitter: _hasOption(options, Flags.fastStartup),
verbose: _hasOption(options, Flags.verbose));
}
/// Creates an option object for the compiler.
///
/// This validates and normalizes dependent options to be consistent. For
/// example, if [analyzeAll] is true, the resulting options object will also
/// have [analyzeOnly] as true.
factory CompilerOptions(
{Uri entryPoint,
Uri libraryRoot,
Uri packageRoot,
Uri packageConfig,
PackagesDiscoveryProvider packagesDiscoveryProvider,
Map<String, dynamic> environment: const <String, dynamic>{},
bool allowMockCompilation: false,
bool allowNativeExtensions: false,
bool analyzeAll: false,
bool analyzeMain: false,
bool analyzeOnly: false,
bool analyzeSignaturesOnly: false,
String buildId: _UNDETERMINED_BUILD_ID,
bool dart2dartMultiFile: false,
Uri deferredMapUri: null,
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,
bool emitJavaScript: true,
bool enableAssertMessage: false,
bool enableConditionalDirectives: false,
bool enableExperimentalMirrors: false,
bool enableMinification: false,
bool enableNativeLiveTypeAnalysis: true,
bool enableTypeAssertions: false,
bool enableUserAssertions: false,
bool generateCodeWithCompileTimeErrors: false,
bool generateSourceMap: true,
bool hasIncrementalSupport: false,
Uri outputUri: null,
Uri platformConfigUri: null,
bool preserveComments: false,
bool preserveUris: false,
Uri sourceMapUri: null,
List<String> strips: const [],
bool testMode: false,
bool trustJSInteropTypeAnnotations: false,
bool trustPrimitives: false,
bool trustTypeAnnotations: false,
bool useContentSecurityPolicy: false,
bool useCpsIr: false,
bool useFrequencyNamer: true,
bool useNewSourceInfo: false,
bool useStartupEmitter: false,
bool verbose: false}) {
// TODO(sigmund): should entrypoint be here? should we validate it is not
// null? In unittests we use the same compiler to analyze or build multiple
// entrypoints.
if (libraryRoot == null) {
throw new ArgumentError("[libraryRoot] is null.");
}
if (!libraryRoot.path.endsWith("/")) {
throw new ArgumentError("[libraryRoot] must end with a /");
}
if (packageRoot != null && packageConfig != null) {
throw new ArgumentError("Only one of [packageRoot] or [packageConfig] "
"may be given.");
}
if (packageRoot != null && !packageRoot.path.endsWith("/")) {
throw new ArgumentError("[packageRoot] must end with a /");
}
if (!analyzeOnly) {
if (allowNativeExtensions) {
throw new ArgumentError(
"${Flags.allowNativeExtensions} is only supported in combination "
"with ${Flags.analyzeOnly}");
}
}
return new CompilerOptions._(entryPoint, libraryRoot, packageRoot,
packageConfig, packagesDiscoveryProvider, environment,
allowMockCompilation: allowMockCompilation,
allowNativeExtensions: allowNativeExtensions,
analyzeAll: analyzeAll,
analyzeMain: analyzeMain,
analyzeOnly: analyzeOnly || analyzeSignaturesOnly || analyzeAll,
analyzeSignaturesOnly: analyzeSignaturesOnly,
buildId: buildId,
dart2dartMultiFile: dart2dartMultiFile,
deferredMapUri: deferredMapUri,
fatalWarnings: fatalWarnings,
terseDiagnostics: terseDiagnostics,
suppressWarnings: suppressWarnings,
suppressHints: suppressHints,
shownPackageWarnings: shownPackageWarnings,
disableInlining: disableInlining || hasIncrementalSupport,
disableTypeInference: disableTypeInference || !emitJavaScript,
dumpInfo: dumpInfo,
emitJavaScript: emitJavaScript,
enableAssertMessage: enableAssertMessage,
enableConditionalDirectives: enableConditionalDirectives,
enableExperimentalMirrors: enableExperimentalMirrors,
enableMinification: enableMinification,
enableNativeLiveTypeAnalysis: enableNativeLiveTypeAnalysis,
enableTypeAssertions: enableTypeAssertions,
enableUserAssertions: enableUserAssertions,
generateCodeWithCompileTimeErrors: generateCodeWithCompileTimeErrors,
generateSourceMap: generateSourceMap,
hasIncrementalSupport: hasIncrementalSupport,
outputUri: outputUri,
platformConfigUri: platformConfigUri ??
_resolvePlatformConfig(
libraryRoot, null, !emitJavaScript, const []),
preserveComments: preserveComments,
preserveUris: preserveUris,
sourceMapUri: sourceMapUri,
strips: strips,
testMode: testMode,
trustJSInteropTypeAnnotations: trustJSInteropTypeAnnotations,
trustPrimitives: trustPrimitives,
trustTypeAnnotations: trustTypeAnnotations,
useContentSecurityPolicy: useContentSecurityPolicy,
useCpsIr: useCpsIr,
useFrequencyNamer: useFrequencyNamer,
useNewSourceInfo: useNewSourceInfo,
useStartupEmitter: useStartupEmitter,
verbose: verbose);
}
CompilerOptions._(this.entryPoint, this.libraryRoot, this.packageRoot,
this.packageConfig, this.packagesDiscoveryProvider, this.environment,
{this.allowMockCompilation: false,
this.allowNativeExtensions: false,
this.analyzeAll: false,
this.analyzeMain: false,
this.analyzeOnly: false,
this.analyzeSignaturesOnly: false,
this.buildId: _UNDETERMINED_BUILD_ID,
this.dart2dartMultiFile: false,
this.deferredMapUri: 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,
this.emitJavaScript: true,
this.enableAssertMessage: false,
this.enableConditionalDirectives: false,
this.enableExperimentalMirrors: false,
this.enableMinification: false,
this.enableNativeLiveTypeAnalysis: false,
this.enableTypeAssertions: false,
this.enableUserAssertions: false,
this.generateCodeWithCompileTimeErrors: false,
this.generateSourceMap: true,
this.hasIncrementalSupport: false,
this.outputUri: null,
this.platformConfigUri: null,
this.preserveComments: false,
this.preserveUris: false,
this.sourceMapUri: null,
this.strips: const [],
this.testMode: false,
this.trustJSInteropTypeAnnotations: false,
this.trustPrimitives: false,
this.trustTypeAnnotations: false,
this.useContentSecurityPolicy: false,
this.useCpsIr: false,
this.useFrequencyNamer: false,
this.useNewSourceInfo: false,
this.useStartupEmitter: false,
this.verbose: false})
: _shownPackageWarnings = shownPackageWarnings;
/// Returns `true` if warnings and hints are shown for all packages.
bool get showAllPackageWarnings {
return _shownPackageWarnings != null && _shownPackageWarnings.isEmpty;
}
/// 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(
List<String> options, String prefix, String defaultValue) {
for (String option in options) {
if (option.startsWith(prefix)) {
return option.substring(prefix.length);
}
}
return defaultValue;
}
Uri _extractUriOption(List<String> options, String prefix) {
var option = _extractStringOption(options, prefix, null);
return (option == null) ? null : Uri.parse(option);
}
// CSV: Comma separated values.
List<String> _extractCsvOption(List<String> options, String prefix) {
for (String option in options) {
if (option.startsWith(prefix)) {
return option.substring(prefix.length).split(',');
}
}
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.
List<String> _extractOptionalCsvOption(List<String> options, String flag) {
String prefix = '$flag=';
for (String option in options) {
if (option == flag) {
return const <String>[];
}
if (option.startsWith(flag)) {
return option.substring(prefix.length).split(',');
}
}
return null;
}
Uri _resolvePlatformConfig(Uri libraryRoot, String platformConfigPath,
bool isDart2Dart, Iterable<String> categories) {
if (platformConfigPath != null) {
return libraryRoot.resolve(platformConfigPath);
} else if (isDart2Dart) {
return libraryRoot.resolve(_dart2dartPlatform);
} else {
if (categories.length == 0) {
return libraryRoot.resolve(_clientPlatform);
}
assert(categories.length <= 2);
if (categories.contains("Client")) {
if (categories.contains("Server")) {
return libraryRoot.resolve(_sharedPlatform);
}
return libraryRoot.resolve(_clientPlatform);
}
assert(categories.contains("Server"));
return libraryRoot.resolve(_serverPlatform);
}
}
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.
const String _clientPlatform = "lib/dart_client.platform";
const String _serverPlatform = "lib/dart_server.platform";
const String _sharedPlatform = "lib/dart_shared.platform";
const String _dart2dartPlatform = "lib/dart2dart.platform";
const String _UNDETERMINED_BUILD_ID = "build number could not be determined";
const bool _forceIncrementalSupport =
const bool.fromEnvironment('DART2JS_EXPERIMENTAL_INCREMENTAL_SUPPORT');

View file

@ -9,12 +9,14 @@ import '../tokens/token.dart' show
import 'listener.dart' show
Listener;
import '../options.dart' show
ParserOptions;
import 'partial_parser.dart' show
PartialParser;
class ClassElementParser extends PartialParser {
ClassElementParser(Listener listener)
: super(listener, enableConditionalDirectives: false);
ClassElementParser(Listener listener, ParserOptions options)
: super(listener, options);
Token parseClassBody(Token token) => fullParseClassBody(token);
}

View file

@ -19,28 +19,26 @@ import 'listener.dart' show
import 'element_listener.dart' show
ElementListener,
ScannerOptions;
import '../options.dart' show
ParserOptions;
import 'partial_parser.dart' show
PartialParser;
class DietParserTask extends CompilerTask {
final bool _enableConditionalDirectives;
final ParserOptions _parserOptions;
DietParserTask(Compiler compiler, {bool enableConditionalDirectives})
: this._enableConditionalDirectives = enableConditionalDirectives,
super(compiler);
DietParserTask(Compiler compiler, this._parserOptions) : super(compiler);
final String name = 'Diet Parser';
dietParse(CompilationUnitElement compilationUnit, Token tokens) {
measure(() {
Function idGenerator = compiler.getNextFreeClassId;
ScannerOptions scannerOptions = new ScannerOptions(
canUseNative: compiler.backend.canLibraryUseNative(
compilationUnit.library));
ScannerOptions scannerOptions =
new ScannerOptions.from(compiler, compilationUnit.library);
ElementListener listener = new ElementListener(
scannerOptions, compiler.reporter, compilationUnit, idGenerator);
PartialParser parser = new PartialParser(
listener, enableConditionalDirectives: _enableConditionalDirectives);
PartialParser parser = new PartialParser(listener, _parserOptions);
try {
parser.parseUnit(tokens);
} on ParserError catch(_) {

View file

@ -4,6 +4,8 @@
library dart2js.parser.element_listener;
import '../compiler.dart' show
Compiler;
import '../common.dart';
import '../diagnostics/messages.dart' show
MessageTemplate;
@ -57,11 +59,17 @@ typedef int IdGenerator();
/// Options used for scanning.
///
/// Use this to conditionally support special tokens.
///
/// TODO(johnniwinther): This class should be renamed, it is not about options
/// in the same sense as `CompilerOptions` or `DiagnosticOptions`.
class ScannerOptions {
/// If `true` the pseudo keyword `native` is supported.
final bool canUseNative;
const ScannerOptions({this.canUseNative: false});
ScannerOptions.from(Compiler compiler, LibraryElement libraryElement) :
canUseNative = compiler.backend.canLibraryUseNative(libraryElement);
}
/**

View file

@ -4,6 +4,8 @@
library dart2js.parser;
import '../options.dart' show
ParserOptions;
import '../common.dart';
import '../tokens/keyword.dart' show
Keyword;
@ -97,13 +99,12 @@ class FormalParameterType {
*/
class Parser {
final Listener listener;
final ParserOptions parserOptions;
bool mayParseFunctionExpressions = true;
final bool enableConditionalDirectives;
bool asyncAwaitKeywordsEnabled;
Parser(this.listener,
{this.enableConditionalDirectives: false,
this.asyncAwaitKeywordsEnabled: false});
Parser(this.listener, this.parserOptions,
{this.asyncAwaitKeywordsEnabled: false});
Token parseUnit(Token token) {
listener.beginCompilationUnit(token);
@ -180,7 +181,7 @@ class Parser {
Token parseConditionalUris(Token token) {
listener.beginConditionalUris(token);
int count = 0;
if (enableConditionalDirectives) {
if (parserOptions.enableConditionalDirectives) {
while (optional('if', token)) {
count++;
token = parseConditionalUri(token);

View file

@ -11,6 +11,8 @@ import '../compiler.dart' show
Compiler;
import '../elements/modelx.dart' show
ElementX;
import '../options.dart' show
ParserOptions;
import '../tokens/token.dart' show
Token;
import '../tree/tree.dart' show
@ -26,12 +28,9 @@ import 'parser.dart' show
Parser;
class ParserTask extends CompilerTask {
final bool _enableConditionalDirectives;
final ParserOptions parserOptions;
ParserTask(Compiler compiler,
{bool enableConditionalDirectives: false})
: this._enableConditionalDirectives = enableConditionalDirectives,
super(compiler);
ParserTask(Compiler compiler, this.parserOptions) : super(compiler);
String get name => 'Parser';
@ -43,8 +42,7 @@ class ParserTask extends CompilerTask {
return measure(() {
NodeListener listener = new NodeListener(
const ScannerOptions(), reporter, null);
Parser parser = new Parser(
listener, enableConditionalDirectives: _enableConditionalDirectives);
Parser parser = new Parser(listener, parserOptions);
try {
parser.parseUnit(token);
} on ParserError catch(_) {

View file

@ -427,7 +427,7 @@ class PartialClassElement extends ClassElementX with PartialElement {
parsing.measure(() {
MemberListener listener = new MemberListener(
parsing.getScannerOptionsFor(this), reporter, this);
Parser parser = new ClassElementParser(listener);
Parser parser = new ClassElementParser(listener, parsing.parserOptions);
try {
Token token = parser.parseTopLevelDeclaration(beginToken);
assert(identical(token, endToken.next));
@ -491,7 +491,7 @@ Node parse(
if (partial.hasParseError) {
listener.suppressParseErrors = true;
}
doParse(new Parser(listener));
doParse(new Parser(listener, parsing.parserOptions));
} on ParserError catch (e) {
partial.hasParseError = true;
return new ErrorNode(element.position, e.reason);

View file

@ -5,6 +5,8 @@
library dart2js.parser.partial;
import '../common.dart';
import '../options.dart' show
ParserOptions;
import '../util/characters.dart' as Characters show
$CLOSE_CURLY_BRACKET;
import '../tokens/token.dart' show
@ -20,9 +22,8 @@ import 'parser.dart' show
Parser;
class PartialParser extends Parser {
PartialParser(Listener listener, {bool enableConditionalDirectives})
: super(listener,
enableConditionalDirectives: enableConditionalDirectives);
PartialParser(Listener listener, ParserOptions options)
: super(listener, options);
Token parseClassBody(Token token) => skipClassBody(token);

View file

@ -137,6 +137,8 @@ import 'js_backend/js_backend.dart' show
JavaScriptBackend;
import 'library_loader.dart' show
LibraryLoader;
import 'options.dart' show
ParserOptions;
import 'parser/listener.dart' show
Listener,
ParserError;
@ -159,11 +161,9 @@ import 'tokens/token.dart' show
class PatchParserTask extends CompilerTask {
final String name = "Patching Parser";
final bool _enableConditionalDirectives;
final ParserOptions parserOptions;
PatchParserTask(Compiler compiler, {bool enableConditionalDirectives})
: this._enableConditionalDirectives = enableConditionalDirectives,
super(compiler);
PatchParserTask(Compiler compiler, this.parserOptions) : super(compiler);
/**
* Scans a library patch file, applies the method patches and
@ -198,9 +198,7 @@ class PatchParserTask extends CompilerTask {
compilationUnit,
idGenerator);
try {
new PartialParser(patchListener,
enableConditionalDirectives: _enableConditionalDirectives)
.parseUnit(tokens);
new PartialParser(patchListener, parserOptions).parseUnit(tokens);
} on ParserError catch (e) {
// No need to recover from a parser error in platform libraries, user
// will never see this if the libraries are tested correctly.
@ -217,8 +215,7 @@ class PatchParserTask extends CompilerTask {
measure(() => reporter.withCurrentElement(cls, () {
MemberListener listener = new PatchMemberListener(compiler, cls);
Parser parser = new PatchClassElementParser(
listener, enableConditionalDirectives: _enableConditionalDirectives);
Parser parser = new PatchClassElementParser(listener, parserOptions);
try {
Token token = parser.parseTopLevelDeclaration(cls.beginToken);
assert(identical(token, cls.endToken.next));
@ -270,9 +267,8 @@ class PatchMemberListener extends MemberListener {
* declarations.
*/
class PatchClassElementParser extends PartialParser {
PatchClassElementParser(Listener listener, {bool enableConditionalDirectives})
: super(listener,
enableConditionalDirectives: enableConditionalDirectives);
PatchClassElementParser(Listener listener, ParserOptions options)
: super(listener, options);
Token parseClassBody(Token token) => fullParseClassBody(token);
}

View file

@ -18,9 +18,11 @@ import 'package:compiler/compiler_new.dart' show
CompilerDiagnostics,
CompilerInput,
CompilerOutput,
CompilerOptions,
Diagnostic;
import 'package:compiler/src/options.dart' show
CompilerOptions;
import 'package:compiler/src/null_compiler_output.dart' show
NullCompilerOutput;

View file

@ -330,10 +330,10 @@ class LibraryUpdater extends JsFeatures {
Token token = new Scanner(_entrySourceFiles[library]).tokenize();
_entryUnitTokens[library] = token;
// Using two parsers to only create the nodes we want ([LibraryTag]).
Parser parser = new Parser(new Listener());
Parser parser = new Parser(new Listener(), compiler.options);
NodeListener listener = new NodeListener(
compiler, library.entryCompilationUnit);
Parser nodeParser = new Parser(listener);
Parser nodeParser = new Parser(listener, compiler.options);
Iterator<LibraryTag> tags = library.tags.iterator;
while (token.kind != EOF_TOKEN) {
token = parser.parseMetadataStar(token);

View file

@ -1,4 +1,4 @@
// Copyright (c) 2013, 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.
@ -7,13 +7,14 @@ library analyze_helper;
import 'dart:async';
import 'dart:io';
import 'package:compiler/compiler.dart' as api;
import 'package:compiler/compiler_new.dart' as new_api;
import 'package:compiler/src/apiimpl.dart';
import 'package:compiler/src/commandline_options.dart';
import 'package:compiler/src/diagnostics/messages.dart' show
Message,
MessageKind;
import 'package:compiler/src/filenames.dart';
import 'package:compiler/src/options.dart' show
CompilerOptions;
import 'package:compiler/src/source_file_provider.dart';
import 'package:compiler/src/util/uri_extras.dart';
@ -226,7 +227,7 @@ Future analyze(List<Uri> uriList,
provider,
null,
handler,
new new_api.CompilerOptions.parse(
new CompilerOptions.parse(
libraryRoot: libraryRoot,
packageRoot: packageRoot,
options: options,

View file

@ -22,6 +22,7 @@ import 'package:compiler/src/io/source_file.dart';
import 'package:compiler/src/string_validator.dart';
import 'package:compiler/src/tree/tree.dart' show DartString;
import 'package:compiler/src/tree/tree.dart' as tree;
import '../options_helper.dart';
/// For debugging the [AstBuilder] stack. Prints information about [x].
void show(x) {
@ -673,7 +674,7 @@ Expression parseExpression(String code) {
Scanner scan = new Scanner(file);
Token tok = scan.tokenize();
AstBuilder builder = new AstBuilder();
Parser parser = new Parser(builder);
Parser parser = new Parser(builder, new MockParserOptions());
tok = parser.parseExpression(tok);
if (builder.stack.length != 1 || tok.kind != EOF_TOKEN) {
throw "Parse error in $code";
@ -685,7 +686,7 @@ Statement parseStatement(String code) {
Scanner scan = new Scanner(file);
Token tok = scan.tokenize();
AstBuilder builder = new AstBuilder();
Parser parser = new Parser(builder);
Parser parser = new Parser(builder, new MockParserOptions());
tok = parser.parseStatement(tok);
if (builder.stack.length != 1 || tok.kind != EOF_TOKEN) {
throw "Parse error in $code";

View file

@ -1,4 +1,4 @@
// Copyright (c) 2013, 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.
@ -8,7 +8,7 @@ import "package:async_helper/async_helper.dart";
import 'package:compiler/compiler.dart'
show Diagnostic;
import 'package:compiler/compiler_new.dart' show CompilerOptions;
import 'package:compiler/src/options.dart' show CompilerOptions;
import 'package:compiler/src/old_to_new_api.dart';
main() {

View file

@ -1,10 +1,10 @@
// Copyright (c) 2013, 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.
import 'dart:async';
import 'package:expect/expect.dart';
import 'package:compiler/compiler_new.dart' show CompilerOptions;
import 'package:compiler/src/options.dart' show CompilerOptions;
import 'package:compiler/src/null_compiler_output.dart';
import 'memory_source_file_helper.dart';

View file

@ -9,6 +9,7 @@ import 'package:compiler/src/diagnostics/messages.dart';
import 'package:compiler/src/diagnostics/spannable.dart';
import 'package:compiler/src/diagnostics/source_span.dart';
import 'package:compiler/src/elements/elements.dart';
import 'options_helper.dart';
abstract class DiagnosticReporterWrapper extends DiagnosticReporter {
DiagnosticReporter get reporter;

View file

@ -27,6 +27,7 @@ import 'package:compiler/src/elements/elements.dart';
import 'package:compiler/src/library_loader.dart';
import 'package:compiler/src/null_compiler_output.dart';
import 'package:compiler/src/old_to_new_api.dart';
import 'package:compiler/src/options.dart' show CompilerOptions;
import 'package:compiler/src/resolution/resolution.dart';
import 'package:compiler/src/scanner/scanner_task.dart';
import 'package:compiler/src/universe/world_impact.dart';
@ -51,7 +52,7 @@ class TestCompiler extends apiimpl.CompilerImpl {
String this.testType,
Function this.onTest)
: super(inputProvider, outputProvider, handler,
new api.CompilerOptions.parse(
new CompilerOptions.parse(
libraryRoot: libraryRoot,
packageRoot: packageRoot,
options: options,

View file

@ -1,14 +1,10 @@
// 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.
/// Check that 'dart:' libraries have their corresponding dart.library.X
/// environment variable set.
import "dart:io";
import "dart:async";
import "memory_source_file_helper.dart";
import "package:async_helper/async_helper.dart";
@ -16,19 +12,15 @@ import "package:async_helper/async_helper.dart";
import 'package:expect/expect.dart' show
Expect;
import 'package:compiler/src/elements/elements.dart' show
LibraryElement;
import 'package:compiler/src/null_compiler_output.dart' show
NullCompilerOutput;
import 'package:compiler/compiler_new.dart' show
CompilerInput,
CompilerDiagnostics,
import 'package:compiler/src/options.dart' show
CompilerOptions;
import 'package:sdk_library_metadata/libraries.dart' show
LibraryInfo;
import 'package:compiler/compiler_new.dart' show
CompilerInput,
CompilerDiagnostics;
const clientPlatform = r'''
[dart-spec]

View file

@ -25,7 +25,7 @@ import 'package:compiler/src/null_compiler_output.dart' show NullCompilerOutput;
import 'package:compiler/src/old_to_new_api.dart'
show LegacyCompilerDiagnostics, LegacyCompilerInput;
import 'package:compiler/compiler_new.dart' show CompilerOptions;
import 'package:compiler/src/options.dart' show CompilerOptions;
Uri sdkRoot = Uri.base.resolve("sdk/");
Uri mock1LibraryUri = sdkRoot.resolve("lib/mock1.dart");

View file

@ -1,4 +1,4 @@
// Copyright (c) 2013, 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.
@ -11,7 +11,6 @@ import 'package:compiler/compiler.dart' show
import 'package:compiler/compiler_new.dart' show
CompilationResult,
CompilerDiagnostics,
CompilerOptions,
CompilerOutput,
Diagnostic,
PackagesDiscoveryProvider;
@ -23,6 +22,8 @@ import 'package:compiler/src/null_compiler_output.dart' show
NullCompilerOutput;
import 'package:compiler/src/library_loader.dart' show
LoadedLibraries;
import 'package:compiler/src/options.dart' show
CompilerOptions;
import 'memory_source_file_helper.dart';

View file

@ -1,15 +1,13 @@
// Copyright (c) 2012, 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.
library mock_compiler;
import "package:expect/expect.dart";
import 'dart:async';
import 'dart:collection';
import 'package:compiler/compiler.dart' as api;
import 'package:compiler/compiler_new.dart' as new_api;
import 'package:compiler/src/common/names.dart' show
Uris;
import 'package:compiler/src/constants/expressions.dart';
@ -18,11 +16,13 @@ import 'package:compiler/src/diagnostics/source_span.dart';
import 'package:compiler/src/diagnostics/spannable.dart';
import 'package:compiler/src/elements/elements.dart';
import 'package:compiler/src/elements/visitor.dart';
import 'package:compiler/src/js_backend/backend_helpers.dart'
show BackendHelpers;
import 'package:compiler/src/js_backend/lookup_map_analysis.dart'
show LookupMapAnalysis;
import 'package:compiler/src/js_backend/backend_helpers.dart' show
BackendHelpers;
import 'package:compiler/src/js_backend/lookup_map_analysis.dart' show
LookupMapAnalysis;
import 'package:compiler/src/io/source_file.dart';
import 'package:compiler/src/options.dart' show
CompilerOptions;
import 'package:compiler/src/resolution/members.dart';
import 'package:compiler/src/resolution/registry.dart';
import 'package:compiler/src/resolution/scope.dart';
@ -32,17 +32,17 @@ import 'package:compiler/src/tree/tree.dart';
import 'package:compiler/src/old_to_new_api.dart';
import 'parser_helper.dart';
import 'package:compiler/src/elements/modelx.dart'
show ElementX,
LibraryElementX,
ErroneousElementX,
FunctionElementX;
import 'package:compiler/src/elements/modelx.dart' show
ElementX,
LibraryElementX,
ErroneousElementX,
FunctionElementX;
import 'package:compiler/src/compiler.dart';
import 'package:compiler/src/deferred_load.dart'
show DeferredLoadTask,
OutputUnit;
import 'package:compiler/src/deferred_load.dart' show
DeferredLoadTask,
OutputUnit;
import 'mock_libraries.dart';
import 'diagnostic_helper.dart';
@ -89,7 +89,7 @@ class MockCompiler extends Compiler {
LibrarySourceProvider this.librariesOverride})
: sourceFiles = new Map<String, SourceFile>(),
testedPatchVersion = patchVersion,
super(options: new new_api.CompilerOptions(
super(options: new CompilerOptions(
entryPoint: new Uri(scheme: 'mock'),
libraryRoot: Uri.parse('placeholder_library_root_for_mock/'),
enableTypeAssertions: enableTypeAssertions,
@ -104,8 +104,7 @@ class MockCompiler extends Compiler {
preserveComments: preserveComments,
trustTypeAnnotations: trustTypeAnnotations,
trustJSInteropTypeAnnotations: trustJSInteropTypeAnnotations,
diagnosticOptions:
new DiagnosticOptions(shownPackageWarnings: const [])),
shownPackageWarnings: const []),
outputProvider: new LegacyCompilerOutput(outputProvider)) {
deferredLoadTask = new MockDeferredLoadTask(this);

View file

@ -0,0 +1,24 @@
// 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.
library options_helper;
import 'package:compiler/src/options.dart';
export 'package:compiler/src/options.dart';
class MockDiagnosticOptions implements DiagnosticOptions {
const MockDiagnosticOptions();
bool get fatalWarnings => false;
bool get terseDiagnostics => false;
bool get suppressWarnings => false;
bool get suppressHints => false;
bool get showAllPackageWarnings => false;
bool get hidePackageWarnings => true;
bool showPackageWarningsFor(Uri uri) => false;
}
class MockParserOptions implements ParserOptions {
bool get enableConditionalDirectives => true;
}

View file

@ -1,4 +1,4 @@
// Copyright (c) 2012, 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.
@ -22,12 +22,15 @@ import "package:compiler/src/elements/modelx.dart"
show CompilationUnitElementX, ElementX, LibraryElementX;
import "package:compiler/src/compiler.dart";
import 'package:compiler/src/options.dart';
import "package:compiler/src/diagnostics/source_span.dart";
import "package:compiler/src/diagnostics/spannable.dart";
import "package:compiler/src/diagnostics/diagnostic_listener.dart";
import "package:compiler/src/diagnostics/messages.dart";
import "package:compiler/src/script.dart";
import "options_helper.dart";
export "package:compiler/src/diagnostics/diagnostic_listener.dart";
export 'package:compiler/src/parser/listener.dart';
export 'package:compiler/src/parser/node_listener.dart';
@ -38,6 +41,8 @@ export "package:compiler/src/tokens/token.dart";
export "package:compiler/src/tokens/token_constants.dart";
class LoggerCanceler extends DiagnosticReporter {
DiagnosticOptions get options => const MockDiagnosticOptions();
void log(message) {
print(message);
}
@ -102,7 +107,7 @@ Node parseBodyCode(String text, Function parseMethod,
NodeListener listener = new NodeListener(
new ScannerOptions(canUseNative: true),
reporter, library.entryCompilationUnit);
Parser parser = new Parser(listener, enableConditionalDirectives: true);
Parser parser = new Parser(listener, new MockParserOptions());
Token endToken = parseMethod(parser, tokens);
assert(endToken.kind == EOF_TOKEN);
Node node = listener.popNode();
@ -150,7 +155,7 @@ Link<Element> parseUnit(String text, Compiler compiler,
ElementListener listener = new ElementListener(
compiler.parsing.getScannerOptionsFor(library),
reporter, unit, () => id++);
PartialParser parser = new PartialParser(listener);
PartialParser parser = new PartialParser(listener, new MockParserOptions());
reporter.withCurrentElement(unit, () => parser.parseUnit(tokens));
return unit.localMembers;
}

View file

@ -3,6 +3,7 @@
// BSD-style license that can be found in the LICENSE file.
import "package:expect/expect.dart";
import 'options_helper.dart';
import 'parser_helper.dart';
void main() {
@ -10,7 +11,8 @@ void main() {
}
void testSkipExpression() {
PartialParser parser = new PartialParser(new Listener());
PartialParser parser =
new PartialParser(new Listener(), new MockParserOptions());
Token token = scan('a < b;');
token = parser.skipExpression(token);
Expect.equals(';', token.value);

View file

@ -26,6 +26,7 @@ import 'package:compiler/src/script.dart';
import 'package:compiler/src/util/util.dart';
import 'mock_compiler.dart';
import 'options_helper.dart';
import 'parser_helper.dart';
final MessageKind NOT_ASSIGNABLE = MessageKind.NOT_ASSIGNABLE;
@ -2555,7 +2556,7 @@ analyze(MockCompiler compiler,
Token tokens = scan(text);
NodeListener listener = new NodeListener(
const ScannerOptions(), compiler.reporter, null);
Parser parser = new Parser(listener);
Parser parser = new Parser(listener, new MockParserOptions());
parser.parseStatement(tokens);
Node node = listener.popNode();
Element compilationUnit =
@ -2601,7 +2602,7 @@ analyzeIn(MockCompiler compiler,
Token tokens = scan(text);
NodeListener listener = new NodeListener(
const ScannerOptions(), compiler.reporter, null);
Parser parser = new Parser(listener,
Parser parser = new Parser(listener, new MockParserOptions(),
asyncAwaitKeywordsEnabled: element.asyncMarker != AsyncMarker.SYNC);
parser.parseStatement(tokens);
Node node = listener.popNode();

View file

@ -19,6 +19,8 @@ import "package:compiler/src/elements/modelx.dart"
LibraryElementX;
import "package:compiler/src/script.dart";
import "options_helper.dart";
main() {
testClassDef();
testClass1Field();
@ -84,7 +86,6 @@ void compareCode(String code, {String expectedResult}) {
Expect.equals(expectedResult, doUnparse(code));
}
String doUnparse(String source) {
MessageCollector diagnosticListener = new MessageCollector();
Script script = new Script(null, null, null);
@ -94,7 +95,7 @@ String doUnparse(String source) {
Token beginToken = scanner.tokenize();
NodeListener listener = new NodeListener(
const ScannerOptions(), diagnosticListener, element);
Parser parser = new Parser(listener);
Parser parser = new Parser(listener, new MockParserOptions());
parser.parseUnit(beginToken);
Node node = listener.popNode();
Expect.isTrue(listener.nodes.isEmpty);