Search in sources :

Example 1 with LitBoolean

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

the class Component method evaluate.

@Override
public TagLibTag evaluate(TagLibTag tagLibTag, Tag tag) throws AttributeEvaluatorException {
    tagLibTag.setParseBody(false);
    Attribute attr = tag.getAttribute("output");
    if (attr != null) {
        Expression expr = attr.getValue();
        if (!(expr instanceof LitBoolean))
            throw new AttributeEvaluatorException("Attribute output of the Tag Component, must be a static boolean value (true or false)");
        if (((LitBoolean) expr).getBooleanValue())
            tagLibTag.setParseBody(true);
    }
    return tagLibTag;
}
Also used : AttributeEvaluatorException(lucee.transformer.cfml.attributes.AttributeEvaluatorException) Attribute(lucee.transformer.bytecode.statement.tag.Attribute) Expression(lucee.transformer.expression.Expression) LitBoolean(lucee.transformer.expression.literal.LitBoolean)

Example 2 with LitBoolean

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

the class Function method evaluate.

@Override
public TagLibTag evaluate(TagLibTag tagLibTag, Tag tag) throws AttributeEvaluatorException {
    tagLibTag.setParseBody(false);
    Attribute attrOutput = tag.getAttribute("output");
    if (attrOutput == null)
        return tagLibTag;
    Expression expr = CastBoolean.toExprBoolean(attrOutput.getValue());
    if (!(expr instanceof LitBoolean))
        throw new AttributeEvaluatorException("Attribute output of the Tag Function, must be a literal boolean value (true or false)");
    boolean output = ((LitBoolean) expr).getBooleanValue();
    if (output)
        tagLibTag.setParseBody(true);
    return tagLibTag;
}
Also used : AttributeEvaluatorException(lucee.transformer.cfml.attributes.AttributeEvaluatorException) Attribute(lucee.transformer.bytecode.statement.tag.Attribute) Expression(lucee.transformer.expression.Expression) LitBoolean(lucee.transformer.expression.literal.LitBoolean)

Example 3 with LitBoolean

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

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

the class AbstrCFMLScriptTransformer method getScriptFunctionArguments.

@Override
public ArrayList<Argument> getScriptFunctionArguments(ExprData data) throws TemplateException {
    // arguments
    LitBoolean passByRef;
    Expression displayName;
    Expression hint;
    Map<String, Attribute> meta;
    String _name;
    ArrayList<Argument> result = new ArrayList<Argument>();
    do {
        comments(data);
        // finish
        if (data.srcCode.isCurrent(')'))
            break;
        // attribute
        // name
        // String idName=identifier(data,false,true);
        boolean required = false;
        String idName = variableDec(data, false);
        // required
        if ("required".equalsIgnoreCase(idName)) {
            comments(data);
            String idName2 = variableDec(data, false);
            if (idName2 != null) {
                idName = idName2;
                required = true;
            }
            if (idName == null)
                throw new TemplateException(data.srcCode, "invalid argument definition");
        }
        String typeName = "any";
        if (idName == null)
            throw new TemplateException(data.srcCode, "invalid argument definition");
        comments(data);
        if (!data.srcCode.isCurrent(')') && !data.srcCode.isCurrent('=') && !data.srcCode.isCurrent(':') && !data.srcCode.isCurrent(',')) {
            typeName = idName.toLowerCase();
            // MUST was upper case before, is this a problem?
            idName = identifier(data, false);
        } else if (idName.indexOf('.') != -1 || idName.indexOf('[') != -1) {
            throw new TemplateException(data.srcCode, "invalid argument name [" + idName + "] definition");
        }
        if (idName == null)
            throw new TemplateException(data.srcCode, "invalid argument definition");
        comments(data);
        Expression defaultValue;
        if (data.srcCode.isCurrent('=') || data.srcCode.isCurrent(':')) {
            data.srcCode.next();
            comments(data);
            defaultValue = expression(data);
        } else
            defaultValue = null;
        // assign meta data defined in doc comment
        passByRef = data.factory.TRUE();
        displayName = data.factory.EMPTY();
        hint = data.factory.EMPTY();
        meta = null;
        if (data.docComment != null) {
            Map<String, Attribute> params = data.docComment.getParams();
            Attribute[] attrs = params.values().toArray(new Attribute[params.size()]);
            Attribute attr;
            String name;
            for (int i = 0; i < attrs.length; i++) {
                attr = attrs[i];
                name = attr.getName();
                // hint
                if (idName.equalsIgnoreCase(name) || name.equalsIgnoreCase(idName + ".hint")) {
                    hint = data.factory.toExprString(attr.getValue());
                    params.remove(name);
                }
                // meta
                if (StringUtil.startsWithIgnoreCase(name, idName + ".")) {
                    if (name.length() > idName.length() + 1) {
                        if (meta == null)
                            meta = new HashMap<String, Attribute>();
                        _name = name.substring(idName.length() + 1);
                        meta.put(_name, new Attribute(attr.isDynamicType(), _name, attr.getValue(), attr.getType()));
                    }
                    params.remove(name);
                }
            }
        }
        // argument attributes
        Attribute[] _attrs = attributes(null, null, data, COMMA_ENDBRACKED, data.factory.EMPTY(), Boolean.TRUE, null, false, NO_ATTR_SEP, true);
        Attribute _attr;
        if (!ArrayUtil.isEmpty(_attrs)) {
            if (meta == null)
                meta = new HashMap<String, Attribute>();
            for (int i = 0; i < _attrs.length; i++) {
                _attr = _attrs[i];
                meta.put(_attr.getName(), _attr);
            }
        }
        result.add(new Argument(data.factory.createLitString(idName), data.factory.createLitString(typeName), data.factory.createLitBoolean(required), defaultValue, passByRef, displayName, hint, meta));
        comments(data);
    } while (data.srcCode.forwardIfCurrent(','));
    return result;
}
Also used : Argument(lucee.transformer.bytecode.statement.Argument) Attribute(lucee.transformer.bytecode.statement.tag.Attribute) TemplateException(lucee.runtime.exp.TemplateException) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) LitBoolean(lucee.transformer.expression.literal.LitBoolean) FunctionAsExpression(lucee.transformer.bytecode.expression.FunctionAsExpression) Expression(lucee.transformer.expression.Expression)

