Search in sources :

Example 16 with Expression

use of lucee.transformer.expression.Expression in project Lucee by lucee.

the class Function method addAttribute.

public final void addAttribute(Attribute attr) throws TemplateException {
    String name = attr.getName().toLowerCase();
    // name
    if ("name".equals(name)) {
        throw new TransformerException("name cannot be defined twice", getStart());
    } else if ("returntype".equals(name)) {
        this.returnType = toLitString(name, attr.getValue());
    } else if ("access".equals(name)) {
        LitString ls = toLitString(name, attr.getValue());
        String strAccess = ls.getString();
        int acc = ComponentUtil.toIntAccess(strAccess, -1);
        if (acc == -1)
            throw new TransformerException("invalid access type [" + strAccess + "], access types are remote, public, package, private", getStart());
        access = acc;
    } else if ("output".equals(name))
        this.output = toLitBoolean(name, attr.getValue());
    else if ("bufferoutput".equals(name))
        this.bufferOutput = toLitBoolean(name, attr.getValue());
    else if ("displayname".equals(name))
        this.displayName = toLitString(name, attr.getValue());
    else if ("hint".equals(name))
        this.hint = toLitString(name, attr.getValue());
    else if ("description".equals(name))
        this.description = toLitString(name, attr.getValue());
    else if ("returnformat".equals(name))
        this.returnFormat = toLitString(name, attr.getValue());
    else if ("securejson".equals(name))
        this.secureJson = toLitBoolean(name, attr.getValue());
    else if ("verifyclient".equals(name))
        this.verifyClient = toLitBoolean(name, attr.getValue());
    else if ("localmode".equals(name)) {
        Expression v = attr.getValue();
        if (v != null) {
            String str = ASMUtil.toString(v, null);
            if (!StringUtil.isEmpty(str)) {
                int mode = AppListenerUtil.toLocalMode(str, -1);
                if (mode != -1)
                    this.localMode = v.getFactory().createLitInteger(mode);
                else
                    throw new TransformerException("Attribute localMode of the Tag Function, must be a literal value (modern, classic, true or false)", getStart());
            }
        }
    } else if ("cachedwithin".equals(name)) {
        try {
            // ASMUtil.timeSpanToLong(attr.getValue());
            this.cachedWithin = ASMUtil.cachedWithinValue(attr.getValue());
        } catch (EvaluatorException e) {
            throw new TemplateException(e.getMessage());
        }
    } else if ("modifier".equals(name)) {
        Expression val = attr.getValue();
        if (val instanceof Literal) {
            Literal l = (Literal) val;
            String str = StringUtil.emptyIfNull(l.getString()).trim();
            if ("abstract".equalsIgnoreCase(str))
                modifier = Component.MODIFIER_ABSTRACT;
            else if ("final".equalsIgnoreCase(str))
                modifier = Component.MODIFIER_FINAL;
        }
    } else {
        // needed for testing
        toLitString(name, attr.getValue());
        if (metadata == null)
            metadata = new HashMap<String, Attribute>();
        metadata.put(attr.getName(), attr);
    }
}
Also used : LitString(lucee.transformer.expression.literal.LitString) Expression(lucee.transformer.expression.Expression) EvaluatorException(lucee.transformer.cfml.evaluator.EvaluatorException) TemplateException(lucee.runtime.exp.TemplateException) Attribute(lucee.transformer.bytecode.statement.tag.Attribute) Literal(lucee.transformer.expression.literal.Literal) LitString(lucee.transformer.expression.literal.LitString) ExprString(lucee.transformer.expression.ExprString) TransformerException(lucee.transformer.TransformerException)

Example 17 with Expression

use of lucee.transformer.expression.Expression in project Lucee by lucee.

the class BodyBase method concatPrintouts.

