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

Method opt

basex-core/src/main/java/org/basex/query/func/fn/FnApply.java:34–62  ·  view source on GitHub ↗
(final CompileContext cc)

Source from the content-addressed store, hash-verified

32 }
33
34 @Override
35 protected Expr opt(final CompileContext cc) throws QueryException {
36 final Expr func = arg(0), args = arg(1);
37 FuncType ft = func.funcType();
38 final Type argsTp = args.seqType().type;
39
40 // try to pass on types of array argument to function item
41 if(argsTp instanceof final ArrayType aat) {
42 if(args instanceof final XQArray array) {
43 // argument is a value: final types are known
44 final int as = Math.max(0, (int) array.structSize());
45 final SeqType[] ast = new SeqType[as];
46 for(int a = 0; a < as; a++) ast[a] = array.valueAt(a).seqType();
47 arg(0, arg -> refineFunc(arg, cc, ast));
48 } else if(ft != null) {
49 // argument will be of type array: assign generic array return type to all arguments
50 final SeqType[] at = ft.argTypes;
51 if(at != null) {
52 final SeqType[] ast = new SeqType[at.length];
53 Arrays.fill(ast, aat.valueType());
54 arg(0, arg -> refineFunc(arg, cc, ast));
55 }
56 }
57 }
58
59 ft = arg(0).funcType();
60 if(ft != null) exprType.assign(ft.declType);
61 return this;
62 }
63
64 /**
65 * Applies a function with the specified arguments.

Callers

nothing calls this directly

Calls 12

funcTypeMethod · 0.95
seqTypeMethod · 0.95
refineFuncMethod · 0.80
fillMethod · 0.80
seqTypeMethod · 0.65
funcTypeMethod · 0.65
argMethod · 0.45
maxMethod · 0.45
structSizeMethod · 0.45
valueAtMethod · 0.45
valueTypeMethod · 0.45
assignMethod · 0.45

Tested by

no test coverage detected