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;
}
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;
}
Aggregations