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

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

Issue 12033003: Deferred (aka lazy) loading of static functions. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 7 years, 10 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: 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..244c24976170dfb12a6337528c3cfd3cca154bfc
--- /dev/null
+++ b/dart/sdk/lib/_internal/compiler/implementation/deferred_load.dart
@@ -0,0 +1,51 @@
+// 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>();
kasperl 2013/02/05 08:30:53 I guess this will have to be replaced with some so
ahe 2013/02/05 13:54:22 Correct. Added a TODO.
+
+ bool isDeferred(Element element) => 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,
+ {'text':'Library name mismatch "${expectedName.slowToString()}" != "${actualName.slowToString()}"'});
+ } else {
+ 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);
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698