@Test public void testRemoveParamOnlyIfReduceEverywhere() throws Exception { final String shader = "" + "float x = 0.0;" + "void bar(float a) { }" + "float foo() {" + " x = 1.0;" + " return 3.0;" + "}" + "void main() {" + " bar(foo());" + " gl_FragColor = vec4(x);" + "}"; final String shaderIfReduced = "" + "float x = 0.0;" + "void bar() { }" + "float foo() {" + " x = 1.0;" + " return 3.0;" + "}" + "void main() {" + " bar();" + " gl_FragColor = vec4(x);" + "}"; TranslationUnit tu = ParseHelper.parse(shader); List<RemoveUnusedParameterReductionOpportunity> opportunities = findOpportunities(tu, true); assertEquals(1, opportunities.size()); opportunities.get(0).applyReduction(); CompareAsts.assertEqualAsts(shaderIfReduced, tu); tu = ParseHelper.parse(shader); opportunities = findOpportunities(tu, false); assertEquals(0, opportunities.size()); }
static List<RemoveUnusedParameterReductionOpportunity> findOpportunities( ShaderJob shaderJob, ReducerContext context) { return shaderJob.getShaders() .stream() .map(item -> findOpportunitiesForShader(item, context)) .reduce(Arrays.asList(), ListConcat::concatenate); }
RemoveUnusedParameterReductionOpportunities extends ReductionOpportunitiesBase<RemoveUnusedParameterReductionOpportunity> { static List<RemoveUnusedParameterReductionOpportunity> findOpportunities( ShaderJob shaderJob, ReducerContext context) { return shaderJob.getShaders() .stream() .map(item -> findOpportunitiesForShader(item, context)) .reduce(Arrays.asList(), ListConcat::concatenate); } }
RemoveUnusedParameterReductionOpportunities extends ReductionOpportunitiesBase<RemoveUnusedParameterReductionOpportunity> { static List<RemoveUnusedParameterReductionOpportunity> findOpportunities( ShaderJob shaderJob, ReducerContext context) { return shaderJob.getShaders() .stream() .map(item -> findOpportunitiesForShader(item, context)) .reduce(Arrays.asList(), ListConcat::concatenate); } private  RemoveUnusedParameterReductionOpportunities(TranslationUnit tu,
                                                      ReducerContext context); }
RemoveUnusedParameterReductionOpportunities extends ReductionOpportunitiesBase<RemoveUnusedParameterReductionOpportunity> { static List<RemoveUnusedParameterReductionOpportunity> findOpportunities( ShaderJob shaderJob, ReducerContext context) { return shaderJob.getShaders() .stream() .map(item -> findOpportunitiesForShader(item, context)) .reduce(Arrays.asList(), ListConcat::concatenate); } private  RemoveUnusedParameterReductionOpportunities(TranslationUnit tu,
                                                      ReducerContext context); @Override void visitTranslationUnit(TranslationUnit translationUnit); @Override void visitFunctionDefinition(FunctionDefinition functionDefinition); @Override void visitVariableIdentifierExpr(VariableIdentifierExpr variableIdentifierExpr); @Override void visitFunctionPrototype(FunctionPrototype functionPrototype); }
RemoveUnusedParameterReductionOpportunities extends ReductionOpportunitiesBase<RemoveUnusedParameterReductionOpportunity> { static List<RemoveUnusedParameterReductionOpportunity> findOpportunities( ShaderJob shaderJob, ReducerContext context) { return shaderJob.getShaders() .stream() .map(item -> findOpportunitiesForShader(item, context)) .reduce(Arrays.asList(), ListConcat::concatenate); } private  RemoveUnusedParameterReductionOpportunities(TranslationUnit tu,
                                                      ReducerContext context); @Override void visitTranslationUnit(TranslationUnit translationUnit); @Override void visitFunctionDefinition(FunctionDefinition functionDefinition); @Override void visitVariableIdentifierExpr(VariableIdentifierExpr variableIdentifierExpr); @Override void visitFunctionPrototype(FunctionPrototype functionPrototype);  }