Beispiel #1
0
        internal static bool CompileTimeCompare(object x, object y, RelationOperator op)
        {
            Fx.Assert(null != x && null != y, "");

            if (x is string)
            {
                if (y is double)
                {
                    return(QueryValueModel.Compare((string)x, (double)y, op));
                }
                else if (y is string)
                {
                    return(QueryValueModel.Compare((string)x, (string)y, op));
                }
            }
            else if (x is double)
            {
                if (y is double)
                {
                    return(QueryValueModel.Compare((double)x, (double)y, op));
                }
                else if (y is string)
                {
                    return(QueryValueModel.Compare((double)x, (string)y, op));
                }
            }
            throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new QueryCompileException(QueryCompileError.InvalidComparison));
        }
Beispiel #2
0
        private void TokenizeNumber()
        {
            XPathTokenID integer = XPathTokenID.Integer;

            while (XPathCharTypes.IsDigit(this.ch))
            {
                this.AdvanceChar();
            }
            if (this.ch == '.')
            {
                this.AdvanceChar();
                if (XPathCharTypes.IsDigit(this.ch))
                {
                    integer = XPathTokenID.Decimal;
                    while (XPathCharTypes.IsDigit(this.ch))
                    {
                        this.AdvanceChar();
                    }
                }
            }
            this.PutbackChar();
            double number = QueryValueModel.Double(this.CurrentSubstring());

            this.token.Set(integer, number);
        }
        private void TokenizeNumber()
        {
            XPathTokenID id = XPathTokenID.Integer;

            // Read all the digits
            for (; XPathCharTypes.IsDigit(this.ch); AdvanceChar())
            {
                ;
            }
            if (this.ch == '.')
            {
                AdvanceChar();
                if (XPathCharTypes.IsDigit(this.ch))
                {
                    id = XPathTokenID.Decimal;
                    // Read all the digits after the decimal point
                    for (; XPathCharTypes.IsDigit(this.ch); AdvanceChar())
                    {
                        ;
                    }
                }
            }
            PutbackChar();

            // The converted double
            double d = QueryValueModel.Double(CurrentSubstring());

            // flip the sign if we're negative
            token.Set(id, d);
        }
Beispiel #4
0
            private void CompileLiteralRelation(XPathRelationExpr expr)
            {
                XPathLiteralExpr left    = (XPathLiteralExpr)expr.Left;
                XPathLiteralExpr right   = (XPathLiteralExpr)expr.Right;
                bool             literal = QueryValueModel.CompileTimeCompare(left.Literal, right.Literal, expr.Op);

                this.codeBlock.Append(new PushBooleanOpcode(literal));
            }
Beispiel #5
0
        internal static void NumberRound(ProcessingContext context)
        {
            StackFrame topArg = context.TopArg;

            while (topArg.basePtr <= topArg.endPtr)
            {
                context.PeekDouble(topArg.basePtr);
                context.SetValue(context, topArg.basePtr, QueryValueModel.Round(context.PeekDouble(topArg.basePtr)));
                topArg.basePtr++;
            }
        }
Beispiel #6
0
        internal static bool Compare(double x, bool y, RelationOperator op)
        {
            switch (op)
            {
            default:
                return(QueryValueModel.Compare(x, QueryValueModel.Double(y), op));

            case RelationOperator.Eq:
                return(QueryValueModel.Boolean(x) == y);

            case RelationOperator.Ne:
                return(QueryValueModel.Boolean(x) != y);
            }
        }
Beispiel #7
0
        internal static bool Compare(bool x, double y, RelationOperator op)
        {
            switch (op)
            {
            default:
                return(QueryValueModel.Compare(QueryValueModel.Double(x), y, op));

            case RelationOperator.Eq:
                return(x == QueryValueModel.Boolean(y));

            case RelationOperator.Ne:
                return(x != QueryValueModel.Boolean(y));
            }
        }
Beispiel #8
0
        internal static bool Compare(string x, bool y, RelationOperator op)
        {
            Fx.Assert(null != x, "");
            switch (op)
            {
            default:
                return(QueryValueModel.Compare(QueryValueModel.Double(x), QueryValueModel.Double(y), op));

            case RelationOperator.Eq:
                return(y == QueryValueModel.Boolean(x));

            case RelationOperator.Ne:
                return(y != QueryValueModel.Boolean(x));
            }
        }
