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

Side by Side Diff: sdk/lib/_internal/compiler/implementation/dart2js.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: Rebased Created 7 years, 3 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 dart2js.cmdline; 5 library dart2js.cmdline;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 import 'dart:io'; 8 import 'dart:io';
9 import 'dart:math' as math; 9 import 'dart:math' as math;
10 10
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
84 } else { 84 } else {
85 handler.handle(argument); 85 handler.handle(argument);
86 } 86 }
87 continue OUTER; 87 continue OUTER;
88 } 88 }
89 } 89 }
90 throw 'Internal error: "$argument" did not match'; 90 throw 'Internal error: "$argument" did not match';
91 } 91 }
92 } 92 }
93 93
94 void compile(List<String> argv) { 94 Future compile(List<String> argv) {
95 bool isWindows = (Platform.operatingSystem == 'windows'); 95 bool isWindows = (Platform.operatingSystem == 'windows');
96 stackTraceFilePrefix = '$currentDirectory'; 96 stackTraceFilePrefix = '$currentDirectory';
97 Uri libraryRoot = currentDirectory; 97 Uri libraryRoot = currentDirectory;
98 Uri out = currentDirectory.resolve('out.js'); 98 Uri out = currentDirectory.resolve('out.js');
99 Uri sourceMapOut = currentDirectory.resolve('out.js.map'); 99 Uri sourceMapOut = currentDirectory.resolve('out.js.map');
100 Uri packageRoot = null; 100 Uri packageRoot = null;
101 List<String> options = new List<String>(); 101 List<String> options = new List<String>();
102 bool explicitOut = false; 102 bool explicitOut = false;
103 bool wantHelp = false; 103 bool wantHelp = false;
104 bool wantVersion = false; 104 bool wantVersion = false;
105 String outputLanguage = 'JavaScript'; 105 String outputLanguage = 'JavaScript';
106 bool stripArgumentSet = false; 106 bool stripArgumentSet = false;
107 bool analyzeOnly = false; 107 bool analyzeOnly = false;
108 // TODO(johnniwinther): Measure time for reading files.
108 SourceFileProvider inputProvider = new SourceFileProvider(); 109 SourceFileProvider inputProvider = new SourceFileProvider();
109 FormattingDiagnosticHandler diagnosticHandler = 110 FormattingDiagnosticHandler diagnosticHandler =
110 new FormattingDiagnosticHandler(inputProvider); 111 new FormattingDiagnosticHandler(inputProvider);
111 112
112 passThrough(String argument) => options.add(argument); 113 passThrough(String argument) => options.add(argument);
113 114
114 if (BUILD_ID != null) { 115 if (BUILD_ID != null) {
115 passThrough("--build-id=$BUILD_ID"); 116 passThrough("--build-id=$BUILD_ID");
116 } 117 }
117 118
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
280 '--output-type=dart'); 281 '--output-type=dart');
281 } 282 }
282 if (arguments.isEmpty) { 283 if (arguments.isEmpty) {
283 helpAndFail('Error: No Dart file specified.'); 284 helpAndFail('Error: No Dart file specified.');
284 } 285 }
285 if (arguments.length > 1) { 286 if (arguments.length > 1) {
286 var extra = arguments.sublist(1); 287 var extra = arguments.sublist(1);
287 helpAndFail('Error: Extra arguments: ${extra.join(" ")}'); 288 helpAndFail('Error: Extra arguments: ${extra.join(" ")}');
288 } 289 }
289 290
290 void handler(Uri uri, int begin, int end, String message,
291 api.Diagnostic kind) {
292 diagnosticHandler.diagnosticHandler(uri, begin, end, message, kind);
293 }
294
295 Uri uri = currentDirectory.resolve(arguments[0]); 291 Uri uri = currentDirectory.resolve(arguments[0]);
296 if (packageRoot == null) { 292 if (packageRoot == null) {
297 packageRoot = uri.resolve('./packages/'); 293 packageRoot = uri.resolve('./packages/');
298 } 294 }
299 295
300 diagnosticHandler.info('package root is $packageRoot'); 296 diagnosticHandler.info('package root is $packageRoot');
301 297
302 int totalCharactersWritten = 0; 298 int totalCharactersWritten = 0;
303 299
304 options.add('--source-map=$sourceMapOut'); 300 options.add('--source-map=$sourceMapOut');
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
379 } 375 }
380 output.closeSync(); 376 output.closeSync();
381 if (isPrimaryOutput) { 377 if (isPrimaryOutput) {
382 totalCharactersWritten += charactersWritten; 378 totalCharactersWritten += charactersWritten;
383 } 379 }
384 } 380 }
385 381
386 return new EventSinkWrapper(writeStringSync, onDone); 382 return new EventSinkWrapper(writeStringSync, onDone);
387 } 383 }
388 384
389 api.compile(uri, libraryRoot, packageRoot, 385 return api.compile(uri, libraryRoot, packageRoot,
390 inputProvider.readStringFromUri, handler, 386 inputProvider, diagnosticHandler,
391 options, outputProvider) 387 options, outputProvider)
392 .then(compilationDone); 388 .then(compilationDone);
393 } 389 }
394 390
395 class EventSinkWrapper extends EventSink<String> { 391 class EventSinkWrapper extends EventSink<String> {
396 var onAdd, onClose; 392 var onAdd, onClose;
397 393
398 EventSinkWrapper(this.onAdd, this.onClose); 394 EventSinkWrapper(this.onAdd, this.onClose);
399 395
400 void add(String data) => onAdd(data); 396 void add(String data) => onAdd(data);
401 397
402 void addError(error) => throw error; 398 void addError(error) => throw error;
(...skipping 14 matching lines...) Expand all
417 var file = new File(uriPathToNative(uri.path)).openSync(mode: FileMode.WRITE); 413 var file = new File(uriPathToNative(uri.path)).openSync(mode: FileMode.WRITE);
418 file.writeStringSync(text); 414 file.writeStringSync(text);
419 file.closeSync(); 415 file.closeSync();
420 } 416 }
421 417
422 void fail(String message) { 418 void fail(String message) {
423 print(message); 419 print(message);
424 exit(1); 420 exit(1);
425 } 421 }
426 422
427 void compilerMain(Options options) { 423 Future compilerMain(Options options) {
428 var root = uriPathToNative("/$LIBRARY_ROOT"); 424 var root = uriPathToNative("/$LIBRARY_ROOT");
429 List<String> argv = ['--library-root=${options.script}$root']; 425 List<String> argv = ['--library-root=${options.script}$root'];
430 argv.addAll(options.arguments); 426 argv.addAll(options.arguments);
431 compile(argv); 427 return compile(argv);
432 } 428 }
433 429
434 void help() { 430 void help() {
435 // This message should be no longer than 20 lines. The default 431 // This message should be no longer than 20 lines. The default
436 // terminal size normally 80x24. Two lines are used for the prompts 432 // terminal size normally 80x24. Two lines are used for the prompts
437 // before and after running the compiler. Another two lines may be 433 // before and after running the compiler. Another two lines may be
438 // used to print an error message. 434 // used to print an error message.
439 print(''' 435 print('''
440 Usage: dart2js [options] dartfile 436 Usage: dart2js [options] dartfile
441 437
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
559 exit(0); 555 exit(0);
560 } 556 }
561 557
562 void helpAndFail(String message) { 558 void helpAndFail(String message) {
563 help(); 559 help();
564 print(''); 560 print('');
565 fail(message); 561 fail(message);
566 } 562 }
567 563
568 void mainWithErrorHandler(Options options) { 564 void mainWithErrorHandler(Options options) {
569 try { 565 compilerMain(options).catchError((exception) {
ahe 2013/09/02 13:43:24 Wrap the call to compilerMain in try-catch.
Johnni Winther 2013/09/03 07:51:39 Done.
570 compilerMain(options);
571 } catch (exception, trace) {
572 try { 566 try {
573 print('Internal error: $exception'); 567 print('Internal error: $exception');
574 } catch (ignored) { 568 } catch (ignored) {
575 print('Internal error: error while printing exception'); 569 print('Internal error: error while printing exception');
576 } 570 }
571
577 try { 572 try {
578 print(trace); 573 var trace = getAttachedStackTrace(exception);
574 if (trace != null) {
575 print(trace);
576 }
579 } finally { 577 } finally {
580 exit(253); // 253 is recognized as a crash by our test scripts. 578 exit(253); // 253 is recognized as a crash by our test scripts.
581 } 579 }
582 } 580 });
583 } 581 }
584 582
585 void main() { 583 void main() {
586 mainWithErrorHandler(new Options()); 584 mainWithErrorHandler(new Options());
587 } 585 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698