boolean checkLibrary)
throws TemplateException {
// get Function Library
checkLibrary=checkLibrary && data.flibs!=null;
FunctionLibFunction flf = null;
if (checkLibrary) {
if(!(name instanceof Literal))
throw new TemplateException(data.cfml,"syntax error"); // should never happen!
for (int i = 0; i < data.flibs.length; i++) {
flf = data.flibs[i].getFunction(((Literal)name).getString());
if (flf != null)break;
}
if (flf == null) {
checkLibrary = false;
}
}
// Element Function
FunctionMember fm;
if(checkLibrary) {
BIF bif=new BIF(name,flf);
bif.setArgType(flf.getArgType());
bif.setClass(flf.getClazz());
bif.setReturnType(flf.getReturnTypeAsString());
fm=bif;
if(flf.getArgType()== FunctionLibFunction.ARG_DYNAMIC && flf.hasDefaultValues()){
ArrayList<FunctionLibFunctionArg> args = flf.getArg();
Iterator<FunctionLibFunctionArg> it = args.iterator();
FunctionLibFunctionArg arg;
while(it.hasNext()){
arg=it.next();
if(arg.getDefaultValue()!=null)
bif.addArgument(
new NamedArgument(
LitString.toExprString(arg.getName()),
LitString.toExprString(arg.getDefaultValue()),
arg.getTypeAsString(),false
));
}
}
}
else {
fm = new UDF(name);
}
// Function Attributes
ArrayList<FunctionLibFunctionArg> arrFuncLibAtt = null;
int libLen = 0;
if (checkLibrary) {
arrFuncLibAtt = flf.getArg();
libLen = arrFuncLibAtt.size();
}
int count = 0;
do {
data.cfml.next();
comments(data);
// finish
if (count==0 && data.cfml.isCurrent(')'))
break;
// too many Attributes
boolean isDynamic=false;
int max=-1;
if(checkLibrary) {
isDynamic=flf.getArgType()==FunctionLibFunction.ARG_DYNAMIC;
max=flf.getArgMax();
// Dynamic
if(isDynamic) {
if(max!=-1 && max <= count)
throw new TemplateException(
data.cfml,
"too many Attributes in function [" + ASMUtil.display(name) + "]");
}
// Fix
else {
if(libLen <= count){
TemplateException te = new TemplateException(
data.cfml,
"too many Attributes in function call [" + ASMUtil.display(name) + "]");
UDFUtil.addFunctionDoc(te, flf);
throw te;
}
}
}
//Argument arg;
if (checkLibrary && !isDynamic) {
// current attribues from library
FunctionLibFunctionArg funcLibAtt =arrFuncLibAtt.get(count);
fm.addArgument(functionArgument(data,funcLibAtt.getTypeAsString(),false));
}
else {
fm.addArgument(functionArgument(data,false));
}
comments(data);
count++;
if (data.cfml.isCurrent(')'))
break;
}
while (data.cfml.isCurrent(','));
// end with ) ??
if (!data.cfml.forwardIfCurrent(')'))
throw new TemplateException(
data.cfml,
"Invalid Syntax Closing [)] for function ["
+ ASMUtil.display(name)
+ "] not found");
// check min attributes
if (checkLibrary && flf.getArgMin() > count){
TemplateException te = new TemplateException(
data.cfml,
"too few attributes in function [" + ASMUtil.display(name) + "]");
if(flf.getArgType()==FunctionLibFunction.ARG_FIX) UDFUtil.addFunctionDoc(te, flf);
throw te;
}
comments(data);
// evaluator
if(checkLibrary && flf.hasTteClass()){
flf.getEvaluator().evaluate((BIF) fm, flf);
}
return fm;
}