Initial set of Ward sgen annotations (#5705)
[mono.git] / mcs / mcs / literal.cs
index cf48e07cc2838e06ab4e5a9d72280a8daf6a1533..1af2d0c9e379ecb600379156bfe84dbf1ab67bb9 100644 (file)
@@ -6,6 +6,7 @@
 //   Marek Safar (marek.safar@seznam.cz)
 //
 // Copyright 2001 Ximian, Inc.
+// Copyright 2011 Xamarin Inc
 //
 //
 // Notice that during parsing we create objects of type Literal, but the
@@ -25,7 +26,14 @@ using IKVM.Reflection.Emit;
 using System.Reflection.Emit;
 #endif
 
-namespace Mono.CSharp {
+namespace Mono.CSharp
+{
+       public interface ILiteralConstant
+       {
+#if FULL_AST
+               char[] ParsedValue { get; set; }
+#endif
+       }
 
        //
        // The null literal
@@ -42,7 +50,7 @@ namespace Mono.CSharp {
                {
                }
 
-               public override void Error_ValueCannotBeConverted (ResolveContext ec, Location loc, TypeSpec t, bool expl)
+               public override void Error_ValueCannotBeConverted (ResolveContext ec, TypeSpec t, bool expl)
                {
                        if (t.IsGenericParameter) {
                                ec.Report.Error(403, loc,
@@ -51,13 +59,13 @@ namespace Mono.CSharp {
                                return;
                        }
 
-                       if (TypeManager.IsValueType (t)) {
+                       if (TypeSpec.IsValueType (t)) {
                                ec.Report.Error(37, loc, "Cannot convert null to `{0}' because it is a value type",
-                                       TypeManager.CSharpName(t));
+                                       t.GetSignatureForError ());
                                return;
                        }
 
-                       base.Error_ValueCannotBeConverted (ec, loc, t, expl);
+                       base.Error_ValueCannotBeConverted (ec, t, expl);
                }
 
                public override string GetValueAsLiteral ()
@@ -75,7 +83,8 @@ namespace Mono.CSharp {
                }
        }
 
-       public class BoolLiteral : BoolConstant {
+       public class BoolLiteral : BoolConstant, ILiteralConstant
+       {
                public BoolLiteral (BuiltinTypes types, bool val, Location loc)
                        : base (types, val, loc)
                {
@@ -84,9 +93,19 @@ namespace Mono.CSharp {
                public override bool IsLiteral {
                        get { return true; }
                }
+
+#if FULL_AST
+               public char[] ParsedValue { get; set; }
+#endif
+
+               public override object Accept (StructuralVisitor visitor)
+               {
+                       return visitor.Visit (this);
+               }
        }
 
-       public class CharLiteral : CharConstant {
+       public class CharLiteral : CharConstant, ILiteralConstant
+       {
                public CharLiteral (BuiltinTypes types, char c, Location loc)
                        : base (types, c, loc)
                {
@@ -95,9 +114,19 @@ namespace Mono.CSharp {
                public override bool IsLiteral {
                        get { return true; }
                }
+
+#if FULL_AST
+               public char[] ParsedValue { get; set; }
+#endif
+
+               public override object Accept (StructuralVisitor visitor)
+               {
+                       return visitor.Visit (this);
+               }
        }
 
-       public class IntLiteral : IntConstant {
+       public class IntLiteral : IntConstant, ILiteralConstant
+       {
                public IntLiteral (BuiltinTypes types, int l, Location loc)
                        : base (types, l, loc)
                {
@@ -108,7 +137,7 @@ namespace Mono.CSharp {
                        //
                        // The 0 literal can be converted to an enum value
                        //
-                       if (Value == 0 && TypeManager.IsEnumType (type)) {
+                       if (Value == 0 && type.IsEnum) {
                                Constant c = ConvertImplicitly (EnumSpec.GetUnderlyingType (type));
                                if (c == null)
                                        return null;
@@ -122,9 +151,19 @@ namespace Mono.CSharp {
                public override bool IsLiteral {
                        get { return true; }
                }
+
+#if FULL_AST
+               public char[] ParsedValue { get; set; }
+#endif
+
+               public override object Accept (StructuralVisitor visitor)
+               {
+                       return visitor.Visit (this);
+               }
        }
 
-       public class UIntLiteral : UIntConstant {
+       public class UIntLiteral : UIntConstant, ILiteralConstant
+       {
                public UIntLiteral (BuiltinTypes types, uint l, Location loc)
                        : base (types, l, loc)
                {
@@ -133,9 +172,19 @@ namespace Mono.CSharp {
                public override bool IsLiteral {
                        get { return true; }
                }
+
+#if FULL_AST
+               public char[] ParsedValue { get; set; }
+#endif
+
+               public override object Accept (StructuralVisitor visitor)
+               {
+                       return visitor.Visit (this);
+               }
        }
-       
-       public class LongLiteral : LongConstant {
+
+       public class LongLiteral : LongConstant, ILiteralConstant
+       {
                public LongLiteral (BuiltinTypes types, long l, Location loc)
                        : base (types, l, loc)
                {
@@ -144,9 +193,19 @@ namespace Mono.CSharp {
                public override bool IsLiteral {
                        get { return true; }
                }
+
+#if FULL_AST
+               public char[] ParsedValue { get; set; }
+#endif
+
+               public override object Accept (StructuralVisitor visitor)
+               {
+                       return visitor.Visit (this);
+               }
        }
 
-       public class ULongLiteral : ULongConstant {
+       public class ULongLiteral : ULongConstant, ILiteralConstant
+       {
                public ULongLiteral (BuiltinTypes types, ulong l, Location loc)
                        : base (types, l, loc)
                {
@@ -155,10 +214,19 @@ namespace Mono.CSharp {
                public override bool IsLiteral {
                        get { return true; }
                }
+
+#if FULL_AST
+               public char[] ParsedValue { get; set; }
+#endif
+
+               public override object Accept (StructuralVisitor visitor)
+               {
+                       return visitor.Visit (this);
+               }
        }
-       
-       public class FloatLiteral : FloatConstant {
 
+       public class FloatLiteral : FloatConstant, ILiteralConstant
+       {
                public FloatLiteral (BuiltinTypes types, float f, Location loc)
                        : base (types, f, loc)
                {
@@ -168,15 +236,24 @@ namespace Mono.CSharp {
                        get { return true; }
                }
 
+#if FULL_AST
+               public char[] ParsedValue { get; set; }
+#endif
+
+               public override object Accept (StructuralVisitor visitor)
+               {
+                       return visitor.Visit (this);
+               }
        }
 
-       public class DoubleLiteral : DoubleConstant {
+       public class DoubleLiteral : DoubleConstant, ILiteralConstant
+       {
                public DoubleLiteral (BuiltinTypes types, double d, Location loc)
                        : base (types, d, loc)
                {
                }
 
-               public override void Error_ValueCannotBeConverted (ResolveContext ec, Location loc, TypeSpec target, bool expl)
+               public override void Error_ValueCannotBeConverted (ResolveContext ec, TypeSpec target, bool expl)
                {
                        if (target.BuiltinType == BuiltinTypeSpec.Type.Float) {
                                Error_664 (ec, loc, "float", "f");
@@ -188,7 +265,7 @@ namespace Mono.CSharp {
                                return;
                        }
 
-                       base.Error_ValueCannotBeConverted (ec, loc, target, expl);
+                       base.Error_ValueCannotBeConverted (ec, target, expl);
                }
 
                static void Error_664 (ResolveContext ec, Location loc, string type, string suffix)
@@ -202,9 +279,18 @@ namespace Mono.CSharp {
                        get { return true; }
                }
 
+#if FULL_AST
+               public char[] ParsedValue { get; set; }
+#endif
+
+               public override object Accept (StructuralVisitor visitor)
+               {
+                       return visitor.Visit (this);
+               }
        }
 
-       public class DecimalLiteral : DecimalConstant {
+       public class DecimalLiteral : DecimalConstant, ILiteralConstant
+       {
                public DecimalLiteral (BuiltinTypes types, decimal d, Location loc)
                        : base (types, d, loc)
                {
@@ -213,9 +299,19 @@ namespace Mono.CSharp {
                public override bool IsLiteral {
                        get { return true; }
                }
+
+#if FULL_AST
+               public char[] ParsedValue { get; set; }
+#endif
+
+               public override object Accept (StructuralVisitor visitor)
+               {
+                       return visitor.Visit (this);
+               }
        }
 
-       public class StringLiteral : StringConstant {
+       public class StringLiteral : StringConstant, ILiteralConstant
+       {
                public StringLiteral (BuiltinTypes types, string s, Location loc)
                        : base (types, s, loc)
                {
@@ -225,5 +321,13 @@ namespace Mono.CSharp {
                        get { return true; }
                }
 
+#if FULL_AST
+               public char[] ParsedValue { get; set; }
+#endif
+
+               public override object Accept (StructuralVisitor visitor)
+               {
+                       return visitor.Visit (this);
+               }
        }
 }