@Test public void testNonLocalInitialization() throws Exception { final String shader = "struct _GLF_struct_28 {\n" + " mat4 _f0;\n" + " vec4 a;\n" + "};\n" + "vec4 f(_GLF_struct_28 _GLF_struct_replacement_29)\n" + "{\n" + " return _GLF_struct_28(mat4(1.0), vec4(1.0)).a;\n" + "}\n" + "void main()\n" + "{\n" + " _GLF_struct_28 _GLF_struct_replacement_29;\n" + "}\n"; final String expected = "struct _GLF_struct_28 {\n" + " vec4 a;\n" + "};\n" + "vec4 f(_GLF_struct_28 _GLF_struct_replacement_29)\n" + "{\n" + " return _GLF_struct_28(vec4(1.0)).a;\n" + "}\n" + "void main()\n" + "{\n" + " _GLF_struct_28 _GLF_struct_replacement_29;\n" + "}\n"; TranslationUnit tu = ParseHelper.parse(shader); List<RemoveStructFieldReductionOpportunity> ops = RemoveStructFieldReductionOpportunities .findOpportunities(MakeShaderJobFromFragmentShader.make(tu), new ReducerContext(true, ShadingLanguageVersion.ESSL_100, new RandomWrapper(0), new IdGenerator())); assertEquals(1, ops.size()); ops.get(0).applyReduction(); assertEquals(PrettyPrinterVisitor.prettyPrintAsString(tu), PrettyPrinterVisitor.prettyPrintAsString(ParseHelper.parse(expected))); }
static List<RemoveStructFieldReductionOpportunity> findOpportunities( ShaderJob shaderJob, ReducerContext context) { return shaderJob.getShaders() .stream() .map(item -> findOpportunitiesForShader(item)) .reduce(Arrays.asList(), ListConcat::concatenate); }
RemoveStructFieldReductionOpportunities extends ScopeTrackingVisitor { static List<RemoveStructFieldReductionOpportunity> findOpportunities( ShaderJob shaderJob, ReducerContext context) { return shaderJob.getShaders() .stream() .map(item -> findOpportunitiesForShader(item)) .reduce(Arrays.asList(), ListConcat::concatenate); } }
RemoveStructFieldReductionOpportunities extends ScopeTrackingVisitor { static List<RemoveStructFieldReductionOpportunity> findOpportunities( ShaderJob shaderJob, ReducerContext context) { return shaderJob.getShaders() .stream() .map(item -> findOpportunitiesForShader(item)) .reduce(Arrays.asList(), ListConcat::concatenate); } private  RemoveStructFieldReductionOpportunities(TranslationUnit translationUnit); }
RemoveStructFieldReductionOpportunities extends ScopeTrackingVisitor { static List<RemoveStructFieldReductionOpportunity> findOpportunities( ShaderJob shaderJob, ReducerContext context) { return shaderJob.getShaders() .stream() .map(item -> findOpportunitiesForShader(item)) .reduce(Arrays.asList(), ListConcat::concatenate); } private  RemoveStructFieldReductionOpportunities(TranslationUnit translationUnit); @Override void visitDeclarationStmt(DeclarationStmt declarationStmt); }
RemoveStructFieldReductionOpportunities extends ScopeTrackingVisitor { static List<RemoveStructFieldReductionOpportunity> findOpportunities( ShaderJob shaderJob, ReducerContext context) { return shaderJob.getShaders() .stream() .map(item -> findOpportunitiesForShader(item)) .reduce(Arrays.asList(), ListConcat::concatenate); } private  RemoveStructFieldReductionOpportunities(TranslationUnit translationUnit); @Override void visitDeclarationStmt(DeclarationStmt declarationStmt);  }