Search in sources :

Example 1 with PrintOut

use of lucee.transformer.bytecode.statement.PrintOut in project Lucee by lucee.

the class Interface method evaluate.

@Override
public void evaluate(Tag tag, TagLibTag libTag) throws EvaluatorException {
    super.evaluate(tag, libTag);
    Body body = tag.getBody();
    List<Statement> statments = body.getStatements();
    Statement stat;
    Iterator<Statement> it = statments.iterator();
    Tag t;
    while (it.hasNext()) {
        stat = it.next();
        if (stat instanceof PrintOut) {
        // body.remove(stat);
        } else if (stat instanceof Tag) {
            t = (Tag) stat;
            if (stat instanceof TagImport) {
            // ignore
            } else if (stat instanceof TagFunction) {
                Function.throwIfNotEmpty(t);
                Attribute attr = t.getAttribute("access");
                if (attr != null) {
                    ExprString expr = t.getFactory().toExprString(attr.getValue());
                    if (!(expr instanceof LitString))
                        throw new EvaluatorException("the attribute access of the Tag function inside an interface must contain a constant value");
                    String access = ((LitString) expr).getString().trim();
                    if (!"public".equalsIgnoreCase(access))
                        throw new EvaluatorException("the attribute access of the tag function inside an interface definition can only have the value [public] not [" + access + "]");
                } else
                    t.addAttribute(new Attribute(false, "access", stat.getFactory().createLitString("public"), "string"));
            } else
                throw new EvaluatorException("tag " + libTag.getFullName() + " can only contain function definitions.");
        }
    }
}
Also used : TagFunction(lucee.transformer.bytecode.statement.tag.TagFunction) Attribute(lucee.transformer.bytecode.statement.tag.Attribute) ExprString(lucee.transformer.expression.ExprString) Statement(lucee.transformer.bytecode.Statement) LitString(lucee.transformer.expression.literal.LitString) ExprString(lucee.transformer.expression.ExprString) TagImport(lucee.transformer.bytecode.statement.tag.TagImport) LitString(lucee.transformer.expression.literal.LitString) PrintOut(lucee.transformer.bytecode.statement.PrintOut) EvaluatorException(lucee.transformer.cfml.evaluator.EvaluatorException) TagLibTag(lucee.transformer.library.tag.TagLibTag) Tag(lucee.transformer.bytecode.statement.tag.Tag) Body(lucee.transformer.bytecode.Body)

Example 2 with PrintOut

use of lucee.transformer.bytecode.statement.PrintOut 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 3 with PrintOut

use of lucee.transformer.bytecode.statement.PrintOut in project Lucee by lucee.

the class TagFunction method _writeOut.

public void _writeOut(BytecodeContext bc, int type) throws TransformerException {
    // private static final Expression EMPTY = LitString.toExprString("");
    Body functionBody = new BodyBase(bc.getFactory());
    RefBoolean isStatic = new RefBooleanImpl();
    Function func = createFunction(bc.getPage(), functionBody, isStatic, bc.getOutput());
    // ScriptBody sb=new ScriptBody(bc.getFactory());
    func.setParent(getParent());
    List<Statement> statements = getBody().getStatements();
    Statement stat;
    Tag tag;
    // suppress WS between cffunction and the last cfargument
    Tag last = null;
    if (bc.getSupressWSbeforeArg()) {
        // check if there is a cfargument at all
        Iterator<Statement> it = statements.iterator();
        while (it.hasNext()) {
            stat = it.next();
            if (stat instanceof Tag) {
                tag = (Tag) stat;
                if (tag.getTagLibTag().getTagClassDefinition().isClassNameEqualTo("lucee.runtime.tag.Argument")) {
                    last = tag;
                }
            }
        }
        // check if there are only literal WS printouts
        if (last != null) {
            it = statements.iterator();
            while (it.hasNext()) {
                stat = it.next();
                if (stat == last)
                    break;
                if (stat instanceof PrintOut) {
                    PrintOut po = (PrintOut) stat;
                    Expression expr = po.getExpr();
                    if (!(expr instanceof LitString) || !StringUtil.isWhiteSpace(((LitString) expr).getString())) {
                        last = null;
                        break;
                    }
                }
            }
        }
    }
    Iterator<Statement> it = statements.iterator();
    boolean beforeLastArgument = last != null;
    while (it.hasNext()) {
        stat = it.next();
        if (beforeLastArgument) {
            if (stat == last) {
                beforeLastArgument = false;
            } else if (stat instanceof PrintOut) {
                PrintOut po = (PrintOut) stat;
                Expression expr = po.getExpr();
                if (expr instanceof LitString) {
                    LitString ls = (LitString) expr;
                    if (StringUtil.isWhiteSpace(ls.getString()))
                        continue;
                }
            }
        }
        if (stat instanceof Tag) {
            tag = (Tag) stat;
            if (tag.getTagLibTag().getTagClassDefinition().isClassNameEqualTo("lucee.runtime.tag.Argument")) {
                addArgument(func, tag);
                continue;
            }
        }
        functionBody.addStatement(stat);
    }
    func._writeOut(bc, type);
}
Also used : RefBoolean(lucee.commons.lang.types.RefBoolean) Statement(lucee.transformer.bytecode.Statement) Function(lucee.transformer.bytecode.statement.udf.Function) IFunction(lucee.transformer.bytecode.statement.IFunction) LitString(lucee.transformer.expression.literal.LitString) PrintOut(lucee.transformer.bytecode.statement.PrintOut) Expression(lucee.transformer.expression.Expression) RefBooleanImpl(lucee.commons.lang.types.RefBooleanImpl) Body(lucee.transformer.bytecode.Body) BodyBase(lucee.transformer.bytecode.BodyBase)

