MCPcopy Create free account
hub / github.com/BaseXdb/basex / refine

Method refine

basex-core/src/main/java/org/basex/query/func/Closure.java:243–263  ·  view source on GitHub ↗

Returns a copy of this closure with refined parameter types. @param argTypes argument types @param cc compilation context @return original or refined closure @throws QueryException query exception @see FuncItem#refine(SeqType[], CompileContext)

(final SeqType[] argTypes, final CompileContext cc)

Source from the content-addressed store, hash-verified

241 * @see FuncItem#refine(SeqType[], CompileContext)
242 */
243 public Expr refine(final SeqType[] argTypes, final CompileContext cc) throws QueryException {
244 // skip refinement if function has too many parameters
245 final int arity = arity();
246 if(argTypes.length < arity) return this;
247
248 // skip if no parameter type can be narrowed
249 boolean narrow = false;
250 for(int a = 0; a < arity; a++) {
251 final SeqType at = argTypes[a], pt = params[a].seqType();
252 if(at.instanceOf(pt) && !at.eq(pt)) {
253 narrow = true;
254 break;
255 }
256 }
257 if(!narrow) return this;
258
259 // clone the closure, narrow the cloned params, re-compile the body
260 final Closure copy = (Closure) copy(cc, new IntObjectMap<>());
261 for(int a = 0; a < arity; a++) copy.params[a].refineType(argTypes[a], cc);
262 return copy.optimize(cc);
263 }
264
265 @Override
266 public Expr inline(final InlineContext ic) throws QueryException {

Callers

nothing calls this directly

Calls 7

arityMethod · 0.95
instanceOfMethod · 0.95
eqMethod · 0.95
copyMethod · 0.95
optimizeMethod · 0.95
seqTypeMethod · 0.65
refineTypeMethod · 0.45

Tested by

no test coverage detected