Search in sources :

Example 16 with Ref

use of lucee.runtime.interpreter.ref.Ref in project Lucee by lucee.

the class CFMLExpressionInterpreter method newOp.

private Ref newOp() throws PageException {
    int start = cfml.getPos();
    String name = null;
    cfml.removeSpace();
    // first identifier
    name = identifier(true);
    Ref refName = null;
    if (name != null) {
        StringBuilder fullName = new StringBuilder();
        fullName.append(name);
        // Loop over addional identifier
        while (cfml.isValidIndex()) {
            if (cfml.forwardIfCurrent('.')) {
                cfml.removeSpace();
                name = identifier(true);
                if (name == null)
                    throw new InterpreterException("invalid Component declaration");
                cfml.removeSpace();
                fullName.append('.');
                fullName.append(name);
            } else
                break;
        }
        refName = new LString(fullName.toString());
    } else {
        if (cfml.isCurrentQuoter())
            refName = string();
        if (refName == null) {
            cfml.setPos(start);
            return null;
        }
    }
    cfml.removeSpace();
    if (cfml.isCurrent('(')) {
        FunctionLibFunction function = fld.getFunction("_createComponent");
        Ref[] arguments = functionArg("_createComponent", true, function, ')');
        Ref[] args = new Ref[arguments.length + 1];
        for (int i = 0; i < arguments.length; i++) {
            args[i] = arguments[i];
        }
        args[args.length - 1] = refName;
        BIFCall bif = new BIFCall(function, args);
        cfml.removeSpace();
        return bif;
    }
    throw new InterpreterException("invalid Component declaration ");
}
Also used : Ref(lucee.runtime.interpreter.ref.Ref) FunctionLibFunction(lucee.transformer.library.function.FunctionLibFunction) BIFCall(lucee.runtime.interpreter.ref.func.BIFCall) LString(lucee.runtime.interpreter.ref.literal.LString) ParserString(lucee.commons.lang.ParserString) LString(lucee.runtime.interpreter.ref.literal.LString)

Example 17 with Ref

use of lucee.runtime.interpreter.ref.Ref in project Lucee by lucee.

the class CFMLExpressionInterpreter method contOp.

private Ref contOp() throws PageException {
    Ref ref = impOp();
    while (cfml.forwardIfCurrent('?')) {
        cfml.removeSpace();
        if (cfml.forwardIfCurrent(':')) {
            cfml.removeSpace();
            Ref right = assignOp();
            ref = new Elvis(ref, right, limited);
        } else {
            Ref left = assignOp();
            if (!cfml.forwardIfCurrent(':'))
                throw new InterpreterException("Syntax Error, invalid conditional operator [" + cfml.toString() + "]");
            cfml.removeSpace();
            Ref right = assignOp();
            ref = new Cont(ref, left, right, limited);
        }
    }
    return ref;
}
Also used : Ref(lucee.runtime.interpreter.ref.Ref) Cont(lucee.runtime.interpreter.ref.op.Cont) Elvis(lucee.runtime.interpreter.ref.op.Elvis)

Example 18 with Ref

use of lucee.runtime.interpreter.ref.Ref in project Lucee by lucee.

the class CFMLExpressionInterpreter method _div.

private Ref _div(Ref ref) throws PageException {
    // /=
    if (cfml.forwardIfCurrent('=')) {
        cfml.removeSpace();
        Ref right = assignOp();
        Ref res = preciseMath ? new BigDiv(ref, right, limited) : new Div(ref, right, limited);
        ref = new Assign(ref, res, limited);
    } else {
        cfml.removeSpace();
        ref = preciseMath ? new BigDiv(ref, expoOp(), limited) : new Div(ref, expoOp(), limited);
    }
    return ref;
}
Also used : BigDiv(lucee.runtime.interpreter.ref.op.BigDiv) IntDiv(lucee.runtime.interpreter.ref.op.IntDiv) Div(lucee.runtime.interpreter.ref.op.Div) BigIntDiv(lucee.runtime.interpreter.ref.op.BigIntDiv) Ref(lucee.runtime.interpreter.ref.Ref) BigDiv(lucee.runtime.interpreter.ref.op.BigDiv) Assign(lucee.runtime.interpreter.ref.var.Assign) DynAssign(lucee.runtime.interpreter.ref.var.DynAssign)

Example 19 with Ref

use of lucee.runtime.interpreter.ref.Ref in project Lucee by lucee.

the class MemberUtil method callWithNamedValues.

