2008-06-06 James Fitzsimons <james.fitzsimons@gmail.com>
[mono.git] / mcs / mcs / pending.cs
index 79c0fb5e24f3469ef33c96939545ae16571cee89..db89736ab5f92c631f3d091b12cd9a9a4e053c01 100644 (file)
@@ -4,10 +4,10 @@
 // Author:
 //   Miguel de Icaza (miguel@gnu.org)
 //
-// Licensed under the terms of the GNU GPL
-//
-// (C) 2001, 2002 Ximian, Inc (http://www.ximian.com)
+// Dual licensed under the terms of the MIT X11 or GNU GPL
 //
+// Copyright 2001, 2002 Ximian, Inc (http://www.ximian.com)
+// Copyright 2003-2008 Novell, Inc.
 //
 
 using System;
@@ -148,7 +148,43 @@ namespace Mono.CSharp {
                        pending_implementations = new TypeAndMethods [total];
 
                        int i = 0;
-                       foreach (MissingInterfacesInfo missing in missing_ifaces){
+                       if (abstract_methods != null) {
+                               int count = abstract_methods.Count;
+                               pending_implementations [i].methods = new MethodInfo [count];
+                               pending_implementations [i].need_proxy = new MethodInfo [count];
+                               
+                               abstract_methods.CopyTo (pending_implementations [i].methods, 0);
+                               pending_implementations [i].found = new bool [count];
+                               pending_implementations [i].args = new Type [count][];
+                               pending_implementations [i].mods = new Parameter.Modifier [count][];
+                               pending_implementations [i].type = type_builder;
+
+                               string indexer_name = TypeManager.IndexerPropertyName (type_builder);
+                               pending_implementations [i].set_indexer_name = "set_" + indexer_name;
+                               pending_implementations [i].get_indexer_name = "get_" + indexer_name;
+                               
+                               int j = 0;
+                               foreach (MemberInfo m in abstract_methods) {
+                                       MethodInfo mi = (MethodInfo) m;
+                                       
+                                       ParameterData pd = TypeManager.GetParameterData (mi);
+                                       Type [] types = pd.Types;
+                                       
+                                       pending_implementations [i].args [j] = types;
+                                       pending_implementations [i].mods [j] = null;
+                                       if (pd.Count > 0) {
+                                               Parameter.Modifier [] pm = new Parameter.Modifier [pd.Count];
+                                               for (int k = 0; k < pd.Count; k++)
+                                                       pm [k] = pd.ParameterModifier (k);
+                                               pending_implementations [i].mods [j] = pm;
+                                       }
+                                               
+                                       j++;
+                               }
+                               ++i;
+                       }
+
+                       foreach (MissingInterfacesInfo missing in missing_ifaces) {
                                MethodInfo [] mi;
                                Type t = missing.Type;
                                
@@ -200,41 +236,6 @@ namespace Mono.CSharp {
                                }
                                i++;
                        }
-
-                       if (abstract_methods != null){
-                               int count = abstract_methods.Count;
-                               pending_implementations [i].methods = new MethodInfo [count];
-                               pending_implementations [i].need_proxy = new MethodInfo [count];
-                               
-                               abstract_methods.CopyTo (pending_implementations [i].methods, 0);
-                               pending_implementations [i].found = new bool [count];
-                               pending_implementations [i].args = new Type [count][];
-                               pending_implementations [i].mods = new Parameter.Modifier [count][];
-                               pending_implementations [i].type = type_builder;
-
-                               string indexer_name = TypeManager.IndexerPropertyName (type_builder);
-                               pending_implementations [i].set_indexer_name = "set_" + indexer_name;
-                               pending_implementations [i].get_indexer_name = "get_" + indexer_name;
-                               
-                               int j = 0;
-                               foreach (MemberInfo m in abstract_methods){
-                                       MethodInfo mi = (MethodInfo) m;
-                                       
-                                       ParameterData pd = TypeManager.GetParameterData (mi);
-                                       Type [] types = pd.Types;
-                                       
-                                       pending_implementations [i].args [j] = types;
-                                       pending_implementations [i].mods [j] = null;
-                                       if (pd.Count > 0){
-                                               Parameter.Modifier [] pm = new Parameter.Modifier [pd.Count];
-                                               for (int k = 0; k < pd.Count; k++)
-                                                       pm [k] = pd.ParameterModifier (k);
-                                               pending_implementations [i].mods [j] = pm;
-                                       }
-                                               
-                                       j++;
-                               }
-                       }
                }
 
                struct MissingInterfacesInfo {
@@ -415,9 +416,10 @@ namespace Mono.CSharp {
                                        } else if ((need_proxy == null) && (name != mname))
                                                continue;
 
-                                       if (!TypeManager.IsEqual (ret_type, m.ReturnType) &&
-                                           !(ret_type == null && m.ReturnType == TypeManager.void_type) &&
-                                           !(m.ReturnType == null && ret_type == TypeManager.void_type))
+                                       Type rt = TypeManager.TypeToCoreType (m.ReturnType);
+                                       if (!TypeManager.IsEqual (ret_type, rt) &&
+                                           !(ret_type == null && rt == TypeManager.void_type) &&
+                                           !(rt == null && ret_type == TypeManager.void_type))
                                                continue;
 
                                        //
@@ -456,7 +458,7 @@ namespace Mono.CSharp {
                                                bool name_matches = false;
                                                if (name == mname || mname == tm.get_indexer_name || mname == tm.set_indexer_name)
                                                        name_matches = true;
-                                               
+
                                                if ((t == null) && (need_proxy != null) && !name_matches)
                                                        tm.need_proxy [i] = need_proxy;
                                                else 
@@ -532,7 +534,7 @@ namespace Mono.CSharp {
                        MethodSignature ms;
                        
                        Type [] args = TypeManager.GetParameterData (mi).Types;
-                       ms = new MethodSignature (mi.Name, mi.ReturnType, args);
+                       ms = new MethodSignature (mi.Name, TypeManager.TypeToCoreType (mi.ReturnType), args);
                        MemberList list = TypeContainer.FindMembers (
                                container.TypeBuilder.BaseType, MemberTypes.Method | MemberTypes.Property,
                                BindingFlags.Public | BindingFlags.Instance,
@@ -544,17 +546,14 @@ namespace Mono.CSharp {
                        if (TypeManager.ImplementsInterface (container.TypeBuilder.BaseType, iface_type))
                                return true;
 
-                       //
-                       // FIXME: We should be creating fewer proxies.  The runtime can handle most cases.  
-                       //        At worst, if we can't avoid creating the proxy, we may need to make the 
-                       //        proxy use Callvirt.
-                       //
                        MethodInfo base_method = (MethodInfo) list [0];
 
                        if (base_method.DeclaringType.IsInterface)
                                return false;
 
                        if (!base_method.IsAbstract && !base_method.IsVirtual)
+                               // FIXME: We can avoid creating a proxy if base_method can be marked 'final virtual' instead.
+                               //        However, it's too late now, the MethodBuilder has already been created (see bug 377519)
                                DefineProxy (iface_type, base_method, mi, args);
 
                        return true;