Search in sources :

Example 6 with ExprString

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

the class OpString method toExprString.

public static ExprString toExprString(Expression left, Expression right, boolean concatStatic) {
    if (concatStatic && left instanceof Literal && right instanceof Literal) {
        String l = ((Literal) left).getString();
        String r = ((Literal) right).getString();
        if ((l.length() + r.length()) <= MAX_SIZE)
            return left.getFactory().createLitString(l.concat(r), left.getStart(), right.getEnd());
    }
    return new OpString(left, right);
}
Also used : Literal(lucee.transformer.expression.literal.Literal) ExprString(lucee.transformer.expression.ExprString)

Example 7 with ExprString

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

the class PrintOut method _writeOut.

/**
 * @see lucee.transformer.bytecode.Statement#_writeOut(org.objectweb.asm.commons.GeneratorAdapter)
 */
@Override
public void _writeOut(BytecodeContext bc) throws TransformerException {
    boolean doEncode = !checkPSQ && encodeFor != null;
    GeneratorAdapter adapter = bc.getAdapter();
    adapter.loadArg(0);
    // FUTURE keyword:encodefore remove
    if (doEncode)
        adapter.checkCast(Types.PAGE_CONTEXT_IMPL);
    ExprString es = bc.getFactory().toExprString(expr);
    boolean usedExternalizer = false;
    if (!usedExternalizer)
        es.writeOut(bc, Expression.MODE_REF);
    if (doEncode) {
        if (encodeForIsInt) {
            encodeFor.writeOut(bc, Expression.MODE_VALUE);
            adapter.visitInsn(Opcodes.I2S);
            // FUTURE keyword:encodefore remove _IMPL
            adapter.invokeVirtual(Types.PAGE_CONTEXT_IMPL, METHOD_WRITE_ENCODE_SHORT);
        } else {
            encodeFor.writeOut(bc, Expression.MODE_REF);
            // FUTURE keyword:encodefore remove _IMPL
            adapter.invokeVirtual(Types.PAGE_CONTEXT_IMPL, METHOD_WRITE_ENCODE_STRING);
        }
    } else
        adapter.invokeVirtual(Types.PAGE_CONTEXT, checkPSQ ? METHOD_WRITE_PSQ : METHOD_WRITE);
}
Also used : ExprString(lucee.transformer.expression.ExprString) GeneratorAdapter(org.objectweb.asm.commons.GeneratorAdapter)

Example 8 with ExprString

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

the class CastBoolean 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 ExprDouble) {
        expr.writeOut(bc, MODE_VALUE);
        if (mode == MODE_VALUE)
            adapter.invokeStatic(Types.CASTER, Methods.METHOD_TO_BOOLEAN_VALUE_FROM_DOUBLE);
        else
            adapter.invokeStatic(Types.CASTER, Methods.METHOD_TO_BOOLEAN_FROM_DOUBLE);
    } else if (expr instanceof ExprString) {
        expr.writeOut(bc, MODE_REF);
        if (mode == MODE_VALUE)
            adapter.invokeStatic(Types.CASTER, Methods.METHOD_TO_BOOLEAN_VALUE_FROM_STRING);
        else
            adapter.invokeStatic(Types.CASTER, Methods.METHOD_TO_BOOLEAN_FROM_STRING);
    } else {
        Type rtn = expr.writeOut(bc, mode);
        if (mode == MODE_VALUE) {
            if (!Types.isPrimitiveType(rtn)) {
                adapter.invokeStatic(Types.CASTER, Methods.METHOD_TO_BOOLEAN_VALUE);
            } else if (Types.BOOLEAN_VALUE.equals(rtn)) {
            } else if (Types.DOUBLE_VALUE.equals(rtn)) {
                adapter.invokeStatic(Types.CASTER, Methods.METHOD_TO_BOOLEAN_VALUE_FROM_DOUBLE);
            } else {
                adapter.invokeStatic(Types.CASTER, new Method("toRef", Types.toRefType(rtn), new Type[] { rtn }));
                adapter.invokeStatic(Types.CASTER, Methods.METHOD_TO_BOOLEAN_VALUE);
            }
        // return Types.BOOLEAN_VALUE;
        } else {
            if (Types.BOOLEAN.equals(rtn)) {
            } else
                adapter.invokeStatic(Types.CASTER, Methods.METHOD_TO_BOOLEAN);
        }
    }
    if (mode == MODE_VALUE)
        return Types.BOOLEAN_VALUE;
    return Types.BOOLEAN;
}
Also used : Type(org.objectweb.asm.Type) ExprDouble(lucee.transformer.expression.ExprDouble) ExprString(lucee.transformer.expression.ExprString) GeneratorAdapter(org.objectweb.asm.commons.GeneratorAdapter) Method(org.objectweb.asm.commons.Method)

Example 9 with ExprString

use of lucee.transformer.expression.ExprString 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 10 with ExprString

use of lucee.transformer.expression.ExprString 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)

Aggregations

ExprString (lucee.transformer.expression.ExprString)22 LitString (lucee.transformer.expression.literal.LitString)15 Expression (lucee.transformer.expression.Expression)9 GeneratorAdapter (org.objectweb.asm.commons.GeneratorAdapter)8 Type (org.objectweb.asm.Type)6 TemplateException (lucee.runtime.exp.TemplateException)4 FunctionAsExpression (lucee.transformer.bytecode.expression.FunctionAsExpression)4 Attribute (lucee.transformer.bytecode.statement.tag.Attribute)4 Variable (lucee.transformer.expression.var.Variable)4 Method (org.objectweb.asm.commons.Method)4 OpVariable (lucee.transformer.bytecode.op.OpVariable)3 EvaluatorException (lucee.transformer.cfml.evaluator.EvaluatorException)3 ExprBoolean (lucee.transformer.expression.ExprBoolean)3 ExprDouble (lucee.transformer.expression.ExprDouble)3 DataMember (lucee.transformer.expression.var.DataMember)3 Member (lucee.transformer.expression.var.Member)3 Position (lucee.transformer.Position)2 TransformerException (lucee.transformer.TransformerException)2 Body (lucee.transformer.bytecode.Body)2 Argument (lucee.transformer.bytecode.expression.var.Argument)2