Simplifies the expression. @param mode mode of simplification @param cc compilation context @return simplified or original expression @see Simplify @throws QueryException query exception
(final Simplify mode, final CompileContext cc)
| 343 | * @throws QueryException query exception |
| 344 | */ |
| 345 | public final Expr simplify(final Simplify mode, final CompileContext cc) throws QueryException { |
| 346 | Expr expr = this; |
| 347 | if(mode.oneOf(Simplify.EBV, Simplify.PREDICATE)) { |
| 348 | // boolean(<a/>) → true() |
| 349 | // E[()] → E[false()] |
| 350 | final SeqType st = seqType(); |
| 351 | final boolean nodes = st.instanceOf(Types.NODE_OM); |
| 352 | if((nodes || st.zero()) && !has(Flag.NDT)) expr = Bln.get(nodes); |
| 353 | } else if(mode == Simplify.COUNT && !(this instanceof Value)) { |
| 354 | // count(db:get('db')//with-known-result-size) → replicate('', size) |
| 355 | final long size = size(); |
| 356 | if(size != -1 && !has(Flag.NDT)) expr = SingletonSeq.get(Str.EMPTY, size); |
| 357 | } |
| 358 | return expr != this ? cc.simplify(this, expr, mode) : this; |
| 359 | } |
| 360 | |
| 361 | /** |
| 362 | * Returns the static type of the resulting value. |
no test coverage detected