@Test public void testDoubleRemoval() throws Exception { final String shader = "void main() { if (" + Constants.GLF_DEAD + "(false)) { { { } } } }"; final String expected = "void main() { }"; final TranslationUnit tu = ParseHelper.parse(shader); final IRandom generator = new RandomWrapper(0); List<StmtReductionOpportunity> stmtOps = StmtReductionOpportunities .findOpportunities(MakeShaderJobFromFragmentShader.make(tu), new ReducerContext(false, ShadingLanguageVersion.ESSL_100, generator, new IdGenerator())); List<UnwrapReductionOpportunity> unwrapOps = UnwrapReductionOpportunities .findOpportunities(MakeShaderJobFromFragmentShader.make(tu), new ReducerContext(false, ShadingLanguageVersion.ESSL_100, generator, new IdGenerator())); assertFalse(stmtOps.isEmpty()); assertFalse(unwrapOps.isEmpty()); stmtOps.forEach(StmtReductionOpportunity::applyReduction); assertEquals(PrettyPrinterVisitor.prettyPrintAsString(ParseHelper.parse(expected)), PrettyPrinterVisitor.prettyPrintAsString(tu)); unwrapOps.forEach(UnwrapReductionOpportunity::applyReduction); assertEquals(PrettyPrinterVisitor.prettyPrintAsString(ParseHelper.parse(expected)), PrettyPrinterVisitor.prettyPrintAsString(tu)); }
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);  }