Make all evaluator created type public
[mono.git] / mcs / mcs / constant.cs
index 7d6fe944def7e9416b31d630b521c3cf83bc30c0..81d2c9604c33482226971554f6c8f736937bc64d 100644 (file)
@@ -29,19 +29,9 @@ namespace Mono.CSharp {
                        this.loc = loc;
                }
 
-               /// <remarks>
-               ///   This is different from ToString in that ToString
-               ///   is supposed to be there for debugging purposes,
-               ///   and is not guaranteed to be useful for anything else,
-               ///   AsString() will provide something that can be used
-               ///   for round-tripping C# code.  Maybe it can be used
-               ///   for IL assembly as well.
-               /// </remarks>
-               public abstract string AsString ();
-
                override public string ToString ()
                {
-                       return this.GetType ().Name + " (" + AsString () + ")";
+                       return this.GetType ().Name + " (" + GetValueAsLiteral () + ")";
                }
 
                /// <summary>
@@ -50,6 +40,8 @@ namespace Mono.CSharp {
                /// </summary>
                public abstract object GetValue ();
 
+               public abstract string GetValueAsLiteral ();
+
 #if !STATIC
                //
                // Returns an object value which is typed to contant type
@@ -66,7 +58,7 @@ namespace Mono.CSharp {
                                (TypeManager.IsPrimitiveType (target) || type == TypeManager.decimal_type) &&
                                (TypeManager.IsPrimitiveType (type) || type == TypeManager.decimal_type)) {
                                ec.Report.Error (31, loc, "Constant value `{0}' cannot be converted to a `{1}'",
-                                       AsString (), TypeManager.CSharpName (target));
+                                       GetValueAsLiteral (), TypeManager.CSharpName (target));
                        } else {
                                base.Error_ValueCannotBeConverted (ec, loc, target, expl);
                        }
@@ -183,9 +175,10 @@ namespace Mono.CSharp {
                                return TryReduce (ec, target_type);
                        }
                        catch (OverflowException) {
-                               if (ec.ConstantCheckState) {                            
-                                       ec.Report.Error (221, loc, "Constant value `{0}' cannot be converted to a `{1}' (use `unchecked' syntax to override)",
-                                               GetValue ().ToString (), TypeManager.CSharpName (target_type));
+                               if (ec.ConstantCheckState && Type.BuildinType != BuildinTypeSpec.Type.Decimal) {
+                                       ec.Report.Error (221, loc,
+                                               "Constant value `{0}' cannot be converted to a `{1}' (use `unchecked' syntax to override)",
+                                               GetValueAsLiteral (), target_type.GetSignatureForError ());
                                } else {
                                        Error_ValueCannotBeConverted (ec, loc, target_type, false);
                                }
@@ -320,6 +313,11 @@ namespace Mono.CSharp {
                                        GetValue ().ToString (), TypeManager.CSharpName (target));
                        }
                }
+
+               public override string GetValueAsLiteral ()
+               {
+                       return GetValue ().ToString ();
+               }
                
                public abstract Constant Increment ();
        }
@@ -333,11 +331,6 @@ namespace Mono.CSharp {
                        Value = val;
                }
 
