Search in sources :

Example 6 with Literal

use of lucee.transformer.expression.literal.Literal in project Lucee by lucee.

the class Function method toLocalMode.

public static ExprInt toLocalMode(Expression expr, ExprInt defaultValue) {
    int mode = -1;
    if (expr instanceof Literal) {
        String str = ((Literal) expr).getString();
        str = str.trim().toLowerCase();
        mode = AppListenerUtil.toLocalMode(str, -1);
    }
    if (mode == -1)
        return defaultValue;
    return expr.getFactory().createLitInteger(mode);
}
Also used : Literal(lucee.transformer.expression.literal.Literal) LitString(lucee.transformer.expression.literal.LitString) ExprString(lucee.transformer.expression.ExprString)

Example 7 with Literal

use of lucee.transformer.expression.literal.Literal 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 8 with Literal

use of lucee.transformer.expression.literal.Literal 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 9 with Literal

use of lucee.transformer.expression.literal.Literal in project Lucee by lucee.

the class BytecodeFactory method registerKey.

@Override
public void registerKey(Context c, Expression name, boolean doUpperCase) throws TransformerException {
    BytecodeContext bc = (BytecodeContext) c;
    if (name instanceof Literal) {
        Literal l = (Literal) name;
        LitString ls = name instanceof LitString ? (LitString) l : c.getFactory().createLitString(l.getString());
        if (doUpperCase) {
            ls = ls.duplicate();
            ls.upperCase();
        }
        String key = KeyConstants.getFieldName(ls.getString());
        if (key != null) {
            bc.getAdapter().getStatic(KEY_CONSTANTS, key, Types.COLLECTION_KEY);
            return;
        }
        int index = bc.registerKey(ls);
        bc.getAdapter().visitVarInsn(Opcodes.ALOAD, 0);
        bc.getAdapter().visitFieldInsn(Opcodes.GETFIELD, bc.getClassName(), "keys", Types.COLLECTION_KEY_ARRAY.toString());
        bc.getAdapter().push(index);
        bc.getAdapter().visitInsn(Opcodes.AALOAD);
        return;
    }
    name.writeOut(bc, Expression.MODE_REF);
    bc.getAdapter().invokeStatic(Page.KEY_IMPL, INIT);
    // bc.getAdapter().invokeStatic(Types.CASTER, TO_KEY);
    return;
}
Also used : LitString(lucee.transformer.expression.literal.LitString) Literal(lucee.transformer.expression.literal.Literal) CastString(lucee.transformer.bytecode.cast.CastString) LitString(lucee.transformer.expression.literal.LitString) OpString(lucee.transformer.bytecode.op.OpString) ExprString(lucee.transformer.expression.ExprString)

Example 10 with Literal

use of lucee.transformer.expression.literal.Literal in project Lucee by lucee.

the class OpBool method toExprBoolean.

/**
 * Create a String expression from a Expression
 * @param left
 * @param right
 *
 * @return String expression
 * @throws TemplateException
 */
public static ExprBoolean toExprBoolean(Expression left, Expression right, int operation) {
    if (left instanceof Literal && right instanceof Literal) {
        Boolean l = ((Literal) left).getBoolean(null);
        Boolean r = ((Literal) right).getBoolean(null);
        if (l != null && r != null) {
            switch(operation) {
                case Factory.OP_BOOL_AND:
                    return left.getFactory().createLitBoolean(l.booleanValue() && r.booleanValue(), left.getStart(), right.getEnd());
                case Factory.OP_BOOL_OR:
                    return left.getFactory().createLitBoolean(l.booleanValue() || r.booleanValue(), left.getStart(), right.getEnd());
                case Factory.OP_BOOL_XOR:
                    return left.getFactory().createLitBoolean(l.booleanValue() ^ r.booleanValue(), left.getStart(), right.getEnd());
            }
        }
    }
    return new OpBool(left, right, operation);
}
Also used : Literal(lucee.transformer.expression.literal.Literal) ExprBoolean(lucee.transformer.expression.ExprBoolean)

Aggregations

Literal (lucee.transformer.expression.literal.Literal)19 Expression (lucee.transformer.expression.Expression)8 Attribute (lucee.transformer.bytecode.statement.tag.Attribute)6 ExprString (lucee.transformer.expression.ExprString)6 LitString (lucee.transformer.expression.literal.LitString)6 Member (lucee.transformer.expression.var.Member)5 TransformerException (lucee.transformer.TransformerException)4 Body (lucee.transformer.bytecode.Body)4 BIF (lucee.transformer.bytecode.expression.var.BIF)4 ArrayList (java.util.ArrayList)3 Statement (lucee.transformer.bytecode.Statement)3 PrintOut (lucee.transformer.bytecode.statement.PrintOut)3 Tag (lucee.transformer.bytecode.statement.tag.Tag)3 EvaluatorException (lucee.transformer.cfml.evaluator.EvaluatorException)3 DataMember (lucee.transformer.expression.var.DataMember)3 Variable (lucee.transformer.expression.var.Variable)3 GeneratorAdapter (org.objectweb.asm.commons.GeneratorAdapter)3 Iterator (java.util.Iterator)2 Map (java.util.Map)2 TemplateException (lucee.runtime.exp.TemplateException)2