private static void addToPostReversePostOrderList( Statement stat, List<Statement> lst, HashSet<Statement> setVisited) { if (setVisited.contains( stat)) { // because of not considered exception edges, s. isExitComponent. Should be // rewritten, if possible. return; } setVisited.add(stat); for (StatEdge prededge : stat.getEdges(StatEdge.TYPE_REGULAR | StatEdge.TYPE_EXCEPTION, DIRECTION_BACKWARD)) { Statement pred = prededge.getSource(); if (!setVisited.contains(pred)) { addToPostReversePostOrderList(pred, lst, setVisited); } } lst.add(0, stat); }
public void collapseNodesToStatement(Statement stat) { Statement head = stat.getFirst(); Statement post = stat.getPost(); VBStyleCollection<Statement, Integer> setNodes = stat.getStats(); // post edges if (post != null) { for (StatEdge edge : post.getEdges(STATEDGE_DIRECT_ALL, DIRECTION_BACKWARD)) { if (stat.containsStatementStrict(edge.getSource())) { edge.getSource().changeEdgeType(DIRECTION_FORWARD, edge, StatEdge.TYPE_BREAK); stat.addLabeledEdge(edge); } } } // regular head edges for (StatEdge prededge : head.getAllPredecessorEdges()) { if (prededge.getType() != StatEdge.TYPE_EXCEPTION && stat.containsStatementStrict(prededge.getSource())) { prededge.getSource().changeEdgeType(DIRECTION_FORWARD, prededge, StatEdge.TYPE_CONTINUE); stat.addLabeledEdge(prededge); } head.removePredecessor(prededge); prededge.getSource().changeEdgeNode(DIRECTION_FORWARD, prededge, stat); stat.addPredecessor(prededge); } if (setNodes.containsKey(first.id)) { first = stat; } // exception edges Set<Statement> setHandlers = new HashSet<Statement>(head.getNeighbours(StatEdge.TYPE_EXCEPTION, DIRECTION_FORWARD)); for (Statement node : setNodes) { setHandlers.retainAll(node.getNeighbours(StatEdge.TYPE_EXCEPTION, DIRECTION_FORWARD)); } if (!setHandlers.isEmpty()) { for (StatEdge edge : head.getEdges(StatEdge.TYPE_EXCEPTION, DIRECTION_FORWARD)) { Statement handler = edge.getDestination(); if (setHandlers.contains(handler)) { if (!setNodes.containsKey(handler.id)) { stat.addSuccessor(new StatEdge(stat, handler, edge.getExceptions())); } } } for (Statement node : setNodes) { for (StatEdge edge : node.getEdges(StatEdge.TYPE_EXCEPTION, DIRECTION_FORWARD)) { if (setHandlers.contains(edge.getDestination())) { node.removeSuccessor(edge); } } } } if (post != null && !stat.getNeighbours(StatEdge.TYPE_EXCEPTION, DIRECTION_FORWARD) .contains(post)) { // TODO: second condition redundant? stat.addSuccessor(new StatEdge(StatEdge.TYPE_REGULAR, stat, post)); } // adjust statement collection for (Statement st : setNodes) { stats.removeWithKey(st.id); } stats.addWithKey(stat, stat.id); stat.setAllParent(); stat.setParent(this); stat.buildContinueSet(); // monitorenter and monitorexit stat.buildMonitorFlags(); if (stat.type == TYPE_SWITCH) { // special case switch, sorting leaf nodes ((SwitchStatement) stat).sortEdgesAndNodes(); } }