@Test public void testMultipleDeclarations() throws Exception { final String program = "void main() {" + "int a = 1;" + "int b = foo();" + "int c;" + "}"; final String expected = "void main() {" + " int a;" + " a = 1;" + " int b;" + " b = foo();" + " int c;" + "}"; final TranslationUnit tu = ParseHelper.parse(program); List<VariableDeclToExprReductionOpportunity> ops = VariableDeclToExprReductionOpportunities .findOpportunities(MakeShaderJobFromFragmentShader.make(tu), new ReducerContext(true, ShadingLanguageVersion.ESSL_100, new RandomWrapper(0), new IdGenerator())); assertEquals(2, ops.size()); ops.forEach(VariableDeclToExprReductionOpportunity::applyReductionImpl); CompareAsts.assertEqualAsts(expected, tu); }
static List<VariableDeclToExprReductionOpportunity> findOpportunities( ShaderJob shaderJob, ReducerContext context) { return shaderJob.getShaders() .stream() .map(item -> findOpportunitiesForShader(item, context)) .reduce(Arrays.asList(), ListConcat::concatenate); }
VariableDeclToExprReductionOpportunities extends ReductionOpportunitiesBase<VariableDeclToExprReductionOpportunity> { static List<VariableDeclToExprReductionOpportunity> findOpportunities( ShaderJob shaderJob, ReducerContext context) { return shaderJob.getShaders() .stream() .map(item -> findOpportunitiesForShader(item, context)) .reduce(Arrays.asList(), ListConcat::concatenate); } }
VariableDeclToExprReductionOpportunities extends ReductionOpportunitiesBase<VariableDeclToExprReductionOpportunity> { static List<VariableDeclToExprReductionOpportunity> findOpportunities( ShaderJob shaderJob, ReducerContext context) { return shaderJob.getShaders() .stream() .map(item -> findOpportunitiesForShader(item, context)) .reduce(Arrays.asList(), ListConcat::concatenate); } private  VariableDeclToExprReductionOpportunities(TranslationUnit tu, ReducerContext context); }
VariableDeclToExprReductionOpportunities extends ReductionOpportunitiesBase<VariableDeclToExprReductionOpportunity> { static List<VariableDeclToExprReductionOpportunity> findOpportunities( ShaderJob shaderJob, ReducerContext context) { return shaderJob.getShaders() .stream() .map(item -> findOpportunitiesForShader(item, context)) .reduce(Arrays.asList(), ListConcat::concatenate); } private  VariableDeclToExprReductionOpportunities(TranslationUnit tu, ReducerContext context); @Override void visitDeclarationStmt(DeclarationStmt declarationStmt); }
VariableDeclToExprReductionOpportunities extends ReductionOpportunitiesBase<VariableDeclToExprReductionOpportunity> { static List<VariableDeclToExprReductionOpportunity> findOpportunities( ShaderJob shaderJob, ReducerContext context) { return shaderJob.getShaders() .stream() .map(item -> findOpportunitiesForShader(item, context)) .reduce(Arrays.asList(), ListConcat::concatenate); } private  VariableDeclToExprReductionOpportunities(TranslationUnit tu, ReducerContext context); @Override void visitDeclarationStmt(DeclarationStmt declarationStmt);  }