Beispiel #1
0
 //also used by XPathPatternBuilder
 public static QilNode PredicateToBoolean(QilNode predicate, XPathQilFactory f, IXPathEnvironment env)
 {
     // Prepocess predicate: if (predicate is number) then predicate := (position() == predicate)
     if (!f.IsAnyType(predicate))
     {
         if (predicate.XmlType.TypeCode == XmlTypeCode.Double)
         {
             predicate = f.Eq(env.GetPosition(), predicate);
         }
         else
         {
             predicate = f.ConvertToBoolean(predicate);
         }
     }
     else
     {
         QilIterator i;
         predicate = f.Loop(i = f.Let(predicate),
                            f.Conditional(f.IsType(i, T.Double),
                                          f.Eq(env.GetPosition(), f.TypeAssert(i, T.DoubleX)),
                                          f.ConvertToBoolean(i)
                                          )
                            );
     }
     return(predicate);
 }
Beispiel #2
0
        private QilNode CompareValues(XPathOperator op, QilNode left, QilNode right, XmlTypeCode compType)
        {
            Debug.Assert(compType == XmlTypeCode.Boolean || compType == XmlTypeCode.Double || compType == XmlTypeCode.String);
            Debug.Assert(compType == XmlTypeCode.Boolean || left.XmlType !.IsSingleton && right.XmlType !.IsSingleton, "Both comparison operands must be singletons");
            left  = _f.ConvertToType(compType, left);
            right = _f.ConvertToType(compType, right);

            switch (op)
            {
            case XPathOperator.Eq: return(_f.Eq(left, right));

            case XPathOperator.Ne: return(_f.Ne(left, right));

            case XPathOperator.Lt: return(_f.Lt(left, right));

            case XPathOperator.Le: return(_f.Le(left, right));

            case XPathOperator.Gt: return(_f.Gt(left, right));

            case XPathOperator.Ge: return(_f.Ge(left, right));

            default:
                Debug.Fail("Wrong operator type");
                return(null);
            }
        }