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) )); } }
private ArrayInfo getArrayInfo(Array_specifierContext arraySpecifierContext) { if (arraySpecifierContext.array_specifier() != null) { throw new RuntimeException("Not yet supporting multi-dimmensional arrays"); } if (arraySpecifierContext.constant_expression() == null) { // An array with unspecified length. return new ArrayInfo(); } final Expr expr = (Expr) visit(arraySpecifierContext.constant_expression()); if (expr instanceof IntConstantExpr) { return new ArrayInfo(Integer.parseInt(((IntConstantExpr) expr).getValue())); } throw new RuntimeException("Unable to construct array info for array with size " + expr.getText()); }
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)); }