@Test public void testRemoveDuplicateReturn1() throws Exception { final String program = "int foo() { return 0; return 1; return 2; return 3; }"; final String expected = "int foo() { return 1; }"; final TranslationUnit tu = ParseHelper.parse(program); final ReducerContext context = new ReducerContext(true, ShadingLanguageVersion.ESSL_300, new RandomWrapper(0), new IdGenerator()); final ShaderJob shaderJob = MakeShaderJobFromFragmentShader.make(tu); List<StmtReductionOpportunity> ops = StmtReductionOpportunities.findOpportunities( shaderJob, context); assertEquals(4, ops.size()); ops.get(0).applyReduction(); ops.get(3).applyReduction(); ops.get(2).applyReduction(); assertFalse(ops.get(1).preconditionHolds()); CompareAsts.assertEqualAsts(expected, tu); ops = StmtReductionOpportunities.findOpportunities( shaderJob, context); assertTrue(ops.isEmpty()); }
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);   }