Search in sources :

Example 1 with ExprBoolean

use of lucee.transformer.expression.ExprBoolean in project Lucee by lucee.

the class TagIf method writeOutElseIfStart.

private static Label writeOutElseIfStart(BytecodeContext bc, Tag tag) throws TransformerException {
    GeneratorAdapter adapter = bc.getAdapter();
    ExprBoolean cont = bc.getFactory().toExprBoolean(tag.getAttribute("condition").getValue());
    Label endIf = new Label();
    ExpressionUtil.visitLine(bc, tag.getStart());
    cont.writeOut(bc, Expression.MODE_VALUE);
    adapter.ifZCmp(Opcodes.IFEQ, endIf);
    return endIf;
}
Also used : ExprBoolean(lucee.transformer.expression.ExprBoolean) Label(org.objectweb.asm.Label) GeneratorAdapter(org.objectweb.asm.commons.GeneratorAdapter)

Example 2 with ExprBoolean

use of lucee.transformer.expression.ExprBoolean in project Lucee by lucee.

the class CastDouble method _writeOut.

/**
 * @see lucee.transformer.expression.Expression#_writeOut(org.objectweb.asm.commons.GeneratorAdapter, int)
 */
@Override
public Type _writeOut(BytecodeContext bc, int mode) throws TransformerException {
    GeneratorAdapter adapter = bc.getAdapter();
    if (expr instanceof ExprBoolean) {
        expr.writeOut(bc, MODE_VALUE);
        if (mode == MODE_VALUE)
            adapter.invokeStatic(Types.CASTER, Methods.METHOD_TO_DOUBLE_VALUE_FROM_BOOLEAN);
        else
            adapter.invokeStatic(Types.CASTER, Methods.METHOD_TO_DOUBLE_FROM_BOOLEAN);
    } else if (expr instanceof ExprDouble) {
        expr.writeOut(bc, mode);
    // if(mode==MODE_VALUE)adapter.invokeStatic(Types.CASTER,Methods.METHOD_TO_DOUBLE_VALUE_FROM_DOUBLE);
    // if(mode==MODE_REF) adapter.invokeStatic(Types.CASTER,Methods.METHOD_TO_DOUBLE_FROM_DOUBLE);
    } else if (expr instanceof ExprString) {
        expr.writeOut(bc, MODE_REF);
        if (mode == MODE_VALUE)
            adapter.invokeStatic(Types.CASTER, Methods.METHOD_TO_DOUBLE_VALUE_FROM_STRING);
        else
            adapter.invokeStatic(Types.CASTER, Methods.METHOD_TO_DOUBLE_FROM_STRING);
    } else {
        Type rtn = expr.writeOut(bc, mode);
        if (mode == MODE_VALUE) {
            if (!Types.isPrimitiveType(rtn)) {
                adapter.invokeStatic(Types.CASTER, Methods.METHOD_TO_DOUBLE_VALUE);
            } else if (Types.DOUBLE_VALUE.equals(rtn)) {
            } else if (Types.BOOLEAN_VALUE.equals(rtn)) {
                adapter.invokeStatic(Types.CASTER, Methods.METHOD_TO_DOUBLE_VALUE_FROM_BOOLEAN);
            } else {
                adapter.invokeStatic(Types.CASTER, new Method("toRef", Types.toRefType(rtn), new Type[] { rtn }));
                adapter.invokeStatic(Types.CASTER, Methods.METHOD_TO_DOUBLE_VALUE);
            }
            return Types.DOUBLE_VALUE;
        } else if (Types.isPrimitiveType(rtn)) {
            if (Types.DOUBLE_VALUE.equals(rtn)) {
                adapter.invokeStatic(Types.CASTER, Methods.METHOD_TO_DOUBLE_FROM_DOUBLE);
            } else if (Types.BOOLEAN_VALUE.equals(rtn)) {
                adapter.invokeStatic(Types.CASTER, Methods.METHOD_TO_DOUBLE_FROM_BOOLEAN);
            } else {
                adapter.invokeStatic(Types.CASTER, new Method("toRef", Types.toRefType(rtn), new Type[] { rtn }));
                adapter.invokeStatic(Types.CASTER, Methods.METHOD_TO_DOUBLE);
            }
            return Types.DOUBLE;
        }
        // else {
        if (!Types.DOUBLE.equals(rtn))
            adapter.invokeStatic(Types.CASTER, Methods.METHOD_TO_DOUBLE);
        return Types.DOUBLE;
    // }
    }
    if (mode == MODE_VALUE)
        return Types.DOUBLE_VALUE;
    return Types.DOUBLE;
}
Also used : Type(org.objectweb.asm.Type) ExprDouble(lucee.transformer.expression.ExprDouble) ExprString(lucee.transformer.expression.ExprString) ExprBoolean(lucee.transformer.expression.ExprBoolean) GeneratorAdapter(org.objectweb.asm.commons.GeneratorAdapter) Method(org.objectweb.asm.commons.Method)