Example 4 with PrintOut

use of lucee.transformer.bytecode.statement.PrintOut 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 5 with PrintOut

use of lucee.transformer.bytecode.statement.PrintOut in project Lucee by lucee.

the class ASMUtil method removeLiterlChildren.

public static void removeLiterlChildren(Tag tag, boolean recursive) {
    Body body = tag.getBody();
    if (body != null) {
        List<Statement> list = body.getStatements();
        Statement[] stats = list.toArray(new Statement[list.size()]);
        PrintOut po;
        Tag t;
        for (int i = 0; i < stats.length; i++) {
            if (stats[i] instanceof PrintOut) {
                po = (PrintOut) stats[i];
                if (po.getExpr() instanceof Literal) {
                    body.getStatements().remove(po);
                }
            } else if (recursive && stats[i] instanceof Tag) {
                t = (Tag) stats[i];
                if (t.getTagLibTag().isAllowRemovingLiteral()) {
                    removeLiterlChildren(t, recursive);
                }
            }
        }
    }
}
Also used : PrintOut(lucee.transformer.bytecode.statement.PrintOut) Statement(lucee.transformer.bytecode.Statement) Literal(lucee.transformer.expression.literal.Literal) Tag(lucee.transformer.bytecode.statement.tag.Tag) Body(lucee.transformer.bytecode.Body) ScriptBody(lucee.transformer.bytecode.ScriptBody) HasBody(lucee.transformer.bytecode.statement.HasBody) lucee.aprint(lucee.aprint)

Aggregations

PrintOut (lucee.transformer.bytecode.statement.PrintOut)10 Statement (lucee.transformer.bytecode.Statement)6 Expression (lucee.transformer.expression.Expression)6 LitString (lucee.transformer.expression.literal.LitString)6 Body (lucee.transformer.bytecode.Body)5 Tag (lucee.transformer.bytecode.statement.tag.Tag)4 Literal (lucee.transformer.expression.literal.Literal)3 TagLibTag (lucee.transformer.library.tag.TagLibTag)3 ArrayList (java.util.ArrayList)2 List (java.util.List)2 TemplateException (lucee.runtime.exp.TemplateException)2 BIF (lucee.transformer.bytecode.expression.var.BIF)2 ComponentTemplateException (lucee.transformer.cfml.script.AbstrCFMLScriptTransformer.ComponentTemplateException)2 Member (lucee.transformer.expression.var.Member)2 Variable (lucee.transformer.expression.var.Variable)2 Charset (java.nio.charset.Charset)1 Iterator (java.util.Iterator)1 lucee.aprint (lucee.aprint)1 RefBoolean (lucee.commons.lang.types.RefBoolean)1 RefBooleanImpl (lucee.commons.lang.types.RefBooleanImpl)1