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

Method simplify

basex-core/src/main/java/org/basex/query/expr/Expr.java:345–359  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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.

Callers 15

simplifyForMethod · 0.95
simplifyForMethod · 0.45
simplifyForMethod · 0.45
simplifyForMethod · 0.45
simplifyForMethod · 0.45
optimizeMethod · 0.45
simplifyForMethod · 0.45
simplifyForMethod · 0.45
simplifyForMethod · 0.45
simplifyForCastMethod · 0.45
optimizeMethod · 0.45
optimizeMethod · 0.45

Calls 8

seqTypeMethod · 0.95
instanceOfMethod · 0.95
zeroMethod · 0.95
hasMethod · 0.95
getMethod · 0.95
sizeMethod · 0.95
getMethod · 0.95
oneOfMethod · 0.65

Tested by

no test coverage detected