Search in sources :

Example 26 with Body

use of lucee.transformer.bytecode.Body in project Lucee by lucee.

the class Try method evaluate.

/**
 * @see lucee.transformer.cfml.evaluator.EvaluatorSupport#evaluate(Element)
 */
@Override
public void evaluate(Tag tag) throws EvaluatorException {
    Body body = tag.getBody();
    int catchCount = 0;
    int noCatchCount = 0;
    int finallyCount = 0;
    // count catch tag and other in body
    if (body != null) {
        List stats = body.getStatements();
        Iterator it = stats.iterator();
        Statement stat;
        Tag t;
        String name;
        while (it.hasNext()) {
            stat = (Statement) it.next();
            if (stat instanceof Tag) {
                t = (Tag) stat;
                name = t.getTagLibTag().getName();
                if (name.equals("finally")) {
                    finallyCount++;
                    noCatchCount++;
                } else if (name.equals("catch"))
                    catchCount++;
                else
                    noCatchCount++;
            } else
                noCatchCount++;
        }
    }
    // check if has Content
    if (catchCount == 0 && finallyCount == 0)
        throw new EvaluatorException("Wrong Context, tag cftry must have at least one tag cfcatch inside or a cffinally tag.");
    if (finallyCount > 1)
        throw new EvaluatorException("Wrong Context, tag cftry can have only one tag cffinally inside.");
    // check if no has Content
    if (noCatchCount == 0) {
        ASMUtil.remove(tag);
    }
}
Also used : EvaluatorException(lucee.transformer.cfml.evaluator.EvaluatorException) Statement(lucee.transformer.bytecode.Statement) Iterator(java.util.Iterator) List(java.util.List) Tag(lucee.transformer.bytecode.statement.tag.Tag) Body(lucee.transformer.bytecode.Body)

Example 27 with Body

use of lucee.transformer.bytecode.Body 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 28 with Body

use of lucee.transformer.bytecode.Body in project Lucee by lucee.

the class AbstrCFMLScriptTransformer method lambdaPart.

@Override
protected final Function lambdaPart(ExprData data, String id, int access, int modifier, String rtnType, Position line, ArrayList<Argument> args) throws TemplateException {
    Body body = new FunctionBody(data.factory);
    Function func = new Lambda(data.root, id, access, modifier, rtnType, body, line, null);
    // new FunctionImpl(data.page,id,access,rtnType,body,line,null);
    comments(data);
    // add arguments
    for (Argument arg : args) {
        func.addArgument(arg.getName(), arg.getType(), arg.getRequired(), arg.getDefaultValue(), arg.isPassByReference(), arg.getDisplayName(), arg.getHint(), arg.getMetaData());
    }
    comments(data);
    // body
    boolean oldInsideFunction = data.insideFunction;
    data.insideFunction = true;
    try {
        if (data.srcCode.isCurrent('{')) {
            statement(data, body, CTX_FUNCTION);
        } else {
            if (data.srcCode.forwardIfCurrent("return ")) {
                comments(data);
            }
            // ex block
            short prior = data.context;
            data.context = CTX_FUNCTION;
            comments(data);
            Expression expr = expression(data);
            // checkSemiColonLineFeed( data, true ,true );
            Return rtn = new Return(expr, line, data.srcCode.getPosition());
            body.addStatement(rtn);
            data.docComment = null;
            data.context = prior;
        }
    } finally {
        data.insideFunction = oldInsideFunction;
    }
    /*try {
		// ex block
		statement(data,body,CTX_FUNCTION);
		}
		finally{
			data.insideFunction=oldInsideFunction;
		}*/
    func.setEnd(data.srcCode.getPosition());
    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) Return(lucee.transformer.bytecode.statement.Return) Argument(lucee.transformer.bytecode.statement.Argument) FunctionAsExpression(lucee.transformer.bytecode.expression.FunctionAsExpression) Expression(lucee.transformer.expression.Expression) FunctionBody(lucee.transformer.bytecode.FunctionBody) Body(lucee.transformer.bytecode.Body) ScriptBody(lucee.transformer.bytecode.ScriptBody) FunctionBody(lucee.transformer.bytecode.FunctionBody) Lambda(lucee.transformer.bytecode.statement.udf.Lambda)

Example 29 with Body

use of lucee.transformer.bytecode.Body 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)

Example 30 with Body

use of lucee.transformer.bytecode.Body in project Lucee by lucee.

the class AbstrCFMLScriptTransformer method __singleAttrStatement.