-               override public string AsString ()
-               {
-                       return Value ? "true" : "false";
-               }
-
                protected override Expression DoResolve (ResolveContext ec)
                {
                        type = TypeManager.bool_type;
@@ -350,6 +343,11 @@ namespace Mono.CSharp {
                        return (object) Value;
                }
 
+               public override string GetValueAsLiteral ()
+               {
+                       return Value ? "true" : "false";
+               }
+
                public override void EncodeAttributeValue (IMemberContext rc, AttributeEncoder enc, TypeSpec targetType)
                {
                        enc.Encode (Value);
@@ -405,11 +403,6 @@ namespace Mono.CSharp {
                        ec.EmitInt (Value);
                }
 
-               public override string AsString ()
-               {
-                       return Value.ToString ();
-               }
-
                protected override Expression DoResolve (ResolveContext ec)
                {
                        type = TypeManager.byte_type;
@@ -539,14 +532,14 @@ namespace Mono.CSharp {
                        return c.ToString ();
                }
 
-               public override string AsString ()
+               public override object GetValue ()
                {
-                       return "\"" + descape (Value) + "\"";
+                       return Value;
                }
 
-               public override object GetValue ()
+               public override string GetValueAsLiteral ()
                {
-                       return Value;
+                       return "\"" + descape (Value) + "\"";
                }
 
                public override bool IsDefaultValue {
@@ -634,11 +627,6 @@ namespace Mono.CSharp {
                        ec.EmitInt (Value);
                }
 
-               public override string AsString ()
-               {
-                       return Value.ToString ();
-               }
-
                public override object GetValue ()
                {
                        return Value;
@@ -740,11 +728,6 @@ namespace Mono.CSharp {
                        ec.EmitInt (Value);
                }
 
-               public override string AsString ()
-               {
-                       return Value.ToString ();
-               }
-
                public override object GetValue ()
                {
                        return Value;
@@ -858,11 +841,6 @@ namespace Mono.CSharp {
                        ec.EmitInt (Value);
                }
 
-               public override string AsString ()
-               {
-                       return Value.ToString ();
-               }
-
                public override object GetValue ()
                {
                        return Value;
@@ -970,11 +948,6 @@ namespace Mono.CSharp {
                        ec.EmitInt (Value);
                }
 
-               public override string AsString ()
-               {
-                       return Value.ToString ();
-               }
-
                public override object GetValue ()
                {
                        return Value;
@@ -1151,11 +1124,6 @@ namespace Mono.CSharp {
                        ec.EmitInt (unchecked ((int) Value));
                }
 
-               public override string AsString ()
-               {
-                       return Value.ToString ();
-               }
-
                public override object GetValue ()
                {
                        return Value;
@@ -1192,7 +1160,7 @@ namespace Mono.CSharp {
                {
                        if (target_type == TypeManager.byte_type) {
                                if (in_checked_context){
-                                       if (Value < Char.MinValue || Value > Char.MaxValue)
+                                       if (Value < 0 || Value > byte.MaxValue)
                                                throw new OverflowException ();
                                }
                                return new ByteConstant ((byte) Value, Location);
@@ -1274,11 +1242,6 @@ namespace Mono.CSharp {
                        ec.EmitLong (Value);
                }
 
-               public override string AsString ()
-               {
-                       return Value.ToString ();
-               }
-
                public override object GetValue ()
                {
                        return Value;
@@ -1413,11 +1376,6 @@ namespace Mono.CSharp {
                        ec.EmitLong (unchecked ((long) Value));
                }
 
-               public override string AsString ()
-               {
-                       return Value.ToString ();
-               }
-
                public override object GetValue ()
                {
                        return Value;
@@ -1530,14 +1488,14 @@ namespace Mono.CSharp {
                        ec.Emit (OpCodes.Ldc_R4, Value);
                }
 
-               public override string AsString ()
+               public override object GetValue ()
                {
-                       return Value.ToString ();
+                       return Value;
                }
 
-               public override object GetValue ()
+               public override string GetValueAsLiteral ()
                {
-                       return Value;
+                       return Value.ToString ();
                }
 
                public override bool IsDefaultValue {
@@ -1653,14 +1611,14 @@ namespace Mono.CSharp {
                        ec.Emit (OpCodes.Ldc_R8, Value);
                }
 
-               public override string AsString ()
+               public override object GetValue ()
                {
-                       return Value.ToString ();
+                       return Value;
                }
 
-               public override object GetValue ()
+               public override string GetValueAsLiteral ()
                {
-                       return Value;
+                       return Value.ToString ();
                }
 
                public override bool IsDefaultValue {
@@ -1759,11 +1717,6 @@ namespace Mono.CSharp {
                        Value = d;
                }
 
-               override public string AsString ()
-               {
-                       return Value.ToString () + "M";
-               }
-
                protected override Expression DoResolve (ResolveContext rc)
                {
                        type = TypeManager.decimal_type;
@@ -1773,7 +1726,12 @@ namespace Mono.CSharp {
 
                public override object GetValue ()
                {
-                       return (object) Value;
+                       return Value;
+               }
+
+               public override string GetValueAsLiteral ()
+               {
+                       return Value.ToString () + "M";
                }
 
                public override void Emit (EmitContext ec)
@@ -1884,12 +1842,6 @@ namespace Mono.CSharp {
                        Value = s;
                }
 
-               // FIXME: Escape the string.
-               override public string AsString ()
-               {
-                       return "\"" + Value + "\"";
-               }
-
                protected override Expression DoResolve (ResolveContext rc)
                {
                        type = TypeManager.string_type;
@@ -1901,6 +1853,12 @@ namespace Mono.CSharp {
                {
                        return Value;
                }
+
+               public override string GetValueAsLiteral ()
+               {
+                       // FIXME: Escape the string.
+                       return "\"" + Value + "\"";
+               }
                
                public override void Emit (EmitContext ec)
                {
@@ -1971,11 +1929,6 @@ namespace Mono.CSharp {
                        this.type = type;
                }
 
-               public override string AsString ()
-               {
-                       return GetSignatureForError ();
-               }
-
                public override Expression CreateExpressionTree (ResolveContext ec)
                {
                        if (type == InternalType.Null || type == TypeManager.object_type) {
@@ -2025,11 +1978,6 @@ namespace Mono.CSharp {
                        }
                }
 
-               public override string GetSignatureForError ()
-               {
-                       return "null";
-               }
-
                public override Constant ConvertExplicitly (bool inCheckedContext, TypeSpec targetType)
                {
                        if (targetType.IsPointer) {
@@ -2060,11 +2008,21 @@ namespace Mono.CSharp {
                        return ConvertExplicitly (false, targetType);
                }
 
+               public override string GetSignatureForError ()
+               {
+                       return "null";
+               }
+
                public override object GetValue ()
                {
                        return null;
                }
 
+               public override string GetValueAsLiteral ()
+               {
+                       return GetSignatureForError ();
+               }
+
                public override bool IsDefaultValue {
                        get { return true; }
                }
@@ -2099,11 +2057,6 @@ namespace Mono.CSharp {
                        this.side_effect = side_effect;
                }
 
-               public override string AsString ()
-               {
-                       return value.AsString ();
-               }
-
                protected override Expression DoResolve (ResolveContext rc)
                {
                        value = value.Resolve (rc);
@@ -2118,6 +2071,11 @@ namespace Mono.CSharp {
                        return value.GetValue ();
                }
 
+               public override string GetValueAsLiteral ()
+               {
+                       return value.GetValueAsLiteral ();
+               }
+
                public override void Emit (EmitContext ec)
                {
                        side_effect.EmitSideEffect (ec);