Tries to simplify an expression with equal operands. @param op operator @param cc compilation context @return optimized or original expression
(final CmpOp op, final CompileContext cc)
| 119 | * @return optimized or original expression |
| 120 | */ |
| 121 | private Expr optEqual(final CmpOp op, final CompileContext cc) { |
| 122 | if(!(this instanceof CmpG)) return this; |
| 123 | |
| 124 | final Expr expr1 = exprs[0], expr2 = exprs[1]; |
| 125 | final SeqType st1 = expr1.seqType(); |
| 126 | final Type type1 = st1.type; |
| 127 | if(expr1.equals(expr2) && |
| 128 | // keep: () = (), (1,2) != (1,2), (1,2) eq (1,2) |
| 129 | (op != CmpOp.EQ ? st1.one() : st1.oneOrMore()) && |
| 130 | // keep: xs:double('NaN') = xs:double('NaN') |
| 131 | (type1.isStringOrUntyped() || type1.instanceOf(BasicType.DECIMAL) || |
| 132 | type1 == BasicType.BOOLEAN) && |
| 133 | // keep: random:integer() = random:integer() |
| 134 | // keep if no context is available: last() = last() |
| 135 | !expr1.has(Flag.NDT) && (!expr1.has(Flag.CTX) || cc.qc.focus.value != null) |
| 136 | ) { |
| 137 | // 1 = 1 → true() |
| 138 | // <x/> ne <x/> → false() |
| 139 | // (1, 2) >= (1, 2) → true() |
| 140 | // (1, 2, 3)[last() = last()] → (1, 2, 3) |
| 141 | return Bln.get(op.oneOf(CmpOp.EQ, CmpOp.GE, CmpOp.LE)); |
| 142 | } |
| 143 | return this; |
| 144 | } |
| 145 | |
| 146 | /** |
| 147 | * Tries to rewrite boolean comparisons. |
no test coverage detected