| 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..298799f8c5e1a2dda5bac73c7323b71f0eb07afe 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.
|
| @@ -97,8 +120,8 @@ part of dart2js;
|
| * point to the 'packages' folder.
|
| *
|
| */
|
| -abstract class LibraryLoader extends CompilerTask {
|
| - LibraryLoader(Compiler compiler) : super(compiler);
|
| +abstract class LibraryLoaderTask implements CompilerTask {
|
| + factory LibraryLoaderTask(Compiler compiler) = _LibraryLoaderTask;
|
|
|
| /**
|
| * Loads the library specified by the [resolvedUri] and returns its
|
| @@ -108,15 +131,21 @@ abstract class LibraryLoader extends CompilerTask {
|
| * [LibraryElement] for the library and computes the import/export scope,
|
| * loading and computing the import/export scopes of all required libraries in
|
| * the process. The method handles cyclic dependency between libraries.
|
| - *
|
| - * 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);
|
| +/// Handle for creating synthesized/patch libraries during library loading.
|
| +abstract class LibraryLoader {
|
| + /// This method must be called when a new synthesized/patch library has been
|
| + /// created to ensure that [library] will part of library dependency graph
|
| + /// used for computing import/export scopes.
|
| + void registerNewLibrary(LibraryElement library);
|
| +
|
| + /// This method must be called when a new synthesized/patch library has been
|
| + /// scanned in order to process the library tags in [library] and thus handle
|
| + /// imports/exports/parts in the synthesized/patch library.
|
| + Future processLibraryTags(LibraryElement library);
|
| }
|
|
|
| /**
|
| @@ -205,8 +234,8 @@ class HideFilter extends CombinatorFilter {
|
| * [LibraryLoader] and [LibraryLoaderTask] is made to hide internal members from
|
| * the [LibraryLoader] interface.
|
| */
|
| -class LibraryLoaderTask extends LibraryLoader {
|
| - LibraryLoaderTask(Compiler compiler) : super(compiler);
|
| +class _LibraryLoaderTask extends CompilerTask implements LibraryLoaderTask {
|
| + _LibraryLoaderTask(Compiler compiler) : super(compiler);
|
| String get name => 'LibraryLoader';
|
|
|
| final Map<Uri, LibraryElement> libraryResourceUriMap =
|
| @@ -221,7 +250,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, () {
|
| @@ -270,7 +299,7 @@ class LibraryLoaderTask extends LibraryLoader {
|
| var libraryDependencies = new LinkBuilder<LibraryDependency>();
|
| Uri base = library.entryCompilationUnit.script.readableUri;
|
|
|
| - // TODO(rnystrom): Remove .toList() here if #11523 is fixed.
|
| + // TODO(johnniwinther): Reverse the tag list on access and cache the result.
|
| return Future.forEach(library.tags.reverse().toList(), (LibraryTag tag) {
|
| return compiler.withCurrentElement(library, () {
|
| if (tag.isImport) {
|
| @@ -301,17 +330,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) {
|
| @@ -320,7 +343,6 @@ class LibraryLoaderTask extends LibraryLoader {
|
| }
|
| });
|
| }).then((_) {
|
| - // TODO(rnystrom): Remove .toList() here if #11523 is fixed.
|
| return Future.forEach(libraryDependencies.toLink().toList(), (tag) {
|
| return compiler.withCurrentElement(library, () {
|
| return registerLibraryFromTag(handler, library, tag);
|
| @@ -386,16 +408,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,7 +477,6 @@ class LibraryLoaderTask extends LibraryLoader {
|
| if (script == null) return null;
|
| LibraryElement element = new LibraryElementX(script, resolvedUri);
|
| compiler.withCurrentElement(element, () {
|
| - compiler.onLibraryCreated(element);
|
| handler.registerNewLibrary(element);
|
| native.maybeEnableNative(compiler, element);
|
| compiler.libraries[resolvedUri.toString()] = element;
|
| @@ -807,8 +818,8 @@ class LibraryDependencyNode {
|
| * libraries and to compute their import/export scopes through a fixed-point
|
| * algorithm.
|
| */
|
| -class LibraryDependencyHandler {
|
| - final Compiler compiler;
|
| +class LibraryDependencyHandler implements LibraryLoader {
|
| + final _LibraryLoaderTask task;
|
|
|
| /**
|
| * Newly loaded libraries and their corresponding node in the library
|
| @@ -819,7 +830,9 @@ class LibraryDependencyHandler {
|
| Map<LibraryElement, LibraryDependencyNode> nodeMap =
|
| new Map<LibraryElement, LibraryDependencyNode>();
|
|
|
| - LibraryDependencyHandler(Compiler this.compiler);
|
| + LibraryDependencyHandler(this.task);
|
| +
|
| + Compiler get compiler => task.compiler;
|
|
|
| /// The libraries loaded with this handler.
|
| Iterable<LibraryElement> get loadedLibraries => nodeMap.keys;
|
| @@ -908,6 +921,7 @@ class LibraryDependencyHandler {
|
| */
|
| void registerNewLibrary(LibraryElement library) {
|
| nodeMap[library] = new LibraryDependencyNode(library);
|
| + compiler.onLibraryCreated(library);
|
| }
|
|
|
| /**
|
| @@ -917,4 +931,8 @@ class LibraryDependencyHandler {
|
| void registerLibraryExports(LibraryElement library) {
|
| nodeMap[library].registerInitialExports();
|
| }
|
| +
|
| + Future processLibraryTags(LibraryElement library) {
|
| + return task.processLibraryTags(this, library);
|
| + }
|
| }
|
|
|