@Test public void testBasicInline() throws Exception { final String program = "int inlineme(int x) { int y = 2; return y + x; }" + "void main() { int z = inlineme(5); }"; final String expected = "int inlineme(int x) { int y = 2; return y + x; }" + "void main() { " + " int inlineme_inline_return_value_0;" + " {" + " int x = 5;" + " int y = 2;" + " inlineme_inline_return_value_0 = y + x;" + " }" + " int z = inlineme_inline_return_value_0;" + "}"; final TranslationUnit tu = ParseHelper.parse(program); final ShaderJob shaderJob = MakeShaderJobFromFragmentShader.make(tu); final List<InlineFunctionReductionOpportunity> ops = InlineFunctionReductionOpportunities.findOpportunities(shaderJob, new ReducerContext(true, ShadingLanguageVersion.ESSL_100, new RandomWrapper(0), new IdGenerator())); assertEquals(1, ops.size()); ops.get(0).applyReduction(); CompareAsts.assertEqualAsts(expected, tu); }
static List<InlineFunctionReductionOpportunity> findOpportunities( ShaderJob shaderJob, ReducerContext context) { return shaderJob.getShaders() .stream() .map(item -> findOpportunitiesForShader(item, context)) .reduce(Arrays.asList(), ListConcat::concatenate); }
InlineFunctionReductionOpportunities extends StandardVisitor { static List<InlineFunctionReductionOpportunity> findOpportunities( ShaderJob shaderJob, ReducerContext context) { return shaderJob.getShaders() .stream() .map(item -> findOpportunitiesForShader(item, context)) .reduce(Arrays.asList(), ListConcat::concatenate); } }
InlineFunctionReductionOpportunities extends StandardVisitor { static List<InlineFunctionReductionOpportunity> findOpportunities( ShaderJob shaderJob, ReducerContext context) { return shaderJob.getShaders() .stream() .map(item -> findOpportunitiesForShader(item, context)) .reduce(Arrays.asList(), ListConcat::concatenate); } private  InlineFunctionReductionOpportunities(TranslationUnit tu,
        ReducerContext context); }
InlineFunctionReductionOpportunities extends StandardVisitor { static List<InlineFunctionReductionOpportunity> findOpportunities( ShaderJob shaderJob, ReducerContext context) { return shaderJob.getShaders() .stream() .map(item -> findOpportunitiesForShader(item, context)) .reduce(Arrays.asList(), ListConcat::concatenate); } private  InlineFunctionReductionOpportunities(TranslationUnit tu,
        ReducerContext context); @Override void visitFunctionCallExpr(FunctionCallExpr functionCallExpr); }
InlineFunctionReductionOpportunities extends StandardVisitor { static List<InlineFunctionReductionOpportunity> findOpportunities( ShaderJob shaderJob, ReducerContext context) { return shaderJob.getShaders() .stream() .map(item -> findOpportunitiesForShader(item, context)) .reduce(Arrays.asList(), ListConcat::concatenate); } private  InlineFunctionReductionOpportunities(TranslationUnit tu,
        ReducerContext context); @Override void visitFunctionCallExpr(FunctionCallExpr functionCallExpr);  }