Merge pull request #686 from LHCGreg/12971-IsRedirectedAfterSet
[mono.git] / mcs / mcs / enum.cs
index 4258211fa8ec52fa82df1b41762ec358575828ae..1081e0e551e55849bf18118da5bab9b941b87d3d 100644 (file)
@@ -9,6 +9,7 @@
 //
 // Copyright 2001 Ximian, Inc (http://www.ximian.com)
 // Copyright 2003-2003 Novell, Inc (http://www.novell.com)
+// Copyright 2011 Xamarin Inc
 //
 
 using System;
@@ -27,11 +28,11 @@ namespace Mono.CSharp {
        {
                class EnumTypeExpr : TypeExpr
                {
-                       public override TypeExpr ResolveAsType (IMemberContext ec)
+                       public override TypeSpec ResolveAsType (IMemberContext ec)
                        {
                                type = ec.CurrentType;
                                eclass = ExprClass.Type;
-                               return this;
+                               return type;
                        }
                }
 
@@ -90,12 +91,18 @@ namespace Mono.CSharp {
                        Parent.MemberCache.AddMember (spec);
                        return true;
                }
+               
+               public override void Accept (StructuralVisitor visitor)
+               {
+                       visitor.Visit (this);
+               }
+
        }
 
        /// <summary>
        ///   Enumeration container
        /// </summary>
-       public class Enum : TypeContainer
+       public class Enum : TypeDefinition
        {
                //
                // Implicit enum member initializer, used when no constant value is provided
@@ -111,6 +118,11 @@ namespace Mono.CSharp {
                                this.prev = prev;
                        }
 
+                       public override bool ContainsEmitWithAwait ()
+                       {
+                               return false;
+                       }
+
                        public override Expression CreateExpressionTree (ResolveContext ec)
                        {
                                throw new NotSupportedException ("Missing Resolve call");
@@ -150,11 +162,12 @@ namespace Mono.CSharp {
                        Modifiers.INTERNAL |
                        Modifiers.PRIVATE;
 
-               public Enum (NamespaceContainer ns, DeclSpace parent, TypeExpression type,
-                            Modifiers mod_flags, MemberName name, Attributes attrs)
-                       : base (ns, parent, name, attrs, MemberKind.Enum)
+               readonly FullNamedExpression underlying_type_expr;
+
+               public Enum (TypeContainer parent, FullNamedExpression type, Modifiers mod_flags, MemberName name, Attributes attrs)
+                       : base (parent, name, attrs, MemberKind.Enum)
                {
-                       base_type_expr = type;
+                       underlying_type_expr = type;
                        var accmods = IsTopLevel ? Modifiers.INTERNAL : Modifiers.PRIVATE;
                        ModFlags = ModifiersExtensions.Check (AllowedModifiers, mod_flags, accmods, Location, Report);
                        spec = new EnumSpec (null, this, null, null, ModFlags);
@@ -168,16 +181,15 @@ namespace Mono.CSharp {
                        }
                }
 
-               public TypeExpr BaseTypeExpression {
+               public FullNamedExpression BaseTypeExpression {
                        get {
-                               return base_type_expr;
+                               return underlying_type_expr;
                        }
                }
 
                protected override TypeAttributes TypeAttr {
                        get {
-                               return ModifiersExtensions.TypeAttr (ModFlags, IsTopLevel) |
-                                       TypeAttributes.Class | TypeAttributes.Sealed | base.TypeAttr;
+                               return base.TypeAttr | TypeAttributes.Class | TypeAttributes.Sealed;
                        }
                }
 
@@ -202,7 +214,7 @@ namespace Mono.CSharp {
                                return;
                        }
 
-                       AddConstant (em);
+                       AddMember (em);
                }
 
                public static void Error_1008 (Location loc, Report Report)
@@ -211,27 +223,25 @@ namespace Mono.CSharp {
                                "Type byte, sbyte, short, ushort, int, uint, long or ulong expected");
                }
 
-               protected override bool DefineNestedTypes ()
+               protected override void DoDefineContainer ()
                {
-                       ((EnumSpec) spec).UnderlyingType = base_type_expr == null ? Compiler.BuiltinTypes.Int : base_type_expr.Type;
+                       ((EnumSpec) spec).UnderlyingType = underlying_type_expr == null ? Compiler.BuiltinTypes.Int : underlying_type_expr.Type;
 
                        TypeBuilder.DefineField (UnderlyingValueField, UnderlyingType.GetMetaInfo (),
                                FieldAttributes.Public | FieldAttributes.SpecialName | FieldAttributes.RTSpecialName);
 
-                       return true;
+                       DefineBaseTypes ();
                }
 
                protected override bool DoDefineMembers ()
                {
-                       if (constants != null) {
-                               for (int i = 0; i < constants.Count; ++i) {
-                                       EnumMember em = (EnumMember) constants [i];
-                                       if (em.Initializer == null) {
-                                               em.Initializer = new ImplicitInitializer (em, i == 0 ? null : (EnumMember) constants[i - 1]);
-                                       }
-
-                                       em.Define ();
+                       for (int i = 0; i < Members.Count; ++i) {
+                               EnumMember em = (EnumMember) Members[i];
+                               if (em.Initializer == null) {
+                                       em.Initializer = new ImplicitInitializer (em, i == 0 ? null : (EnumMember) Members[i - 1]);
                                }
+
+                               em.Define ();
                        }
 
                        return true;
@@ -242,10 +252,10 @@ namespace Mono.CSharp {
                        return true;
                }
 
-               protected override TypeExpr[] ResolveBaseTypes (out TypeExpr base_class)
+               protected override TypeSpec[] ResolveBaseTypes (out FullNamedExpression base_class)
                {
                        base_type = Compiler.BuiltinTypes.Enum;
-                       base_class = base_type_expr;
+                       base_class = null;
                        return null;
                }
 
@@ -259,7 +269,7 @@ namespace Mono.CSharp {
                        case BuiltinTypeSpec.Type.ULong:
                        case BuiltinTypeSpec.Type.UShort:
                                Report.Warning (3009, 1, Location, "`{0}': base type `{1}' is not CLS-compliant",
-                                       GetSignatureForError (), TypeManager.CSharpName (UnderlyingType));
+                                       GetSignatureForError (), UnderlyingType.GetSignatureForError ());
                                break;
                        }