mirror of
https://github.com/dart-lang/sdk
synced 2024-10-14 08:51:21 +00:00
Consolidate analyzer dependencies.
This allows us to create a smaller .dill file for Fasta. R=paulberry@google.com Review-Url: https://codereview.chromium.org/2723113002 .
This commit is contained in:
parent
369c94815d
commit
6176847e36
63
pkg/front_end/lib/src/fasta/analyzer/analyzer_compile.dart
Normal file
63
pkg/front_end/lib/src/fasta/analyzer/analyzer_compile.dart
Normal file
|
@ -0,0 +1,63 @@
|
|||
// Copyright (c) 2017, 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 fasta.analyzer_compile;
|
||||
|
||||
import 'dart:async' show Future;
|
||||
|
||||
import 'dart:io' show exitCode;
|
||||
|
||||
import '../compiler_command_line.dart' show CompilerCommandLine;
|
||||
|
||||
import '../compiler_context.dart' show CompilerContext;
|
||||
|
||||
import '../ticker.dart' show Ticker;
|
||||
|
||||
import '../outline.dart' show CompileTask;
|
||||
|
||||
import '../errors.dart' show InputError;
|
||||
|
||||
import 'analyzer_target.dart' show AnalyzerTarget;
|
||||
|
||||
import '../dill/dill_target.dart' show DillTarget;
|
||||
|
||||
import '../translate_uri.dart' show TranslateUri;
|
||||
|
||||
const int iterations = const int.fromEnvironment("iterations", defaultValue: 1);
|
||||
|
||||
Future<Uri> compile(List<String> arguments) async {
|
||||
try {
|
||||
return await CompilerCommandLine.withGlobalOptions("kompile", arguments,
|
||||
(CompilerContext c) async {
|
||||
if (c.options.verbose) {
|
||||
print("Compiling via analyzer: ${arguments.join(' ')}");
|
||||
}
|
||||
AnalyzerCompileTask task =
|
||||
new AnalyzerCompileTask(c, new Ticker(isVerbose: c.options.verbose));
|
||||
return await task.compile();
|
||||
});
|
||||
} on InputError catch (e) {
|
||||
exitCode = 1;
|
||||
print(e.format());
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
class AnalyzerCompileTask extends CompileTask {
|
||||
AnalyzerCompileTask(CompilerContext c, Ticker ticker) : super(c, ticker);
|
||||
|
||||
AnalyzerTarget createKernelTarget(
|
||||
DillTarget dillTarget, TranslateUri uriTranslator) {
|
||||
return new AnalyzerTarget(dillTarget, uriTranslator, c.uriToSource);
|
||||
}
|
||||
}
|
||||
|
||||
main(List<String> arguments) async {
|
||||
for (int i = 0; i < iterations; i++) {
|
||||
if (i > 0) {
|
||||
print("\n");
|
||||
}
|
||||
await compile(arguments);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,35 @@
|
|||
// Copyright (c) 2017, 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 fasta.analyzer_diet_listener;
|
||||
|
||||
import '../source/stack_listener.dart' show StackListener;
|
||||
|
||||
import '../builder/builder.dart';
|
||||
|
||||
import '../builder/scope.dart' show Scope;
|
||||
|
||||
import '../source/source_library_builder.dart' show SourceLibraryBuilder;
|
||||
|
||||
import '../source/diet_listener.dart' show DietListener;
|
||||
|
||||
import 'element_store.dart' show ElementStore;
|
||||
|
||||
import 'ast_builder.dart' show AstBuilder;
|
||||
|
||||
class AnalyzerDietListener extends DietListener {
|
||||
final ElementStore elementStore;
|
||||
|
||||
AnalyzerDietListener(SourceLibraryBuilder library, this.elementStore)
|
||||
: super(library, null, null);
|
||||
|
||||
StackListener createListener(
|
||||
MemberBuilder builder, Scope memberScope, bool isInstanceMember,
|
||||
[Scope formalParameterScope]) {
|
||||
return new AstBuilder(library, builder, elementStore, memberScope, uri);
|
||||
}
|
||||
|
||||
@override
|
||||
AsyncMarker getAsyncMarker(StackListener listener) => null;
|
||||
}
|
34
pkg/front_end/lib/src/fasta/analyzer/analyzer_loader.dart
Normal file
34
pkg/front_end/lib/src/fasta/analyzer/analyzer_loader.dart
Normal file
|
@ -0,0 +1,34 @@
|
|||
// Copyright (c) 2017, 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 fasta.analyzer_loader;
|
||||
|
||||
import 'package:kernel/ast.dart' show Program;
|
||||
|
||||
import '../builder/builder.dart' show LibraryBuilder;
|
||||
|
||||
import '../target_implementation.dart' show TargetImplementation;
|
||||
|
||||
import '../source/source_loader.dart' show SourceLoader;
|
||||
|
||||
import 'element_store.dart' show ElementStore;
|
||||
|
||||
import 'analyzer_diet_listener.dart' show AnalyzerDietListener;
|
||||
|
||||
class AnalyzerLoader<L> extends SourceLoader<L> {
|
||||
ElementStore elementStore;
|
||||
|
||||
AnalyzerLoader(TargetImplementation target) : super(target);
|
||||
|
||||
@override
|
||||
void computeHierarchy(Program program) {
|
||||
elementStore = new ElementStore(coreLibrary, builders);
|
||||
ticker.logMs("Built analyzer element model.");
|
||||
}
|
||||
|
||||
@override
|
||||
AnalyzerDietListener createDietListener(LibraryBuilder library) {
|
||||
return new AnalyzerDietListener(library, elementStore);
|
||||
}
|
||||
}
|
24
pkg/front_end/lib/src/fasta/analyzer/analyzer_target.dart
Normal file
24
pkg/front_end/lib/src/fasta/analyzer/analyzer_target.dart
Normal file
|
@ -0,0 +1,24 @@
|
|||
// Copyright (c) 2017, 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 fasta.analyzer_target;
|
||||
|
||||
import 'package:kernel/ast.dart' show Library, Source;
|
||||
|
||||
import '../kernel/kernel_target.dart' show KernelTarget;
|
||||
|
||||
import '../translate_uri.dart' show TranslateUri;
|
||||
|
||||
import '../dill/dill_target.dart' show DillTarget;
|
||||
|
||||
import 'analyzer_loader.dart' show AnalyzerLoader;
|
||||
|
||||
class AnalyzerTarget extends KernelTarget {
|
||||
AnalyzerTarget(DillTarget dillTarget, TranslateUri uriTranslator,
|
||||
[Map<String, Source> uriToSource])
|
||||
: super(dillTarget, uriTranslator, uriToSource);
|
||||
|
||||
@override
|
||||
AnalyzerLoader<Library> createLoader() => new AnalyzerLoader<Library>(this);
|
||||
}
|
|
@ -25,10 +25,10 @@ import 'package:kernel/target/targets.dart' show Target, TargetFlags, getTarget;
|
|||
|
||||
import 'package:kernel/ast.dart' show Program;
|
||||
|
||||
import 'environment_variable.dart'
|
||||
import '../environment_variable.dart'
|
||||
show EnvironmentVariableDirectory, fileExists;
|
||||
|
||||
import 'errors.dart' show inputError;
|
||||
import '../errors.dart' show inputError;
|
||||
|
||||
const EnvironmentVariableSdk dartAotSdk = const EnvironmentVariableSdk(
|
||||
"DART_AOT_SDK",
|
|
@ -1,10 +0,0 @@
|
|||
// 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 fasta.ast_kind;
|
||||
|
||||
enum AstKind {
|
||||
Analyzer,
|
||||
Kernel,
|
||||
}
|
|
@ -1,16 +0,0 @@
|
|||
// 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 '../outline.dart' as outline;
|
||||
|
||||
const int iterations = const int.fromEnvironment("iterations", defaultValue: 1);
|
||||
|
||||
main(List<String> arguments) async {
|
||||
for (int i = 0; i < iterations; i++) {
|
||||
if (i > 0) {
|
||||
print("\n");
|
||||
}
|
||||
await outline.kompile(arguments);
|
||||
}
|
||||
}
|
|
@ -4,13 +4,11 @@
|
|||
|
||||
import 'dart:io' show exit, exitCode;
|
||||
|
||||
import '../ast_kind.dart' show AstKind;
|
||||
|
||||
import '../compiler_command_line.dart' show CompilerCommandLine;
|
||||
|
||||
import '../compiler_context.dart' show CompilerContext;
|
||||
|
||||
import '../outline.dart' show doCompile;
|
||||
import '../outline.dart' show CompileTask;
|
||||
|
||||
import '../errors.dart' show InputError;
|
||||
|
||||
|
@ -29,8 +27,9 @@ main(List<String> arguments) async {
|
|||
print("\n");
|
||||
}
|
||||
try {
|
||||
uri = await doCompile(
|
||||
c, new Ticker(isVerbose: c.options.verbose), AstKind.Kernel);
|
||||
CompileTask task =
|
||||
new CompileTask(c, new Ticker(isVerbose: c.options.verbose));
|
||||
uri = await task.compile();
|
||||
} on InputError catch (e) {
|
||||
print(e.format());
|
||||
exit(1);
|
||||
|
|
|
@ -24,8 +24,6 @@ import 'dill/dill_target.dart' show DillTarget;
|
|||
|
||||
import 'translate_uri.dart' show TranslateUri;
|
||||
|
||||
import 'ast_kind.dart' show AstKind;
|
||||
|
||||
Future main(List<String> arguments) async {
|
||||
Ticker ticker = new Ticker();
|
||||
try {
|
||||
|
@ -60,7 +58,7 @@ Future compilePlatform(CompilerContext c, Ticker ticker) async {
|
|||
await kernelTarget.writeOutline(output);
|
||||
|
||||
if (exitCode != 0) return null;
|
||||
await kernelTarget.writeProgram(output, AstKind.Kernel);
|
||||
await kernelTarget.writeProgram(output);
|
||||
if (c.options.dumpIr) {
|
||||
kernelTarget.dumpIr();
|
||||
}
|
||||
|
|
|
@ -37,7 +37,7 @@ class DillLoader extends Loader<Library> {
|
|||
builder.library.fields.forEach(builder.addMember);
|
||||
}
|
||||
|
||||
Future<Null> buildBody(DillLibraryBuilder builder, _) {
|
||||
Future<Null> buildBody(DillLibraryBuilder builder) {
|
||||
return buildOutline(builder);
|
||||
}
|
||||
|
||||
|
|
|
@ -18,8 +18,6 @@ import '../ticker.dart' show Ticker;
|
|||
|
||||
import '../translate_uri.dart' show TranslateUri;
|
||||
|
||||
import '../ast_kind.dart' show AstKind;
|
||||
|
||||
import '../kernel/kernel_builder.dart' show ClassBuilder, KernelClassBuilder;
|
||||
|
||||
import 'dill_library_builder.dart' show DillLibraryBuilder;
|
||||
|
@ -45,7 +43,7 @@ class DillTarget extends TargetImplementation {
|
|||
}
|
||||
}
|
||||
|
||||
Future<Null> writeProgram(Uri uri, AstKind kind) {
|
||||
Future<Null> writeProgram(Uri uri) {
|
||||
return internalError("not implemented.");
|
||||
}
|
||||
|
||||
|
|
|
@ -57,8 +57,6 @@ import '../translate_uri.dart' show TranslateUri;
|
|||
|
||||
import '../dill/dill_target.dart' show DillTarget;
|
||||
|
||||
import '../ast_kind.dart' show AstKind;
|
||||
|
||||
import '../errors.dart'
|
||||
show InputError, internalError, reportCrash, resetCrashReporting;
|
||||
|
||||
|
@ -99,9 +97,11 @@ class KernelTarget extends TargetImplementation {
|
|||
uriToSource = uriToSource ?? CompilerContext.current.uriToSource,
|
||||
super(dillTarget.ticker, uriTranslator) {
|
||||
resetCrashReporting();
|
||||
loader = new SourceLoader<Library>(this);
|
||||
loader = createLoader();
|
||||
}
|
||||
|
||||
SourceLoader<Library> createLoader() => new SourceLoader<Library>(this);
|
||||
|
||||
void addLineStarts(Uri uri, List<int> lineStarts) {
|
||||
String fileUri = relativizeUri(uri);
|
||||
uriToSource[fileUri] = new Source(lineStarts, fileUri);
|
||||
|
@ -205,18 +205,14 @@ class KernelTarget extends TargetImplementation {
|
|||
: writeLinkedProgram(uri, program, isFullProgram: isFullProgram);
|
||||
}
|
||||
|
||||
Future<Program> writeProgram(Uri uri, AstKind astKind) async {
|
||||
Future<Program> writeProgram(Uri uri) async {
|
||||
if (loader.first == null) return null;
|
||||
if (errors.isNotEmpty) {
|
||||
return handleInputError(uri, null, isFullProgram: true);
|
||||
}
|
||||
try {
|
||||
if (astKind == AstKind.Analyzer) {
|
||||
loader.buildElementStore();
|
||||
} else {
|
||||
loader.computeHierarchy(program);
|
||||
}
|
||||
await loader.buildBodies(astKind);
|
||||
loader.computeHierarchy(program);
|
||||
await loader.buildBodies();
|
||||
loader.finishStaticInvocations();
|
||||
finishAllConstructors();
|
||||
loader.finishNativeMethods();
|
||||
|
|
|
@ -8,8 +8,6 @@ import 'dart:async' show Future;
|
|||
|
||||
import 'dart:collection' show Queue;
|
||||
|
||||
import 'ast_kind.dart' show AstKind;
|
||||
|
||||
import 'builder/builder.dart' show Builder, LibraryBuilder;
|
||||
|
||||
import 'errors.dart' show InputError, firstSourceUri;
|
||||
|
@ -81,11 +79,11 @@ abstract class Loader<L> {
|
|||
}
|
||||
}
|
||||
|
||||
Future<Null> buildBodies(AstKind astKind) async {
|
||||
Future<Null> buildBodies() async {
|
||||
assert(coreLibrary != null);
|
||||
for (LibraryBuilder library in builders.values) {
|
||||
currentUriForCrashReporting = library.uri;
|
||||
await buildBody(library, astKind);
|
||||
await buildBody(library);
|
||||
}
|
||||
currentUriForCrashReporting = null;
|
||||
ticker.log((Duration elapsed, Duration sinceStart) {
|
||||
|
@ -126,10 +124,7 @@ ${format(ms / libraryCount, 3, 12)} ms/compilation unit.""");
|
|||
Future<Null> buildOutline(covariant LibraryBuilder library);
|
||||
|
||||
/// Builds all the method bodies found in the given [library].
|
||||
///
|
||||
/// [astKind] determines whether or not analyzer ASTs are used as an
|
||||
/// intermediate data structure.
|
||||
Future<Null> buildBody(covariant LibraryBuilder library, AstKind astKind);
|
||||
Future<Null> buildBody(covariant LibraryBuilder library);
|
||||
|
||||
List<InputError> collectCompileTimeErrors() {
|
||||
List<InputError> errors = <InputError>[];
|
||||
|
|
|
@ -24,8 +24,6 @@ import 'ticker.dart' show Ticker;
|
|||
|
||||
import 'translate_uri.dart' show TranslateUri;
|
||||
|
||||
import 'ast_kind.dart' show AstKind;
|
||||
|
||||
Future<KernelTarget> outline(List<String> arguments) async {
|
||||
try {
|
||||
return await CompilerCommandLine.withGlobalOptions("outline", arguments,
|
||||
|
@ -33,8 +31,9 @@ Future<KernelTarget> outline(List<String> arguments) async {
|
|||
if (c.options.verbose) {
|
||||
print("Building outlines for ${arguments.join(' ')}");
|
||||
}
|
||||
return await doOutline(
|
||||
c, new Ticker(isVerbose: c.options.verbose), c.options.output);
|
||||
CompileTask task =
|
||||
new CompileTask(c, new Ticker(isVerbose: c.options.verbose));
|
||||
return await task.buildOutline(c.options.output);
|
||||
});
|
||||
} on InputError catch (e) {
|
||||
exitCode = 1;
|
||||
|
@ -50,8 +49,9 @@ Future<Uri> compile(List<String> arguments) async {
|
|||
if (c.options.verbose) {
|
||||
print("Compiling directly to Kernel: ${arguments.join(' ')}");
|
||||
}
|
||||
return await doCompile(
|
||||
c, new Ticker(isVerbose: c.options.verbose), AstKind.Kernel);
|
||||
CompileTask task =
|
||||
new CompileTask(c, new Ticker(isVerbose: c.options.verbose));
|
||||
return await task.compile();
|
||||
});
|
||||
} on InputError catch (e) {
|
||||
exitCode = 1;
|
||||
|
@ -60,69 +60,62 @@ Future<Uri> compile(List<String> arguments) async {
|
|||
}
|
||||
}
|
||||
|
||||
Future<Uri> kompile(List<String> arguments) async {
|
||||
try {
|
||||
return await CompilerCommandLine.withGlobalOptions("kompile", arguments,
|
||||
(CompilerContext c) async {
|
||||
if (c.options.verbose) {
|
||||
print("Compiling via analyzer: ${arguments.join(' ')}");
|
||||
}
|
||||
return await doCompile(
|
||||
c, new Ticker(isVerbose: c.options.verbose), AstKind.Analyzer);
|
||||
});
|
||||
} on InputError catch (e) {
|
||||
exitCode = 1;
|
||||
print(e.format());
|
||||
return null;
|
||||
}
|
||||
}
|
||||
class CompileTask {
|
||||
final CompilerContext c;
|
||||
final Ticker ticker;
|
||||
|
||||
Future<KernelTarget> doOutline(CompilerContext c, Ticker ticker,
|
||||
[Uri output]) async {
|
||||
TranslateUri uriTranslator = await TranslateUri.parse(c.options.sdk);
|
||||
ticker.logMs("Read packages file");
|
||||
DillTarget dillTarget = new DillTarget(ticker, uriTranslator);
|
||||
KernelTarget kernelTarget =
|
||||
new KernelTarget(dillTarget, uriTranslator, c.uriToSource);
|
||||
Uri platform = c.options.platform;
|
||||
if (platform != null) {
|
||||
dillTarget.read(platform);
|
||||
}
|
||||
String argument = c.options.arguments.first;
|
||||
Uri uri = Uri.base.resolve(argument);
|
||||
String path = uriTranslator.translate(uri)?.path ?? argument;
|
||||
if (path.endsWith(".dart")) {
|
||||
kernelTarget.read(uri);
|
||||
} else {
|
||||
inputError(uri, -1, "Unexpected input: $uri");
|
||||
}
|
||||
await dillTarget.writeOutline(null);
|
||||
await kernelTarget.writeOutline(output);
|
||||
if (c.options.dumpIr && output != null) {
|
||||
kernelTarget.dumpIr();
|
||||
}
|
||||
return kernelTarget;
|
||||
}
|
||||
CompileTask(this.c, this.ticker);
|
||||
|
||||
Future<Uri> doCompile(CompilerContext c, Ticker ticker, AstKind kind) async {
|
||||
KernelTarget kernelTarget = await doOutline(c, ticker);
|
||||
if (exitCode != 0) return null;
|
||||
Uri uri = c.options.output;
|
||||
await kernelTarget.writeProgram(uri, kind);
|
||||
if (c.options.dumpIr) {
|
||||
kernelTarget.dumpIr();
|
||||
KernelTarget createKernelTarget(
|
||||
DillTarget dillTarget, TranslateUri uriTranslator) {
|
||||
return new KernelTarget(dillTarget, uriTranslator, c.uriToSource);
|
||||
}
|
||||
if (c.options.verify) {
|
||||
try {
|
||||
verifyProgram(kernelTarget.program);
|
||||
ticker.logMs("Verified program");
|
||||
} catch (e, s) {
|
||||
exitCode = 1;
|
||||
print("Verification of program failed: $e");
|
||||
if (s != null && c.options.verbose) {
|
||||
print(s);
|
||||
|
||||
Future<KernelTarget> buildOutline([Uri output]) async {
|
||||
TranslateUri uriTranslator = await TranslateUri.parse(c.options.sdk);
|
||||
ticker.logMs("Read packages file");
|
||||
DillTarget dillTarget = new DillTarget(ticker, uriTranslator);
|
||||
KernelTarget kernelTarget = createKernelTarget(dillTarget, uriTranslator);
|
||||
Uri platform = c.options.platform;
|
||||
if (platform != null) {
|
||||
dillTarget.read(platform);
|
||||
}
|
||||
String argument = c.options.arguments.first;
|
||||
Uri uri = Uri.base.resolve(argument);
|
||||
String path = uriTranslator.translate(uri)?.path ?? argument;
|
||||
if (path.endsWith(".dart")) {
|
||||
kernelTarget.read(uri);
|
||||
} else {
|
||||
inputError(uri, -1, "Unexpected input: $uri");
|
||||
}
|
||||
await dillTarget.writeOutline(null);
|
||||
await kernelTarget.writeOutline(output);
|
||||
if (c.options.dumpIr && output != null) {
|
||||
kernelTarget.dumpIr();
|
||||
}
|
||||
return kernelTarget;
|
||||
}
|
||||
|
||||
Future<Uri> compile() async {
|
||||
KernelTarget kernelTarget = await buildOutline();
|
||||
if (exitCode != 0) return null;
|
||||
Uri uri = c.options.output;
|
||||
await kernelTarget.writeProgram(uri);
|
||||
if (c.options.dumpIr) {
|
||||
kernelTarget.dumpIr();
|
||||
}
|
||||
if (c.options.verify) {
|
||||
try {
|
||||
verifyProgram(kernelTarget.program);
|
||||
ticker.logMs("Verified program");
|
||||
} catch (e, s) {
|
||||
exitCode = 1;
|
||||
print("Verification of program failed: $e");
|
||||
if (s != null && c.options.verbose) {
|
||||
print(s);
|
||||
}
|
||||
}
|
||||
}
|
||||
return uri;
|
||||
}
|
||||
return uri;
|
||||
}
|
||||
|
|
|
@ -187,7 +187,7 @@ abstract class ArrayKeywordState implements KeywordState {
|
|||
final List<KeywordState> table;
|
||||
final Keyword keyword;
|
||||
|
||||
ArrayKeywordState(List<KeywordState> this.table, String syntax)
|
||||
ArrayKeywordState(this.table, String syntax)
|
||||
: keyword = ((syntax == null) ? null : Keyword.keywords[syntax]);
|
||||
|
||||
KeywordState next(int c);
|
||||
|
|
|
@ -29,12 +29,8 @@ import '../kernel/body_builder.dart' show BodyBuilder;
|
|||
|
||||
import '../builder/builder.dart';
|
||||
|
||||
import '../analyzer/analyzer.dart';
|
||||
|
||||
import '../builder/scope.dart' show Scope;
|
||||
|
||||
import '../ast_kind.dart' show AstKind;
|
||||
|
||||
import 'source_library_builder.dart' show SourceLibraryBuilder;
|
||||
|
||||
import '../kernel/kernel_library_builder.dart' show isConstructorName;
|
||||
|
@ -42,14 +38,10 @@ import '../kernel/kernel_library_builder.dart' show isConstructorName;
|
|||
class DietListener extends StackListener {
|
||||
final SourceLibraryBuilder library;
|
||||
|
||||
final ElementStore elementStore;
|
||||
|
||||
final ClassHierarchy hierarchy;
|
||||
|
||||
final CoreTypes coreTypes;
|
||||
|
||||
final AstKind astKind;
|
||||
|
||||
final bool isDartLibrary;
|
||||
|
||||
ClassBuilder currentClass;
|
||||
|
@ -61,8 +53,7 @@ class DietListener extends StackListener {
|
|||
@override
|
||||
Uri uri;
|
||||
|
||||
DietListener(SourceLibraryBuilder library, this.elementStore, this.hierarchy,
|
||||
this.coreTypes, this.astKind)
|
||||
DietListener(SourceLibraryBuilder library, this.hierarchy, this.coreTypes)
|
||||
: library = library,
|
||||
uri = library.fileUri,
|
||||
memberScope = library.scope,
|
||||
|
@ -380,24 +371,8 @@ class DietListener extends StackListener {
|
|||
StackListener createListener(
|
||||
MemberBuilder builder, Scope memberScope, bool isInstanceMember,
|
||||
[Scope formalParameterScope]) {
|
||||
switch (astKind) {
|
||||
case AstKind.Kernel:
|
||||
return new BodyBuilder(
|
||||
library,
|
||||
builder,
|
||||
memberScope,
|
||||
formalParameterScope,
|
||||
hierarchy,
|
||||
coreTypes,
|
||||
currentClass,
|
||||
isInstanceMember,
|
||||
uri);
|
||||
|
||||
case AstKind.Analyzer:
|
||||
return new AstBuilder(library, builder, elementStore, memberScope, uri);
|
||||
}
|
||||
|
||||
return internalError("Unknown $astKind");
|
||||
return new BodyBuilder(library, builder, memberScope, formalParameterScope,
|
||||
hierarchy, coreTypes, currentClass, isInstanceMember, uri);
|
||||
}
|
||||
|
||||
void buildFunctionBody(Token token, ProcedureBuilder builder) {
|
||||
|
@ -487,6 +462,8 @@ class DietListener extends StackListener {
|
|||
return removeNativeClause(identifiers);
|
||||
}
|
||||
|
||||
AsyncMarker getAsyncMarker(StackListener listener) => listener.pop();
|
||||
|
||||
void parseFunctionBody(StackListener listener, Token token) {
|
||||
try {
|
||||
Parser parser = new Parser(listener);
|
||||
|
@ -496,8 +473,7 @@ class DietListener extends StackListener {
|
|||
listener.prepareInitializers();
|
||||
token = parser.parseInitializersOpt(token);
|
||||
token = parser.parseAsyncModifier(token);
|
||||
AsyncMarker asyncModifier =
|
||||
astKind == AstKind.Analyzer ? null : listener.pop();
|
||||
AsyncMarker asyncModifier = getAsyncMarker(listener);
|
||||
bool isExpression = false;
|
||||
bool allowAbstract = true;
|
||||
parser.parseFunctionBody(token, isExpression, allowAbstract);
|
||||
|
|
|
@ -26,8 +26,6 @@ import '../messages.dart' show warning;
|
|||
|
||||
import '../export.dart' show Export;
|
||||
|
||||
import '../analyzer/element_store.dart' show ElementStore;
|
||||
|
||||
import '../builder/builder.dart' show Builder, ClassBuilder, LibraryBuilder;
|
||||
|
||||
import 'outline_builder.dart' show OutlineBuilder;
|
||||
|
@ -42,8 +40,6 @@ import 'diet_parser.dart' show DietParser;
|
|||
|
||||
import 'source_library_builder.dart' show SourceLibraryBuilder;
|
||||
|
||||
import '../ast_kind.dart' show AstKind;
|
||||
|
||||
class SourceLoader<L> extends Loader<L> {
|
||||
final Map<Uri, List<int>> sourceBytes = <Uri, List<int>>{};
|
||||
|
||||
|
@ -51,9 +47,6 @@ class SourceLoader<L> extends Loader<L> {
|
|||
ClassHierarchy hierarchy;
|
||||
CoreTypes coreTypes;
|
||||
|
||||
// Used when building analyzer ASTs.
|
||||
ElementStore elementStore;
|
||||
|
||||
SourceLoader(TargetImplementation target) : super(target);
|
||||
|
||||
Future<Token> tokenize(SourceLibraryBuilder library,
|
||||
|
@ -98,15 +91,14 @@ class SourceLoader<L> extends Loader<L> {
|
|||
new ClassMemberParser(listener).parseUnit(tokens);
|
||||
}
|
||||
|
||||
Future<Null> buildBody(LibraryBuilder library, AstKind astKind) async {
|
||||
Future<Null> buildBody(LibraryBuilder library) async {
|
||||
if (library is SourceLibraryBuilder) {
|
||||
// We tokenize source files twice to keep memory usage low. This is the
|
||||
// second time, and the first time was in [buildOutline] above. So this
|
||||
// time we suppress lexical errors.
|
||||
Token tokens = await tokenize(library, suppressLexicalErrors: true);
|
||||
if (tokens == null) return;
|
||||
DietListener listener = new DietListener(
|
||||
library, elementStore, hierarchy, coreTypes, astKind);
|
||||
DietListener listener = createDietListener(library);
|
||||
DietParser parser = new DietParser(listener);
|
||||
parser.parseUnit(tokens);
|
||||
for (SourceLibraryBuilder part in library.parts) {
|
||||
|
@ -119,6 +111,10 @@ class SourceLoader<L> extends Loader<L> {
|
|||
}
|
||||
}
|
||||
|
||||
DietListener createDietListener(LibraryBuilder library) {
|
||||
return new DietListener(library, hierarchy, coreTypes);
|
||||
}
|
||||
|
||||
void resolveParts() {
|
||||
List<Uri> parts = <Uri>[];
|
||||
builders.forEach((Uri uri, LibraryBuilder library) {
|
||||
|
@ -339,11 +335,6 @@ class SourceLoader<L> extends Loader<L> {
|
|||
ticker.logMs("Built program");
|
||||
}
|
||||
|
||||
void buildElementStore() {
|
||||
elementStore = new ElementStore(coreLibrary, builders);
|
||||
ticker.logMs("Built analyzer element model.");
|
||||
}
|
||||
|
||||
void computeHierarchy(Program program) {
|
||||
hierarchy = new ClassHierarchy(program);
|
||||
ticker.logMs("Computed class hierarchy");
|
||||
|
|
|
@ -8,8 +8,6 @@ import 'dart:async' show Future;
|
|||
|
||||
import 'ticker.dart' show Ticker;
|
||||
|
||||
import 'ast_kind.dart' show AstKind;
|
||||
|
||||
/// A compilation target.
|
||||
///
|
||||
/// A target reads source files with [read] and writes out the resulting
|
||||
|
@ -23,7 +21,7 @@ abstract class Target {
|
|||
void read(Uri uri);
|
||||
|
||||
/// Write the resulting program in the file [uri].
|
||||
Future writeProgram(Uri uri, AstKind astKind);
|
||||
Future writeProgram(Uri uri);
|
||||
|
||||
/// Write the resulting outline in the file [uri].
|
||||
Future writeOutline(Uri uri);
|
||||
|
|
|
@ -28,18 +28,16 @@ import '../ticker.dart' show Ticker;
|
|||
|
||||
import '../translate_uri.dart' show TranslateUri;
|
||||
|
||||
import '../analyzer/analyzer_target.dart' show AnalyzerTarget;
|
||||
|
||||
import '../kernel/kernel_target.dart' show KernelTarget;
|
||||
|
||||
import '../dill/dill_target.dart' show DillTarget;
|
||||
|
||||
import '../ast_kind.dart' show AstKind;
|
||||
|
||||
export 'kernel_chain.dart' show TestContext;
|
||||
|
||||
export 'package:testing/testing.dart' show Chain, runMe;
|
||||
|
||||
export '../ast_kind.dart' show AstKind;
|
||||
|
||||
const String ENABLE_FULL_COMPILE = " full compile ";
|
||||
|
||||
const String AST_KIND_INDEX = " AST kind index ";
|
||||
|
@ -63,6 +61,11 @@ String shortenAstKindName(AstKind astKind) {
|
|||
throw "Unknown AST kind: $astKind";
|
||||
}
|
||||
|
||||
enum AstKind {
|
||||
Analyzer,
|
||||
Kernel,
|
||||
}
|
||||
|
||||
class FastaContext extends TestContext {
|
||||
final TranslateUri uriTranslator;
|
||||
|
||||
|
@ -159,7 +162,7 @@ class Outline extends Step<TestDescription, Program, FastaContext> {
|
|||
const Outline(this.fullCompile, this.astKind);
|
||||
|
||||
String get name {
|
||||
return fullCompile ? "${shortenAstKindName(astKind)} compile" : "outline";
|
||||
return fullCompile ? "${astKind} compile" : "outline";
|
||||
}
|
||||
|
||||
bool get isCompiler => fullCompile;
|
||||
|
@ -172,15 +175,17 @@ class Outline extends Step<TestDescription, Program, FastaContext> {
|
|||
dillTarget.loader
|
||||
..input = Uri.parse("org.dartlang:platform") // Make up a name.
|
||||
..setProgram(platform);
|
||||
KernelTarget sourceTarget =
|
||||
new KernelTarget(dillTarget, context.uriTranslator);
|
||||
KernelTarget sourceTarget = astKind == AstKind.Analyzer
|
||||
? new AnalyzerTarget(dillTarget, context.uriTranslator)
|
||||
: new KernelTarget(dillTarget, context.uriTranslator);
|
||||
|
||||
Program p;
|
||||
try {
|
||||
sourceTarget.read(description.uri);
|
||||
await dillTarget.writeOutline(null);
|
||||
p = await sourceTarget.writeOutline(null);
|
||||
if (fullCompile) {
|
||||
p = await sourceTarget.writeProgram(null, astKind);
|
||||
p = await sourceTarget.writeProgram(null);
|
||||
}
|
||||
} on InputError catch (e, s) {
|
||||
return fail(null, e.error, s);
|
||||
|
|
|
@ -12,7 +12,7 @@ class LinkIterator<T> implements Iterator<T> {
|
|||
T _current;
|
||||
Link<T> _link;
|
||||
|
||||
LinkIterator(Link<T> this._link);
|
||||
LinkIterator(this._link);
|
||||
|
||||
T get current => _current;
|
||||
|
||||
|
@ -64,7 +64,7 @@ class LinkEntry<T> extends Link<T> {
|
|||
final T head;
|
||||
Link<T> tail;
|
||||
|
||||
LinkEntry(T this.head, [Link<T> tail])
|
||||
LinkEntry(this.head, [Link<T> tail])
|
||||
: this.tail = ((tail == null) ? const Link() : tail);
|
||||
|
||||
Link<T> prepend(T element) {
|
||||
|
|
|
@ -32,7 +32,7 @@ final subpackageRules = {
|
|||
'lib/src/base': new SubpackageRules(
|
||||
mayImportAnalyzer: true, allowedDependencies: ['lib']),
|
||||
'lib/src/fasta':
|
||||
new SubpackageRules(mayImportAnalyzer: true, allowedDependencies: [
|
||||
new SubpackageRules(mayImportAnalyzer: false, allowedDependencies: [
|
||||
'lib/src/fasta/builder',
|
||||
'lib/src/fasta/dill',
|
||||
'lib/src/fasta/kernel',
|
||||
|
@ -89,7 +89,6 @@ final subpackageRules = {
|
|||
]),
|
||||
'lib/src/fasta/source': new SubpackageRules(allowedDependencies: [
|
||||
'lib/src/fasta',
|
||||
'lib/src/fasta/analyzer',
|
||||
'lib/src/fasta/builder',
|
||||
'lib/src/fasta/dill',
|
||||
'lib/src/fasta/kernel',
|
||||
|
@ -102,6 +101,7 @@ final subpackageRules = {
|
|||
'lib/src/fasta',
|
||||
'lib/src/fasta/dill',
|
||||
'lib/src/fasta/kernel',
|
||||
'lib/src/fasta/analyzer',
|
||||
]),
|
||||
'lib/src/fasta/util': new SubpackageRules(),
|
||||
'lib/src/scanner': new SubpackageRules(allowedDependencies: [
|
||||
|
|
|
@ -9,7 +9,6 @@ import 'dart:async';
|
|||
import 'dart:io';
|
||||
|
||||
import 'package:front_end/src/fasta/analyzer/ast_builder.dart';
|
||||
import 'package:front_end/src/fasta/ast_kind.dart' show AstKind;
|
||||
import 'package:front_end/src/fasta/dill/dill_target.dart' show DillTarget;
|
||||
import 'package:front_end/src/fasta/kernel/kernel_target.dart'
|
||||
show KernelTarget;
|
||||
|
@ -276,7 +275,7 @@ generateKernel(Uri entryUri, {bool compileSdk: true}) async {
|
|||
}
|
||||
await dillTarget.writeOutline(null);
|
||||
var program = await kernelTarget.writeOutline(null);
|
||||
program = await kernelTarget.writeProgram(null, AstKind.Kernel);
|
||||
program = await kernelTarget.writeProgram(null);
|
||||
if (kernelTarget.errors.isNotEmpty) {
|
||||
throw kernelTarget.errors.first;
|
||||
}
|
||||
|
|
|
@ -34,7 +34,6 @@ import 'package:front_end/src/fasta/translate_uri.dart' show TranslateUri;
|
|||
import 'package:front_end/src/fasta/ticker.dart' show Ticker;
|
||||
import 'package:front_end/src/fasta/kernel/kernel_target.dart'
|
||||
show KernelTarget;
|
||||
import 'package:front_end/src/fasta/ast_kind.dart' show AstKind;
|
||||
import 'package:front_end/src/fasta/errors.dart' show InputError;
|
||||
|
||||
const bool verbose = const bool.fromEnvironment('DFE_VERBOSE');
|
||||
|
@ -122,7 +121,7 @@ Future<CompilationResult> parseScriptImpl(
|
|||
kernelTarget.read(fileName);
|
||||
await dillTarget.writeOutline(null);
|
||||
program = await kernelTarget.writeOutline(null);
|
||||
program = await kernelTarget.writeProgram(null, AstKind.Kernel);
|
||||
program = await kernelTarget.writeProgram(null);
|
||||
if (kernelTarget.errors.isNotEmpty) {
|
||||
return new CompilationError(kernelTarget.errors
|
||||
.map((err) => err.toString())
|
||||
|
|
Loading…
Reference in a new issue