Search in sources :

Example 26 with Attribute

use of lucee.transformer.bytecode.statement.tag.Attribute in project Lucee by lucee.

the class Continue 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) {
        TagContinue tc = (TagContinue) tag;
        label = Break.variableToString(tag, attrLabel, null);
        if (label != null) {
            tc.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)) {
                tc.setLabel(label = label.trim());
                tag.removeAttribute("label");
            } else
                label = null;
        }
    }
    if (ASMUtil.isLiteralAttribute(tag, "label", ASMUtil.TYPE_STRING, false, true)) {
        LitString ls = (LitString) tag.getFactory().toExprString(tag.getAttribute("label").getValue());
        TagContinue tc = (TagContinue) tag;
        label = ls.getString();
        if (!StringUtil.isEmpty(label, true)) {
            tc.setLabel(label = label.trim());
            tag.removeAttribute("label");
        } else
            label = null;
    }
    if (!ASMUtil.hasAncestorContinueFCStatement(tag, label)) {
        if (tag.isScriptBase()) {
            if (StringUtil.isEmpty(label))
                throw new EvaluatorException("Wrong Context, " + libTag.getName() + " must be inside a loop (for,while,loop ...)");
            throw new EvaluatorException("Wrong Context, " + libTag.getName() + " must be inside a loop (for,while,loop ...) 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) TagContinue(lucee.transformer.bytecode.statement.tag.TagContinue) Attribute(lucee.transformer.bytecode.statement.tag.Attribute) EvaluatorException(lucee.transformer.cfml.evaluator.EvaluatorException) LitString(lucee.transformer.expression.literal.LitString)

Example 27 with Attribute

use of lucee.transformer.bytecode.statement.tag.Attribute in project Lucee by lucee.

the class Mail method evaluate.

@Override
public void evaluate(Tag tag, TagLibTag libTag) throws EvaluatorException {
    if (tag.containsAttribute("query")) {
        TagLib lib = libTag.getTagLib();
        TagLibTag outputTag = lib.getTag("output");
        TagOutput output = new TagOutput(tag.getFactory(), tag.getStart(), null);
        output.setFullname(outputTag.getFullName());
        output.setTagLibTag(outputTag);
        output.addAttribute(new Attribute(false, "output", tag.getFactory().TRUE(), "boolean"));
        output.addAttribute(new Attribute(false, "formail", tag.getFactory().TRUE(), "boolean"));
        // output.getBody();
        Body body = new BodyBase(tag.getFactory());
        output.setBody(body);
        ASMUtil.replace(tag, output, false);
        body.addStatement(tag);
        output.addAttribute(tag.removeAttribute("query"));
        if (tag.containsAttribute("group"))
            output.addAttribute(tag.removeAttribute("group"));
        if (tag.containsAttribute("groupcasesensitive"))
            output.addAttribute(tag.removeAttribute("groupcasesensitive"));
        if (tag.containsAttribute("startrow"))
            output.addAttribute(tag.removeAttribute("startrow"));
        if (tag.containsAttribute("maxrows"))
            output.addAttribute(tag.removeAttribute("maxrows"));
        new Output().evaluate(output, outputTag);
    }
}
Also used : TagLibTag(lucee.transformer.library.tag.TagLibTag) TagOutput(lucee.transformer.bytecode.statement.tag.TagOutput) Attribute(lucee.transformer.bytecode.statement.tag.Attribute) TagLib(lucee.transformer.library.tag.TagLib) TagOutput(lucee.transformer.bytecode.statement.tag.TagOutput) Body(lucee.transformer.bytecode.Body) BodyBase(lucee.transformer.bytecode.BodyBase)

Example 28 with Attribute

use of lucee.transformer.bytecode.statement.tag.Attribute in project Lucee by lucee.

the class Sprite method evaluate.

@Override
public void evaluate(Tag tag, TagLibTag tagLibTag, FunctionLib[] flibs) throws EvaluatorException {
    String id = "sprite_" + IDGenerator.intId();
    try {
        Page page = ASMUtil.getAncestorPage(tag);
        SourceCode sc = page.getSourceCode();
        String key = sc.id();
        key = HashUtil.create64BitHashAsString(Thread.currentThread().getId() + ":" + key);
        Expression src = tag.getAttribute("src").getValue();
        // get data from previous sprites
        Previous previous = sprites.get(key);
        if (previous != null) {
            previous.tag.removeAttribute("_ids");
            previous.tag.removeAttribute("_srcs");
            previous.tag = tag;
        } else {
            sprites.put(key, previous = new Previous(tag));
        }
        previous.ids.add(id);
        if (previous.src == null)
            previous.src = src;
        else {
            previous.src = tag.getFactory().opString(previous.src, tag.getFactory().createLitString(","));
            previous.src = tag.getFactory().opString(previous.src, src);
        }
        tag.addAttribute(new Attribute(false, "_id", tag.getFactory().createLitString(id), "string"));
        tag.addAttribute(new Attribute(false, "_ids", tag.getFactory().createLitString(lucee.runtime.type.util.ListUtil.listToList(previous.ids, ",")), "string"));
        tag.addAttribute(new Attribute(false, "_srcs", previous.src, "string"));
    } catch (Throwable e) {
        // TODO handle Excpetion much more precise
        ExceptionUtil.rethrowIfNecessary(e);
        throw new PageRuntimeException(Caster.toPageException(e));
    }
}
Also used : SourceCode(lucee.transformer.util.SourceCode) Expression(lucee.transformer.expression.Expression) Attribute(lucee.transformer.bytecode.statement.tag.Attribute) Page(lucee.transformer.bytecode.Page) PageRuntimeException(lucee.runtime.exp.PageRuntimeException)

Example 29 with Attribute

use of lucee.transformer.bytecode.statement.tag.Attribute in project Lucee by lucee.

the class AbstrCFMLScriptTransformer method __multiAttrStatement.

private final Tag __multiAttrStatement(Body parent, ExprData data, TagLibTag tlt) throws TemplateException {
    if (data.ep == null)
        return null;
    String type = tlt.getName();
    if (data.srcCode.forwardIfCurrent(type) || // lucee dialect support component as alias for class
    (data.srcCode.getDialect() == CFMLEngine.DIALECT_LUCEE && type.equalsIgnoreCase(Constants.LUCEE_COMPONENT_TAG_NAME) && data.srcCode.forwardIfCurrent(Constants.CFML_COMPONENT_TAG_NAME))) {
        boolean isValid = (data.srcCode.isCurrent(' ') || (tlt.getHasBody() && data.srcCode.isCurrent('{')));
        if (!isValid) {
            data.srcCode.setPos(data.srcCode.getPos() - type.length());
            return null;
        }
    } else
        return null;
    Position line = data.srcCode.getPosition();
    TagLibTagScript script = tlt.getScript();
    // TagLibTag tlt = CFMLTransformer.getTLT(data.srcCode,type);
    if (script.getContext() == CTX_CFC)
        data.isCFC = true;
    else if (script.getContext() == CTX_INTERFACE)
        data.isInterface = true;
    // Tag tag=new TagComponent(line);
    Tag tag = getTag(data, parent, tlt, line, null);
    tag.setTagLibTag(tlt);
    tag.setScriptBase(true);
    // add component meta data
    if (data.isCFC) {
        addMetaData(data, tag, IGNORE_LIST_COMPONENT);
    }
    if (data.isInterface) {
        addMetaData(data, tag, IGNORE_LIST_INTERFACE);
    }
    // EvaluatorPool.getPool();
    comments(data);
    // attributes
    // attributes(func,data);
    Attribute[] attrs = attributes(tag, tlt, data, SEMI_BLOCK, data.factory.EMPTY(), script.getRtexpr() ? Boolean.TRUE : Boolean.FALSE, null, false, ',', false);
    for (int i = 0; i < attrs.length; i++) {
        tag.addAttribute(attrs[i]);
    }
    comments(data);
    // body
    if (tlt.getHasBody()) {
        Body body = new BodyBase(data.factory);
        boolean wasSemiColon = statement(data, body, script.getContext());
        if (!wasSemiColon || !tlt.isBodyFree() || body.hasStatements())
            tag.setBody(body);
    } else
        checkSemiColonLineFeed(data, true, true, true);
    tag.setEnd(data.srcCode.getPosition());
    eval(tlt, data, tag);
    return tag;
}
Also used : TagLibTagScript(lucee.transformer.library.tag.TagLibTagScript) Position(lucee.transformer.Position) Attribute(lucee.transformer.bytecode.statement.tag.Attribute) TagLibTag(lucee.transformer.library.tag.TagLibTag) Tag(lucee.transformer.bytecode.statement.tag.Tag) Body(lucee.transformer.bytecode.Body) ScriptBody(lucee.transformer.bytecode.ScriptBody) FunctionBody(lucee.transformer.bytecode.FunctionBody) BodyBase(lucee.transformer.bytecode.BodyBase)

Example 30 with Attribute

use of lucee.transformer.bytecode.statement.tag.Attribute in project Lucee by lucee.

the class AbstrCFMLScriptTransformer method closurePart.

@Override
protected final Function closurePart(ExprData data, String id, int access, int modifier, String rtnType, Position line, boolean closure) throws TemplateException {
    Body body = new FunctionBody(data.factory);
    Function func = closure ? new Closure(data.root, id, access, modifier, rtnType, body, line, null) : new FunctionImpl(data.root, id, access, modifier, rtnType, body, line, null);
    comments(data);
    if (!data.srcCode.forwardIfCurrent('('))
        throw new TemplateException(data.srcCode, "invalid syntax in function head, missing begin [(]");
    // arguments
    ArrayList<Argument> args = getScriptFunctionArguments(data);
    for (Argument arg : args) {
        func.addArgument(arg.getName(), arg.getType(), arg.getRequired(), arg.getDefaultValue(), arg.isPassByReference(), arg.getDisplayName(), arg.getHint(), arg.getMetaData());
    }
    // end )
    comments(data);
    if (!data.srcCode.forwardIfCurrent(')'))
        throw new TemplateException(data.srcCode, "invalid syntax in function head, missing ending [)]");
    // doc comment
    if (data.docComment != null) {
        func.setHint(data.factory, data.docComment.getHint());
        // params
        /*Map<String, Attribute> params = data.docComment.getParams();
			Iterator<Attribute> it = params.values().iterator();
			Attribute attr;
			String name;
			while(it.hasNext()){
				attr=it.next();
				name=attr.getName();
			}*/
        func.setMetaData(data.docComment.getParams());
        data.docComment = null;
    }
    comments(data);
    // attributes
    Attribute[] attrs = attributes(null, null, data, SEMI_BLOCK, data.factory.EMPTY(), Boolean.TRUE, null, false, NO_ATTR_SEP, true);
    for (int i = 0; i < attrs.length; i++) {
        func.addAttribute(attrs[i]);
    }
    // body
    boolean oldInsideFunction = data.insideFunction;
    data.insideFunction = true;
    try {
        // ex block
        statement(data, body, CTX_FUNCTION);
    } finally {
        data.insideFunction = oldInsideFunction;
    }
    func.setEnd(data.srcCode.getPosition());
    if (closure)
        comments(data);
    return func;
}
Also used : Function(lucee.transformer.bytecode.statement.udf.Function) CFFunction(lucee.runtime.functions.system.CFFunction) FunctionLibFunction(lucee.transformer.library.function.FunctionLibFunction) Closure(lucee.transformer.bytecode.statement.udf.Closure) Argument(lucee.transformer.bytecode.statement.Argument) TemplateException(lucee.runtime.exp.TemplateException) Attribute(lucee.transformer.bytecode.statement.tag.Attribute) FunctionBody(lucee.transformer.bytecode.FunctionBody) FunctionImpl(lucee.transformer.bytecode.statement.udf.FunctionImpl) Body(lucee.transformer.bytecode.Body) ScriptBody(lucee.transformer.bytecode.ScriptBody) FunctionBody(lucee.transformer.bytecode.FunctionBody)

Aggregations

Attribute (lucee.transformer.bytecode.statement.tag.Attribute)35 Expression (lucee.transformer.expression.Expression)16 LitString (lucee.transformer.expression.literal.LitString)13 TagLibTag (lucee.transformer.library.tag.TagLibTag)11 TemplateException (lucee.runtime.exp.TemplateException)10 EvaluatorException (lucee.transformer.cfml.evaluator.EvaluatorException)9 Tag (lucee.transformer.bytecode.statement.tag.Tag)8 LitBoolean (lucee.transformer.expression.literal.LitBoolean)8 Body (lucee.transformer.bytecode.Body)7 Literal (lucee.transformer.expression.literal.Literal)6 TagLibTagAttr (lucee.transformer.library.tag.TagLibTagAttr)6 Position (lucee.transformer.Position)5 ExprString (lucee.transformer.expression.ExprString)5 ArrayList (java.util.ArrayList)4 RefBoolean (lucee.commons.lang.types.RefBoolean)4 RefBooleanImpl (lucee.commons.lang.types.RefBooleanImpl)4 BodyBase (lucee.transformer.bytecode.BodyBase)4 FunctionBody (lucee.transformer.bytecode.FunctionBody)4 Page (lucee.transformer.bytecode.Page)4 ScriptBody (lucee.transformer.bytecode.ScriptBody)4