Revert this patch as it breaks mscorlib and System.Web's test compilation
[mono.git] / mcs / mcs / literal.cs
old mode 100755 (executable)
new mode 100644 (file)
index 1081252..639e536
@@ -36,15 +36,19 @@ namespace System {
        
 namespace Mono.CSharp {
 
-       public class NullLiteral : Constant {
-               public static readonly NullLiteral Null;
+       //
+       // The NullType just exists to compare type equality, and for
+       // expressions that might have the `null type'
+       //
+       public class NullType {
+       }
 
-               static NullLiteral ()
-               {
-                       Null = new NullLiteral ();
-               }
-                       
-               public NullLiteral ()
+       //
+       // The null Literal constant
+       //
+       public class NullLiteral : Constant {
+               public NullLiteral (Location loc):
+                       base (loc)
                {
                        eclass = ExprClass.Value;
                }
@@ -61,7 +65,7 @@ namespace Mono.CSharp {
 
                public override Expression DoResolve (EmitContext ec)
                {
-                       type = typeof (System.Null); 
+                       type = TypeManager.null_type;
                        return this;
                }
 
@@ -69,24 +73,62 @@ namespace Mono.CSharp {
                {
                        ec.ig.Emit (OpCodes.Ldnull);
                }
-               
+
+               public override Constant Increment ()
+               {
+                       throw new NotSupportedException ();
+               }
+
+               public override bool IsDefaultValue {
+                       get {
+                               return true;
+                       }
+               }
+
+               public override bool IsNegative {
+                       get {
+                               return false;
+                       }
+               }
+
                public override bool IsZeroInteger {
                        get { return true; }
                }
+
+               public override string GetSignatureForError()
+               {
+                       return "null";
+               }
+
+               public override void Error_ValueCannotBeConverted (Location loc, Type t, bool expl)
+               {
+                       Report.Error (37, loc, "Cannot convert null to `{0}' because it is a value type",
+                               TypeManager.CSharpName (t));
+               }
+
+               public override Constant ToType (Type type, Location loc)
+               {
+                       if (!type.IsValueType && !TypeManager.IsEnumType (type))
+                               return this;
+
+                       return base.ToType (type, loc);
+               }
+
        }
 
        //
        // A null literal in a pointer context
        //
        public class NullPointer : NullLiteral {
-               public new static readonly NullLiteral Null;
+               public static readonly NullLiteral Null;
 
                static NullPointer ()
                {
                        Null = new NullPointer ();
                }
 
-               private NullPointer ()
+               private NullPointer ():
+                       base (Location.Null)
                {
                        type = TypeManager.object_type;
                }
@@ -101,7 +143,7 @@ namespace Mono.CSharp {
        }
 
        public class BoolLiteral : BoolConstant {
-               public BoolLiteral (bool val) : base (val)
+               public BoolLiteral (bool val, Location loc) : base (val, loc)
                {
                }
 
@@ -113,7 +155,7 @@ namespace Mono.CSharp {
        }
 
        public class CharLiteral : CharConstant {
-               public CharLiteral (char c) : base (c)
+               public CharLiteral (char c, Location loc) : base (c, loc)
                {
                }
 
@@ -125,15 +167,7 @@ namespace Mono.CSharp {
        }
 
        public class IntLiteral : IntConstant {
-               public static IntLiteral One, Zero;
-               
-               static IntLiteral ()
-               {
-                       Zero = new IntLiteral (0);
-                       One = new IntLiteral (1);
-               }
-               
-               public IntLiteral (int l) : base (l)
+               public IntLiteral (int l, Location loc) : base (l, loc)
                {
                }
 
@@ -145,7 +179,7 @@ namespace Mono.CSharp {
        }
 
        public class UIntLiteral : UIntConstant {
-               public UIntLiteral (uint l) : base (l)
+               public UIntLiteral (uint l, Location loc) : base (l, loc)
                {
                }
 
@@ -157,7 +191,7 @@ namespace Mono.CSharp {
        }
        
        public class LongLiteral : LongConstant {
-               public LongLiteral (long l) : base (l)
+               public LongLiteral (long l, Location loc) : base (l, loc)
                {
                }
 
@@ -170,7 +204,7 @@ namespace Mono.CSharp {
        }
 
        public class ULongLiteral : ULongConstant {
-               public ULongLiteral (ulong l) : base (l)
+               public ULongLiteral (ulong l, Location loc) : base (l, loc)
                {
                }
 
@@ -183,7 +217,7 @@ namespace Mono.CSharp {
        
        public class FloatLiteral : FloatConstant {
                
-               public FloatLiteral (float f) : base (f)
+               public FloatLiteral (float f, Location loc) : base (f, loc)
                {
                }
 
@@ -195,7 +229,7 @@ namespace Mono.CSharp {
        }
 
        public class DoubleLiteral : DoubleConstant {
-               public DoubleLiteral (double d) : base (d)
+               public DoubleLiteral (double d, Location loc) : base (d, loc)
                {
                }
 
@@ -208,7 +242,7 @@ namespace Mono.CSharp {
        }
 
        public class DecimalLiteral : DecimalConstant {
-               public DecimalLiteral (decimal d) : base (d)
+               public DecimalLiteral (decimal d, Location loc) : base (d, loc)
                {
                }
 
@@ -220,7 +254,7 @@ namespace Mono.CSharp {
        }
 
        public class StringLiteral : StringConstant {
-               public StringLiteral (string s) : base (s)
+               public StringLiteral (string s, Location loc) : base (s, loc)
                {
                }