Search in sources :

Example 1 with ActualControlFlowGraph

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());
        }
    }
}
Also used : ActualControlFlowGraph(org.evosuite.graphs.cfg.ActualControlFlowGraph) HashSet(java.util.HashSet) Set(java.util.Set) LinkedHashSet(java.util.LinkedHashSet) ControlFlowEdge(org.evosuite.graphs.cfg.ControlFlowEdge) BasicBlock(org.evosuite.graphs.cfg.BasicBlock)

Aggregations

HashSet (java.util.HashSet)1 LinkedHashSet (java.util.LinkedHashSet)1 Set (java.util.Set)1 ActualControlFlowGraph (org.evosuite.graphs.cfg.ActualControlFlowGraph)1 BasicBlock (org.evosuite.graphs.cfg.BasicBlock)1 ControlFlowEdge (org.evosuite.graphs.cfg.ControlFlowEdge)1