if (BuiltinFunctions.FN_LAST_QNAME.equals(fName)) {
XQueryVariable var = tCtx.varScope.lookupVariable(XMLQueryCompilerConstants.LAST_VAR_NAME);
return var.getLogicalVariable();
}
int nArgs = fnNode.getArguments().size();
Function fn = moduleCtx.lookupFunction(fName, nArgs);
if (fn != null && fn.useContextImplicitly()) {
args.add(tCtx.varScope.lookupVariable(XMLQueryCompilerConstants.DOT_VAR_NAME).getLogicalVariable());
fn = moduleCtx.lookupFunction(fName, nArgs + 1);
}
if (fn == null) {
Function[] fns = moduleCtx.lookupFunctions(fName);
if (fns != null) {
for (int i = 0; i < fns.length && i <= nArgs; ++i) {
if (fns[i] != null && fns[i].getSignature().isVarArgs()) {
fn = fns[i];
break;
}
}
}
}
if (fn == null) {
throw new SystemException(ErrorCode.XPST0017, fnNode.getName().getSourceLocation());
}
Signature sign = fn.getSignature();
List<Mutable<ILogicalExpression>> argExprs = new ArrayList<Mutable<ILogicalExpression>>();
for (int i = 0; i < args.size(); ++i) {
SequenceType argType = sign.getParameterType(i);
argExprs.add(mutable(normalize(vre(args.get(i)), argType)));
}