2002-05-04 Miguel de Icaza <miguel@ximian.com>
authorMiguel de Icaza <miguel@gnome.org>
Sat, 4 May 2002 22:40:40 +0000 (22:40 -0000)
committerMiguel de Icaza <miguel@gnome.org>
Sat, 4 May 2002 22:40:40 +0000 (22:40 -0000)
* ecore.cs (FieldExpr): Remove un-needed tests for null, since now
events are always registered FieldBuilders.

* class.cs (FieldBase): New class shared by Fields

svn path=/trunk/mcs/; revision=4287

mcs/mcs/ChangeLog
mcs/mcs/class.cs
mcs/mcs/cs-parser.jay
mcs/mcs/ecore.cs
mcs/mcs/typemanager.cs

index 8de10d4439a7ec324bd2ec51c4a65703eaa75478..58e0535d602694153bd2c39e8ac4579b8fe0bb32 100755 (executable)
@@ -1,5 +1,10 @@
 2002-05-04  Miguel de Icaza  <miguel@ximian.com>
 
+       * ecore.cs (FieldExpr): Remove un-needed tests for null, since now
+       events are always registered FieldBuilders.
+       
+       * class.cs (FieldBase): New class shared by Fields 
+
        * delegate.cs: If we are a toplevel delegate, use our full name.
        If we are a nested delegate, then only use our tail name.
 
index dbfa3291e0eee148ac5f5f532fc8139cde2d0416..d8a97c9cf32af67cc953e5fe28f06f1834e0ade4 100755 (executable)
@@ -2703,8 +2703,12 @@ namespace Mono.CSharp {
                        ec.EmitTopBlock (Block, Location);
                }
        }