Example 3 with ExprBoolean

use of lucee.transformer.expression.ExprBoolean in project Lucee by lucee.

the class CastFloat method _writeOut.

/**
 * @see lucee.transformer.expression.Expression#_writeOut(org.objectweb.asm.commons.GeneratorAdapter, int)
 */
@Override
public Type _writeOut(BytecodeContext bc, int mode) throws TransformerException {
    GeneratorAdapter adapter = bc.getAdapter();
    if (expr instanceof OpDouble) {
        ((OpDouble) expr).writeOutDouble(bc, MODE_VALUE);
        if (mode == MODE_VALUE)
            adapter.invokeStatic(Types.CASTER, Methods.METHOD_TO_FLOAT_VALUE_FROM_DOUBLE);
        else
            adapter.invokeStatic(Types.CASTER, Methods.METHOD_TO_FLOAT_FROM_DOUBLE);
    } else if (expr instanceof ExprBoolean) {
        expr.writeOut(bc, MODE_VALUE);
        if (mode == MODE_VALUE)
            adapter.invokeStatic(Types.CASTER, Methods.METHOD_TO_FLOAT_VALUE_FROM_BOOLEAN);
        else
            adapter.invokeStatic(Types.CASTER, Methods.METHOD_TO_FLOAT_FROM_BOOLEAN);
    } else if (expr instanceof ExprFloat) {
        expr.writeOut(bc, mode);
    } else if (expr instanceof ExprDouble) {
        expr.writeOut(bc, MODE_VALUE);
        if (mode == MODE_VALUE)
            adapter.invokeStatic(Types.CASTER, Methods.METHOD_TO_FLOAT_VALUE_FROM_DOUBLE);
        else
            adapter.invokeStatic(Types.CASTER, Methods.METHOD_TO_FLOAT_FROM_DOUBLE);
    } else if (expr instanceof ExprString) {
        expr.writeOut(bc, MODE_REF);
        if (mode == MODE_VALUE)
            adapter.invokeStatic(Types.CASTER, Methods.METHOD_TO_FLOAT_VALUE_FROM_STRING);
        else
            adapter.invokeStatic(Types.CASTER, Methods.METHOD_TO_FLOAT_FROM_STRING);
    } else {
        Type rtn = expr.writeOut(bc, mode);
        if (mode == MODE_VALUE) {
            if (!Types.isPrimitiveType(rtn)) {
                adapter.invokeStatic(Types.CASTER, Methods.METHOD_TO_FLOAT_VALUE);
            } else if (Types.DOUBLE_VALUE.equals(rtn)) {
                adapter.cast(Types.DOUBLE_VALUE, Types.FLOAT_VALUE);
            } else if (Types.FLOAT_VALUE.equals(rtn)) {
            } else if (Types.BOOLEAN_VALUE.equals(rtn)) {
                adapter.invokeStatic(Types.CASTER, Methods.METHOD_TO_FLOAT_VALUE_FROM_BOOLEAN);
            } else {
                adapter.invokeStatic(Types.CASTER, new Method("toRef", Types.toRefType(rtn), new Type[] { rtn }));
                adapter.invokeStatic(Types.CASTER, Methods.METHOD_TO_FLOAT_VALUE);
            }
            return Types.FLOAT_VALUE;
        } else if (Types.isPrimitiveType(rtn)) {
            if (Types.DOUBLE_VALUE.equals(rtn)) {
                adapter.invokeStatic(Types.CASTER, Methods.METHOD_TO_FLOAT_FROM_DOUBLE);
            } else if (Types.FLOAT_VALUE.equals(rtn)) {
                adapter.invokeStatic(Types.CASTER, Methods.METHOD_TO_FLOAT_FROM_FLOAT);
            } else if (Types.BOOLEAN_VALUE.equals(rtn)) {
                adapter.invokeStatic(Types.CASTER, Methods.METHOD_TO_FLOAT_FROM_BOOLEAN);
            } else {
                adapter.invokeStatic(Types.CASTER, new Method("toRef", Types.toRefType(rtn), new Type[] { rtn }));
                adapter.invokeStatic(Types.CASTER, Methods.METHOD_TO_FLOAT);
            }
            return Types.FLOAT;
        }
        // else {
        if (!Types.FLOAT.equals(rtn))
            adapter.invokeStatic(Types.CASTER, Methods.METHOD_TO_FLOAT);
        return Types.FLOAT;
    // }
    }
    if (mode == MODE_VALUE)
        return Types.FLOAT_VALUE;
    return Types.FLOAT;
}
Also used : OpDouble(lucee.transformer.bytecode.op.OpDouble) Type(org.objectweb.asm.Type) ExprDouble(lucee.transformer.expression.ExprDouble) ExprString(lucee.transformer.expression.ExprString) ExprBoolean(lucee.transformer.expression.ExprBoolean) GeneratorAdapter(org.objectweb.asm.commons.GeneratorAdapter) ExprFloat(lucee.transformer.expression.ExprFloat) Method(org.objectweb.asm.commons.Method)

