Search in sources :

Example 6 with Statement

use of lucee.transformer.bytecode.Statement in project Lucee by lucee.

the class TagTry method hasFinally.

private boolean hasFinally() {
    List<Statement> statements = getBody().getStatements();
    Statement stat;
    Tag tag;
    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.Finally")) {
                return true;
            }
        }
    }
    return false;
}
Also used : Statement(lucee.transformer.bytecode.Statement)

Example 7 with Statement

use of lucee.transformer.bytecode.Statement in project Lucee by lucee.

the class ASMUtil method getAncestorFCStatement.

private static FlowControl getAncestorFCStatement(Statement stat, List<FlowControlFinal> finallyLabels, int flowType, String label) {
    Statement parent = stat;
    FlowControlFinal fcf;
    while (true) {
        parent = parent.getParent();
        if (parent == null)
            return null;
        if (((flowType == FlowControl.RETRY && parent instanceof FlowControlRetry) || (flowType == FlowControl.CONTINUE && parent instanceof FlowControlContinue) || (flowType == FlowControl.BREAK && parent instanceof FlowControlBreak)) && labelMatch((FlowControl) parent, label)) {
            if (parent instanceof ScriptBody) {
                List<FlowControlFinal> _finallyLabels = finallyLabels == null ? null : new ArrayList<FlowControlFinal>();
                FlowControl scriptBodyParent = getAncestorFCStatement(parent, _finallyLabels, flowType, label);
                if (scriptBodyParent != null) {
                    if (finallyLabels != null) {
                        Iterator<FlowControlFinal> it = _finallyLabels.iterator();
                        while (it.hasNext()) {
                            finallyLabels.add(it.next());
                        }
                    }
                    return scriptBodyParent;
                }
                return (FlowControl) parent;
            }
            return (FlowControl) parent;
        }
        // only if not last
        if (finallyLabels != null) {
            fcf = parent.getFlowControlFinal();
            if (fcf != null) {
                finallyLabels.add(fcf);
            }
        }
    }
}
Also used : FlowControlContinue(lucee.transformer.bytecode.statement.FlowControlContinue) FlowControl(lucee.transformer.bytecode.statement.FlowControl) Statement(lucee.transformer.bytecode.Statement) ScriptBody(lucee.transformer.bytecode.ScriptBody) FlowControlFinal(lucee.transformer.bytecode.statement.FlowControlFinal) FlowControlBreak(lucee.transformer.bytecode.statement.FlowControlBreak) FlowControlRetry(lucee.transformer.bytecode.statement.FlowControlRetry)

Example 8 with Statement

use of lucee.transformer.bytecode.Statement in project Lucee by lucee.

the class ASMUtil method replace.

/**
 * replace src with trg
 * @param src
 * @param trg
 */
public static void replace(Tag src, Tag trg, boolean moveBody) {
    trg.setParent(src.getParent());
    Body p = (Body) src.getParent();
    List<Statement> stats = p.getStatements();
    Iterator<Statement> it = stats.iterator();
    Statement stat;
    int count = 0;
    while (it.hasNext()) {
        stat = it.next();
        if (stat == src) {
            if (moveBody && src.getBody() != null)
                src.getBody().setParent(trg);
            stats.set(count, trg);
            break;
        }
        count++;
    }
}
Also used : Statement(lucee.transformer.bytecode.Statement) Body(lucee.transformer.bytecode.Body) ScriptBody(lucee.transformer.bytecode.ScriptBody) HasBody(lucee.transformer.bytecode.statement.HasBody) lucee.aprint(lucee.aprint)

Example 9 with Statement

use of lucee.transformer.bytecode.Statement in project Lucee by lucee.

the class ASMUtil method count.

public static int count(List<Statement> statements, boolean recursive) {
    if (statements == null)
        return 0;
    int count = 0;
    Iterator<Statement> it = statements.iterator();
    while (it.hasNext()) {
        count += count(it.next(), recursive);
    }
    return count;
}
Also used : Statement(lucee.transformer.bytecode.Statement) lucee.aprint(lucee.aprint)

Example 10 with Statement

use of lucee.transformer.bytecode.Statement in project Lucee by lucee.

the class ASMUtil method move.

public static void move(Tag src, Body dest) {
    // switch children
    Body srcBody = (Body) src.getParent();
    Iterator<Statement> it = srcBody.getStatements().iterator();
    Statement stat;
    while (it.hasNext()) {
        stat = it.next();
        if (stat == src) {
            it.remove();
            dest.addStatement(stat);
        }
    }
    // switch parent
    src.setParent(dest);
}
Also used : Statement(lucee.transformer.bytecode.Statement) Body(lucee.transformer.bytecode.Body) ScriptBody(lucee.transformer.bytecode.ScriptBody) HasBody(lucee.transformer.bytecode.statement.HasBody)

Aggregations

Statement (lucee.transformer.bytecode.Statement)28 Body (lucee.transformer.bytecode.Body)15 Tag (lucee.transformer.bytecode.statement.tag.Tag)13 Expression (lucee.transformer.expression.Expression)7 LitString (lucee.transformer.expression.literal.LitString)7 TagLibTag (lucee.transformer.library.tag.TagLibTag)7 ArrayList (java.util.ArrayList)6 ScriptBody (lucee.transformer.bytecode.ScriptBody)6 PrintOut (lucee.transformer.bytecode.statement.PrintOut)6 Iterator (java.util.Iterator)5 HasBody (lucee.transformer.bytecode.statement.HasBody)5 EvaluatorException (lucee.transformer.cfml.evaluator.EvaluatorException)5 List (java.util.List)4 StaticBody (lucee.transformer.bytecode.StaticBody)4 GeneratorAdapter (org.objectweb.asm.commons.GeneratorAdapter)4 lucee.aprint (lucee.aprint)3 TransformerException (lucee.transformer.TransformerException)3 BodyBase (lucee.transformer.bytecode.BodyBase)3 Literal (lucee.transformer.expression.literal.Literal)3 Label (org.objectweb.asm.Label)3