Search in sources :

Example 1 with ConditionVisitor

use of lucee.transformer.bytecode.visitor.ConditionVisitor in project Lucee by lucee.

the class SourceLastModifiedClassAdapter method writeOutInitComponent.

private void writeOutInitComponent(ConstrBytecodeContext constr, List<LitString> keys, ClassWriter cw, Tag component, String name) throws TransformerException {
    final GeneratorAdapter adapter = new GeneratorAdapter(Opcodes.ACC_PUBLIC + Opcodes.ACC_FINAL, INIT_COMPONENT3, null, new Type[] { Types.PAGE_EXCEPTION }, cw);
    BytecodeContext bc = new BytecodeContext(null, constr, this, keys, cw, name, adapter, INIT_COMPONENT3, writeLog(), suppressWSbeforeArg, output, returnValue);
    Label methodBegin = new Label();
    Label methodEnd = new Label();
    adapter.visitLocalVariable("this", "L" + name + ";", null, methodBegin, methodEnd, 0);
    adapter.visitLabel(methodBegin);
    // Scope oldData=null;
    final int oldData = adapter.newLocal(Types.VARIABLES);
    ASMConstants.NULL(adapter);
    adapter.storeLocal(oldData);
    int localBC = adapter.newLocal(Types.BODY_CONTENT);
    ConditionVisitor cv = new ConditionVisitor();
    cv.visitBefore();
    cv.visitWhenBeforeExpr();
    adapter.loadArg(1);
    adapter.invokeVirtual(Types.COMPONENT_IMPL, GET_OUTPUT);
    cv.visitWhenAfterExprBeforeBody(bc);
    ASMConstants.NULL(adapter);
    cv.visitWhenAfterBody(bc);
    cv.visitOtherviseBeforeBody();
    adapter.loadArg(0);
    adapter.invokeVirtual(Types.PAGE_CONTEXT, PUSH_BODY);
    cv.visitOtherviseAfterBody();
    cv.visitAfter(bc);
    adapter.storeLocal(localBC);
    // c.init(pc,this);
    adapter.loadArg(1);
    adapter.loadArg(0);
    adapter.loadThis();
    adapter.loadArg(2);
    // adapter.visitVarInsn(Opcodes.ALOAD, 0);
    adapter.invokeVirtual(Types.COMPONENT_IMPL, INIT_COMPONENT);
    // return when executeConstr is false
    adapter.loadArg(2);
    Label afterIf = new Label();
    adapter.visitJumpInsn(Opcodes.IFNE, afterIf);
    adapter.loadArg(0);
    adapter.loadLocal(localBC);
    adapter.invokeStatic(Types.BODY_CONTENT_UTIL, CLEAR_AND_POP);
    adapter.visitInsn(Opcodes.RETURN);
    adapter.visitLabel(afterIf);
    // int oldCheckArgs=	pc.undefinedScope().setMode(Undefined.MODE_NO_LOCAL_AND_ARGUMENTS);
    final int oldCheckArgs = adapter.newLocal(Types.INT_VALUE);
    adapter.loadArg(0);
    adapter.invokeVirtual(Types.PAGE_CONTEXT, UNDEFINED_SCOPE);
    adapter.push(Undefined.MODE_NO_LOCAL_AND_ARGUMENTS);
    adapter.invokeInterface(Types.UNDEFINED, SET_MODE);
    adapter.storeLocal(oldCheckArgs);
    TryCatchFinallyVisitor tcf = new TryCatchFinallyVisitor(new OnFinally() {

        public void _writeOut(BytecodeContext bc) {
            // undefined.setMode(oldMode);
            adapter.loadArg(0);
            adapter.invokeVirtual(Types.PAGE_CONTEXT, UNDEFINED_SCOPE);
            adapter.loadLocal(oldCheckArgs, Types.INT_VALUE);
            adapter.invokeInterface(Types.UNDEFINED, SET_MODE);
            adapter.pop();
            // c.afterCall(pc,_oldData);
            adapter.loadArg(1);
            adapter.loadArg(0);
            adapter.loadLocal(oldData);
            adapter.invokeVirtual(Types.COMPONENT_IMPL, AFTER_CALL);
        }
    }, null);
    tcf.visitTryBegin(bc);
    // oldData=c.beforeCall(pc);
    adapter.loadArg(1);
    adapter.loadArg(0);
    adapter.invokeVirtual(Types.COMPONENT_IMPL, BEFORE_CALL);
    adapter.storeLocal(oldData);
    ExpressionUtil.visitLine(bc, component.getStart());
    writeOutCallBody(bc, component.getBody(), IFunction.PAGE_TYPE_COMPONENT);
    ExpressionUtil.visitLine(bc, component.getEnd());
    int t = tcf.visitTryEndCatchBeging(bc);
    // BodyContentUtil.flushAndPop(pc,bc);
    adapter.loadArg(0);
    adapter.loadLocal(localBC);
    adapter.invokeStatic(Types.BODY_CONTENT_UTIL, FLUSH_AND_POP);
    // throw Caster.toPageException(t);
    adapter.loadLocal(t);
    adapter.invokeStatic(Types.CASTER, TO_PAGE_EXCEPTION);
    adapter.throwException();
    tcf.visitCatchEnd(bc);
    adapter.loadArg(0);
    adapter.loadLocal(localBC);
    adapter.invokeStatic(Types.BODY_CONTENT_UTIL, CLEAR_AND_POP);
    adapter.returnValue();
    adapter.visitLabel(methodEnd);
    adapter.endMethod();
}
Also used : ConditionVisitor(lucee.transformer.bytecode.visitor.ConditionVisitor) Label(org.objectweb.asm.Label) OnFinally(lucee.transformer.bytecode.visitor.OnFinally) GeneratorAdapter(org.objectweb.asm.commons.GeneratorAdapter) TryCatchFinallyVisitor(lucee.transformer.bytecode.visitor.TryCatchFinallyVisitor)