public static Object callWithNamedValues(PageContext pc, Object coll, Collection.Key methodName, Struct args, short type, String strType) throws PageException {
    Map<Key, FunctionLibFunction> members = getMembers(pc, type);
    FunctionLibFunction member = members.get(methodName);
    if (member != null) {
        List<FunctionLibFunctionArg> _args = member.getArg();
        FunctionLibFunctionArg arg;
        if (args.size() < _args.size()) {
            Object val;
            ArrayList<Ref> refs = new ArrayList<Ref>();
            arg = _args.get(0);
            refs.add(new Casting(arg.getTypeAsString(), arg.getType(), new LFunctionValue(new LString(arg.getName()), coll)));
            for (int y = 1; y < _args.size(); y++) {
                arg = _args.get(y);
                // match by name
                val = args.get(arg.getName(), null);
                // match by alias
                if (val == null) {
                    String alias = arg.getAlias();
                    if (!StringUtil.isEmpty(alias, true)) {
                        String[] aliases = lucee.runtime.type.util.ListUtil.trimItems(lucee.runtime.type.util.ListUtil.listToStringArray(alias, ','));
                        for (int x = 0; x < aliases.length; x++) {
                            val = args.get(aliases[x], null);
                            if (val != null)
                                break;
                        }
                    }
                }
                if (val == null) {
                    if (arg.getRequired()) {
                        String[] names = member.getMemberNames();
                        String n = ArrayUtil.isEmpty(names) ? "" : names[0];
                        throw new ExpressionException("missing required argument [" + arg.getName() + "] for member function call [" + n + "]");
                    }
                } else {
                    refs.add(new Casting(arg.getTypeAsString(), arg.getType(), new LFunctionValue(new LString(arg.getName()), val)));
                // refs.add(new LFunctionValue(new LString(arg.getName()),new Casting(pc,arg.getTypeAsString(),arg.getType(),val)));
                }
            }
            return new BIFCall(coll, member, refs.toArray(new Ref[refs.size()])).getValue(pc);
        }
    }
    throw new ExpressionException("No matching function member [" + methodName + "] for call with named arguments found, available function members are [" + lucee.runtime.type.util.ListUtil.sort(CollectionUtil.getKeyList(members.keySet().iterator(), ","), "textnocase", "asc", ",") + "]");
}
Also used : ArrayList(java.util.ArrayList) LString(lucee.runtime.interpreter.ref.literal.LString) LString(lucee.runtime.interpreter.ref.literal.LString) ExpressionException(lucee.runtime.exp.ExpressionException) Casting(lucee.runtime.interpreter.ref.cast.Casting) Ref(lucee.runtime.interpreter.ref.Ref) FunctionLibFunction(lucee.transformer.library.function.FunctionLibFunction) LFunctionValue(lucee.runtime.interpreter.ref.literal.LFunctionValue) BIFCall(lucee.runtime.interpreter.ref.func.BIFCall) Key(lucee.runtime.type.Collection.Key) FunctionLibFunctionArg(lucee.transformer.library.function.FunctionLibFunctionArg)

Example 20 with Ref

use of lucee.runtime.interpreter.ref.Ref in project Lucee by lucee.

the class BIF method call.

@Override
public Object call(PageContext pageContext, Object[] args, boolean doIncludePath) throws PageException {
    ArrayList<FunctionLibFunctionArg> flfas = flf.getArg();
    FunctionLibFunctionArg flfa;
    List<Ref> refs = new ArrayList<Ref>();
    for (int i = 0; i < args.length; i++) {
        if (i >= flfas.size())
            throw new ApplicationException("too many Attributes in function call [" + flf.getName() + "]");
        flfa = flfas.get(i);
        refs.add(new Casting(flfa.getTypeAsString(), flfa.getType(), args[i]));
    }
    BIFCall call = new BIFCall(flf, refs.toArray(new Ref[refs.size()]));
    return call.getValue(pageContext);
}
Also used : Casting(lucee.runtime.interpreter.ref.cast.Casting) Ref(lucee.runtime.interpreter.ref.Ref) ApplicationException(lucee.runtime.exp.ApplicationException) ArrayList(java.util.ArrayList) BIFCall(lucee.runtime.interpreter.ref.func.BIFCall) FunctionLibFunctionArg(lucee.transformer.library.function.FunctionLibFunctionArg)

Aggregations

Ref (lucee.runtime.interpreter.ref.Ref)34 Assign (lucee.runtime.interpreter.ref.var.Assign)9 DynAssign (lucee.runtime.interpreter.ref.var.DynAssign)9 ArrayList (java.util.ArrayList)6 Casting (lucee.runtime.interpreter.ref.cast.Casting)6 BIFCall (lucee.runtime.interpreter.ref.func.BIFCall)6 LString (lucee.runtime.interpreter.ref.literal.LString)6 FunctionLibFunctionArg (lucee.transformer.library.function.FunctionLibFunctionArg)5 ParserString (lucee.commons.lang.ParserString)4 FunctionLibFunction (lucee.transformer.library.function.FunctionLibFunction)4 ExpressionException (lucee.runtime.exp.ExpressionException)3 LFunctionValue (lucee.runtime.interpreter.ref.literal.LFunctionValue)3 BigPlus (lucee.runtime.interpreter.ref.op.BigPlus)3 Plus (lucee.runtime.interpreter.ref.op.Plus)3 BigIntDiv (lucee.runtime.interpreter.ref.op.BigIntDiv)2 BigMinus (lucee.runtime.interpreter.ref.op.BigMinus)2 Concat (lucee.runtime.interpreter.ref.op.Concat)2 IntDiv (lucee.runtime.interpreter.ref.op.IntDiv)2 Minus (lucee.runtime.interpreter.ref.op.Minus)2 Key (lucee.runtime.type.Collection.Key)2