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

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

Issue 17759007: First pass at asynchronous input loading in dart2js. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Change to unix line endings. Created 7 years, 4 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) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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 leg_apiimpl; 5 library leg_apiimpl;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 8
9 import '../compiler.dart' as api; 9 import '../compiler.dart' as api;
10 import 'dart2jslib.dart' as leg; 10 import 'dart2jslib.dart' as leg;
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
130 130
131 String lookupPatchPath(String dartLibraryName) { 131 String lookupPatchPath(String dartLibraryName) {
132 LibraryInfo info = LIBRARIES[dartLibraryName]; 132 LibraryInfo info = LIBRARIES[dartLibraryName];
133 if (info == null) return null; 133 if (info == null) return null;
134 if (!info.isDart2jsLibrary) return null; 134 if (!info.isDart2jsLibrary) return null;
135 String path = info.dart2jsPatchPath; 135 String path = info.dart2jsPatchPath;
136 if (path == null) return null; 136 if (path == null) return null;
137 return "lib/$path"; 137 return "lib/$path";
138 } 138 }
139 139
140 elements.LibraryElement scanBuiltinLibrary(String path) { 140 Future<elements.LibraryElement> scanBuiltinLibrary(String path) {
141 Uri uri = libraryRoot.resolve(lookupLibraryPath(path)); 141 Uri uri = libraryRoot.resolve(lookupLibraryPath(path));
142 Uri canonicalUri = new Uri(scheme: "dart", path: path); 142 Uri canonicalUri = new Uri(scheme: "dart", path: path);
143 elements.LibraryElement library = 143 return libraryLoader.loadLibrary(uri, null, canonicalUri);
144 libraryLoader.loadLibrary(uri, null, canonicalUri);
145 return library;
146 } 144 }
147 145
148 void log(message) { 146 void log(message) {
149 handler(null, null, null, message, api.Diagnostic.VERBOSE_INFO); 147 handler(null, null, null, message, api.Diagnostic.VERBOSE_INFO);
150 } 148 }
151 149
152 /// See [leg.Compiler.translateResolvedUri]. 150 /// See [leg.Compiler.translateResolvedUri].
153 Uri translateResolvedUri(elements.LibraryElement importingLibrary, 151 Uri translateResolvedUri(elements.LibraryElement importingLibrary,
154 Uri resolvedUri, tree.Node node) { 152 Uri resolvedUri, tree.Node node) {
155 if (resolvedUri.scheme == 'dart') { 153 if (resolvedUri.scheme == 'dart') {
156 return translateDartUri(importingLibrary, resolvedUri, node); 154 return translateDartUri(importingLibrary, resolvedUri, node);
157 } 155 }
158 return resolvedUri; 156 return resolvedUri;
159 } 157 }
160 158
161 /** 159 /**
162 * Reads the script designated by [readableUri]. 160 * Reads the script designated by [readableUri].
163 */ 161 */
164 leg.Script readScript(Uri readableUri, [tree.Node node]) { 162 Future<leg.Script> readScript(Uri readableUri, [tree.Node node]) {
165 if (!readableUri.isAbsolute) { 163 if (!readableUri.isAbsolute) {
166 internalError('Relative uri $readableUri provided to readScript(Uri)', 164 internalError('Relative uri $readableUri provided to readScript(Uri)',
167 node: node); 165 node: node);
168 } 166 }
169 return fileReadingTask.measure(() { 167
170 Uri resourceUri = translateUri(readableUri, node); 168 Uri resourceUri = translateUri(readableUri, node);
171 String text = ""; 169 return provider(resourceUri).then((String text) {
172 try {
173 // TODO(ahe): We expect the future to be complete and call value
174 // directly. In effect, we don't support truly asynchronous API.
175 text = deprecatedFutureValue(provider(resourceUri));
176 } catch (exception) {
177 if (node != null) {
178 cancel("$exception", node: node);
179 } else {
180 reportError(
181 null,
182 leg.MessageKind.GENERIC, {'text': 'Error: $exception'});
183 throw new leg.CompilerCancelledException("$exception");
184 }
185 }
186 SourceFile sourceFile = new SourceFile(resourceUri.toString(), text); 170 SourceFile sourceFile = new SourceFile(resourceUri.toString(), text);
187 // We use [readableUri] as the URI for the script since need to preserve 171 // We use [readableUri] as the URI for the script since need to preserve
188 // the scheme in the script because [Script.uri] is used for resolving 172 // the scheme in the script because [Script.uri] is used for resolving
189 // relative URIs mentioned in the script. See the comment on 173 // relative URIs mentioned in the script. See the comment on
190 // [LibraryLoader] for more details. 174 // [LibraryLoader] for more details.
191 return new leg.Script(readableUri, sourceFile); 175 return new leg.Script(readableUri, sourceFile);
176 }).catchError((error) {
177 reportFatalError(
178 node,
179 leg.MessageKind.GENERIC, {'text': 'Error: $error'});
192 }); 180 });
193 } 181 }
194 182
195 /** 183 /**
196 * Translates a readable URI into a resource URI. 184 * Translates a readable URI into a resource URI.
197 * 185 *
198 * See [LibraryLoader] for terminology on URIs. 186 * See [LibraryLoader] for terminology on URIs.
199 */ 187 */
200 Uri translateUri(Uri readableUri, tree.Node node) { 188 Uri translateUri(Uri readableUri, tree.Node node) {
201 switch (readableUri.scheme) { 189 switch (readableUri.scheme) {
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
266 } 254 }
267 255
268 Uri translatePackageUri(Uri uri, tree.Node node) { 256 Uri translatePackageUri(Uri uri, tree.Node node) {
269 if (packageRoot == null) { 257 if (packageRoot == null) {
270 reportFatalError( 258 reportFatalError(
271 node, leg.MessageKind.PACKAGE_ROOT_NOT_SET, {'uri': uri}); 259 node, leg.MessageKind.PACKAGE_ROOT_NOT_SET, {'uri': uri});
272 } 260 }
273 return packageRoot.resolve(uri.path); 261 return packageRoot.resolve(uri.path);
274 } 262 }
275 263
276 bool run(Uri uri) { 264 Future<bool> run(Uri uri) {
277 log('Allowed library categories: $allowedLibraryCategories'); 265 log('Allowed library categories: $allowedLibraryCategories');
278 bool success = super.run(uri); 266 return super.run(uri).then((bool success) {
279 int cumulated = 0; 267 int cumulated = 0;
280 for (final task in tasks) { 268 for (final task in tasks) {
281 cumulated += task.timing; 269 cumulated += task.timing;
282 log('${task.name} took ${task.timing}msec'); 270 log('${task.name} took ${task.timing}msec');
283 } 271 }
284 int total = totalCompileTime.elapsedMilliseconds; 272 int total = totalCompileTime.elapsedMilliseconds;
285 log('Total compile-time ${total}msec;' 273 log('Total compile-time ${total}msec;'
286 ' unaccounted ${total - cumulated}msec'); 274 ' unaccounted ${total - cumulated}msec');
287 return success; 275 return success;
276 });
288 } 277 }
289 278
290 void reportDiagnostic(leg.SourceSpan span, String message, 279 void reportDiagnostic(leg.SourceSpan span, String message,
291 api.Diagnostic kind) { 280 api.Diagnostic kind) {
292 if (identical(kind, api.Diagnostic.ERROR) 281 if (identical(kind, api.Diagnostic.ERROR)
293 || identical(kind, api.Diagnostic.CRASH)) { 282 || identical(kind, api.Diagnostic.CRASH)) {
294 compilationFailed = true; 283 compilationFailed = true;
295 } 284 }
296 // [:span.uri:] might be [:null:] in case of a [Script] with no [uri]. For 285 // [:span.uri:] might be [:null:] in case of a [Script] with no [uri]. For
297 // instance in the [Types] constructor in typechecker.dart. 286 // instance in the [Types] constructor in typechecker.dart.
298 if (span == null || span.uri == null) { 287 if (span == null || span.uri == null) {
299 handler(null, null, null, message, kind); 288 handler(null, null, null, message, kind);
300 } else { 289 } else {
301 handler(translateUri(span.uri, null), span.begin, span.end, 290 handler(translateUri(span.uri, null), span.begin, span.end,
302 message, kind); 291 message, kind);
303 } 292 }
304 } 293 }
305 294
306 bool get isMockCompilation { 295 bool get isMockCompilation {
307 return mockableLibraryUsed 296 return mockableLibraryUsed
308 && (options.indexOf('--allow-mock-compilation') != -1); 297 && (options.indexOf('--allow-mock-compilation') != -1);
309 } 298 }
310 } 299 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698