| 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 library dart2js.compiler_base; | 5 library dart2js.compiler_base; |
| 6 | 6 |
| 7 import 'dart:async' show | 7 import 'dart:async' show |
| 8 EventSink, | 8 EventSink, |
| 9 Future; | 9 Future; |
| 10 | 10 |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 131 import 'universe/selector.dart' show | 131 import 'universe/selector.dart' show |
| 132 Selector; | 132 Selector; |
| 133 import 'universe/universe.dart' show | 133 import 'universe/universe.dart' show |
| 134 Universe; | 134 Universe; |
| 135 import 'util/util.dart' show | 135 import 'util/util.dart' show |
| 136 Link, | 136 Link, |
| 137 Setlet; | 137 Setlet; |
| 138 import 'world.dart' show | 138 import 'world.dart' show |
| 139 World; | 139 World; |
| 140 | 140 |
| 141 abstract class Compiler implements DiagnosticListener { | 141 abstract class Compiler extends DiagnosticListener { |
| 142 | 142 |
| 143 final Stopwatch totalCompileTime = new Stopwatch(); | 143 final Stopwatch totalCompileTime = new Stopwatch(); |
| 144 int nextFreeClassId = 0; | 144 int nextFreeClassId = 0; |
| 145 World world; | 145 World world; |
| 146 Types types; | 146 Types types; |
| 147 _CompilerCoreTypes _coreTypes; | 147 _CompilerCoreTypes _coreTypes; |
| 148 | 148 |
| 149 final CacheStrategy cacheStrategy; | 149 final CacheStrategy cacheStrategy; |
| 150 | 150 |
| 151 /** | 151 /** |
| (...skipping 457 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 609 bool get disableTypeInference { | 609 bool get disableTypeInference { |
| 610 return disableTypeInferenceFlag || compilationFailed; | 610 return disableTypeInferenceFlag || compilationFailed; |
| 611 } | 611 } |
| 612 | 612 |
| 613 int getNextFreeClassId() => nextFreeClassId++; | 613 int getNextFreeClassId() => nextFreeClassId++; |
| 614 | 614 |
| 615 void unimplemented(Spannable spannable, String methodName) { | 615 void unimplemented(Spannable spannable, String methodName) { |
| 616 internalError(spannable, "$methodName not implemented."); | 616 internalError(spannable, "$methodName not implemented."); |
| 617 } | 617 } |
| 618 | 618 |
| 619 void internalError(Spannable node, reason) { | 619 internalError(Spannable node, reason) { |
| 620 String message = tryToString(reason); | 620 String message = tryToString(reason); |
| 621 reportDiagnosticInternal( | 621 reportDiagnosticInternal( |
| 622 node, MessageKind.GENERIC, {'text': message}, api.Diagnostic.CRASH); | 622 createMessage(node, MessageKind.GENERIC, {'text': message}), |
| 623 const <DiagnosticMessage>[], |
| 624 api.Diagnostic.CRASH); |
| 623 throw 'Internal Error: $message'; | 625 throw 'Internal Error: $message'; |
| 624 } | 626 } |
| 625 | 627 |
| 626 void unhandledExceptionOnElement(Element element) { | 628 void unhandledExceptionOnElement(Element element) { |
| 627 if (hasCrashed) return; | 629 if (hasCrashed) return; |
| 628 hasCrashed = true; | 630 hasCrashed = true; |
| 629 reportDiagnostic( | 631 reportDiagnostic( |
| 630 element, | 632 createMessage(element, MessageKind.COMPILER_CRASHED), |
| 631 MessageTemplate.TEMPLATES[MessageKind.COMPILER_CRASHED].message(), | 633 const <DiagnosticMessage>[], |
| 632 api.Diagnostic.CRASH); | 634 api.Diagnostic.CRASH); |
| 633 pleaseReportCrash(); | 635 pleaseReportCrash(); |
| 634 } | 636 } |
| 635 | 637 |
| 636 void pleaseReportCrash() { | 638 void pleaseReportCrash() { |
| 637 print( | 639 print( |
| 638 MessageTemplate.TEMPLATES[MessageKind.PLEASE_REPORT_THE_CRASH] | 640 MessageTemplate.TEMPLATES[MessageKind.PLEASE_REPORT_THE_CRASH] |
| 639 .message({'buildId': buildId})); | 641 .message({'buildId': buildId})); |
| 640 } | 642 } |
| 641 | 643 |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 684 element = node; | 686 element = node; |
| 685 } else if (node is HInstruction) { | 687 } else if (node is HInstruction) { |
| 686 element = _elementFromHInstruction(node); | 688 element = _elementFromHInstruction(node); |
| 687 } else if (node is MetadataAnnotation) { | 689 } else if (node is MetadataAnnotation) { |
| 688 element = node.annotatedElement; | 690 element = node.annotatedElement; |
| 689 } | 691 } |
| 690 return element != null ? element : currentElement; | 692 return element != null ? element : currentElement; |
| 691 } | 693 } |
| 692 | 694 |
| 693 void log(message) { | 695 void log(message) { |
| 694 reportDiagnostic(null, | 696 Message msg = MessageTemplate.TEMPLATES[MessageKind.GENERIC] |
| 695 MessageTemplate.TEMPLATES[MessageKind.GENERIC] | 697 .message({'text': '$message'}); |
| 696 .message({'text': '$message'}), | 698 reportDiagnostic( |
| 699 new DiagnosticMessage(null, null, msg), |
| 700 const <DiagnosticMessage>[], |
| 697 api.Diagnostic.VERBOSE_INFO); | 701 api.Diagnostic.VERBOSE_INFO); |
| 698 } | 702 } |
| 699 | 703 |
| 700 Future<bool> run(Uri uri) { | 704 Future<bool> run(Uri uri) { |
| 701 totalCompileTime.start(); | 705 totalCompileTime.start(); |
| 702 | 706 |
| 703 return new Future.sync(() => runCompiler(uri)).catchError((error) { | 707 return new Future.sync(() => runCompiler(uri)).catchError((error) { |
| 704 try { | 708 try { |
| 705 if (!hasCrashed) { | 709 if (!hasCrashed) { |
| 706 hasCrashed = true; | 710 hasCrashed = true; |
| 707 if (error is SpannableAssertionFailure) { | 711 if (error is SpannableAssertionFailure) { |
| 708 reportAssertionFailure(error); | 712 reportAssertionFailure(error); |
| 709 } else { | 713 } else { |
| 710 reportDiagnostic( | 714 reportDiagnostic( |
| 711 new SourceSpan(uri, 0, 0), | 715 createMessage( |
| 712 MessageTemplate.TEMPLATES[MessageKind.COMPILER_CRASHED] | 716 new SourceSpan(uri, 0, 0), |
| 713 .message(), | 717 MessageKind.COMPILER_CRASHED), |
| 718 const <DiagnosticMessage>[], |
| 714 api.Diagnostic.CRASH); | 719 api.Diagnostic.CRASH); |
| 715 } | 720 } |
| 716 pleaseReportCrash(); | 721 pleaseReportCrash(); |
| 717 } | 722 } |
| 718 } catch (doubleFault) { | 723 } catch (doubleFault) { |
| 719 // Ignoring exceptions in exception handling. | 724 // Ignoring exceptions in exception handling. |
| 720 } | 725 } |
| 721 throw error; | 726 throw error; |
| 722 }).whenComplete(() { | 727 }).whenComplete(() { |
| 723 tracer.close(); | 728 tracer.close(); |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 868 | 873 |
| 869 if (!loadedLibraries.containsLibrary(Uris.dart_core)) { | 874 if (!loadedLibraries.containsLibrary(Uris.dart_core)) { |
| 870 return null; | 875 return null; |
| 871 } | 876 } |
| 872 | 877 |
| 873 if (!enableExperimentalMirrors && | 878 if (!enableExperimentalMirrors && |
| 874 loadedLibraries.containsLibrary(Uris.dart_mirrors)) { | 879 loadedLibraries.containsLibrary(Uris.dart_mirrors)) { |
| 875 Set<String> importChains = | 880 Set<String> importChains = |
| 876 computeImportChainsFor(loadedLibraries, Uris.dart_mirrors); | 881 computeImportChainsFor(loadedLibraries, Uris.dart_mirrors); |
| 877 if (!backend.supportsReflection) { | 882 if (!backend.supportsReflection) { |
| 878 reportError(NO_LOCATION_SPANNABLE, | 883 reportErrorMessage( |
| 879 MessageKind.MIRRORS_LIBRARY_NOT_SUPPORT_BY_BACKEND); | 884 NO_LOCATION_SPANNABLE, |
| 885 MessageKind.MIRRORS_LIBRARY_NOT_SUPPORT_BY_BACKEND); |
| 880 } else { | 886 } else { |
| 881 reportWarning(NO_LOCATION_SPANNABLE, | 887 reportWarningMessage( |
| 882 MessageKind.IMPORT_EXPERIMENTAL_MIRRORS, | 888 NO_LOCATION_SPANNABLE, |
| 889 MessageKind.IMPORT_EXPERIMENTAL_MIRRORS, |
| 883 {'importChain': importChains.join( | 890 {'importChain': importChains.join( |
| 884 MessageTemplate.IMPORT_EXPERIMENTAL_MIRRORS_PADDING)}); | 891 MessageTemplate.IMPORT_EXPERIMENTAL_MIRRORS_PADDING)}); |
| 885 } | 892 } |
| 886 } | 893 } |
| 887 | 894 |
| 888 functionClass.ensureResolved(this); | 895 functionClass.ensureResolved(this); |
| 889 functionApplyMethod = functionClass.lookupLocalMember('apply'); | 896 functionApplyMethod = functionClass.lookupLocalMember('apply'); |
| 890 | 897 |
| 891 if (preserveComments) { | 898 if (preserveComments) { |
| 892 return libraryLoader.loadLibrary(Uris.dart_mirrors) | 899 return libraryLoader.loadLibrary(Uris.dart_mirrors) |
| (...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1079 if (mainFunction == null) { | 1086 if (mainFunction == null) { |
| 1080 if (errorElement == null && !analyzeOnly && !analyzeAll) { | 1087 if (errorElement == null && !analyzeOnly && !analyzeAll) { |
| 1081 internalError(mainApp, "Problem with '${Identifiers.main}'."); | 1088 internalError(mainApp, "Problem with '${Identifiers.main}'."); |
| 1082 } else { | 1089 } else { |
| 1083 mainFunction = errorElement; | 1090 mainFunction = errorElement; |
| 1084 } | 1091 } |
| 1085 } | 1092 } |
| 1086 if (errorElement != null && | 1093 if (errorElement != null && |
| 1087 errorElement.isSynthesized && | 1094 errorElement.isSynthesized && |
| 1088 !mainApp.isSynthesized) { | 1095 !mainApp.isSynthesized) { |
| 1089 reportWarning( | 1096 reportWarningMessage( |
| 1090 errorElement, errorElement.messageKind, | 1097 errorElement, errorElement.messageKind, |
| 1091 errorElement.messageArguments); | 1098 errorElement.messageArguments); |
| 1092 } | 1099 } |
| 1093 } | 1100 } |
| 1094 | 1101 |
| 1095 /// Analyze all member of the library in [libraryUri]. | 1102 /// Analyze all member of the library in [libraryUri]. |
| 1096 /// | 1103 /// |
| 1097 /// If [skipLibraryWithPartOfTag] is `true`, member analysis is skipped if the | 1104 /// If [skipLibraryWithPartOfTag] is `true`, member analysis is skipped if the |
| 1098 /// library has a `part of` tag, assuming it is a part and not a library. | 1105 /// library has a `part of` tag, assuming it is a part and not a library. |
| 1099 /// | 1106 /// |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1147 | 1154 |
| 1148 if (!showPackageWarnings && !suppressWarnings) { | 1155 if (!showPackageWarnings && !suppressWarnings) { |
| 1149 suppressedWarnings.forEach((Uri uri, SuppressionInfo info) { | 1156 suppressedWarnings.forEach((Uri uri, SuppressionInfo info) { |
| 1150 MessageKind kind = MessageKind.HIDDEN_WARNINGS_HINTS; | 1157 MessageKind kind = MessageKind.HIDDEN_WARNINGS_HINTS; |
| 1151 if (info.warnings == 0) { | 1158 if (info.warnings == 0) { |
| 1152 kind = MessageKind.HIDDEN_HINTS; | 1159 kind = MessageKind.HIDDEN_HINTS; |
| 1153 } else if (info.hints == 0) { | 1160 } else if (info.hints == 0) { |
| 1154 kind = MessageKind.HIDDEN_WARNINGS; | 1161 kind = MessageKind.HIDDEN_WARNINGS; |
| 1155 } | 1162 } |
| 1156 MessageTemplate template = MessageTemplate.TEMPLATES[kind]; | 1163 MessageTemplate template = MessageTemplate.TEMPLATES[kind]; |
| 1157 reportDiagnostic(null, | 1164 Message message = template.message( |
| 1158 template.message( | 1165 {'warnings': info.warnings, |
| 1159 {'warnings': info.warnings, | 1166 'hints': info.hints, |
| 1160 'hints': info.hints, | 1167 'uri': uri}, |
| 1161 'uri': uri}, | 1168 terseDiagnostics); |
| 1162 terseDiagnostics), | 1169 reportDiagnostic( |
| 1170 new DiagnosticMessage(null, null, message), |
| 1171 const <DiagnosticMessage>[], |
| 1163 api.Diagnostic.HINT); | 1172 api.Diagnostic.HINT); |
| 1164 }); | 1173 }); |
| 1165 } | 1174 } |
| 1166 | 1175 |
| 1167 if (compilationFailed){ | 1176 if (compilationFailed){ |
| 1168 if (!generateCodeWithCompileTimeErrors) return; | 1177 if (!generateCodeWithCompileTimeErrors) return; |
| 1169 if (!backend.enableCodegenWithErrorsIfSupported(NO_LOCATION_SPANNABLE)) { | 1178 if (!backend.enableCodegenWithErrorsIfSupported(NO_LOCATION_SPANNABLE)) { |
| 1170 return; | 1179 return; |
| 1171 } | 1180 } |
| 1172 } | 1181 } |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1319 } | 1328 } |
| 1320 if (identical(e.kind, ElementKind.GENERATIVE_CONSTRUCTOR)) { | 1329 if (identical(e.kind, ElementKind.GENERATIVE_CONSTRUCTOR)) { |
| 1321 resolved.remove(e); | 1330 resolved.remove(e); |
| 1322 } | 1331 } |
| 1323 if (backend.isBackendLibrary(e.library)) { | 1332 if (backend.isBackendLibrary(e.library)) { |
| 1324 resolved.remove(e); | 1333 resolved.remove(e); |
| 1325 } | 1334 } |
| 1326 } | 1335 } |
| 1327 log('Excess resolution work: ${resolved.length}.'); | 1336 log('Excess resolution work: ${resolved.length}.'); |
| 1328 for (Element e in resolved) { | 1337 for (Element e in resolved) { |
| 1329 reportWarning(e, | 1338 reportWarningMessage(e, |
| 1330 MessageKind.GENERIC, | 1339 MessageKind.GENERIC, |
| 1331 {'text': 'Warning: $e resolved but not compiled.'}); | 1340 {'text': 'Warning: $e resolved but not compiled.'}); |
| 1332 } | 1341 } |
| 1333 } | 1342 } |
| 1334 | 1343 |
| 1335 WorldImpact analyzeElement(Element element) { | 1344 WorldImpact analyzeElement(Element element) { |
| 1336 assert(invariant(element, | 1345 assert(invariant(element, |
| 1337 element.impliesType || | 1346 element.impliesType || |
| 1338 element.isField || | 1347 element.isField || |
| 1339 element.isFunction || | 1348 element.isFunction || |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1386 assert(invariant(work.element, identical(world, enqueuer.codegen))); | 1395 assert(invariant(work.element, identical(world, enqueuer.codegen))); |
| 1387 if (shouldPrintProgress) { | 1396 if (shouldPrintProgress) { |
| 1388 // TODO(ahe): Add structured diagnostics to the compiler API and | 1397 // TODO(ahe): Add structured diagnostics to the compiler API and |
| 1389 // use it to separate this from the --verbose option. | 1398 // use it to separate this from the --verbose option. |
| 1390 log('Compiled ${enqueuer.codegen.generatedCode.length} methods.'); | 1399 log('Compiled ${enqueuer.codegen.generatedCode.length} methods.'); |
| 1391 progress.reset(); | 1400 progress.reset(); |
| 1392 } | 1401 } |
| 1393 return backend.codegen(work); | 1402 return backend.codegen(work); |
| 1394 } | 1403 } |
| 1395 | 1404 |
| 1396 void reportError(Spannable node, | 1405 DiagnosticMessage createMessage( |
| 1397 MessageKind messageKind, | 1406 Spannable spannable, |
| 1398 [Map arguments = const {}]) { | 1407 MessageKind messageKind, |
| 1399 reportDiagnosticInternal( | 1408 [Map arguments = const {}]) { |
| 1400 node, messageKind, arguments, api.Diagnostic.ERROR); | 1409 SourceSpan span = spanFromSpannable(spannable); |
| 1410 MessageTemplate template = MessageTemplate.TEMPLATES[messageKind]; |
| 1411 Message message = template.message(arguments, terseDiagnostics); |
| 1412 return new DiagnosticMessage(span, spannable, message); |
| 1401 } | 1413 } |
| 1402 | 1414 |
| 1403 void reportWarning(Spannable node, MessageKind messageKind, | 1415 void reportError( |
| 1404 [Map arguments = const {}]) { | 1416 DiagnosticMessage message, |
| 1405 reportDiagnosticInternal( | 1417 [List<DiagnosticMessage> infos = const <DiagnosticMessage>[]]) { |
| 1406 node, messageKind, arguments, api.Diagnostic.WARNING); | 1418 reportDiagnosticInternal(message, infos, api.Diagnostic.ERROR); |
| 1407 } | 1419 } |
| 1408 | 1420 |
| 1421 void reportWarning( |
| 1422 DiagnosticMessage message, |
| 1423 [List<DiagnosticMessage> infos = const <DiagnosticMessage>[]]) { |
| 1424 reportDiagnosticInternal(message, infos, api.Diagnostic.WARNING); |
| 1425 } |
| 1426 |
| 1427 void reportHint( |
| 1428 DiagnosticMessage message, |
| 1429 [List<DiagnosticMessage> infos = const <DiagnosticMessage>[]]) { |
| 1430 reportDiagnosticInternal(message, infos, api.Diagnostic.HINT); |
| 1431 } |
| 1432 |
| 1433 @deprecated |
| 1409 void reportInfo(Spannable node, MessageKind messageKind, | 1434 void reportInfo(Spannable node, MessageKind messageKind, |
| 1410 [Map arguments = const {}]) { | 1435 [Map arguments = const {}]) { |
| 1411 reportDiagnosticInternal(node, messageKind, arguments, api.Diagnostic.INFO); | 1436 reportDiagnosticInternal( |
| 1437 createMessage(node, messageKind, arguments), |
| 1438 const <DiagnosticMessage>[], |
| 1439 api.Diagnostic.INFO); |
| 1412 } | 1440 } |
| 1413 | 1441 |
| 1414 void reportHint(Spannable node, MessageKind messageKind, | 1442 void reportDiagnosticInternal(DiagnosticMessage message, |
| 1415 [Map arguments = const {}]) { | 1443 List<DiagnosticMessage> infos, |
| 1416 reportDiagnosticInternal(node, messageKind, arguments, api.Diagnostic.HINT); | |
| 1417 } | |
| 1418 | |
| 1419 void reportDiagnosticInternal(Spannable node, | |
| 1420 MessageKind messageKind, | |
| 1421 Map arguments, | |
| 1422 api.Diagnostic kind) { | 1444 api.Diagnostic kind) { |
| 1423 if (!showPackageWarnings && node != NO_LOCATION_SPANNABLE) { | 1445 if (!showPackageWarnings && message.spannable != NO_LOCATION_SPANNABLE) { |
| 1424 switch (kind) { | 1446 switch (kind) { |
| 1425 case api.Diagnostic.WARNING: | 1447 case api.Diagnostic.WARNING: |
| 1426 case api.Diagnostic.HINT: | 1448 case api.Diagnostic.HINT: |
| 1427 Element element = elementFromSpannable(node); | 1449 Element element = elementFromSpannable(message.spannable); |
| 1428 if (!inUserCode(element, assumeInUserCode: true)) { | 1450 if (!inUserCode(element, assumeInUserCode: true)) { |
| 1429 Uri uri = getCanonicalUri(element); | 1451 Uri uri = getCanonicalUri(element); |
| 1430 SuppressionInfo info = | 1452 SuppressionInfo info = |
| 1431 suppressedWarnings.putIfAbsent(uri, () => new SuppressionInfo()); | 1453 suppressedWarnings.putIfAbsent(uri, () => new SuppressionInfo()); |
| 1432 if (kind == api.Diagnostic.WARNING) { | 1454 if (kind == api.Diagnostic.WARNING) { |
| 1433 info.warnings++; | 1455 info.warnings++; |
| 1434 } else { | 1456 } else { |
| 1435 info.hints++; | 1457 info.hints++; |
| 1436 } | 1458 } |
| 1437 lastDiagnosticWasFiltered = true; | 1459 lastDiagnosticWasFiltered = true; |
| 1438 return; | 1460 return; |
| 1439 } | 1461 } |
| 1440 break; | 1462 break; |
| 1441 case api.Diagnostic.INFO: | 1463 case api.Diagnostic.INFO: |
| 1442 if (lastDiagnosticWasFiltered) { | 1464 if (lastDiagnosticWasFiltered) { |
| 1443 return; | 1465 return; |
| 1444 } | 1466 } |
| 1445 break; | 1467 break; |
| 1446 } | 1468 } |
| 1447 } | 1469 } |
| 1448 lastDiagnosticWasFiltered = false; | 1470 lastDiagnosticWasFiltered = false; |
| 1449 MessageTemplate template = MessageTemplate.TEMPLATES[messageKind]; | 1471 reportDiagnostic(message, infos, kind); |
| 1450 reportDiagnostic( | |
| 1451 node, | |
| 1452 template.message(arguments, terseDiagnostics), | |
| 1453 kind); | |
| 1454 } | 1472 } |
| 1455 | 1473 |
| 1456 void reportDiagnostic(Spannable span, | 1474 void reportDiagnostic(DiagnosticMessage message, |
| 1457 Message message, | 1475 List<DiagnosticMessage> infos, |
| 1458 api.Diagnostic kind); | 1476 api.Diagnostic kind); |
| 1459 | 1477 |
| 1460 void reportAssertionFailure(SpannableAssertionFailure ex) { | 1478 void reportAssertionFailure(SpannableAssertionFailure ex) { |
| 1461 String message = (ex.message != null) ? tryToString(ex.message) | 1479 String message = (ex.message != null) ? tryToString(ex.message) |
| 1462 : tryToString(ex); | 1480 : tryToString(ex); |
| 1463 reportDiagnosticInternal( | 1481 reportDiagnosticInternal( |
| 1464 ex.node, MessageKind.GENERIC, {'text': message}, api.Diagnostic.CRASH); | 1482 createMessage(ex.node, MessageKind.GENERIC, {'text': message}), |
| 1483 const <DiagnosticMessage>[], |
| 1484 api.Diagnostic.CRASH); |
| 1465 } | 1485 } |
| 1466 | 1486 |
| 1467 SourceSpan spanFromTokens(Token begin, Token end, [Uri uri]) { | 1487 SourceSpan spanFromTokens(Token begin, Token end, [Uri uri]) { |
| 1468 if (begin == null || end == null) { | 1488 if (begin == null || end == null) { |
| 1469 // TODO(ahe): We can almost always do better. Often it is only | 1489 // TODO(ahe): We can almost always do better. Often it is only |
| 1470 // end that is null. Otherwise, we probably know the current | 1490 // end that is null. Otherwise, we probably know the current |
| 1471 // URI. | 1491 // URI. |
| 1472 throw 'Cannot find tokens to produce error message.'; | 1492 throw 'Cannot find tokens to produce error message.'; |
| 1473 } | 1493 } |
| 1474 if (uri == null && currentElement != null) { | 1494 if (uri == null && currentElement != null) { |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1591 currentToken = currentToken.next; | 1611 currentToken = currentToken.next; |
| 1592 } | 1612 } |
| 1593 return firstToken; | 1613 return firstToken; |
| 1594 } | 1614 } |
| 1595 | 1615 |
| 1596 void reportUnusedCode() { | 1616 void reportUnusedCode() { |
| 1597 void checkLive(member) { | 1617 void checkLive(member) { |
| 1598 if (member.isErroneous) return; | 1618 if (member.isErroneous) return; |
| 1599 if (member.isFunction) { | 1619 if (member.isFunction) { |
| 1600 if (!enqueuer.resolution.hasBeenResolved(member)) { | 1620 if (!enqueuer.resolution.hasBeenResolved(member)) { |
| 1601 reportHint(member, MessageKind.UNUSED_METHOD, | 1621 reportHintMessage( |
| 1602 {'name': member.name}); | 1622 member, MessageKind.UNUSED_METHOD, {'name': member.name}); |
| 1603 } | 1623 } |
| 1604 } else if (member.isClass) { | 1624 } else if (member.isClass) { |
| 1605 if (!member.isResolved) { | 1625 if (!member.isResolved) { |
| 1606 reportHint(member, MessageKind.UNUSED_CLASS, | 1626 reportHintMessage( |
| 1607 {'name': member.name}); | 1627 member, MessageKind.UNUSED_CLASS, {'name': member.name}); |
| 1608 } else { | 1628 } else { |
| 1609 member.forEachLocalMember(checkLive); | 1629 member.forEachLocalMember(checkLive); |
| 1610 } | 1630 } |
| 1611 } else if (member.isTypedef) { | 1631 } else if (member.isTypedef) { |
| 1612 if (!member.isResolved) { | 1632 if (!member.isResolved) { |
| 1613 reportHint(member, MessageKind.UNUSED_TYPEDEF, | 1633 reportHintMessage( |
| 1614 {'name': member.name}); | 1634 member, MessageKind.UNUSED_TYPEDEF, {'name': member.name}); |
| 1615 } | 1635 } |
| 1616 } | 1636 } |
| 1617 } | 1637 } |
| 1618 libraryLoader.libraries.forEach((LibraryElement library) { | 1638 libraryLoader.libraries.forEach((LibraryElement library) { |
| 1619 // TODO(ahe): Implement better heuristics to discover entry points of | 1639 // TODO(ahe): Implement better heuristics to discover entry points of |
| 1620 // packages and use that to discover unused implementation details in | 1640 // packages and use that to discover unused implementation details in |
| 1621 // packages. | 1641 // packages. |
| 1622 if (library.isPlatformLibrary || library.isPackageLibrary) return; | 1642 if (library.isPlatformLibrary || library.isPackageLibrary) return; |
| 1623 library.compilationUnits.forEach((unit) { | 1643 library.compilationUnits.forEach((unit) { |
| 1624 unit.forEachLocalMember(checkLive); | 1644 unit.forEachLocalMember(checkLive); |
| (...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1832 | 1852 |
| 1833 @override | 1853 @override |
| 1834 InterfaceType streamType([DartType elementType]) { | 1854 InterfaceType streamType([DartType elementType]) { |
| 1835 InterfaceType type = streamClass.computeType(compiler); | 1855 InterfaceType type = streamClass.computeType(compiler); |
| 1836 if (elementType == null) { | 1856 if (elementType == null) { |
| 1837 return streamClass.rawType; | 1857 return streamClass.rawType; |
| 1838 } | 1858 } |
| 1839 return type.createInstantiation([elementType]); | 1859 return type.createInstantiation([elementType]); |
| 1840 } | 1860 } |
| 1841 } | 1861 } |
| OLD | NEW |