@Test public void testVarIsRemovedButStructLeftBehind() throws Exception { final String original = "struct S { float x; } myS; void main() { gl_FragColor = vec4(S(3.0)" + ".x); }"; final String expected = "struct S { float x; } ; void main() { gl_FragColor = vec4(S(3.0)" + ".x); }"; final TranslationUnit tu = ParseHelper.parse(original); final List<VariableDeclReductionOpportunity> ops = VariableDeclReductionOpportunities .findOpportunities(MakeShaderJobFromFragmentShader.make(tu), new ReducerContext(false, ShadingLanguageVersion.ESSL_100, new RandomWrapper(0), new IdGenerator())); assertEquals(1, ops.size()); ops.get(0).applyReduction(); CompareAsts.assertEqualAsts(expected, tu); final List<GlobalVariablesDeclarationReductionOpportunity> moreOps = GlobalVariablesDeclarationReductionOpportunities .findOpportunities(MakeShaderJobFromFragmentShader.make(tu), new ReducerContext(false, ShadingLanguageVersion.ESSL_100, new RandomWrapper(0), new IdGenerator())); assertEquals(0, moreOps.size()); }
static List<GlobalVariablesDeclarationReductionOpportunity> findOpportunities( ShaderJob shaderJob, ReducerContext context) { return shaderJob.getShaders() .stream() .map(item -> findOpportunitiesForShader(item, context)) .reduce(Arrays.asList(), ListConcat::concatenate); }
GlobalVariablesDeclarationReductionOpportunities extends ReductionOpportunitiesBase<GlobalVariablesDeclarationReductionOpportunity> { static List<GlobalVariablesDeclarationReductionOpportunity> findOpportunities( ShaderJob shaderJob, ReducerContext context) { return shaderJob.getShaders() .stream() .map(item -> findOpportunitiesForShader(item, context)) .reduce(Arrays.asList(), ListConcat::concatenate); } }
GlobalVariablesDeclarationReductionOpportunities extends ReductionOpportunitiesBase<GlobalVariablesDeclarationReductionOpportunity> { static List<GlobalVariablesDeclarationReductionOpportunity> findOpportunities( ShaderJob shaderJob, ReducerContext context) { return shaderJob.getShaders() .stream() .map(item -> findOpportunitiesForShader(item, context)) .reduce(Arrays.asList(), ListConcat::concatenate); } private  GlobalVariablesDeclarationReductionOpportunities(TranslationUnit tu,
                                                           ReducerContext context); }
GlobalVariablesDeclarationReductionOpportunities extends ReductionOpportunitiesBase<GlobalVariablesDeclarationReductionOpportunity> { static List<GlobalVariablesDeclarationReductionOpportunity> findOpportunities( ShaderJob shaderJob, ReducerContext context) { return shaderJob.getShaders() .stream() .map(item -> findOpportunitiesForShader(item, context)) .reduce(Arrays.asList(), ListConcat::concatenate); } private  GlobalVariablesDeclarationReductionOpportunities(TranslationUnit tu,
                                                           ReducerContext context); @Override void visitVariablesDeclaration(VariablesDeclaration variablesDeclaration); @Override void visitFunctionDefinition(FunctionDefinition functionDefinition); }
GlobalVariablesDeclarationReductionOpportunities extends ReductionOpportunitiesBase<GlobalVariablesDeclarationReductionOpportunity> { static List<GlobalVariablesDeclarationReductionOpportunity> findOpportunities( ShaderJob shaderJob, ReducerContext context) { return shaderJob.getShaders() .stream() .map(item -> findOpportunitiesForShader(item, context)) .reduce(Arrays.asList(), ListConcat::concatenate); } private  GlobalVariablesDeclarationReductionOpportunities(TranslationUnit tu,
                                                           ReducerContext context); @Override void visitVariablesDeclaration(VariablesDeclaration variablesDeclaration); @Override void visitFunctionDefinition(FunctionDefinition functionDefinition);  }