Search in sources :

Example 11 with LitString

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

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

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

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

use of lucee.transformer.expression.literal.LitString 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

LitString (lucee.transformer.expression.literal.LitString)36 Expression (lucee.transformer.expression.Expression)21 ExprString (lucee.transformer.expression.ExprString)13 GeneratorAdapter (org.objectweb.asm.commons.GeneratorAdapter)11 Attribute (lucee.transformer.bytecode.statement.tag.Attribute)9 EvaluatorException (lucee.transformer.cfml.evaluator.EvaluatorException)8 TransformerException (lucee.transformer.TransformerException)6 Statement (lucee.transformer.bytecode.Statement)6 ArrayList (java.util.ArrayList)5 Iterator (java.util.Iterator)5 Body (lucee.transformer.bytecode.Body)5 Argument (lucee.transformer.bytecode.expression.var.Argument)5 PrintOut (lucee.transformer.bytecode.statement.PrintOut)5 Literal (lucee.transformer.expression.literal.Literal)5 TemplateException (lucee.runtime.exp.TemplateException)4 BytecodeContext (lucee.transformer.bytecode.BytecodeContext)4 TagLibTag (lucee.transformer.library.tag.TagLibTag)4 Label (org.objectweb.asm.Label)4 BodyBase (lucee.transformer.bytecode.BodyBase)3 Page (lucee.transformer.bytecode.Page)3