Iterator<FunctionLibFunctionArg> it = list.iterator();
argTypes=new Type[list.size()+1];
argTypes[0]=Types.PAGE_CONTEXT;
FunctionLibFunctionArg flfa;
int index=0;
VT vt;
while(it.hasNext()) {
flfa =it.next();
vt = getMatchingValueAndType(flfa,nargs,names,line);
if(vt.index!=-1)
names[vt.index]=null;
argTypes[++index]=Types.toType(vt.type);
if(vt.value==null)ASMConstants.NULL(bc.getAdapter());
else vt.value.writeOut(bc, Types.isPrimitiveType(argTypes[index])?MODE_VALUE:MODE_REF);
}
for(int y=0;y<names.length;y++){
if(names[y]!=null) {
BytecodeException bce = new BytecodeException("argument ["+names[y]+"] is not allowed for function ["+bif.getFlf().getName()+"]", args[y].getStart());
UDFUtil.addFunctionDoc(bce, bif.getFlf());
throw bce;
}
}
}
else{
argTypes=new Type[args.length+1];
argTypes[0]=Types.PAGE_CONTEXT;
for(int y=0;y<args.length;y++) {
argTypes[y+1]=Types.toType(args[y].getStringType());
args[y].writeOutValue(bc, Types.isPrimitiveType(argTypes[y+1])?MODE_VALUE:MODE_REF);
}
// if no method exists for the exact match of arguments, call the method with all arguments (when exists)
if(methodExists(bifClass,"call",argTypes,rtnType)==Boolean.FALSE) {
ArrayList<FunctionLibFunctionArg> _args = bif.getFlf().getArg();
Type[] tmp = new Type[_args.size()+1];
// fill the existing
for(int i=0;i<argTypes.length;i++){
tmp[i]=argTypes[i];
}
// get the rest with default values
FunctionLibFunctionArg flfa;
for(int i=argTypes.length;i<tmp.length;i++){
flfa = _args.get(i-1);
tmp[i]=Types.toType(flfa.getTypeAsString());
getDefaultValue(flfa).value.writeOut(
bc,
Types.isPrimitiveType(tmp[i])?MODE_VALUE:MODE_REF);
}
argTypes=tmp;