Search in sources :

Example 6 with FunctionLibFunction

use of lucee.transformer.library.function.FunctionLibFunction in project Lucee by lucee.

the class AbstrCFMLExprTransformer method json.

protected Expression json(ExprData data, FunctionLibFunction flf, char start, char end) throws TemplateException {
    if (!data.srcCode.forwardIfCurrent(start))
        return null;
    Position line = data.srcCode.getPosition();
    data.srcCode.removeSpace();
    // [:|=]
    if (data.srcCode.forwardIfCurrent(':', ']') || data.srcCode.forwardIfCurrent('=', ']')) {
        flf = flf.getFunctionLib().getFunction("_literalOrderedStruct");
        BIF bif = new BIF(data.factory, data.settings, flf);
        bif.setArgType(flf.getArgType());
        try {
            bif.setClassDefinition(flf.getFunctionClassDefinition());
        } catch (Throwable t) {
            ExceptionUtil.rethrowIfNecessary(t);
            throw new PageRuntimeException(t);
        }
        bif.setReturnType(flf.getReturnTypeAsString());
        data.ep.add(flf, bif, data.srcCode);
        Variable var = data.factory.createVariable(line, data.srcCode.getPosition());
        var.addMember(bif);
        return var;
    }
    BIF bif = new BIF(data.factory, data.settings, flf);
    bif.setArgType(flf.getArgType());
    try {
        bif.setClassDefinition(flf.getFunctionClassDefinition());
    } catch (Throwable t) {
        ExceptionUtil.rethrowIfNecessary(t);
        throw new PageRuntimeException(t);
    }
    bif.setReturnType(flf.getReturnTypeAsString());
    do {
        comments(data);
        if (data.srcCode.isCurrent(end))
            break;
        bif.addArgument(functionArgument(data, data.settings.dotNotationUpper));
        comments(data);
    } while (data.srcCode.forwardIfCurrent(','));
    comments(data);
    if (!data.srcCode.forwardIfCurrent(end))
        throw new TemplateException(data.srcCode, "Invalid Syntax Closing [" + end + "] not found");
    comments(data);
    if (flf.hasTteClass()) {
        FunctionLibFunction tmp = flf.getEvaluator().pre(bif, flf);
        if (tmp != null && tmp != flf) {
            bif.setFlf(flf = tmp);
            bif.setArgType(flf.getArgType());
            try {
                bif.setClassDefinition(flf.getFunctionClassDefinition());
            } catch (Throwable t) {
                ExceptionUtil.rethrowIfNecessary(t);
                throw new PageRuntimeException(t);
            }
            bif.setReturnType(flf.getReturnTypeAsString());
        }
    }
    data.ep.add(flf, bif, data.srcCode);
    Variable var = data.factory.createVariable(line, data.srcCode.getPosition());
    var.addMember(bif);
    return var;
}
Also used : OpVariable(lucee.transformer.bytecode.op.OpVariable) Variable(lucee.transformer.expression.var.Variable) Position(lucee.transformer.Position) TemplateException(lucee.runtime.exp.TemplateException) FunctionLibFunction(lucee.transformer.library.function.FunctionLibFunction) PageRuntimeException(lucee.runtime.exp.PageRuntimeException) BIF(lucee.transformer.bytecode.expression.var.BIF)

Example 7 with FunctionLibFunction

use of lucee.transformer.library.function.FunctionLibFunction 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 8 with FunctionLibFunction

use of lucee.transformer.library.function.FunctionLibFunction 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 9 with FunctionLibFunction

use of lucee.transformer.library.function.FunctionLibFunction in project Lucee by lucee.

the class GetFunctionData method _call.

private static Struct _call(PageContext pc, String strFunctionName, int dialect) throws PageException {
    FunctionLib[] flds;
    flds = ((ConfigImpl) pc.getConfig()).getFLDs(dialect);
    FunctionLibFunction function = null;
    for (int i = 0; i < flds.length; i++) {
        function = flds[i].getFunction(strFunctionName.toLowerCase());
        if (function != null)
            break;
    }
    if (function == null)
        throw new ExpressionException("function [" + strFunctionName + "] is not a built in function");
    // CFML Based Function
    Class clazz = null;
    try {
        clazz = function.getFunctionClassDefinition().getClazz();
    } catch (Throwable t) {
        ExceptionUtil.rethrowIfNecessary(t);
    }
    if (clazz == lucee.runtime.functions.system.CFFunction.class) {
        return cfmlBasedFunction(pc, function);
    }
    return javaBasedFunction(function);
}
Also used : FunctionLibFunction(lucee.transformer.library.function.FunctionLibFunction) FunctionLib(lucee.transformer.library.function.FunctionLib) ExpressionException(lucee.runtime.exp.ExpressionException)

Example 10 with FunctionLibFunction

use of lucee.transformer.library.function.FunctionLibFunction in project Lucee by lucee.

the class GetFunctionList method _call.

private static lucee.runtime.type.Struct _call(PageContext pc, int dialect) throws PageException {
    Struct sct = new StructImpl();
    // synchronized(sct) {
    // hasSet=true;
    FunctionLib[] flds;
    flds = ((ConfigImpl) pc.getConfig()).getFLDs(dialect);
    FunctionLibFunction func;
    Map<String, FunctionLibFunction> _functions;
    Iterator<Entry<String, FunctionLibFunction>> it;
    Entry<String, FunctionLibFunction> e;
    for (int i = 0; i < flds.length; i++) {
        _functions = flds[i].getFunctions();
        it = _functions.entrySet().iterator();
        while (it.hasNext()) {
            e = it.next();
            func = e.getValue();
            if (func.getStatus() != TagLib.STATUS_HIDDEN && func.getStatus() != TagLib.STATUS_UNIMPLEMENTED)
                sct.set(e.getKey(), "");
        }
    }
    return sct;
}
Also used : Entry(java.util.Map.Entry) StructImpl(lucee.runtime.type.StructImpl) FunctionLibFunction(lucee.transformer.library.function.FunctionLibFunction) FunctionLib(lucee.transformer.library.function.FunctionLib) Struct(lucee.runtime.type.Struct)

Aggregations

FunctionLibFunction (lucee.transformer.library.function.FunctionLibFunction)15 FunctionLib (lucee.transformer.library.function.FunctionLib)6 FunctionLibFunctionArg (lucee.transformer.library.function.FunctionLibFunctionArg)5 Ref (lucee.runtime.interpreter.ref.Ref)4 BIFCall (lucee.runtime.interpreter.ref.func.BIFCall)4 LString (lucee.runtime.interpreter.ref.literal.LString)4 ExpressionException (lucee.runtime.exp.ExpressionException)3 PageRuntimeException (lucee.runtime.exp.PageRuntimeException)3 TemplateException (lucee.runtime.exp.TemplateException)3 Key (lucee.runtime.type.Collection.Key)3 ArrayList (java.util.ArrayList)2 Entry (java.util.Map.Entry)2 ConfigWebImpl (lucee.runtime.config.ConfigWebImpl)2 CFFunction (lucee.runtime.functions.system.CFFunction)2 Casting (lucee.runtime.interpreter.ref.cast.Casting)2 Position (lucee.transformer.Position)2 BIF (lucee.transformer.bytecode.expression.var.BIF)2 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1