Chromium Code Reviews| 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 1354 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1365 void reportInfo(Spannable node, MessageKind messageKind, | 1365 void reportInfo(Spannable node, MessageKind messageKind, |
| 1366 [Map arguments = const {}]) { | 1366 [Map arguments = const {}]) { |
| 1367 reportDiagnosticInternal(node, messageKind, arguments, api.Diagnostic.INFO); | 1367 reportDiagnosticInternal(node, messageKind, arguments, api.Diagnostic.INFO); |
| 1368 } | 1368 } |
| 1369 | 1369 |
| 1370 void reportHint(Spannable node, MessageKind messageKind, | 1370 void reportHint(Spannable node, MessageKind messageKind, |
| 1371 [Map arguments = const {}]) { | 1371 [Map arguments = const {}]) { |
| 1372 reportDiagnosticInternal(node, messageKind, arguments, api.Diagnostic.HINT); | 1372 reportDiagnosticInternal(node, messageKind, arguments, api.Diagnostic.HINT); |
| 1373 } | 1373 } |
| 1374 | 1374 |
| 1375 /// For debugging only, print a message with a source location. | |
| 1376 void reportHere(Spannable node, String debugMessage) { | |
|
ahe
2014/04/10 11:06:32
Is there an alternative to this?
Johnni Winther
2014/04/10 11:11:45
It is moved to helpers/helpers.dart to ensure that
ahe
2014/04/10 11:43:46
That means I have to import helpers/helpers.dart.
Johnni Winther
2014/04/10 12:04:21
Why is it a problem to import 'helpers/helpers.dar
| |
| 1377 reportInfo(node, MessageKind.GENERIC, {'text': 'HERE: $debugMessage'}); | |
| 1378 } | |
| 1379 | |
| 1380 void reportDiagnosticInternal(Spannable node, | 1375 void reportDiagnosticInternal(Spannable node, |
| 1381 MessageKind messageKind, | 1376 MessageKind messageKind, |
| 1382 Map arguments, | 1377 Map arguments, |
| 1383 api.Diagnostic kind) { | 1378 api.Diagnostic kind) { |
| 1384 if (!showPackageWarnings) { | 1379 if (!showPackageWarnings) { |
| 1385 switch (kind) { | 1380 switch (kind) { |
| 1386 case api.Diagnostic.WARNING: | 1381 case api.Diagnostic.WARNING: |
| 1387 case api.Diagnostic.HINT: | 1382 case api.Diagnostic.HINT: |
| 1388 Element element = elementFromSpannable(node); | 1383 Element element = elementFromSpannable(node); |
| 1389 if (!inUserCode(element)) { | 1384 if (!inUserCode(element, assumeInUserCode: true)) { |
| 1390 Uri uri = getCanonicalUri(element); | 1385 Uri uri = getCanonicalUri(element); |
| 1391 SuppressionInfo info = | 1386 SuppressionInfo info = |
| 1392 suppressedWarnings.putIfAbsent(uri, () => new SuppressionInfo()); | 1387 suppressedWarnings.putIfAbsent(uri, () => new SuppressionInfo()); |
| 1393 if (kind == api.Diagnostic.WARNING) { | 1388 if (kind == api.Diagnostic.WARNING) { |
| 1394 info.warnings++; | 1389 info.warnings++; |
| 1395 } else { | 1390 } else { |
| 1396 info.hints++; | 1391 info.hints++; |
| 1397 } | 1392 } |
| 1398 lastDiagnosticWasFiltered = true; | 1393 lastDiagnosticWasFiltered = true; |
| 1399 return; | 1394 return; |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1543 currentToken = currentToken.next; | 1538 currentToken = currentToken.next; |
| 1544 } | 1539 } |
| 1545 return firstToken; | 1540 return firstToken; |
| 1546 } | 1541 } |
| 1547 | 1542 |
| 1548 void reportUnusedCode() { | 1543 void reportUnusedCode() { |
| 1549 void checkLive(member) { | 1544 void checkLive(member) { |
| 1550 if (member.isFunction()) { | 1545 if (member.isFunction()) { |
| 1551 if (!enqueuer.resolution.isLive(member)) { | 1546 if (!enqueuer.resolution.isLive(member)) { |
| 1552 reportHint(member, MessageKind.UNUSED_METHOD, | 1547 reportHint(member, MessageKind.UNUSED_METHOD, |
| 1553 {'method_name': member.name}); | 1548 {'name': member.name}); |
| 1554 } | 1549 } |
| 1555 } else if (member.isClass() && !member.isMixinApplication) { | 1550 } else if (member.isClass()) { |
| 1556 member.forEachLocalMember(checkLive); | 1551 if (!member.isResolved) { |
| 1552 reportHint(member, MessageKind.UNUSED_CLASS, | |
| 1553 {'name': member.name}); | |
| 1554 } else { | |
| 1555 member.forEachLocalMember(checkLive); | |
| 1556 } | |
| 1557 } else if (member.isTypedef()) { | |
| 1558 if (!member.isResolved) { | |
| 1559 reportHint(member, MessageKind.UNUSED_TYPEDEF, | |
| 1560 {'name': member.name}); | |
| 1561 } | |
| 1557 } | 1562 } |
| 1558 } | 1563 } |
| 1559 libraries.forEach((_, library) { | 1564 libraries.forEach((_, library) { |
| 1560 // TODO(ahe): Implement better heuristics to discover entry points of | 1565 // TODO(ahe): Implement better heuristics to discover entry points of |
| 1561 // packages and use that to discover unused implementation details in | 1566 // packages and use that to discover unused implementation details in |
| 1562 // packages. | 1567 // packages. |
| 1563 if (library.isPlatformLibrary || library.isPackageLibrary) return; | 1568 if (library.isPlatformLibrary || library.isPackageLibrary) return; |
| 1564 library.compilationUnits.forEach((unit) { | 1569 library.compilationUnits.forEach((unit) { |
| 1565 unit.forEachLocalMember(checkLive); | 1570 unit.forEachLocalMember(checkLive); |
| 1566 }); | 1571 }); |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 1582 /// | 1587 /// |
| 1583 /// If an entrypoint URI uses the 'package' scheme then every library from | 1588 /// 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 | 1589 /// 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 | 1590 /// an entry point URI is 'package:foo/bar.dart' then every library whose |
| 1586 /// canonical URI starts with 'package:foo/' is in user code. | 1591 /// canonical URI starts with 'package:foo/' is in user code. |
| 1587 /// | 1592 /// |
| 1588 /// If an entrypoint URI uses another scheme than 'package' then every library | 1593 /// 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 | 1594 /// 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 | 1595 /// 'file:///foo.dart' then every library whose canonical URI scheme is |
| 1591 /// 'file' is in user code. | 1596 /// 'file' is in user code. |
| 1592 bool inUserCode(Element element) { | 1597 /// |
| 1598 /// If [assumeInUserCode] is `true`, [element] is assumed to be in user code | |
| 1599 /// if no entrypoints have been set. | |
| 1600 bool inUserCode(Element element, {bool assumeInUserCode: false}) { | |
| 1593 List<Uri> entrypoints = <Uri>[]; | 1601 List<Uri> entrypoints = <Uri>[]; |
| 1594 if (mainApp != null) { | 1602 if (mainApp != null) { |
| 1595 entrypoints.add(mainApp.canonicalUri); | 1603 entrypoints.add(mainApp.canonicalUri); |
| 1596 } | 1604 } |
| 1597 if (librariesToAnalyzeWhenRun != null) { | 1605 if (librariesToAnalyzeWhenRun != null) { |
| 1598 entrypoints.addAll(librariesToAnalyzeWhenRun); | 1606 entrypoints.addAll(librariesToAnalyzeWhenRun); |
| 1599 } | 1607 } |
| 1600 if (entrypoints.isEmpty) { | 1608 if (entrypoints.isEmpty && assumeInUserCode) { |
| 1601 // Assume in user code since [mainApp] has not been set yet. | 1609 // Assume in user code since [mainApp] has not been set yet. |
| 1602 return true; | 1610 return true; |
| 1603 } | 1611 } |
| 1604 if (element == null) return false; | 1612 if (element == null) return false; |
| 1605 Uri libraryUri = element.getLibrary().canonicalUri; | 1613 Uri libraryUri = element.getLibrary().canonicalUri; |
| 1606 if (libraryUri.scheme == 'package') { | 1614 if (libraryUri.scheme == 'package') { |
| 1607 for (Uri uri in entrypoints) { | 1615 for (Uri uri in entrypoints) { |
| 1608 if (uri.scheme != 'package') continue; | 1616 if (uri.scheme != 'package') continue; |
| 1609 int slashPos = libraryUri.path.indexOf('/'); | 1617 int slashPos = libraryUri.path.indexOf('/'); |
| 1610 if (slashPos != -1) { | 1618 if (slashPos != -1) { |
| (...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1781 static NullSink outputProvider(String name, String extension) { | 1789 static NullSink outputProvider(String name, String extension) { |
| 1782 return new NullSink('$name.$extension'); | 1790 return new NullSink('$name.$extension'); |
| 1783 } | 1791 } |
| 1784 } | 1792 } |
| 1785 | 1793 |
| 1786 /// Information about suppressed warnings and hints for a given library. | 1794 /// Information about suppressed warnings and hints for a given library. |
| 1787 class SuppressionInfo { | 1795 class SuppressionInfo { |
| 1788 int warnings = 0; | 1796 int warnings = 0; |
| 1789 int hints = 0; | 1797 int hints = 0; |
| 1790 } | 1798 } |
| OLD | NEW |