@Override public int getNumChildren() { return getNumArgs(); }
@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); }
@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 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; }
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; }
FunctionPrototype bestMatch = null; for (FunctionPrototype candidate : typer.getPrototypes(functionCallExpr.getCallee())) { if (candidate.getNumParameters() == functionCallExpr.getNumArgs()) { if (bestMatch == null || callMatchesPrototype(functionCallExpr, candidate)) { for (int i = 0; i < functionCallExpr.getNumArgs(); i++) { boolean isLValue = false; if (bestMatch != null) {
@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())); } } }
if (prototype.getNumParameters() != functionCallExpr.getNumArgs()) { return false;
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; }
switch (maybeFce.get().getCallee()) { case "sin": assert maybeFce.get().getNumArgs() == 1; if (isZeroFloat(maybeFce.get().getArg(0))) { addReplaceWithZero(parent, child); assert maybeFce.get().getNumArgs() == 1; if (isZeroFloat(maybeFce.get().getArg(0))) { addReplaceWithOne(parent, child);