Search in sources :

Example 1 with ExprString

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

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

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

use of lucee.transformer.expression.ExprString in project Lucee by lucee.

the class Interface method evaluate.

@Override
public void evaluate(Tag tag, TagLibTag libTag) throws EvaluatorException {
    super.evaluate(tag, libTag);
    Body body = tag.getBody();
    List<Statement> statments = body.getStatements();
    Statement stat;
    Iterator<Statement> it = statments.iterator();
    Tag t;
    while (it.hasNext()) {
        stat = it.next();
        if (stat instanceof PrintOut) {
        // body.remove(stat);
        } else if (stat instanceof Tag) {
            t = (Tag) stat;
            if (stat instanceof TagImport) {
            // ignore
            } else if (stat instanceof TagFunction) {
                Function.throwIfNotEmpty(t);
                Attribute attr = t.getAttribute("access");
                if (attr != null) {
                    ExprString expr = t.getFactory().toExprString(attr.getValue());
                    if (!(expr instanceof LitString))
                        throw new EvaluatorException("the attribute access of the Tag function inside an interface must contain a constant value");
                    String access = ((LitString) expr).getString().trim();
                    if (!"public".equalsIgnoreCase(access))
                        throw new EvaluatorException("the attribute access of the tag function inside an interface definition can only have the value [public] not [" + access + "]");
                } else
                    t.addAttribute(new Attribute(false, "access", stat.getFactory().createLitString("public"), "string"));
            } else
                throw new EvaluatorException("tag " + libTag.getFullName() + " can only contain function definitions.");
        }
    }
}
Also used : TagFunction(lucee.transformer.bytecode.statement.tag.TagFunction) Attribute(lucee.transformer.bytecode.statement.tag.Attribute) ExprString(lucee.transformer.expression.ExprString) Statement(lucee.transformer.bytecode.Statement) LitString(lucee.transformer.expression.literal.LitString) ExprString(lucee.transformer.expression.ExprString) TagImport(lucee.transformer.bytecode.statement.tag.TagImport) LitString(lucee.transformer.expression.literal.LitString) PrintOut(lucee.transformer.bytecode.statement.PrintOut) EvaluatorException(lucee.transformer.cfml.evaluator.EvaluatorException) TagLibTag(lucee.transformer.library.tag.TagLibTag) Tag(lucee.transformer.bytecode.statement.tag.Tag) Body(lucee.transformer.bytecode.Body)

Example 5 with ExprString

use of lucee.transformer.expression.ExprString in project Lucee by lucee.

the class AbstrCFMLExprTransformer method newOp.

private Expression newOp(ExprData data, Expression expr) throws TemplateException {
    if (!(expr instanceof Variable))
        return expr;
    Variable var = (Variable) expr;
    Member m = var.getFirstMember();
    if (!(m instanceof DataMember))
        return expr;
    ExprString n = ((DataMember) m).getName();
    if (!(n instanceof LitString))
        return expr;
    LitString ls = (LitString) n;
    if (!"new".equalsIgnoreCase(ls.getString()))
        return expr;
    int start = data.srcCode.getPos();
    ExprString exprName = readComponentPath(data);
    if (exprName == null) {
        data.srcCode.setPos(start);
        return expr;
    }
    comments(data);
    if (data.srcCode.isCurrent('(')) {
        FunctionMember func = getFunctionMember(data, Identifier.toIdentifier(data.factory, "_createComponent", Identifier.CASE_ORIGNAL, null, null), true);
        func.addArgument(new Argument(exprName, "string"));
        Variable v = expr.getFactory().createVariable(expr.getStart(), expr.getEnd());
        v.addMember(func);
        comments(data);
        return v;
    }
    data.srcCode.setPos(start);
    return expr;
}
Also used : LitString(lucee.transformer.expression.literal.LitString) OpVariable(lucee.transformer.bytecode.op.OpVariable) Variable(lucee.transformer.expression.var.Variable) NamedArgument(lucee.transformer.bytecode.expression.var.NamedArgument) Argument(lucee.transformer.bytecode.expression.var.Argument) ExprString(lucee.transformer.expression.ExprString) DataMember(lucee.transformer.expression.var.DataMember) FunctionMember(lucee.transformer.bytecode.expression.var.FunctionMember) DataMember(lucee.transformer.expression.var.DataMember) Member(lucee.transformer.expression.var.Member) FunctionMember(lucee.transformer.bytecode.expression.var.FunctionMember)

Aggregations

ExprString (lucee.transformer.expression.ExprString)22 LitString (lucee.transformer.expression.literal.LitString)15 Expression (lucee.transformer.expression.Expression)9 GeneratorAdapter (org.objectweb.asm.commons.GeneratorAdapter)8 Type (org.objectweb.asm.Type)6 TemplateException (lucee.runtime.exp.TemplateException)4 FunctionAsExpression (lucee.transformer.bytecode.expression.FunctionAsExpression)4 Attribute (lucee.transformer.bytecode.statement.tag.Attribute)4 Variable (lucee.transformer.expression.var.Variable)4 Method (org.objectweb.asm.commons.Method)4 OpVariable (lucee.transformer.bytecode.op.OpVariable)3 EvaluatorException (lucee.transformer.cfml.evaluator.EvaluatorException)3 ExprBoolean (lucee.transformer.expression.ExprBoolean)3 ExprDouble (lucee.transformer.expression.ExprDouble)3 DataMember (lucee.transformer.expression.var.DataMember)3 Member (lucee.transformer.expression.var.Member)3 Position (lucee.transformer.Position)2 TransformerException (lucee.transformer.TransformerException)2 Body (lucee.transformer.bytecode.Body)2 Argument (lucee.transformer.bytecode.expression.var.Argument)2