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)); }
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); }
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)); }
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++; } }
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); } }
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)); } }
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)); } }
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++; } }
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++; } }
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); }
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)); }
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)); } }
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); }
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); }
internal double NumberValue() { return(QueryValueModel.Double(this.StringValue())); }
internal bool Equals(string literal) { return(QueryValueModel.Equals(this.StringValue(), literal)); }
internal bool Compare(ref NodeSequenceItem item, RelationOperator op) { return(QueryValueModel.Compare(this.StringValue(), item.StringValue(), op)); }
internal bool Compare(string strVal, RelationOperator op) { return(QueryValueModel.Compare(this.StringValue(), strVal, op)); }
internal bool Compare(double dblVal, RelationOperator op) { return(QueryValueModel.Compare(this.NumberValue(), dblVal, op)); }
internal static bool Compare(bool x, NodeSequence y, RelationOperator op) { Fx.Assert(null != y, ""); return(QueryValueModel.Compare(x, QueryValueModel.Boolean(y), op)); }
internal static bool Compare(double x, string y, RelationOperator op) { Fx.Assert(null != y, ""); return(QueryValueModel.Compare(x, QueryValueModel.Double(y), op)); }
internal static bool Compare(string x, double y, RelationOperator op) { Fx.Assert(null != x, ""); return(QueryValueModel.Compare(QueryValueModel.Double(x), y, op)); }
internal static bool Compare(NodeSequence x, bool y, RelationOperator op) { Fx.Assert(null != x, ""); return(QueryValueModel.Compare(QueryValueModel.Boolean(x), y, op)); }
internal static bool Equals(double x, string y) { return(x == QueryValueModel.Double(y)); }
internal static bool Equals(bool x, double y) { return(x == QueryValueModel.Boolean(y)); }