use of org.checkerframework.dataflow.cfg.block.SingleSuccessorBlock in project checker-framework by typetools.
the class DOTCFGVisualizer method generateDotGraph.
/**
* Generate the dot representation as String.
*/
protected String generateDotGraph(ControlFlowGraph cfg, Block entry, @Nullable Analysis<A, S, T> analysis) {
this.sbDigraph.setLength(0);
Set<Block> visited = new HashSet<>();
// header
this.sbDigraph.append("digraph {\n");
Block cur = entry;
Queue<Block> worklist = new ArrayDeque<>();
visited.add(entry);
// traverse control flow graph and define all arrows
while (true) {
if (cur == null) {
break;
}
if (cur.getType() == BlockType.CONDITIONAL_BLOCK) {
ConditionalBlock ccur = ((ConditionalBlock) cur);
Block thenSuccessor = ccur.getThenSuccessor();
addDotEdge(ccur.getId(), thenSuccessor.getId(), "then\\n" + ccur.getThenFlowRule());
if (!visited.contains(thenSuccessor)) {
visited.add(thenSuccessor);
worklist.add(thenSuccessor);
}
Block elseSuccessor = ccur.getElseSuccessor();
addDotEdge(ccur.getId(), elseSuccessor.getId(), "else\\n" + ccur.getElseFlowRule());
if (!visited.contains(elseSuccessor)) {
visited.add(elseSuccessor);
worklist.add(elseSuccessor);
}
} else {
assert cur instanceof SingleSuccessorBlock;
Block b = ((SingleSuccessorBlock) cur).getSuccessor();
if (b != null) {
addDotEdge(cur.getId(), b.getId(), ((SingleSuccessorBlock) cur).getFlowRule().name());
if (!visited.contains(b)) {
visited.add(b);
worklist.add(b);
}
}
}
// exceptional edges
if (cur.getType() == BlockType.EXCEPTION_BLOCK) {
ExceptionBlock ecur = (ExceptionBlock) cur;
for (Entry<TypeMirror, Set<Block>> e : ecur.getExceptionalSuccessors().entrySet()) {
Set<Block> blocks = e.getValue();
TypeMirror cause = e.getKey();
String exception = cause.toString();
if (exception.startsWith("java.lang.")) {
exception = exception.replace("java.lang.", "");
}
for (Block b : blocks) {
addDotEdge(cur.getId(), b.getId(), exception);
if (!visited.contains(b)) {
visited.add(b);
worklist.add(b);
}
}
}
}
cur = worklist.poll();
}
generateDotNodes(visited, cfg, analysis);
// footer
this.sbDigraph.append("}\n");
return this.sbDigraph.toString();
}
use of org.checkerframework.dataflow.cfg.block.SingleSuccessorBlock in project checker-framework by typetools.
the class MustCallInferenceLogic method getNormalSuccessors.
/**
* Returns the non-exceptional successors of the current block.
*
* @param cur the current block
* @return the successors of this current block
*/
private List<Block> getNormalSuccessors(Block cur) {
List<Block> successorBlock = new ArrayList<>();
if (cur.getType() == Block.BlockType.CONDITIONAL_BLOCK) {
ConditionalBlock ccur = (ConditionalBlock) cur;
successorBlock.add(ccur.getThenSuccessor());
successorBlock.add(ccur.getElseSuccessor());
} else {
if (!(cur instanceof SingleSuccessorBlock)) {
throw new BugInCF("BlockImpl is neither a conditional block nor a SingleSuccessorBlock");
}
Block b = ((SingleSuccessorBlock) cur).getSuccessor();
if (b != null) {
successorBlock.add(b);
}
}
return successorBlock;
}
Aggregations