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

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

Issue 206193002: Remove cancel and make crash exit with code 253. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Updated cf. comments. Created 6 years, 9 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 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 677 matching lines...) Expand 10 before | Expand all | Expand 10 after
688 bool get hasBuildId => buildId != UNDETERMINED_BUILD_ID; 688 bool get hasBuildId => buildId != UNDETERMINED_BUILD_ID;
689 689
690 bool get analyzeAll => analyzeAllFlag || compileAll; 690 bool get analyzeAll => analyzeAllFlag || compileAll;
691 691
692 bool get compileAll => false; 692 bool get compileAll => false;
693 693
694 bool get disableTypeInference => disableTypeInferenceFlag; 694 bool get disableTypeInference => disableTypeInferenceFlag;
695 695
696 int getNextFreeClassId() => nextFreeClassId++; 696 int getNextFreeClassId() => nextFreeClassId++;
697 697
698 void unimplemented(String methodName, 698 void unimplemented(Spannable spannable, String methodName) {
699 {Node node, Token token, HInstruction instruction, 699 internalError(spannable, "$methodName not implemented.");
700 Element element}) {
701 internalError("$methodName not implemented",
702 node: node, token: token,
703 instruction: instruction, element: element);
704 } 700 }
705 701
706 void internalError(String message, 702 void internalError(Spannable node, reason) {
707 {Node node, Token token, HInstruction instruction, 703 assembledCode = null; // Compilation failed. Make sure that we
708 Element element}) { 704 // don't return a bogus result.
709 cancel(message, 705 String message = tryToString(reason);
710 node: node, token: token, 706 reportDiagnosticInternal(
711 instruction: instruction, element: element); 707 node, MessageKind.GENERIC, {'text': message}, api.Diagnostic.CRASH);
712 } 708 throw 'Internal Error: $message';
713
714 void internalErrorOnElement(Element element, String message) {
715 internalError(message, element: element);
716 } 709 }
717 710
718 void unhandledExceptionOnElement(Element element) { 711 void unhandledExceptionOnElement(Element element) {
719 if (hasCrashed) return; 712 if (hasCrashed) return;
720 hasCrashed = true; 713 hasCrashed = true;
721 reportDiagnostic(element, 714 reportDiagnostic(element,
722 MessageKind.COMPILER_CRASHED.message(), 715 MessageKind.COMPILER_CRASHED.message(),
723 api.Diagnostic.CRASH); 716 api.Diagnostic.CRASH);
724 pleaseReportCrash(); 717 pleaseReportCrash();
725 } 718 }
726 719
727 void pleaseReportCrash() { 720 void pleaseReportCrash() {
728 print(MessageKind.PLEASE_REPORT_THE_CRASH.message({'buildId': buildId})); 721 print(MessageKind.PLEASE_REPORT_THE_CRASH.message({'buildId': buildId}));
729 } 722 }
730 723
731 void cancel(String reason, {Node node, Token token,
732 HInstruction instruction, Element element}) {
733 assembledCode = null; // Compilation failed. Make sure that we
734 // don't return a bogus result.
735 Spannable spannable = null;
736 if (node != null) {
737 spannable = node;
738 } else if (token != null) {
739 spannable = token;
740 } else if (instruction != null) {
741 spannable = instruction;
742 } else if (element != null) {
743 spannable = element;
744 } else {
745 throw 'No error location for error: $reason';
746 }
747 reportInternalError(spannable, MessageKind.GENERIC, {'text': reason});
748 throw new CompilerCancelledException(reason);
749 }
750
751 SourceSpan spanFromSpannable(Spannable node) { 724 SourceSpan spanFromSpannable(Spannable node) {
725 // TODO(johnniwinther): Disallow `node == null` ?
752 if (node == null) return null; 726 if (node == null) return null;
753 if (node == CURRENT_ELEMENT_SPANNABLE) { 727 if (node == CURRENT_ELEMENT_SPANNABLE) {
754 node = currentElement; 728 node = currentElement;
729 } else if (node == NO_LOCATION_SPANNABLE) {
730 if (currentElement == null) return null;
731 node = currentElement;
755 } 732 }
756 if (node is SourceSpan) { 733 if (node is SourceSpan) {
757 return node; 734 return node;
758 } else if (node is Node) { 735 } else if (node is Node) {
759 return spanFromNode(node); 736 return spanFromNode(node);
760 } else if (node is Token) { 737 } else if (node is Token) {
761 return spanFromTokens(node, node); 738 return spanFromTokens(node, node);
762 } else if (node is HInstruction) { 739 } else if (node is HInstruction) {
763 return spanFromHInstruction(node); 740 return spanFromHInstruction(node);
764 } else if (node is Element) { 741 } else if (node is Element) {
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
861 } else if (foreignLibrary == null 838 } else if (foreignLibrary == null
862 && (uri == new Uri(scheme: 'dart', path: '_foreign_helper'))) { 839 && (uri == new Uri(scheme: 'dart', path: '_foreign_helper'))) {
863 foreignLibrary = library; 840 foreignLibrary = library;
864 } 841 }
865 return backend.onLibraryLoaded(library, uri); 842 return backend.onLibraryLoaded(library, uri);
866 } 843 }
867 844
868 Element findRequiredElement(LibraryElement library, String name) { 845 Element findRequiredElement(LibraryElement library, String name) {
869 var element = library.find(name); 846 var element = library.find(name);
870 if (element == null) { 847 if (element == null) {
871 internalErrorOnElement( 848 internalError(library,
872 library, 849 "The library '${library.canonicalUri}' does not contain required "
873 'The library "${library.canonicalUri}" does not contain required ' 850 "element: '$name'.");
874 'element: $name');
875 } 851 }
876 return element; 852 return element;
877 } 853 }
878 854
879 void onClassResolved(ClassElement cls) { 855 void onClassResolved(ClassElement cls) {
880 if (mirrorSystemClass == cls) { 856 if (mirrorSystemClass == cls) {
881 mirrorSystemGetNameFunction = 857 mirrorSystemGetNameFunction =
882 cls.lookupLocalMember('getName'); 858 cls.lookupLocalMember('getName');
883 } else if (symbolClass == cls) { 859 } else if (symbolClass == cls) {
884 symbolConstructor = cls.constructors.head; 860 symbolConstructor = cls.constructors.head;
(...skipping 29 matching lines...) Expand all
914 intClass = lookupCoreClass('int'); 890 intClass = lookupCoreClass('int');
915 doubleClass = lookupCoreClass('double'); 891 doubleClass = lookupCoreClass('double');
916 stringClass = lookupCoreClass('String'); 892 stringClass = lookupCoreClass('String');
917 functionClass = lookupCoreClass('Function'); 893 functionClass = lookupCoreClass('Function');
918 listClass = lookupCoreClass('List'); 894 listClass = lookupCoreClass('List');
919 typeClass = lookupCoreClass('Type'); 895 typeClass = lookupCoreClass('Type');
920 mapClass = lookupCoreClass('Map'); 896 mapClass = lookupCoreClass('Map');
921 nullClass = lookupCoreClass('Null'); 897 nullClass = lookupCoreClass('Null');
922 stackTraceClass = lookupCoreClass('StackTrace'); 898 stackTraceClass = lookupCoreClass('StackTrace');
923 if (!missingCoreClasses.isEmpty) { 899 if (!missingCoreClasses.isEmpty) {
924 internalErrorOnElement(coreLibrary, 900 internalError(coreLibrary,
925 'dart:core library does not contain required classes: ' 901 'dart:core library does not contain required classes: '
926 '$missingCoreClasses'); 902 '$missingCoreClasses');
927 } 903 }
928 904
929 // The Symbol class may not exist during unit testing. 905 // The Symbol class may not exist during unit testing.
930 // TODO(ahe): It is possible that we have to require the presence 906 // TODO(ahe): It is possible that we have to require the presence
931 // of Symbol as we change how we implement noSuchMethod. 907 // of Symbol as we change how we implement noSuchMethod.
932 symbolClass = lookupCoreClass('Symbol'); 908 symbolClass = lookupCoreClass('Symbol');
933 909
934 final List missingHelperClasses = []; 910 final List missingHelperClasses = [];
935 ClassElement lookupHelperClass(String name) { 911 ClassElement lookupHelperClass(String name) {
936 ClassElement result = jsHelperLibrary.find(name); 912 ClassElement result = jsHelperLibrary.find(name);
937 if (result == null) { 913 if (result == null) {
938 missingHelperClasses.add(name); 914 missingHelperClasses.add(name);
939 } 915 }
940 return result; 916 return result;
941 } 917 }
942 jsInvocationMirrorClass = lookupHelperClass('JSInvocationMirror'); 918 jsInvocationMirrorClass = lookupHelperClass('JSInvocationMirror');
943 boundClosureClass = lookupHelperClass('BoundClosure'); 919 boundClosureClass = lookupHelperClass('BoundClosure');
944 closureClass = lookupHelperClass('Closure'); 920 closureClass = lookupHelperClass('Closure');
945 dynamicClass = lookupHelperClass('Dynamic_'); 921 dynamicClass = lookupHelperClass('Dynamic_');
946 if (!missingHelperClasses.isEmpty) { 922 if (!missingHelperClasses.isEmpty) {
947 internalErrorOnElement(jsHelperLibrary, 923 internalError(jsHelperLibrary,
948 'dart:_js_helper library does not contain required classes: ' 924 'dart:_js_helper library does not contain required classes: '
949 '$missingHelperClasses'); 925 '$missingHelperClasses');
950 } 926 }
951 927
952 if (types == null) { 928 if (types == null) {
953 types = new Types(this, dynamicClass); 929 types = new Types(this, dynamicClass);
954 } 930 }
955 backend.initializeHelperClasses(); 931 backend.initializeHelperClasses();
956 932
957 dynamicClass.ensureResolved(this); 933 dynamicClass.ensureResolved(this);
(...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after
1247 1223
1248 /** 1224 /**
1249 * Perform various checks of the queues. This includes checking that 1225 * Perform various checks of the queues. This includes checking that
1250 * the queues are empty (nothing was added after we stopped 1226 * the queues are empty (nothing was added after we stopped
1251 * processing the queues). Also compute the number of methods that 1227 * processing the queues). Also compute the number of methods that
1252 * were resolved, but not compiled (aka excess resolution). 1228 * were resolved, but not compiled (aka excess resolution).
1253 */ 1229 */
1254 checkQueues() { 1230 checkQueues() {
1255 for (Enqueuer world in [enqueuer.resolution, enqueuer.codegen]) { 1231 for (Enqueuer world in [enqueuer.resolution, enqueuer.codegen]) {
1256 world.forEach((WorkItem work) { 1232 world.forEach((WorkItem work) {
1257 internalErrorOnElement(work.element, "Work list is not empty."); 1233 internalError(work.element, "Work list is not empty.");
1258 }); 1234 });
1259 } 1235 }
1260 if (!REPORT_EXCESS_RESOLUTION) return; 1236 if (!REPORT_EXCESS_RESOLUTION) return;
1261 var resolved = new Set.from(enqueuer.resolution.resolvedElements.keys); 1237 var resolved = new Set.from(enqueuer.resolution.resolvedElements.keys);
1262 for (Element e in enqueuer.codegen.generatedCode.keys) { 1238 for (Element e in enqueuer.codegen.generatedCode.keys) {
1263 resolved.remove(e); 1239 resolved.remove(e);
1264 } 1240 }
1265 for (Element e in new Set.from(resolved)) { 1241 for (Element e in new Set.from(resolved)) {
1266 if (e.isClass() || 1242 if (e.isClass() ||
1267 e.isField() || 1243 e.isField() ||
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
1409 void reportHint(Spannable node, MessageKind messageKind, 1385 void reportHint(Spannable node, MessageKind messageKind,
1410 [Map arguments = const {}]) { 1386 [Map arguments = const {}]) {
1411 reportDiagnosticInternal(node, messageKind, arguments, api.Diagnostic.HINT); 1387 reportDiagnosticInternal(node, messageKind, arguments, api.Diagnostic.HINT);
1412 } 1388 }
1413 1389
1414 /// For debugging only, print a message with a source location. 1390 /// For debugging only, print a message with a source location.
1415 void reportHere(Spannable node, String debugMessage) { 1391 void reportHere(Spannable node, String debugMessage) {
1416 reportInfo(node, MessageKind.GENERIC, {'text': 'HERE: $debugMessage'}); 1392 reportInfo(node, MessageKind.GENERIC, {'text': 'HERE: $debugMessage'});
1417 } 1393 }
1418 1394
1419 void reportInternalError(Spannable node, MessageKind messageKind,
1420 [Map arguments = const {}]) {
1421 reportDiagnosticInternal(
1422 node, messageKind, arguments, api.Diagnostic.CRASH);
1423 }
1424
1425 void reportDiagnosticInternal(Spannable node, 1395 void reportDiagnosticInternal(Spannable node,
1426 MessageKind messageKind, 1396 MessageKind messageKind,
1427 Map arguments, 1397 Map arguments,
1428 api.Diagnostic kind) { 1398 api.Diagnostic kind) {
1429 if (!showPackageWarnings) { 1399 if (!showPackageWarnings) {
1430 switch (kind) { 1400 switch (kind) {
1431 case api.Diagnostic.WARNING: 1401 case api.Diagnostic.WARNING:
1432 case api.Diagnostic.HINT: 1402 case api.Diagnostic.HINT:
1433 Element element = elementFromSpannable(node); 1403 Element element = elementFromSpannable(node);
1434 if (!inUserCode(element)) { 1404 if (!inUserCode(element)) {
(...skipping 22 matching lines...) Expand all
1457 } 1427 }
1458 1428
1459 void reportDiagnostic(Spannable span, 1429 void reportDiagnostic(Spannable span,
1460 Message message, 1430 Message message,
1461 api.Diagnostic kind); 1431 api.Diagnostic kind);
1462 1432
1463 void reportAssertionFailure(SpannableAssertionFailure ex) { 1433 void reportAssertionFailure(SpannableAssertionFailure ex) {
1464 String message = (ex.message != null) ? tryToString(ex.message) 1434 String message = (ex.message != null) ? tryToString(ex.message)
1465 : tryToString(ex); 1435 : tryToString(ex);
1466 SourceSpan span = spanFromSpannable(ex.node); 1436 SourceSpan span = spanFromSpannable(ex.node);
1467 reportInternalError(ex.node, MessageKind.GENERIC, {'text': message}); 1437 reportDiagnosticInternal(
1438 ex.node, MessageKind.GENERIC, {'text': message}, api.Diagnostic.CRASH);
1468 } 1439 }
1469 1440
1470 SourceSpan spanFromTokens(Token begin, Token end, [Uri uri]) { 1441 SourceSpan spanFromTokens(Token begin, Token end, [Uri uri]) {
1471 if (begin == null || end == null) { 1442 if (begin == null || end == null) {
1472 // TODO(ahe): We can almost always do better. Often it is only 1443 // TODO(ahe): We can almost always do better. Often it is only
1473 // end that is null. Otherwise, we probably know the current 1444 // end that is null. Otherwise, we probably know the current
1474 // URI. 1445 // URI.
1475 throw 'Cannot find tokens to produce error message.'; 1446 throw 'Cannot find tokens to produce error message.';
1476 } 1447 }
1477 if (uri == null && currentElement != null) { 1448 if (uri == null && currentElement != null) {
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
1529 * [importingLibrary] is used to grant access to internal libraries from 1500 * [importingLibrary] is used to grant access to internal libraries from
1530 * platform libraries and patch libraries. 1501 * platform libraries and patch libraries.
1531 * 1502 *
1532 * If the [resolvedUri] is not accessible from [importingLibrary], this method 1503 * If the [resolvedUri] is not accessible from [importingLibrary], this method
1533 * is responsible for reporting errors. 1504 * is responsible for reporting errors.
1534 * 1505 *
1535 * See [LibraryLoader] for terminology on URIs. 1506 * See [LibraryLoader] for terminology on URIs.
1536 */ 1507 */
1537 Uri translateResolvedUri(LibraryElement importingLibrary, 1508 Uri translateResolvedUri(LibraryElement importingLibrary,
1538 Uri resolvedUri, Node node) { 1509 Uri resolvedUri, Node node) {
1539 unimplemented('Compiler.translateResolvedUri'); 1510 unimplemented(importingLibrary, 'Compiler.translateResolvedUri');
1540 return null; 1511 return null;
1541 } 1512 }
1542 1513
1543 /** 1514 /**
1544 * Reads the script specified by the [readableUri]. 1515 * Reads the script specified by the [readableUri].
1545 * 1516 *
1546 * See [LibraryLoader] for terminology on URIs. 1517 * See [LibraryLoader] for terminology on URIs.
1547 */ 1518 */
1548 Future<Script> readScript(Uri readableUri, [Element element, Node node]) { 1519 Future<Script> readScript(Spannable node, Uri readableUri) {
1549 unimplemented('Compiler.readScript'); 1520 unimplemented(node, 'Compiler.readScript');
1550 return null; 1521 return null;
1551 } 1522 }
1552 1523
1553 String get legDirectory {
1554 unimplemented('Compiler.legDirectory');
1555 return null;
1556 }
1557
1558 // TODO(karlklose): split into findHelperFunction and findHelperClass and 1524 // TODO(karlklose): split into findHelperFunction and findHelperClass and
1559 // add a check that the element has the expected kind. 1525 // add a check that the element has the expected kind.
1560 Element findHelper(String name) 1526 Element findHelper(String name)
1561 => jsHelperLibrary.findLocal(name); 1527 => jsHelperLibrary.findLocal(name);
1562 Element findInterceptor(String name) 1528 Element findInterceptor(String name)
1563 => interceptorsLibrary.findLocal(name); 1529 => interceptorsLibrary.findLocal(name);
1564 1530
1565 Element lookupElementIn(ScopeContainerElement container, String name) { 1531 Element lookupElementIn(ScopeContainerElement container, String name) {
1566 Element element = container.localLookup(name); 1532 Element element = container.localLookup(name);
1567 if (element == null) { 1533 if (element == null) {
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after
1830 static NullSink outputProvider(String name, String extension) { 1796 static NullSink outputProvider(String name, String extension) {
1831 return new NullSink('$name.$extension'); 1797 return new NullSink('$name.$extension');
1832 } 1798 }
1833 } 1799 }
1834 1800
1835 /// Information about suppressed warnings and hints for a given library. 1801 /// Information about suppressed warnings and hints for a given library.
1836 class SuppressionInfo { 1802 class SuppressionInfo {
1837 int warnings = 0; 1803 int warnings = 0;
1838 int hints = 0; 1804 int hints = 0;
1839 } 1805 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698