public override string BuildSql(SqlOptions sqlOptions)
        {
            var left    = LeftOperand.BuildSql(sqlOptions, FlowOptions.Construct(this));
            var right   = RightOperand.BuildSql(sqlOptions, FlowOptions.Construct(this));
            var command = sqlOptions.Command("IN");

            return($"{left} {command} ({right})");
        }
 public override ExpressionCode GenerateCode()
 {
     return(new ExpressionCode
     {
         Code = "( " + LeftOperand.GenerateCode().Code + " || " + RightOperand.GenerateCode().Code + " )",
         Type = "bool"
     });
 }
        /// <summary>
        /// This property signs if an expression is ready to be evaluated,
        /// namely, all subexpression values are known
        /// </summary>
        public override bool ReadyToEvaluate(IEvaluationContext evalContext)
        {
            // --- Note: We intentionally avoid short-circuit evaluation!
            var leftResult  = LeftOperand.ReadyToEvaluate(evalContext);
            var rightResult = RightOperand.ReadyToEvaluate(evalContext);

            return(leftResult && rightResult);
        }
        public override void GenCode(ICodeGenerator cg)
        {
            var gen = cg.GetGenerator;

            LeftOperand.GenCode(cg);
            RightOperand.GenCode(cg);
            gen.Emit(OpCodes.Mul);
        }
Exemple #5
0
        public bool Evaluate(IReadOnlyMemory memory)
        {
            var leftValue  = LeftOperand.Evaluate(memory).ToInt();
            var rightValue = RightOperand.Evaluate(memory).ToInt();
            var result     = EvaluateExpression(leftValue, rightValue, Operation);

            return(result);
        }
Exemple #6
0
        protected override void EmitOperator(Context ctx)
        {
            var gen = ctx.CurrentMethod.Generator;

            LeftOperand.Emit(ctx, true);
            RightOperand.Emit(ctx, true);

            gen.EmitShift(IsLeft);
        }
        public override string ToString()
        {
            if (Operator == QueryLogicalOperator.Not)
            {
                return($"{Operator}({LeftOperand.ToString()})");
            }

            return($"({LeftOperand.ToString()}) {Operator} ({RightOperand.ToString()})");
        }
        /// <summary>
        /// Returns a string representation of the formula
        /// </summary>
        public override string FormulaRepresentation()
        {
            string strOperationType = GetWFSOperationTypeString();
            string strLeftOperand   = LeftOperand.FormulaRepresentation();
            string strRightOperand  = RightOperand.FormulaRepresentation();
            string str = "(" + strLeftOperand + " " + strOperationType + " " + strRightOperand + ")";

            return(str);
        }
Exemple #9
0
        public override ITypedValue GetValueInternal(ExpressionState state)
        {
            var leftValue  = LeftOperand.GetValueInternal(state).Value;
            var rightValue = RightOperand.GetValueInternal(state).Value;

            _leftActualDescriptor  = CodeFlow.ToDescriptorFromObject(leftValue);
            _rightActualDescriptor = CodeFlow.ToDescriptorFromObject(rightValue);
            return(BooleanTypedValue.ForValue(!EqualityCheck(state.EvaluationContext, leftValue, rightValue)));
        }
Exemple #10
0
        public void DigitButtonPress(string button)
        {
            switch (button)
            {
            case "CLEAR":
            {
                Display      = "0";
                LeftOperand  = string.Empty;
                RightOperand = string.Empty;
                Operation    = string.Empty;
                break;
            }

            case "BACKSPACE":
            {
                if (Operation != string.Empty && RightOperand == string.Empty)
                {
                    Operation = string.Empty;
                    Display   = LeftOperand;
                }
                else if (Operation != string.Empty && RightOperand != string.Empty)
                {
                    RightOperand = RightOperand.Remove(RightOperand.Length - 1);
                    Display      = LeftOperand + Operation + RightOperand;
                }
                else if (LeftOperand != string.Empty)
                {
                    LeftOperand = LeftOperand.Remove(LeftOperand.Length - 1);
                    if (LeftOperand != string.Empty)
                    {
                        Display = LeftOperand;
                    }
                    else
                    {
                        Display = "0";
                    }
                }
                break;
            }

            default:
            {
                if (Operation == string.Empty)
                {
                    LeftOperand = LeftOperand + button;
                    Display     = LeftOperand;
                }
                else
                {
                    RightOperand = RightOperand + button;
                    Display      = LeftOperand + Operation + RightOperand;
                }

                break;
            }
            }
        }
