| 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 375 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 386 | 386 |
| 387 /** | 387 /** |
| 388 * URI of the main source map if the compiler is generating source | 388 * URI of the main source map if the compiler is generating source |
| 389 * maps. | 389 * maps. |
| 390 */ | 390 */ |
| 391 final Uri sourceMapUri; | 391 final Uri sourceMapUri; |
| 392 | 392 |
| 393 /// Emit terse diagnostics without howToFix. | 393 /// Emit terse diagnostics without howToFix. |
| 394 final bool terseDiagnostics; | 394 final bool terseDiagnostics; |
| 395 | 395 |
| 396 /// If `true`, warnings and hints not from user code are not reported. | 396 /// If `true`, warnings and hints not from user code are reported. |
| 397 final bool hidePackageWarnings; | 397 final bool showPackageWarnings; |
| 398 | 398 |
| 399 /// `true` if the last diagnostic was filtered, in which case the | 399 /// `true` if the last diagnostic was filtered, in which case the |
| 400 /// accompanying info message should be filtered as well. | 400 /// accompanying info message should be filtered as well. |
| 401 bool lastDiagnosticWasFiltered = false; | 401 bool lastDiagnosticWasFiltered = false; |
| 402 | 402 |
| 403 /// Map containing information about the warnings and hints that have been |
| 404 /// suppressed for each library. |
| 405 Map<Uri, SuppressionInfo> suppressedWarnings = <Uri, SuppressionInfo>{}; |
| 406 |
| 403 final api.CompilerOutputProvider outputProvider; | 407 final api.CompilerOutputProvider outputProvider; |
| 404 | 408 |
| 405 bool disableInlining = false; | 409 bool disableInlining = false; |
| 406 | 410 |
| 407 List<Uri> librariesToAnalyzeWhenRun; | 411 List<Uri> librariesToAnalyzeWhenRun; |
| 408 | 412 |
| 409 final Tracer tracer; | 413 final Tracer tracer; |
| 410 | 414 |
| 411 CompilerTask measuredTask; | 415 CompilerTask measuredTask; |
| 412 Element _currentElement; | 416 Element _currentElement; |
| (...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 615 bool generateSourceMap: true, | 619 bool generateSourceMap: true, |
| 616 this.analyzeAllFlag: false, | 620 this.analyzeAllFlag: false, |
| 617 bool analyzeOnly: false, | 621 bool analyzeOnly: false, |
| 618 bool analyzeSignaturesOnly: false, | 622 bool analyzeSignaturesOnly: false, |
| 619 this.preserveComments: false, | 623 this.preserveComments: false, |
| 620 this.verbose: false, | 624 this.verbose: false, |
| 621 this.sourceMapUri: null, | 625 this.sourceMapUri: null, |
| 622 this.buildId: UNDETERMINED_BUILD_ID, | 626 this.buildId: UNDETERMINED_BUILD_ID, |
| 623 this.terseDiagnostics: false, | 627 this.terseDiagnostics: false, |
| 624 this.dumpInfo: false, | 628 this.dumpInfo: false, |
| 625 this.hidePackageWarnings: false, | 629 this.showPackageWarnings: false, |
| 626 outputProvider, | 630 outputProvider, |
| 627 List<String> strips: const []}) | 631 List<String> strips: const []}) |
| 628 : this.analyzeOnly = analyzeOnly || analyzeSignaturesOnly, | 632 : this.analyzeOnly = analyzeOnly || analyzeSignaturesOnly, |
| 629 this.analyzeSignaturesOnly = analyzeSignaturesOnly, | 633 this.analyzeSignaturesOnly = analyzeSignaturesOnly, |
| 630 this.outputProvider = (outputProvider == null) | 634 this.outputProvider = (outputProvider == null) |
| 631 ? NullSink.outputProvider | 635 ? NullSink.outputProvider |
| 632 : outputProvider { | 636 : outputProvider { |
| 633 world = new World(this); | 637 world = new World(this); |
| 634 | 638 |
| 635 closureMapping.ClosureNamer closureNamer; | 639 closureMapping.ClosureNamer closureNamer; |
| (...skipping 451 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1087 (_, lib) => fullyEnqueueLibrary(lib, enqueuer.resolution)); | 1091 (_, lib) => fullyEnqueueLibrary(lib, enqueuer.resolution)); |
| 1088 } | 1092 } |
| 1089 // Elements required by enqueueHelpers are global dependencies | 1093 // Elements required by enqueueHelpers are global dependencies |
| 1090 // that are not pulled in by a particular element. | 1094 // that are not pulled in by a particular element. |
| 1091 backend.enqueueHelpers(enqueuer.resolution, globalDependencies); | 1095 backend.enqueueHelpers(enqueuer.resolution, globalDependencies); |
| 1092 resolveLibraryMetadata(); | 1096 resolveLibraryMetadata(); |
| 1093 processQueue(enqueuer.resolution, main); | 1097 processQueue(enqueuer.resolution, main); |
| 1094 enqueuer.resolution.logSummary(log); | 1098 enqueuer.resolution.logSummary(log); |
| 1095 | 1099 |
| 1096 if (compilationFailed) return; | 1100 if (compilationFailed) return; |
| 1101 if (!showPackageWarnings) { |
| 1102 suppressedWarnings.forEach((Uri uri, SuppressionInfo info) { |
| 1103 MessageKind kind = MessageKind.HIDDEN_WARNINGS_HINTS; |
| 1104 if (info.warnings == 0) { |
| 1105 kind = MessageKind.HIDDEN_HINTS; |
| 1106 } else if (info.hints == 0) { |
| 1107 kind = MessageKind.HIDDEN_WARNINGS; |
| 1108 } |
| 1109 reportDiagnostic(null, |
| 1110 kind.message({'warnings': info.warnings, |
| 1111 'hints': info.hints, |
| 1112 'uri': uri}, |
| 1113 terseDiagnostics), |
| 1114 api.Diagnostic.HINT); |
| 1115 }); |
| 1116 } |
| 1097 if (analyzeOnly) { | 1117 if (analyzeOnly) { |
| 1098 if (!analyzeAll) { | 1118 if (!analyzeAll) { |
| 1099 // No point in reporting unused code when [analyzeAll] is true: all | 1119 // No point in reporting unused code when [analyzeAll] is true: all |
| 1100 // code is artificially used. | 1120 // code is artificially used. |
| 1101 reportUnusedCode(); | 1121 reportUnusedCode(); |
| 1102 } | 1122 } |
| 1103 return; | 1123 return; |
| 1104 } | 1124 } |
| 1105 assert(main != null); | 1125 assert(main != null); |
| 1106 phase = PHASE_DONE_RESOLVING; | 1126 phase = PHASE_DONE_RESOLVING; |
| (...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1379 void reportInternalError(Spannable node, MessageKind messageKind, | 1399 void reportInternalError(Spannable node, MessageKind messageKind, |
| 1380 [Map arguments = const {}]) { | 1400 [Map arguments = const {}]) { |
| 1381 reportDiagnosticInternal( | 1401 reportDiagnosticInternal( |
| 1382 node, messageKind, arguments, api.Diagnostic.CRASH); | 1402 node, messageKind, arguments, api.Diagnostic.CRASH); |
| 1383 } | 1403 } |
| 1384 | 1404 |
| 1385 void reportDiagnosticInternal(Spannable node, | 1405 void reportDiagnosticInternal(Spannable node, |
| 1386 MessageKind messageKind, | 1406 MessageKind messageKind, |
| 1387 Map arguments, | 1407 Map arguments, |
| 1388 api.Diagnostic kind) { | 1408 api.Diagnostic kind) { |
| 1389 if (hidePackageWarnings) { | 1409 if (!showPackageWarnings) { |
| 1390 switch (kind) { | 1410 switch (kind) { |
| 1391 case api.Diagnostic.WARNING: | 1411 case api.Diagnostic.WARNING: |
| 1392 case api.Diagnostic.HINT: | 1412 case api.Diagnostic.HINT: |
| 1393 if (!inUserCode(elementFromSpannable(node))) { | 1413 Element element = elementFromSpannable(node); |
| 1414 if (!inUserCode(element)) { |
| 1415 Uri uri = getCanonicalUri(element); |
| 1416 SuppressionInfo info = |
| 1417 suppressedWarnings.putIfAbsent(uri, () => new SuppressionInfo()); |
| 1418 if (kind == api.Diagnostic.WARNING) { |
| 1419 info.warnings++; |
| 1420 } else { |
| 1421 info.hints++; |
| 1422 } |
| 1394 lastDiagnosticWasFiltered = true; | 1423 lastDiagnosticWasFiltered = true; |
| 1395 return; | 1424 return; |
| 1396 } | 1425 } |
| 1397 break; | 1426 break; |
| 1398 case api.Diagnostic.INFO: | 1427 case api.Diagnostic.INFO: |
| 1399 if (lastDiagnosticWasFiltered) { | 1428 if (lastDiagnosticWasFiltered) { |
| 1400 return; | 1429 return; |
| 1401 } | 1430 } |
| 1402 break; | 1431 break; |
| 1403 } | 1432 } |
| (...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1583 /// If an entrypoint URI uses the 'package' scheme then every library from | 1612 /// If an entrypoint URI uses the 'package' scheme then every library from |
| 1584 /// that same package is considered to be in user code. For instance, if | 1613 /// that same package is considered to be in user code. For instance, if |
| 1585 /// an entry point URI is 'package:foo/bar.dart' then every library whose | 1614 /// an entry point URI is 'package:foo/bar.dart' then every library whose |
| 1586 /// canonical URI starts with 'package:foo/' is in user code. | 1615 /// canonical URI starts with 'package:foo/' is in user code. |
| 1587 /// | 1616 /// |
| 1588 /// If an entrypoint URI uses another scheme than 'package' then every library | 1617 /// If an entrypoint URI uses another scheme than 'package' then every library |
| 1589 /// with that scheme is in user code. For instance, an entry point URI is | 1618 /// with that scheme is in user code. For instance, an entry point URI is |
| 1590 /// 'file:///foo.dart' then every library whose canonical URI scheme is | 1619 /// 'file:///foo.dart' then every library whose canonical URI scheme is |
| 1591 /// 'file' is in user code. | 1620 /// 'file' is in user code. |
| 1592 bool inUserCode(Element element) { | 1621 bool inUserCode(Element element) { |
| 1593 if (element == null) return false; | |
| 1594 Uri libraryUri = element.getLibrary().canonicalUri; | |
| 1595 List<Uri> entrypoints = <Uri>[]; | 1622 List<Uri> entrypoints = <Uri>[]; |
| 1596 if (mainApp != null) { | 1623 if (mainApp != null) { |
| 1597 entrypoints.add(mainApp.canonicalUri); | 1624 entrypoints.add(mainApp.canonicalUri); |
| 1598 } | 1625 } |
| 1599 if (librariesToAnalyzeWhenRun != null) { | 1626 if (librariesToAnalyzeWhenRun != null) { |
| 1600 entrypoints.addAll(librariesToAnalyzeWhenRun); | 1627 entrypoints.addAll(librariesToAnalyzeWhenRun); |
| 1601 } | 1628 } |
| 1629 if (entrypoints.isEmpty) { |
| 1630 // Assume in user code since [mainApp] has not been set yet. |
| 1631 return true; |
| 1632 } |
| 1633 if (element == null) return false; |
| 1634 Uri libraryUri = element.getLibrary().canonicalUri; |
| 1602 if (libraryUri.scheme == 'package') { | 1635 if (libraryUri.scheme == 'package') { |
| 1603 for (Uri uri in entrypoints) { | 1636 for (Uri uri in entrypoints) { |
| 1604 if (uri.scheme != 'package') continue; | 1637 if (uri.scheme != 'package') continue; |
| 1605 int slashPos = libraryUri.path.indexOf('/'); | 1638 int slashPos = libraryUri.path.indexOf('/'); |
| 1606 if (slashPos != -1) { | 1639 if (slashPos != -1) { |
| 1607 String packageName = libraryUri.path.substring(0, slashPos + 1); | 1640 String packageName = libraryUri.path.substring(0, slashPos + 1); |
| 1608 if (uri.path.startsWith(packageName)) { | 1641 if (uri.path.startsWith(packageName)) { |
| 1609 return true; | 1642 return true; |
| 1610 } | 1643 } |
| 1611 } else { | 1644 } else { |
| 1612 if (libraryUri.path == uri.path) { | 1645 if (libraryUri.path == uri.path) { |
| 1613 return true; | 1646 return true; |
| 1614 } | 1647 } |
| 1615 } | 1648 } |
| 1616 } | 1649 } |
| 1617 } else { | 1650 } else { |
| 1618 for (Uri uri in entrypoints) { | 1651 for (Uri uri in entrypoints) { |
| 1619 if (libraryUri.scheme == uri.scheme) return true; | 1652 if (libraryUri.scheme == uri.scheme) return true; |
| 1620 } | 1653 } |
| 1621 } | 1654 } |
| 1622 return false; | 1655 return false; |
| 1623 } | 1656 } |
| 1624 | 1657 |
| 1658 /// Return a canonical URI for the source of [element]. |
| 1659 /// |
| 1660 /// For a package library with canonical URI 'package:foo/bar/baz.dart' the |
| 1661 /// return URI is 'package:foo'. For non-package libraries the returned URI is |
| 1662 /// the canonical URI of the library itself. |
| 1663 Uri getCanonicalUri(Element element) { |
| 1664 if (element == null) return null; |
| 1665 Uri libraryUri = element.getLibrary().canonicalUri; |
| 1666 if (libraryUri.scheme == 'package') { |
| 1667 int slashPos = libraryUri.path.indexOf('/'); |
| 1668 if (slashPos != -1) { |
| 1669 String packageName = libraryUri.path.substring(0, slashPos); |
| 1670 return new Uri(scheme: 'package', path: packageName); |
| 1671 } |
| 1672 } |
| 1673 return libraryUri; |
| 1674 } |
| 1675 |
| 1625 } | 1676 } |
| 1626 | 1677 |
| 1627 class CompilerTask { | 1678 class CompilerTask { |
| 1628 final Compiler compiler; | 1679 final Compiler compiler; |
| 1629 final Stopwatch watch; | 1680 final Stopwatch watch; |
| 1630 | 1681 |
| 1631 CompilerTask(Compiler compiler) | 1682 CompilerTask(Compiler compiler) |
| 1632 : this.compiler = compiler, | 1683 : this.compiler = compiler, |
| 1633 watch = (compiler.verbose) ? new Stopwatch() : null; | 1684 watch = (compiler.verbose) ? new Stopwatch() : null; |
| 1634 | 1685 |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1753 | 1804 |
| 1754 void close() {} | 1805 void close() {} |
| 1755 | 1806 |
| 1756 toString() => name; | 1807 toString() => name; |
| 1757 | 1808 |
| 1758 /// Convenience method for getting an [api.CompilerOutputProvider]. | 1809 /// Convenience method for getting an [api.CompilerOutputProvider]. |
| 1759 static NullSink outputProvider(String name, String extension) { | 1810 static NullSink outputProvider(String name, String extension) { |
| 1760 return new NullSink('$name.$extension'); | 1811 return new NullSink('$name.$extension'); |
| 1761 } | 1812 } |
| 1762 } | 1813 } |
| 1814 |
| 1815 /// Information about suppressed warnings and hints for a given library. |
| 1816 class SuppressionInfo { |
| 1817 int warnings = 0; |
| 1818 int hints = 0; |
| 1819 } |
| OLD | NEW |