Example 5 with LitBoolean

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

the class TagFunction method addArgument.

private void addArgument(Function func, Tag tag) {
    Attribute attr;
    // name
    Expression name = tag.removeAttribute("name").getValue();
    // type
    attr = tag.removeAttribute("type");
    Expression type = (attr == null) ? tag.getFactory().createLitString("any") : attr.getValue();
    // required
    attr = tag.removeAttribute("required");
    Expression required = (attr == null) ? tag.getFactory().FALSE() : attr.getValue();
    // default
    attr = tag.removeAttribute("default");
    Expression defaultValue = (attr == null) ? null : attr.getValue();
    // passby
    attr = tag.removeAttribute("passby");
    LitBoolean passByReference = tag.getFactory().TRUE();
    if (attr != null) {
        // i can cast irt to LitString because he evulator check this before
        String str = ((LitString) attr.getValue()).getString();
        if (str.trim().equalsIgnoreCase("value"))
            passByReference = tag.getFactory().FALSE();
    }
    // displayname
    attr = tag.removeAttribute("displayname");
    Expression displayName = (attr == null) ? tag.getFactory().EMPTY() : attr.getValue();
    // hint
    attr = tag.removeAttribute("hint");
    if (attr == null)
        attr = tag.removeAttribute("description");
    Expression hint;
    if (attr == null)
        hint = tag.getFactory().EMPTY();
    else
        hint = attr.getValue();
    func.addArgument(name, type, required, defaultValue, passByReference, displayName, hint, tag.getAttributes());
}
Also used : LitString(lucee.transformer.expression.literal.LitString) Expression(lucee.transformer.expression.Expression) LitBoolean(lucee.transformer.expression.literal.LitBoolean) LitString(lucee.transformer.expression.literal.LitString)

Aggregations

Expression (lucee.transformer.expression.Expression)7 LitBoolean (lucee.transformer.expression.literal.LitBoolean)7 Attribute (lucee.transformer.bytecode.statement.tag.Attribute)6 LitString (lucee.transformer.expression.literal.LitString)3 Page (lucee.transformer.bytecode.Page)2 AttributeEvaluatorException (lucee.transformer.cfml.attributes.AttributeEvaluatorException)2 EvaluatorException (lucee.transformer.cfml.evaluator.EvaluatorException)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 ParserString (lucee.commons.lang.ParserString)1 PageSource (lucee.runtime.PageSource)1 TemplateException (lucee.runtime.exp.TemplateException)1 TransformerException (lucee.transformer.TransformerException)1 Body (lucee.transformer.bytecode.Body)1 Statement (lucee.transformer.bytecode.Statement)1 StaticBody (lucee.transformer.bytecode.StaticBody)1 FunctionAsExpression (lucee.transformer.bytecode.expression.FunctionAsExpression)1 Argument (lucee.transformer.bytecode.statement.Argument)1 Tag (lucee.transformer.bytecode.statement.tag.Tag)1 TagCIObject (lucee.transformer.bytecode.statement.tag.TagCIObject)1