Exemple #11
0
        public override Value Interpret()
        {
            dynamic leftV  = LeftOperand.Interpret();
            dynamic rightV = RightOperand.Interpret();

            return(new IntValue {
                Value = leftV.Value / rightV.Value
            });
        }
        /// <summary>
        /// TBD ?!?
        /// </summary>
        public override string WfsXmlRepresentation()
        {
            string strOperationType = GetWFSOperationTypeString();
            string strLeftOperand   = LeftOperand.WfsXmlRepresentation();
            string strRightOperand  = RightOperand.WfsXmlRepresentation();
            string str = "<ogc:" + strOperationType + ">" + strLeftOperand + strRightOperand + "</ogc:" + strOperationType + ">";

            return(str);
        }
Exemple #13
0
        /// <summary>
        /// Calculates the result of the binary operation.
        /// </summary>
        /// <param name="evalContext">Evaluation context</param>
        /// <returns>Result of the operation</returns>
        public override ExpressionValue Calculate(IExpressionEvaluationContext evalContext)
        {
            var left  = LeftOperand.Evaluate(evalContext);
            var right = RightOperand.Evaluate(evalContext);

            SuggestType(ExpressionValueType.Bool);
            return(left.IsValid && right.IsValid
                ? new ExpressionValue(left.Value >= right.Value ? 1u : 0u)
                : ExpressionValue.Error);
        }
        /// <summary>
        /// Calculates the result of the binary operation.
        /// </summary>
        /// <param name="evalContext">Evaluation context</param>
        /// <returns>Result of the operation</returns>
        public override ExpressionValue Calculate(IExpressionEvaluationContext evalContext)
        {
            var left  = LeftOperand.Evaluate(evalContext);
            var right = RightOperand.Evaluate(evalContext);

            SuggestWiderType();
            return(left.IsValid && right.IsValid
                ? new ExpressionValue(left.Value >> (int)right.Value)
                : ExpressionValue.Error);
        }
