2009-08-03 Rodrigo Kumpera <rkumpera@novell.com>
authorRodrigo Kumpera <kumpera@gmail.com>
Tue, 4 Aug 2009 00:10:17 +0000 (00:10 -0000)
committerRodrigo Kumpera <kumpera@gmail.com>
Tue, 4 Aug 2009 00:10:17 +0000 (00:10 -0000)
* MonoGenericClass.cs (initialize): Remember the number
of events available at initialization time. This is required as
mcs expect this behavior under compiler context that new events
are not returned for an instance that was inflated before.

* MonoGenericClass.cs: Kill GetEvents_internal and implement it
in terms of managed code.

2009-08-03 Rodrigo Kumpera  <rkumpera@novell.com>

* EventBuilder.cs: Make some fields internal.

* TypeBuilder.cs: Make events field internal.
Remove some MonoTODOs that are already done.

* EventOnTypeBuilderInst.cs: New file which implements
the required functionality by compiler context.

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

mcs/class/corlib/System.Reflection.Emit/ChangeLog
mcs/class/corlib/System.Reflection.Emit/EventBuilder.cs
mcs/class/corlib/System.Reflection.Emit/EventOnTypeBuilderInst.cs [new file with mode: 0644]
mcs/class/corlib/System.Reflection.Emit/TypeBuilder.cs
mcs/class/corlib/System.Reflection/ChangeLog
mcs/class/corlib/System.Reflection/MonoGenericClass.cs
mcs/class/corlib/corlib.dll.sources

index 721c2e8cf11695c8e60aa3c555c1f9418ea2c5da..0e008a33bfa43af9d31d3a8cca418c6d860514b4 100644 (file)
@@ -1,3 +1,13 @@
+2009-08-03 Rodrigo Kumpera  <rkumpera@novell.com>
+
+       * EventBuilder.cs: Make some fields internal.
+
+       * TypeBuilder.cs: Make events field internal.
+       Remove some MonoTODOs that are already done.
+
+       * EventOnTypeBuilderInst.cs: New file which implements
+       the required functionality by compiler context.
+
 2009-07-30 Rodrigo Kumpera  <rkumpera@novell.com>
 
        * TypeBuilder.cs (IsDefined): Throw if not
