Collects statements in program that the client wants.
| 42 | * Collects statements in program that the client wants. |
| 43 | */ |
| 44 | abstract class Collector extends ProgramAnalysis<StmtResult<Boolean>> { |
| 45 | |
| 46 | private static final Logger logger = LogManager.getLogger(Collector.class); |
| 47 | |
| 48 | Collector(AnalysisConfig config) { |
| 49 | super(config); |
| 50 | } |
| 51 | |
| 52 | @Override |
| 53 | public StmtResult<Boolean> analyze() { |
| 54 | PointerAnalysisResult result = World.get().getResult(PointerAnalysis.ID); |
| 55 | CallGraph<Invoke, JMethod> callGraph = result.getCallGraph(); |
| 56 | Set<Stmt> wantedStmts = Sets.newSet(); |
| 57 | int nRelevantStmts = 0; |
| 58 | int nWantedAppStmts = 0, nRelevantAppStmts = 0; |
| 59 | // collect want statements and count |
| 60 | for (JMethod method : callGraph) { |
| 61 | boolean isApp = method.isApplication(); |
| 62 | for (Stmt stmt : method.getIR()) { |
| 63 | if (isRelevant(stmt)) { |
| 64 | ++nRelevantStmts; |
| 65 | if (isApp) { |
| 66 | ++nRelevantAppStmts; |
| 67 | } |
| 68 | if (isWanted(stmt, result)) { |
| 69 | wantedStmts.add(stmt); |
| 70 | if (isApp) { |
| 71 | ++nWantedAppStmts; |
| 72 | } |
| 73 | } |
| 74 | } |
| 75 | } |
| 76 | } |
| 77 | // log statistics |
| 78 | logger.info("#{}: found {} in {} reachable relevant Stmts", |
| 79 | getDescription(), wantedStmts.size(), nRelevantStmts); |
| 80 | logger.info("#{}: found {} in {} reachable relevant Stmts (app)", |
| 81 | getDescription(), nWantedAppStmts, nRelevantAppStmts); |
| 82 | // convert result to StmtResult |
| 83 | return new StmtResult<>() { |
| 84 | |
| 85 | @Override |
| 86 | public boolean isRelevant(Stmt stmt) { |
| 87 | return Collector.this.isRelevant(stmt); |
| 88 | } |
| 89 | |
| 90 | @Override |
| 91 | public Boolean getResult(Stmt stmt) { |
| 92 | return wantedStmts.contains(stmt); |
| 93 | } |
| 94 | }; |
| 95 | } |
| 96 | |
| 97 | /** |
| 98 | * @return {@code true} if the given statement is relevant to the client. |
| 99 | */ |
| 100 | abstract boolean isRelevant(Stmt stmt); |
| 101 |
nothing calls this directly
no outgoing calls
no test coverage detected