Search in sources :

Example 1 with CompiledMethodBody

use of com.google.template.soy.jbcsrc.SoyNodeCompiler.CompiledMethodBody in project closure-templates by google.

the class TemplateCompiler method generateRenderMethod.

private Statement generateRenderMethod() {
    final Label start = new Label();
    final Label end = new Label();
    final LocalVariable thisVar = createThisVar(template.typeInfo(), start, end);
    final LocalVariable appendableVar = createLocal("appendable", 1, LOGGING_ADVISING_APPENDABLE_TYPE, start, end).asNonNullable();
    final LocalVariable contextVar = createLocal("context", 2, RENDER_CONTEXT_TYPE, start, end).asNonNullable();
    final TemplateVariableManager variableSet = new TemplateVariableManager(fieldNames, template.typeInfo(), thisVar, template.renderMethod().method());
    TemplateNode node = template.node();
    TemplateVariables variables = new TemplateVariables(variableSet, thisVar, new RenderContextExpression(contextVar));
    final CompiledMethodBody methodBody = SoyNodeCompiler.create(registry, innerClasses, stateField, thisVar, AppendableExpression.forLocal(appendableVar), variableSet, variables).compile(node);
    final Statement returnDone = Statement.returnExpression(MethodRef.RENDER_RESULT_DONE.invoke());
    new Statement() {

        @Override
        protected void doGen(CodeBuilder adapter) {
            adapter.mark(start);
            methodBody.body().gen(adapter);
            adapter.mark(end);
            returnDone.gen(adapter);
            thisVar.tableEntry(adapter);
            appendableVar.tableEntry(adapter);
            contextVar.tableEntry(adapter);
            variableSet.generateTableEntries(adapter);
        }
    }.writeIOExceptionMethod(Opcodes.ACC_PUBLIC, template.renderMethod().method(), writer);
    writer.setNumDetachStates(methodBody.numberOfDetachStates());
    variableSet.defineStaticFields(writer);
    return variableSet.defineFields(writer);
}
Also used : TemplateNode(com.google.template.soy.soytree.TemplateNode) Statement(com.google.template.soy.jbcsrc.restricted.Statement) Label(org.objectweb.asm.Label) LocalVariable(com.google.template.soy.jbcsrc.restricted.LocalVariable) CompiledMethodBody(com.google.template.soy.jbcsrc.SoyNodeCompiler.CompiledMethodBody) CodeBuilder(com.google.template.soy.jbcsrc.restricted.CodeBuilder)

Aggregations

CompiledMethodBody (com.google.template.soy.jbcsrc.SoyNodeCompiler.CompiledMethodBody)1 CodeBuilder (com.google.template.soy.jbcsrc.restricted.CodeBuilder)1 LocalVariable (com.google.template.soy.jbcsrc.restricted.LocalVariable)1 Statement (com.google.template.soy.jbcsrc.restricted.Statement)1 TemplateNode (com.google.template.soy.soytree.TemplateNode)1 Label (org.objectweb.asm.Label)1