public virtual Net.Vpc.Upa.Expressions.Expression EvalObject(Net.Vpc.Upa.Expressions.Expression e, Net.Vpc.Upa.QLEvaluator evaluator, object context)
        {
            Net.Vpc.Upa.Expressions.UnaryOperatorExpression eq = (Net.Vpc.Upa.Expressions.UnaryOperatorExpression)e;
            Net.Vpc.Upa.Expressions.Expression expr            = evaluator.EvalObject(eq.GetExpression(), context);
            object a = Net.Vpc.Upa.Impl.Util.UPAUtils.UnwrapLiteral(expr);

            if (a is Net.Vpc.Upa.Expressions.Expression)
            {
                return(Net.Vpc.Upa.Impl.Uql.Util.UQLUtils.CreateUnaryExpr(eq.GetOperator(), expr));
            }
            switch (eq.GetOperator())
            {
            case Net.Vpc.Upa.Expressions.UnaryOperator.POSITIVE:
            {
                return(expr);
            }

            case Net.Vpc.Upa.Expressions.UnaryOperator.NEGATIVE:
            {
                Net.Vpc.Upa.Impl.Util.XNumber na = Net.Vpc.Upa.Impl.Util.UPAUtils.ToNumberOrError(a);
                if (na == null)
                {
                    return(Net.Vpc.Upa.Expressions.Literal.NULL);
                }
                return(new Net.Vpc.Upa.Expressions.Literal(na.Negate().ToNumber(), null));
            }

            case Net.Vpc.Upa.Expressions.UnaryOperator.COMPLEMENT:
            {
                Net.Vpc.Upa.Impl.Util.XNumber na = Net.Vpc.Upa.Impl.Util.UPAUtils.ToNumber(a);
                if (na == null)
                {
                    return(Net.Vpc.Upa.Expressions.Literal.NULL);
                }
                return(new Net.Vpc.Upa.Expressions.Literal(na.Complement().ToNumber(), null));
            }

            case Net.Vpc.Upa.Expressions.UnaryOperator.NOT:
            {
                if (a is bool?)
                {
                    return(Net.Vpc.Upa.Expressions.Literal.ValueOf((!(((bool?)a)).Value).Value));
                }
                if (a is object)
                {
                    return(Net.Vpc.Upa.Expressions.Literal.ValueOf(System.Convert.ToDouble(((object)a)) == 0));
                }
                if (a is string)
                {
                    return(Net.Vpc.Upa.Expressions.Literal.ValueOf(!((string)a).Equals("true", System.StringComparison.InvariantCultureIgnoreCase)));
                }
                return(Net.Vpc.Upa.Expressions.Literal.ValueOf(a == null));
            }
            }
            throw new System.ArgumentException("Not supported");
        }
Пример #2
0
 public static int Compare(Net.Vpc.Upa.Impl.Util.XNumber a, Net.Vpc.Upa.Impl.Util.XNumber b) {
     if (a != null && b != null) {
         return a.CompareTo(b);
     }
     if (a == null) {
         a = new Net.Vpc.Upa.Impl.Util.XNumber(System.Double.NaN);
     }
     if (b == null) {
         b = new Net.Vpc.Upa.Impl.Util.XNumber(System.Double.NaN);
     }
     return a.CompareTo(b);
 }
Пример #3
0
 public override bool Equals(object obj) {
     if (obj == null) {
         return false;
     }
     if (GetType() != obj.GetType()) {
         return false;
     }
     Net.Vpc.Upa.Impl.Util.XNumber other = (Net.Vpc.Upa.Impl.Util.XNumber) obj;
     if (CompareTo(other) != 0) {
         return false;
     }
     return true;
 }
