@Test public void testRemoveParam() throws Exception { final String shader = "float foo(int a, float b, float c) {" + " return b;" + "}" + "" + "void main() {" + " foo(5, 4.0, 2.0);" + "}"; final String expectedResult = "float foo(float b) {" + " return b;" + "}" + "" + "void main() {" + " foo(4.0);" + "}"; final TranslationUnit tu = ParseHelper.parse(shader); List<RemoveUnusedParameterReductionOpportunity> opportunities = findOpportunities(tu, true); assertEquals(2, opportunities.size()); opportunities.get(0).applyReduction(); opportunities = findOpportunities(tu, true); assertEquals(1, opportunities.size()); opportunities.get(0).applyReduction(); CompareAsts.assertEqualAsts(expectedResult, tu); }
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);  }