@Override public BlockEndNode copyElements() { return new BlockEndNode(getGraph(), null); }
@Override public void visit(BlockEndNode node) { node.getSuccessor().accept(this); }
@Override public void visit(BlockEndNode node) { SequentialNode base = node.getBase(); if (base instanceof LoopNode) { for (Node p : node.getPredecessors()) { if (idMap.containsKey(p)) { addForwardEdge(p, base); } } } else { addForwardEdge(base, base.getSuccessor()); } }
public IfThenElseNode handleIfStatement(Expression condition, List<SequentialNode> then_part, List<SequentialNode> else_part) { IfThenElseNode ifthenelse = new IfThenElseNode(graph, condition); addNode(ifthenelse); rewireNodes(then_part, ifthenelse); rewireNodes(else_part, ifthenelse); ifthenelse.setPositive(then_part.get(0)); ifthenelse.setNegative((else_part != null && else_part.size() > 0) ? else_part.get(0) : new BlockEndNode(graph, lastNode)); return ifthenelse; }
private void copySubtree(SequentialNode root, SequentialNode newBase) { if (root instanceof BlockEndNode) { ((BlockEndNode) root).updateBase(newBase); return; } else if (root.getSuccessor() instanceof SequentialNode) { SequentialNode successor = (SequentialNode) root.getSuccessor(); SequentialNode newSuccessor = successor.copy(); root.replaceSuccessor(successor, newSuccessor); copySubtree(newSuccessor, newBase); } }
@Override public void visit(BlockEndNode node) { output.println("BlockEndNode: "+node.toString()); super.visit(node); }
/** * Handles a loop statement. A CluCalc loop consists of a body of statements, typically containing the break * keyword. * * @param body list of statements belonging to body * @param iterations (optional) number of iterations for loop unrolling * @return new {@link LoopNode} representing this statement. */ public LoopNode handleLoop(List<SequentialNode> body, String iterations) { LoopNode loop = new LoopNode(graph); addNode(loop); rewireNodes(body, loop); loop.setBody((body != null && body.size() > 0) ? body.get(0) : new BlockEndNode(graph, loop)); // save number of iterations and reset value for next loops if (iterations != null) { loop.setIterations(Integer.parseInt(iterations)); } return loop; }
private void copySubtree(SequentialNode root, SequentialNode newBase) { if (root instanceof BlockEndNode) { ((BlockEndNode) root).updateBase(newBase); return; } else if (root.getSuccessor() instanceof SequentialNode) { SequentialNode successor = (SequentialNode) root.getSuccessor(); SequentialNode newSuccessor = successor.copy(); root.replaceSuccessor(successor, newSuccessor); copySubtree(newSuccessor, newBase); } }
/** * Handles an if statement. The statement consists of a condition expression, a mandatory then part (block) and an * optional else part. * * @param condition condition expression * @param then_part list of statements belonging to then part * @param else_part optional list of statements belonging to else part (empty list in case of no else part) * @return new {@link IfThenElseNode} representing this statement. */ public IfThenElseNode handleIfStatement(Expression condition, List<SequentialNode> then_part, List<SequentialNode> else_part) { IfThenElseNode ifthenelse = new IfThenElseNode(graph, condition); addNode(ifthenelse); rewireNodes(then_part, ifthenelse); rewireNodes(else_part, ifthenelse); ifthenelse.setPositive(then_part.get(0)); ifthenelse.setNegative((else_part != null && else_part.size() > 0) ? else_part.get(0) : new BlockEndNode(graph, ifthenelse)); return ifthenelse; }
@Override public void visit(BlockEndNode node) { node.getSuccessor().accept(this); }
/** * 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 }
@Override public void visit(BlockEndNode node) { node.getSuccessor().accept(this); }
/** * 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 }
@Override public void visit(BlockEndNode node) { node.getSuccessor().accept(this); }
/** * 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 }
@Override public void visit(BlockEndNode node) { node.getSuccessor().accept(this); }
addNode(loop); rewireNodes(body, loop); loop.setBody((body != null && body.size() > 0) ? body.get(0) : new BlockEndNode(graph, loop));
@Override //cfg public void visit(BlockEndNode node) { node.getSuccessor().accept(this); }