@Test public void testSwitch1() throws Exception { final String prog = "void main() {" + " int y = 2;" + " switch(_GLF_SWITCH(0)) {" + " case 5:" + " y += 1;" + " case 6:" + " case 7:" + " y += 2;" + " case 0:" + " case 1:" + " y += 3;" + " case 42:" + " y += 4;" + " break;" + " case 16:" + " y += 5;" + " default:" + " 1;" + " }" + "}"; final String expectedProg = "void main() {" + " int y = 2;" + " switch(_GLF_SWITCH(0)) {" + " case 5:" + " case 0:" + " case 1:" + " y += 3;" + " case 42:" + " y += 4;" + " break;" + " 1;" + " }" + "}"; final TranslationUnit tu = ParseHelper.parse(prog); List<StmtReductionOpportunity> ops = StmtReductionOpportunities .findOpportunities(MakeShaderJobFromFragmentShader.make(tu), new ReducerContext(false, ShadingLanguageVersion.GLSL_130, new RandomWrapper(0), new IdGenerator())); for (StmtReductionOpportunity op : ops) { op.applyReduction(); } CompareAsts.assertEqualAsts(expectedProg, 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);   }