use of org.evosuite.graphs.cfg.ActualControlFlowGraph in project evosuite by EvoSuite.
the class ControlDependenceGraph method computeControlDependence.
private void computeControlDependence() {
ActualControlFlowGraph rcfg = cfg.computeReverseCFG();
DominatorTree<BasicBlock> dt = new DominatorTree<BasicBlock>(rcfg);
for (BasicBlock b : rcfg.vertexSet()) if (!b.isExitBlock()) {
logger.debug("DFs for: " + b.getName());
for (BasicBlock cd : dt.getDominatingFrontiers(b)) {
ControlFlowEdge orig = cfg.getEdge(cd, b);
if (!cd.isEntryBlock() && orig == null) {
// in for loops for example it can happen that cd and b
// were not directly adjacent to each other in the CFG
// but rather there were some intermediate nodes between
// them and the needed information is inside one of the
// edges
// from cd to the first intermediate node. more
// precisely cd is expected to be a branch and to have 2
// outgoing edges, one for evaluating to true (jumping)
// and one for false. one of them can be followed and b
// will eventually be reached, the other one can not be
// followed in that way. TODO TRY!
logger.debug("cd: " + cd.toString());
logger.debug("b: " + b.toString());
// TODO this is just for now! unsafe and probably not
// even correct!
Set<ControlFlowEdge> candidates = cfg.outgoingEdgesOf(cd);
if (candidates.size() < 2)
throw new IllegalStateException("unexpected");
boolean leadToB = false;
boolean skip = false;
for (ControlFlowEdge e : candidates) {
if (!e.hasControlDependency()) {
skip = true;
break;
}
if (cfg.leadsToNode(e, b)) {
if (leadToB)
orig = null;
// throw new
// IllegalStateException("unexpected");
leadToB = true;
orig = e;
}
}
if (skip)
continue;
if (!leadToB)
throw new IllegalStateException("unexpected");
}
if (orig == null)
logger.debug("orig still null!");
if (!addEdge(cd, b, new ControlFlowEdge(orig)))
throw new IllegalStateException("internal error while adding CD edge");
logger.debug(" " + cd.getName());
}
}
}
Aggregations