(final CompileContext cc)
| 119 | } |
| 120 | |
| 121 | @Override |
| 122 | public For optimize(final CompileContext cc) throws QueryException { |
| 123 | // for $a as xs:integer in $array → for $a as xs:integer in data($array) |
| 124 | final SeqType dt = var.declType; |
| 125 | if(dt != null && dt.instanceOf(Types.ANY_ATOMIC_TYPE_ZM) && expr.seqType().mayBeWrapped()) { |
| 126 | expr = cc.function(DATA, info, expr); |
| 127 | } |
| 128 | |
| 129 | // remove empty flag if expression is never empty; assign type to clause and variable |
| 130 | final SeqType st = expr.seqType(); |
| 131 | if(st.oneOrMore()) empty = false; |
| 132 | exprType.assign(st.with(empty ? st.zero() ? Occ.ZERO : Occ.ZERO_OR_ONE : Occ.EXACTLY_ONE)); |
| 133 | |
| 134 | var.refineType(seqType(), size(), cc); |
| 135 | var.expr(expr); |
| 136 | if(pos != null) { |
| 137 | pos.refineType(Types.INTEGER_O, 1, cc); |
| 138 | pos.expr(Itr.ZERO); |
| 139 | } |
| 140 | if(score != null) { |
| 141 | score.refineType(Types.DOUBLE_O, 1, cc); |
| 142 | score.expr(Dbl.ZERO); |
| 143 | } |
| 144 | return this; |
| 145 | } |
| 146 | |
| 147 | @Override |
| 148 | public For copy(final CompileContext cc, final IntObjectMap<Var> vm) { |
no test coverage detected