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