@Test public void testWithBreaks() throws Exception { final String original = "void main() {\n" + " int a;\n" + " int x = 3;\n" + " switch (x) {\n" + " case 0:\n" + " {\n" + " x = 1;\n" + " }\n" + " break;\n" + " case 1:\n" + " a = 4;\n" + " x = 2;\n" + " break;\n" + " case 3:\n" + " default:\n" + " x = 1;\n" + " break;\n" + " }\n" + "}\n"; final String expected = "void main() {\n" + " int a;\n" + " int x = 3;\n" + " do {\n" + " x;\n" + " {\n" + " x = 1;\n" + " }\n" + " break;\n" + " a = 4;\n" + " x = 2;\n" + " break;\n" + " x = 1;\n" + " break;\n" + " } while (false);\n" + "}\n"; final TranslationUnit tu = ParseHelper.parse(original); final List<SwitchToLoopReductionOpportunity> ops = SwitchToLoopReductionOpportunities .findOpportunities(MakeShaderJobFromFragmentShader.make(tu), new ReducerContext(true, ShadingLanguageVersion.ESSL_320, new RandomWrapper(0), new IdGenerator())); assertEquals(1, ops.size()); ops.get(0).applyReduction(); CompareAsts.assertEqualAsts(expected, tu); }
static List<SwitchToLoopReductionOpportunity> findOpportunities( ShaderJob shaderJob, ReducerContext context) { return shaderJob.getShaders() .stream() .map(item -> findOpportunitiesForShader(item, context)) .reduce(Collections.emptyList(), ListConcat::concatenate); }
SwitchToLoopReductionOpportunities extends
    ReductionOpportunitiesBase<SwitchToLoopReductionOpportunity> { static List<SwitchToLoopReductionOpportunity> findOpportunities( ShaderJob shaderJob, ReducerContext context) { return shaderJob.getShaders() .stream() .map(item -> findOpportunitiesForShader(item, context)) .reduce(Collections.emptyList(), ListConcat::concatenate); } }
SwitchToLoopReductionOpportunities extends
    ReductionOpportunitiesBase<SwitchToLoopReductionOpportunity> { static List<SwitchToLoopReductionOpportunity> findOpportunities( ShaderJob shaderJob, ReducerContext context) { return shaderJob.getShaders() .stream() .map(item -> findOpportunitiesForShader(item, context)) .reduce(Collections.emptyList(), ListConcat::concatenate); } private  SwitchToLoopReductionOpportunities(TranslationUnit tu, ReducerContext context); }
SwitchToLoopReductionOpportunities extends
    ReductionOpportunitiesBase<SwitchToLoopReductionOpportunity> { static List<SwitchToLoopReductionOpportunity> findOpportunities( ShaderJob shaderJob, ReducerContext context) { return shaderJob.getShaders() .stream() .map(item -> findOpportunitiesForShader(item, context)) .reduce(Collections.emptyList(), ListConcat::concatenate); } private  SwitchToLoopReductionOpportunities(TranslationUnit tu, ReducerContext context); @Override void visitSwitchStmt(SwitchStmt switchStmt); }
SwitchToLoopReductionOpportunities extends
    ReductionOpportunitiesBase<SwitchToLoopReductionOpportunity> { static List<SwitchToLoopReductionOpportunity> findOpportunities( ShaderJob shaderJob, ReducerContext context) { return shaderJob.getShaders() .stream() .map(item -> findOpportunitiesForShader(item, context)) .reduce(Collections.emptyList(), ListConcat::concatenate); } private  SwitchToLoopReductionOpportunities(TranslationUnit tu, ReducerContext context); @Override void visitSwitchStmt(SwitchStmt switchStmt);  }