/** * 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; }
loop.setIterations(Integer.parseInt(iterations));
@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; }