Exemple #15
0
        public override ITypedValue GetValueInternal(ExpressionState state)
        {
            var leftOperand  = LeftOperand.GetValueInternal(state).Value;
            var rightOperand = RightOperand.GetValueInternal(state).Value;

            if (IsNumber(leftOperand) && IsNumber(rightOperand))
            {
                var leftNumber  = (IConvertible)leftOperand;
                var rightNumber = (IConvertible)rightOperand;

                if (leftNumber is decimal || rightNumber is decimal)
                {
                    var leftVal  = leftNumber.ToDecimal(CultureInfo.InvariantCulture);
                    var rightVal = rightNumber.ToDecimal(CultureInfo.InvariantCulture);
                    return(new TypedValue(leftVal % rightVal));
                }
                else if (leftNumber is double || rightNumber is double)
                {
                    _exitTypeDescriptor = "D";
                    var leftVal  = leftNumber.ToDouble(CultureInfo.InvariantCulture);
                    var rightVal = rightNumber.ToDouble(CultureInfo.InvariantCulture);
                    return(new TypedValue(leftVal % rightVal));
                }
                else if (leftNumber is float || rightNumber is float)
                {
                    _exitTypeDescriptor = "F";
                    var leftVal  = leftNumber.ToSingle(CultureInfo.InvariantCulture);
                    var rightVal = rightNumber.ToSingle(CultureInfo.InvariantCulture);
                    return(new TypedValue(leftVal % rightVal));
                }
                else if (leftNumber is long || rightNumber is long)
                {
                    _exitTypeDescriptor = "J";
                    var leftVal  = leftNumber.ToInt64(CultureInfo.InvariantCulture);
                    var rightVal = rightNumber.ToInt64(CultureInfo.InvariantCulture);
                    return(new TypedValue(leftVal % rightVal));
                }
                else if (CodeFlow.IsIntegerForNumericOp(leftNumber) || CodeFlow.IsIntegerForNumericOp(rightNumber))
                {
                    _exitTypeDescriptor = "I";
                    var leftVal  = leftNumber.ToInt32(CultureInfo.InvariantCulture);
                    var rightVal = rightNumber.ToInt32(CultureInfo.InvariantCulture);
                    return(new TypedValue(leftVal % rightVal));
                }
                else
                {
                    // Unknown Number subtypes -> best guess is double division
                    var leftVal  = leftNumber.ToDouble(CultureInfo.InvariantCulture);
                    var rightVal = rightNumber.ToDouble(CultureInfo.InvariantCulture);
                    return(new TypedValue(leftVal % rightVal));
                }
            }

            return(state.Operate(Operation.MODULUS, leftOperand, rightOperand));
        }
        public override BaseType ValidateSemantic()
        {
            var leftType  = LeftOperand.ValidateSemantic();
            var rightType = RightOperand.ValidateSemantic();

            if (leftType is IntType && rightType is IntType)
            {
                return(leftType);
            }
            throw new SemanticException($"div is not supported for {leftType} and {rightType}");
        }
Exemple #17
0
        public override string Pretty(int level)
        {
            var sb = new StringBuilder("InfixOp");

            sb.AppendLine();
            sb.AppendLine(Display.Utils.Indent(level + 1) + $"Operator: {Operator.Type}");
            sb.AppendLine(Display.Utils.Indent(level + 1) + $"Left: {LeftOperand.Pretty(level + 1)}");
            sb.AppendLine(Display.Utils.Indent(level + 1) + $"Right: {RightOperand.Pretty(level + 1)}");

            return(sb.ToString());
        }
Exemple #18
0
        public override double Calculate()
        {
            var rightOperandResult = RightOperand.Calculate();

            if (rightOperandResult.Equals(0))
            {
                throw new DivideByZeroException();
            }

            return(LeftOperand.Calculate() / RightOperand.Calculate());
        }
        /// <summary>
        /// Calculates the result of the binary operation.
        /// </summary>
        /// <param name="evalContext">Evaluation context</param>
        /// <returns>Result of the operation</returns>
        public override ExpressionValue Calculate(IEvaluationContext evalContext)
        {
            var left  = LeftOperand.Evaluate(evalContext);
            var right = RightOperand.Evaluate(evalContext);

            switch (right.Type)
            {
            case ExpressionValueType.Bool:
            case ExpressionValueType.Integer:
                var rightNum = right.AsLong();
                switch (left.Type)
                {
                case ExpressionValueType.Bool:
                case ExpressionValueType.Integer:
                    return(new ExpressionValue(left.AsLong() > rightNum ? left.AsLong() : rightNum));

                case ExpressionValueType.Real:
                    return(new ExpressionValue(left.AsReal() > rightNum ? left.AsReal() : rightNum));

                case ExpressionValueType.String:
                    EvaluationError = LEFT_STRING_ERROR;
                    return(ExpressionValue.Error);

                default:
                    return(ExpressionValue.Error);
                }

            case ExpressionValueType.Real:
                var rightReal = right.AsReal();
                switch (left.Type)
                {
                case ExpressionValueType.Bool:
                case ExpressionValueType.Integer:
                    return(new ExpressionValue(left.AsLong() > rightReal ? left.AsLong() : rightReal));

                case ExpressionValueType.Real:
                    return(new ExpressionValue(left.AsReal() > rightReal ? left.AsReal() : rightReal));

                case ExpressionValueType.String:
                    EvaluationError = LEFT_STRING_ERROR;
                    return(ExpressionValue.Error);

                default:
                    return(ExpressionValue.Error);
                }

            case ExpressionValueType.String:
                EvaluationError = RIGHT_STRING_ERROR;
                return(ExpressionValue.Error);

            default:
                return(ExpressionValue.Error);
            }
        }
        internal override object Eval()
        {
            var left  = LeftOperand.Eval();
            var right = RightOperand.Eval();

            if (left.GetType() == right.GetType())
            {
                return(!left.Equals(right));
            }
            return(!(left as string ?? left.ToString()).Equals(right as string ?? right.ToString()));
        }
