Search in sources :

Example 1 with EvaluatorException

use of lucee.transformer.cfml.evaluator.EvaluatorException in project Lucee by lucee.

the class Argument method evaluate.

@Override
public void evaluate(Tag tag, TagLibTag libTag) throws EvaluatorException {
    String ns = libTag.getTagLib().getNameSpaceAndSeparator();
    String functionName = ns + "function";
    ASMUtil.isLiteralAttribute(tag, "type", ASMUtil.TYPE_STRING, false, true);
    ASMUtil.isLiteralAttribute(tag, "name", ASMUtil.TYPE_STRING, false, true);
    // ASMUtil.isLiteralAttribute(tag,"hint",ASMUtil.TYPE_STRING,false,true);
    // ASMUtil.isLiteralAttribute(tag,"displayname",ASMUtil.TYPE_STRING,false,true);
    // check if default can be converted to a literal value that match the type declration.
    checkDefaultValue(tag);
    // check attribute passby
    Attribute attrPassBy = tag.getAttribute("passby");
    if (attrPassBy != null) {
        ExprString expr = tag.getFactory().toExprString(attrPassBy.getValue());
        if (!(expr instanceof LitString))
            throw new EvaluatorException("Attribute passby of the Tag Argument, must be a literal string");
        LitString lit = (LitString) expr;
        String passBy = lit.getString().toLowerCase().trim();
        if (!"value".equals(passBy) && !"ref".equals(passBy) && !"reference".equals(passBy))
            throw new EvaluatorException("Attribute passby of the Tag Argument has an invalid value [" + passBy + "], valid values are [reference,value]");
    }
    // check if tag is direct inside function
    if (!ASMUtil.isParentTag(tag, functionName)) {
        Tag parent = ASMUtil.getParentTag(tag);
        String addText = (parent != null) ? "but tag " + libTag.getFullName() + " is inside tag " + parent.getFullname() + "" : "but tag " + libTag.getFullName() + " has no parent";
        throw new EvaluatorException("Wrong Context, tag " + libTag.getFullName() + " must be direct inside a " + functionName + " tag, " + addText);
    }
// TODO check if there is a tag other than argument and text before
}
Also used : LitString(lucee.transformer.expression.literal.LitString) Attribute(lucee.transformer.bytecode.statement.tag.Attribute) ExprString(lucee.transformer.expression.ExprString) EvaluatorException(lucee.transformer.cfml.evaluator.EvaluatorException) LitString(lucee.transformer.expression.literal.LitString) ExprString(lucee.transformer.expression.ExprString) Tag(lucee.transformer.bytecode.statement.tag.Tag) TagLibTag(lucee.transformer.library.tag.TagLibTag)

Example 2 with EvaluatorException

use of lucee.transformer.cfml.evaluator.EvaluatorException in project Lucee by lucee.

the class Break method evaluate.

@Override
public void evaluate(Tag tag, TagLibTag libTag) throws EvaluatorException {
    String ns = libTag.getTagLib().getNameSpaceAndSeparator();
    String loopName = ns + "loop";
    String whileName = ns + "while";
    // label
    String label = null;
    Attribute attrLabel = tag.getAttribute("label");
    if (attrLabel != null) {
        TagBreak tb = (TagBreak) tag;
        label = variableToString(tag, attrLabel, null);
        if (label != null) {
            tb.setLabel(label = label.trim());
            tag.removeAttribute("label");
        } else if (ASMUtil.isLiteralAttribute(tag, attrLabel, ASMUtil.TYPE_STRING, false, true)) {
            LitString ls = (LitString) tag.getFactory().toExprString(tag.getAttribute("label").getValue());
            label = ls.getString();
            if (!StringUtil.isEmpty(label, true)) {
                tb.setLabel(label = label.trim());
                tag.removeAttribute("label");
            } else
                label = null;
        }
    }
    // no base tag found
    if (!ASMUtil.hasAncestorBreakFCStatement(tag, label)) {
        if (tag.isScriptBase()) {
            if (StringUtil.isEmpty(label))
                throw new EvaluatorException("Wrong Context, " + libTag.getName() + " must be inside a looping statement or tag");
            throw new EvaluatorException("Wrong Context, " + libTag.getName() + " must be inside a looping statement or tag with the label [" + label + "]");
        }
        if (StringUtil.isEmpty(label))
            throw new EvaluatorException("Wrong Context, tag " + libTag.getFullName() + " must be inside a " + loopName + " or " + whileName + " tag");
        throw new EvaluatorException("Wrong Context, tag " + libTag.getFullName() + " must be inside a " + loopName + " or " + whileName + " tag with the label [" + label + "]");
    }
}
Also used : LitString(lucee.transformer.expression.literal.LitString) Attribute(lucee.transformer.bytecode.statement.tag.Attribute) EvaluatorException(lucee.transformer.cfml.evaluator.EvaluatorException) VariableString(lucee.transformer.bytecode.expression.var.VariableString) LitString(lucee.transformer.expression.literal.LitString) TagBreak(lucee.transformer.bytecode.statement.tag.TagBreak)

