2008-11-24 Marek Safar <marek.safar@gmail.com>
[mono.git] / mcs / mcs / enum.cs
index b4a24c5eb2d8c47e9ae84599df37d3c647d371ca..2523e0cf76c1cc701b5fb638ac8bc2d7254e300b 100644 (file)
@@ -70,6 +70,9 @@ namespace Mono.CSharp {
 
                public override bool Define ()
                {
+                       if (!ResolveMemberType ())
+                               return false;
+
                        const FieldAttributes attr = FieldAttributes.Public | FieldAttributes.Static | FieldAttributes.Literal;
                        FieldBuilder = Parent.TypeBuilder.DefineField (Name, MemberType, attr);
                        Parent.MemberCache.AddMember (FieldBuilder, this);
@@ -87,7 +90,7 @@ namespace Mono.CSharp {
                                if (c is EnumConstant)
                                        c = ((EnumConstant)c).Child;
 
-                               c = c.ImplicitConversionRequired (ParentEnum.UnderlyingType, Location);
+                               c = c.ImplicitConversionRequired (ec, ParentEnum.UnderlyingType, Location);
                                if (c == null)
                                        return null;
 
@@ -124,9 +127,7 @@ namespace Mono.CSharp {
        {
                public static readonly string UnderlyingValueField = "value__";
 
-               FullNamedExpression base_type;
-
-               public Type UnderlyingType;
+               TypeExpr base_type;
 
                const int AllowedModifiers =
                        Modifiers.NEW |
@@ -135,7 +136,7 @@ namespace Mono.CSharp {
                        Modifiers.INTERNAL |
                        Modifiers.PRIVATE;
 
-               public Enum (NamespaceEntry ns, DeclSpace parent, FullNamedExpression type,
+               public Enum (NamespaceEntry ns, DeclSpace parent, TypeExpr type,
                             int mod_flags, MemberName name, Attributes attrs)
                        : base (ns, parent, name, attrs, Kind.Enum)
                {
@@ -166,26 +167,6 @@ namespace Mono.CSharp {
                        if (!base.DefineNestedTypes ())
                                return false;
 
-                       if (!(base_type is TypeLookupExpression)) {
-                               Error_1008 (Location);
-                               return false;
-                       }
-
-                       TypeExpr ute = base_type.ResolveAsTypeTerminal (this, false);
-                       UnderlyingType = ute.Type;
-
-                       if (UnderlyingType != TypeManager.int32_type &&
-                           UnderlyingType != TypeManager.uint32_type &&
-                           UnderlyingType != TypeManager.int64_type &&
-                           UnderlyingType != TypeManager.uint64_type &&
-                           UnderlyingType != TypeManager.short_type &&
-                           UnderlyingType != TypeManager.ushort_type &&
-                           UnderlyingType != TypeManager.byte_type  &&
-                           UnderlyingType != TypeManager.sbyte_type) {
-                               Error_1008 (Location);
-                               return false;
-                       }
-
                        //
                        // Call MapToInternalType for corlib
                        //
@@ -196,24 +177,22 @@ namespace Mono.CSharp {
                        return true;
                }
 
-               protected override bool DoDefineMembers ()
+               public override bool Define ()
                {
                        member_cache = new MemberCache (TypeManager.enum_type, this);
                        DefineContainerMembers (constants);
                        return true;
                }
 
-               //
-               // Used for error reporting only
-               //
-               public EnumMember GetDefinition (object value)
+               public override bool IsUnmanagedType ()
                {
-                       foreach (EnumMember e in defined_names.Values) {
-                               if (value.Equals (e.Value))
-                                       return e;
-                       }
+                       return true;
+               }
 
-                       throw new ArgumentOutOfRangeException (value.ToString ());
+               public Type UnderlyingType {
+                       get {
+                               return base_type.Type;
+                       }
                }
 
                protected override bool VerifyClsCompliance ()