| 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 1524 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1535 libraries.forEach((_, library) { | 1535 libraries.forEach((_, library) { |
| 1536 // TODO(ahe): Implement better heuristics to discover entry points of | 1536 // TODO(ahe): Implement better heuristics to discover entry points of |
| 1537 // packages and use that to discover unused implementation details in | 1537 // packages and use that to discover unused implementation details in |
| 1538 // packages. | 1538 // packages. |
| 1539 if (library.isPlatformLibrary || library.isPackageLibrary) return; | 1539 if (library.isPlatformLibrary || library.isPackageLibrary) return; |
| 1540 library.compilationUnits.forEach((unit) { | 1540 library.compilationUnits.forEach((unit) { |
| 1541 unit.forEachLocalMember(checkLive); | 1541 unit.forEachLocalMember(checkLive); |
| 1542 }); | 1542 }); |
| 1543 }); | 1543 }); |
| 1544 } | 1544 } |
| 1545 |
| 1546 /// Debugging helper for determining whether the current element is declared |
| 1547 /// within 'user code'. |
| 1548 /// |
| 1549 /// See [inUserCode] for what defines 'user code'. |
| 1550 bool currentlyInUserCode() { |
| 1551 return inUserCode(currentElement); |
| 1552 } |
| 1553 |
| 1554 /// Debugging helper for determining whether [element] is declared within |
| 1555 /// 'user code'. |
| 1556 /// |
| 1557 /// What constitutes 'user code' is defined by the URI(s) provided by the |
| 1558 /// entry point(s) of compilation or analysis: |
| 1559 /// |
| 1560 /// If an entrypoint URI uses the 'package' scheme then every library from |
| 1561 /// that same package is considered to be in user code. For instance, if |
| 1562 /// an entry point URI is 'package:foo/bar.dart' then every library whose |
| 1563 /// canonical URI starts with 'package:foo/' is in user code. |
| 1564 /// |
| 1565 /// If an entrypoint URI uses another scheme than 'package' then every library |
| 1566 /// with that scheme is in user code. For instance, an entry point URI is |
| 1567 /// 'file:///foo.dart' then every library whose canonical URI scheme is |
| 1568 /// 'file' is in user code. |
| 1569 bool inUserCode(Element element) { |
| 1570 if (element == null) return false; |
| 1571 Uri libraryUri = element.getLibrary().canonicalUri; |
| 1572 List<Uri> entrypoints = <Uri>[]; |
| 1573 if (mainApp != null) { |
| 1574 entrypoints.add(mainApp.canonicalUri); |
| 1575 } |
| 1576 if (librariesToAnalyzeWhenRun != null) { |
| 1577 entrypoints.addAll(librariesToAnalyzeWhenRun); |
| 1578 } |
| 1579 if (libraryUri.scheme == 'package') { |
| 1580 for (Uri uri in entrypoints) { |
| 1581 if (uri.scheme != 'package') continue; |
| 1582 int slashPos = libraryUri.path.indexOf('/'); |
| 1583 if (slashPos != -1) { |
| 1584 String packageName = libraryUri.path.substring(0, slashPos + 1); |
| 1585 if (uri.path.startsWith(packageName)) { |
| 1586 return true; |
| 1587 } |
| 1588 } else { |
| 1589 if (libraryUri.path == uri.path) { |
| 1590 return true; |
| 1591 } |
| 1592 } |
| 1593 } |
| 1594 } else { |
| 1595 for (Uri uri in entrypoints) { |
| 1596 if (libraryUri.scheme == uri.scheme) return true; |
| 1597 } |
| 1598 } |
| 1599 return false; |
| 1600 } |
| 1601 |
| 1545 } | 1602 } |
| 1546 | 1603 |
| 1547 class CompilerTask { | 1604 class CompilerTask { |
| 1548 final Compiler compiler; | 1605 final Compiler compiler; |
| 1549 final Stopwatch watch; | 1606 final Stopwatch watch; |
| 1550 | 1607 |
| 1551 CompilerTask(Compiler compiler) | 1608 CompilerTask(Compiler compiler) |
| 1552 : this.compiler = compiler, | 1609 : this.compiler = compiler, |
| 1553 watch = (compiler.verbose) ? new Stopwatch() : null; | 1610 watch = (compiler.verbose) ? new Stopwatch() : null; |
| 1554 | 1611 |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1673 | 1730 |
| 1674 void close() {} | 1731 void close() {} |
| 1675 | 1732 |
| 1676 toString() => name; | 1733 toString() => name; |
| 1677 | 1734 |
| 1678 /// Convenience method for getting an [api.CompilerOutputProvider]. | 1735 /// Convenience method for getting an [api.CompilerOutputProvider]. |
| 1679 static NullSink outputProvider(String name, String extension) { | 1736 static NullSink outputProvider(String name, String extension) { |
| 1680 return new NullSink('$name.$extension'); | 1737 return new NullSink('$name.$extension'); |
| 1681 } | 1738 } |
| 1682 } | 1739 } |
| OLD | NEW |