Jurassic.Compiler.DynamicILGenerator.CheckArithmeticOperands C# (CSharp) Method

CheckArithmeticOperands() private method

private CheckArithmeticOperands ( ArithmeticOperator @operator ) : void
@operator ArithmeticOperator
return void
        private void CheckArithmeticOperands(ArithmeticOperator @operator)
        {
            // Pop the operand types from the stack.
            var right = this.operands.Pop();
            var left = this.operands.Pop();

            // Enumerate all the possible combinations.
            switch (left)
            {
                case VESType.Int32:
                    if (right != VESType.Int32 && right != VESType.NativeInt && (right != VESType.ManagedPointer || @operator != ArithmeticOperator.Add))
                        throw new InvalidOperationException(string.Format("Invalid stack operand(s) ({0} {1} {2}).", @operator, left, right));
                    PushStackOperand(right);
                    break;

                case VESType.Int64:
                    if (right != VESType.Int64)
                        throw new InvalidOperationException(string.Format("Invalid stack operand(s) ({0} {1} {2}).", @operator, left, right));
                    PushStackOperand(VESType.Int64);
                    break;

                case VESType.NativeInt:
                    if (right != VESType.Int32 && right != VESType.NativeInt && (right != VESType.ManagedPointer || @operator != ArithmeticOperator.Add))
                        throw new InvalidOperationException(string.Format("Invalid stack operand(s) ({0} {1} {2}).", @operator, left, right));
                    PushStackOperand(right == VESType.ManagedPointer ? VESType.ManagedPointer : VESType.NativeInt);
                    break;

                case VESType.Float:
                    if (right != VESType.Float)
                        throw new InvalidOperationException(string.Format("Invalid stack operand(s) ({0} {1} {2}).", @operator, left, right));
                    PushStackOperand(VESType.Float);
                    break;

                case VESType.ManagedPointer:
                    if (@operator == ArithmeticOperator.Add)
                    {
                        if (right != VESType.Int32 && right != VESType.NativeInt)
                            throw new InvalidOperationException(string.Format("Invalid stack operand(s) ({0} {1} {2}).", @operator, left, right));
                    }
                    else if (@operator == ArithmeticOperator.Subtract)
                    {
                        if (right != VESType.Int32 && right != VESType.NativeInt && right != VESType.ManagedPointer)
                            throw new InvalidOperationException(string.Format("Invalid stack operand(s) ({0} {1} {2}).", @operator, left, right));
                    }
                    else
                        throw new InvalidOperationException(string.Format("Invalid stack operand(s) ({0} {1} {2}).", @operator, left, right));
                    PushStackOperand(right == VESType.ManagedPointer ? VESType.NativeInt : VESType.ManagedPointer);
                    break;

                case VESType.Object:
                    throw new InvalidOperationException(string.Format("Invalid stack operand(s) ({0} {1} {2}).", @operator, left, right));
            }
        }
DynamicILGenerator