2005-05-31 Sebastien Pouliot <sebastien@ximian.com>
[mono.git] / mcs / mcs / literal.cs
old mode 100755 (executable)
new mode 100644 (file)
index 2faebb5..42762cb
@@ -22,11 +22,33 @@ using System;
 using System.Reflection;
 using System.Reflection.Emit;
 
+//
+// I put System.Null just so we do not have to special case it on 
+// TypeManager.CSharpName
+//
+namespace System {
+       //
+       // Represents the Null Type, just used as a placeholder for the type in NullLiteral
+       //
+       public class Null {
+       }
+}
+       
 namespace Mono.CSharp {
 
+       //
+       // The NullType just exists to compare type equality, and for
+       // expressions that might have the `null type'
+       //
+       public class NullType {
+       }
+
+       //
+       // The null Literal constant
+       //
        public class NullLiteral : Constant {
                public static readonly NullLiteral Null;
-               
+
                static NullLiteral ()
                {
                        Null = new NullLiteral ();
@@ -34,8 +56,6 @@ namespace Mono.CSharp {
                        
                public NullLiteral ()
                {
-                       if (Null != null)
-                               throw new Exception ("More than one null has been created!");
                        eclass = ExprClass.Value;
                }
                
@@ -51,7 +71,7 @@ namespace Mono.CSharp {
 
                public override Expression DoResolve (EmitContext ec)
                {
-                       type = TypeManager.object_type;
+                       type = TypeManager.null_type;
                        return this;
                }
 
@@ -59,6 +79,47 @@ namespace Mono.CSharp {
                {
                        ec.ig.Emit (OpCodes.Ldnull);
                }
+
+               public override bool IsDefaultValue {
+                       get {
+                               return true;
+                       }
+               }
+
+               public override bool IsNegative {
+                       get {
+                               return false;
+                       }
+               }
+
+               public override bool IsZeroInteger {
+                       get { return true; }
+               }
+       }
+
+       //
+       // A null literal in a pointer context
+       //
+       public class NullPointer : NullLiteral {
+               public new static readonly NullLiteral Null;
+
+               static NullPointer ()
+               {
+                       Null = new NullPointer ();
+               }
+
+               private NullPointer ()
+               {
+                       type = TypeManager.object_type;
+               }
+
+               public override void Emit (EmitContext ec)
+               {
+                       ILGenerator ig = ec.ig;
+                               
+                       ig.Emit (OpCodes.Ldc_I4_0);
+                       ig.Emit (OpCodes.Conv_U);
+               }
        }
 
        public class BoolLiteral : BoolConstant {
@@ -86,6 +147,14 @@ 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)
                {
                }
@@ -170,11 +239,6 @@ namespace Mono.CSharp {
                        type = TypeManager.decimal_type;
                        return this;
                }
-
-               public override void Emit (EmitContext ec)
-               {
-                       throw new Exception ("Implement me");
-               }
        }
 
        public class StringLiteral : StringConstant {