*** merged revision 57555 from mcs
[mono.git] / mcs / gmcs / enum.cs
index d7741cd50a8194abcaf83c74718c9ea26a0a15fa..54570d9d8c3eef41f24c98ce6fde219b1fd23aa9 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 (this, 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()
@@ -181,13 +186,6 @@ namespace Mono.CSharp {
                        }
                }
 
-               protected override bool VerifyClsCompliance(DeclSpace ds)
-               {
-                       // Because parent is TypeContainer and we have only DeclSpace parent.
-                       // Parameter replacing is required
-                       return base.VerifyClsCompliance (parent_enum);
-               }
-
                public override string DocCommentHeader {
                        get { return "F:"; }
                }
@@ -244,19 +242,13 @@ 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");
                                return null;
                        }
 
-                       TypeExpr ute = ResolveBaseTypeExpr (BaseType, false, Location);
-                       if (ute == null)
-                               return null;
-
+                       TypeExpr ute = BaseType.ResolveAsTypeTerminal (this, false);
                        UnderlyingType = ute.Type;
 
                        if (UnderlyingType != TypeManager.int32_type &&
@@ -286,8 +278,6 @@ namespace Mono.CSharp {
                                        Basename, TypeAttr, TypeManager.enum_type);
                        }
 
-                       ec.ContainerType = TypeBuilder;
-
                        //
                        // Call MapToInternalType for corlib
                        //
@@ -307,21 +297,17 @@ namespace Mono.CSharp {
                
                public override bool Define ()
                {
-                       if (GetObsoleteAttribute () != null || Parent.GetObsoleteAttribute () != null)
-                               ec.TestObsoleteMethodUsage = false;
-
                        return true;
                }
 
                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 ();
@@ -348,7 +334,7 @@ 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 {
@@ -362,9 +348,9 @@ namespace Mono.CSharp {
                        }
                }
 
-               protected override bool VerifyClsCompliance (DeclSpace ds)
+               protected override bool VerifyClsCompliance ()
                {
-                       if (!base.VerifyClsCompliance (ds))
+                       if (!base.VerifyClsCompliance ())
                                return false;
 
                        VerifyClsName ();