@Override public VariablesDeclaration clone() { return new VariablesDeclaration(baseType.clone(), declInfos.stream().map(x -> x.clone()).collect(Collectors.toList())); }
private void addComponentVariableIfNotPresent() { if (getAllVariableDeclInfosInBlock() .stream() .anyMatch(item -> item.getName().equals(getComponentName()))) { return; } block.insertStmt(0, new DeclarationStmt(new VariablesDeclaration( getComponentType(), new VariableDeclInfo(getComponentName(), null, null)))); }
.add(new VariablesDeclaration(((VariablesDeclaration) d).getBaseType(), declInfo));
public static void addInjectionSwitchIfNotPresent(TranslationUnit tu) { if (alreadyDeclaresInjectionSwitch(tu)) { return; } tu.addDeclaration(new VariablesDeclaration(new QualifiedType(BasicType.VEC2, Arrays.asList(TypeQualifier.UNIFORM)), new VariableDeclInfo(Constants.INJECTION_SWITCH, null, null))); }
private VariablesDeclaration fuzzGlobal() { // TODO: extend to allow generation of multiple globals per declaration group // TODO: extend to fuzz initializers and array globals return new VariablesDeclaration(fuzzType(), new VariableDeclInfo("g" + freshId(), null, null)); }
private DeclarationStmt fuzzDeclarationStmt() { final Type baseType = fuzzType(); final int numDeclsInGroup = generator.nextPositiveInt(MAX_LOCALS_IN_DECL_GROUP); List<VariableDeclInfo> decls = new ArrayList<>(); for (int i = 0; i < numDeclsInGroup; i++) { final String name = createName("v"); ArrayInfo arrayInfo = null; if (generator.nextInt(10) < 3) { // TODO Hack for now, needs thought arrayInfo = new ArrayInfo(generator.nextPositiveInt(MAX_ARRAY_SIZE)); } fuzzingContext.addLocal(name, arrayInfo == null ? baseType : getType(baseType, arrayInfo)); decls.add(new VariableDeclInfo(name, arrayInfo, null)); // TODO: no initializer for now } return new DeclarationStmt(new VariablesDeclaration(baseType, decls)); }
public void apply() { if (blockAlreadyDeclaresVector()) { return; } for (ScopeEntry se : mergeSet.getIndidualScopeEntries()) { new VectorizerVisitor(se).visit(block); } block.insertStmt(0, new DeclarationStmt(new VariablesDeclaration( mergeSet.getMergedType(), new VariableDeclInfo(mergeSet.getMergedName(), null, null)))); }
private FloatLiteralReplacer(TranslationUnit tu) { parentMap = IParentMap.createParentMap(tu); uniformIndex = 0; literalToUniformIndex = new HashMap<>(); visit(tu); if (uniformIndex > 0) { tu.addDeclaration(new VariablesDeclaration( new QualifiedType(BasicType.FLOAT, Arrays.asList(TypeQualifier.UNIFORM)), new VariableDeclInfo(Constants.FLOAT_CONST, new ArrayInfo(uniformIndex), null) )); } }
new VariablesDeclaration(type, new VariableDeclInfo(vars.getKey(), null, initializer))));
private TranslationUnit prepareTranslationUnit(File donorFile, IRandom generator) throws IOException, ParseTimeoutException { TranslationUnit tu = ParseHelper.parse(donorFile); addPrefixes(tu, getDeclaredFunctionNames(tu)); // Add prefixed versions of these builtins, in case they are used tu.addDeclaration(new VariablesDeclaration( BasicType.VEC4, new VariableDeclInfo(addPrefix(OpenGlConstants.GL_FRAG_COORD), null, null))); tu.addDeclaration(new VariablesDeclaration( BasicType.VEC4, new VariableDeclInfo(addPrefix(OpenGlConstants.GL_FRAG_COLOR), null, null))); adaptTranslationUnitForSpecificDonation(tu, generator); translationUnitCount++; return tu; }
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))))); }
/** * This *mutator* method changes all occurrences of gl_FragColor to use the given name. * @param tu The translation unit to be mutated. * @param colorName The replacement name for gl_FragColor. */ public static void avoidDeprecatedGlFragColor(TranslationUnit tu, String colorName) { new AvoidDeprecatedGlFragColor(colorName).visit(tu); tu.addDeclaration(new VariablesDeclaration( new QualifiedType(BasicType.VEC4, Arrays.asList( new LayoutQualifier("location = 0"), TypeQualifier.SHADER_OUTPUT)), new VariableDeclInfo(colorName, null, null) )); }
newTopLevelDeclarations.add(new VariablesDeclaration( new QualifiedType(interfaceBlock.getMemberTypes().get(0).getWithoutQualifiers(), Arrays.asList(TypeQualifier.UNIFORM)),
withoutQualifiers, declInfo.getArrayInfo(), uniformsInfo.getArgs(uniformName))); final VariablesDeclaration newVariablesDeclaration = new VariablesDeclaration( withoutQualifiers, declInfo); variablesDeclaration.removeDeclInfo(i);
@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);
@Override public VariablesDeclaration visitInit_declarator_list(Init_declarator_listContext ctx) { List<VariableDeclInfo> declInfo = new LinkedList<>(); Init_declarator_listContext idl = ctx; while (idl.single_declaration() == null) { declInfo.add(0, processVarDeclInfo(idl.IDENTIFIER().getText(), idl.array_specifier(), idl.initializer())); idl = idl.init_declarator_list(); } Single_declarationContext sdc = idl.single_declaration(); if (sdc.IDENTIFIER() != null) { // Note: a struct declaration on its own is treated as a variables declaration with zero // identifiers. This seems to be the cleanest approach, since a struct declaration can // be followed by declaration of struct instances. declInfo.add(0, processVarDeclInfo(sdc.IDENTIFIER().getText(), sdc.array_specifier(), sdc.initializer())); } final Type baseType = visitFully_specified_type(sdc.fully_specified_type()); return new VariablesDeclaration(baseType, declInfo); }
private List<Stmt> getInlinedStmts(FunctionDefinition functionDefinition, Optional<String> returnVariableName) { final List<Stmt> inlinedStmts = new ArrayList<>(); for (int i = 0; i < functionDefinition.getPrototype().getNumParameters(); i++) { ParameterDecl pd = functionDefinition.getPrototype().getParameter(i); inlinedStmts.add(new DeclarationStmt( new VariablesDeclaration( pd.getType().getWithoutQualifiers(), new VariableDeclInfo(pd.getName(), null, new ScalarInitializer(call.getArg(i).clone()))))); } for (Stmt stmt : functionDefinition.getBody().getStmts()) { if (stmt instanceof ReturnStmt) { if (((ReturnStmt) stmt).hasExpr()) { inlinedStmts.add(new ExprStmt( new BinaryExpr( new VariableIdentifierExpr(returnVariableName.get()), (((ReturnStmt) stmt).getExpr()), BinOp.ASSIGN))); } } else { inlinedStmts.add(stmt); } } return inlinedStmts; }
new VariablesDeclaration(BasicType.INT, new VariableDeclInfo(limiterName, null, new ScalarInitializer(new IntConstantExpr("0")))));
stmts.add(new DeclarationStmt(new VariablesDeclaration( outputVariableType, new VariableDeclInfo(backupName, null, null))));
private Stmt makeSingleIterationForStmt(Stmt stmt, OpaqueExpressionGenerator opaqueExpressionGenerator, Fuzzer fuzzer, IRandom generator, ShadingLanguageVersion shadingLanguageVersion) { boolean up = generator.nextBoolean(); String loopVariableName = "_injected_loop_counter_" + loopVariableCounter; loopVariableCounter++; boolean loopBoundsMustBeConst = shadingLanguageVersion.restrictedForLoops(); Expr start = up ? opaqueExpressionGenerator .makeOpaqueZero(BasicType.INT, loopBoundsMustBeConst, 0, fuzzer) : opaqueExpressionGenerator .makeOpaqueOne(BasicType.INT, loopBoundsMustBeConst, 0, fuzzer); DeclarationStmt init = new DeclarationStmt(new VariablesDeclaration(BasicType.INT, new VariableDeclInfo(loopVariableName, null, new ScalarInitializer(start)))); Expr end = up ? opaqueExpressionGenerator .makeOpaqueOne(BasicType.INT, loopBoundsMustBeConst, 0, fuzzer) : opaqueExpressionGenerator .makeOpaqueZero(BasicType.INT, loopBoundsMustBeConst, 0, fuzzer); BinOp testOp = generator.nextBoolean() ? (up ? BinOp.LT : BinOp.GT) : BinOp.NE; Expr test = new BinaryExpr(new VariableIdentifierExpr(loopVariableName), end, testOp); UnOp incOp = up ? UnOp.POST_INC : UnOp.POST_DEC; Expr inc = new UnaryExpr(new VariableIdentifierExpr(loopVariableName), incOp); return new ForStmt(init, makeWrappedLoopCondition(test), inc, stmt); }