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

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

Issue 169763003: Update dart2js diagnostics to prepare for filtering. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Remove optional Uri. Created 6 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) 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 676 matching lines...) Expand 10 before | Expand all | Expand 10 after
687 instruction: instruction, element: element); 687 instruction: instruction, element: element);
688 } 688 }
689 689
690 void internalErrorOnElement(Element element, String message) { 690 void internalErrorOnElement(Element element, String message) {
691 internalError(message, element: element); 691 internalError(message, element: element);
692 } 692 }
693 693
694 void unhandledExceptionOnElement(Element element) { 694 void unhandledExceptionOnElement(Element element) {
695 if (hasCrashed) return; 695 if (hasCrashed) return;
696 hasCrashed = true; 696 hasCrashed = true;
697 reportDiagnostic(spanFromElement(element), 697 reportDiagnostic(element,
698 MessageKind.COMPILER_CRASHED.error().toString(), 698 MessageKind.COMPILER_CRASHED.error(),
699 api.Diagnostic.CRASH); 699 api.Diagnostic.CRASH);
700 pleaseReportCrash(); 700 pleaseReportCrash();
701 } 701 }
702 702
703 void pleaseReportCrash() { 703 void pleaseReportCrash() {
704 print(MessageKind.PLEASE_REPORT_THE_CRASH.message({'buildId': buildId})); 704 print(MessageKind.PLEASE_REPORT_THE_CRASH.message({'buildId': buildId}));
705 } 705 }
706 706
707 void cancel(String reason, {Node node, Token token, 707 void cancel(String reason, {Node node, Token token,
708 HInstruction instruction, Element element}) { 708 HInstruction instruction, Element element}) {
709 assembledCode = null; // Compilation failed. Make sure that we 709 assembledCode = null; // Compilation failed. Make sure that we
710 // don't return a bogus result. 710 // don't return a bogus result.
711 Spannable spannable = null; 711 Spannable spannable = null;
712 if (node != null) { 712 if (node != null) {
713 spannable = node; 713 spannable = node;
714 } else if (token != null) { 714 } else if (token != null) {
715 spannable = token; 715 spannable = token;
716 } else if (instruction != null) { 716 } else if (instruction != null) {
717 spannable = instruction; 717 spannable = instruction;
718 } else if (element != null) { 718 } else if (element != null) {
719 spannable = element; 719 spannable = element;
720 } else { 720 } else {
721 throw 'No error location for error: $reason'; 721 throw 'No error location for error: $reason';
722 } 722 }
723 reportError(spannable, MessageKind.GENERIC, {'text': reason}); 723 reportError(spannable, MessageKind.GENERIC, {'text': reason});
724 throw new CompilerCancelledException(reason); 724 throw new CompilerCancelledException(reason);
725 } 725 }
726 726
727 SourceSpan spanFromSpannable(Spannable node, [Uri uri]) { 727 SourceSpan spanFromSpannable(Spannable node) {
728 if (node == null) return null; 728 if (node == null) return null;
729 if (node == CURRENT_ELEMENT_SPANNABLE) { 729 if (node == CURRENT_ELEMENT_SPANNABLE) {
730 node = currentElement; 730 node = currentElement;
731 } 731 }
732 if (node is SourceSpan) { 732 if (node is SourceSpan) {
733 return node; 733 return node;
734 } else if (node is Node) { 734 } else if (node is Node) {
735 return spanFromNode(node, uri); 735 return spanFromNode(node);
736 } else if (node is Token) { 736 } else if (node is Token) {
737 return spanFromTokens(node, node, uri); 737 return spanFromTokens(node, node);
738 } else if (node is HInstruction) { 738 } else if (node is HInstruction) {
739 return spanFromHInstruction(node); 739 return spanFromHInstruction(node);
740 } else if (node is Element) { 740 } else if (node is Element) {
741 return spanFromElement(node); 741 return spanFromElement(node);
742 } else if (node is MetadataAnnotation) { 742 } else if (node is MetadataAnnotation) {
743 MetadataAnnotation annotation = node; 743 MetadataAnnotation annotation = node;
744 uri = annotation.annotatedElement.getCompilationUnit().script.uri; 744 Uri uri = annotation.annotatedElement.getCompilationUnit().script.uri;
745 return spanFromTokens(annotation.beginToken, annotation.endToken, uri); 745 return spanFromTokens(annotation.beginToken, annotation.endToken, uri);
746 } else { 746 } else {
747 throw 'No error location.'; 747 throw 'No error location.';
748 } 748 }
749 } 749 }
750 750
751 void log(message) { 751 void log(message) {
752 reportDiagnostic(null, message, api.Diagnostic.VERBOSE_INFO); 752 reportDiagnostic(null,
753 MessageKind.GENERIC.error({'text': '$message'}),
754 api.Diagnostic.VERBOSE_INFO);
753 } 755 }
754 756
755 Future<bool> run(Uri uri) { 757 Future<bool> run(Uri uri) {
756 totalCompileTime.start(); 758 totalCompileTime.start();
757 759
758 return new Future.sync(() => runCompiler(uri)).catchError((error) { 760 return new Future.sync(() => runCompiler(uri)).catchError((error) {
759 if (error is CompilerCancelledException) { 761 if (error is CompilerCancelledException) {
760 log('Error: $error'); 762 log('Error: $error');
761 return false; 763 return false;
762 } 764 }
763 765
764 try { 766 try {
765 if (!hasCrashed) { 767 if (!hasCrashed) {
766 hasCrashed = true; 768 hasCrashed = true;
767 reportDiagnostic(new SourceSpan(uri, 0, 0), 769 reportDiagnostic(new SourceSpan(uri, 0, 0),
768 MessageKind.COMPILER_CRASHED.error().toString(), 770 MessageKind.COMPILER_CRASHED.error(),
769 api.Diagnostic.CRASH); 771 api.Diagnostic.CRASH);
770 pleaseReportCrash(); 772 pleaseReportCrash();
771 } 773 }
772 } catch (doubleFault) { 774 } catch (doubleFault) {
773 // Ignoring exceptions in exception handling. 775 // Ignoring exceptions in exception handling.
774 } 776 }
775 throw error; 777 throw error;
776 }).whenComplete(() { 778 }).whenComplete(() {
777 tracer.close(); 779 tracer.close();
778 totalCompileTime.stop(); 780 totalCompileTime.stop();
(...skipping 445 matching lines...) Expand 10 before | Expand all | Expand 10 after
1224 } 1226 }
1225 if (identical(e.getLibrary(), jsHelperLibrary)) { 1227 if (identical(e.getLibrary(), jsHelperLibrary)) {
1226 resolved.remove(e); 1228 resolved.remove(e);
1227 } 1229 }
1228 if (identical(e.getLibrary(), interceptorsLibrary)) { 1230 if (identical(e.getLibrary(), interceptorsLibrary)) {
1229 resolved.remove(e); 1231 resolved.remove(e);
1230 } 1232 }
1231 } 1233 }
1232 log('Excess resolution work: ${resolved.length}.'); 1234 log('Excess resolution work: ${resolved.length}.');
1233 for (Element e in resolved) { 1235 for (Element e in resolved) {
1234 SourceSpan span = spanFromElement(e); 1236 reportWarning(e,
1235 reportDiagnostic(span, 'Warning: $e resolved but not compiled.', 1237 MessageKind.GENERIC,
1236 api.Diagnostic.WARNING); 1238 {'text': 'Warning: $e resolved but not compiled.'});
1237 } 1239 }
1238 } 1240 }
1239 1241
1240 TreeElements analyzeElement(Element element) { 1242 TreeElements analyzeElement(Element element) {
1241 assert(invariant(element, 1243 assert(invariant(element,
1242 element.impliesType() || 1244 element.impliesType() ||
1243 element.isField() || 1245 element.isField() ||
1244 element.isFunction() || 1246 element.isFunction() ||
1245 element.isGenerativeConstructor() || 1247 element.isGenerativeConstructor() ||
1246 element.isGetter() || 1248 element.isGetter() ||
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
1314 withCurrentElement(element, 1316 withCurrentElement(element,
1315 () => resolver.resolve(element)); 1317 () => resolver.resolve(element));
1316 } 1318 }
1317 1319
1318 FunctionType computeFunctionType(Element element, 1320 FunctionType computeFunctionType(Element element,
1319 FunctionSignature signature) { 1321 FunctionSignature signature) {
1320 return withCurrentElement(element, 1322 return withCurrentElement(element,
1321 () => resolver.computeFunctionType(element, signature)); 1323 () => resolver.computeFunctionType(element, signature));
1322 } 1324 }
1323 1325
1324 reportWarning(Spannable node, var message) {
1325 if (message is TypeWarning) {
1326 // TODO(ahe): Don't supress these warning when the type checker
1327 // is more complete.
1328 if (message.message.kind == MessageKind.MISSING_RETURN) return;
1329 if (message.message.kind == MessageKind.MAYBE_MISSING_RETURN) return;
1330 }
1331 SourceSpan span = spanFromSpannable(node);
1332 reportDiagnostic(span, '$message', api.Diagnostic.WARNING);
1333 }
1334
1335 void reportError(Spannable node, 1326 void reportError(Spannable node,
1336 MessageKind errorCode, 1327 MessageKind errorCode,
1337 [Map arguments = const {}]) { 1328 [Map arguments = const {}]) {
1338 reportMessage(spanFromSpannable(node), 1329 reportDiagnostic(node,
1339 errorCode.error(arguments, terseDiagnostics), 1330 errorCode.error(arguments, terseDiagnostics),
1340 api.Diagnostic.ERROR); 1331 api.Diagnostic.ERROR);
1341 } 1332 }
1342 1333
1343 void reportFatalError(Spannable node, MessageKind errorCode, 1334 void reportFatalError(Spannable node, MessageKind errorCode,
1344 [Map arguments = const {}]) { 1335 [Map arguments = const {}]) {
1345 reportError(node, errorCode, arguments); 1336 reportError(node, errorCode, arguments);
1346 // TODO(ahe): Make this only abort the current method. 1337 // TODO(ahe): Make this only abort the current method.
1347 throw new CompilerCancelledException( 1338 throw new CompilerCancelledException(
1348 'Error: Cannot continue due to previous error.'); 1339 'Error: Cannot continue due to previous error.');
1349 } 1340 }
1350 1341
1351 // TODO(ahe): Rename to reportWarning when that method has been removed. 1342 void reportWarning(Spannable node, MessageKind errorCode,
1352 void reportWarningCode(Spannable node, MessageKind errorCode, 1343 [Map arguments = const {}]) {
1353 [Map arguments = const {}]) { 1344 // TODO(ahe): Don't suppress these warning when the type checker
1354 reportMessage(spanFromSpannable(node), 1345 // is more complete.
1346 if (errorCode == MessageKind.MISSING_RETURN) return;
1347 if (errorCode == MessageKind.MAYBE_MISSING_RETURN) return;
1348 reportDiagnostic(node,
1355 errorCode.error(arguments, terseDiagnostics), 1349 errorCode.error(arguments, terseDiagnostics),
1356 api.Diagnostic.WARNING); 1350 api.Diagnostic.WARNING);
1357 } 1351 }
1358 1352
1359 void reportInfo(Spannable node, MessageKind errorCode, 1353 void reportInfo(Spannable node, MessageKind errorCode,
1360 [Map arguments = const {}]) { 1354 [Map arguments = const {}]) {
1361 reportMessage(spanFromSpannable(node), 1355 reportDiagnostic(node,
1362 errorCode.error(arguments, terseDiagnostics), 1356 errorCode.error(arguments, terseDiagnostics),
1363 api.Diagnostic.INFO); 1357 api.Diagnostic.INFO);
1364 } 1358 }
1365 1359
1366 void reportHint(Spannable node, MessageKind errorCode, 1360 void reportHint(Spannable node, MessageKind errorCode,
1367 [Map arguments = const {}]) { 1361 [Map arguments = const {}]) {
1368 reportMessage(spanFromSpannable(node), 1362 reportDiagnostic(node,
1369 errorCode.error(arguments, terseDiagnostics), 1363 errorCode.error(arguments, terseDiagnostics),
1370 api.Diagnostic.HINT); 1364 api.Diagnostic.HINT);
1371 } 1365 }
1372 1366
1373 /// For debugging only, print a message with a source location. 1367 /// For debugging only, print a message with a source location.
1374 void reportHere(Spannable node, String debugMessage) { 1368 void reportHere(Spannable node, String debugMessage) {
1375 reportInfo(node, MessageKind.GENERIC, {'text': 'HERE: $debugMessage'}); 1369 reportInfo(node, MessageKind.GENERIC, {'text': 'HERE: $debugMessage'});
1376 } 1370 }
1377 1371
1378 void reportInternalError(Spannable node, String message) { 1372 void reportInternalError(Spannable node, String message) {
1379 reportError( 1373 reportError(
1380 node, MessageKind.GENERIC, {'text': 'Internal Error: $message'}); 1374 node, MessageKind.GENERIC, {'text': 'Internal Error: $message'});
1381 } 1375 }
1382 1376
1383 void reportMessage(SourceSpan span, Diagnostic message, api.Diagnostic kind) { 1377 // TODO(ahe): The names Diagnostic and api.Diagnostic are in conflict. Fix it.
1384 // TODO(ahe): The names Diagnostic and api.Diagnostic are in 1378 void reportDiagnostic(Spannable span,
1385 // conflict. Fix it. 1379 Diagnostic message,
1386 reportDiagnostic(span, "$message", kind); 1380 api.Diagnostic kind);
1387 }
1388
1389 void reportDiagnostic(SourceSpan span, String message, api.Diagnostic kind);
1390 1381
1391 void reportAssertionFailure(SpannableAssertionFailure ex) { 1382 void reportAssertionFailure(SpannableAssertionFailure ex) {
1392 String message = (ex.message != null) ? tryToString(ex.message) 1383 String message = (ex.message != null) ? tryToString(ex.message)
1393 : tryToString(ex); 1384 : tryToString(ex);
1394 SourceSpan span = spanFromSpannable(ex.node); 1385 SourceSpan span = spanFromSpannable(ex.node);
1395 reportError(ex.node, MessageKind.GENERIC, {'text': message}); 1386 reportError(ex.node, MessageKind.GENERIC, {'text': message});
1396 } 1387 }
1397 1388
1398 SourceSpan spanFromTokens(Token begin, Token end, [Uri uri]) { 1389 SourceSpan spanFromTokens(Token begin, Token end, [Uri uri]) {
1399 if (begin == null || end == null) { 1390 if (begin == null || end == null) {
1400 // TODO(ahe): We can almost always do better. Often it is only 1391 // TODO(ahe): We can almost always do better. Often it is only
1401 // end that is null. Otherwise, we probably know the current 1392 // end that is null. Otherwise, we probably know the current
1402 // URI. 1393 // URI.
1403 throw 'Cannot find tokens to produce error message.'; 1394 throw 'Cannot find tokens to produce error message.';
1404 } 1395 }
1405 if (uri == null && currentElement != null) { 1396 if (uri == null && currentElement != null) {
1406 uri = currentElement.getCompilationUnit().script.uri; 1397 uri = currentElement.getCompilationUnit().script.uri;
1407 } 1398 }
1408 return SourceSpan.withCharacterOffsets(begin, end, 1399 return SourceSpan.withCharacterOffsets(begin, end,
1409 (beginOffset, endOffset) => new SourceSpan(uri, beginOffset, endOffset)); 1400 (beginOffset, endOffset) => new SourceSpan(uri, beginOffset, endOffset));
1410 } 1401 }
1411 1402
1412 SourceSpan spanFromNode(Node node, [Uri uri]) { 1403 SourceSpan spanFromNode(Node node) {
1413 return spanFromTokens(node.getBeginToken(), node.getEndToken(), uri); 1404 return spanFromTokens(node.getBeginToken(), node.getEndToken());
1414 } 1405 }
1415 1406
1416 SourceSpan spanFromElement(Element element) { 1407 SourceSpan spanFromElement(Element element) {
1417 if (Elements.isErroneousElement(element)) { 1408 if (Elements.isErroneousElement(element)) {
1418 element = element.enclosingElement; 1409 element = element.enclosingElement;
1419 } 1410 }
1420 if (element.position() == null && 1411 if (element.position() == null &&
1421 !element.isLibrary() && 1412 !element.isLibrary() &&
1422 !element.isCompilationUnit()) { 1413 !element.isCompilationUnit()) {
1423 // Sometimes, the backend fakes up elements that have no 1414 // Sometimes, the backend fakes up elements that have no
(...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after
1731 1722
1732 void close() {} 1723 void close() {}
1733 1724
1734 toString() => name; 1725 toString() => name;
1735 1726
1736 /// Convenience method for getting an [api.CompilerOutputProvider]. 1727 /// Convenience method for getting an [api.CompilerOutputProvider].
1737 static NullSink outputProvider(String name, String extension) { 1728 static NullSink outputProvider(String name, String extension) {
1738 return new NullSink('$name.$extension'); 1729 return new NullSink('$name.$extension');
1739 } 1730 }
1740 } 1731 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698