Ejemplo n.º 1
0
        public static BinaryOperatorKind WithOverflowChecksIfApplicable(this BinaryOperatorKind kind, bool enabled)
        {
            if (enabled)
            {
                // If it's a dynamic binop then make it checked. Let the lowering
                // pass sort out what to do with it.
                if (kind.IsDynamic())
                {
                    return(kind | BinaryOperatorKind.Checked);
                }

                if (kind.IsIntegral())
                {
                    switch (kind.Operator())
                    {
                    case BinaryOperatorKind.Addition:
                    case BinaryOperatorKind.Subtraction:
                    case BinaryOperatorKind.Multiplication:
                    case BinaryOperatorKind.Division:
                        return(kind | BinaryOperatorKind.Checked);
                    }
                }
                return(kind);
            }
            else
            {
                return(kind & ~BinaryOperatorKind.Checked);
            }
        }
Ejemplo n.º 2
0
 public static BinaryOperatorKind WithOverflowChecksIfApplicable(this BinaryOperatorKind kind, bool enabled)
 {
     if (enabled)
     {
         if (kind.IsIntegral())
         {
             switch (kind.Operator())
             {
             case BinaryOperatorKind.Addition:
             case BinaryOperatorKind.Subtraction:
             case BinaryOperatorKind.Multiplication:
             case BinaryOperatorKind.Division:
                 return(kind | BinaryOperatorKind.Checked);
             }
         }
         return(kind);
     }
     else
     {
         return(kind & ~BinaryOperatorKind.Checked);
     }
 }