Example 4 with ExprBoolean

use of lucee.transformer.expression.ExprBoolean in project Lucee by lucee.

the class CastString method _writeOut.

/**
 * @see lucee.transformer.expression.Expression#_writeOut(org.objectweb.asm.commons.GeneratorAdapter, int)
 */
@Override
public Type _writeOut(BytecodeContext bc, int mode) throws TransformerException {
    GeneratorAdapter adapter = bc.getAdapter();
    if (expr instanceof ExprBoolean) {
        expr.writeOut(bc, MODE_VALUE);
        adapter.invokeStatic(Types.CASTER, Methods.METHOD_TO_STRING_FROM_BOOLEAN);
    } else if (expr instanceof ExprDouble) {
        expr.writeOut(bc, MODE_VALUE);
        adapter.invokeStatic(Types.CASTER, Methods.METHOD_TO_STRING_FROM_DOUBLE);
    } else {
        Type rtn = expr.writeOut(bc, MODE_REF);
        if (rtn.equals(Types.STRING))
            return Types.STRING;
        adapter.invokeStatic(Types.CASTER, Methods.METHOD_TO_STRING);
    }
    return Types.STRING;
}
Also used : Type(org.objectweb.asm.Type) ExprDouble(lucee.transformer.expression.ExprDouble) ExprBoolean(lucee.transformer.expression.ExprBoolean) GeneratorAdapter(org.objectweb.asm.commons.GeneratorAdapter)

Example 5 with ExprBoolean

use of lucee.transformer.expression.ExprBoolean in project Lucee by lucee.

the class OpBool method toExprBoolean.

/**
 * Create a String expression from a Expression
 * @param left
 * @param right
 *
 * @return String expression
 * @throws TemplateException
 */
public static ExprBoolean toExprBoolean(Expression left, Expression right, int operation) {
    if (left instanceof Literal && right instanceof Literal) {
        Boolean l = ((Literal) left).getBoolean(null);
        Boolean r = ((Literal) right).getBoolean(null);
        if (l != null && r != null) {
            switch(operation) {
                case Factory.OP_BOOL_AND:
                    return left.getFactory().createLitBoolean(l.booleanValue() && r.booleanValue(), left.getStart(), right.getEnd());
                case Factory.OP_BOOL_OR:
                    return left.getFactory().createLitBoolean(l.booleanValue() || r.booleanValue(), left.getStart(), right.getEnd());
                case Factory.OP_BOOL_XOR:
                    return left.getFactory().createLitBoolean(l.booleanValue() ^ r.booleanValue(), left.getStart(), right.getEnd());
            }
        }
    }
    return new OpBool(left, right, operation);
}
Also used : Literal(lucee.transformer.expression.literal.Literal) ExprBoolean(lucee.transformer.expression.ExprBoolean)

Aggregations

ExprBoolean (lucee.transformer.expression.ExprBoolean)9 GeneratorAdapter (org.objectweb.asm.commons.GeneratorAdapter)6 Type (org.objectweb.asm.Type)4 ExprDouble (lucee.transformer.expression.ExprDouble)3 ExprString (lucee.transformer.expression.ExprString)3 Expression (lucee.transformer.expression.Expression)3 Method (org.objectweb.asm.commons.Method)3 HashMap (java.util.HashMap)1 Map (java.util.Map)1 TemplateException (lucee.runtime.exp.TemplateException)1 FunctionArgument (lucee.runtime.type.FunctionArgument)1 FunctionAsExpression (lucee.transformer.bytecode.expression.FunctionAsExpression)1 OpDouble (lucee.transformer.bytecode.op.OpDouble)1 OpVariable (lucee.transformer.bytecode.op.OpVariable)1 Argument (lucee.transformer.bytecode.statement.Argument)1 ExprFloat (lucee.transformer.expression.ExprFloat)1 LitString (lucee.transformer.expression.literal.LitString)1 Literal (lucee.transformer.expression.literal.Literal)1 Variable (lucee.transformer.expression.var.Variable)1 Label (org.objectweb.asm.Label)1