(final CompileContext cc)
| 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. |
nothing calls this directly
no test coverage detected