Search in sources :

Example 1 with BIF

use of lucee.transformer.bytecode.expression.var.BIF in project Lucee by lucee.

the class Output method addEncodeToChildren.

private void addEncodeToChildren(Iterator it, Expression encodeForValue, FunctionLibFunction encodeForBIF) {
    Statement stat;
    while (it.hasNext()) {
        stat = (Statement) it.next();
        if (stat instanceof PrintOut) {
            PrintOut printOut = ((PrintOut) stat);
            Expression e = removeCastString(printOut.getExpr());
            if (!(e instanceof Literal)) {
                if (e instanceof Variable) {
                    Member member = ((Variable) e).getFirstMember();
                    if (member instanceof BIF) {
                        BIF bif = (BIF) member;
                        String cn = bif.getClassDefinition().getClassName();
                        if (cn.startsWith(ENCODE_FOR) || cn.equals(ESAPIEncode.class.getName())) {
                            continue;
                        }
                    }
                }
                printOut.setEncodeFor(encodeForValue);
            }
        } else if (stat instanceof Tag) {
            Body b = ((Tag) stat).getBody();
            if (b != null)
                addEncodeToChildren(b.getStatements().iterator(), encodeForValue, encodeForBIF);
        } else if (stat instanceof Body) {
            addEncodeToChildren(((Body) stat).getStatements().iterator(), encodeForValue, encodeForBIF);
        }
    }
}
Also used : Variable(lucee.transformer.expression.var.Variable) PrintOut(lucee.transformer.bytecode.statement.PrintOut) Expression(lucee.transformer.expression.Expression) Statement(lucee.transformer.bytecode.Statement) Literal(lucee.transformer.expression.literal.Literal) CastString(lucee.transformer.bytecode.cast.CastString) TagLibTag(lucee.transformer.library.tag.TagLibTag) Tag(lucee.transformer.bytecode.statement.tag.Tag) Member(lucee.transformer.expression.var.Member) Body(lucee.transformer.bytecode.Body) BIF(lucee.transformer.bytecode.expression.var.BIF)

Example 2 with BIF

use of lucee.transformer.bytecode.expression.var.BIF in project Lucee by lucee.

the class ASMUtil method createBif.

public static BIF createBif(ExprData data, FunctionLibFunction flf) {
    BIF bif = new BIF(data.factory, data.settings, flf);
    data.ep.add(flf, bif, data.srcCode);
    bif.setArgType(flf.getArgType());
    try {
        bif.setClassDefinition(flf.getFunctionClassDefinition());
    } catch (Throwable t) {
        ExceptionUtil.rethrowIfNecessary(t);
        throw new PageRuntimeException(t);
    }
    bif.setReturnType(flf.getReturnTypeAsString());
    return bif;
}
Also used : PageRuntimeException(lucee.runtime.exp.PageRuntimeException) BIF(lucee.transformer.bytecode.expression.var.BIF)

Example 3 with BIF

use of lucee.transformer.bytecode.expression.var.BIF in project Lucee by lucee.

the class ASMUtil method cachedWithinValue.

public static Literal cachedWithinValue(Expression val) throws EvaluatorException {
    if (val instanceof Literal) {
        Literal l = (Literal) val;
        // double == days
        Double d = l.getDouble(null);
        if (d != null) {
            return val.getFactory().createLitLong(TimeSpanImpl.fromDays(d.doubleValue()).getMillis(), null, null);
        }
        return l;
    } else // createTimespan
    if (val instanceof Variable) {
        Variable var = (Variable) val;
        if (var.getMembers().size() == 1) {
            Member first = var.getFirstMember();
            if (first instanceof BIF) {
                BIF bif = (BIF) first;
                if ("createTimeSpan".equalsIgnoreCase(bif.getFlf().getName())) {
                    Argument[] args = bif.getArguments();
                    int len = ArrayUtil.size(args);
                    if (len >= 4 && len <= 5) {
                        double days = toDouble(args[0].getValue());
                        double hours = toDouble(args[1].getValue());
                        double minutes = toDouble(args[2].getValue());
                        double seconds = toDouble(args[3].getValue());
                        double millis = len == 5 ? toDouble(args[4].getValue()) : 0;
                        return val.getFactory().createLitLong(new TimeSpanImpl((int) days, (int) hours, (int) minutes, (int) seconds, (int) millis).getMillis(), null, null);
                    }
                }
            }
        }
    }
    throw cacheWithinException();
}
Also used : Variable(lucee.transformer.expression.var.Variable) Literal(lucee.transformer.expression.literal.Literal) TimeSpanImpl(lucee.runtime.type.dt.TimeSpanImpl) LitDouble(lucee.transformer.expression.literal.LitDouble) ExprDouble(lucee.transformer.expression.ExprDouble) DataMember(lucee.transformer.expression.var.DataMember) Member(lucee.transformer.expression.var.Member) BIF(lucee.transformer.bytecode.expression.var.BIF)

Example 4 with BIF

use of lucee.transformer.bytecode.expression.var.BIF in project Lucee by lucee.

the class AbstrCFMLExprTransformer method getFunctionMember.

/**
 * Liest die Argumente eines Funktonsaufruf ein und prueft ob die Funktion
 * innerhalb der FLD (Function Library Descriptor) definiert ist.
 * Falls sie existiert wird die Funktion gegen diese geprueft und ein build-in-function CFXD Element generiert,
 * ansonsten ein normales funcion-call Element.
 * <br />
 * EBNF:<br />
 * <code>[impOp{"," impOp}];</code>
 * @param name Identifier der Funktion als Zeichenkette
 * @param checkLibrary Soll geprueft werden ob die Funktion innerhalb der Library existiert.
 * @return CFXD Element
 * @throws TemplateException
 */
