Anirban Bhattacharjee <banirban@novell.com>
[mono.git] / mcs / mbas / pending.cs
index 4bfaa6ff15aa4a548b72b1f991673c36ae749575..d32b46ab279cd86a761cd897e92188dfb9a421de 100644 (file)
@@ -15,7 +15,7 @@ using System.Collections;
 using System.Reflection;
 using System.Reflection.Emit;
 
-namespace Mono.CSharp {
+namespace Mono.MonoBASIC {
 
        struct TypeAndMethods {
                public Type          type;
@@ -83,7 +83,7 @@ namespace Mono.CSharp {
                        Type current_type = t;
                        
                        do {
-                               MemberInfo [] mi;
+                               MemberList mi;
                                
                                mi = TypeContainer.FindMembers (
                                        current_type, MemberTypes.Method,
@@ -99,14 +99,10 @@ namespace Mono.CSharp {
                                                searching = false;
                                }
 
-                               if (mi == null)
+                               if (mi.Count == 0)
                                        continue;
 
-                               int count = mi.Length;
-                               if (count == 0)
-                                       continue;
-
-                               if (count == 1 && !(mi [0] is MethodBase))
+                               if (mi.Count == 1 && !(mi [0] is MethodBase))
                                        searching = false;
                                else 
                                        list = TypeManager.CopyNewMethods (list, mi);
@@ -138,14 +134,14 @@ namespace Mono.CSharp {
                                foreach (Type t in ifaces){
                                        MethodInfo [] mi;
 
-                                       if (t is TypeBuilder){
+                                       /*if (t is TypeBuilder){
                                                Interface iface;
 
                                                iface = TypeManager.LookupInterface (t);
                                                
-                                               mi = iface.GetMethods ();
-                                       } else
-                                               mi = t.GetMethods ();
+                                               mi = iface.GetMethods (container);
+                                       } else*/
+                                       mi = t.GetMethods ();
 
                                        int count = mi.Length;
                                        pending_implementations [i].type = t;
@@ -210,6 +206,7 @@ namespace Mono.CSharp {
                        // TypeBuilder.
                        //
                        ifaces = type_builder.GetInterfaces ();
+
 #if DEBUG
                        {
                                Type x = type_builder;
@@ -314,7 +311,7 @@ namespace Mono.CSharp {
                        foreach (TypeAndMethods tm in pending_implementations){
                                if (!(t == null || tm.type == t))
                                        continue;
-
+                               
                                int i = 0;
                                foreach (MethodInfo m in tm.methods){
                                        if (m == null){
@@ -437,6 +434,45 @@ namespace Mono.CSharp {
                        container.TypeBuilder.DefineMethodOverride (proxy, iface_method);
                }
                
+               static bool IsPropertyGetMethod (string m)
+               {
+                       return (m.Substring (0, 4) == "get_");  
+               }
+
+               static bool IsPropertySetMethod (string m)
+               {
+                       return (m.Substring (0, 4) == "set_");  
+               }
+
+               MethodInfo FindExplicitImplementation (string iface_name, string method_name)
+               {
+                       if (container.Properties != null) {
+                               foreach (Property p in container.Properties) 
+                               {
+                                       if (p.Implements != null) {                                     
+                                               if (IsPropertyGetMethod (method_name) && (container.Namespace.Name +  "." + p.Implements.ToString() == iface_name + "." + method_name.Substring(4))) 
+                                                               return p.PropertyBuilder.GetGetMethod(true);
+
+                                               if (IsPropertySetMethod (method_name) && (container.Namespace.Name +  "." + p.Implements.ToString() == iface_name + "." + method_name.Substring(4))) 
+                                                               return p.PropertyBuilder.GetSetMethod(true);
+                                       }
+                               }
+                       }
+
+                       if (container.Methods != null) 
+                       {
+                               foreach (Method m in container.Methods) 
+                               {
+                                       if (m.Implements != null) 
+                                       {                                       
+                                               if (container.Namespace.Name +  "." + m.Implements.ToString() == iface_name + "." + method_name)
+                                                       return (MethodInfo) m.MethodBuilder;
+                                       }
+                               }
+                       }
+                       return null;
+               }
+
                /// <summary>
                ///   This function tells whether one of our parent classes implements
                ///   the given method (which turns out, it is valid to have an interface
@@ -445,19 +481,27 @@ namespace Mono.CSharp {
                bool ParentImplements (Type iface_type, MethodInfo mi)
                {
                        MethodSignature ms;
+                       MethodInfo mr;
                        
                        Type [] args = TypeManager.GetArgumentTypes (mi);
+
                        ms = new MethodSignature (mi.Name, mi.ReturnType, args);
-                       MemberInfo [] list = TypeContainer.FindMembers (
+                       MemberList list = TypeContainer.FindMembers (
                                container.TypeBuilder.BaseType, MemberTypes.Method | MemberTypes.Property,
                                BindingFlags.Public | BindingFlags.Instance,
                                MethodSignature.method_signature_filter, ms);
 
-                       if (list == null || list.Length == 0)
-                               return false;
+                       if (list.Count == 0) 
+                       {
+                               mr = FindExplicitImplementation (iface_type.ToString(), mi.Name);
+                               if (mr == null)
+                                       return false;
+                       }
+                       else
+                               mr = (MethodInfo) list[0];
 
-                       DefineProxy (iface_type, (MethodInfo) list [0], mi, args);
-                       return true;
+                       DefineProxy (iface_type, mr, mi, args);
+                       return true;                                            
                }
 
                /// <summary>
@@ -502,9 +546,9 @@ namespace Mono.CSharp {
                                                        type.FullName + "." + mi.Name + "'" + extra);
                                        } else {
                                                Report.Error (
-                                                       534, container.Location,
+                                                       30610, container.Location,
                                                        "`" + container.Name + "' does not implement " +
-                                                       "inherited abstract member `" +
+                                                       "inherited 'MustOverride' member `" +
                                                        type.FullName + "." + mi.Name + "'");
                                        }
                                        errors = true;