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

Unified Diff: pkg/compiler/lib/src/compiler.dart

Issue 1819053002: Split loader from the rest of the compiler. This adds several abstractions to (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: add environment.dart Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: pkg/compiler/lib/src/compiler.dart
diff --git a/pkg/compiler/lib/src/compiler.dart b/pkg/compiler/lib/src/compiler.dart
index 3152635a7b7bf0dfc0f1aad441f806ad10b149e1..cea5dd4b3366a57d07423dbfcb6080caf426cc5b 100644
--- a/pkg/compiler/lib/src/compiler.dart
+++ b/pkg/compiler/lib/src/compiler.dart
@@ -73,6 +73,7 @@ import 'enqueue.dart' show
EnqueueTask,
ResolutionEnqueuer,
QueueFilter;
+import 'environment.dart';
import 'io/source_information.dart' show
SourceInformation;
import 'js_backend/backend_helpers.dart' as js_backend show
@@ -80,9 +81,13 @@ import 'js_backend/backend_helpers.dart' as js_backend show
import 'js_backend/js_backend.dart' as js_backend show
JavaScriptBackend;
import 'library_loader.dart' show
+ ElementScanner,
LibraryLoader,
LibraryLoaderTask,
- LoadedLibraries;
+ LoadedLibraries,
+ LibraryLoaderListener,
+ ResolvedUriTranslator,
+ ScriptLoader;
import 'mirrors_used.dart' show
MirrorUsageAnalyzerTask;
import 'common/names.dart' show
@@ -146,7 +151,7 @@ import 'util/util.dart' show
import 'world.dart' show
World;
-abstract class Compiler {
+abstract class Compiler implements LibraryLoaderListener {
final Stopwatch totalCompileTime = new Stopwatch();
int nextFreeClassId = 0;
@@ -280,7 +285,10 @@ abstract class Compiler {
/// Tracks elements with compile-time errors.
final Set<Element> elementsWithCompileTimeErrors = new Set<Element>();
- fromEnvironment(String name) => null;
+ final Environment environment;
+ // TODO(sigmund): delete once we migrate the rest of the compiler to use
+ // `environment` directly.
+ fromEnvironment(String name) => environment.valueOf(name);
Harry Terkelsen 2016/03/22 21:49:28 add @deprecated
Siggi Cherem (dart-lang) 2016/03/23 22:51:05 Done.
Element get currentElement => _reporter.currentElement;
@@ -348,7 +356,8 @@ abstract class Compiler {
}
Compiler({api.CompilerOptions options,
- api.CompilerOutput outputProvider})
+ api.CompilerOutput outputProvider,
+ this.environment: const _EmptyEnvironment()})
: this.options = options,
this.cacheStrategy = new CacheStrategy(options.hasIncrementalSupport),
this.userOutputProvider = outputProvider == null
@@ -389,11 +398,17 @@ abstract class Compiler {
}
tasks = [
- libraryLoader = new LibraryLoaderTask(this),
- serialization = new SerializationTask(this),
- scanner = new ScannerTask(this),
dietParser = new DietParserTask(
this, enableConditionalDirectives: options.enableConditionalDirectives),
Harry Terkelsen 2016/03/22 21:49:28 long line
+ scanner = new ScannerTask(this),
+ serialization = new SerializationTask(this),
+ libraryLoader = new LibraryLoaderTask(this,
+ new _ResolvedUriTranslator(this),
+ new _ScriptLoader(this),
+ new _ElementScanner(scanner),
+ this.serialization,
+ this,
+ environment),
parser = new ParserTask(
this, enableConditionalDirectives: options.enableConditionalDirectives),
Harry Terkelsen 2016/03/22 21:49:28 ditto
Siggi Cherem (dart-lang) 2016/03/23 22:51:05 Done.
patchParser = new PatchParserTask(
@@ -1151,6 +1166,7 @@ abstract class Compiler {
}
}
+ // TODO(sigmund): move this dart doc somewhere else too.
/**
* Translates the [resolvedUri] into a readable URI.
*
@@ -1175,18 +1191,11 @@ abstract class Compiler {
*
* See [LibraryLoader] for terminology on URIs.
*/
- Future<Script> readScript(Spannable node, Uri readableUri) {
+ Future<Script> readScript(Uri readableUri, [Spannable node]) {
unimplemented(node, 'Compiler.readScript');
return null;
}
- /// Compatible with [readScript] and used by [LibraryLoader] to create
- /// synthetic scripts to recover from read errors and bad URIs.
- Future<Script> synthesizeScript(Spannable node, Uri readableUri) {
- unimplemented(node, 'Compiler.synthesizeScript');
- return null;
- }
-
Element lookupElementIn(ScopeContainerElement container, String name) {
Element element = container.localLookup(name);
if (element == null) {
@@ -1321,10 +1330,6 @@ abstract class Compiler {
return libraryUri;
}
- void diagnoseCrashInUserCode(String message, exception, stackTrace) {
- // Overridden by Compiler in apiimpl.dart.
- }
-
void forgetElement(Element element) {
enqueuer.forgetElement(element);
if (element is MemberElement) {
@@ -2094,3 +2099,35 @@ class GlobalDependencyRegistry extends EagerRegistry {
return _otherDependencies != null ? _otherDependencies : const <Element>[];
}
}
+
+// TODO(sigmund): in the future, each of these classes should be self contained
+// and not use references to `compiler`.
+class _ResolvedUriTranslator implements ResolvedUriTranslator {
+ Compiler compiler;
+ _ResolvedUriTranslator(this.compiler);
+
+ Uri translate(LibraryElement importingLibrary, Uri resolvedUri,
+ [Spannable spannable]) =>
+ compiler.translateResolvedUri(importingLibrary, resolvedUri, spannable);
+}
+
+class _ScriptLoader implements ScriptLoader {
+ Compiler compiler;
+ _ScriptLoader(this.compiler);
+
+ Future<Script> readScript(Uri uri, [Spannable spannable]) =>
+ compiler.readScript(uri, spannable);
+}
+
+class _ElementScanner implements ElementScanner {
+ ScannerTask scanner;
+ _ElementScanner(this.scanner);
+ void scanLibrary(LibraryElement library) => scanner.scanLibrary(library);
+ void scanUnit(CompilationUnitElement unit) => scanner.scan(unit);
+}
+
+class _EmptyEnvironment implements Environment {
+ const _EmptyEnvironment();
+
+ String valueOf(String key) => null;
+}

Powered by Google App Engine
This is Rietveld 408576698