private static void resetAllEdges(Statement stat) { for (Statement st : stat.getStats()) { resetAllEdges(st); } for (StatEdge edge : stat.getAllSuccessorEdges()) { edge.explicit = true; edge.labeled = true; } }
public void removeAllSuccessors(Statement stat) { if (stat == null) { return; } for (StatEdge edge : getAllSuccessorEdges()) { if (edge.getDestination() == stat) { removeSuccessor(edge); } } }
private static void addToReversePostOrderListIterative(Statement root, List<Statement> lst) { LinkedList<Statement> stackNode = new LinkedList<>(); LinkedList<Integer> stackIndex = new LinkedList<>(); HashSet<Statement> setVisited = new HashSet<>(); stackNode.add(root); stackIndex.add(0); while (!stackNode.isEmpty()) { Statement node = stackNode.getLast(); int index = stackIndex.removeLast(); setVisited.add(node); List<StatEdge> lstEdges = node.getAllSuccessorEdges(); for (; index < lstEdges.size(); index++) { StatEdge edge = lstEdges.get(index); Statement succ = edge.getDestination(); if (!setVisited.contains(succ) && (edge.getType() == StatEdge.TYPE_REGULAR || edge.getType() == StatEdge.TYPE_EXCEPTION)) { // TODO: edge filter? stackIndex.add(index + 1); stackNode.add(succ); stackIndex.add(0); break; } } if (index == lstEdges.size()) { lst.add(0, node); stackNode.removeLast(); } } }
private void calcReachabilitySuppPoints(final int edgetype) { iterateReachability((node, mapSets) -> { // consider to be a support point for (StatEdge sucedge : node.getAllSuccessorEdges()) { if ((sucedge.getType() & edgetype) != 0) { if (mapSets.containsKey(sucedge.getDestination().id)) { FastFixedSet<Integer> setReachability = mapSets.get(node.id); if (!InterpreterUtil.equalObjects(setReachability, mapSupportPoints.get(node.id))) { mapSupportPoints.put(node.id, setReachability); return true; } } } } return false; }, edgetype); }
private static void hideDefaultSwitchEdges(Statement stat) { if (stat.type == Statement.TYPE_SWITCH) { SwitchStatement swst = (SwitchStatement)stat; int last = swst.getCaseStatements().size() - 1; if (last >= 0) { // empty switch possible Statement stlast = swst.getCaseStatements().get(last); if (stlast.getExprents() != null && stlast.getExprents().isEmpty()) { if (!stlast.getAllSuccessorEdges().get(0).explicit) { List<StatEdge> lstEdges = swst.getCaseEdges().get(last); lstEdges.remove(swst.getDefault_edge()); if (lstEdges.isEmpty()) { swst.getCaseStatements().remove(last); swst.getCaseEdges().remove(last); } } } } } for (Statement st : stat.getStats()) { hideDefaultSwitchEdges(st); } }
private static boolean isSequenceDisbandable(Statement block, Statement next) { Statement last = block.getStats().getLast(); List<StatEdge> lstSuccs = last.getAllSuccessorEdges(); if (!lstSuccs.isEmpty()) { if (lstSuccs.get(0).getDestination() != next) { return false; } } for (StatEdge edge : next.getPredecessorEdges(StatEdge.TYPE_BREAK)) { if (last != edge.getSource() && !last.containsStatementStrict(edge.getSource())) { return false; } } return true; }
stnext = stnext.getAllSuccessorEdges().get(0).getDestination();
public static void destroyStatementContent(Statement stat, boolean self) { for (Statement st : stat.getStats()) { destroyStatementContent(st, true); } stat.getStats().clear(); if (self) { for (StatEdge edge : stat.getAllSuccessorEdges()) { stat.removeSuccessor(edge); } } } }
private static void liftClosures(Statement stat) { for (StatEdge edge : stat.getAllSuccessorEdges()) { switch (edge.getType()) { case StatEdge.TYPE_CONTINUE:
for (StatEdge sucedge : pred.getAllSuccessorEdges()) { if ((sucedge.getType() & edgetype) != 0) { if (!mapSets.containsKey(sucedge.getDestination().id)) {
private static boolean isExternStatement(DoStatement loop, Statement block, Statement stat) { for (StatEdge edge : stat.getAllSuccessorEdges()) { if (loop.containsStatement(edge.getDestination()) && !block.containsStatement(edge.getDestination())) { return false; } } for (Statement st : stat.getStats()) { if (!isExternStatement(loop, block, st)) { return false; } } return true; }
private static boolean noExitLabels(Statement block, Statement sequence) { for (StatEdge edge : block.getAllSuccessorEdges()) { if (edge.getType() != StatEdge.TYPE_REGULAR && edge.getDestination().type != Statement.TYPE_DUMMYEXIT) { if (!sequence.containsStatementStrict(edge.getDestination())) { return false; } } } for (Statement st : block.getStats()) { if (!noExitLabels(st, sequence)) { return false; } } return true; }
ifstat.getExprents().isEmpty() && (ifstat.getAllSuccessorEdges().isEmpty() || !ifstat.getAllSuccessorEdges().get(0).explicit)) { ifelsestat.setElsestat(null); if (ifelsestat.getAllSuccessorEdges().isEmpty() && !ifstat.getAllSuccessorEdges().isEmpty()) { StatEdge endedge = ifstat.getAllSuccessorEdges().get(0);
ifinner.setParent(ifparent); if (!ifinner.getAllSuccessorEdges().isEmpty()) { StatEdge edge = ifinner.getAllSuccessorEdges().get(0); if (edge.closure == ifchild) { edge.closure = null;
private static void removeParameterCheck(Statement stat) { Statement st = stat.getFirst(); while (st.type == Statement.TYPE_SEQUENCE) { st = st.getFirst(); } IfStatement ifstat = (IfStatement)st; if (ifstat.getElsestat() != null) { // if - else StatEdge ifedge = ifstat.getIfEdge(); StatEdge elseedge = ifstat.getElseEdge(); Statement ifbranch = ifstat.getIfstat(); Statement elsebranch = ifstat.getElsestat(); ifstat.getFirst().removeSuccessor(ifedge); ifstat.getFirst().removeSuccessor(elseedge); ifstat.getStats().removeWithKey(ifbranch.id); ifstat.getStats().removeWithKey(elsebranch.id); if (!ifbranch.getAllSuccessorEdges().isEmpty()) { ifbranch.removeSuccessor(ifbranch.getAllSuccessorEdges().get(0)); } ifstat.getParent().replaceStatement(ifstat, elsebranch); ifstat.getParent().setAllParent(); } }
if (!ifchild.getAllSuccessorEdges().isEmpty()) { ifnode.addChild(new IfNode(ifchild.getAllSuccessorEdges().get(0).getDestination()), 1); if (!elsechild.getAllSuccessorEdges().isEmpty()) { elsenode.addChild(new IfNode(elsechild.getAllSuccessorEdges().get(0).getDestination()), 1);
for (StatEdge edge : oldstat.getAllSuccessorEdges()) { oldstat.removeSuccessor(edge); edge.setSource(newstat);
if (st.getAllSuccessorEdges().isEmpty()) { List<StatEdge> lstBreaks = st.getPredecessorEdges(StatEdge.TYPE_BREAK); StatEdge sucedge = st.getAllSuccessorEdges().get(0); if (sucedge.getType() != StatEdge.TYPE_FINALLYEXIT) { st.removeSuccessor(sucedge);
pre.removeSuccessor(pre.getAllSuccessorEdges().get(0)); // single regular edge
private static boolean hasDirectEndEdge(Statement stat, Statement from) { for (StatEdge edge : stat.getAllSuccessorEdges()) { if (MergeHelper.isDirectPath(from, edge.getDestination())) { return true;