/** * Inserts a node after this sequential node and its successor. This method will rewire the nodes to keep the graph * consistent. It will do the following: * <ol> * <li>Remove the connection between this node and its successor.</li> * <li>Add a bi-directional connection between this node and the new node.</li> * <li>Add a bi-directional connection between the new node and this nodes old successor.</li> * </ol> * * @param newNode The new node that should be inserted in the control flow after this one. */ public void insertAfter(SequentialNode newNode) { Node oldSuccessor = successor; successor = newNode; newNode.addPredecessor(this); if (oldSuccessor != null) { newNode.successor = oldSuccessor; oldSuccessor.removePredecessor(this); oldSuccessor.addPredecessor(newNode); } }
/** * Removes the nodes given by <code>list</code> from the control flow graph and rewires them to be a sequence of * separate nodes, e.g. in the body of an if-statement. The first node has <code>base</code> as predecessor. For the * last node in the list, base's successor will be set as successor, e.g. the first statement after an if-then-else * statement. * * @param list list of nodes from a block * @param base basis of block, e.g. an if-statement */ private void rewireNodes(List<SequentialNode> list, SequentialNode base) { if (list == null || list.size() == 0) { return; } Iterator<SequentialNode> it = list.iterator(); SequentialNode current = it.next(); graph.removeNode(current); current.addPredecessor(base); // first node has if-then-else node as predecessor while (it.hasNext()) { SequentialNode next = it.next(); graph.removeNode(next); current.replaceSuccessor(current.getSuccessor(), next); // could be redundant next.addPredecessor(current); current = next; } current.replaceSuccessor(current.getSuccessor(), new BlockEndNode(graph, base)); // mark the end of this block }
/** * Removes the nodes given by <code>list</code> from the control flow graph and rewires them to be a sequence of separate * nodes, e.g. in the body of an if-statement. The first node has <code>base</code> as predecessor. For the last node in the * list, base's successor will be set as successor, e.g. the first statement after an if-then-else statement. * * @param list list of nodes from a block * @param base basis of block, e.g. an if-statement */ private void rewireNodes(List<SequentialNode> list, IfThenElseNode base) { if (list == null || list.size() == 0) { return; } Iterator<SequentialNode> it = list.iterator(); SequentialNode current = it.next(); graph.removeNode(current); current.addPredecessor(base); // first node has if-then-else node as predecessor while (it.hasNext()) { SequentialNode next = it.next(); graph.removeNode(next); current.replaceSuccessor(current.getSuccessor(), next); // could be redundant next.addPredecessor(current); current = next; } current.replaceSuccessor(current.getSuccessor(), new BlockEndNode(graph, current)); // mark the end of this block }
/** * Removes the nodes given by <code>list</code> from the control flow graph and rewires them to be a sequence of * separate nodes, e.g. in the body of an if-statement. The first node has <code>base</code> as predecessor. For the * last node in the list, base's successor will be set as successor, e.g. the first statement after an if-then-else * statement. * * @param list list of nodes from a block * @param base basis of block, e.g. an if-statement */ private void rewireNodes(List<SequentialNode> list, SequentialNode base) { if (list == null || list.size() == 0) { return; } Iterator<SequentialNode> it = list.iterator(); SequentialNode current = it.next(); graph.removeNode(current); current.addPredecessor(base); // first node has if-then-else node as predecessor while (it.hasNext()) { SequentialNode next = it.next(); graph.removeNode(next); current.replaceSuccessor(current.getSuccessor(), next); // could be redundant next.addPredecessor(current); current = next; } current.replaceSuccessor(current.getSuccessor(), new BlockEndNode(graph, base)); // mark the end of this block }
/** * Makes a deep copy of this node using the same predecessors and successor as the original. Depending on the * subtype, more properties are copied according to the {@link #copyElements()} method. * * @return a copy of this node with same predecessors and successors */ public SequentialNode copy() { SequentialNode copy = copyElements(); copy.setSuccessor(successor); for (Node p : getPredecessors()) { copy.addPredecessor(p); } return copy; } }
@Override public IfThenElseNode copyElements() { IfThenElseNode copy = new IfThenElseNode(getGraph(), condition.copy()); copy.elseif = elseif; SequentialNode newPositive = positive.copy(); newPositive.removePredecessor(this); newPositive.addPredecessor(copy); copy.setPositive(newPositive); copySubtree(newPositive, copy); SequentialNode newNegative = negative.copy(); newNegative.removePredecessor(this); newNegative.addPredecessor(copy); copy.setNegative(newNegative); copySubtree(newNegative, copy); return copy; }
@Override public LoopNode copyElements() { LoopNode copy = new LoopNode(getGraph()); copy.setIterations(iterations); copy.setCounterVariable(counter); SequentialNode newBody = body.copy(); newBody.removePredecessor(this); newBody.addPredecessor(copy); copy.setBody(newBody); copySubtree(newBody, copy); return copy; }