Search in sources :

Example 1 with Ref

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

the class BIF method callWithNamedValues.

@Override
public Object callWithNamedValues(PageContext pageContext, Struct values, boolean doIncludePath) throws PageException {
    ArrayList<FunctionLibFunctionArg> flfas = flf.getArg();
    Iterator<FunctionLibFunctionArg> it = flfas.iterator();
    FunctionLibFunctionArg arg;
    Object val;
    List<Ref> refs = new ArrayList<Ref>();
    while (it.hasNext()) {
        arg = it.next();
        // match by name
        val = values.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 = values.get(aliases[x], null);
                    if (val != null)
                        break;
                }
            }
        }
        if (val == null) {
            if (arg.getRequired()) {
                String[] names = flf.getMemberNames();
                String n = ArrayUtil.isEmpty(names) ? "" : names[0];
                throw new ExpressionException("missing required argument [" + arg.getName() + "] for build in function call [" + n + "]");
            }
        } else {
            refs.add(new Casting(arg.getTypeAsString(), arg.getType(), new LFunctionValue(new LString(arg.getName()), val)));
        }
    }
    BIFCall call = new BIFCall(flf, refs.toArray(new Ref[refs.size()]));
    return call.getValue(pageContext);
}
Also used : ArrayList(java.util.ArrayList) LString(lucee.runtime.interpreter.ref.literal.LString) ExpressionException(lucee.runtime.exp.ExpressionException) LString(lucee.runtime.interpreter.ref.literal.LString) Casting(lucee.runtime.interpreter.ref.cast.Casting) Ref(lucee.runtime.interpreter.ref.Ref) LFunctionValue(lucee.runtime.interpreter.ref.literal.LFunctionValue) BIFCall(lucee.runtime.interpreter.ref.func.BIFCall) FunctionLibFunctionArg(lucee.transformer.library.function.FunctionLibFunctionArg)

Example 2 with Ref

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

the class MemberUtil method call.

public static Object call(PageContext pc, Object coll, Collection.Key methodName, Object[] args, short[] types, String[] strTypes) throws PageException {
    // look for members
    short type;
    String strType;
    Map<Key, FunctionLibFunction> members = null;
    for (int i = 0; i < types.length; i++) {
        type = types[i];
        strType = strTypes[i];
        members = getMembers(pc, type);
        FunctionLibFunction member = members.get(methodName);
        if (member != null) {
            List<FunctionLibFunctionArg> _args = member.getArg();
            if (args.length < _args.size()) {
                ArrayList<Ref> refs = new ArrayList<Ref>();
                int pos = member.getMemberPosition();
                FunctionLibFunctionArg flfa;
                Iterator<FunctionLibFunctionArg> it = _args.iterator();
                int glbIndex = 0, argIndex = -1;
                while (it.hasNext()) {
                    glbIndex++;
                    flfa = it.next();
                    if (glbIndex == pos) {
                        refs.add(new Casting(strType, type, coll));
                    } else if (args.length > ++argIndex) {
                        // careful, argIndex is only incremented when condition above is false
                        refs.add(new Casting(flfa.getTypeAsString(), flfa.getType(), args[argIndex]));
                    }
                }
                return new BIFCall(coll, member, refs.toArray(new Ref[refs.size()])).getValue(pc);
            }
        }
    }
    // do reflection
    if (pc.getConfig().getSecurityManager().getAccess(lucee.runtime.security.SecurityManager.TYPE_DIRECT_JAVA_ACCESS) == lucee.runtime.security.SecurityManager.VALUE_YES) {
        if (!(coll instanceof Undefined)) {
            Object res = callMethod(coll, methodName, args);
            if (res != DEFAULT)
                return res;
        }
    }
    // merge
    if (types.length > 1) {
        Map<Key, FunctionLibFunction> tmp;
        members = null;
        for (int i = 0; i < types.length; i++) {
            tmp = getMembers(pc, types[i]);
            if (members == null)
                members = tmp;
            else {
                Iterator<Entry<Key, FunctionLibFunction>> it = tmp.entrySet().iterator();
                Entry<Key, FunctionLibFunction> e;
                while (it.hasNext()) {
                    e = it.next();
                    members.put(e.getKey(), e.getValue());
                }
            }
        }
    }
    Set<Key> set = members.keySet();
    String msg = ExceptionUtil.similarKeyMessage(set.toArray(new Key[set.size()]), methodName.getString(), "function", "functions", "Object", true);
    throw new ExpressionException(msg);
// throw new ExpressionException("No matching function member ["+methodName+"] found, available function members are ["+
// lucee.runtime.type.util.ListUtil.sort(CollectionUtil.getKeyList(members.keySet().iterator(), ","),"textnocase","asc",",")+"]");
}
Also used : Undefined(lucee.runtime.type.scope.Undefined) ArrayList(java.util.ArrayList) 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) Entry(java.util.Map.Entry) FunctionLibFunction(lucee.transformer.library.function.FunctionLibFunction) BIFCall(lucee.runtime.interpreter.ref.func.BIFCall) Key(lucee.runtime.type.Collection.Key) FunctionLibFunctionArg(lucee.transformer.library.function.FunctionLibFunctionArg)

