2007-01-01 Miguel de Icaza <miguel@novell.com>
[mono.git] / mcs / mcs / literal.cs
index eb06c1fffa353f7cb86e1f748d210ddb5cbaf807..7bc25b31669673e0c2dd174bf89c8e84a8ea67f4 100644 (file)
@@ -94,7 +94,7 @@ namespace Mono.CSharp {
                        get { return true; }
                }
 
-               public override Constant Reduce(bool inCheckedContext, Type target_type)
+               public override Constant ConvertExplicitly(bool inCheckedContext, Type target_type)
                {
                        if (!TypeManager.IsValueType (target_type))
                                return new EmptyConstantCast (this, target_type);
@@ -102,7 +102,7 @@ namespace Mono.CSharp {
                        return null;
                }
 
-               public override Constant ToType(Type targetType)
+               public override Constant ConvertImplicitly (Type targetType)
                {
                        if (!TypeManager.IsValueType (targetType))
                                return new EmptyConstantCast (this, targetType);
@@ -121,9 +121,9 @@ namespace Mono.CSharp {
                {
                }
 
-               public override void Error_ValueCannotBeConverted (Location loc, Type target, bool expl)
+               public override void Error_ValueCannotBeConverted (EmitContext ec, Location loc, Type target, bool expl)
                {
-                       base.Error_ValueCannotBeConverted(loc, target, expl);
+                       base.Error_ValueCannotBeConverted (ec, loc, target, expl);
                }
        }
 
@@ -142,7 +142,7 @@ namespace Mono.CSharp {
                        return this;
                }
 
-               public override void Error_ValueCannotBeConverted (Location loc, Type t, bool expl)
+               public override void Error_ValueCannotBeConverted (EmitContext ec, Location loc, Type t, bool expl)
                {
                        if (TypeManager.IsGenericParameter (t)) {
                                Report.Error(403, loc,
@@ -154,7 +154,7 @@ namespace Mono.CSharp {
                        }
                }
 
-               public override Constant ToType (Type targetType)
+               public override Constant ConvertImplicitly (Type targetType)
                {
                        if (targetType.IsPointer)
                                return new EmptyConstantCast (NullPointer.Null, targetType);
@@ -168,11 +168,11 @@ namespace Mono.CSharp {
                                if (gc != null && gc.IsReferenceType)
                                        return new EmptyConstantCast (this, targetType);
 
-                               Error_ValueCannotBeConverted (loc, targetType, false);
+                               Error_ValueCannotBeConverted (null, loc, targetType, false);
                                return null;
                        }
 
-                       return base.ToType(targetType);
+                       return base.ConvertImplicitly(targetType);
                }
 
        }
@@ -238,6 +238,22 @@ namespace Mono.CSharp {
                        type = TypeManager.int32_type;
                        return this;
                }
+
+               public override Constant ConvertImplicitly (Type type)
+               {
+                       ///
+                       /// The 0 literal can be converted to an enum value,
+                       ///
+                       if (Value == 0 && TypeManager.IsEnumType (type)) {
+                               Constant c = ConvertImplicitly (TypeManager.EnumToUnderlying (type));
+                               if (c == null)
+                                       return null;
+
+                               return new EnumConstant (c, type);
+                       }
+                       return base.ConvertImplicitly (type);
+               }
+
        }
 
        public class UIntLiteral : UIntConstant {
@@ -302,7 +318,7 @@ namespace Mono.CSharp {
                        return this;
                }
 
-               public override void Error_ValueCannotBeConverted (Location loc, Type target, bool expl)
+               public override void Error_ValueCannotBeConverted (EmitContext ec, Location loc, Type target, bool expl)
                {
                        if (target == TypeManager.float_type) {
                                Error_664 (loc, "float", "f");
@@ -314,7 +330,7 @@ namespace Mono.CSharp {
                                return;
                        }
 
-                       base.Error_ValueCannotBeConverted (loc, target, expl);
+                       base.Error_ValueCannotBeConverted (ec, loc, target, expl);
                }
 
                static void Error_664 (Location loc, string type, string suffix)