Check whether parent struct field is assigned when assigning to child field. Fixes...
[mono.git] / mcs / mcs / literal.cs
index fbf7188a7384012ba5a048737863470d891a68fa..b2efb35c1a95d74106eca17124da57f0bdd9f5a0 100644 (file)
@@ -25,7 +25,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
@@ -38,7 +45,7 @@ namespace Mono.CSharp {
                // Default type of null is an object
                //
                public NullLiteral (Location loc)
-                       : base (InternalType.Null, loc)
+                       : base (InternalType.NullLiteral, loc)
                {
                }
 
@@ -51,7 +58,7 @@ 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));
                                return;
@@ -60,6 +67,11 @@ namespace Mono.CSharp {
                        base.Error_ValueCannotBeConverted (ec, loc, t, expl);
                }
 
+               public override string GetValueAsLiteral ()
+               {
+                       return "null";
+               }
+
                public override bool IsLiteral {
                        get { return true; }
                }
@@ -70,105 +82,122 @@ namespace Mono.CSharp {
                }
        }
 
-       //
-       // A null literal in a pointer context
-       //
-       class NullPointer : NullLiteral {
-               public NullPointer (Location loc):
-                       base (loc)
-               {
-                       type = TypeManager.object_type;
-               }
-
-               public override void Emit (EmitContext ec)
-               {
-                       //
-                       // Emits null pointer
-                       //
-                       ec.Emit (OpCodes.Ldc_I4_0);
-                       ec.Emit (OpCodes.Conv_U);
-               }
-       }
-
-       public class BoolLiteral : BoolConstant {
-               public BoolLiteral (bool val, Location loc) : base (val, loc)
+       public class BoolLiteral : BoolConstant, ILiteralConstant
+       {
+               public BoolLiteral (BuiltinTypes types, bool val, Location loc)
+                       : base (types, val, loc)
                {
                }
 
                public override bool IsLiteral {
                        get { return true; }
                }
+
+#if FULL_AST
+               char[] ILiteralConstant.ParsedValue { get; set; }
+#endif
        }
 
-       public class CharLiteral : CharConstant {
-               public CharLiteral (char c, Location loc) : base (c, loc)
+       public class CharLiteral : CharConstant, ILiteralConstant
+       {
+               public CharLiteral (BuiltinTypes types, char c, Location loc)
+                       : base (types, c, loc)
                {
                }
 
                public override bool IsLiteral {
                        get { return true; }
                }
+
+#if FULL_AST
+               char[] ILiteralConstant.ParsedValue { get; set; }
+#endif
        }
 
-       public class IntLiteral : IntConstant {
-               public IntLiteral (int l, Location loc) : base (l, loc)
+       public class IntLiteral : IntConstant, ILiteralConstant
+       {
+               public IntLiteral (BuiltinTypes types, int l, Location loc)
+                       : base (types, l, loc)
                {
                }
 
-               public override Constant ConvertImplicitly (ResolveContext rc, TypeSpec type)
+               public override Constant ConvertImplicitly (TypeSpec type)
                {
                        //
                        // The 0 literal can be converted to an enum value
                        //
                        if (Value == 0 && TypeManager.IsEnumType (type)) {
-                               Constant c = ConvertImplicitly (rc, EnumSpec.GetUnderlyingType (type));
+                               Constant c = ConvertImplicitly (EnumSpec.GetUnderlyingType (type));
                                if (c == null)
                                        return null;
 
-                               return new EnumConstant (c, type).Resolve (rc);
+                               return new EnumConstant (c, type);
                        }
 
-                       return base.ConvertImplicitly (rc, type);
+                       return base.ConvertImplicitly (type);
                }
 
                public override bool IsLiteral {
                        get { return true; }
                }
+
+#if FULL_AST
+               char[] ILiteralConstant.ParsedValue { get; set; }
+#endif
        }
 
-       public class UIntLiteral : UIntConstant {
-               public UIntLiteral (uint l, Location loc) : base (l, loc)
+       public class UIntLiteral : UIntConstant, ILiteralConstant
+       {
+               public UIntLiteral (BuiltinTypes types, uint l, Location loc)
+                       : base (types, l, loc)
                {
                }
 
                public override bool IsLiteral {
                        get { return true; }
                }
+
+#if FULL_AST
+               char[] ILiteralConstant.ParsedValue { get; set; }
+#endif
        }
-       
-       public class LongLiteral : LongConstant {
-               public LongLiteral (long l, Location loc) : base (l, loc)
+
+       public class LongLiteral : LongConstant, ILiteralConstant
+       {
+               public LongLiteral (BuiltinTypes types, long l, Location loc)
+                       : base (types, l, loc)
                {
                }
 
                public override bool IsLiteral {
                        get { return true; }
                }
+
+#if FULL_AST
+               char[] ILiteralConstant.ParsedValue { get; set; }
+#endif
        }
 
-       public class ULongLiteral : ULongConstant {
-               public ULongLiteral (ulong l, Location loc) : base (l, loc)
+       public class ULongLiteral : ULongConstant, ILiteralConstant
+       {
+               public ULongLiteral (BuiltinTypes types, ulong l, Location loc)
+                       : base (types, l, loc)
                {
                }
 
                public override bool IsLiteral {
                        get { return true; }
                }
+
+#if FULL_AST
+               char[] ILiteralConstant.ParsedValue { get; set; }
+#endif
        }
-       
-       public class FloatLiteral : FloatConstant {
-               
-               public FloatLiteral (float f, Location loc) : base (f, loc)
+
+       public class FloatLiteral : FloatConstant, ILiteralConstant
+       {
+               public FloatLiteral (BuiltinTypes types, float f, Location loc)
+                       : base (types, f, loc)
                {
                }
 
@@ -176,21 +205,26 @@ namespace Mono.CSharp {
                        get { return true; }
                }
 
+#if FULL_AST
+               char[] ILiteralConstant.ParsedValue { get; set; }
+#endif
        }
 
-       public class DoubleLiteral : DoubleConstant {
-               public DoubleLiteral (double d, Location loc) : base (d, loc)
+       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)
                {
-                       if (target == TypeManager.float_type) {
+                       if (target.BuiltinType == BuiltinTypeSpec.Type.Float) {
                                Error_664 (ec, loc, "float", "f");
                                return;
                        }
 
-                       if (target == TypeManager.decimal_type) {
+                       if (target.BuiltinType == BuiltinTypeSpec.Type.Decimal) {
                                Error_664 (ec, loc, "decimal", "m");
                                return;
                        }
@@ -209,20 +243,31 @@ namespace Mono.CSharp {
                        get { return true; }
                }
 
+#if FULL_AST
+               char[] ILiteralConstant.ParsedValue { get; set; }
+#endif
        }
 
-       public class DecimalLiteral : DecimalConstant {
-               public DecimalLiteral (decimal d, Location loc) : base (d, loc)
+       public class DecimalLiteral : DecimalConstant, ILiteralConstant
+       {
+               public DecimalLiteral (BuiltinTypes types, decimal d, Location loc)
+                       : base (types, d, loc)
                {
                }
 
                public override bool IsLiteral {
                        get { return true; }
                }
+
+#if FULL_AST
+               char[] ILiteralConstant.ParsedValue { get; set; }
+#endif
        }
 
-       public class StringLiteral : StringConstant {
-               public StringLiteral (string s, Location loc) : base (s, loc)
+       public class StringLiteral : StringConstant, ILiteralConstant
+       {
+               public StringLiteral (BuiltinTypes types, string s, Location loc)
+                       : base (types, s, loc)
                {
                }
 
@@ -230,5 +275,8 @@ namespace Mono.CSharp {
                        get { return true; }
                }
 
+#if FULL_AST
+               char[] ILiteralConstant.ParsedValue { get; set; }
+#endif
        }
 }