2004-09-22 Marek Safar <marek.safar@seznam.cz>
authorMarek Safar <marek.safar@gmail.com>
Wed, 22 Sep 2004 13:02:11 +0000 (13:02 -0000)
committerMarek Safar <marek.safar@gmail.com>
Wed, 22 Sep 2004 13:02:11 +0000 (13:02 -0000)
* constant.cs (Constant.IsNegative): New abstract property
IsNegative.

* expression.cs (ArrayAccess.DoResolve): Add warning 251.
(StackAlloc.DoResolve): Reused IsNegative.

svn path=/trunk/mcs/; revision=34217

mcs/mcs/ChangeLog
mcs/mcs/constant.cs
mcs/mcs/ecore.cs
mcs/mcs/expression.cs
mcs/mcs/literal.cs

index 9eaaa9d72915f092d4cf8351d153c8ebf22dc22d..ba3ed2b3f7c96c934f333d31a2fcc44db9159cc7 100755 (executable)
@@ -1,3 +1,11 @@
+2004-09-22  Marek Safar  <marek.safar@seznam.cz>
+
+       * constant.cs (Constant.IsNegative): New abstract property
+       IsNegative.
+
+       * expression.cs (ArrayAccess.DoResolve): Add warning 251.
+       (StackAlloc.DoResolve): Reused IsNegative.
+
 2004-09-21  Martin Baulig  <martin@ximian.com>
 
        Merged latest changes into gmcs.  Please keep this comment in
index bb73f8e4b06093f48e9510152148261c5e8c57d0..103572b1d54af86099bd3919309430dbb5359702 100755 (executable)
@@ -147,6 +147,10 @@ namespace Mono.CSharp {
                        return null;
                }
                
+               public abstract bool IsNegative {
+                       get;
+               }
+
                //
                // Returns true iff 1) the stack type of this is one of Object, 
                // int32, int64 and 2) this == 0 or this == null.
@@ -185,7 +189,13 @@ namespace Mono.CSharp {
                        else
                                ec.ig.Emit (OpCodes.Ldc_I4_0);
                }
-               
+       
+               public override bool IsNegative {
+                       get {
+                               return false;
+                       }
+               }
+       
                public override bool IsZeroInteger {
                        get { return Value == false; }
                }
