@Test public void testNothingToReplace() throws Exception { final String program = "#version 130\n" + "int foo(vec3 p, vec2 t) {" + " ivec2 q = ivec2(0);" + " return 0;" + "}" + "void main() { }"; final TranslationUnit tu = ParseHelper.parse(program); final PipelineInfo pipelineInfo = new PipelineInfo(); FloatLiteralReplacer.replace(tu, pipelineInfo); final String expectedProgram = "#version 130\n" + "int foo(vec3 p, vec2 t) {" + " ivec2 q = ivec2(0);" + " return 0;" + "}" + "void main() { }"; CompareAsts.assertEqualAsts(expectedProgram, tu); }
public static void replace(TranslationUnit tu, PipelineInfo pipelineInfo) { FloatLiteralReplacer floatLiteralReplacer = new FloatLiteralReplacer(tu); ConstCleaner.clean(tu); List<Float> literals = new ArrayList<>(); for (int i = 0; i < floatLiteralReplacer.uniformIndex; i++) { literals.add(null); } for (String s : floatLiteralReplacer.literalToUniformIndex.keySet()) { assert literals.get(floatLiteralReplacer.literalToUniformIndex.get(s)) == null; literals.set(floatLiteralReplacer.literalToUniformIndex.get(s), new Float(s)); } if (literals.size() > 0) { pipelineInfo.addUniform(Constants.FLOAT_CONST, BasicType.FLOAT, Optional.of(literals.size()), literals); } }
FloatLiteralReplacer extends StandardVisitor { public static void replace(TranslationUnit tu, PipelineInfo pipelineInfo) { FloatLiteralReplacer floatLiteralReplacer = new FloatLiteralReplacer(tu); ConstCleaner.clean(tu); List<Float> literals = new ArrayList<>(); for (int i = 0; i < floatLiteralReplacer.uniformIndex; i++) { literals.add(null); } for (String s : floatLiteralReplacer.literalToUniformIndex.keySet()) { assert literals.get(floatLiteralReplacer.literalToUniformIndex.get(s)) == null; literals.set(floatLiteralReplacer.literalToUniformIndex.get(s), new Float(s)); } if (literals.size() > 0) { pipelineInfo.addUniform(Constants.FLOAT_CONST, BasicType.FLOAT, Optional.of(literals.size()), literals); } } }
FloatLiteralReplacer extends StandardVisitor { public static void replace(TranslationUnit tu, PipelineInfo pipelineInfo) { FloatLiteralReplacer floatLiteralReplacer = new FloatLiteralReplacer(tu); ConstCleaner.clean(tu); List<Float> literals = new ArrayList<>(); for (int i = 0; i < floatLiteralReplacer.uniformIndex; i++) { literals.add(null); } for (String s : floatLiteralReplacer.literalToUniformIndex.keySet()) { assert literals.get(floatLiteralReplacer.literalToUniformIndex.get(s)) == null; literals.set(floatLiteralReplacer.literalToUniformIndex.get(s), new Float(s)); } if (literals.size() > 0) { pipelineInfo.addUniform(Constants.FLOAT_CONST, BasicType.FLOAT, Optional.of(literals.size()), literals); } } private  FloatLiteralReplacer(TranslationUnit tu); }
FloatLiteralReplacer extends StandardVisitor { public static void replace(TranslationUnit tu, PipelineInfo pipelineInfo) { FloatLiteralReplacer floatLiteralReplacer = new FloatLiteralReplacer(tu); ConstCleaner.clean(tu); List<Float> literals = new ArrayList<>(); for (int i = 0; i < floatLiteralReplacer.uniformIndex; i++) { literals.add(null); } for (String s : floatLiteralReplacer.literalToUniformIndex.keySet()) { assert literals.get(floatLiteralReplacer.literalToUniformIndex.get(s)) == null; literals.set(floatLiteralReplacer.literalToUniformIndex.get(s), new Float(s)); } if (literals.size() > 0) { pipelineInfo.addUniform(Constants.FLOAT_CONST, BasicType.FLOAT, Optional.of(literals.size()), literals); } } private  FloatLiteralReplacer(TranslationUnit tu); static void replace(TranslationUnit tu, PipelineInfo pipelineInfo); @Override void visitFloatConstantExpr(FloatConstantExpr floatConstantExpr); }
FloatLiteralReplacer extends StandardVisitor { public static void replace(TranslationUnit tu, PipelineInfo pipelineInfo) { FloatLiteralReplacer floatLiteralReplacer = new FloatLiteralReplacer(tu); ConstCleaner.clean(tu); List<Float> literals = new ArrayList<>(); for (int i = 0; i < floatLiteralReplacer.uniformIndex; i++) { literals.add(null); } for (String s : floatLiteralReplacer.literalToUniformIndex.keySet()) { assert literals.get(floatLiteralReplacer.literalToUniformIndex.get(s)) == null; literals.set(floatLiteralReplacer.literalToUniformIndex.get(s), new Float(s)); } if (literals.size() > 0) { pipelineInfo.addUniform(Constants.FLOAT_CONST, BasicType.FLOAT, Optional.of(literals.size()), literals); } } private  FloatLiteralReplacer(TranslationUnit tu); static void replace(TranslationUnit tu, PipelineInfo pipelineInfo); @Override void visitFloatConstantExpr(FloatConstantExpr floatConstantExpr);  }