private final Statement __singleAttrStatement(Body parent, ExprData data, TagLibTag tlt, boolean allowTwiceAttr) throws TemplateException {
    String tagName = tlt.getName();
    if (data.srcCode.forwardIfCurrent(tagName)) {
        if (!data.srcCode.isCurrent(' ') && !data.srcCode.isCurrent(';')) {
            data.srcCode.setPos(data.srcCode.getPos() - tagName.length());
            return null;
        }
    } else
        return null;
    int pos = data.srcCode.getPos() - tagName.length();
    Position line = data.srcCode.getPosition();
    // TagLibTag tlt = CFMLTransformer.getTLT(data.srcCode,tagName.equals("pageencoding")?"processingdirective":tagName);
    Tag tag = getTag(data, parent, tlt, line, null);
    tag.setScriptBase(true);
    tag.setTagLibTag(tlt);
    comments(data);
    // attribute
    TagLibTagAttr attr = tlt.getScript().getSingleAttr();
    String attrName = null;
    Expression attrValue = null;
    short attrType = ATTR_TYPE_NONE;
    if (attr != null) {
        attrType = attr.getScriptSupport();
        char c = data.srcCode.getCurrent();
        if (ATTR_TYPE_REQUIRED == attrType || (!data.srcCode.isCurrent(';') && ATTR_TYPE_OPTIONAL == attrType)) {
            if (data.srcCode.isCurrent('{')) {
                // this can be only a json string
                int p = data.srcCode.getPos();
                try {
                    attrValue = isSimpleValue(attr.getType()) ? null : json(data, JSON_STRUCT, '{', '}');
                } catch (Throwable t) {
                    ExceptionUtil.rethrowIfNecessary(t);
                    data.srcCode.setPos(p);
                }
            } else
                attrValue = attributeValue(data, tlt.getScript().getRtexpr());
            if (attrValue != null && isOperator(c)) {
                data.srcCode.setPos(pos);
                return null;
            }
        }
    }
    if (attrValue != null) {
        attrName = attr.getName();
        TagLibTagAttr tlta = tlt.getAttribute(attr.getName(), true);
        tag.addAttribute(new Attribute(false, attrName, CastOther.toExpression(attrValue, tlta.getType()), tlta.getType()));
    } else if (ATTR_TYPE_REQUIRED == attrType) {
        data.srcCode.setPos(pos);
        return null;
    }
    // body
    if (tlt.getHasBody()) {
        Body body = new BodyBase(data.factory);
        boolean wasSemiColon = statement(data, body, tlt.getScript().getContext());
        if (!wasSemiColon || !tlt.isBodyFree() || body.hasStatements())
            tag.setBody(body);
    } else
        checkSemiColonLineFeed(data, true, true, true);
    if (tlt.hasTTE())
        data.ep.add(tlt, tag, data.flibs, data.srcCode);
    if (!StringUtil.isEmpty(attrName))
        validateAttributeName(attrName, data.srcCode, new ArrayList<String>(), tlt, new RefBooleanImpl(false), new StringBuffer(), allowTwiceAttr);
    tag.setEnd(data.srcCode.getPosition());
    eval(tlt, data, tag);
    return tag;
}
Also used : TagLibTagAttr(lucee.transformer.library.tag.TagLibTagAttr) Position(lucee.transformer.Position) Attribute(lucee.transformer.bytecode.statement.tag.Attribute) ArrayList(java.util.ArrayList) FunctionAsExpression(lucee.transformer.bytecode.expression.FunctionAsExpression) Expression(lucee.transformer.expression.Expression) TagLibTag(lucee.transformer.library.tag.TagLibTag) Tag(lucee.transformer.bytecode.statement.tag.Tag) RefBooleanImpl(lucee.commons.lang.types.RefBooleanImpl) Body(lucee.transformer.bytecode.Body) ScriptBody(lucee.transformer.bytecode.ScriptBody) FunctionBody(lucee.transformer.bytecode.FunctionBody) BodyBase(lucee.transformer.bytecode.BodyBase)

Aggregations

Body (lucee.transformer.bytecode.Body)33 ScriptBody (lucee.transformer.bytecode.ScriptBody)21 BodyBase (lucee.transformer.bytecode.BodyBase)17 FunctionBody (lucee.transformer.bytecode.FunctionBody)15 Statement (lucee.transformer.bytecode.Statement)15 Tag (lucee.transformer.bytecode.statement.tag.Tag)12 Expression (lucee.transformer.expression.Expression)11 Position (lucee.transformer.Position)9 TemplateException (lucee.runtime.exp.TemplateException)8 TagLibTag (lucee.transformer.library.tag.TagLibTag)8 Attribute (lucee.transformer.bytecode.statement.tag.Attribute)7 HasBody (lucee.transformer.bytecode.statement.HasBody)6 LitString (lucee.transformer.expression.literal.LitString)6 ArrayList (java.util.ArrayList)5 FunctionAsExpression (lucee.transformer.bytecode.expression.FunctionAsExpression)5 PrintOut (lucee.transformer.bytecode.statement.PrintOut)5 EvaluatorException (lucee.transformer.cfml.evaluator.EvaluatorException)5 TransformerException (lucee.transformer.TransformerException)4 StaticBody (lucee.transformer.bytecode.StaticBody)4 Literal (lucee.transformer.expression.literal.Literal)4