private static boolean extractLastIf(DoStatement stat) { // search for an if condition at the end of the loop Statement last = stat.getFirst(); while (last.type == Statement.TYPE_SEQUENCE) { last = last.getStats().getLast(); } if (last.type == Statement.TYPE_IF) { IfStatement lastif = (IfStatement)last; if (lastif.iftype == IfStatement.IFTYPE_IF && lastif.getIfstat() != null) { Statement ifstat = lastif.getIfstat(); StatEdge elseedge = lastif.getAllSuccessorEdges().get(0); if (elseedge.getType() == StatEdge.TYPE_CONTINUE && elseedge.closure == stat) { Set<Statement> set = stat.getNeighboursSet(StatEdge.TYPE_CONTINUE, Statement.DIRECTION_BACKWARD); set.remove(last); if (set.isEmpty()) { // no direct continues in a do{}while loop if (isExternStatement(stat, ifstat, ifstat)) { extractIfBlock(stat, lastif); return true; } } } } } return false; }
StatEdge ifedge = ifchild.getAllSuccessorEdges().get(0);
ifchild.removeSuccessor(ifchild.getAllSuccessorEdges().get(0)); ifparent.getStats().removeWithKey(ifchild.id);
ifelsestat.setElsestat(null); if (ifelsestat.getAllSuccessorEdges().isEmpty() && !ifstat.getAllSuccessorEdges().isEmpty()) { StatEdge endedge = ifstat.getAllSuccessorEdges().get(0);
statement.setExprents(data); if (statement.getAllSuccessorEdges().isEmpty()) { StatEdge ifEdge = ifStatement.getAllSuccessorEdges().get(0); StatEdge edge = new StatEdge(ifEdge.getType(), statement, ifEdge.getDestination());
ifstat.removeSuccessor(ifstat.getAllSuccessorEdges().get(0)); // remove 'else' edge
StatEdge edge = stat.getAllSuccessorEdges().get(0); Statement elsechild = edge.getDestination(); IfNode elsenode = new IfNode(elsechild);
if (lastif.iftype == IfStatement.IFTYPE_IF && lastif.getIfstat() == null) { StatEdge ifedge = lastif.getIfEdge(); StatEdge elseedge = lastif.getAllSuccessorEdges().get(0);
hasDirectEndEdge(last, from); if (!noelsestat && existsPath(ifstat, ifstat.getAllSuccessorEdges().get(0).getDestination())) { return false; ifstat.removeSuccessor(ifstat.getAllSuccessorEdges().get(0)); for (Statement st : lst) { sequence.getStats().removeWithKey(st.id); StatEdge elseedge = ifstat.getAllSuccessorEdges().get(0); ifstat.removeSuccessor(ifstat.getAllSuccessorEdges().get(0)); for (Statement st : lst) { sequence.getStats().removeWithKey(st.id);
firstif.removeSuccessor(firstif.getAllSuccessorEdges().get(0)); StatEdge elseedge = firstif.getAllSuccessorEdges().get(0); if (isDirectPath(stat, elseedge.getDestination())) {
private static boolean extractLastIf(DoStatement stat) { // search for an if condition at the end of the loop Statement last = stat.getFirst(); while (last.type == Statement.TYPE_SEQUENCE) { last = last.getStats().getLast(); } if (last.type == Statement.TYPE_IF) { IfStatement lastif = (IfStatement)last; if (lastif.iftype == IfStatement.IFTYPE_IF && lastif.getIfstat() != null) { Statement ifstat = lastif.getIfstat(); StatEdge elseedge = lastif.getAllSuccessorEdges().get(0); if (elseedge.getType() == StatEdge.TYPE_CONTINUE && elseedge.closure == stat) { Set<Statement> set = stat.getNeighboursSet(StatEdge.TYPE_CONTINUE, Statement.DIRECTION_BACKWARD); set.remove(last); if (set.isEmpty()) { // no direct continues in a do{}while loop if (isExternStatement(stat, ifstat, ifstat)) { extractIfBlock(stat, lastif); return true; } } } } } return false; }
StatEdge ifedge = ifchild.getAllSuccessorEdges().get(0);
ifchild.removeSuccessor(ifchild.getAllSuccessorEdges().get(0)); ifparent.getStats().removeWithKey(ifchild.id);
ifelsestat.setElsestat(null); if (ifelsestat.getAllSuccessorEdges().isEmpty() && !ifstat.getAllSuccessorEdges().isEmpty()) { StatEdge endedge = ifstat.getAllSuccessorEdges().get(0);
stif.setExprents(data); if (stif.getAllSuccessorEdges().isEmpty()) { StatEdge ifedge = ifstat.getAllSuccessorEdges().get(0); StatEdge edge = new StatEdge(ifedge.getType(), stif, ifedge.getDestination());
ifstat.removeSuccessor(ifstat.getAllSuccessorEdges().get(0)); // remove 'else' edge
StatEdge edge = stat.getAllSuccessorEdges().get(0); Statement elsechild = edge.getDestination(); IfNode elsenode = new IfNode(elsechild);
if (lastif.iftype == IfStatement.IFTYPE_IF && lastif.getIfstat() == null) { StatEdge ifedge = lastif.getIfEdge(); StatEdge elseedge = lastif.getAllSuccessorEdges().get(0);
if (!noelsestat && existsPath(ifstat, ifstat.getAllSuccessorEdges().get(0).getDestination())) { return false; ifstat.removeSuccessor(ifstat.getAllSuccessorEdges().get(0)); for (Statement st : lst) { sequence.getStats().removeWithKey(st.id); StatEdge elseedge = ifstat.getAllSuccessorEdges().get(0); ifstat.removeSuccessor(ifstat.getAllSuccessorEdges().get(0)); for (Statement st : lst) { sequence.getStats().removeWithKey(st.id);
firstif.removeSuccessor(firstif.getAllSuccessorEdges().get(0)); StatEdge elseedge = firstif.getAllSuccessorEdges().get(0); if (isDirectPath(stat, elseedge.getDestination())) {