@Test public void testGlobalScope() throws Exception { final String program = "const int x = 2; void main() { int y = x + 3; }"; final String expected = "const int x = 2; void main() { int y = (2) + 3; }"; final TranslationUnit tu = ParseHelper.parse(program); final List<SimplifyExprReductionOpportunity> ops = InlineInitializerReductionOpportunities .findOpportunities(MakeShaderJobFromFragmentShader.make(tu), new ReducerContext(true, ShadingLanguageVersion.ESSL_100, new RandomWrapper(0), new IdGenerator())); assertEquals(1, ops.size()); ops.get(0).applyReduction(); CompareAsts.assertEqualAsts(expected, tu); assertTrue(InlineInitializerReductionOpportunities .findOpportunities(MakeShaderJobFromFragmentShader.make(tu), new ReducerContext(false, ShadingLanguageVersion.ESSL_100, new RandomWrapper(0), new IdGenerator())).isEmpty()); }
static List<SimplifyExprReductionOpportunity> findOpportunities( ShaderJob shaderJob, ReducerContext context) { return shaderJob.getShaders() .stream() .map(item -> findOpportunitiesForShader(item, context)) .reduce(Arrays.asList(), ListConcat::concatenate); }
InlineInitializerReductionOpportunities extends ReductionOpportunitiesBase<SimplifyExprReductionOpportunity> { static List<SimplifyExprReductionOpportunity> findOpportunities( ShaderJob shaderJob, ReducerContext context) { return shaderJob.getShaders() .stream() .map(item -> findOpportunitiesForShader(item, context)) .reduce(Arrays.asList(), ListConcat::concatenate); } }
InlineInitializerReductionOpportunities extends ReductionOpportunitiesBase<SimplifyExprReductionOpportunity> { static List<SimplifyExprReductionOpportunity> findOpportunities( ShaderJob shaderJob, ReducerContext context) { return shaderJob.getShaders() .stream() .map(item -> findOpportunitiesForShader(item, context)) .reduce(Arrays.asList(), ListConcat::concatenate); } private  InlineInitializerReductionOpportunities(
        TranslationUnit tu,
        ReducerContext context); }
InlineInitializerReductionOpportunities extends ReductionOpportunitiesBase<SimplifyExprReductionOpportunity> { static List<SimplifyExprReductionOpportunity> findOpportunities( ShaderJob shaderJob, ReducerContext context) { return shaderJob.getShaders() .stream() .map(item -> findOpportunitiesForShader(item, context)) .reduce(Arrays.asList(), ListConcat::concatenate); } private  InlineInitializerReductionOpportunities(
        TranslationUnit tu,
        ReducerContext context); @Override void visitVariableIdentifierExpr(VariableIdentifierExpr variableIdentifierExpr); }
InlineInitializerReductionOpportunities extends ReductionOpportunitiesBase<SimplifyExprReductionOpportunity> { static List<SimplifyExprReductionOpportunity> findOpportunities( ShaderJob shaderJob, ReducerContext context) { return shaderJob.getShaders() .stream() .map(item -> findOpportunitiesForShader(item, context)) .reduce(Arrays.asList(), ListConcat::concatenate); } private  InlineInitializerReductionOpportunities(
        TranslationUnit tu,
        ReducerContext context); @Override void visitVariableIdentifierExpr(VariableIdentifierExpr variableIdentifierExpr);  }