-       
-       public class Field : MemberCore {
+
+       //
+       // Fields and Events both generate FieldBuilders, we use this to share 
+       // their common bits.  This is also used to flag usage of the field
+       //
+       abstract public class FieldBase : MemberCore {
                public readonly string Type;
                public readonly Object Initializer;
                public readonly Attributes OptAttributes;
@@ -2714,7 +2718,24 @@ namespace Mono.CSharp {
                [Flags]
                public enum Status : byte { ASSIGNED = 1, USED = 2 }
 
-               
+               //
+               // The constructor is only exposed to our children
+               //
+               protected FieldBase (string type, int mod, int allowed_mod, string name,
+                                    object init, Attributes attrs, Location loc)
+                       : base (name, loc)
+               {
+                       Type = type;
+                       ModFlags = Modifiers.Check (allowed_mod, mod, Modifiers.PRIVATE, loc);
+                       Initializer = init;
+                       OptAttributes = attrs;
+               }
+       }
+
+       //
+       // The Field class is used to represents class/struct fields during parsing.
+       //
+       public class Field : FieldBase {
                // <summary>
                //   Modifiers allowed in a class declaration
                // </summary>
@@ -2731,12 +2752,8 @@ namespace Mono.CSharp {
 
                public Field (string type, int mod, string name, Object expr_or_array_init,
                              Attributes attrs, Location loc)
-                       : base (name, loc)
+                       : base (type, mod, AllowedModifiers, name, expr_or_array_init, attrs, loc)
                {
-                       Type = type;
-                       ModFlags = Modifiers.Check (AllowedModifiers, mod, Modifiers.PRIVATE, loc);
-                       Initializer = expr_or_array_init;
-                       OptAttributes = attrs;
                }
 
                public override bool Define (TypeContainer parent)
@@ -2793,7 +2810,7 @@ namespace Mono.CSharp {
                        FieldBuilder = parent.TypeBuilder.DefineField (
                                Name, t, Modifiers.FieldAttr (ModFlags));
 
-                       TypeManager.RegisterField (FieldBuilder, this);
+                       TypeManager.RegisterFieldBase (FieldBuilder, this);
                        return true;
                }
 
@@ -3295,8 +3312,7 @@ namespace Mono.CSharp {
                }
        }
        
-       public class Event : MemberCore {
-               
+       public class Event : FieldBase {
                const int AllowedModifiers =
                        Modifiers.NEW |
                        Modifiers.PUBLIC |
@@ -3310,28 +3326,19 @@ namespace Mono.CSharp {
                        Modifiers.UNSAFE |
                        Modifiers.ABSTRACT;
 
-               public readonly string    Type;
-               public readonly Object    Initializer;
                public readonly Block     Add;
                public readonly Block     Remove;
                public MyEventBuilder     EventBuilder;
-               public FieldBuilder       FieldBuilder;
-               public Attributes         OptAttributes;
 
                Type EventType;
                MethodBuilder AddBuilder, RemoveBuilder;
                
-
-               public Event (string type, string name, Object init, int flags, Block add_block,
+               public Event (string type, string name, Object init, int mod, Block add_block,
                              Block rem_block, Attributes attrs, Location loc)
-                       : base (name, loc)
+                       : base (type, mod, AllowedModifiers, name, init, attrs, loc)
                {
-                       Type = type;
-                       Initializer = init;
-                       ModFlags = Modifiers.Check (AllowedModifiers, flags, Modifiers.PRIVATE, loc);  
                        Add = add_block;
                        Remove = rem_block;
-                       OptAttributes = attrs;
                }
 
                public override bool Define (TypeContainer parent)
@@ -3363,8 +3370,11 @@ namespace Mono.CSharp {
 
                        EventBuilder = new MyEventBuilder (parent.TypeBuilder, Name, e_attr, EventType);
 
-                       if (Add == null && Remove == null)
-                               FieldBuilder = parent.TypeBuilder.DefineField (Name, EventType, FieldAttributes.Private);
+                       if (Add == null && Remove == null){
+                               FieldBuilder = parent.TypeBuilder.DefineField (
+                                       Name, EventType, FieldAttributes.Private);
+                               TypeManager.RegisterFieldBase (FieldBuilder, this);
+                       }
                        
                        //
                        // Now define the accessors
index 448327d48cf78c63174da35f05df7cbfdbba8740..a4bd2012ad559c30808fbeaa476eced1db725e56 100755 (executable)
@@ -1488,7 +1488,8 @@ event_declaration
          {
                foreach (VariableDeclaration var in (ArrayList) $5) {
 
-                       Event e = new Event ((string) $4, var.identifier, var.expression_or_array_initializer,
+                       Event e = new Event ((string) $4, var.identifier, 
+                                            var.expression_or_array_initializer,
                                             (int) $2, null, null, (Attributes) $1, lexer.Location);
 
                        CheckDef (current_container.AddEvent (e), e.Name, e.Location);
index 15a51fc0848835a07289d59c8e8b139342c74756..528a0091a6042ee0cbed065d6f7c1855fbc2e095 100755 (executable)
@@ -3336,13 +3336,12 @@ namespace Mono.CSharp {
                        bool is_volatile = false;
                                
                        if (FieldInfo is FieldBuilder){
-                               Field f = TypeManager.GetField (FieldInfo);
-                               if (f != null){
-                                       if ((f.ModFlags & Modifiers.VOLATILE) != 0)
-                                               is_volatile = true;
+                               FieldBase f = TypeManager.GetField (FieldInfo);
+
+                               if ((f.ModFlags & Modifiers.VOLATILE) != 0)
+                                       is_volatile = true;
                                
-                                       f.status |= Field.Status.USED;
-                               }
+                               f.status |= Field.Status.USED;
                        }
                        
                        if (FieldInfo.IsStatic){
@@ -3400,8 +3399,9 @@ namespace Mono.CSharp {
                        source.Emit (ec);
 
                        if (FieldInfo is FieldBuilder){
-                               Field f = TypeManager.GetField (FieldInfo);
-                               if (f != null && (f.ModFlags & Modifiers.VOLATILE) != 0)
+                               FieldBase f = TypeManager.GetField (FieldInfo);
+                               
+                               if ((f.ModFlags & Modifiers.VOLATILE) != 0)
                                        ig.Emit (OpCodes.Volatile);
                        }
                        
@@ -3411,7 +3411,7 @@ namespace Mono.CSharp {
                                ig.Emit (OpCodes.Stfld, FieldInfo);
 
                        if (FieldInfo is FieldBuilder){
-                               Field f = TypeManager.GetField (FieldInfo);
+                               FieldBase f = TypeManager.GetField (FieldInfo);
 
                                f.status |= Field.Status.ASSIGNED;
                        }
@@ -3422,13 +3422,13 @@ namespace Mono.CSharp {
                        ILGenerator ig = ec.ig;
                        
                        if (FieldInfo is FieldBuilder){
-                               Field f = TypeManager.GetField (FieldInfo);
-                               if (f != null && (f.ModFlags & Modifiers.VOLATILE) != 0)
+                               FieldBase f = TypeManager.GetField (FieldInfo);
+                               if ((f.ModFlags & Modifiers.VOLATILE) != 0)
                                        ig.Emit (OpCodes.Volatile);
                        }
 
                        if (FieldInfo is FieldBuilder){
-                               Field f = TypeManager.GetField (FieldInfo);
+                               FieldBase f = TypeManager.GetField (FieldInfo);
 
                                if ((mode & AddressOp.Store) != 0)
                                        f.status |= Field.Status.ASSIGNED;
index 0c465667fbf2def71d72f36fbd50ccb17f4edead..f228c0d8cbfd24d0a385e2e35612bd842f0c7b52 100755 (executable)
@@ -833,7 +833,7 @@ public class TypeManager {
        }
 
        static Hashtable fieldbuilders_to_fields = new Hashtable ();
-       static public bool RegisterField (FieldBuilder fb, Field f)
+       static public bool RegisterFieldBase (FieldBuilder fb, FieldBase f)
        {
                if (fieldbuilders_to_fields.Contains (fb))
                        return false;
@@ -842,9 +842,9 @@ public class TypeManager {
                return true;
        }
 
-       static public Field GetField (FieldInfo fb)
+       static public FieldBase GetField (FieldInfo fb)
        {
-               return (Field) fieldbuilders_to_fields [fb];
+               return (FieldBase) fieldbuilders_to_fields [fb];
        }
        
        static Hashtable events;