@Test public void testRemoveDuplicateReturn2() throws Exception { final String program = "int foo() {\n" + " int x;\n" + " return 0;\n" + " x = 1;\n" + " return 1;\n" + " x = 2;\n" + " return 2;\n" + " return 3;\n" + "}\n"; final String expected = "int foo() {\n" + " int x;\n" + " return 3;\n" + "}\n"; final TranslationUnit tu = ParseHelper.parse(program); final List<StmtReductionOpportunity> ops = StmtReductionOpportunities.findOpportunities( MakeShaderJobFromFragmentShader.make(tu), new ReducerContext(true, ShadingLanguageVersion.ESSL_300, new RandomWrapper(0), new IdGenerator())); assertEquals(6, ops.size()); ops.get(0).applyReduction(); ops.get(1).applyReduction(); ops.get(2).applyReduction(); ops.get(3).applyReduction(); ops.get(4).applyReduction(); assertFalse(ops.get(5).preconditionHolds()); CompareAsts.assertEqualAsts(expected, tu); }
static List<StmtReductionOpportunity> findOpportunities(ShaderJob shaderJob, ReducerContext context) { return shaderJob.getShaders() .stream() .map(item -> findOpportunitiesForShader(item, context)) .reduce(Arrays.asList(), ListConcat::concatenate); }
StmtReductionOpportunities extends ReductionOpportunitiesBase<StmtReductionOpportunity> { static List<StmtReductionOpportunity> findOpportunities(ShaderJob shaderJob, ReducerContext context) { return shaderJob.getShaders() .stream() .map(item -> findOpportunitiesForShader(item, context)) .reduce(Arrays.asList(), ListConcat::concatenate); } }
StmtReductionOpportunities extends ReductionOpportunitiesBase<StmtReductionOpportunity> { static List<StmtReductionOpportunity> findOpportunities(ShaderJob shaderJob, ReducerContext context) { return shaderJob.getShaders() .stream() .map(item -> findOpportunitiesForShader(item, context)) .reduce(Arrays.asList(), ListConcat::concatenate); } private  StmtReductionOpportunities(TranslationUnit tu,
        ReducerContext context); }
StmtReductionOpportunities extends ReductionOpportunitiesBase<StmtReductionOpportunity> { static List<StmtReductionOpportunity> findOpportunities(ShaderJob shaderJob, ReducerContext context) { return shaderJob.getShaders() .stream() .map(item -> findOpportunitiesForShader(item, context)) .reduce(Arrays.asList(), ListConcat::concatenate); } private  StmtReductionOpportunities(TranslationUnit tu,
        ReducerContext context);  }
StmtReductionOpportunities extends ReductionOpportunitiesBase<StmtReductionOpportunity> { static List<StmtReductionOpportunity> findOpportunities(ShaderJob shaderJob, ReducerContext context) { return shaderJob.getShaders() .stream() .map(item -> findOpportunitiesForShader(item, context)) .reduce(Arrays.asList(), ListConcat::concatenate); } private  StmtReductionOpportunities(TranslationUnit tu,
        ReducerContext context);   }