private FunctionMember getFunctionMember(ExprData data, final ExprString name, boolean checkLibrary) throws TemplateException {
    // get Function Library
    checkLibrary = checkLibrary && data.flibs != null;
    FunctionLibFunction flf = null;
    if (checkLibrary) {
        if (!(name instanceof Literal))
            // should never happen!
            throw new TemplateException(data.srcCode, "syntax error");
        for (int i = 0; i < data.flibs.length; i++) {
            flf = data.flibs[i].getFunction(((Literal) name).getString());
            if (flf != null)
                break;
        }
        if (flf == null) {
            checkLibrary = false;
        }
    }
    FunctionMember fm = null;
    while (true) {
        int pos = data.srcCode.getPos();
        // Element Function
        if (checkLibrary) {
            BIF bif = new BIF(data.factory, data.settings, flf);
            // TODO data.ep.add(flf, bif, data.srcCode);
            bif.setArgType(flf.getArgType());
            try {
                bif.setClassDefinition(flf.getFunctionClassDefinition());
            } catch (Throwable t) {
                ExceptionUtil.rethrowIfNecessary(t);
                throw new PageRuntimeException(t);
            }
            bif.setReturnType(flf.getReturnTypeAsString());
            fm = bif;
            if (flf.getArgType() == FunctionLibFunction.ARG_DYNAMIC && flf.hasDefaultValues()) {
                ArrayList<FunctionLibFunctionArg> args = flf.getArg();
                Iterator<FunctionLibFunctionArg> it = args.iterator();
                FunctionLibFunctionArg arg;
                while (it.hasNext()) {
                    arg = it.next();
                    if (arg.getDefaultValue() != null)
                        bif.addArgument(new NamedArgument(data.factory.createLitString(arg.getName()), data.factory.createLitString(arg.getDefaultValue()), arg.getTypeAsString(), false));
                }
            }
        } else {
            fm = new UDF(name);
        }
        int count = getFunctionMemberAttrs(data, name, checkLibrary, fm, flf);
        if (checkLibrary) {
            // pre
            if (flf.hasTteClass()) {
                FunctionLibFunction tmp = flf.getEvaluator().pre((BIF) fm, flf);
                if (tmp != null && tmp != flf) {
                    flf = tmp;
                    data.srcCode.setPos(pos);
                    continue;
                }
            }
            // check max attributes
            {
                boolean isDynamic = flf.getArgType() == FunctionLibFunction.ARG_DYNAMIC;
                int max = flf.getArgMax();
                // Dynamic
                if (isDynamic) {
                    if (max != -1 && max < fm.getArguments().length)
                        throw new TemplateException(data.srcCode, "too many Attributes (" + max + ":" + fm.getArguments().length + ") in function [ " + ASMUtil.display(name) + " ]");
                } else // Fix
                {
                    if (flf.getArg().size() < fm.getArguments().length) {
                        TemplateException te = new TemplateException(data.srcCode, "too many Attributes (" + flf.getArg().size() + ":" + fm.getArguments().length + ") in function call [" + ASMUtil.display(name) + "]");
                        UDFUtil.addFunctionDoc(te, flf);
                        throw te;
                    }
                }
            }
            // check min attributes
            if (flf.getArgMin() > count) {
                TemplateException te = new TemplateException(data.srcCode, "too few attributes in function [" + ASMUtil.display(name) + "]");
                if (flf.getArgType() == FunctionLibFunction.ARG_FIX)
                    UDFUtil.addFunctionDoc(te, flf);
                throw te;
            }
            // evaluator
            if (flf.hasTteClass()) {
                flf.getEvaluator().execute((BIF) fm, flf);
            }
        }
        comments(data);
        if (checkLibrary)
            data.ep.add(flf, (BIF) fm, data.srcCode);
        break;
    }
    return fm;
}
Also used : TemplateException(lucee.runtime.exp.TemplateException) FunctionMember(lucee.transformer.bytecode.expression.var.FunctionMember) UDF(lucee.transformer.bytecode.expression.var.UDF) FunctionLibFunction(lucee.transformer.library.function.FunctionLibFunction) Literal(lucee.transformer.expression.literal.Literal) PageRuntimeException(lucee.runtime.exp.PageRuntimeException) NamedArgument(lucee.transformer.bytecode.expression.var.NamedArgument) BIF(lucee.transformer.bytecode.expression.var.BIF) FunctionLibFunctionArg(lucee.transformer.library.function.FunctionLibFunctionArg)

Example 5 with BIF

use of lucee.transformer.bytecode.expression.var.BIF 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

BIF (lucee.transformer.bytecode.expression.var.BIF)7 Variable (lucee.transformer.expression.var.Variable)5 Literal (lucee.transformer.expression.literal.Literal)4 PageRuntimeException (lucee.runtime.exp.PageRuntimeException)3 TemplateException (lucee.runtime.exp.TemplateException)3 Expression (lucee.transformer.expression.Expression)3 Member (lucee.transformer.expression.var.Member)3 Body (lucee.transformer.bytecode.Body)2 Statement (lucee.transformer.bytecode.Statement)2 Argument (lucee.transformer.bytecode.expression.var.Argument)2 NamedArgument (lucee.transformer.bytecode.expression.var.NamedArgument)2 UDF (lucee.transformer.bytecode.expression.var.UDF)2 OpVariable (lucee.transformer.bytecode.op.OpVariable)2 PrintOut (lucee.transformer.bytecode.statement.PrintOut)2 Tag (lucee.transformer.bytecode.statement.tag.Tag)2 FunctionLibFunction (lucee.transformer.library.function.FunctionLibFunction)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 PreserveSingleQuotes (lucee.runtime.functions.other.PreserveSingleQuotes)1 QuotedValueList (lucee.runtime.functions.other.QuotedValueList)1