Search in sources :

Example 1 with Literal

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

the class Function method evaluate.

@Override
public void evaluate(Tag tag, TagLibTag libTag, FunctionLib[] flibs) throws EvaluatorException {
    // Body p=(Body) tag.getParent();
    // Statement pp = p.getParent();
    boolean isCI = true;
    try {
        isCI = ASMUtil.getAncestorPage(tag).isComponent() || ASMUtil.getAncestorPage(tag).isInterface();
    } catch (TransformerException e) {
    }
    Attribute attrName = tag.getAttribute("name");
    if (attrName != null) {
        Expression expr = attrName.getValue();
        PageSource ps = null;
        if (expr instanceof LitString && !isCI) {
            Page p = ASMUtil.getAncestorPage(tag, null);
            if (p != null) {
                SourceCode sc = p.getSourceCode();
                if (sc instanceof PageSourceCode) {
                    PageSourceCode psc = (PageSourceCode) sc;
                    ps = psc.getPageSource();
                }
            }
            checkFunctionName(((LitString) expr).getString(), flibs, ps);
        }
    }
    // attribute modifier
    boolean isStatic = false;
    {
        Attribute attrModifier = tag.getAttribute("modifier");
        if (attrModifier != null) {
            ExprString expr = tag.getFactory().toExprString(attrModifier.getValue());
            if (!(expr instanceof Literal))
                throw new EvaluatorException("Attribute modifier of the Tag Function, must be one of the following literal string values: [abstract,final,static]");
            String modifier = StringUtil.emptyIfNull(((Literal) expr).getString()).trim();
            if (!StringUtil.isEmpty(modifier) && !"abstract".equalsIgnoreCase(modifier) && !"final".equalsIgnoreCase(modifier) && !"static".equalsIgnoreCase(modifier))
                throw new EvaluatorException("Attribute modifier of the Tag Function, must be one of the following literal string values: [abstract,final,static]");
            isStatic = "static".equalsIgnoreCase(modifier);
            boolean abstr = "abstract".equalsIgnoreCase(modifier);
            if (abstr)
                throwIfNotEmpty(tag);
        }
    }
    // cachedWithin
    {
        Attribute attrCachedWithin = tag.getAttribute("cachedwithin");
        if (attrCachedWithin != null) {
            Expression val = attrCachedWithin.getValue();
            tag.addAttribute(new Attribute(attrCachedWithin.isDynamicType(), attrCachedWithin.getName(), ASMUtil.cachedWithinValue(val), attrCachedWithin.getType()));
        }
    }
    // Attribute localMode
    {
        Attribute attrLocalMode = tag.getAttribute("localmode");
        if (attrLocalMode != null) {
            Expression expr = attrLocalMode.getValue();
            String str = ASMUtil.toString(expr, null);
            if (!StringUtil.isEmpty(str) && AppListenerUtil.toLocalMode(str, -1) == -1)
                throw new EvaluatorException("Attribute localMode of the Tag Function, must be a literal value (modern, classic, true or false)");
        // boolean output = ((LitBoolean)expr).getBooleanValue();
        // if(!output) ASMUtil.removeLiterlChildren(tag, true);
        }
    }
    // Attribute Output
    {
        Attribute attrOutput = tag.getAttribute("output");
        if (attrOutput != null) {
            Expression expr = tag.getFactory().toExprBoolean(attrOutput.getValue());
            if (!(expr instanceof LitBoolean))
                throw new EvaluatorException("Attribute output of the Tag Function, must be a literal boolean value (true or false, yes or no)");
        }
    }
    // Buffer output
    {
        Attribute attrBufferOutput = tag.getAttribute("bufferoutput");
        if (attrBufferOutput != null) {
            Expression expr = tag.getFactory().toExprBoolean(attrBufferOutput.getValue());
            if (!(expr instanceof LitBoolean))
                throw new EvaluatorException("Attribute bufferOutput of the Tag Function, must be a literal boolean value (true or false, yes or no)");
        }
    }
    // check attribute values
    Map<String, Attribute> attrs = tag.getAttributes();
    Iterator<Attribute> it = attrs.values().iterator();
    while (it.hasNext()) {
        checkAttributeValue(tag, it.next());
    }
    // add to static scope
    if (isStatic) {
        // remove that tag from parent
        ASMUtil.remove(tag);
        Body body = (Body) tag.getParent();
        StaticBody sb = Static.getStaticBody(body);
        sb.addStatement(tag);
    }
}
Also used : SourceCode(lucee.transformer.util.SourceCode) PageSourceCode(lucee.transformer.util.PageSourceCode) PageSourceCode(lucee.transformer.util.PageSourceCode) Attribute(lucee.transformer.bytecode.statement.tag.Attribute) ExprString(lucee.transformer.expression.ExprString) StaticBody(lucee.transformer.bytecode.StaticBody) Page(lucee.transformer.bytecode.Page) LitBoolean(lucee.transformer.expression.literal.LitBoolean) LitString(lucee.transformer.expression.literal.LitString) ExprString(lucee.transformer.expression.ExprString) PageSource(lucee.runtime.PageSource) LitString(lucee.transformer.expression.literal.LitString) Expression(lucee.transformer.expression.Expression) EvaluatorException(lucee.transformer.cfml.evaluator.EvaluatorException) Literal(lucee.transformer.expression.literal.Literal) StaticBody(lucee.transformer.bytecode.StaticBody) Body(lucee.transformer.bytecode.Body) TransformerException(lucee.transformer.TransformerException)

