Search in sources :

Example 11 with ExprString

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

the class CastInt 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 ExprString) {
        expr.writeOut(bc, MODE_REF);
        if (mode == MODE_VALUE)
            adapter.invokeStatic(Types.CASTER, Methods.METHOD_TO_INT_VALUE_FROM_STRING);
        else
            adapter.invokeStatic(Types.CASTER, Methods.METHOD_TO_INTEGER_FROM_STRING);
    } else {
        Type rtn = expr.writeOut(bc, mode);
        if (mode == MODE_VALUE) {
            if (!Types.isPrimitiveType(rtn)) {
                adapter.invokeStatic(Types.CASTER, Methods.METHOD_TO_INT_VALUE);
            } else if (Types.BOOLEAN_VALUE.equals(rtn)) {
                adapter.invokeStatic(Types.CASTER, Methods.METHOD_TO_INT_VALUE_FROM_BOOLEAN);
            } else if (Types.SHORT_VALUE.equals(rtn)) {
            // No Cast needed
            } else if (Types.FLOAT_VALUE.equals(rtn)) {
                adapter.cast(Types.FLOAT_VALUE, Types.INT_VALUE);
            } else if (Types.LONG_VALUE.equals(rtn)) {
                adapter.cast(Types.LONG_VALUE, Types.INT_VALUE);
            } else if (Types.DOUBLE_VALUE.equals(rtn)) {
                adapter.cast(Types.DOUBLE_VALUE, Types.INT_VALUE);
            } else if (Types.INT_VALUE.equals(rtn)) {
            // No Cast needed
            } else {
                adapter.invokeStatic(Types.CASTER, new Method("toRef", Types.toRefType(rtn), new Type[] { rtn }));
                adapter.invokeStatic(Types.CASTER, Methods.METHOD_TO_INT_VALUE);
            }
            return Types.INT_VALUE;
        } else if (Types.isPrimitiveType(rtn)) {
            if (Types.DOUBLE_VALUE.equals(rtn)) {
                adapter.invokeStatic(Types.CASTER, Methods.METHOD_TO_INTEGER_FROM_DOUBLE);
            } else if (Types.BOOLEAN_VALUE.equals(rtn)) {
                adapter.invokeStatic(Types.CASTER, Methods.METHOD_TO_INTEGER_FROM_BOOLEAN);
            } else {
                adapter.invokeStatic(Types.CASTER, new Method("toRef", Types.toRefType(rtn), new Type[] { rtn }));
                adapter.invokeStatic(Types.CASTER, Methods.METHOD_TO_INTEGER);
            }
            return Types.INTEGER;
        }
        if (!Types.INTEGER.equals(rtn))
            adapter.invokeStatic(Types.CASTER, Methods.METHOD_TO_INTEGER);
        return Types.INTEGER;
    }
    if (mode == MODE_VALUE)
        return Types.INT_VALUE;
    return Types.INTEGER;
}
Also used : Type(org.objectweb.asm.Type) ExprString(lucee.transformer.expression.ExprString) GeneratorAdapter(org.objectweb.asm.commons.GeneratorAdapter) Method(org.objectweb.asm.commons.Method)

Example 12 with ExprString

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

the class VT method _writeOut.

private Type _writeOut(BytecodeContext bc, int mode, Boolean asCollection) throws TransformerException {
    final GeneratorAdapter adapter = bc.getAdapter();
    final int count = countFM + countDM;
    // count 0
    if (count == 0)
        return _writeOutEmpty(bc);
    boolean doOnlyScope = scope == Scope.SCOPE_LOCAL;
    // boolean last;
    int c = 0;
    for (int i = doOnlyScope ? 0 : 1; i < count; i++) {
        Member member = (members.get((count - 1) - c));
        c++;
        adapter.loadArg(0);
        if (member.getSafeNavigated() && member instanceof UDF)
            adapter.checkCast(Types.PAGE_CONTEXT_IMPL);
    }
    Type rtn = _writeOutFirst(bc, (members.get(0)), mode, count == 1, doOnlyScope, null, null);
    // pc.get(
    for (int i = doOnlyScope ? 0 : 1; i < count; i++) {
        Member member = (members.get(i));
        boolean last = (i + 1) == count;
        // Data Member
        if (member instanceof DataMember) {
            ExprString name = ((DataMember) member).getName();
            if (last && ASMUtil.isDotKey(name)) {
                LitString ls = (LitString) name;
                if (ls.getString().equalsIgnoreCase("RECORDCOUNT")) {
                    adapter.invokeStatic(Types.VARIABLE_UTIL_IMPL, RECORDCOUNT);
                } else if (ls.getString().equalsIgnoreCase("CURRENTROW")) {
                    adapter.invokeStatic(Types.VARIABLE_UTIL_IMPL, CURRENTROW);
                } else if (ls.getString().equalsIgnoreCase("COLUMNLIST")) {
                    adapter.invokeStatic(Types.VARIABLE_UTIL_IMPL, COLUMNLIST);
                } else {
                    getFactory().registerKey(bc, name, false);
                    // safe nav
                    int type;
                    if (member.getSafeNavigated()) {
                        Expression val = member.getSafeNavigatedValue();
                        if (val == null)
                            ASMConstants.NULL(adapter);
                        else
                            val.writeOut(bc, Expression.MODE_REF);
                        type = THREE;
                    } else
                        type = TWO;
                    adapter.invokeVirtual(Types.PAGE_CONTEXT, asCollection(asCollection, last) ? GET_COLLECTION[type] : GET[type]);
                }
            } else {
                getFactory().registerKey(bc, name, false);
                // safe nav
                int type;
                if (member.getSafeNavigated()) {
                    Expression val = member.getSafeNavigatedValue();
                    if (val == null)
                        ASMConstants.NULL(adapter);
                    else
                        val.writeOut(bc, Expression.MODE_REF);
                    type = THREE;
                } else
                    type = TWO;
                adapter.invokeVirtual(Types.PAGE_CONTEXT, asCollection(asCollection, last) ? GET_COLLECTION[type] : GET[type]);
            }
            rtn = Types.OBJECT;
        } else // UDF
        if (member instanceof UDF) {
            rtn = _writeOutUDF(bc, (UDF) member);
        }
    }
    return rtn;
}
Also used : LitString(lucee.transformer.expression.literal.LitString) Type(org.objectweb.asm.Type) ExprString(lucee.transformer.expression.ExprString) Expression(lucee.transformer.expression.Expression) DataMember(lucee.transformer.expression.var.DataMember) GeneratorAdapter(org.objectweb.asm.commons.GeneratorAdapter) DataMember(lucee.transformer.expression.var.DataMember) Member(lucee.transformer.expression.var.Member)

