@Test public void misc() throws Exception { final String shader = "void main()\n" + "{\n" + " float x;\n" + " for(\n" + " int i = 0;\n" + " _GLF_IDENTITY(i, i) < 10;\n" + " i ++\n" + " )\n" + " {\n" + " {\n" + " if(_GLF_DEAD(false))\n" + " {\n" + " }\n" + " x = 1.0;\n" + " }\n" + " }\n" + "}\n"; TranslationUnit tu = ParseHelper.parse(shader); final String expectedStmt = "x = 1.0;"; assertTrue(PrettyPrinterVisitor.prettyPrintAsString(tu).contains(expectedStmt)); IRandom generator = new RandomWrapper(1); List<UnwrapReductionOpportunity> ops = UnwrapReductionOpportunities .findOpportunities(MakeShaderJobFromFragmentShader.make(tu), new ReducerContext(false, ShadingLanguageVersion.ESSL_100, generator, new IdGenerator())); assertEquals(1, ops.size()); ops.get(0).applyReduction(); assertTrue(PrettyPrinterVisitor.prettyPrintAsString(tu).contains(expectedStmt)); }
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);  }