@Override public boolean preconditionHolds() { return functionDefinition.getPrototype().getParameters().contains(parameterDecl); } }
@Override public void visitFunctionDefinition(FunctionDefinition functionDefinition) { assert unusedParametersForCurrentFunction == null; unusedParametersForCurrentFunction = new ArrayList<>(); unusedParametersForCurrentFunction.addAll(functionDefinition.getPrototype().getParameters()); super.visitFunctionDefinition(functionDefinition); functionsToUnusedParameters.put(functionDefinition, unusedParametersForCurrentFunction); unusedParametersForCurrentFunction = null; }
private boolean hasArrayParameter(FunctionDefinition functionDefinition) { return functionDefinition.getPrototype().getParameters().stream() .anyMatch(item -> item.getArrayInfo() != null); }
private boolean hasOutQualifier(FunctionDefinition functionDefinition) { return functionDefinition.getPrototype().getParameters().stream() .map(item -> item.getType()) .anyMatch(item -> item.hasQualifier(TypeQualifier.OUT_PARAM) || item.hasQualifier(TypeQualifier.INOUT_PARAM)); }
public FunctionCallExprTemplate(FunctionPrototype prototype) { this.name = prototype.getName(); this.resultType = prototype.getReturnType(); this.argTypes = new ArrayList<>(); for (ParameterDecl param : prototype.getParameters()) { assert param.getArrayInfo() == null; this.argTypes.add(param.getType()); } }
@Override void applyReductionImpl() { final int paramIndex = functionDefinition.getPrototype().getParameters().indexOf(parameterDecl); new StandardVisitor() { @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); } } @Override public void visitFunctionPrototype(FunctionPrototype functionPrototype) { super.visitFunctionPrototype(functionPrototype); if (functionPrototype.getName().equals(functionDefinition.getPrototype().getName())) { // As we only apply this reduction opportunity if the function name is not overloaded, // this has to be a prototype for the relevant function (there could be multiple identical // prototypes). functionPrototype.removeParameter(paramIndex); } } }.visit(translationUnit); }
@Override public void visitFunctionPrototype(FunctionPrototype functionPrototype) { visit(functionPrototype.getReturnType()); out.append(" " + functionPrototype.getName() + "("); boolean first = true; for (ParameterDecl p : functionPrototype.getParameters()) { if (!first) { out.append(", "); } first = false; visit(p); } out.append(")"); if (!inFunctionDefinition) { out.append(";"); } out.append(newLine()); }
@Override public void visitFunctionPrototype(FunctionPrototype functionPrototype) { for (int i = 0; i < functionPrototype.getNumParameters(); i++) { visitChildFromParent(functionPrototype.getParameters().get(i), functionPrototype); } visitChildFromParent(functionPrototype.getReturnType(), functionPrototype); }
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; }
/** * Return true if and only if this prototype and the given prototype have identical names, * return types, and argument types. * * @param functionPrototype The function prototype to be checked * @return true if and only if the prototypes match */ public boolean matches(FunctionPrototype functionPrototype) { if (!getName().equals(functionPrototype.getName())) { return false; } if (getNumParameters() != functionPrototype.getNumParameters()) { return false; } if (!getReturnType().equals(functionPrototype.getReturnType())) { return false; } for (int i = 0; i < getNumParameters(); i++) { if (!getParameters().get(i).getType().equals(functionPrototype.getParameters() .get(i).getType())) { return false; } } return true; }
/** * Return true if and only if this prototype and the given prototype match exactly, * except that they differ in return type or in type qualifiers of parameters. * Thus they are too similar to be overloads of one another, yet do not match * perfectly. * * @param functionPrototype The function prototype to be checked * @return true if and only if the prototypes clash */ public boolean clashes(FunctionPrototype functionPrototype) { if (matches(functionPrototype)) { return false; } if (!getName().equals(functionPrototype.getName())) { return false; } if (getNumParameters() != functionPrototype.getNumParameters()) { return false; } for (int i = 0; i < getNumParameters(); i++) { // If parameters differ after qualifier removal then there is no clash if (!getParameters().get(i).getType().getWithoutQualifiers().equals( functionPrototype.getParameters().get(i).getType().getWithoutQualifiers())) { return false; } } // We have two functions that do not match, yet have the same names and identical // parameter types once qualifiers are ignored. This is a clash. return true; }
assert prototype.getParameters().get(i).getArrayInfo() == null; if (!argType.getWithoutQualifiers() .equals(prototype.getParameters().get(i).getType().getWithoutQualifiers())) { return false;
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 visitFunctionPrototype(FunctionPrototype functionPrototype) { encounteredFunctionPrototypes.add(functionPrototype); for (ParameterDecl p : functionPrototype.getParameters()) { visitParameterDecl(p); if (addEncounteredParametersToScope) { if (p.getName() == null) { continue; } currentScope.add(p.getName(), p.getArrayInfo() == null ? p.getType() : new ArrayType(p.getType(), p.getArrayInfo()), Optional.of(p)); } } }
boolean isLValue = false; if (bestMatch != null) { Type argType = bestMatch.getParameters().get(i).getType(); if (argType instanceof QualifiedType) { QualifiedType qt = (QualifiedType) argType;