private boolean incompatibleReturnTypes(FunctionDefinition f1, FunctionDefinition f2) { return !f1.getPrototype().getReturnType().equals(f2.getPrototype().getReturnType()); }
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 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()); }
private Stmt fuzzReturnStmt() { return new ReturnStmt( fuzzExpr(fuzzingContext.getEnclosingFunction().getReturnType(), false, false, 0)); }
@Override public void visitFunctionCallExpr(FunctionCallExpr functionCallExpr) { super.visitFunctionCallExpr(functionCallExpr); List<FunctionPrototype> candidateBuiltins = TyperHelper.getBuiltins(shadingLanguageVersion) .get(functionCallExpr.getCallee()); if (candidateBuiltins != null) { for (FunctionPrototype prototype : candidateBuiltins) { if (prototypeMatches(prototype, functionCallExpr)) { types.put(functionCallExpr, prototype.getReturnType()); } } } Set<FunctionPrototype> candidateUserDefined = userDefinedFunctions.get(functionCallExpr.getCallee()); if (candidateUserDefined != null) { for (FunctionPrototype prototype : candidateUserDefined) { if (prototypeMatches(prototype, functionCallExpr)) { types.put(functionCallExpr, prototype.getReturnType()); } } } }
@Override public void visitFunctionPrototype(FunctionPrototype functionPrototype) { for (int i = 0; i < functionPrototype.getNumParameters(); i++) { visitChildFromParent(functionPrototype.getParameters().get(i), functionPrototype); } visitChildFromParent(functionPrototype.getReturnType(), functionPrototype); }
/** * 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; }
private IfStmt prepareReturnStmt(IInjectionPoint injectionPoint, IRandom generator, ShadingLanguageVersion shadingLanguageVersion, GenerationParams generationParams) { Type returnType = injectionPoint.getEnclosingFunction().getPrototype().getReturnType(); Stmt stmtToInject; if (returnType.hasCanonicalConstant()) { stmtToInject = new ReturnStmt(returnType.getCanonicalConstant()); } else if (returnType.getWithoutQualifiers() == VoidType.VOID) { stmtToInject = new ReturnStmt(); } else { stmtToInject = new BlockStmt(new ArrayList<>(), true); } return makeDeadConditional(injectionPoint, stmtToInject, generator, shadingLanguageVersion, generationParams); }
@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);
= clonedFunctionDefinition.getPrototype().getReturnType().getWithoutQualifiers() == VoidType.VOID ? Optional.empty() : Optional.of(call.getCallee() + "_inline_return_value_"
private void addSpecialDeclarations() { if (fd.getPrototype().getReturnType().getWithoutQualifiers() != VoidType.VOID) { fd.getBody().insertStmt(0, new DeclarationStmt( new VariablesDeclaration(fd.getPrototype().getReturnType().getWithoutQualifiers(), new VariableDeclInfo(makeReturnValueName(), null, null)))); fd.getBody().addStmt(new ReturnStmt(makeReturnValue())); } fd.getBody().insertStmt(0, new DeclarationStmt( new VariablesDeclaration(BasicType.BOOL, new VariableDeclInfo(makeHasReturnedName(), null, new ScalarInitializer(BoolConstantExpr.FALSE))))); }