@@ -245,7 +255,13 @@ namespace Mono.CSharp {
                {
                        return new IntConstant (Value);
                }
-               
+
+               public override bool IsNegative {
+                       get {
+                               return false;
+                       }
+               }
+
                public override bool IsZeroInteger {
                        get { return Value == 0; }
                }
@@ -335,6 +351,12 @@ namespace Mono.CSharp {
                        return new IntConstant (Value);
                }
                
+               public override bool IsNegative {
+                       get {
+                               return false;
+                       }
+               }
+
                public override bool IsZeroInteger {
                        get { return Value == '\0'; }
                }
@@ -397,6 +419,12 @@ namespace Mono.CSharp {
                {
                        return new IntConstant (Value);
                }
+
+               public override bool IsNegative {
+                       get {
+                               return Value < 0;
+                       }
+               }
                
                public override bool IsZeroInteger {
                        get { return Value == 0; }
@@ -461,6 +489,12 @@ namespace Mono.CSharp {
                public override bool IsZeroInteger {
                        get { return Value == 0; }
                }
+
+               public override bool IsNegative {
+                       get {
+                               return Value < 0;
+                       }
+               }
        }
 
        public class UShortConstant : Constant {
@@ -517,7 +551,13 @@ namespace Mono.CSharp {
                {
                        return new IntConstant (Value);
                }
-               
+       
+               public override bool IsNegative {
+                       get {
+                               return false;
+                       }
+               }
+       
                public override bool IsZeroInteger {
                        get { return Value == 0; }
                }
@@ -636,6 +676,12 @@ namespace Mono.CSharp {
                        return this;
                }
                
+               public override bool IsNegative {
+                       get {
+                               return Value < 0;
+                       }
+               }
+
                public override bool IsZeroInteger {
                        get { return Value == 0; }
                }
@@ -696,6 +742,12 @@ namespace Mono.CSharp {
                        return null;
                }
                
+               public override bool IsNegative {
+                       get {
+                               return false;
+                       }
+               }
+
                public override bool IsZeroInteger {
                        get { return Value == 0; }
                }
@@ -771,6 +823,12 @@ namespace Mono.CSharp {
                        return null;
                }
                
+               public override bool IsNegative {
+                       get {
+                               return Value < 0;
+                       }
+               }
+
                public override bool IsZeroInteger {
                        get { return Value == 0; }
                }
@@ -832,7 +890,13 @@ namespace Mono.CSharp {
                {
                        return null;
                }
-               
+
+               public override bool IsNegative {
+                       get {
+                               return false;
+                       }
+               }
+
                public override bool IsZeroInteger {
                        get { return Value == 0; }
                }
@@ -887,6 +951,12 @@ namespace Mono.CSharp {
                {
                        return null;
                }
+
+               public override bool IsNegative {
+                       get {
+                               return Value < 0;
+                       }
+               }
        }
 
        public class DoubleConstant : Constant {
@@ -943,6 +1013,12 @@ namespace Mono.CSharp {
                {
                        return null;
                }
+
+               public override bool IsNegative {
+                       get {
+                               return Value < 0;
+                       }
+               }
        }
 
        public class DecimalConstant : Constant {
@@ -988,6 +1064,12 @@ namespace Mono.CSharp {
 
                        ig.Emit (OpCodes.Newobj, TypeManager.void_decimal_ctor_five_args);
                }
+
+               public override bool IsNegative {
+                       get {
+                               return Value < 0;
+                       }
+               }
        }
 
        public class StringConstant : Constant {
@@ -1018,6 +1100,12 @@ namespace Mono.CSharp {
                        else
                                ec.ig.Emit (OpCodes.Ldstr, Value);
                }
+
+               public override bool IsNegative {
+                       get {
+                               return false;
+                       }
+               }
        }
 
 }
index be9c761cdca71e4ce316f509b74319d5dce4b112..45523736c7a57b581662daa823054e2f34120e20 100755 (executable)
@@ -1390,6 +1390,12 @@ namespace Mono.CSharp {
                {
                        child.Emit (ec);
                }
+
+               public override bool IsNegative {
+                       get {
+                               return false;
+                       }
+               }
        }
 
 
@@ -1520,6 +1526,12 @@ namespace Mono.CSharp {
                public override bool IsZeroInteger {
                        get { return Child.IsZeroInteger; }
                }
+
+               public override bool IsNegative {
+                       get {
+                               return Child.IsNegative;
+                       }
+               }
        }
 
        /// <summary>
index b6586006adcc2266f0105897417e05d5b3aecbb8..f895e702afe2a99bbeba79cd25df61ef8ae935fd 100755 (executable)
@@ -7537,8 +7537,13 @@ namespace Mono.CSharp {
                                if (argtype == TypeManager.int32_type ||
                                    argtype == TypeManager.uint32_type ||
                                    argtype == TypeManager.int64_type ||
-                                   argtype == TypeManager.uint64_type)
+                                   argtype == TypeManager.uint64_type) {
+                                       Constant c = a.Expr as Constant;
+                                       if (c != null && c.IsNegative) {
+                                               Report.Warning (251, 2, a.Expr.Location, "Indexing an array with a negative index (array indices always start at zero)");
+                                       }
                                        continue;
+                               }
 
                                //
                                // Mhm.  This is strage, because the Argument.Type is not the same as
@@ -8520,8 +8525,7 @@ namespace Mono.CSharp {
                        }
 
                        Constant c = count as Constant;
-                       // TODO: because we don't have property IsNegative
-                       if (c != null && c.ConvertToUInt () == null) {
+                       if (c != null && c.IsNegative) {
                                Report.Error (247, loc, "Cannot use a negative size with stackalloc");
                                return null;
                        }
index 10812524d4eefffaa035f4f44e986532c633b8bd..ac8a49eeb85703ca63cb523f28739d1c0a4ed831 100755 (executable)
@@ -70,6 +70,12 @@ namespace Mono.CSharp {
                        ec.ig.Emit (OpCodes.Ldnull);
                }
                
+               public override bool IsNegative {
+                       get {
+                               return false;
+                       }
+               }
+
                public override bool IsZeroInteger {
                        get { return true; }
                }