Index: dart/sdk/lib/_internal/compiler/implementation/deferred_load.dart |
diff --git a/dart/sdk/lib/_internal/compiler/implementation/deferred_load.dart b/dart/sdk/lib/_internal/compiler/implementation/deferred_load.dart |
new file mode 100644 |
index 0000000000000000000000000000000000000000..1b5295db3fcd8a9196910f74b7d5d8561d258084 |
--- /dev/null |
+++ b/dart/sdk/lib/_internal/compiler/implementation/deferred_load.dart |
@@ -0,0 +1,64 @@ |
+// Copyright (c) 2013, 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. |
+ |
+class DeferredLoadTask extends CompilerTask { |
+ DeferredLoadTask(Compiler compiler) : super(compiler); |
+ String get name => 'Lazy'; |
+ final Set<LibraryElement> deferredLibraries = new Set<LibraryElement>(); |
+ |
+ bool isDeferred(Element element) { |
+ // TODO(ahe): This is really a graph coloring problem. We should |
+ // make sure that libraries and elements only used by a deferred |
+ // library are also deferred. |
+ // Also, if something is deferred depends on your |
+ // perspective. Inside a deferred library, other elements of the |
+ // same library are not deferred. We should add an extra parameter |
+ // to this method to indicate "from where". |
+ return deferredLibraries.contains(element.getLibrary()); |
+ } |
+ |
+ void registerMainApp(LibraryElement mainApp) { |
+ if (mainApp == null) return; |
+ compiler.withCurrentElement(mainApp, () { |
+ deferredLibraries.addAll(new List.from(findDeferredLibraries(mainApp))); |
+ }); |
+ } |
+ |
+ Link<Element> findDeferredLibraries(LibraryElement library) { |
+ Link<Element> link = const Link<Element>(); |
+ for (LibraryTag tag in library.tags) { |
+ for (MetadataAnnotation metadata in tag.metadata) { |
+ metadata.ensureResolved(compiler); |
+ if (metadata.value.type.element == compiler.deferLoadClass) { |
+ ConstructedConstant value = metadata.value; |
+ SourceString expectedName = value.fields[0].toDartString().source; |
+ LibraryElement deferredLibrary = library.getDependency(tag); |
+ link = link.prepend(deferredLibrary); |
+ note(tag, 'Defer loading of $deferredLibrary'); |
+ SourceString actualName = |
+ new SourceString(deferredLibrary.getLibraryOrScriptName()); |
+ if (expectedName != actualName) { |
+ compiler.reportErrorCode( |
+ metadata, |
+ MessageKind.GENERIC, // DO NOT SUBMIT (add proper error code). |
+ {'text': |
+ 'Library name mismatch "${expectedName.slowToString()}" != ' |
+ '"${actualName.slowToString()}"'}); |
+ } else { |
+ // DO NOT SUBMIT (this is for debugging). |
+ note(metadata, |
+ '${actualName.slowToString()} matches $deferredLibrary'); |
+ } |
+ } |
+ } |
+ } |
+ return link; |
+ } |
+ |
+ void note(Spannable node, message) { |
+ compiler.reportMessage(compiler.spanFromSpannable(node), |
+ MessageKind.GENERIC.error({'text': message}), |
+ api.Diagnostic.INFO); |
+ } |
+} |