Example 3 with Ref

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

the class CFMLExpressionInterpreter method functionArgDeclaration.

/**
 * Liest einen gelableten  Funktionsparamter ein
 * <br />
 * EBNF:<br />
 * <code>assignOp [":" spaces assignOp];</code>
 * @return CFXD Element
 * @throws PageException
 */
private Ref functionArgDeclaration() throws PageException {
    Ref ref = impOp();
    if (cfml.forwardIfCurrent(':') || cfml.forwardIfCurrent('=')) {
        cfml.removeSpace();
        ref = new LFunctionValue(ref, assignOp());
    }
    return ref;
}
Also used : Ref(lucee.runtime.interpreter.ref.Ref) LFunctionValue(lucee.runtime.interpreter.ref.literal.LFunctionValue)

Example 4 with Ref

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

the class CFMLExpressionInterpreter method startElement.

/**
 * Extrahiert den Start Element einer Variale,
 * dies ist entweder eine Funktion, eine Scope Definition oder eine undefinierte Variable.
 * <br />
 * EBNF:<br />
 * <code>identifier "(" functionArg ")" | scope | identifier;</code>
 * @param name Einstiegsname
 * @return CFXD Element
 * @throws PageException
 */
private Ref startElement(String name) throws PageException {
    // check function
    if (!limited && cfml.isCurrent('(')) {
        FunctionLibFunction function = fld.getFunction(name);
        Ref[] arguments = functionArg(name, true, function, ')');
        if (function != null)
            return new BIFCall(function, arguments);
        Ref ref = new lucee.runtime.interpreter.ref.var.Scope(Scope.SCOPE_UNDEFINED);
        return new UDFCall(ref, name, arguments);
    }
    // check scope
    return scope(name);
}
Also used : UDFCall(lucee.runtime.interpreter.ref.func.UDFCall) Ref(lucee.runtime.interpreter.ref.Ref) Scope(lucee.runtime.type.scope.Scope) FunctionLibFunction(lucee.transformer.library.function.FunctionLibFunction) BIFCall(lucee.runtime.interpreter.ref.func.BIFCall)

Example 5 with Ref

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

the class CFMLExpressionInterpreter method _minus.

private Ref _minus(Ref ref) throws PageException {
    // -=
    if (cfml.isCurrent('=')) {
        cfml.next();
        cfml.removeSpace();
        Ref right = assignOp();
        Ref res = preciseMath ? new BigMinus(ref, right, limited) : new Minus(ref, right, limited);
        ref = new Assign(ref, res, limited);
    } else {
        cfml.removeSpace();
        ref = preciseMath ? new BigMinus(ref, modOp(), limited) : new Minus(ref, modOp(), limited);
    }
    return ref;
}
Also used : Ref(lucee.runtime.interpreter.ref.Ref) Assign(lucee.runtime.interpreter.ref.var.Assign) DynAssign(lucee.runtime.interpreter.ref.var.DynAssign) BigMinus(lucee.runtime.interpreter.ref.op.BigMinus) BigMinus(lucee.runtime.interpreter.ref.op.BigMinus) Minus(lucee.runtime.interpreter.ref.op.Minus)

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