Nothing to see here
[mono.git] / mcs / mcs / literal.cs
index 4e2ffed15a054a734874545041ca7b3c896dd0e1..77a8832036946b54ccc16c86ed652b6eb23c8ee8 100644 (file)
@@ -5,7 +5,7 @@
 //   Miguel de Icaza (miguel@ximian.com)
 //   Marek Safar (marek.safar@seznam.cz)
 //
-// (C) 2001 Ximian, Inc.
+// Copyright 2001 Ximian, Inc.
 //
 //
 // Notice that during parsing we create objects of type Literal, but the
@@ -43,6 +43,7 @@ namespace Mono.CSharp {
                
                public override Expression CreateExpressionTree (EmitContext ec)
                {
+                       // HACK: change type to be object
                        type = TypeManager.object_type;
                        return base.CreateExpressionTree (ec);
                }               
@@ -80,10 +81,14 @@ namespace Mono.CSharp {
                        }
                }
 
-               public override Constant ConvertImplicitly (Type targetType)
+               public override Constant ConvertExplicitly (bool inCheckedContext, Type targetType)
                {
                        if (targetType.IsPointer)
-                               return new EmptyConstantCast (NullPointer.Null, targetType);
+                               return new EmptyConstantCast (new NullPointer (loc), targetType);
+
+                       // Exlude internal compiler types
+                       if (targetType == TypeManager.anonymous_method_type)
+                               return null;
 
                        if (TypeManager.IsReferenceType (targetType))
                                return new EmptyConstantCast (this, targetType);
@@ -91,6 +96,17 @@ namespace Mono.CSharp {
                        return null;
                }
 
+               public override Constant ConvertImplicitly (Type targetType)
+               {
+                       //
+                       // Null literal is of object type
+                       //
+                       if (targetType == TypeManager.object_type)
+                               return this;
+
+                       return ConvertExplicitly (false, targetType);
+               }
+
                public override object GetValue ()
                {
                        return null;
@@ -106,8 +122,11 @@ namespace Mono.CSharp {
                        get { return true; }
                }
 
-               public override bool IsNegative 
-               {
+               public override bool IsLiteral {
+                       get { return true; }
+               }
+
+               public override bool IsNegative {
                        get { return false; }
                }
 
@@ -115,28 +134,17 @@ namespace Mono.CSharp {
                        get { return true; }
                }
 
-               public override bool IsZeroInteger 
-               {
+               public override bool IsZeroInteger {
                        get { return true; }
                }
-
-               public override Constant ConvertExplicitly(bool inCheckedContext, Type target_type)
-               {
-                       if (!TypeManager.IsValueType (target_type))
-                               return new EmptyConstantCast (this, target_type);
-
-                       return null;
-               }
        }
 
        //
        // A null literal in a pointer context
        //
        public class NullPointer : NullLiteral {
-               public static readonly NullLiteral Null = new NullPointer ();
-
-               private NullPointer ():
-                       base (Location.Null)
+               public NullPointer (Location loc):
+                       base (loc)
                {
                        type = TypeManager.object_type;
                }
@@ -145,7 +153,9 @@ namespace Mono.CSharp {
                {
                        ILGenerator ig = ec.ig;
                                
-                       // TODO: why not use Ldnull instead ?
+                       //
+                       // Emits null pointer
+                       //
                        ig.Emit (OpCodes.Ldc_I4_0);
                        ig.Emit (OpCodes.Conv_U);
                }
@@ -161,6 +171,10 @@ namespace Mono.CSharp {
                        type = TypeManager.bool_type;
                        return this;
                }
+
+               public override bool IsLiteral {
+                       get { return true; }
+               }
        }
 
        public class CharLiteral : CharConstant {
@@ -173,6 +187,10 @@ namespace Mono.CSharp {
                        type = TypeManager.char_type;
                        return this;
                }
+
+               public override bool IsLiteral {
+                       get { return true; }
+               }
        }
 
        public class IntLiteral : IntConstant {
@@ -201,6 +219,9 @@ namespace Mono.CSharp {
                        return base.ConvertImplicitly (type);
                }
 
+               public override bool IsLiteral {
+                       get { return true; }
+               }
        }
 
        public class UIntLiteral : UIntConstant {
@@ -213,6 +234,10 @@ namespace Mono.CSharp {
                        type = TypeManager.uint32_type;
                        return this;
                }
+
+               public override bool IsLiteral {
+                       get { return true; }
+               }
        }
        
        public class LongLiteral : LongConstant {
@@ -223,9 +248,12 @@ namespace Mono.CSharp {
                public override Expression DoResolve (EmitContext ec)
                {
                        type = TypeManager.int64_type;
-
                        return this;
                }
+
+               public override bool IsLiteral {
+                       get { return true; }
+               }
        }
 
        public class ULongLiteral : ULongConstant {
@@ -238,6 +266,10 @@ namespace Mono.CSharp {
                        type = TypeManager.uint64_type;
                        return this;
                }
+
+               public override bool IsLiteral {
+                       get { return true; }
+               }
        }
        
        public class FloatLiteral : FloatConstant {
@@ -251,6 +283,11 @@ namespace Mono.CSharp {
                        type = TypeManager.float_type;
                        return this;
                }
+
+               public override bool IsLiteral {
+                       get { return true; }
+               }
+
        }
 
        public class DoubleLiteral : DoubleConstant {
@@ -286,6 +323,11 @@ namespace Mono.CSharp {
                                "Literal of type double cannot be implicitly converted to type `{0}'. Add suffix `{1}' to create a literal of this type",
                                type, suffix);
                }
+
+               public override bool IsLiteral {
+                       get { return true; }
+               }
+
        }
 
        public class DecimalLiteral : DecimalConstant {
@@ -298,6 +340,10 @@ namespace Mono.CSharp {
                        type = TypeManager.decimal_type;
                        return this;
                }
+
+               public override bool IsLiteral {
+                       get { return true; }
+               }
        }
 
        public class StringLiteral : StringConstant {
@@ -311,5 +357,10 @@ namespace Mono.CSharp {
 
                        return this;
                }
+
+               public override bool IsLiteral {
+                       get { return true; }
+               }
+
        }
 }