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

CheckComparisonOperands() private method

private CheckComparisonOperands ( ComparisonOperator @operator, bool branchOperation ) : void
@operator ComparisonOperator
branchOperation bool
return void
        private void CheckComparisonOperands(ComparisonOperator @operator, bool branchOperation)
        {
            // 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)
                        throw new InvalidOperationException(string.Format("Invalid stack operand(s) ({0} {1} {2}).", @operator, left, right));
                    break;

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

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

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

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

                case VESType.Object:
                    if (right != VESType.Object || (@operator != ComparisonOperator.Equal && @operator != ComparisonOperator.NotEqual && @operator != ComparisonOperator.GreaterThanUnsigned))
                        throw new InvalidOperationException(string.Format("Invalid stack operand(s) ({0} {1} {2}).", @operator, left, right));
                    break;
            }

            if (branchOperation == false)
            {
                // All comparison operations produce an int32 as the output.
                PushStackOperand(VESType.Int32);
            }
        }
DynamicILGenerator