index 4c391538ec15f619ed2615bc9e238bec342eb576..ca7331bef64caa50614a37102dc051447fcd45a3 100644 (file)
@@ -46,15 +46,15 @@ namespace System.Reflection.Emit {
        [ClassInterface (ClassInterfaceType.None)]
        public sealed class EventBuilder : _EventBuilder {
 #pragma warning disable 169, 414
-               string name;
+               internal string name;
                Type type;
                TypeBuilder typeb;
                CustomAttributeBuilder[] cattrs;
-               MethodBuilder add_method;
-               MethodBuilder remove_method;
-               MethodBuilder raise_method;
-               MethodBuilder[] other_methods;
-               EventAttributes attrs;
+               internal MethodBuilder add_method;
+               internal MethodBuilder remove_method;
+               internal MethodBuilder raise_method;
+               internal MethodBuilder[] other_methods;
+               internal EventAttributes attrs;
                int table_idx;
 #pragma warning restore 169, 414
 
diff --git a/mcs/class/corlib/System.Reflection.Emit/EventOnTypeBuilderInst.cs b/mcs/class/corlib/System.Reflection.Emit/EventOnTypeBuilderInst.cs
new file mode 100644 (file)
index 0000000..76d8e92
--- /dev/null
@@ -0,0 +1,124 @@
+//
+// System.Reflection.Emit/EventOnTypeBuilderInst.cs
+//
+// Author:
+//   Rodrigo Kumpera (rkumpera@novell.com)
+//
+//
+// Copyright (C) 2009 Novell, Inc (http://www.novell.com)
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+// 
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+// 
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+using System;
+using System.Collections;
+using System.Globalization;
+using System.Reflection;
+
+#if NET_2_0 || BOOTSTRAP_NET_2_0
+
+namespace System.Reflection.Emit
+{
+       /*
+        * This class represents an event of an instantiation of a generic type builder.
+        */
+       internal class EventOnTypeBuilderInst : EventInfo
+       {
+               MonoGenericClass instantiation;
+               EventBuilder evt;
+
+               internal EventOnTypeBuilderInst (MonoGenericClass instantiation, EventBuilder evt)
+               {
+                       this.instantiation = instantiation;
+                       this.evt = evt;
+               }
+
+               public override EventAttributes Attributes {
+                       get { return evt.attrs; }
+               }
+
+               public override MethodInfo GetAddMethod (bool nonPublic)
+               {
+                       if (evt.add_method == null || (!nonPublic && !evt.add_method.IsPublic))
+                               return null;
+                       return TypeBuilder.GetMethod (instantiation, evt.add_method);
+               }
+
+               public override MethodInfo GetRaiseMethod (bool nonPublic)
+               {
+                       if (evt.raise_method == null || (!nonPublic && !evt.raise_method.IsPublic))
+                               return null;
+                       return TypeBuilder.GetMethod (instantiation, evt.raise_method);
+               }
+
+               public override MethodInfo GetRemoveMethod (bool nonPublic)
+               {
+                       if (evt.remove_method == null || (!nonPublic && !evt.remove_method.IsPublic))
+                               return null;
+                       return TypeBuilder.GetMethod (instantiation, evt.remove_method);
+               }
+
+#if NET_2_0
+               public override MethodInfo[] GetOtherMethods (bool nonPublic)
+               {
+                       if (evt.other_methods == null)
+                               return new MethodInfo [0];
+
+                       ArrayList ar = new ArrayList ();
+                       foreach (MethodInfo method in evt.other_methods) {
+                               if (nonPublic || method.IsPublic)
+                                       ar.Add (TypeBuilder.GetMethod (instantiation, method));
+                       }
+                       MethodInfo[] res = new MethodInfo [ar.Count];
+                       ar.CopyTo (res, 0);
+                       return res;
+               }
+#endif
+
+               public override Type DeclaringType {
+                       get { return instantiation; }
+               }
+
+               public override string Name {
+                       get { return evt.name; }
+               }
+
+               public override Type ReflectedType {
+                       get { return instantiation; }
+               }
+
+               public override bool IsDefined (Type attributeType, bool inherit)
+               {
+                       throw new NotSupportedException ();
+               }
+
+               public override object [] GetCustomAttributes (bool inherit)
+               {
+                       throw new NotSupportedException ();
+               }
+
+               public override object [] GetCustomAttributes (Type attributeType, bool inherit)
+               {
+                       throw new NotSupportedException ();
+               }
+       }
+}
+
+#endif
\ No newline at end of file
index 1aef914597e43b156195f725171ca19abf655163..8037c402bbee0e70568a93380ed9896eabe1bc9c 100644 (file)
@@ -65,7 +65,7 @@ namespace System.Reflection.Emit
                internal PropertyBuilder[] properties;
                internal int num_fields;
                internal FieldBuilder[] fields;
-               private EventBuilder[] events;
+               internal EventBuilder[] events;
                private CustomAttributeBuilder[] cattrs;
                internal TypeBuilder[] subtypes;
                internal TypeAttributes attrs;
@@ -1428,7 +1428,6 @@ namespace System.Reflection.Emit
                        return new ArrayType (this, rank);
                }
 
-               [MonoTODO]
                public override Type MakeByRefType ()
                {
                        return new ByRefType (this);
@@ -1440,7 +1439,6 @@ namespace System.Reflection.Emit
                        return base.MakeGenericType (typeArguments);
                }
 
-               [MonoTODO]
                public override Type MakePointerType ()
                {
                        return new PointerType (this);
index cf02e0a07bc0511392fd81acc69bf1760e49a0b4..d22314f8942ba0a98cbea39538473cc28bb143ad 100644 (file)
@@ -1,3 +1,13 @@
+2009-08-03 Rodrigo Kumpera  <rkumpera@novell.com>
+
+       * MonoGenericClass.cs (initialize): Remember the number
+       of events available at initialization time. This is required as
+       mcs expect this behavior under compiler context that new events
+       are not returned for an instance that was inflated before.
+
+       * MonoGenericClass.cs: Kill GetEvents_internal and implement it
+       in terms of managed code.
+
 2009-07-30  Zoltan Varga  <vargaz@gmail.com>
 
        * FieldInfo.cs: Throw an exception if internal_from_handle_type ()
index c1ced726c487b9e3539d19f352c0c752173dff18..5ba0e5bf0b823eba3d5c1d3af9f631433ce0fd90 100644 (file)
@@ -58,6 +58,7 @@ namespace System.Reflection
                #endregion
 
                Hashtable fields, ctors, methods;
+               int event_count;
 
                internal MonoGenericClass ()
                        : base (null)
@@ -71,9 +72,6 @@ namespace System.Reflection
 
                [MethodImplAttribute(MethodImplOptions.InternalCall)]
                extern MethodInfo GetCorrespondingInflatedMethod (MethodInfo generic);
-               
-               [MethodImplAttribute(MethodImplOptions.InternalCall)]
-               extern EventInfo[] GetEvents_internal (Type reflected_type);
 
                private const BindingFlags flags = BindingFlags.Public | BindingFlags.NonPublic |
                BindingFlags.Static | BindingFlags.Instance | BindingFlags.DeclaredOnly;
@@ -86,12 +84,14 @@ namespace System.Reflection
                        MonoGenericClass parent = GetParentType () as MonoGenericClass;
                        if (parent != null)
                                parent.initialize ();
-
+                       EventInfo[] events = generic_type.GetEvents_internal (flags);
+                       event_count = events.Length;
+                               
                        initialize (generic_type.GetMethods (flags),
                                                generic_type.GetConstructorsInternal (flags),
                                                generic_type.GetFields (flags),
                                                generic_type.GetProperties (flags),
-                                               generic_type.GetEvents_internal (flags));
+                                               events);
 
                        initialized = true;
                }
