*/
public static Expression rewriteEffectiveBooleanValue(
Expression exp, ExpressionVisitor visitor, ItemType contextItemType) throws XPathException {
Configuration config = visitor.getConfiguration();
TypeHierarchy th = config.getTypeHierarchy();
if (exp instanceof ValueComparison) {
ValueComparison vc = (ValueComparison)exp;
if (vc.getResultWhenEmpty() == null) {
vc.setResultWhenEmpty(BooleanValue.FALSE);
}
return exp;
} else if (exp instanceof BooleanFn && ((BooleanFn)exp).operation == BooleanFn.BOOLEAN) {
return ((BooleanFn)exp).getArguments()[0];
} else if (th.isSubType(exp.getItemType(th), BuiltInAtomicType.BOOLEAN) &&
exp.getCardinality() == StaticProperty.EXACTLY_ONE) {
return exp;
} else if (exp instanceof Count) {
// rewrite boolean(count(x)) => exists(x)
FunctionCall exists = SystemFunction.makeSystemFunction("exists", ((Count)exp).getArguments());