Search in sources :

Example 6 with Casting

use of lucee.runtime.interpreter.ref.cast.Casting in project Lucee by lucee.

the class CFMLExpressionInterpreter method negateMinusOp.

/**
 * Liest die Vordlobe einer Zahl ein
 * @return CFXD Element
 * @throws PageException
 */
private Ref negateMinusOp() throws PageException {
    // And Operation
    if (cfml.forwardIfCurrent('-')) {
        if (cfml.forwardIfCurrent('-')) {
            cfml.removeSpace();
            Ref expr = clip();
            Ref res = preciseMath ? new BigMinus(expr, new LNumber(new Double(1)), limited) : new Minus(expr, new LNumber(new Double(1)), limited);
            return new Assign(expr, res, limited);
        }
        cfml.removeSpace();
        return new Negate(clip(), limited);
    }
    if (cfml.forwardIfCurrent('+')) {
        if (cfml.forwardIfCurrent('+')) {
            cfml.removeSpace();
            Ref expr = clip();
            Ref res = preciseMath ? new BigPlus(expr, new LNumber(new Double(1)), limited) : new Plus(expr, new LNumber(new Double(1)), limited);
            return new Assign(expr, res, limited);
        }
        cfml.removeSpace();
        return new Casting("numeric", CFTypes.TYPE_NUMERIC, clip());
    }
    return clip();
}
Also used : Casting(lucee.runtime.interpreter.ref.cast.Casting) Ref(lucee.runtime.interpreter.ref.Ref) LNumber(lucee.runtime.interpreter.ref.literal.LNumber) BigPlus(lucee.runtime.interpreter.ref.op.BigPlus) Assign(lucee.runtime.interpreter.ref.var.Assign) DynAssign(lucee.runtime.interpreter.ref.var.DynAssign) Negate(lucee.runtime.interpreter.ref.op.Negate) Plus(lucee.runtime.interpreter.ref.op.Plus) BigPlus(lucee.runtime.interpreter.ref.op.BigPlus) BigMinus(lucee.runtime.interpreter.ref.op.BigMinus) BigMinus(lucee.runtime.interpreter.ref.op.BigMinus) Minus(lucee.runtime.interpreter.ref.op.Minus)

Example 7 with Casting

use of lucee.runtime.interpreter.ref.cast.Casting in project Lucee by lucee.

the class VT method isNamed.

private boolean isNamed(PageContext pc, Ref[] refArgs) throws PageException {
    if (ArrayUtil.isEmpty(refArgs))
        return false;
    Casting cast;
    int count = 0;
    for (int i = 0; i < refArgs.length; i++) {
        if (refArgs[i] instanceof Casting) {
            cast = (Casting) refArgs[i];
            if (cast.getRef() instanceof LFunctionValue && ((LFunctionValue) cast.getRef()).getValue(pc) instanceof FunctionValue) {
                count++;
            }
        }
    }
    if (count != 0 && count != refArgs.length) {
        ExpressionException ee = new InterpreterException("invalid argument for function " + flf.getName() + ", you can not mix named and unnamed arguments");
        UDFUtil.addFunctionDoc(ee, flf);
        throw ee;
    }
    return count != 0;
}
Also used : Casting(lucee.runtime.interpreter.ref.cast.Casting) InterpreterException(lucee.runtime.interpreter.InterpreterException) LFunctionValue(lucee.runtime.interpreter.ref.literal.LFunctionValue) FunctionValue(lucee.runtime.type.FunctionValue) LFunctionValue(lucee.runtime.interpreter.ref.literal.LFunctionValue) ExpressionException(lucee.runtime.exp.ExpressionException)

Example 8 with Casting

use of lucee.runtime.interpreter.ref.cast.Casting in project Lucee by lucee.

the class VT method getValue.

