Beispiel #1
0
        public override ExprNode Validate(ExprValidationContext validationContext)
        {
            if (ChildNodes.Length != 2) {
                throw new ExprValidationException("BitWise node must have 2 parameters");
            }

            var typeOne = ChildNodes[0].Forge.EvaluationType.GetBoxedType();
            var typeTwo = ChildNodes[1].Forge.EvaluationType.GetBoxedType();
            CheckNumericOrBoolean(typeOne);
            CheckNumericOrBoolean(typeTwo);

            if (typeOne.IsFloatingPointClass() || typeTwo.IsFloatingPointClass()) {
                throw new ExprValidationException(
                    "Invalid type for bitwise " + BitWiseOpEnum.ComputeDescription + " operator");
            }

            if (typeOne != typeTwo) {
                throw new ExprValidationException(
                    "Bitwise expressions must be of the same type for bitwise " +
                    BitWiseOpEnum.ComputeDescription +
                    " operator");
            }

            var computer = BitWiseOpEnum.GetComputer(typeOne);
            _forge = new ExprBitWiseNodeForge(this, typeOne, computer);
            return null;
        }
Beispiel #2
0
        /// <summary>
        /// Returns number or bool computation for the target coercion type.
        /// </summary>
        /// <param name="value">The value.</param>
        /// <param name="coercedType">target type</param>
        /// <returns>number cruncher</returns>

        public static Computer GetComputer(this BitWiseOpEnum value, Type coercedType)
        {
            if ((coercedType != typeof(byte?)) &&
                (coercedType != typeof(byte?)) &&
                (coercedType != typeof(short?)) &&
                (coercedType != typeof(int?)) &&
                (coercedType != typeof(long?)) &&
                (coercedType != typeof(bool?)))
            {
                throw new ArgumentException("Expected base numeric or bool type for computation result but got type " + coercedType);
            }

            MultiKeyUntyped key = new MultiKeyUntyped(new Object[] { coercedType, value });

            return(Computers[key]);
        }
Beispiel #3
0
        public static String GetExpressionText(this BitWiseOpEnum value)
        {
            switch (value)
            {
            case BitWiseOpEnum.BAND:
                return("&");

            case BitWiseOpEnum.BOR:
                return("|");

            case BitWiseOpEnum.BXOR:
                return("^");
            }

            throw new ArgumentException("invalid value", "value");
        }
Beispiel #4
0
 /// <summary>
 ///     Ctor.
 /// </summary>
 /// <param name="bitWiseOpEnum">type of math</param>
 public ExprBitWiseNode(BitWiseOpEnum bitWiseOpEnum)
 {
     BitWiseOpEnum = bitWiseOpEnum;
 }
 public void QExprBitwise(ExprNode exprNode, BitWiseOpEnum bitWiseOpEnum)
 {
 }
Beispiel #6
0
 /// <summary>
 /// Ctor - for use to create an expression tree, without child expression.
 /// <para/>
 /// Use add methods to add child expressions to acts upon.
 /// </summary>
 /// <param name="binaryOp">the binary operator</param>
 public BitwiseOpExpression(BitWiseOpEnum binaryOp)
 {
     _binaryOp = binaryOp;
 }
Beispiel #7
0
        /// <summary>Returns string rendering of enum.</summary>
        /// <returns>bitwise operator string</returns>

        public static String GetComputeDescription(this BitWiseOpEnum value)
        {
            return(GetExpressionText(value));
        }
Beispiel #8
0
 public void QExprBitwise(
     string text,
     BitWiseOpEnum bitWiseOpEnum)
 {
 }