Example #1
0
        public static SingleOperandFunctionVector Create()
        {
            var vector = new SingleOperandFunctionVector();

            vector.RegisterDelegate(OperandType.Sbyte, operand => new Operand(OperandType.Int, ~(sbyte)operand.GetValue()));
            vector.RegisterDelegate(OperandType.Byte, operand => new Operand(OperandType.Int, ~(byte)operand.GetValue()));
            vector.RegisterDelegate(OperandType.Short, operand => new Operand(OperandType.Int, ~(short)operand.GetValue()));
            vector.RegisterDelegate(OperandType.Ushort, operand => new Operand(OperandType.Int, ~(ushort)operand.GetValue()));
            vector.RegisterDelegate(OperandType.Int, operand => new Operand(OperandType.Int, ~(int)operand.GetValue()));
            vector.RegisterDelegate(OperandType.Uint, operand => new Operand(OperandType.Uint, ~(uint)operand.GetValue()));
            vector.RegisterDelegate(OperandType.Long, operand => new Operand(OperandType.Long, ~(long)operand.GetValue()));
            vector.RegisterDelegate(OperandType.Ulong, operand => new Operand(OperandType.Ulong, ~(ulong)operand.GetValue()));
            vector.RegisterDelegate(OperandType.Char, operand => new Operand(OperandType.Int, ~(char)operand.GetValue()));
            vector.RegisterDelegate(OperandType.NullableSbyte, operand => new Operand(OperandType.NullableInt, ~(sbyte?)operand.GetValue()));
            vector.RegisterDelegate(OperandType.NullableByte, operand => new Operand(OperandType.NullableInt, ~(byte?)operand.GetValue()));
            vector.RegisterDelegate(OperandType.NullableShort, operand => new Operand(OperandType.NullableInt, ~(short?)operand.GetValue()));
            vector.RegisterDelegate(OperandType.NullableUshort, operand => new Operand(OperandType.NullableInt, ~(ushort?)operand.GetValue()));
            vector.RegisterDelegate(OperandType.NullableInt, operand => new Operand(OperandType.NullableInt, ~(int?)operand.GetValue()));
            vector.RegisterDelegate(OperandType.NullableUint, operand => new Operand(OperandType.NullableUint, ~(uint?)operand.GetValue()));
            vector.RegisterDelegate(OperandType.NullableLong, operand => new Operand(OperandType.NullableLong, ~(long?)operand.GetValue()));
            vector.RegisterDelegate(OperandType.NullableUlong, operand => new Operand(OperandType.NullableUlong, ~(ulong?)operand.GetValue()));
            vector.RegisterDelegate(OperandType.NullableChar, operand => new Operand(OperandType.NullableInt, ~(char?)operand.GetValue()));

            return(vector);
        }
