Creates a function item expression. @param qnm function name @param arity number of arguments @param runtime true if this method is called at runtime @param info input info (can be null) @param qc query context @return literal if found, null otherwise @throws QueryException q
(final QNm qnm, final int arity, final boolean runtime,
final InputInfo info, final QueryContext qc)
| 147 | * @throws QueryException query exception |
| 148 | */ |
| 149 | public static Expr item(final QNm qnm, final int arity, final boolean runtime, |
| 150 | final InputInfo info, final QueryContext qc) throws QueryException { |
| 151 | |
| 152 | final FuncBuilder fb = new FuncBuilder(info, arity, runtime); |
| 153 | final QNm name = funcName(qnm, arity, info, qc); |
| 154 | |
| 155 | // constructor function |
| 156 | if(eq(name.uri(), XS_URI)) { |
| 157 | if(arity > 0) fb.add(CAST_PARAM[0], Types.ANY_ATOMIC_TYPE_ZO, qc); |
| 158 | final Cast expr = constructorCall(name, fb); |
| 159 | final FuncType ft = FuncType.get(fb.anns, expr.castType(), fb.params); |
| 160 | return item(expr, fb, ft, name, false, arity == 0); |
| 161 | } |
| 162 | |
| 163 | // built-in function |
| 164 | final FuncDefinition fd = builtIn(name); |
| 165 | if(fd != null) { |
| 166 | final IntList arts = checkArity(arity, fd.minMax[0], fd.minMax[1]); |
| 167 | if(arts != null) throw wrongArity(arity, arts, true, info, fd); |
| 168 | |
| 169 | final FuncType ft = fd.type(arity, fb.anns); |
| 170 | final QNm[] names = fd.paramNames(arity); |
| 171 | for(int a = 0; a < arity; a++) fb.add(names[a], ft.argTypes[a], qc); |
| 172 | final StandardFunc sf = fd.get(info, fb.args()); |
| 173 | final boolean updating = sf.hasUPD(); |
| 174 | if(updating) { |
| 175 | fb.anns = fb.anns.attach(new Ann(info, Annotation.UPDATING, Empty.VALUE)); |
| 176 | qc.updating(); |
| 177 | } |
| 178 | return item(sf, fb, ft, name, updating, sf.has(Flag.CTX)); |
| 179 | } |
| 180 | |
| 181 | // user-defined function |
| 182 | final StaticFunc sf = qc.functions.get(info.sc(), name, arity, runtime); |
| 183 | if(sf != null) { |
| 184 | final Expr func = item(sf, fb, qc); |
| 185 | if(sf.updating) qc.updating(); |
| 186 | return func; |
| 187 | } |
| 188 | |
| 189 | for(int a = 0; a < arity; a++) fb.add(new QNm(ARG + (a + 1), ""), null, qc); |
| 190 | |
| 191 | // Java function |
| 192 | final JavaCall java = JavaCall.get(name, fb.args(), qc, info); |
| 193 | if(java != null) { |
| 194 | final SeqType[] sts = new SeqType[arity]; |
| 195 | Arrays.fill(sts, Types.ITEM_ZM); |
| 196 | final SeqType st = FuncType.get(fb.anns, null, sts).seqType(); |
| 197 | return new FuncLit(info, java, fb.params, fb.anns, st, name, fb.vs); |
| 198 | } |
| 199 | if(runtime) return null; |
| 200 | |
| 201 | throw qc.functions.unknownFunctionError(name, arity, info); |
| 202 | } |
| 203 | |
| 204 | /** |
| 205 | * Returns the actual function name of a function call or named function reference. For an |
no test coverage detected