private boolean concatPrintouts(String str) {
    if (last instanceof PrintOut) {
        PrintOut po = (PrintOut) last;
        Expression expr = po.getExpr();
        if (expr instanceof LitString) {
            LitString lit = (LitString) expr;
            if (lit.getString().length() < 1024) {
                po.setExpr(lit.getFactory().createLitString(lit.getString().concat(str), lit.getStart(), lit.getEnd()));
                return true;
            }
        }
    }
    return false;
}
Also used : LitString(lucee.transformer.expression.literal.LitString) PrintOut(lucee.transformer.bytecode.statement.PrintOut) Expression(lucee.transformer.expression.Expression)

Example 18 with Expression

use of lucee.transformer.expression.Expression in project Lucee by lucee.

the class VT method _writeOut.

private Type _writeOut(BytecodeContext bc, int mode, Boolean asCollection) throws TransformerException {
    final GeneratorAdapter adapter = bc.getAdapter();
    final int count = countFM + countDM;
    // count 0
    if (count == 0)
        return _writeOutEmpty(bc);
    boolean doOnlyScope = scope == Scope.SCOPE_LOCAL;
    // boolean last;
    int c = 0;
    for (int i = doOnlyScope ? 0 : 1; i < count; i++) {
        Member member = (members.get((count - 1) - c));
        c++;
        adapter.loadArg(0);
        if (member.getSafeNavigated() && member instanceof UDF)
            adapter.checkCast(Types.PAGE_CONTEXT_IMPL);
    }
    Type rtn = _writeOutFirst(bc, (members.get(0)), mode, count == 1, doOnlyScope, null, null);
    // pc.get(
    for (int i = doOnlyScope ? 0 : 1; i < count; i++) {
        Member member = (members.get(i));
        boolean last = (i + 1) == count;
        // Data Member
        if (member instanceof DataMember) {
            ExprString name = ((DataMember) member).getName();
            if (last && ASMUtil.isDotKey(name)) {
                LitString ls = (LitString) name;
                if (ls.getString().equalsIgnoreCase("RECORDCOUNT")) {
                    adapter.invokeStatic(Types.VARIABLE_UTIL_IMPL, RECORDCOUNT);
                } else if (ls.getString().equalsIgnoreCase("CURRENTROW")) {
                    adapter.invokeStatic(Types.VARIABLE_UTIL_IMPL, CURRENTROW);
                } else if (ls.getString().equalsIgnoreCase("COLUMNLIST")) {
                    adapter.invokeStatic(Types.VARIABLE_UTIL_IMPL, COLUMNLIST);
                } else {
                    getFactory().registerKey(bc, name, false);
                    // safe nav
                    int type;
                    if (member.getSafeNavigated()) {
                        Expression val = member.getSafeNavigatedValue();
                        if (val == null)
                            ASMConstants.NULL(adapter);
                        else
                            val.writeOut(bc, Expression.MODE_REF);
                        type = THREE;
                    } else
                        type = TWO;
                    adapter.invokeVirtual(Types.PAGE_CONTEXT, asCollection(asCollection, last) ? GET_COLLECTION[type] : GET[type]);
                }
            } else {
                getFactory().registerKey(bc, name, false);
                // safe nav
                int type;
                if (member.getSafeNavigated()) {
                    Expression val = member.getSafeNavigatedValue();
                    if (val == null)
                        ASMConstants.NULL(adapter);
                    else
                        val.writeOut(bc, Expression.MODE_REF);
                    type = THREE;
                } else
                    type = TWO;
                adapter.invokeVirtual(Types.PAGE_CONTEXT, asCollection(asCollection, last) ? GET_COLLECTION[type] : GET[type]);
            }
            rtn = Types.OBJECT;
        } else // UDF
        if (member instanceof UDF) {
            rtn = _writeOutUDF(bc, (UDF) member);
        }
    }
    return rtn;
}
Also used : LitString(lucee.transformer.expression.literal.LitString) Type(org.objectweb.asm.Type) ExprString(lucee.transformer.expression.ExprString) Expression(lucee.transformer.expression.Expression) DataMember(lucee.transformer.expression.var.DataMember) GeneratorAdapter(org.objectweb.asm.commons.GeneratorAdapter) DataMember(lucee.transformer.expression.var.DataMember) Member(lucee.transformer.expression.var.Member)

Example 19 with Expression

use of lucee.transformer.expression.Expression in project Lucee by lucee.