Пример #4
0
 public virtual Net.Vpc.Upa.Impl.Util.XNumber Add(Net.Vpc.Upa.Impl.Util.XNumber other) {
     System.Type c = BestFit(type, other.type);
     if (c == typeof(byte?)) {
         return new Net.Vpc.Upa.Impl.Util.XNumber(ByteValue() + other.ByteValue());
     } else if (c == typeof(short?)) {
         return new Net.Vpc.Upa.Impl.Util.XNumber(ShortValue() + other.ShortValue());
     } else if (c == typeof(int?)) {
         return new Net.Vpc.Upa.Impl.Util.XNumber(IntValue() + other.IntValue());
     } else if (c == typeof(float?)) {
         return new Net.Vpc.Upa.Impl.Util.XNumber(FloatValue() + other.FloatValue());
     } else if (c == typeof(double?)) {
         return new Net.Vpc.Upa.Impl.Util.XNumber(DoubleValue() + other.DoubleValue());
     } else if (c == typeof(System.Numerics.BigInteger?)) {
         return new Net.Vpc.Upa.Impl.Util.XNumber(((BigIntegerValue())+(other.BigIntegerValue())));
     } else if (c == typeof(System.Decimal?)) {
         return new Net.Vpc.Upa.Impl.Util.XNumber(((BigDecimalValue())+(other.BigDecimalValue())));
     }
     throw new System.ArgumentException ("Invalid");
 }
Пример #5
0
 public virtual int CompareTo(Net.Vpc.Upa.Impl.Util.XNumber other) {
     System.Type c = BestFit(type, other.type);
     if (c == typeof(byte?)) {
         return ByteValue().CompareTo(other.ByteValue());
     } else if (c == typeof(short?)) {
         return ShortValue().CompareTo(other.ShortValue());
     } else if (c == typeof(int?)) {
         return IntValue().CompareTo(other.IntValue());
     } else if (c == typeof(float?)) {
         return FloatValue().CompareTo(other.FloatValue());
     } else if (c == typeof(double?)) {
         return DoubleValue().CompareTo(other.DoubleValue());
     } else if (c == typeof(System.Numerics.BigInteger?)) {
         return (BigIntegerValue().Value.CompareTo(other.BigIntegerValue()));
     } else if (c == typeof(System.Decimal?)) {
         return (BigDecimalValue().Value.CompareTo(other.BigDecimalValue()));
     }
     throw new System.ArgumentException ("Invalid");
 }
