Search in sources :

Example 1 with StaticBody

use of lucee.transformer.bytecode.StaticBody 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 StaticBody

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

the class Static method getStaticBody.

static StaticBody getStaticBody(Body body) {
    Iterator<Statement> it = body.getStatements().iterator();
    Statement s;
    while (it.hasNext()) {
        s = it.next();
        if (s instanceof StaticBody)
            return (StaticBody) s;
    }
    StaticBody sb = new StaticBody(body.getFactory());
    body.addStatement(sb);
    return sb;
}
Also used : Statement(lucee.transformer.bytecode.Statement) StaticBody(lucee.transformer.bytecode.StaticBody)

Example 3 with StaticBody

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

the class TagCIObject method getStaticBodies.

public List<StaticBody> getStaticBodies() {
    Body b = getBody();
    List<StaticBody> list = null;
    if (!ASMUtil.isEmpty(b)) {
        Statement stat;
        Iterator<Statement> it = b.getStatements().iterator();
        while (it.hasNext()) {
            stat = it.next();
            // StaticBody
            if (stat instanceof StaticBody) {
                it.remove();
                if (list == null)
                    list = new ArrayList<StaticBody>();
                list.add((StaticBody) stat);
            // return (StaticBody) stat;
            }
        }
    }
    return list;
}
Also used : StaticBody(lucee.transformer.bytecode.StaticBody) Statement(lucee.transformer.bytecode.Statement) ArrayList(java.util.ArrayList) Body(lucee.transformer.bytecode.Body) StaticBody(lucee.transformer.bytecode.StaticBody)

Example 4 with StaticBody

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

the class Static method evaluate.

@Override
public void evaluate(Tag tag, TagLibTag libTag) throws EvaluatorException {
    // check parent
    Body body = null;
    String compName = Property.getComponentName(tag);
    boolean isCompChild = false;
    Tag p = ASMUtil.getParentTag(tag);
    if (p != null && (p instanceof TagComponent || getFullname(p, "").equalsIgnoreCase(compName))) {
        isCompChild = true;
        body = p.getBody();
    }
    Tag pp = p != null ? ASMUtil.getParentTag(p) : null;
    if (!isCompChild && pp != null && (p instanceof TagComponent || getFullname(pp, "").equalsIgnoreCase(compName))) {
        isCompChild = true;
        body = pp.getBody();
    }
    if (!isCompChild) {
        throw new EvaluatorException("Wrong Context for the the static constructor, " + "a static constructor must inside a component body.");
    }
    // Body body=(Body) tag.getParent();
    List<Statement> children = tag.getBody().getStatements();
    // remove that tag from parent
    ASMUtil.remove(tag);
    StaticBody sb = getStaticBody(body);
    ASMUtil.addStatements(sb, children);
}
Also used : EvaluatorException(lucee.transformer.cfml.evaluator.EvaluatorException) Statement(lucee.transformer.bytecode.Statement) StaticBody(lucee.transformer.bytecode.StaticBody) Tag(lucee.transformer.bytecode.statement.tag.Tag) TagLibTag(lucee.transformer.library.tag.TagLibTag) TagComponent(lucee.transformer.bytecode.statement.tag.TagComponent) Body(lucee.transformer.bytecode.Body) StaticBody(lucee.transformer.bytecode.StaticBody)

Aggregations

StaticBody (lucee.transformer.bytecode.StaticBody)4 Body (lucee.transformer.bytecode.Body)3 Statement (lucee.transformer.bytecode.Statement)3 EvaluatorException (lucee.transformer.cfml.evaluator.EvaluatorException)2 ArrayList (java.util.ArrayList)1 PageSource (lucee.runtime.PageSource)1 TransformerException (lucee.transformer.TransformerException)1 Page (lucee.transformer.bytecode.Page)1 Attribute (lucee.transformer.bytecode.statement.tag.Attribute)1 Tag (lucee.transformer.bytecode.statement.tag.Tag)1 TagComponent (lucee.transformer.bytecode.statement.tag.TagComponent)1 ExprString (lucee.transformer.expression.ExprString)1 Expression (lucee.transformer.expression.Expression)1 LitBoolean (lucee.transformer.expression.literal.LitBoolean)1 LitString (lucee.transformer.expression.literal.LitString)1 Literal (lucee.transformer.expression.literal.Literal)1 TagLibTag (lucee.transformer.library.tag.TagLibTag)1 PageSourceCode (lucee.transformer.util.PageSourceCode)1 SourceCode (lucee.transformer.util.SourceCode)1