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

Unified Diff: sdk/lib/_internal/compiler/implementation/library_loader.dart

Issue 350693007: Load patches via callback. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 6 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: sdk/lib/_internal/compiler/implementation/library_loader.dart
diff --git a/sdk/lib/_internal/compiler/implementation/library_loader.dart b/sdk/lib/_internal/compiler/implementation/library_loader.dart
index c9b2d5c4f3938fed74fcefb0f1b57f879876c97f..bc6eac33022dc6a9e2df00962e2215e2e18a83fd 100644
--- a/sdk/lib/_internal/compiler/implementation/library_loader.dart
+++ b/sdk/lib/_internal/compiler/implementation/library_loader.dart
@@ -2,7 +2,30 @@
// 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.
-part of dart2js;
+library dart2js.library_loader;
+
+import 'dart:async';
+import 'dart2jslib.dart'
+ show Compiler,
+ CompilerTask,
+ MessageKind,
+ Script,
+ invariant;
+import 'elements/elements.dart'
+ show CompilationUnitElement,
+ Element,
+ LibraryElement,
+ PrefixElement;
+import 'elements/modelx.dart'
+ show CompilationUnitElementX,
+ DeferredLoaderGetterElementX,
+ ErroneousElementX,
+ LibraryElementX,
+ PrefixElementX;
+import 'helpers/helpers.dart';
+import 'native_handler.dart' as native;
+import 'tree/tree.dart';
+import 'util/util.dart' show Link, LinkBuilder;
/**
* [CompilerTask] for loading libraries and setting up the import/export scopes.
@@ -112,11 +135,21 @@ abstract class LibraryLoader extends CompilerTask {
* This is the main entry point for [LibraryLoader].
*/
Future<LibraryElement> loadLibrary(Uri resolvedUri);
+}
- // TODO(johnniwinther): Remove this when patches don't need special parsing.
- Future registerLibraryFromTag(LibraryDependencyHandler handler,
- LibraryElement library,
- LibraryDependency tag);
+/// Callback for creating synthesized/patch libraries during library loading.
+abstract class LibraryLoaderCallback {
floitsch 2014/06/23 19:12:33 Don't call this "callback". It took me some time t
Johnni Winther 2014/06/24 08:11:20 Done.
+ /// Call this when a new synthesized/patch library has been created.
floitsch 2014/06/23 19:12:33 This is ambiguous. Who needs to call this method?
Johnni Winther 2014/06/24 08:11:20 Done.
+ ///
+ /// This call ensures that [library] will part of library dependency graph
+ /// used for computing import/export scopes.
+ void onLibraryCreated(LibraryElement library);
+
+ /// Call this when a new synthesized/patch library has been scanned.
+ ///
+ /// On this call library tags in [library] will be processed, allowing for
+ /// imports/exports/parts in the synthesized/patch library.
+ Future onLibraryScanned(LibraryElement library);
}
/**
@@ -221,7 +254,7 @@ class LibraryLoaderTask extends LibraryLoader {
assert(currentHandler == null);
// TODO(johnniwinther): Ensure that currentHandler correctly encloses the
// loading of a library cluster.
- currentHandler = new LibraryDependencyHandler(compiler);
+ currentHandler = new LibraryDependencyHandler(this);
return createLibrary(currentHandler, null, resolvedUri)
.then((LibraryElement library) {
return compiler.withCurrentElement(library, () {
@@ -301,17 +334,11 @@ class LibraryLoaderTask extends LibraryLoader {
}
});
}).then((_) {
- // TODO(johnniwinther): Move callback to after patching.
- compiler.onLibraryScanned(library);
- return compiler.withCurrentElement(library, () {
- checkDuplicatedLibraryName(library);
- // Apply patch, if any.
- if (library.isPlatformLibrary) {
- return patchDartLibrary(handler, library, library.canonicalUri.path);
- }
- });
+ return compiler.onLibraryScanned(library, handler);
}).then((_) {
return compiler.withCurrentElement(library, () {
+ checkDuplicatedLibraryName(library);
+
// Import dart:core if not already imported.
if (!importsDartCore && !isDartCore(library.canonicalUri)) {
return loadCoreLibrary(handler).then((LibraryElement coreLibrary) {
@@ -386,16 +413,6 @@ class LibraryLoaderTask extends LibraryLoader {
});
}
- Future patchDartLibrary(LibraryDependencyHandler handler,
- LibraryElement library,
- String dartLibraryPath) {
- if (library.isPatched) return new Future.value();
- Uri patchUri = compiler.resolvePatchUri(dartLibraryPath);
- if (patchUri == null) return new Future.value();
-
- return compiler.patchParser.patchLibrary(handler, patchUri, library);
- }
-
/**
* Handle a part tag in the scope of [library]. The [resolvedUri] given is
* used as is, any URI resolution should be done beforehand.
@@ -465,8 +482,7 @@ class LibraryLoaderTask extends LibraryLoader {
if (script == null) return null;
LibraryElement element = new LibraryElementX(script, resolvedUri);
compiler.withCurrentElement(element, () {
- compiler.onLibraryCreated(element);
- handler.registerNewLibrary(element);
+ handler.onLibraryCreated(element);
native.maybeEnableNative(compiler, element);
compiler.libraries[resolvedUri.toString()] = element;
compiler.scanner.scanLibrary(element);
@@ -807,8 +823,8 @@ class LibraryDependencyNode {
* libraries and to compute their import/export scopes through a fixed-point
* algorithm.
*/
-class LibraryDependencyHandler {
- final Compiler compiler;
+class LibraryDependencyHandler implements LibraryLoaderCallback {
+ final LibraryLoaderTask task;
/**
* Newly loaded libraries and their corresponding node in the library
@@ -819,7 +835,9 @@ class LibraryDependencyHandler {
Map<LibraryElement, LibraryDependencyNode> nodeMap =
new Map<LibraryElement, LibraryDependencyNode>();
- LibraryDependencyHandler(Compiler this.compiler);
+ LibraryDependencyHandler(LibraryLoaderTask this.task);
+
+ Compiler get compiler => task.compiler;
/// The libraries loaded with this handler.
Iterable<LibraryElement> get loadedLibraries => nodeMap.keys;
@@ -917,4 +935,13 @@ class LibraryDependencyHandler {
void registerLibraryExports(LibraryElement library) {
nodeMap[library].registerInitialExports();
}
+
+ void onLibraryCreated(LibraryElement library) {
+ compiler.onLibraryCreated(library);
+ registerNewLibrary(library);
+ }
+
+ Future onLibraryScanned(LibraryElement library) {
+ return task.processLibraryTags(this, library);
+ }
}

Powered by Google App Engine
This is Rietveld 408576698