Example 2 with ConditionVisitor

use of lucee.transformer.bytecode.visitor.ConditionVisitor in project Lucee by lucee.

the class Condition method _writeOut.

@Override
public void _writeOut(BytecodeContext bc) throws TransformerException {
    Iterator<Pair> it = ifs.iterator();
    Pair pair;
    ConditionVisitor cv = new ConditionVisitor();
    cv.visitBefore();
    // ifs
    while (it.hasNext()) {
        pair = it.next();
        ExpressionUtil.visitLine(bc, pair.start);
        cv.visitWhenBeforeExpr();
        pair.condition.writeOut(bc, Expression.MODE_VALUE);
        cv.visitWhenAfterExprBeforeBody(bc);
        pair.body.writeOut(bc);
        cv.visitWhenAfterBody(bc);
        if (pair.end != null)
            ExpressionUtil.visitLine(bc, pair.end);
    }
    // else
    if (_else != null && _else.body != null) {
        cv.visitOtherviseBeforeBody();
        _else.body.writeOut(bc);
        cv.visitOtherviseAfterBody();
    }
    cv.visitAfter(bc);
}
Also used : ConditionVisitor(lucee.transformer.bytecode.visitor.ConditionVisitor)

Example 3 with ConditionVisitor

use of lucee.transformer.bytecode.visitor.ConditionVisitor in project Lucee by lucee.

the class TagSwitch method _writeOut.

/**
 * @see lucee.transformer.bytecode.statement.tag.TagBase#_writeOut(org.objectweb.asm.commons.GeneratorAdapter)
 */
@Override
public void _writeOut(BytecodeContext bc) throws TransformerException {
    GeneratorAdapter adapter = bc.getAdapter();
    // expression
    int expression = adapter.newLocal(Types.STRING);
    getAttribute("expression").getValue().writeOut(bc, Expression.MODE_REF);
    adapter.storeLocal(expression);
    List statements = getBody().getStatements();
    Statement stat;
    Tag tag;
    ConditionVisitor cv = new ConditionVisitor();
    cv.visitBefore();
    // cases
    Iterator it = statements.iterator();
    Tag def = null;
    while (it.hasNext()) {
        stat = (Statement) it.next();
        if (stat instanceof Tag) {
            tag = (Tag) stat;
            if (tag.getTagLibTag().getTagClassDefinition().isClassNameEqualTo("lucee.runtime.tag.Case")) {
                addCase(bc, cv, tag, expression);
                continue;
            } else if (tag.getTagLibTag().getTagClassDefinition().isClassNameEqualTo("lucee.runtime.tag.Defaultcase")) {
                if (def != null)
                    throw new TransformerException("multiple defaultcases are not allowed", getStart());
                def = tag;
            // setDefaultCase(bc,cv,tag);
            // break;
            }
        }
    }
    // default
    if (def != null)
        setDefaultCase(bc, cv, def);
    cv.visitAfter(bc);
}
Also used : ConditionVisitor(lucee.transformer.bytecode.visitor.ConditionVisitor) Statement(lucee.transformer.bytecode.Statement) Iterator(java.util.Iterator) GeneratorAdapter(org.objectweb.asm.commons.GeneratorAdapter) List(java.util.List) TransformerException(lucee.transformer.TransformerException)

Example 4 with ConditionVisitor

use of lucee.transformer.bytecode.visitor.ConditionVisitor in project Lucee by lucee.

the class SourceLastModifiedClassAdapter method writeUdfDefaultValueInner.

