OLD | NEW |
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 part of dart2js; | 5 part of dart2js; |
6 | 6 |
7 /** | 7 /** |
8 * If true, print a warning for each method that was resolved, but not | 8 * If true, print a warning for each method that was resolved, but not |
9 * compiled. | 9 * compiled. |
10 */ | 10 */ |
(...skipping 486 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
497 /** | 497 /** |
498 * Perform an operation, [f], returning the return value from [f]. If an | 498 * Perform an operation, [f], returning the return value from [f]. If an |
499 * error occurs then report it as having occurred during compilation of | 499 * error occurs then report it as having occurred during compilation of |
500 * [element]. Can be nested. | 500 * [element]. Can be nested. |
501 */ | 501 */ |
502 withCurrentElement(Element element, f()) { | 502 withCurrentElement(Element element, f()) { |
503 Element old = currentElement; | 503 Element old = currentElement; |
504 _currentElement = element; | 504 _currentElement = element; |
505 try { | 505 try { |
506 return f(); | 506 return f(); |
507 } on SpannableAssertionFailure catch (ex, s) { | 507 } on SpannableAssertionFailure catch (ex) { |
508 if (!hasCrashed) { | 508 if (!hasCrashed) { |
509 String message = (ex.message != null) ? tryToString(ex.message) | 509 String message = (ex.message != null) ? tryToString(ex.message) |
510 : tryToString(ex); | 510 : tryToString(ex); |
511 SourceSpan span = spanFromSpannable(ex.node); | 511 SourceSpan span = spanFromSpannable(ex.node); |
512 reportError(ex.node, MessageKind.GENERIC, {'text': message}); | 512 reportError(ex.node, MessageKind.GENERIC, {'text': message}); |
513 pleaseReportCrash(s, 'The compiler crashed: $message.'); | 513 pleaseReportCrash(); |
514 } | 514 } |
515 hasCrashed = true; | 515 hasCrashed = true; |
516 throw new CompilerCancelledException('The compiler crashed.'); | 516 rethrow; |
517 } on CompilerCancelledException catch (ex) { | 517 } on CompilerCancelledException catch (ex) { |
518 rethrow; | 518 rethrow; |
519 } on StackOverflowError catch (ex) { | 519 } on StackOverflowError catch (ex) { |
520 // We cannot report anything useful in this case, because we | 520 // We cannot report anything useful in this case, because we |
521 // do not have enough stack space. | 521 // do not have enough stack space. |
522 rethrow; | 522 rethrow; |
523 } catch (ex, s) { | 523 } catch (ex) { |
524 if (hasCrashed) rethrow; | 524 if (hasCrashed) rethrow; |
525 String message = 'The compiler crashed: ${tryToString(ex)}.'; | |
526 try { | 525 try { |
527 unhandledExceptionOnElement(element, s, message); | 526 unhandledExceptionOnElement(element); |
528 } catch (doubleFault) { | 527 } catch (doubleFault) { |
529 // Ignoring exceptions in exception handling. | 528 // Ignoring exceptions in exception handling. |
530 } | 529 } |
531 throw new CompilerCancelledException(message); | 530 rethrow; |
532 } finally { | 531 } finally { |
533 _currentElement = old; | 532 _currentElement = old; |
534 } | 533 } |
535 } | 534 } |
536 | 535 |
537 List<CompilerTask> tasks; | 536 List<CompilerTask> tasks; |
538 ScannerTask scanner; | 537 ScannerTask scanner; |
539 DietParserTask dietParser; | 538 DietParserTask dietParser; |
540 ParserTask parser; | 539 ParserTask parser; |
541 PatchParserTask patchParser; | 540 PatchParserTask patchParser; |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
697 Element element}) { | 696 Element element}) { |
698 cancel('Internal Error: $message', | 697 cancel('Internal Error: $message', |
699 node: node, token: token, | 698 node: node, token: token, |
700 instruction: instruction, element: element); | 699 instruction: instruction, element: element); |
701 } | 700 } |
702 | 701 |
703 void internalErrorOnElement(Element element, String message) { | 702 void internalErrorOnElement(Element element, String message) { |
704 internalError(message, element: element); | 703 internalError(message, element: element); |
705 } | 704 } |
706 | 705 |
707 void unhandledExceptionOnElement(Element element, | 706 void unhandledExceptionOnElement(Element element) { |
708 StackTrace stackTrace, | |
709 String message) { | |
710 if (hasCrashed) return; | 707 if (hasCrashed) return; |
711 hasCrashed = true; | 708 hasCrashed = true; |
712 reportDiagnostic(spanFromElement(element), | 709 reportDiagnostic(spanFromElement(element), |
713 MessageKind.COMPILER_CRASHED.error().toString(), | 710 MessageKind.COMPILER_CRASHED.error().toString(), |
714 api.Diagnostic.CRASH); | 711 api.Diagnostic.CRASH); |
715 pleaseReportCrash(stackTrace, message); | 712 pleaseReportCrash(); |
716 } | 713 } |
717 | 714 |
718 void pleaseReportCrash(StackTrace stackTrace, String message) { | 715 void pleaseReportCrash() { |
719 print(MessageKind.PLEASE_REPORT_THE_CRASH.message({'buildId': buildId})); | 716 print(MessageKind.PLEASE_REPORT_THE_CRASH.message({'buildId': buildId})); |
720 if (message != null) { | |
721 print(message); | |
722 } | |
723 if (stackTrace != null) { | |
724 print(stackTrace); | |
725 } | |
726 } | 717 } |
727 | 718 |
728 void cancel(String reason, {Node node, Token token, | 719 void cancel(String reason, {Node node, Token token, |
729 HInstruction instruction, Element element}) { | 720 HInstruction instruction, Element element}) { |
730 assembledCode = null; // Compilation failed. Make sure that we | 721 assembledCode = null; // Compilation failed. Make sure that we |
731 // don't return a bogus result. | 722 // don't return a bogus result. |
732 Spannable spannable = null; | 723 Spannable spannable = null; |
733 if (node != null) { | 724 if (node != null) { |
734 spannable = node; | 725 spannable = node; |
735 } else if (token != null) { | 726 } else if (token != null) { |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
769 } | 760 } |
770 } | 761 } |
771 | 762 |
772 void log(message) { | 763 void log(message) { |
773 reportDiagnostic(null, message, api.Diagnostic.VERBOSE_INFO); | 764 reportDiagnostic(null, message, api.Diagnostic.VERBOSE_INFO); |
774 } | 765 } |
775 | 766 |
776 Future<bool> run(Uri uri) { | 767 Future<bool> run(Uri uri) { |
777 totalCompileTime.start(); | 768 totalCompileTime.start(); |
778 | 769 |
779 return new Future.sync(() => runCompiler(uri)).catchError((error, trace) { | 770 return new Future.sync(() => runCompiler(uri)).catchError((error) { |
780 if (error is CompilerCancelledException) { | 771 if (error is CompilerCancelledException) { |
781 log('Error: $error'); | 772 log('Error: $error'); |
782 return false; | 773 return false; |
783 } | 774 } |
784 | 775 |
785 try { | 776 try { |
786 if (!hasCrashed) { | 777 if (!hasCrashed) { |
787 hasCrashed = true; | 778 hasCrashed = true; |
788 reportDiagnostic(new SourceSpan(uri, 0, 0), | 779 reportDiagnostic(new SourceSpan(uri, 0, 0), |
789 MessageKind.COMPILER_CRASHED.error().toString(), | 780 MessageKind.COMPILER_CRASHED.error().toString(), |
790 api.Diagnostic.CRASH); | 781 api.Diagnostic.CRASH); |
791 String message = 'The compiler crashed.'; | 782 pleaseReportCrash(); |
792 pleaseReportCrash(trace, message); | |
793 } | 783 } |
794 } catch (doubleFault) { | 784 } catch (doubleFault) { |
795 // Ignoring exceptions in exception handling. | 785 // Ignoring exceptions in exception handling. |
796 } | 786 } |
797 throw error; | 787 throw error; |
798 }).whenComplete(() { | 788 }).whenComplete(() { |
799 tracer.close(); | 789 tracer.close(); |
800 totalCompileTime.stop(); | 790 totalCompileTime.stop(); |
801 }).then((_) { | 791 }).then((_) { |
802 return !compilationFailed; | 792 return !compilationFailed; |
(...skipping 858 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1661 | 1651 |
1662 void close() {} | 1652 void close() {} |
1663 | 1653 |
1664 toString() => name; | 1654 toString() => name; |
1665 | 1655 |
1666 /// Convenience method for getting an [api.CompilerOutputProvider]. | 1656 /// Convenience method for getting an [api.CompilerOutputProvider]. |
1667 static NullSink outputProvider(String name, String extension) { | 1657 static NullSink outputProvider(String name, String extension) { |
1668 return new NullSink('$name.$extension'); | 1658 return new NullSink('$name.$extension'); |
1669 } | 1659 } |
1670 } | 1660 } |
OLD | NEW |