예제 #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;
        }
예제 #2
0
        public override ExprNode Validate(ExprValidationContext validationContext)
        {
            if (ChildNodes.Count != 2)
            {
                throw new ExprValidationException("BitWise node must have 2 parameters");
            }

            _evaluators = ExprNodeUtility.GetEvaluators(ChildNodes);
            foreach (var child in _evaluators)
            {
                var childType = child.ReturnType;
                if ((!childType.IsBoolean()) && (!childType.IsNumeric()))
                {
                    throw new ExprValidationException("Invalid datatype for bitwise " +
                                                      childType.Name + " is not allowed");
                }
            }

            // Determine result type, set up compute function
            var childTypeOne = _evaluators[0].ReturnType;
            var childTypeTwo = _evaluators[1].ReturnType;

            if ((childTypeOne.IsFloatingPointClass()) || (childTypeTwo.IsFloatingPointClass()))
            {
                throw new ExprValidationException("Invalid type for bitwise " + _bitWiseOpEnum.GetComputeDescription() + " operator");
            }
            else
            {
                var childBoxedTypeOne = childTypeOne.GetBoxedType();
                var childBoxedTypeTwo = childTypeTwo.GetBoxedType();
                if (childBoxedTypeOne == childBoxedTypeTwo)
                {
                    _returnType            = childBoxedTypeOne;
                    _bitWiseOpEnumComputer = _bitWiseOpEnum.GetComputer(_returnType);
                }
                else
                {
                    throw new ExprValidationException("Bitwise expressions must be of the same type for bitwise " + _bitWiseOpEnum.GetComputeDescription() + " operator");
                }
            }

            return(null);
        }