private void writeUdfDefaultValueInner(BytecodeContext bc, Function[] functions, int offset, int length) throws TransformerException {
    GeneratorAdapter adapter = bc.getAdapter();
    ConditionVisitor cv = new ConditionVisitor();
    DecisionIntVisitor div;
    cv.visitBefore();
    for (int i = offset; i < length; i++) {
        cv.visitWhenBeforeExpr();
        div = new DecisionIntVisitor();
        div.visitBegin();
        adapter.loadArg(1);
        div.visitEQ();
        adapter.push(i);
        div.visitEnd(bc);
        cv.visitWhenAfterExprBeforeBody(bc);
        writeOutFunctionDefaultValueInnerInner(bc, functions[i]);
        cv.visitWhenAfterBody(bc);
    }
    cv.visitAfter(bc);
}
Also used : ConditionVisitor(lucee.transformer.bytecode.visitor.ConditionVisitor) GeneratorAdapter(org.objectweb.asm.commons.GeneratorAdapter) DecisionIntVisitor(lucee.transformer.bytecode.visitor.DecisionIntVisitor)

Example 5 with ConditionVisitor

use of lucee.transformer.bytecode.visitor.ConditionVisitor in project Lucee by lucee.

the class SourceLastModifiedClassAdapter method writeOutFunctionDefaultValueInnerInner.

private void writeOutFunctionDefaultValueInnerInner(BytecodeContext bc, Function function) throws TransformerException {
    GeneratorAdapter adapter = bc.getAdapter();
    List<Argument> args = function.getArguments();
    if (args.size() == 0) {
        adapter.loadArg(DEFAULT_VALUE);
        adapter.returnValue();
        return;
    }
    Iterator<Argument> it = args.iterator();
    Argument arg;
    ConditionVisitor cv = new ConditionVisitor();
    DecisionIntVisitor div;
    cv.visitBefore();
    int count = 0;
    while (it.hasNext()) {
        arg = it.next();
        cv.visitWhenBeforeExpr();
        div = new DecisionIntVisitor();
        div.visitBegin();
        adapter.loadArg(2);
        div.visitEQ();
        adapter.push(count++);
        div.visitEnd(bc);
        cv.visitWhenAfterExprBeforeBody(bc);
        Expression defaultValue = arg.getDefaultValue();
        if (defaultValue != null) {
            /*if(defaultValue instanceof Null) {
						adapter.invokeStatic(NULL, GET_INSTANCE);
					}
					else*/
            defaultValue.writeOut(bc, Expression.MODE_REF);
        } else
            adapter.loadArg(DEFAULT_VALUE);
        // adapter.visitInsn(Opcodes.ACONST_NULL);
        adapter.returnValue();
        cv.visitWhenAfterBody(bc);
    }
    cv.visitOtherviseBeforeBody();
    // adapter.visitInsn(ACONST_NULL);
    // adapter.returnValue();
    cv.visitOtherviseAfterBody();
    cv.visitAfter(bc);
}
Also used : ConditionVisitor(lucee.transformer.bytecode.visitor.ConditionVisitor) Argument(lucee.transformer.bytecode.statement.Argument) Expression(lucee.transformer.expression.Expression) GeneratorAdapter(org.objectweb.asm.commons.GeneratorAdapter) DecisionIntVisitor(lucee.transformer.bytecode.visitor.DecisionIntVisitor)

Aggregations

ConditionVisitor (lucee.transformer.bytecode.visitor.ConditionVisitor)8 GeneratorAdapter (org.objectweb.asm.commons.GeneratorAdapter)7 DecisionIntVisitor (lucee.transformer.bytecode.visitor.DecisionIntVisitor)5 Iterator (java.util.Iterator)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 InterfacePageImpl (lucee.runtime.InterfacePageImpl)1 PageSource (lucee.runtime.PageSource)1 TransformerException (lucee.transformer.TransformerException)1 Data (lucee.transformer.bytecode.ConstrBytecodeContext.Data)1 Statement (lucee.transformer.bytecode.Statement)1 Argument (lucee.transformer.bytecode.statement.Argument)1 HasBody (lucee.transformer.bytecode.statement.HasBody)1 IFunction (lucee.transformer.bytecode.statement.IFunction)1 TagCIObject (lucee.transformer.bytecode.statement.tag.TagCIObject)1 TagThread (lucee.transformer.bytecode.statement.tag.TagThread)1 Function (lucee.transformer.bytecode.statement.udf.Function)1 ArrayVisitor (lucee.transformer.bytecode.visitor.ArrayVisitor)1 OnFinally (lucee.transformer.bytecode.visitor.OnFinally)1 TryCatchFinallyVisitor (lucee.transformer.bytecode.visitor.TryCatchFinallyVisitor)1