2004-07-18 Martin Baulig <martin@ximian.com>
[mono.git] / mcs / gmcs / enum.cs
index 2c76438a76ab6095819301d264a61affce1dad2c..22a10381ca0783939d4cdae9568f0991e4cda111 100755 (executable)
@@ -13,9 +13,11 @@ using System;
 using System.Collections;
 using System.Reflection;
 using System.Reflection.Emit;
+using System.Globalization;
 
 namespace Mono.CSharp {
 
+       // Maybe can be usefull to derive from MemberCore
        class EnumMember: Attributable {
                string name;
                Enum parent;
@@ -73,6 +75,23 @@ namespace Mono.CSharp {
                                OptAttributes.Emit (ec, this); 
                }
 
+               // TODO: caching would be usefull
+               public ObsoleteAttribute GetObsoleteAttribute (EmitContext ec)
+               {
+                       if (OptAttributes == null)
+                               return null;
+
+                       Attribute obsolete_attr = OptAttributes.Search (TypeManager.obsolete_attribute_type, ec);
+                       if (obsolete_attr == null)
+                               return null;
+
+                       ObsoleteAttribute obsolete = obsolete_attr.GetObsoleteAttribute (ec.DeclSpace);
+                       if (obsolete == null)
+                               return null;
+
+                       return obsolete;
+               }
+
                protected override string[] ValidAttributeTargets {
                        get {
                                return attribute_targets;
@@ -203,6 +222,13 @@ namespace Mono.CSharp {
 
                        attr |= TypeAttributes.Class | TypeAttributes.Sealed;
 
+                       if (!(BaseType is TypeLookupExpression)) {
+                               Report.Error (1008, Location,
+                                             "Type byte, sbyte, short, ushort, int, uint, " +
+                                             "long, or ulong expected (got: `{0}')", BaseType);
+                               return null;
+                       }
+
                        UnderlyingType = ResolveType (BaseType, false, Location);
 
                        if (UnderlyingType != TypeManager.int32_type &&
@@ -659,6 +685,7 @@ namespace Mono.CSharp {
 
                                default_value = GetNextDefaultValue (default_value);
                        }
+
                        return true;
                }
                        
@@ -689,7 +716,7 @@ namespace Mono.CSharp {
                                                continue;
 
                                        string enumerator_name = ordered_enums [ii] as string;
-                                       if (String.Compare (checked_name, enumerator_name, true) == 0) {
+                                       if (String.Compare (checked_name, enumerator_name, true, CultureInfo.InvariantCulture) == 0) {
                                                Report.SymbolRelatedToPreviousError ((Location)member_to_location [enumerator_name], enumerator_name);
                                                Report.Error_T (3005, (Location)member_to_location [checked_name], GetEnumeratorName (checked_name));
                                                break;
@@ -767,5 +794,32 @@ namespace Mono.CSharp {
                        }
                }
 
+               protected override void VerifyObsoleteAttribute()
+               {
+                       // UnderlyingType is never obsolete
+               }
+
+               /// <summary>
+               /// Returns ObsoleteAttribute for both enum type and enum member
+               /// </summary>
+               public ObsoleteAttribute GetObsoleteAttribute (EmitContext ec, string identifier)
+               {
+                       if ((caching_flags & Flags.Obsolete_Undetected) == 0 && (caching_flags & Flags.Obsolete) == 0) {
+                               return null;
+                       }
+
+                       ObsoleteAttribute oa = GetObsoleteAttribute (ec.DeclSpace);
+                       if (oa != null)
+                               return oa;
+
+                       EnumMember em = (EnumMember)name_to_member [identifier];
+                       oa = em.GetObsoleteAttribute (ec);
+
+                       if (oa == null)
+                               return null;
+
+                       caching_flags |= Flags.Obsolete;
+                       return oa;
+               }
        }
 }