Search in sources :

Example 1 with LitString

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

the class StructKeyExists method execute.

@Override
public void execute(BIF bif, FunctionLibFunction flf) throws TemplateException {
    Argument arg = bif.getArguments()[1];
    Expression value = arg.getValue();
    if (value instanceof LitString) {
        String str = ((LitString) value).getString();
        // update first arg
        arg.setValue(new CollectionKey(bif.getFactory(), str), Collection.Key.class.getName());
    }
}
Also used : LitString(lucee.transformer.expression.literal.LitString) Argument(lucee.transformer.bytecode.expression.var.Argument) Expression(lucee.transformer.expression.Expression) CollectionKey(lucee.transformer.bytecode.expression.type.CollectionKey) LitString(lucee.transformer.expression.literal.LitString) CollectionKey(lucee.transformer.bytecode.expression.type.CollectionKey)

Example 2 with LitString

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

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

the class Argument method checkDefaultValue.

public static void checkDefaultValue(Tag tag) {
    Attribute _type = tag.getAttribute("type");
    if (_type != null) {
        ExprString typeValue = tag.getFactory().toExprString(_type.getValue());
        if (typeValue instanceof LitString) {
            String strType = ((LitString) typeValue).getString();
            Attribute _default = tag.getAttribute("default");
            if (_default != null) {
                Expression defaultValue = _default.getValue();
                if (defaultValue instanceof LitString) {
                    String strDefault = ((LitString) defaultValue).getString();
                    // check for boolean
                    if ("boolean".equalsIgnoreCase(strType)) {
                        if ("true".equalsIgnoreCase(strDefault) || "yes".equalsIgnoreCase(strDefault))
                            tag.addAttribute(new Attribute(_default.isDynamicType(), _default.getName(), tag.getFactory().TRUE(), _default.getType()));
                        if ("false".equalsIgnoreCase(strDefault) || "no".equalsIgnoreCase(strDefault))
                            tag.addAttribute(new Attribute(_default.isDynamicType(), _default.getName(), tag.getFactory().FALSE(), _default.getType()));
                    }
                    // check for numbers
                    if ("number".equalsIgnoreCase(strType) || "numeric".equalsIgnoreCase(strType)) {
                        Double dbl = Caster.toDouble(strDefault, null);
                        if (dbl != null) {
                            tag.addAttribute(new Attribute(_default.isDynamicType(), _default.getName(), tag.getFactory().createLitDouble(dbl.doubleValue()), _default.getType()));
                        }
                    }
                }
            }
        }
    }
}
Also used : LitString(lucee.transformer.expression.literal.LitString) Attribute(lucee.transformer.bytecode.statement.tag.Attribute) ExprString(lucee.transformer.expression.ExprString) Expression(lucee.transformer.expression.Expression) LitString(lucee.transformer.expression.literal.LitString) ExprString(lucee.transformer.expression.ExprString)

Example 4 with LitString

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

use of lucee.transformer.expression.literal.LitString 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

LitString (lucee.transformer.expression.literal.LitString)36 Expression (lucee.transformer.expression.Expression)21 ExprString (lucee.transformer.expression.ExprString)13 GeneratorAdapter (org.objectweb.asm.commons.GeneratorAdapter)11 Attribute (lucee.transformer.bytecode.statement.tag.Attribute)9 EvaluatorException (lucee.transformer.cfml.evaluator.EvaluatorException)8 TransformerException (lucee.transformer.TransformerException)6 Statement (lucee.transformer.bytecode.Statement)6 ArrayList (java.util.ArrayList)5 Iterator (java.util.Iterator)5 Body (lucee.transformer.bytecode.Body)5 Argument (lucee.transformer.bytecode.expression.var.Argument)5 PrintOut (lucee.transformer.bytecode.statement.PrintOut)5 Literal (lucee.transformer.expression.literal.Literal)5 TemplateException (lucee.runtime.exp.TemplateException)4 BytecodeContext (lucee.transformer.bytecode.BytecodeContext)4 TagLibTag (lucee.transformer.library.tag.TagLibTag)4 Label (org.objectweb.asm.Label)4 BodyBase (lucee.transformer.bytecode.BodyBase)3 Page (lucee.transformer.bytecode.Page)3