@Test public void testInliningInLiveCodeWithPreserveSemantics() throws Exception { final String variableName = Constants.LIVE_PREFIX + "do_inline_me"; final String program = "void main() {\n" + " {\n" + " int " + variableName + " = 5 + 2;\n" + " " + variableName + " * " + variableName + ";\n" + " }\n" + "}\n"; final String expected = "void main() {\n" + " {\n" + " int " + variableName + " = 5 + 2;\n" + " (5 + 2) * (5 + 2);\n" + " }\n" + "}\n"; final TranslationUnit tu = ParseHelper.parse(program); final List<SimplifyExprReductionOpportunity> ops = InlineInitializerReductionOpportunities .findOpportunities(MakeShaderJobFromFragmentShader.make(tu), new ReducerContext(false, ShadingLanguageVersion.ESSL_100, new RandomWrapper(0), new IdGenerator())); assertEquals(2, ops.size()); ops.get(0).applyReduction(); ops.get(1).applyReduction(); CompareAsts.assertEqualAsts(expected, tu); }
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);  }