@Override public void applyReductionImpl() { firstLoop.setCondition(secondLoop.getCondition()); enclosingBlock.removeStmt(secondLoop); final String splitLoopCounter = ((DeclarationStmt) firstLoop.getInit()) .getVariablesDeclaration().getDeclInfo(0).getName(); int originalNameBeginIndex = Constants.SPLIT_LOOP_COUNTER_PREFIX.length(); assert Character.isDigit(splitLoopCounter.charAt(originalNameBeginIndex)); while (Character.isDigit(splitLoopCounter.charAt(originalNameBeginIndex))) { originalNameBeginIndex++; } final String mergedLoopCounter = splitLoopCounter.substring(originalNameBeginIndex); ReplaceLoopCounter.replaceLoopCounter(firstLoop, splitLoopCounter, mergedLoopCounter); }
@Override public void applyReductionImpl() { for (int i = 0; i < blockStmt.getNumStmts(); i++) { if (child == blockStmt.getStmt(i)) { blockStmt.removeStmt(i); return; } } throw new FailedReductionException("Should be unreachable."); }
@Override public void applyReductionImpl() { try { Stmt parent = (Stmt) parentMap.getParent(wrapper); if (parent instanceof BlockStmt) { final BlockStmt parentBlock = (BlockStmt) parent; if (!parentBlock.getStmts().contains(wrapper)) { throw new ChildDoesNotExistException(wrapper, parentBlock); } for (Stmt stmt : wrapees) { parentBlock.insertBefore(wrapper, stmt); } parentBlock.removeStmt(wrapper); } else { parent.replaceChild(wrapper, wrapees.size() == 1 ? wrapees.get(0) : new BlockStmt(wrapees, true)); } } catch (ChildDoesNotExistException exception) { // TODO: it would be cleaner to capture this in the precondition. // The wrapper has already been eliminated // by some other reduction opportunity } }
@Override public void visitFunctionCallExpr(FunctionCallExpr functionCallExpr) { super.visitFunctionCallExpr(functionCallExpr); if (functionCallExpr != call) { return; } if (currentBlockStmt == null) { // Cannot inline e.g. at global scope return; } currentBlockStmt.insertStmt(currentIndex, new BlockStmt(inlinedStmts, true)); if (returnVariableName.isPresent()) { currentBlockStmt.insertStmt(currentIndex, new DeclarationStmt( new VariablesDeclaration( clonedFunctionDefinition.getPrototype().getReturnType() .getWithoutQualifiers(), new VariableDeclInfo(returnVariableName.get(), null, null)))); parentMap.getParent(functionCallExpr).replaceChild(functionCallExpr, new VariableIdentifierExpr(returnVariableName.get())); } else { assert clonedFunctionDefinition.getPrototype().getReturnType().getWithoutQualifiers() == VoidType.VOID; assert parentMap.getParent(functionCallExpr) instanceof ExprStmt; currentBlockStmt.removeStmt((Stmt) parentMap.getParent(functionCallExpr)); } } }.visit(tu);