Search in sources :

Example 1 with FunctionBody

use of lucee.transformer.bytecode.FunctionBody 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 2 with FunctionBody

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

CFFunction (lucee.runtime.functions.system.CFFunction)2 Body (lucee.transformer.bytecode.Body)2 FunctionBody (lucee.transformer.bytecode.FunctionBody)2 ScriptBody (lucee.transformer.bytecode.ScriptBody)2 Argument (lucee.transformer.bytecode.statement.Argument)2 Function (lucee.transformer.bytecode.statement.udf.Function)2 FunctionLibFunction (lucee.transformer.library.function.FunctionLibFunction)2 TemplateException (lucee.runtime.exp.TemplateException)1 FunctionAsExpression (lucee.transformer.bytecode.expression.FunctionAsExpression)1 Return (lucee.transformer.bytecode.statement.Return)1 Attribute (lucee.transformer.bytecode.statement.tag.Attribute)1 Closure (lucee.transformer.bytecode.statement.udf.Closure)1 FunctionImpl (lucee.transformer.bytecode.statement.udf.FunctionImpl)1 Lambda (lucee.transformer.bytecode.statement.udf.Lambda)1 Expression (lucee.transformer.expression.Expression)1