private ILogicalExpression normalize(ILogicalExpression expr, SequenceType type) throws SystemException {
if (type.getItemType().isAtomicType()) {
ILogicalExpression atomizedExpr = new ScalarFunctionCallExpression(BuiltinFunctions.FN_DATA_1,
Collections.singletonList(mutable(expr)));
AtomicType aType = (AtomicType) type.getItemType();
if (TypeUtils.isSubtypeTypeOf(aType, BuiltinTypeRegistry.XS_BOOLEAN)) {
return new ScalarFunctionCallExpression(BuiltinFunctions.FN_BOOLEAN_1,
Collections.singletonList(mutable(atomizedExpr)));
}
return promote(atomizedExpr, type);