OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 analyze_unused_dart2js; | 5 library analyze_unused_dart2js; |
6 | 6 |
7 import 'package:async_helper/async_helper.dart'; | 7 import 'package:async_helper/async_helper.dart'; |
8 | 8 |
9 import 'package:compiler/src/compiler.dart'; | 9 import 'package:compiler/src/compiler.dart'; |
10 import 'package:compiler/src/diagnostics/messages.dart'; | 10 import 'package:compiler/src/diagnostics/messages.dart'; |
11 import 'package:compiler/src/filenames.dart'; | 11 import 'package:compiler/src/filenames.dart'; |
12 | 12 |
13 import 'analyze_helper.dart'; | 13 import 'analyze_helper.dart'; |
14 | 14 |
15 // Do not remove WHITE_LIST even if it's empty. The error message for | 15 // Do not remove WHITE_LIST even if it's empty. The error message for |
16 // unused members refers to WHITE_LIST by name. | 16 // unused members refers to WHITE_LIST by name. |
17 const Map<String, List<String>> WHITE_LIST = const { | 17 const Map<String, List<String>> WHITE_LIST = const { |
18 // Helper methods for debugging should never be called from production code: | 18 // Helper methods for debugging should never be called from production code: |
19 "lib/src/helpers/": const [" is never "], | 19 "lib/src/helpers/": const [" is never "], |
20 | 20 |
21 // Node.asAssert, Node.asLiteralBool is never used. | 21 // Node.asAssert, Node.asLiteralBool is never used. |
22 "lib/src/tree/nodes.dart": const [ | 22 "lib/src/tree/nodes.dart": const [ |
23 "The method 'asAssert' is never called.", | 23 "The method 'asAssert' is never called.", |
24 "The method 'asLiteralBool' is never called."], | 24 "The method 'asLiteralBool' is never called." |
| 25 ], |
25 | 26 |
26 // Uncalled methods in SemanticSendVisitor and subclasses. | 27 // Uncalled methods in SemanticSendVisitor and subclasses. |
27 "lib/src/resolution/semantic_visitor.dart": const [ | 28 "lib/src/resolution/semantic_visitor.dart": const ["The method 'error"], |
28 "The method 'error"], | |
29 "lib/src/resolution/semantic_visitor_mixins.dart": const [ | 29 "lib/src/resolution/semantic_visitor_mixins.dart": const [ |
30 "The class 'SuperBulkMixin'", | 30 "The class 'SuperBulkMixin'", |
31 "The class 'Base", | 31 "The class 'Base", |
32 "The method 'error", | 32 "The method 'error", |
33 "The method 'visit"], | 33 "The method 'visit" |
| 34 ], |
34 | 35 |
35 // Uncalled type predicate. Keep while related predicates are used. | 36 // Uncalled type predicate. Keep while related predicates are used. |
36 "lib/src/ssa/nodes.dart": const [ | 37 "lib/src/ssa/nodes.dart": const ["The method 'isArray' is never called"], |
37 "The method 'isArray' is never called"], | |
38 | 38 |
39 // Serialization code is only used in test. | 39 // Serialization code is only used in test. |
40 "lib/src/serialization/": const [ | 40 "lib/src/serialization/": const ["is never"], |
41 "is never"], | |
42 | 41 |
43 "lib/src/universe/universe.dart": const [ | 42 "lib/src/universe/universe.dart": const [ |
44 "The method 'getterInvocationsByName' is never called.", | 43 "The method 'getterInvocationsByName' is never called.", |
45 "The method 'setterInvocationsByName' is never called."], | 44 "The method 'setterInvocationsByName' is never called." |
| 45 ], |
46 }; | 46 }; |
47 | 47 |
48 void main() { | 48 void main() { |
49 var uri = currentDirectory.resolve( | 49 var uri = |
50 'pkg/compiler/lib/src/use_unused_api.dart'); | 50 currentDirectory.resolve('pkg/compiler/lib/src/use_unused_api.dart'); |
51 asyncTest(() => analyze( | 51 asyncTest(() => analyze([uri], |
52 [uri], | |
53 // TODO(johnniwinther): Use [WHITE_LIST] again when | 52 // TODO(johnniwinther): Use [WHITE_LIST] again when |
54 // [Compiler.reportUnusedCode] is reenabled. | 53 // [Compiler.reportUnusedCode] is reenabled. |
55 const {}, // WHITE_LIST | 54 const {}, // WHITE_LIST |
56 mode: AnalysisMode.TREE_SHAKING, | 55 mode: AnalysisMode.TREE_SHAKING, |
57 checkResults: checkResults)); | 56 checkResults: checkResults)); |
58 } | 57 } |
59 | 58 |
60 bool checkResults(Compiler compiler, CollectingDiagnosticHandler handler) { | 59 bool checkResults(Compiler compiler, CollectingDiagnosticHandler handler) { |
61 var helperUri = currentDirectory.resolve( | 60 var helperUri = |
62 'pkg/compiler/lib/src/helpers/helpers.dart'); | 61 currentDirectory.resolve('pkg/compiler/lib/src/helpers/helpers.dart'); |
63 void checkLive(member) { | 62 void checkLive(member) { |
64 if (member.isFunction) { | 63 if (member.isFunction) { |
65 if (compiler.enqueuer.resolution.hasBeenProcessed(member)) { | 64 if (compiler.enqueuer.resolution.hasBeenProcessed(member)) { |
66 compiler.reporter.reportHintMessage( | 65 compiler.reporter.reportHintMessage(member, MessageKind.GENERIC, |
67 member, MessageKind.GENERIC, | |
68 {'text': "Helper function in production code '$member'."}); | 66 {'text': "Helper function in production code '$member'."}); |
69 } | 67 } |
70 } else if (member.isClass) { | 68 } else if (member.isClass) { |
71 if (member.isResolved) { | 69 if (member.isResolved) { |
72 compiler.reporter.reportHintMessage( | 70 compiler.reporter.reportHintMessage(member, MessageKind.GENERIC, |
73 member, MessageKind.GENERIC, | |
74 {'text': "Helper class in production code '$member'."}); | 71 {'text': "Helper class in production code '$member'."}); |
75 } else { | 72 } else { |
76 member.forEachLocalMember(checkLive); | 73 member.forEachLocalMember(checkLive); |
77 } | 74 } |
78 } else if (member.isTypedef) { | 75 } else if (member.isTypedef) { |
79 if (member.isResolved) { | 76 if (member.isResolved) { |
80 compiler.reporter.reportHintMessage( | 77 compiler.reporter.reportHintMessage(member, MessageKind.GENERIC, |
81 member, MessageKind.GENERIC, | |
82 {'text': "Helper typedef in production code '$member'."}); | 78 {'text': "Helper typedef in production code '$member'."}); |
83 } | 79 } |
84 } | 80 } |
85 } | 81 } |
| 82 |
86 compiler.libraryLoader.lookupLibrary(helperUri).forEachLocalMember(checkLive); | 83 compiler.libraryLoader.lookupLibrary(helperUri).forEachLocalMember(checkLive); |
87 return handler.checkResults(); | 84 return handler.checkResults(); |
88 } | 85 } |
OLD | NEW |