Nothing to see here
[mono.git] / mcs / mcs / literal.cs
index 1735670d0d3d1cbe522e300814fa563b8ac8a201..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
@@ -40,6 +40,13 @@ namespace Mono.CSharp {
                {
                        return GetSignatureForError ();
                }
+               
+               public override Expression CreateExpressionTree (EmitContext ec)
+               {
+                       // HACK: change type to be object
+                       type = TypeManager.object_type;
+                       return base.CreateExpressionTree (ec);
+               }               
 
                public override Expression DoResolve (EmitContext ec)
                {
@@ -74,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);
@@ -85,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;
@@ -100,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; }
                }
 
@@ -109,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;
                }
@@ -139,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);
                }
@@ -155,6 +171,10 @@ namespace Mono.CSharp {
                        type = TypeManager.bool_type;
                        return this;
                }
+
+               public override bool IsLiteral {
+                       get { return true; }
+               }
        }
 
        public class CharLiteral : CharConstant {
@@ -167,6 +187,10 @@ namespace Mono.CSharp {
                        type = TypeManager.char_type;
                        return this;
                }
+
+               public override bool IsLiteral {
+                       get { return true; }
+               }
        }
 
        public class IntLiteral : IntConstant {
@@ -195,6 +219,9 @@ namespace Mono.CSharp {
                        return base.ConvertImplicitly (type);
                }
 
+               public override bool IsLiteral {
+                       get { return true; }
+               }
        }
 
        public class UIntLiteral : UIntConstant {
@@ -207,6 +234,10 @@ namespace Mono.CSharp {
                        type = TypeManager.uint32_type;
                        return this;
                }
+
+               public override bool IsLiteral {
+                       get { return true; }
+               }
        }
        
        public class LongLiteral : LongConstant {
@@ -217,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 {
@@ -232,6 +266,10 @@ namespace Mono.CSharp {
                        type = TypeManager.uint64_type;
                        return this;
                }
+
+               public override bool IsLiteral {
+                       get { return true; }
+               }
        }
        
        public class FloatLiteral : FloatConstant {
@@ -245,6 +283,11 @@ namespace Mono.CSharp {
                        type = TypeManager.float_type;
                        return this;
                }
+
+               public override bool IsLiteral {
+                       get { return true; }
+               }
+
        }
 
        public class DoubleLiteral : DoubleConstant {
@@ -280,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 {
@@ -292,6 +340,10 @@ namespace Mono.CSharp {
                        type = TypeManager.decimal_type;
                        return this;
                }
+
+               public override bool IsLiteral {
+                       get { return true; }
+               }
        }
 
        public class StringLiteral : StringConstant {
@@ -305,5 +357,10 @@ namespace Mono.CSharp {
 
                        return this;
                }
+
+               public override bool IsLiteral {
+                       get { return true; }
+               }
+
        }
 }