Example 13 with ExprString

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

the class LitStringImpl method _toExpr.

private static ExprString _toExpr(Factory factory, String str) {
    int size = str.length() / 2;
    String l = str.substring(0, size);
    String r = str.substring(size);
    ExprString left = toBig(l) ? _toExpr(factory, l) : factory.createLitString(l);
    ExprString right = toBig(r) ? _toExpr(factory, r) : factory.createLitString(r);
    return OpString.toExprString(left, right, false);
}
Also used : ExprString(lucee.transformer.expression.ExprString) LitString(lucee.transformer.expression.literal.LitString) OpString(lucee.transformer.bytecode.op.OpString) ExprString(lucee.transformer.expression.ExprString)

Example 14 with ExprString

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

the class AbstrCFMLExprTransformer method readComponentPath.

private ExprString readComponentPath(ExprData data) throws TemplateException {
    // first identifier
    String name = identifier(data, true);
    if (name != null) {
        StringBuilder fullName = new StringBuilder();
        fullName.append(name);
        // Loop over addional identifier
        while (data.srcCode.isValidIndex()) {
            if (data.srcCode.forwardIfCurrent('.')) {
                comments(data);
                name = identifier(data, true);
                if (name == null)
                    return null;
                fullName.append('.');
                fullName.append(name);
                comments(data);
            } else
                break;
        }
        return data.factory.createLitString(fullName.toString());
    }
    Expression str = string(data);
    if (str != null) {
        return data.factory.toExprString(str);
    }
    return null;
}
Also used : FunctionAsExpression(lucee.transformer.bytecode.expression.FunctionAsExpression) Expression(lucee.transformer.expression.Expression) LitString(lucee.transformer.expression.literal.LitString) ExprString(lucee.transformer.expression.ExprString)

Example 15 with ExprString

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

the class AbstrCFMLExprTransformer method staticScope.

private Expression staticScope(ExprData data, Expression expr) throws TemplateException {
    if (data.srcCode.forwardIfCurrent("::")) {
        if (!(expr instanceof Variable))
            throw new TemplateException(data.srcCode, "invalid syntax before [::]");
        Variable old = (Variable) expr;
        // set back to read again as a component path
        data.srcCode.setPos(old.getStart().pos);
        // now we read the component path
        ExprString componentPath = readComponentPath(data);
        if (!data.srcCode.forwardIfCurrent("::"))
            throw new TemplateException(data.srcCode, "invalid syntax before [::]" + data.srcCode.getCurrent());
        comments(data);
        BIF bif = null;
        if (componentPath instanceof LitString) {
            LitString ls = (LitString) componentPath;
            if ("super".equalsIgnoreCase(ls.getString())) {
                bif = ASMUtil.createBif(data, GET_SUPER_STATIC_SCOPE);
            }
        }
        // now we generate a _getStaticScope function call with that path
        if (bif == null) {
            bif = ASMUtil.createBif(data, GET_STATIC_SCOPE);
            bif.addArgument(new Argument(componentPath, "string"));
        }
        Variable var = data.factory.createVariable(old.getStart(), data.srcCode.getPosition());
        var.addMember(bif);
        // now we are reading what is coming after ":::"
        Expression sd = subDynamic(data, var, false, true);
        return sd;
    }
    return null;
}
Also used : LitString(lucee.transformer.expression.literal.LitString) OpVariable(lucee.transformer.bytecode.op.OpVariable) Variable(lucee.transformer.expression.var.Variable) NamedArgument(lucee.transformer.bytecode.expression.var.NamedArgument) Argument(lucee.transformer.bytecode.expression.var.Argument) TemplateException(lucee.runtime.exp.TemplateException) ExprString(lucee.transformer.expression.ExprString) FunctionAsExpression(lucee.transformer.bytecode.expression.FunctionAsExpression) Expression(lucee.transformer.expression.Expression) BIF(lucee.transformer.bytecode.expression.var.BIF)

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