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

Side by Side Diff: dart/sdk/lib/_internal/compiler/implementation/deferred_load.dart

Issue 12294028: Fix warnings spotted by dart. (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
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 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 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. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 library deferred_load; 5 library deferred_load;
6 6
7 import 'dart:uri'; 7 import 'dart:uri';
8 8
9 import 'dart2jslib.dart' 9 import 'dart2jslib.dart'
10 show Compiler, 10 show Compiler,
11 CompilerTask, 11 CompilerTask,
12 ConstructedConstant, 12 ConstructedConstant,
13 SourceString; 13 MessageKind,
14 SourceString,
15 StringConstant;
14 16
15 import 'elements/elements.dart' 17 import 'elements/elements.dart'
16 show ClassElement, 18 show ClassElement,
17 Element, 19 Element,
18 LibraryElement, 20 LibraryElement,
19 MetadataAnnotation; 21 MetadataAnnotation;
20 22
21 import 'util/util.dart' 23 import 'util/util.dart'
22 show Link; 24 show Link;
23 25
(...skipping 16 matching lines...) Expand all
40 } 42 }
41 return cachedDeferredLibraryClass; 43 return cachedDeferredLibraryClass;
42 } 44 }
43 45
44 ClassElement findDeferredLibraryClass() { 46 ClassElement findDeferredLibraryClass() {
45 var uri = new Uri.fromComponents(scheme: 'dart', path: 'async'); 47 var uri = new Uri.fromComponents(scheme: 'dart', path: 'async');
46 LibraryElement asyncLibrary = 48 LibraryElement asyncLibrary =
47 compiler.libraryLoader.loadLibrary(uri, null, uri); 49 compiler.libraryLoader.loadLibrary(uri, null, uri);
48 var element = asyncLibrary.find(const SourceString('DeferredLibrary')); 50 var element = asyncLibrary.find(const SourceString('DeferredLibrary'));
49 if (element == null) { 51 if (element == null) {
50 internalErrorOnElement( 52 compiler.internalErrorOnElement(
51 asyncLibrary, 53 asyncLibrary,
52 'dart:async library does not contain required class: ' 54 'dart:async library does not contain required class: '
53 'DeferredLibrary'); 55 'DeferredLibrary');
54 } 56 }
55 return element; 57 return element;
56 } 58 }
57 59
58 bool isDeferred(Element element) { 60 bool isDeferred(Element element) {
59 // TODO(ahe): This is really a graph coloring problem. We should 61 // TODO(ahe): This is really a graph coloring problem. We should
60 // make sure that libraries and elements only used by a deferred 62 // make sure that libraries and elements only used by a deferred
61 // library are also deferred. 63 // library are also deferred.
62 // Also, if something is deferred depends on your 64 // Also, if something is deferred depends on your
63 // perspective. Inside a deferred library, other elements of the 65 // perspective. Inside a deferred library, other elements of the
64 // same library are not deferred. We should add an extra parameter 66 // same library are not deferred. We should add an extra parameter
65 // to this method to indicate "from where". 67 // to this method to indicate "from where".
66 return deferredLibraries.contains(element.getLibrary()); 68 return deferredLibraries.contains(element.getLibrary());
67 } 69 }
68 70
69 void registerMainApp(LibraryElement mainApp) { 71 void registerMainApp(LibraryElement mainApp) {
70 if (mainApp == null) return; 72 if (mainApp == null) return;
71 measureElement(mainApp, () { 73 measureElement(mainApp, () {
72 deferredLibraries.addAll(findDeferredLibraries(mainApp)); 74 deferredLibraries.addAll(findDeferredLibraries(mainApp));
73 }); 75 });
74 } 76 }
75 77
76 Link<Element> findDeferredLibraries(LibraryElement library) { 78 Link<LibraryElement> findDeferredLibraries(LibraryElement library) {
77 Link<LibraryElement> link = const Link<LibraryElement>(); 79 Link<LibraryElement> link = const Link<LibraryElement>();
78 for (LibraryTag tag in library.tags) { 80 for (LibraryTag tag in library.tags) {
79 Link<MetadataAnnotation> metadata = tag.metadata; 81 Link<MetadataAnnotation> metadata = tag.metadata;
80 if (metadata == null) continue; 82 if (metadata == null) continue;
81 for (MetadataAnnotation metadata in tag.metadata) { 83 for (MetadataAnnotation metadata in tag.metadata) {
82 metadata.ensureResolved(compiler); 84 metadata.ensureResolved(compiler);
83 Element element = metadata.value.computeType(compiler).element; 85 Element element = metadata.value.computeType(compiler).element;
84 if (element == deferredLibraryClass) { 86 if (element == deferredLibraryClass) {
85 ConstructedConstant value = metadata.value; 87 ConstructedConstant value = metadata.value;
86 SourceString expectedName = value.fields[0].toDartString().source; 88 StringConstant nameField = value.fields[0];
89 SourceString expectedName = nameField.toDartString().source;
87 LibraryElement deferredLibrary = library.getLibraryFromTag(tag); 90 LibraryElement deferredLibrary = library.getLibraryFromTag(tag);
88 link = link.prepend(deferredLibrary); 91 link = link.prepend(deferredLibrary);
89 SourceString actualName = 92 SourceString actualName =
90 new SourceString(deferredLibrary.getLibraryOrScriptName()); 93 new SourceString(deferredLibrary.getLibraryOrScriptName());
91 if (expectedName != actualName) { 94 if (expectedName != actualName) {
92 compiler.reportErrorCode( 95 compiler.reportErrorCode(
93 metadata, 96 metadata,
94 MessageKind.DEFERRED_LIBRARY_NAME_MISMATCH, 97 MessageKind.DEFERRED_LIBRARY_NAME_MISMATCH,
95 { 'expectedName': expectedName.slowToString(), 98 { 'expectedName': expectedName.slowToString(),
96 'actualName': actualName.slowToString()}); 99 'actualName': actualName.slowToString()});
97 } 100 }
98 } 101 }
99 } 102 }
100 } 103 }
101 return link; 104 return link;
102 } 105 }
103 } 106 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698