Пример #6
0
        public virtual Net.Vpc.Upa.Expressions.Expression EvalObject(Net.Vpc.Upa.Expressions.Expression e, Net.Vpc.Upa.QLEvaluator evaluator, object context)
        {
            Net.Vpc.Upa.Expressions.BinaryOperatorExpression eq = (Net.Vpc.Upa.Expressions.BinaryOperatorExpression)e;
            Net.Vpc.Upa.Expressions.Expression a0 = evaluator.EvalObject(eq.GetLeft(), context);
            Net.Vpc.Upa.Expressions.Expression b0 = evaluator.EvalObject(eq.GetRight(), context);
            object a = Net.Vpc.Upa.Impl.Util.UPAUtils.UnwrapLiteral(a0);
            object b = Net.Vpc.Upa.Impl.Util.UPAUtils.UnwrapLiteral(b0);

            if ((a is Net.Vpc.Upa.Expressions.Expression) || (b is Net.Vpc.Upa.Expressions.Expression))
            {
                //could not simplify
                //            if(!(a instanceof Expression)){
                //                a=new Literal(a,null);
                //            }
                //            if(!(b instanceof Expression)){
                //                b=new Literal(a,null);
                //            }
                return(Net.Vpc.Upa.Impl.Uql.Util.UQLUtils.CreateBinaryExpr(eq.GetOperator(), a0, b0));
            }
            switch (eq.GetOperator())
            {
            case Net.Vpc.Upa.Expressions.BinaryOperator.AND:
            {
                if ((!(((bool?)a)).Value).Value)
                {
                    return(Net.Vpc.Upa.Expressions.Literal.FALSE);
                }
                return(((bool?)b) ? Net.Vpc.Upa.Expressions.Literal.TRUE : Net.Vpc.Upa.Expressions.Literal.FALSE);
            }

            case Net.Vpc.Upa.Expressions.BinaryOperator.OR:
            {
                if ((((bool?)a)).Value)
                {
                    return(Net.Vpc.Upa.Expressions.Literal.TRUE);
                }
                return(((bool?)b) ? Net.Vpc.Upa.Expressions.Literal.TRUE : Net.Vpc.Upa.Expressions.Literal.FALSE);
            }

            case Net.Vpc.Upa.Expressions.BinaryOperator.EQ:
            {
                return((Net.Vpc.Upa.Impl.Util.UPAUtils.Equals(a, b) || Net.Vpc.Upa.Impl.Util.UPAUtils.Equals(a == null ? "" : a.ToString(), b == null ? "" : b.ToString())) ? Net.Vpc.Upa.Expressions.Literal.TRUE : Net.Vpc.Upa.Expressions.Literal.FALSE);
            }

            case Net.Vpc.Upa.Expressions.BinaryOperator.DIFF:
            {
                return((!Net.Vpc.Upa.Impl.Util.UPAUtils.Equals(a, b) && !Net.Vpc.Upa.Impl.Util.UPAUtils.Equals(a == null ? "" : a.ToString(), b == null ? "" : b.ToString())) ? Net.Vpc.Upa.Expressions.Literal.TRUE : Net.Vpc.Upa.Expressions.Literal.FALSE);
            }

            case Net.Vpc.Upa.Expressions.BinaryOperator.GE:
            {
                Net.Vpc.Upa.Impl.Util.XNumber na = Net.Vpc.Upa.Impl.Util.UPAUtils.ToNumberOrError(a);
                Net.Vpc.Upa.Impl.Util.XNumber nb = Net.Vpc.Upa.Impl.Util.UPAUtils.ToNumberOrError(b);
                return((Net.Vpc.Upa.Impl.Util.XNumber.Compare(na, nb) >= 0) ? Net.Vpc.Upa.Expressions.Literal.TRUE : Net.Vpc.Upa.Expressions.Literal.FALSE);
            }

            case Net.Vpc.Upa.Expressions.BinaryOperator.GT:
            {
                Net.Vpc.Upa.Impl.Util.XNumber na = Net.Vpc.Upa.Impl.Util.UPAUtils.ToNumberOrError(a);
                Net.Vpc.Upa.Impl.Util.XNumber nb = Net.Vpc.Upa.Impl.Util.UPAUtils.ToNumberOrError(b);
                return((Net.Vpc.Upa.Impl.Util.XNumber.Compare(na, nb) > 0) ? Net.Vpc.Upa.Expressions.Literal.TRUE : Net.Vpc.Upa.Expressions.Literal.FALSE);
            }

            case Net.Vpc.Upa.Expressions.BinaryOperator.LE:
            {
                Net.Vpc.Upa.Impl.Util.XNumber na = Net.Vpc.Upa.Impl.Util.UPAUtils.ToNumberOrError(a);
                Net.Vpc.Upa.Impl.Util.XNumber nb = Net.Vpc.Upa.Impl.Util.UPAUtils.ToNumberOrError(b);
                return((Net.Vpc.Upa.Impl.Util.XNumber.Compare(na, nb) <= 0) ? Net.Vpc.Upa.Expressions.Literal.TRUE : Net.Vpc.Upa.Expressions.Literal.FALSE);
            }

            case Net.Vpc.Upa.Expressions.BinaryOperator.LT:
            {
                Net.Vpc.Upa.Impl.Util.XNumber na = Net.Vpc.Upa.Impl.Util.UPAUtils.ToNumberOrError(a);
                Net.Vpc.Upa.Impl.Util.XNumber nb = Net.Vpc.Upa.Impl.Util.UPAUtils.ToNumberOrError(b);
                return((Net.Vpc.Upa.Impl.Util.XNumber.Compare(na, nb) < 0) ? Net.Vpc.Upa.Expressions.Literal.TRUE : Net.Vpc.Upa.Expressions.Literal.FALSE);
            }

            case Net.Vpc.Upa.Expressions.BinaryOperator.PLUS:
            {
                if (a is string || b is string)
                {
                    return(new Net.Vpc.Upa.Expressions.Literal(FormatResult(a) + FormatResult(b)));
                }
                Net.Vpc.Upa.Impl.Util.XNumber na = Net.Vpc.Upa.Impl.Util.UPAUtils.ToNumberOrError(a);
                Net.Vpc.Upa.Impl.Util.XNumber nb = Net.Vpc.Upa.Impl.Util.UPAUtils.ToNumberOrError(b);
                if (na == null)
                {
                    return(new Net.Vpc.Upa.Expressions.Literal(nb, null));
                }
                if (nb == null)
                {
                    return(new Net.Vpc.Upa.Expressions.Literal(na, null));
                }
                return(new Net.Vpc.Upa.Expressions.Literal(na.Add(nb).ToNumber(), null));
            }

            case Net.Vpc.Upa.Expressions.BinaryOperator.MINUS:
            {
                Net.Vpc.Upa.Impl.Util.XNumber na = Net.Vpc.Upa.Impl.Util.UPAUtils.ToNumberOrError(a);
                Net.Vpc.Upa.Impl.Util.XNumber nb = Net.Vpc.Upa.Impl.Util.UPAUtils.ToNumberOrError(b);
                if (na == null)
                {
                    return(new Net.Vpc.Upa.Expressions.Literal(nb.Negate(), null));
                }
                if (nb == null)
                {
                    return(new Net.Vpc.Upa.Expressions.Literal(na, null));
                }
                return(new Net.Vpc.Upa.Expressions.Literal(na.Subtract(nb).ToNumber(), null));
            }

            case Net.Vpc.Upa.Expressions.BinaryOperator.DIV:
            {
                Net.Vpc.Upa.Impl.Util.XNumber na = Net.Vpc.Upa.Impl.Util.UPAUtils.ToNumberOrError(a);
                Net.Vpc.Upa.Impl.Util.XNumber nb = Net.Vpc.Upa.Impl.Util.UPAUtils.ToNumberOrError(b);
                if (na == null)
                {
                    return(Net.Vpc.Upa.Expressions.Literal.ZERO);
                }
                if (nb == null)
                {
                    return(new Net.Vpc.Upa.Expressions.Literal(System.Double.NaN));
                }
                return(new Net.Vpc.Upa.Expressions.Literal(na.Divide(nb).ToNumber(), null));
            }

            case Net.Vpc.Upa.Expressions.BinaryOperator.MUL:
            {
                Net.Vpc.Upa.Impl.Util.XNumber na = Net.Vpc.Upa.Impl.Util.UPAUtils.ToNumberOrError(a);
                Net.Vpc.Upa.Impl.Util.XNumber nb = Net.Vpc.Upa.Impl.Util.UPAUtils.ToNumberOrError(b);
                if (na == null)
                {
                    return(Net.Vpc.Upa.Expressions.Literal.ZERO);
                }
                if (nb == null)
                {
                    return(Net.Vpc.Upa.Expressions.Literal.ZERO);
                }
                return(new Net.Vpc.Upa.Expressions.Literal(na.Multiply(nb).ToNumber(), null));
            }

            case Net.Vpc.Upa.Expressions.BinaryOperator.LIKE:
            {
                if (a == null)
                {
                    a = "";
                }
                if (b == null)
                {
                    b = "";
                }
                a = FormatResult(a);
                b = FormatResult(b);
                string val     = (string)a;
                string pattern = ((string)b).Replace('%', '*');
                return(Net.Vpc.Upa.Impl.Util.StringUtils.MatchesSimpleExpression(val, pattern, Net.Vpc.Upa.Impl.Util.PatternType.ANY) ? Net.Vpc.Upa.Expressions.Literal.TRUE : Net.Vpc.Upa.Expressions.Literal.FALSE);
            }
            }
            //TODO other binary operators
            throw new System.ArgumentException("Not supported");
        }
Пример #7
0
 public virtual bool Equals(Net.Vpc.Upa.Impl.Util.XNumber other) {
     return CompareTo(other) == 0;
 }