Exemple #21
0
        protected override NodeBase expand(Context ctx, bool mustReturn)
        {
            if (Resolve(ctx).IsNullableType())
            {
                var leftNullable  = LeftOperand.Resolve(ctx).IsNullableType();
                var rightNullable = RightOperand.Resolve(ctx).IsNullableType();
                if (leftNullable && rightNullable)
                {
                    return(Expr.If(
                               Expr.And(
                                   Expr.GetMember(LeftOperand, "HasValue"),
                                   Expr.GetMember(RightOperand, "HasValue")
                                   ),
                               Expr.Block(
                                   recreateSelfWithArgs(
                                       Expr.GetMember(LeftOperand, "Value"),
                                       Expr.GetMember(RightOperand, "Value")
                                       )
                                   ),
                               Expr.Block(Expr.Null())
                               ));
                }

                if (leftNullable)
                {
                    return(Expr.If(
                               Expr.GetMember(LeftOperand, "HasValue"),
                               Expr.Block(
                                   recreateSelfWithArgs(
                                       Expr.GetMember(LeftOperand, "Value"),
                                       RightOperand
                                       )
                                   ),
                               Expr.Block(Expr.Null())
                               ));
                }

                if (rightNullable)
                {
                    return(Expr.If(
                               Expr.GetMember(RightOperand, "HasValue"),
                               Expr.Block(
                                   recreateSelfWithArgs(
                                       LeftOperand,
                                       Expr.GetMember(RightOperand, "Value")
                                       )
                                   ),
                               Expr.Block(Expr.Null())
                               ));
                }
            }

            return(base.expand(ctx, mustReturn));
        }
