@Test public void unwrapFor() throws Exception { final String shader = "void main() {" + " int a;" + " for(_injected_loop_counter_0 = 0;" + " " + Constants.GLF_WRAPPED_LOOP + "(_injected_loop_counter_0 < 1);" + " _injected_loop_counter_0++) {" + " int a;" + " }" + "}"; final String expected = "void main() {" + " int a;" + " {" + " int a;" + " }" + "}"; final TranslationUnit tu = ParseHelper.parse(shader); final ShadingLanguageVersion version = ShadingLanguageVersion.ESSL_100; final RandomWrapper generator = new RandomWrapper(0); final IdGenerator idGenerator = new IdGenerator(); List<UnwrapReductionOpportunity> ops = UnwrapReductionOpportunities .findOpportunities(MakeShaderJobFromFragmentShader.make(tu), new ReducerContext(false, version, generator, idGenerator)); assertEquals(1, ops.size()); ops.get(0).applyReduction(); List<? extends IReductionOpportunity> remainingOps = VariableDeclReductionOpportunities .findOpportunities(MakeShaderJobFromFragmentShader.make(tu), new ReducerContext(false, version, generator, idGenerator)); assertEquals(PrettyPrinterVisitor.prettyPrintAsString(tu), PrettyPrinterVisitor.prettyPrintAsString(ParseHelper.parse(expected))); assertEquals(2, remainingOps.size()); remainingOps.get(0).applyReduction(); remainingOps.get(1).applyReduction(); final String expected2 = "void main() {" + " int ;" + " {" + " int ;" + " }" + "}"; assertEquals(PrettyPrinterVisitor.prettyPrintAsString(tu), PrettyPrinterVisitor.prettyPrintAsString(ParseHelper.parse(expected2))); remainingOps = StmtReductionOpportunities.findOpportunities(MakeShaderJobFromFragmentShader.make(tu), new ReducerContext(false, version, generator, idGenerator)); assertEquals(3, remainingOps.size()); remainingOps.get(0).applyReduction(); remainingOps.get(1).applyReduction(); remainingOps.get(2).applyReduction(); final String expected3 = "void main() {" + "}"; assertEquals(PrettyPrinterVisitor.prettyPrintAsString(tu), PrettyPrinterVisitor.prettyPrintAsString(ParseHelper.parse(expected3))); remainingOps = ReductionOpportunities.getReductionOpportunities( MakeShaderJobFromFragmentShader.make(tu), new ReducerContext(false, version, generator, idGenerator), fileOps); assertEquals(0, remainingOps.size()); }
static List<UnwrapReductionOpportunity> findOpportunities( ShaderJob shaderJob, ReducerContext context) { return shaderJob.getShaders() .stream() .map(item -> findOpportunitiesForShader(item, context)) .reduce(Arrays.asList(), ListConcat::concatenate); }
UnwrapReductionOpportunities extends ReductionOpportunitiesBase<UnwrapReductionOpportunity> { static List<UnwrapReductionOpportunity> findOpportunities( ShaderJob shaderJob, ReducerContext context) { return shaderJob.getShaders() .stream() .map(item -> findOpportunitiesForShader(item, context)) .reduce(Arrays.asList(), ListConcat::concatenate); } }
UnwrapReductionOpportunities extends ReductionOpportunitiesBase<UnwrapReductionOpportunity> { static List<UnwrapReductionOpportunity> findOpportunities( ShaderJob shaderJob, ReducerContext context) { return shaderJob.getShaders() .stream() .map(item -> findOpportunitiesForShader(item, context)) .reduce(Arrays.asList(), ListConcat::concatenate); } private  UnwrapReductionOpportunities(TranslationUnit tu, ReducerContext context); }
UnwrapReductionOpportunities extends ReductionOpportunitiesBase<UnwrapReductionOpportunity> { static List<UnwrapReductionOpportunity> findOpportunities( ShaderJob shaderJob, ReducerContext context) { return shaderJob.getShaders() .stream() .map(item -> findOpportunitiesForShader(item, context)) .reduce(Arrays.asList(), ListConcat::concatenate); } private  UnwrapReductionOpportunities(TranslationUnit tu, ReducerContext context); @Override void visitIfStmt(IfStmt ifStmt); @Override void visitForStmt(ForStmt forStmt); @Override void visitDoStmt(DoStmt doStmt); }
UnwrapReductionOpportunities extends ReductionOpportunitiesBase<UnwrapReductionOpportunity> { static List<UnwrapReductionOpportunity> findOpportunities( ShaderJob shaderJob, ReducerContext context) { return shaderJob.getShaders() .stream() .map(item -> findOpportunitiesForShader(item, context)) .reduce(Arrays.asList(), ListConcat::concatenate); } private  UnwrapReductionOpportunities(TranslationUnit tu, ReducerContext context); @Override void visitIfStmt(IfStmt ifStmt); @Override void visitForStmt(ForStmt forStmt); @Override void visitDoStmt(DoStmt doStmt);  }