Beispiel #9
0
        internal static void NumberSum(ProcessingContext context)
        {
            StackFrame topArg = context.TopArg;

            while (topArg.basePtr <= topArg.endPtr)
            {
                NodeSequence sequence = context.PeekSequence(topArg.basePtr);
                double       val      = 0.0;
                for (int i = 0; i < sequence.Count; i++)
                {
                    NodeSequenceItem item = sequence[i];
                    val += QueryValueModel.Double(item.StringValue());
                }
                context.SetValue(context, topArg.basePtr, val);
                topArg.basePtr++;
            }
        }
Beispiel #10
0
        internal static void NumberSum(ProcessingContext context)
        {
            StackFrame arg = context.TopArg;

            while (arg.basePtr <= arg.endPtr)
            {
                NodeSequence sequence = context.PeekSequence(arg.basePtr);
                double       sum      = 0.0;
                for (int item = 0; item < sequence.Count; ++item)
                {
                    sum += QueryValueModel.Double(sequence[item].StringValue());
                }

                context.SetValue(context, arg.basePtr, sum);
                arg.basePtr++;
            }
        }
Beispiel #11
0
        internal bool Equals(double val)
        {
            switch (this.type)
            {
            case ValueDataType.Boolean:
                return(QueryValueModel.Equals(this.boolVal, val));

            case ValueDataType.Double:
                return(QueryValueModel.Equals(this.dblVal, val));

            case ValueDataType.Sequence:
                return(QueryValueModel.Equals(this.sequence, val));

            case ValueDataType.String:
                return(QueryValueModel.Equals(val, this.strVal));
            }
            return(false);
        }
Beispiel #12
0
        public override string ToString()
        {
            switch (this.type)
            {
            case ValueDataType.Boolean:
                return(QueryValueModel.String(this.boolVal));

            case ValueDataType.Double:
                return(QueryValueModel.String(this.dblVal));

            case ValueDataType.Sequence:
                return(QueryValueModel.String(this.sequence));

            case ValueDataType.String:
                return(this.strVal);
            }
            throw DiagnosticUtility.ExceptionUtility.ThrowHelperCritical(new QueryProcessingException(QueryProcessingError.TypeMismatch));
        }
Beispiel #13
0
        internal bool CompareTo(double val, RelationOperator op)
        {
            switch (this.type)
            {
            case ValueDataType.Boolean:
                return(QueryValueModel.Compare(this.boolVal, val, op));

            case ValueDataType.Double:
                return(QueryValueModel.Compare(this.dblVal, val, op));

            case ValueDataType.Sequence:
                return(QueryValueModel.Compare(this.sequence, val, op));

            case ValueDataType.String:
                return(QueryValueModel.Compare(this.strVal, val, op));
            }
            throw DiagnosticUtility.ExceptionUtility.ThrowHelperCritical(new QueryProcessingException(QueryProcessingError.TypeMismatch));
        }
        public bool GetResultAsBoolean()
        {
            switch (this.resultType)
            {
            case XPathResultType.Number:
                return(QueryValueModel.Boolean(this.numberResult));

            case XPathResultType.String:
                return(QueryValueModel.Boolean(this.stringResult));

            case XPathResultType.Boolean:
                return(this.boolResult);

            case XPathResultType.NodeSet:
                return(QueryValueModel.Boolean(this.nodeSetResult));
            }
            throw Fx.AssertAndThrow("Unexpected result type.");
        }
        internal bool Equals(bool val)
        {
            switch (this.type)
            {
            default:
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new QueryProcessingException(QueryProcessingError.TypeMismatch), TraceEventType.Critical);

            case ValueDataType.Boolean:
                return(QueryValueModel.Equals(this.boolVal, val));

            case ValueDataType.Double:
                return(QueryValueModel.Equals(this.dblVal, val));

            case ValueDataType.Sequence:
                return(QueryValueModel.Equals(this.sequence, val));

            case ValueDataType.String:
                return(QueryValueModel.Equals(this.strVal, val));
            }
        }
        internal double ToDouble()
        {
            switch (this.type)
            {
            default:
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperCritical(new QueryProcessingException(QueryProcessingError.TypeMismatch));

            case ValueDataType.Boolean:
                return(QueryValueModel.Double(this.boolVal));

            case ValueDataType.Double:
                return(this.dblVal);

            case ValueDataType.Sequence:
                return(QueryValueModel.Double(this.sequence));

            case ValueDataType.String:
                return(QueryValueModel.Double(this.strVal));
            }
        }
        internal bool Equals(double val)
        {
            switch (this.type)
            {
            default:
                Fx.Assert("Invalid Type");
                return(false);

            case ValueDataType.Boolean:
                return(QueryValueModel.Equals(this.boolVal, val));

            case ValueDataType.Double:
                return(QueryValueModel.Equals(this.dblVal, val));

            case ValueDataType.Sequence:
                return(QueryValueModel.Equals(this.sequence, val));

            case ValueDataType.String:
                return(QueryValueModel.Equals(val, this.strVal));
            }
        }