@@ -514,7 +514,7 @@ namespace System.Reflection
                        do {
                                MonoGenericClass gi = current_type as MonoGenericClass;
                                if (gi != null)
-                                       l.AddRange (gi.GetEvents_impl (bf, this));
+                                       l.AddRange (gi.GetEventsInternal (bf, this));
                                else if (current_type is TypeBuilder)
                                        l.AddRange (current_type.GetEvents (bf));
                                else {
@@ -532,25 +532,25 @@ namespace System.Reflection
                        l.CopyTo (result);
                        return result;
                }
+       
+               EventInfo[] GetEventsInternal (BindingFlags bf, MonoGenericClass reftype) {
+                       if (generic_type.events == null)
+                               return new EventInfo [0];
+
+                       initialize ();
 
-               protected EventInfo[] GetEvents_impl (BindingFlags bf, Type reftype)
-               {
                        ArrayList l = new ArrayList ();
                        bool match;
                        MethodAttributes mattrs;
                        MethodInfo accessor;
 
-                       initialize ();
-
-                       EventInfo[] events = GetEvents_internal (reftype);
-
-                       for (int i = 0; i < events.Length; i++) {
-                               EventInfo c = events [i];
+                       for (int i = 0; i < event_count; ++i) {
+                               EventBuilder ev = generic_type.events [i];
 
                                match = false;
-                               accessor = c.GetAddMethod (true);
+                               accessor = ev.add_method;
                                if (accessor == null)
-                                       accessor = c.GetRemoveMethod (true);
+                                       accessor = ev.remove_method;
                                if (accessor == null)
                                        continue;
                                mattrs = accessor.Attributes;
@@ -573,7 +573,7 @@ namespace System.Reflection
                                }
                                if (!match)
                                        continue;
-                               l.Add (c);
+                               l.Add (new EventOnTypeBuilderInst (this, ev));
                        }
                        EventInfo[] result = new EventInfo [l.Count];
                        l.CopyTo (result);
index cf8b52cdcf20af6311b1ffc3da9a6e9b34e7c6a0..84e3fdb781b6c685aa1157e21b0a2a28faac6916 100644 (file)
@@ -519,6 +519,7 @@ System.Reflection.Emit/DynamicILInfo.cs
 System.Reflection.Emit/DynamicMethod.cs
 System.Reflection.Emit/EnumBuilder.cs
 System.Reflection.Emit/EventBuilder.cs
+System.Reflection.Emit/EventOnTypeBuilderInst.cs
 System.Reflection.Emit/EventToken.cs
 System.Reflection.Emit/FieldBuilder.cs
 System.Reflection.Emit/FieldOnTypeBuilderInst.cs