Search in sources :

Example 1 with FunctionImpl

use of lucee.transformer.bytecode.statement.udf.FunctionImpl in project Lucee by lucee.

the class TagFunction method createFunction.

private Function createFunction(Page page, Body body, RefBoolean isStatic, boolean defaultOutput) throws TransformerException {
    Attribute attr;
    LitString ANY = page.getFactory().createLitString("any");
    LitString PUBLIC = page.getFactory().createLitString("public");
    // name
    Expression name = removeAttribute("name").getValue();
    /*if(name instanceof LitString) {
			((LitString)name).upperCase();
		}*/
    // return
    attr = removeAttribute("returntype");
    // if(attr==null) attr = getAttribute("return");
    // if(attr==null) attr = getAttribute("type");
    Expression returnType = (attr == null) ? ANY : attr.getValue();
    // output
    attr = removeAttribute("output");
    Expression output = (attr == null) ? (defaultOutput ? page.getFactory().TRUE() : page.getFactory().TRUE()) : attr.getValue();
    // bufferOutput
    attr = removeAttribute("bufferoutput");
    Expression bufferOutput = (attr == null) ? null : attr.getValue();
    // modifier
    isStatic.setValue(false);
    int modifier = Component.MODIFIER_NONE;
    attr = removeAttribute("modifier");
    if (attr != null) {
        Expression val = attr.getValue();
        if (val instanceof Literal) {
            Literal l = (Literal) val;
            String str = StringUtil.emptyIfNull(l.getString()).trim();
            if ("abstract".equalsIgnoreCase(str))
                modifier = Component.MODIFIER_ABSTRACT;
            else if ("final".equalsIgnoreCase(str))
                modifier = Component.MODIFIER_FINAL;
            else if ("static".equalsIgnoreCase(str))
                isStatic.setValue(true);
        }
    }
    // access
    attr = removeAttribute("access");
    Expression access = (attr == null) ? PUBLIC : attr.getValue();
    // dspLabel
    attr = removeAttribute("displayname");
    Expression displayname = (attr == null) ? page.getFactory().EMPTY() : attr.getValue();
    // hint
    attr = removeAttribute("hint");
    Expression hint = (attr == null) ? page.getFactory().EMPTY() : attr.getValue();
    // description
    attr = removeAttribute("description");
    Expression description = (attr == null) ? page.getFactory().EMPTY() : attr.getValue();
    // returnformat
    attr = removeAttribute("returnformat");
    Expression returnFormat = (attr == null) ? null : attr.getValue();
    // secureJson
    attr = removeAttribute("securejson");
    Expression secureJson = (attr == null) ? null : attr.getValue();
    // verifyClient
    attr = removeAttribute("verifyclient");
    Expression verifyClient = (attr == null) ? null : attr.getValue();
    // localMode
    attr = removeAttribute("localmode");
    Expression localMode = (attr == null) ? null : attr.getValue();
    // cachedWithin
    Literal cachedWithin = null;
    attr = removeAttribute("cachedwithin");
    if (attr != null) {
        Expression val = attr.getValue();
        if (val instanceof Literal)
            cachedWithin = ((Literal) val);
    }
    String strAccess = ((LitString) access).getString();
    int acc = ComponentUtil.toIntAccess(strAccess, -1);
    if (acc == -1)
        throw new TransformerException("invalid access type [" + strAccess + "], access types are remote, public, package, private", getStart());
    Function func = new FunctionImpl(page, name, returnType, returnFormat, output, bufferOutput, acc, displayname, description, hint, secureJson, verifyClient, localMode, cachedWithin, modifier, body, getStart(), getEnd());
    // %**%
    Map attrs = getAttributes();
    Iterator it = attrs.entrySet().iterator();
    HashMap<String, Attribute> metadatas = new HashMap<String, Attribute>();
    while (it.hasNext()) {
        attr = (Attribute) ((Map.Entry) it.next()).getValue();
        metadatas.put(attr.getName(), attr);
    }
    func.setMetaData(metadatas);
    return func;
}
Also used : HashMap(java.util.HashMap) LitString(lucee.transformer.expression.literal.LitString) LitString(lucee.transformer.expression.literal.LitString) Function(lucee.transformer.bytecode.statement.udf.Function) IFunction(lucee.transformer.bytecode.statement.IFunction) Expression(lucee.transformer.expression.Expression) Literal(lucee.transformer.expression.literal.Literal) FunctionImpl(lucee.transformer.bytecode.statement.udf.FunctionImpl) Iterator(java.util.Iterator) HashMap(java.util.HashMap) Map(java.util.Map) TransformerException(lucee.transformer.TransformerException)

Example 2 with FunctionImpl

use of lucee.transformer.bytecode.statement.udf.FunctionImpl 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

Function (lucee.transformer.bytecode.statement.udf.Function)2 FunctionImpl (lucee.transformer.bytecode.statement.udf.FunctionImpl)2 HashMap (java.util.HashMap)1 Iterator (java.util.Iterator)1 Map (java.util.Map)1 TemplateException (lucee.runtime.exp.TemplateException)1 CFFunction (lucee.runtime.functions.system.CFFunction)1 TransformerException (lucee.transformer.TransformerException)1 Body (lucee.transformer.bytecode.Body)1 FunctionBody (lucee.transformer.bytecode.FunctionBody)1 ScriptBody (lucee.transformer.bytecode.ScriptBody)1 Argument (lucee.transformer.bytecode.statement.Argument)1 IFunction (lucee.transformer.bytecode.statement.IFunction)1 Attribute (lucee.transformer.bytecode.statement.tag.Attribute)1 Closure (lucee.transformer.bytecode.statement.udf.Closure)1 Expression (lucee.transformer.expression.Expression)1 LitString (lucee.transformer.expression.literal.LitString)1 Literal (lucee.transformer.expression.literal.Literal)1 FunctionLibFunction (lucee.transformer.library.function.FunctionLibFunction)1