private Set<FunctionPrototype> findPossibleMatchesForCall(FunctionCallExpr functionCallExpr) { Set<FunctionPrototype> candidates = declaredFunctions.stream() .filter(proto -> proto.getName().equals(functionCallExpr.getCallee())) .filter(proto -> proto.getNumParameters() == functionCallExpr.getNumArgs()) .collect(Collectors.toSet()); for (int i = 0; i < functionCallExpr.getNumArgs(); i++) { if (!typer.hasType(functionCallExpr.getArg(i))) { // If we don't have a type for this argument, we're OK with any function prototype's type continue; } final int currentIndex = i; // Capture i in final variable so it can be used in lambda. candidates = candidates.stream().filter(proto -> typer.lookupType(functionCallExpr.getArg(currentIndex)).getWithoutQualifiers() .equals(proto.getParameters().get(currentIndex).getType().getWithoutQualifiers())) .collect(Collectors.toSet()); } return candidates; }
static Expr makeWrappedIfCondition(Expr expr, boolean truth) { return new FunctionCallExpr(truth ? Constants.GLF_WRAPPED_IF_TRUE : Constants.GLF_WRAPPED_IF_FALSE, expr); }
@Override public Expr getChild(int index) { if (index < 0 || index >= getNumArgs()) { throw new IndexOutOfBoundsException("FunctionCallExpr has no child at index " + index); } return getArg(index); }
private static boolean isCallToNamedFunction(Expr expr, String functionName) { return expr instanceof FunctionCallExpr && ((FunctionCallExpr) expr).getCallee() .equals(functionName); }
@Override public void visitFunctionCallExpr(FunctionCallExpr functionCallExpr) { super.visitFunctionCallExpr(functionCallExpr); for (int i = 0; i < functionCallExpr.getNumArgs(); i++) { Expr arg = functionCallExpr.getArg(i); if (arg instanceof VariableIdentifierExpr && ((VariableIdentifierExpr) arg) .getName().equals(declaration.getVariablesDeclaration().getDeclInfo(0).getName())) { functionCallExpr.setArg(i, new VariableIdentifierExpr(originalVariableInfo.getName())); } } }
@Override public void visitFunctionCallExpr(FunctionCallExpr functionCallExpr) { super.visitFunctionCallExpr(functionCallExpr); if (functionCallExpr.getCallee().equals(functionDefinition.getPrototype().getName())) { // As we only apply this reduction opportunity if the function name is not overloaded, // this has to be a call to the relevant function. functionCallExpr.removeArg(paramIndex); } }
private Expr extractExpr(Expr exprToReduce) { switch (function) { case FALSE: assert MacroNames.isFalse(exprToReduce); break; case IDENTITY: assert MacroNames.isIdentity(exprToReduce); break; case ONE: assert MacroNames.isOne(exprToReduce); break; case TRUE: assert MacroNames.isTrue(exprToReduce); break; case ZERO: assert MacroNames.isZero(exprToReduce); break; default: throw new FailedReductionException("Unknown mutation"); } return ((FunctionCallExpr) exprToReduce).getArg(0); }
@Override public int getNumChildren() { return getNumArgs(); }
@Override public void visitFunctionCallExpr(FunctionCallExpr functionCallExpr) { for (Expr arg : functionCallExpr.getArgs()) { visitChildFromParent(arg, functionCallExpr); } }
private boolean callMatchesPrototype(FunctionCallExpr call, FunctionPrototype prototype) { assert call.getNumArgs() == prototype.getNumParameters(); for (int i = 0; i < call.getNumArgs(); i++) { Type argType = typer.lookupType(call.getArg(i)); if (argType == null) { // With incomplete information we say there is a match continue; } if (!typesMatchWithoutQualifiers(argType, prototype.getParameters().get(i).getType())) { return false; } } return true; }
@Override public void applyReductionImpl() { final BinaryExpr assignment = (BinaryExpr) stmt.getExpr(); final Expr expr = ((ReturnStmt) outlined.getBody().getStmt(0)).getExpr().clone(); Map<String, Expr> paramReplacement = new HashMap<>(); for (int i = 0; i < outlined.getPrototype().getNumParameters(); i++) { Expr actualParam = ((FunctionCallExpr) assignment.getRhs()).getArg(i); assert actualParam != null; paramReplacement.put(outlined.getPrototype().getParameter(i).getName(), actualParam); } assert assignment.getOp() == BinOp.ASSIGN; stmt.setExpr(new BinaryExpr(assignment.getLhs(), applySubstitutionDestructive(expr, paramReplacement), BinOp.ASSIGN)); }
@Override public void setChild(int index, Expr expr) { if (index < 0 || index >= getNumArgs()) { throw new IndexOutOfBoundsException("FunctionCallExpr has no child at index " + index); } args.set(index, expr); }
.getArgs() .indexOf(child); for (FunctionPrototype fp : getEncounteredFunctionPrototypes().stream()
private boolean functionMatches(FunctionDefinition declaration) { final FunctionPrototype prototype = declaration.getPrototype(); if (!prototype.getName().equals(call.getCallee())) { return false; } if (prototype.getNumParameters() != call.getNumArgs()) { return false; } for (int i = 0; i < prototype.getNumParameters(); i++) { if (typer.lookupType(call.getArg(i)) == null) { continue; } if (!typer.lookupType(call.getArg(i)).getWithoutQualifiers() .equals(prototype.getParameter(i).getType().getWithoutQualifiers())) { return false; } } return true; }
@Override public void visitFunctionCallExpr(FunctionCallExpr functionCallExpr) { super.visitFunctionCallExpr(functionCallExpr); calledFunctions.add(functionCallExpr.getCallee()); }
if (prototype.getNumParameters() != functionCallExpr.getNumArgs()) { return false; Type argType = lookupType(functionCallExpr.getArg(i)); if (argType == null) { return false;