Beispiel #18
0
        internal static string ToString(object o)
        {
            if (o is bool)
            {
                return(QueryValueModel.String((bool)o));
            }
            if (o is string)
            {
                return((string)o);
            }
            if (o is double)
            {
                return(QueryValueModel.String((double)o));
            }
            if (!(o is XPathNodeIterator))
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(System.ServiceModel.SR.GetString("QueryFunctionStringArg")));
            }
            XPathNodeIterator iterator = (XPathNodeIterator)o;

            iterator.MoveNext();
            return(iterator.Current.Value);
        }
Beispiel #19
0
        internal static bool Compare(string x, string y, RelationOperator op)
        {
            Fx.Assert(null != x && null != y, "");
            switch (op)
            {
            default:
                Fx.Assert("Invalid RelationOperator");
                break;

            case RelationOperator.Eq:
                return(QueryValueModel.Equals(x, y));

            case RelationOperator.Ge:
            case RelationOperator.Gt:
            case RelationOperator.Le:
            case RelationOperator.Lt:
                return(QueryValueModel.Compare(QueryValueModel.Double(x), QueryValueModel.Double(y), op));

            case RelationOperator.Ne:
                return(x.Length != y.Length || 0 != string.CompareOrdinal(x, y));
            }

            return(false);
        }
Beispiel #20
0
 internal double NumberValue()
 {
     return(QueryValueModel.Double(this.StringValue()));
 }
Beispiel #21
0
 internal bool Equals(string literal)
 {
     return(QueryValueModel.Equals(this.StringValue(), literal));
 }
Beispiel #22
0
 internal bool Compare(ref NodeSequenceItem item, RelationOperator op)
 {
     return(QueryValueModel.Compare(this.StringValue(), item.StringValue(), op));
 }
Beispiel #23
0
 internal bool Compare(string strVal, RelationOperator op)
 {
     return(QueryValueModel.Compare(this.StringValue(), strVal, op));
 }
Beispiel #24
0
 internal bool Compare(double dblVal, RelationOperator op)
 {
     return(QueryValueModel.Compare(this.NumberValue(), dblVal, op));
 }
Beispiel #25
0
 internal static bool Compare(bool x, NodeSequence y, RelationOperator op)
 {
     Fx.Assert(null != y, "");
     return(QueryValueModel.Compare(x, QueryValueModel.Boolean(y), op));
 }
Beispiel #26
0
 internal static bool Compare(double x, string y, RelationOperator op)
 {
     Fx.Assert(null != y, "");
     return(QueryValueModel.Compare(x, QueryValueModel.Double(y), op));
 }
Beispiel #27
0
 internal static bool Compare(string x, double y, RelationOperator op)
 {
     Fx.Assert(null != x, "");
     return(QueryValueModel.Compare(QueryValueModel.Double(x), y, op));
 }
Beispiel #28
0
 internal static bool Compare(NodeSequence x, bool y, RelationOperator op)
 {
     Fx.Assert(null != x, "");
     return(QueryValueModel.Compare(QueryValueModel.Boolean(x), y, op));
 }
Beispiel #29
0
 internal static bool Equals(double x, string y)
 {
     return(x == QueryValueModel.Double(y));
 }
Beispiel #30
0
 internal static bool Equals(bool x, double y)
 {
     return(x == QueryValueModel.Boolean(y));
 }