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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file.
4
5 class DeferredLoadTask extends CompilerTask {
6 DeferredLoadTask(Compiler compiler) : super(compiler);
7 String get name => 'Lazy';
8 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.
9
10 bool isDeferred(Element element) => deferredLibraries.contains(element.getLibr ary());
11
12 void registerMainApp(LibraryElement mainApp) {
13 if (mainApp == null) return;
14 compiler.withCurrentElement(mainApp, () {
15 deferredLibraries.addAll(new List.from(findDeferredLibraries(mainApp)));
16 });
17 }
18
19 Link<Element> findDeferredLibraries(LibraryElement library) {
20 Link<Element> link = const Link<Element>();
21 for (LibraryTag tag in library.tags) {
22 for (MetadataAnnotation metadata in tag.metadata) {
23 metadata.ensureResolved(compiler);
24 if (metadata.value.type.element == compiler.deferLoadClass) {
25 ConstructedConstant value = metadata.value;
26 SourceString expectedName = value.fields[0].toDartString().source;
27 LibraryElement deferredLibrary = library.getDependency(tag);
28 link = link.prepend(deferredLibrary);
29 note(tag, 'Defer loading of $deferredLibrary');
30 SourceString actualName =
31 new SourceString(deferredLibrary.getLibraryOrScriptName());
32 if (expectedName != actualName) {
33 compiler.reportErrorCode(
34 metadata,
35 MessageKind.GENERIC,
36 {'text':'Library name mismatch "${expectedName.slowToString()}" != "${actualName.slowToString()}"'});
37 } else {
38 note(metadata, '${actualName.slowToString()} matches $deferredLibrar y');
39 }
40 }
41 }
42 }
43 return link;
44 }
45
46 void note(Spannable node, message) {
47 compiler.reportMessage(compiler.spanFromSpannable(node),
48 MessageKind.GENERIC.error({'text': message}),
49 api.Diagnostic.INFO);
50 }
51 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698