@Override
public Object getValue(PageContext pc) throws PageException {
    Object[] arguments = null;
    if (isDynamic()) {
        arguments = RefUtil.getValue(pc, refArgs);
        if (flf.hasDefaultValues()) {
            List<Object> tmp = new ArrayList<Object>();
            ArrayList<FunctionLibFunctionArg> args = flf.getArg();
            Iterator<FunctionLibFunctionArg> it = args.iterator();
            FunctionLibFunctionArg arg;
            while (it.hasNext()) {
                arg = it.next();
                if (arg.getDefaultValue() != null)
                    tmp.add(new FunctionValueImpl(arg.getName(), arg.getDefaultValue()));
            }
            for (int i = 0; i < arguments.length; i++) {
                tmp.add(arguments[i]);
            }
            arguments = tmp.toArray();
        }
        arguments = new Object[] { arguments };
    } else {
        if (isNamed(pc, refArgs)) {
            FunctionValue[] fvalues = getFunctionValues(pc, refArgs);
            String[] names = getNames(fvalues);
            ArrayList<FunctionLibFunctionArg> list = flf.getArg();
            Iterator<FunctionLibFunctionArg> it = list.iterator();
            arguments = new Object[list.size()];
            FunctionLibFunctionArg flfa;
            int index = 0;
            VT vt;
            while (it.hasNext()) {
                flfa = it.next();
                vt = getMatchingValueAndType(flfa, fvalues, names);
                if (vt.index != -1)
                    names[vt.index] = null;
                arguments[index++] = new Casting(vt.type, CFTypes.toShort(vt.type, false, CFTypes.TYPE_UNKNOW), vt.value).getValue(pc);
            }
            for (int y = 0; y < names.length; y++) {
                if (names[y] != null) {
                    ExpressionException ee = new InterpreterException("argument [" + names[y] + "] is not allowed for function [" + flf.getName() + "]");
                    UDFUtil.addFunctionDoc(ee, flf);
                    throw ee;
                }
            }
        } else {
            arguments = RefUtil.getValue(pc, refArgs);
        }
    }
    BIF bif = flf.getBIF();
    if (flf.getMemberChaining() && obj != null) {
        bif.invoke(pc, arguments);
        return obj;
    }
    if (!isDynamic() && flf.getArgMin() > arguments.length) {
        throw new FunctionException(pc, flf.getName(), flf.getArgMin(), flf.getArgMax(), arguments.length);
    }
    return Caster.castTo(pc, flf.getReturnTypeAsString(), bif.invoke(pc, arguments), false);
}
Also used : InterpreterException(lucee.runtime.interpreter.InterpreterException) ArrayList(java.util.ArrayList) FunctionException(lucee.runtime.exp.FunctionException) ExpressionException(lucee.runtime.exp.ExpressionException) Casting(lucee.runtime.interpreter.ref.cast.Casting) LFunctionValue(lucee.runtime.interpreter.ref.literal.LFunctionValue) FunctionValue(lucee.runtime.type.FunctionValue) FunctionLibFunctionArg(lucee.transformer.library.function.FunctionLibFunctionArg) FunctionValueImpl(lucee.runtime.type.FunctionValueImpl) BIF(lucee.runtime.ext.function.BIF)

Aggregations

Casting (lucee.runtime.interpreter.ref.cast.Casting)8 ArrayList (java.util.ArrayList)6 Ref (lucee.runtime.interpreter.ref.Ref)6 FunctionLibFunctionArg (lucee.transformer.library.function.FunctionLibFunctionArg)6 ExpressionException (lucee.runtime.exp.ExpressionException)5 BIFCall (lucee.runtime.interpreter.ref.func.BIFCall)4 LFunctionValue (lucee.runtime.interpreter.ref.literal.LFunctionValue)4 LString (lucee.runtime.interpreter.ref.literal.LString)3 InterpreterException (lucee.runtime.interpreter.InterpreterException)2 Key (lucee.runtime.type.Collection.Key)2 FunctionValue (lucee.runtime.type.FunctionValue)2 FunctionLibFunction (lucee.transformer.library.function.FunctionLibFunction)2 Entry (java.util.Map.Entry)1 ApplicationException (lucee.runtime.exp.ApplicationException)1 FunctionException (lucee.runtime.exp.FunctionException)1 BIF (lucee.runtime.ext.function.BIF)1 LNumber (lucee.runtime.interpreter.ref.literal.LNumber)1 BigMinus (lucee.runtime.interpreter.ref.op.BigMinus)1 BigPlus (lucee.runtime.interpreter.ref.op.BigPlus)1 Minus (lucee.runtime.interpreter.ref.op.Minus)1