Author: martin
Date: 2005-04-29 09:50:38 -0400 (Fri, 29 Apr 2005)
New Revision: 43788

Modified:
   trunk/mcs/gmcs/ChangeLog
   trunk/mcs/gmcs/anonymous.cs
   trunk/mcs/gmcs/generic.cs
Log:
2005-04-29  Martin Baulig  <[EMAIL PROTECTED]>

        * generic.cs (Constraints.ResolveTypes): Expand interfaces.

        * anonymous.cs: Added support for anonymous generic methods.



Modified: trunk/mcs/gmcs/ChangeLog
===================================================================
--- trunk/mcs/gmcs/ChangeLog    2005-04-29 13:17:48 UTC (rev 43787)
+++ trunk/mcs/gmcs/ChangeLog    2005-04-29 13:50:38 UTC (rev 43788)
@@ -1,5 +1,11 @@
 2005-04-29  Martin Baulig  <[EMAIL PROTECTED]>
 
+       * generic.cs (Constraints.ResolveTypes): Expand interfaces.
+
+       * anonymous.cs: Added support for anonymous generic methods.
+
+2005-04-29  Martin Baulig  <[EMAIL PROTECTED]>
+
        * typemanager.cs (TypeManager.GetInterfaces): Correctly handle
        generic instances.
 

Modified: trunk/mcs/gmcs/anonymous.cs
===================================================================
--- trunk/mcs/gmcs/anonymous.cs 2005-04-29 13:17:48 UTC (rev 43787)
+++ trunk/mcs/gmcs/anonymous.cs 2005-04-29 13:50:38 UTC (rev 43788)
@@ -47,6 +47,8 @@
                // The emit context for the anonymous method
                public EmitContext aec;
                public InternalParameters amp;
+               public string[] TypeParameters;
+               public Type[] TypeArguments;
                bool unreachable;
                
                //
@@ -129,13 +131,33 @@
                                current_type = null;
                        } 
 
+                       string name = "<#AnonymousMethod>" + 
anonymous_method_count++;
+                       MemberName member_name;
+
+                       GenericMethod generic_method = null;
+                       if (TypeParameters != null) {
+                               TypeArguments args = new TypeArguments (loc);
+                               foreach (string t in TypeParameters)
+                                       args.Add (new SimpleName (t, loc));
+
+                               member_name = new MemberName (name, args);
+
+                               generic_method = new GenericMethod (
+                                       ec.DeclSpace.NamespaceEntry,
+                                       (TypeContainer) ec.TypeContainer,
+                                       member_name, loc);
+
+                               generic_method.SetParameterInfo (null);
+                       } else
+                               member_name = new MemberName (name);
+
                        method = new Method (
-                               (TypeContainer) ec.TypeContainer, null,
+                               (TypeContainer) ec.TypeContainer, 
generic_method,
                                new TypeExpression (return_type, loc),
-                               method_modifiers, false, new MemberName 
("<#AnonymousMethod>" + anonymous_method_count++),
+                               method_modifiers, false, member_name,
                                Parameters, null, loc);
                        method.Block = Block;
-                       
+
                        //
                        // Swap the TypeBuilder while we define the method, 
then restore
                        //
@@ -144,6 +166,7 @@
                        bool res = method.Define ();
                        if (current_type != null)
                                ec.TypeContainer.TypeBuilder = current_type;
+
                        return res;
                }
                
@@ -168,6 +191,16 @@
                        invoke_mb = (MethodInfo) invoke_mg.Methods [0];
                        ParameterData invoke_pd = TypeManager.GetParameterData 
(invoke_mb);
 
+                       if (delegate_type.IsGenericInstance) {
+                               TypeArguments = TypeManager.GetTypeArguments 
(delegate_type);
+
+                               Type def = 
delegate_type.GetGenericTypeDefinition ();
+                               Type[] tparam = TypeManager.GetTypeArguments 
(def);
+                               TypeParameters = new string [tparam.Length];
+                               for (int i = 0; i < tparam.Length; i++)
+                                       TypeParameters [i] = tparam [i].Name;
+                       }
+
                        if (Parameters == null){
                                int i, j;
                                
@@ -285,9 +318,13 @@
                        return null;
                }
 
-               public MethodBuilder GetMethodBuilder ()
+               public MethodInfo GetMethodBuilder ()
                {
-                       return method.MethodData.MethodBuilder;
+                       MethodInfo builder = method.MethodData.MethodBuilder;
+                       if (TypeArguments != null)
+                               return builder.BindGenericParameters 
(TypeArguments);
+                       else
+                               return builder;
                }
                
                public bool EmitMethod (EmitContext ec)
@@ -295,10 +332,10 @@
                        if (!CreateMethodHost (ec, invoke_mb.ReturnType))
                                return false;
 
-                       MethodBuilder builder = GetMethodBuilder ();
+                       MethodBuilder builder = method.MethodData.MethodBuilder;
                        ILGenerator ig = builder.GetILGenerator ();
                        aec.ig = ig;
-                       
+
                        Parameters.LabelParameters (aec, builder, loc);
 
                        //

Modified: trunk/mcs/gmcs/generic.cs
===================================================================
--- trunk/mcs/gmcs/generic.cs   2005-04-29 13:17:48 UTC (rev 43787)
+++ trunk/mcs/gmcs/generic.cs   2005-04-29 13:50:38 UTC (rev 43788)
@@ -330,9 +330,24 @@
                                list.Add (expr.Type);
                        }
 
-                       iface_constraint_types = new Type [list.Count];
-                       list.CopyTo (iface_constraint_types, 0);
+                       ArrayList new_list = new ArrayList ();
+                       foreach (Type iface in list) {
+                               if (new_list.Contains (iface))
+                                       continue;
 
+                               new_list.Add (iface);
+
+                               Type [] implementing = 
TypeManager.GetInterfaces (iface);
+                       
+                               foreach (Type imp in implementing) {
+                                       if (!new_list.Contains (imp))
+                                               new_list.Add (imp);
+                               }
+                       }
+
+                       iface_constraint_types = new Type [new_list.Count];
+                       new_list.CopyTo (iface_constraint_types, 0);
+
                        if (class_constraint != null) {
                                TypeExpr te = 
class_constraint.ResolveAsTypeTerminal (ec);
                                if (te == null)
@@ -509,6 +524,7 @@
                Constraints constraints;
                Location loc;
                GenericTypeParameterBuilder type;
+               Type[] iface_constraints;
 
                public TypeParameter (TypeContainer parent, string name,
                                      Constraints constraints, Location loc)

_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches

Reply via email to