Exemple #22
0
 public override int GetHashCode()
 {
     unchecked
     {
         var hashCode = (LeftOperand != null ? LeftOperand.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (RightOperand != null ? RightOperand.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (Operation != null ? Operation.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (int)Type;
         return(hashCode);
     }
 }
        internal override object Eval()
        {
            var left  = LeftOperand.Eval();
            var right = RightOperand.Eval();

            if (left.GetType() == right.GetType() && left is IComparable lCom && right is IComparable rCom)
            {
                return(lCom.CompareTo(rCom) >= 0);
            }
            return((left as string ?? left.ToString()).CompareTo((right as string ?? right.ToString())) >= 0);
        }
        protected NotEqualsRelationship(SymbolicValue leftOperand, SymbolicValue rightOperand)
            : base(leftOperand, rightOperand)
        {
            this.hash = new Lazy <int>(() =>
            {
                var left  = LeftOperand.GetHashCode();
                var right = RightOperand.GetHashCode();

                return(EqualsRelationship.GetHashCodeMinMaxOrdered(left, right, GetType().GetHashCode()));
            });
        }
 public override void GenCode(ICodeGenerator cg)
 {
     LeftOperand.GenCode(cg);
     RightOperand.GenCode(cg);
     if (LeftOperand.ReturnType.PrimitiveType is StringType)
     {
         MethodInfo method = typeof(string).GetMethod("Compare", new Type[] { typeof(string), typeof(string) });
         cg.GetGenerator.Emit(OpCodes.Call, method);
         cg.GetGenerator.Emit(OpCodes.Ldc_I4_0);
     }
     cg.GetGenerator.Emit(OpCodes.Ceq);
 }
        public override string GenerateCode()
        {
            var leftType  = LeftOperand.ValidateSemantic();
            var rightType = RightOperand.ValidateSemantic();

            if (leftType is StringType && rightType is StringType)
            {
                return($"!({LeftOperand.GenerateCode()}.equals({RightOperand.GenerateCode()}))");
            }

            return($"{LeftOperand.GenerateCode()} != {RightOperand.GenerateCode()}");
        }
        /// <summary>
        /// Calculates the result of the binary operation.
        /// </summary>
        /// <param name="evalContext">Evaluation context</param>
        /// <returns>Result of the operation</returns>
        public override ushort Calculate(IEvaluationContext evalContext)
        {
            var divider = RightOperand.Evaluate(evalContext);

            if (divider != 0)
            {
                return((ushort)(LeftOperand.Evaluate(evalContext) / divider));
            }

            EvaluationError = "Divide by zero error";
            return(0);
        }
        public override Value Interpretation()
        {
            dynamic left  = LeftOperand.Interpretation();
            dynamic right = RightOperand.Interpretation();


            dynamic response = left.Value >= right.Value;

            dynamic typeOfReturn = GetTypeValue(left, right, response);

            return(typeOfReturn);
        }
Exemple #29
0
        /// <summary>
        /// Emits code for relation comparison: greater, less, etc.
        /// </summary>
        private void EmitRelation(Context ctx, Type left, Type right)
        {
            var gen = ctx.CurrentMethod.Generator;

            // string comparisons
            if (left == typeof(string))
            {
                LeftOperand.Emit(ctx, true);
                RightOperand.Emit(ctx, true);

                var method = typeof(string).GetMethod("Compare", new[] { typeof(string), typeof(string) });
                gen.EmitCall(method);

                if (Kind.IsAnyOf(ComparisonOperatorKind.Less, ComparisonOperatorKind.GreaterEquals))
                {
                    gen.EmitConstant(-1);
                    gen.EmitCompareEqual();
                    if (Kind == ComparisonOperatorKind.GreaterEquals)
                    {
                        EmitInversion(gen);
                    }
                }
                else
                {
                    gen.EmitConstant(1);
                    gen.EmitCompareEqual();
                    if (Kind == ComparisonOperatorKind.LessEquals)
                    {
                        EmitInversion(gen);
                    }
                }
            }

            // numeric comparison
            LoadAndConvertNumerics(ctx);
            if (Kind.IsAnyOf(ComparisonOperatorKind.Less, ComparisonOperatorKind.GreaterEquals))
            {
                gen.EmitCompareLess();
                if (Kind == ComparisonOperatorKind.GreaterEquals)
                {
                    EmitInversion(gen);
                }
            }
            else
            {
                gen.EmitCompareGreater();
                if (Kind == ComparisonOperatorKind.LessEquals)
                {
                    EmitInversion(gen);
                }
            }
        }
        internal override IEnumerable <ProgramState> SetConstraint(BoolConstraint boolConstraint,
                                                                   SymbolicValueConstraints leftConstraints, SymbolicValueConstraints rightConstraints,
                                                                   ProgramState programState)
        {
            if (boolConstraint == BoolConstraint.False)
            {
                return(RightOperand.TrySetConstraints(leftConstraints, programState)
                       .SelectMany(ps => LeftOperand.TrySetConstraints(rightConstraints, ps)));
            }

            return(RightOperand.TrySetOppositeConstraints(leftConstraints, programState)
                   .SelectMany(ps => LeftOperand.TrySetOppositeConstraints(rightConstraints, ps)));
        }