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);  }
@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); }
@Test public void testTooLargeToInline() throws Exception { final StringBuilder program = new StringBuilder(); program.append("int donotinlineme(int x) { int y = 2;"); for (int i = 0; i < 100; i++) { program.append(" y = y + x;"); } program.append("}"); program.append("void main() { int z = donotinlineme(5); }"); final TranslationUnit tu = ParseHelper.parse(program.toString()); 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(0, ops.size()); }