manually synchronized with 56802
[mono.git] / mcs / gmcs / enum.cs
index b66ecb5e2888133f9f28bc336cadec1af2a2ee9c..1858d4c37273093625aaf6bb08064b318670b8fd 100644 (file)
@@ -16,7 +16,6 @@ using System.Collections.Specialized;
 using System.Reflection;
 using System.Reflection.Emit;
 using System.Globalization;
-using System.Xml;
 
 namespace Mono.CSharp {
 
@@ -32,14 +31,20 @@ namespace Mono.CSharp {
                Constant value;
                bool in_transit;
 
+               // TODO: remove or simplify
+               EmitContext ec;
+
                public EnumMember (Enum parent_enum, EnumMember prev_member, Expression expr,
                                MemberName name, Attributes attrs):
-                       base (parent_enum.Parent, name, attrs)
+                       base (parent_enum, name, attrs)
                {
                        this.parent_enum = parent_enum;
                        this.ModFlags = parent_enum.ModFlags;
                        this.ValueExpr = expr;
                        this.prev_member = prev_member;
+
+                       ec = new EmitContext (parent_enum, parent_enum, Location, null, null, ModFlags, false);
+                       ec.InEnumContext = true;
                }
 
                public override void ApplyAttributeBuilder (Attribute a, CustomAttributeBuilder cb)
@@ -49,8 +54,8 @@ namespace Mono.CSharp {
                                if (marshal != null) {
                                        builder.SetMarshal (marshal);
                                }
-                                       return;
-                               }
+                               return;
+                       }
 
                        if (a.Type.IsSubclassOf (TypeManager.security_attr_type)) {
                                a.Error_InvalidSecurityParent ();
@@ -79,6 +84,7 @@ namespace Mono.CSharp {
                        const FieldAttributes attr = FieldAttributes.Public | FieldAttributes.Static | FieldAttributes.Literal;
                        TypeBuilder tb = parent_enum.TypeBuilder;
                        builder = tb.DefineField (Name, tb, attr);
+                       ec.ContainerType = tb;
 
                        TypeManager.RegisterConstant (builder, this);
                        return true;
@@ -111,7 +117,7 @@ namespace Mono.CSharp {
 
                        if (ValueExpr != null) {
                                in_transit = true;
-                               Constant c = ValueExpr.ResolveAsConstant (parent_enum.EmitContext, this);
+                               Constant c = ValueExpr.ResolveAsConstant (ec, this);
                                in_transit = false;
 
                                if (c == null)
@@ -157,17 +163,16 @@ namespace Mono.CSharp {
                        return true;
                }
 
-               public bool Emit (EmitContext ec)
+               public override void Emit ()
                {
                        if (OptAttributes != null)
-                               OptAttributes.Emit (ec, this); 
+                               OptAttributes.Emit (); 
 
                        if (!ResolveValue ())
-                               return false;
+                               return;
 
                        builder.SetConstant (value.GetValue ());
-                       Emit ();
-                       return true;
+                       base.Emit ();
                }
 
                public override string GetSignatureForError()
@@ -244,9 +249,6 @@ namespace Mono.CSharp {
                        if (TypeBuilder != null)
                                return TypeBuilder;
 
-                       ec = new EmitContext (this, this, Location, null, null, ModFlags, false);
-                       ec.InEnumContext = true;
-
                        if (!(BaseType is TypeLookupExpression)) {
                                Report.Error (1008, Location,
                                        "Type byte, sbyte, short, ushort, int, uint, long or ulong expected");
@@ -286,8 +288,6 @@ namespace Mono.CSharp {
                                        Basename, TypeAttr, TypeManager.enum_type);
                        }
 
-                       ec.ContainerType = TypeBuilder;
-
                        //
                        // Call MapToInternalType for corlib
                        //
@@ -295,7 +295,7 @@ namespace Mono.CSharp {
                                                 FieldAttributes.Public | FieldAttributes.SpecialName
                                                 | FieldAttributes.RTSpecialName);
 
-                       TypeManager.AddUserType (Name, this);
+                       TypeManager.AddUserType (this);
 
                        foreach (EnumMember em in defined_names.Values) {
                                if (!em.Define ())
@@ -313,12 +313,11 @@ namespace Mono.CSharp {
                public override void Emit ()
                {
                        if (OptAttributes != null) {
-                               OptAttributes.Emit (ec, this);
+                               OptAttributes.Emit ();
                        }
 
                        foreach (EnumMember em in defined_names.Values) {
-                               if (!em.Emit (ec))
-                                       return;
+                               em.Emit ();
                        }
 
                        base.Emit ();
@@ -345,15 +344,16 @@ namespace Mono.CSharp {
                {
                        HybridDictionary dict = new HybridDictionary (defined_names.Count, true);
                        foreach (EnumMember em in defined_names.Values) {
-                               if (!em.IsClsComplianceRequired (this))
+                               if (!em.IsClsComplianceRequired ())
                                        continue;
 
                                try {
                                        dict.Add (em.Name, em);
                                }
                                catch (ArgumentException) {
-                                       Report.SymbolRelatedToPreviousError ((MemberCore)dict [em.Name]);
-                                       Report.Warning (3005, em.Location, "Identifier `{0}' differing only in case is not CLS-compliant", em.GetSignatureForError ());
+                                       Report.SymbolRelatedToPreviousError (em);
+                                       MemberCore col = (MemberCore)dict [em.Name];
+                                       Report.Warning (3005, 1, col.Location, "Identifier `{0}' differing only in case is not CLS-compliant", col.GetSignatureForError ());
                                }
                        }
                }
@@ -365,7 +365,9 @@ namespace Mono.CSharp {
 
                        VerifyClsName ();
 
-                       if (!AttributeTester.IsClsCompliant (UnderlyingType)) {
+                       if (UnderlyingType == TypeManager.uint32_type ||
+                               UnderlyingType == TypeManager.uint64_type ||
+                               UnderlyingType == TypeManager.ushort_type) {
                                Report.Error (3009, Location, "`{0}': base type `{1}' is not CLS-compliant", GetSignatureForError (), TypeManager.CSharpName (UnderlyingType));
                        }