Example 2 with Literal

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

the class Output method evaluate.

@Override
public void evaluate(Tag tag, TagLibTag libTag, FunctionLib[] flibs) throws EvaluatorException {
    TagOutput output = (TagOutput) tag;
    // check if inside a query tag
    TagOutput parent = output;
    // encodeFor
    Attribute encodeFor = tag.getAttribute("encodefor");
    if (encodeFor != null) {
        Expression encodeForValue = CastString.toExprString(encodeFor.getValue());
        if (encodeForValue instanceof Literal) {
            Literal l = (Literal) encodeForValue;
            short df = (short) -1;
            short encType = ESAPIEncode.toEncodeType(l.getString(), df);
            if (encType != df)
                encodeForValue = encodeForValue.getFactory().createLitInteger(encType);
        }
        addEncodeToChildren(tag.getBody().getStatements().iterator(), encodeForValue, getEncodeForFunction(flibs));
    }
    // query
    boolean hasParentWithGroup = false;
    boolean hasParentWithQuery = false;
    boolean hasQuery = tag.containsAttribute("query");
    while ((parent = getParentTagOutput(parent)) != null) {
        if (!hasParentWithQuery)
            hasParentWithQuery = parent.hasQuery();
        if (!hasParentWithGroup)
            hasParentWithGroup = parent.hasGroup();
        if (hasParentWithQuery && hasParentWithGroup)
            break;
    }
    if (hasQuery && hasParentWithQuery)
        throw new EvaluatorException("Nesting of tags cfoutput with attribute query is not allowed");
    if (hasQuery)
        output.setType(TagOutput.TYPE_QUERY);
    else if (tag.containsAttribute("group") && hasParentWithQuery)
        output.setType(TagOutput.TYPE_GROUP);
    else if (hasParentWithQuery) {
        if (hasParentWithGroup)
            output.setType(TagOutput.TYPE_INNER_GROUP);
        else
            output.setType(TagOutput.TYPE_INNER_QUERY);
    } else
        output.setType(TagOutput.TYPE_NORMAL);
    // attribute maxrows and endrow not allowd at the same time
    if (tag.containsAttribute("maxrows") && tag.containsAttribute("endrow"))
        throw new EvaluatorException("Wrong Context, you cannot use attribute maxrows and endrow at the same time.");
}
Also used : TagOutput(lucee.transformer.bytecode.statement.tag.TagOutput) Attribute(lucee.transformer.bytecode.statement.tag.Attribute) Expression(lucee.transformer.expression.Expression) EvaluatorException(lucee.transformer.cfml.evaluator.EvaluatorException) Literal(lucee.transformer.expression.literal.Literal)

Example 3 with Literal

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

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

the class OpString method toExprString.

public static ExprString toExprString(Expression left, Expression right, boolean concatStatic) {
    if (concatStatic && left instanceof Literal && right instanceof Literal) {
        String l = ((Literal) left).getString();
        String r = ((Literal) right).getString();
        if ((l.length() + r.length()) <= MAX_SIZE)
            return left.getFactory().createLitString(l.concat(r), left.getStart(), right.getEnd());
    }
    return new OpString(left, right);
}
Also used : Literal(lucee.transformer.expression.literal.Literal) ExprString(lucee.transformer.expression.ExprString)

Example 5 with Literal

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

the class ExpressionAsStatement method _writeOut.

/**
 * @see lucee.transformer.bytecode.statement.StatementBase#_writeOut(org.objectweb.asm.commons.GeneratorAdapter)
 */
@Override
public void _writeOut(BytecodeContext bc) throws TransformerException {
    GeneratorAdapter adapter = bc.getAdapter();
    int rtn = bc.getReturn();
    // set rtn
    if (rtn > -1) {
        Type type = expr.writeOut(bc, Expression.MODE_REF);
        bc.getAdapter().storeLocal(rtn);
    } else {
        if (!(expr instanceof Literal)) {
            Type type = expr.writeOut(bc, Expression.MODE_VALUE);
            if (!type.equals(Types.VOID)) {
                ASMUtil.pop(adapter, type);
            }
        }
    }
}
Also used : Type(org.objectweb.asm.Type) Literal(lucee.transformer.expression.literal.Literal) GeneratorAdapter(org.objectweb.asm.commons.GeneratorAdapter)

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