Example #2
0
        public static SingleOperandFunctionVector Create()
        {
            var vector = new SingleOperandFunctionVector();

            vector.RegisterDelegate(OperandType.Sbyte, operand => new Operand(OperandType.Int, +(sbyte)operand.GetValue()));
            vector.RegisterDelegate(OperandType.Byte, operand => new Operand(OperandType.Int, +(byte)operand.GetValue()));
            vector.RegisterDelegate(OperandType.Short, operand => new Operand(OperandType.Int, +(short)operand.GetValue()));
            vector.RegisterDelegate(OperandType.Ushort, operand => new Operand(OperandType.Int, +(ushort)operand.GetValue()));
            vector.RegisterDelegate(OperandType.Int, operand => new Operand(OperandType.Int, +(int)operand.GetValue()));
            vector.RegisterDelegate(OperandType.Uint, operand => new Operand(OperandType.Uint, +(uint)operand.GetValue()));
            vector.RegisterDelegate(OperandType.Long, operand => new Operand(OperandType.Long, +(long)operand.GetValue()));
            vector.RegisterDelegate(OperandType.Ulong, operand => new Operand(OperandType.Ulong, +(ulong)operand.GetValue()));
            vector.RegisterDelegate(OperandType.Char, operand => new Operand(OperandType.Int, +(char)operand.GetValue()));
            vector.RegisterDelegate(OperandType.Float, operand => new Operand(OperandType.Float, +(float)operand.GetValue()));
            vector.RegisterDelegate(OperandType.Double, operand => new Operand(OperandType.Double, +(double)operand.GetValue()));
            vector.RegisterDelegate(OperandType.Decimal, operand => new Operand(OperandType.Decimal, +(decimal)operand.GetValue()));
            vector.RegisterDelegate(OperandType.NullableSbyte, operand => new Operand(OperandType.NullableInt, +(sbyte?)operand.GetValue()));
            vector.RegisterDelegate(OperandType.NullableByte, operand => new Operand(OperandType.NullableInt, +(byte?)operand.GetValue()));
            vector.RegisterDelegate(OperandType.NullableShort, operand => new Operand(OperandType.NullableInt, +(short?)operand.GetValue()));
            vector.RegisterDelegate(OperandType.NullableUshort, operand => new Operand(OperandType.NullableInt, +(ushort?)operand.GetValue()));
            vector.RegisterDelegate(OperandType.NullableInt, operand => new Operand(OperandType.NullableInt, +(int?)operand.GetValue()));
            vector.RegisterDelegate(OperandType.NullableUint, operand => new Operand(OperandType.NullableUint, +(uint?)operand.GetValue()));
            vector.RegisterDelegate(OperandType.NullableLong, operand => new Operand(OperandType.NullableLong, +(long?)operand.GetValue()));
            vector.RegisterDelegate(OperandType.NullableUlong, operand => new Operand(OperandType.NullableUlong, +(ulong?)operand.GetValue()));
            vector.RegisterDelegate(OperandType.NullableChar, operand => new Operand(OperandType.NullableInt, +(char?)operand.GetValue()));
            vector.RegisterDelegate(OperandType.NullableFloat, operand => new Operand(OperandType.NullableFloat, +(float?)operand.GetValue()));
            vector.RegisterDelegate(OperandType.NullableDouble, operand => new Operand(OperandType.NullableDouble, +(double?)operand.GetValue()));
            vector.RegisterDelegate(OperandType.NullableDecimal, operand => new Operand(OperandType.NullableDecimal, +(decimal?)operand.GetValue()));

            return(vector);
        }
Example #3
0
        public static SingleOperandFunctionVector Create()
        {
            var vector = new SingleOperandFunctionVector();

            vector.RegisterDelegate(OperandType.Bool, operand => new Operand(OperandType.Bool, !(bool)operand.GetValue()));
            vector.RegisterDelegate(OperandType.NullableBool, operand => new Operand(OperandType.NullableBool, !(bool?)operand.GetValue()));

            return(vector);
        }
        internal static Tuple <OperandType> DoUnaryOperation(SingleOperandFunctionVector vector, Stack <IOperand> stack, IBackingStore backingStore)
        {
            IOperand first = PopAndResolve(stack, backingStore);

            IOperand result = vector.PerformDelegate(first);

            if (result != null)
            {
                stack.Push(result);
                return(null);
            }
            else
            {
                // Signal an error ...
                return(new Tuple <OperandType>(first.Type));
            }
        }
        public IOperator RegisterUnaryOperator(string text, int precedence, SingleOperandFunctionVector vector)
        {
            var op = new Operator(
                OperatorType.UnaryOperator,
                precedence,
                ShortCircuitMode.None,
                (operandStack, vSet, parserPosition) =>
            {
                var result = OperatorActions.DoUnaryOperation(vector, operandStack, vSet);
                if (result != null)
                {
                    throw new ExpressionEvaluatorException(parserPosition,
                                                           ExpressionEvaluatorException.ExceptionCause.BadUnaryOperand,
                                                           "Unary operator '" + text + "' cannot be applied to operand of type " + result.Item1);
                }
            },
                text
                );

            Operators.Add(text, op);
            OperatorVectors.Add(op, vector);
            return(op);
        }