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

Method opt

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

Source from the content-addressed store, hash-verified

33 }
34
35 @Override
36 protected Expr opt(final CompileContext cc) throws QueryException {
37 final Expr expr = opt(false);
38 if(expr != null) return expr;
39
40 final Expr values = arg(0), zero = arg(1);
41 final SeqType st = values.seqType(), stZero = zero.seqType();
42 if(zero == Empty.UNDEFINED) {
43 // no default value
44 if(st.zero()) return cc.voidAndReturn(values, Itr.ZERO, info);
45 if(!st.mayBeWrapped()) {
46 final SeqType ost = optType(values);
47 if(ost != null) exprType.assign(ost);
48 }
49 } else if(st.zero()) {
50 if(zero == Empty.VALUE || stZero.instanceOf(Types.ANY_ATOMIC_TYPE_ZO)) {
51 return cc.voidAndReturn(values, zero, info);
52 }
53 } else if(!st.mayBeWrapped() && !stZero.mayBeWrapped()) {
54 if(st.oneOrMore()) return cc.function(Function.SUM, info, values);
55 final SeqType ost = optType(values), zst = optType(zero);
56 final Type type = ost != null && zst != null ? ost.type.union(zst.type) : ANY_ATOMIC_TYPE;
57 final Occ occ = stZero.oneOrMore() ? Occ.EXACTLY_ONE : Occ.ZERO_OR_ONE;
58 exprType.assign(type, occ);
59 }
60 return this;
61 }
62
63 /**
64 * Pre-evaluates a value expression.

Callers

nothing calls this directly

Calls 15

seqTypeMethod · 0.95
zeroMethod · 0.95
mayBeWrappedMethod · 0.95
instanceOfMethod · 0.95
oneOrMoreMethod · 0.95
rangeMethod · 0.95
isUntypedMethod · 0.95
getMethod · 0.95
dblMethod · 0.95
isNumberMethod · 0.95
getMethod · 0.95
isNumericMethod · 0.95

Tested by

no test coverage detected