the class AbstrCFMLExprTransformer method readComponentPath.

private ExprString readComponentPath(ExprData data) throws TemplateException {
    // first identifier
    String name = identifier(data, true);
    if (name != null) {
        StringBuilder fullName = new StringBuilder();
        fullName.append(name);
        // Loop over addional identifier
        while (data.srcCode.isValidIndex()) {
            if (data.srcCode.forwardIfCurrent('.')) {
                comments(data);
                name = identifier(data, true);
                if (name == null)
                    return null;
                fullName.append('.');
                fullName.append(name);
                comments(data);
            } else
                break;
        }
        return data.factory.createLitString(fullName.toString());
    }
    Expression str = string(data);
    if (str != null) {
        return data.factory.toExprString(str);
    }
    return null;
}
Also used : FunctionAsExpression(lucee.transformer.bytecode.expression.FunctionAsExpression) Expression(lucee.transformer.expression.Expression) LitString(lucee.transformer.expression.literal.LitString) ExprString(lucee.transformer.expression.ExprString)

Example 20 with Expression

use of lucee.transformer.expression.Expression in project Lucee by lucee.

the class AbstrCFMLExprTransformer method concatOp.

/**
 * Transfomiert eine  Konkatinations-Operator (&) Operation. Im Gegensatz zu CFMX ,
 * wird das "!" Zeichen auch als Not Operator anerkannt.
 * <br />
 * EBNF:<br />
 * <code>plusMinusOp {"&" spaces concatOp};</code>
 * @return CFXD Element
 * @throws TemplateException
 */
private Expression concatOp(ExprData data) throws TemplateException {
    Expression expr = plusMinusOp(data);
    while (data.srcCode.isCurrent('&') && !data.srcCode.isCurrent("&&")) {
        data.srcCode.next();
        // &=
        if (data.srcCode.isCurrent('=') && expr instanceof Variable) {
            data.srcCode.next();
            comments(data);
            Expression value = assignOp(data);
            expr = new OPUnary((Variable) expr, value, OPUnary.PRE, OPUnary.CONCAT, expr.getStart(), data.srcCode.getPosition());
        // ExprString res = OpString.toExprString(expr, right);
        // expr=new OpVariable((Variable)expr,res,data.cfml.getPosition());
        } else {
            comments(data);
            expr = data.factory.opString(expr, plusMinusOp(data));
        }
    }
    return expr;
}
Also used : OpVariable(lucee.transformer.bytecode.op.OpVariable) Variable(lucee.transformer.expression.var.Variable) FunctionAsExpression(lucee.transformer.bytecode.expression.FunctionAsExpression) Expression(lucee.transformer.expression.Expression) OPUnary(lucee.transformer.bytecode.op.OPUnary)

Aggregations

Expression (lucee.transformer.expression.Expression)74 FunctionAsExpression (lucee.transformer.bytecode.expression.FunctionAsExpression)34 LitString (lucee.transformer.expression.literal.LitString)25 TemplateException (lucee.runtime.exp.TemplateException)19 Attribute (lucee.transformer.bytecode.statement.tag.Attribute)16 Variable (lucee.transformer.expression.var.Variable)16 Body (lucee.transformer.bytecode.Body)11 ExprString (lucee.transformer.expression.ExprString)11 GeneratorAdapter (org.objectweb.asm.commons.GeneratorAdapter)11 Position (lucee.transformer.Position)10 OpVariable (lucee.transformer.bytecode.op.OpVariable)10 LitBoolean (lucee.transformer.expression.literal.LitBoolean)8 Literal (lucee.transformer.expression.literal.Literal)8 ArrayList (java.util.ArrayList)7 TransformerException (lucee.transformer.TransformerException)7 BodyBase (lucee.transformer.bytecode.BodyBase)7 Statement (lucee.transformer.bytecode.Statement)7 Argument (lucee.transformer.bytecode.expression.var.Argument)7 PrintOut (lucee.transformer.bytecode.statement.PrintOut)6 FunctionBody (lucee.transformer.bytecode.FunctionBody)5