private void cleanUpProgramState(CFG.Block block) { if (cleanup) { programState = programState.cleanupDeadSymbols(liveVariables.getOut(block)); programState = programState.cleanupConstraints(); } }
private void cleanUpProgramState(CFG.Block block) { if (cleanup) { Collection<SymbolicValue> protectedSVs = methodBehavior == null ? Collections.emptyList() : methodBehavior.parameters(); programState = programState.cleanupDeadSymbols(liveVariables.getOut(block), protectedSVs); programState = programState.cleanupConstraints(protectedSVs); } }
private void cleanUpProgramState(CFG.Block block) { if (cleanup) { Collection<SymbolicValue> protectedSVs = methodBehavior == null ? Collections.emptyList() : methodBehavior.parameters(); programState = programState.cleanupDeadSymbols(liveVariables.getOut(block), protectedSVs); programState = programState.cleanupConstraints(protectedSVs); } }
@Override public void visitForEachStatement(ForEachStatement tree) { CFG cfg = CFG.buildCFG(Collections.singletonList(tree), true); Symbol var = tree.variable().symbol(); boolean liveVar = true; if(var.owner().isMethodSymbol()) { cfg.setMethodSymbol((Symbol.MethodSymbol) var.owner()); LiveVariables analyze = LiveVariables.analyze(cfg); Set<Symbol> live = analyze.getOut(cfg.reversedBlocks().get(1)); liveVar = live.contains(var); } if(!liveVar) { variables.add(var); } super.visitForEachStatement(tree); if(!liveVar) { variables.remove(var); } }
@Override public void visitForEachStatement(ForEachStatement tree) { CFG cfg = CFG.buildCFG(Collections.singletonList(tree), true); Symbol var = tree.variable().symbol(); boolean liveVar = true; if(var.owner().isMethodSymbol()) { cfg.setMethodSymbol((Symbol.MethodSymbol) var.owner()); LiveVariables analyze = LiveVariables.analyze(cfg); Set<Symbol> live = analyze.getOut(cfg.reversedBlocks().get(1)); liveVar = live.contains(var); } if(!liveVar) { variables.add(var); } super.visitForEachStatement(tree); if(!liveVar) { variables.remove(var); } }
@Override public void visitNode(Tree tree) { if (!hasSemantic()) { return; } MethodTree methodTree = (MethodTree) tree; if (methodTree.block() == null) { return; } // TODO(npe) Exclude try statements with finally as CFG is incorrect for those and lead to false positive if (hasTryFinallyWithLocalVar(methodTree.block(), methodTree.symbol())) { return; } Symbol.MethodSymbol methodSymbol = methodTree.symbol(); CFG cfg = CFG.build(methodTree); LiveVariables liveVariables = LiveVariables.analyze(cfg); // Liveness analysis provides information only for block boundaries, so we should do analysis between elements within blocks for (CFG.Block block : cfg.blocks()) { checkElements(block, liveVariables.getOut(block), methodSymbol); } }
@Override public void visitNode(Tree tree) { if (!hasSemantic()) { return; } MethodTree methodTree = (MethodTree) tree; if (methodTree.block() == null) { return; } // TODO(npe) Exclude try statements with finally as CFG is incorrect for those and lead to false positive if (hasTryFinallyWithLocalVar(methodTree.block(), methodTree.symbol())) { return; } Symbol.MethodSymbol methodSymbol = methodTree.symbol(); CFG cfg = CFG.build(methodTree); LiveVariables liveVariables = LiveVariables.analyze(cfg); // Liveness analysis provides information only for block boundaries, so we should do analysis between elements within blocks for (CFG.Block block : cfg.blocks()) { checkElements(block, liveVariables.getOut(block), methodSymbol); } }