Example 3 with EvaluatorException

use of lucee.transformer.cfml.evaluator.EvaluatorException in project Lucee by lucee.

the class Else method evaluate.

@Override
public void evaluate(Tag tag, TagLibTag libTag) throws EvaluatorException {
    String ns = libTag.getTagLib().getNameSpaceAndSeparator();
    String ifName = ns + "if";
    // check if tag is direct inside if
    if (!ASMUtil.isParentTag(tag, TagIf.class)) {
        throw new EvaluatorException("Wrong Context, tag " + libTag.getFullName() + " must be direct inside a " + ifName + " tag");
    }
    // check if is there a elseif tag after this tag
    if (ASMUtil.hasSisterTagAfter(tag, "elseif"))
        throw new EvaluatorException("Wrong Context, tag cfelseif can't be after tag else");
    // check if tag else is unique
    if (ASMUtil.hasSisterTagWithSameName(tag))
        throw new EvaluatorException("Wrong Context, tag else must be once inside the tag if");
}
Also used : EvaluatorException(lucee.transformer.cfml.evaluator.EvaluatorException) TagIf(lucee.transformer.bytecode.statement.tag.TagIf)

Example 4 with EvaluatorException

use of lucee.transformer.cfml.evaluator.EvaluatorException in project Lucee by lucee.

the class ElseIf method evaluate.

@Override
public void evaluate(Tag tag, TagLibTag libTag) throws EvaluatorException {
    String ns = libTag.getTagLib().getNameSpaceAndSeparator();
    String ifName = ns + "if";
    // check if tag is direct inside if
    if (!ASMUtil.isParentTag(tag, TagIf.class))
        throw new EvaluatorException("Wrong Context, tag " + libTag.getFullName() + " must be direct inside a " + ifName + " tag");
}
Also used : EvaluatorException(lucee.transformer.cfml.evaluator.EvaluatorException) TagIf(lucee.transformer.bytecode.statement.tag.TagIf)

Example 5 with EvaluatorException

use of lucee.transformer.cfml.evaluator.EvaluatorException 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)

Aggregations

EvaluatorException (lucee.transformer.cfml.evaluator.EvaluatorException)28 LitString (lucee.transformer.expression.literal.LitString)10 Attribute (lucee.transformer.bytecode.statement.tag.Attribute)9 Tag (lucee.transformer.bytecode.statement.tag.Tag)6 Body (lucee.transformer.bytecode.Body)5 Statement (lucee.transformer.bytecode.Statement)5 ExprString (lucee.transformer.expression.ExprString)5 Expression (lucee.transformer.expression.Expression)5 TagLibTag (lucee.transformer.library.tag.TagLibTag)5 TemplateException (lucee.runtime.exp.TemplateException)4 Page (lucee.transformer.bytecode.Page)4 TransformerException (lucee.transformer.TransformerException)3 StaticBody (lucee.transformer.bytecode.StaticBody)3 Literal (lucee.transformer.expression.literal.Literal)3 TagIf (lucee.transformer.bytecode.statement.tag.TagIf)2 TagLoop (lucee.transformer.bytecode.statement.tag.TagLoop)2 LitBoolean (lucee.transformer.expression.literal.LitBoolean)2 TagLib (lucee.transformer.library.tag.TagLib)2 SourceCode (lucee.transformer.util.SourceCode)2 Iterator (java.util.Iterator)1