Anirban Bhattacharjee <banirban@novell.com>
[mono.git] / mcs / mbas / typemanager.cs
index 6b1d0ba8565f4150cda9e224a4a4a455ad2f9cfe..9d34c5882953cdecaaed91f2c7abbb95975d71fd 100644 (file)
@@ -160,7 +160,13 @@ public class TypeManager {
        //  Keeps a list of module builders. We used this to do lookups
        //  on the modulebuilder using GetType -- needed for arrays
        // </remarks>
-       static ModuleBuilder [] modules;
+       
+       // This is changed from list of ModuleBuilders 
+       // to list of Modules for getting addmodule 
+       // compiler option working
+       // Anirban - 13.07.2004
+
+       static System.Reflection.Module [] modules;
 
        // <remarks>
        //   This is the type_cache from the assemblies to avoid
@@ -454,10 +460,10 @@ public class TypeManager {
        /// <summary>
        ///  Registers a module builder to lookup types from
        /// </summary>
-       public static void AddModule (ModuleBuilder mb)
+       public static void AddModule (System.Reflection.Module mb)
        {
                int top = modules != null ? modules.Length : 0;
-               ModuleBuilder [] n = new ModuleBuilder [top + 1];
+               System.Reflection.Module [] n = new System.Reflection.Module [top + 1];
 
                if (modules != null)
                        modules.CopyTo (n, 0);
@@ -465,7 +471,6 @@ public class TypeManager {
                modules = n;
        }
 
-
        private class StandardModule {
                public readonly string Namespace;
                public readonly string Name;
@@ -485,7 +490,12 @@ public class TypeManager {
 
                if (standardModules != null)
                        standardModules.CopyTo (n, 0);
-               n [top] = new StandardModule(module.Namespace.Name, module.Name) ;
+               string name = module.Name;
+               int split = name.LastIndexOf('.'); 
+               if (split > 0)
+                       name = name.Substring(split+1);
+               n [top] = new StandardModule(module.Namespace.Name, name); 
+               // Console.WriteLine("Standard Module added: " + n [top]);
                standardModules = n;
        }
 
@@ -494,26 +504,41 @@ public class TypeManager {
        /// 
        private static void AddStandardModule(Type type)
        {
-               int top = standardModules != null ? standardModules.Length : 0;
-               StandardModule [] n = new StandardModule [top + 1];
+           object[] attributes = type.GetCustomAttributes(false);
+           for (int i = 0; i < attributes.Length; i ++) {
+                       if (attributes[i].ToString() == "Microsoft.VisualBasic.CompilerServices.StandardModuleAttribute") {
+                               int top = standardModules != null ? standardModules.Length : 0;
+                               StandardModule [] n = new StandardModule [top + 1];
 
-               if (standardModules != null)
-                       standardModules.CopyTo (n, 0);
-               n [top] = new StandardModule(type.Namespace, type.Name) ;
-               standardModules = n;
+                               if (standardModules != null)
+                                       standardModules.CopyTo (n, 0);
+                               n [top] = new StandardModule(type.Namespace, type.Name) ;
+                               standardModules = n;
+                               return;
+                       }
+        }
        }
 
        //
        // 
        //
-       public static Type[] GetPertinentStandardModules(string[] namespaces)
+       public static Type[] GetPertinentStandardModules(params string[] namespaces)
        {
                ArrayList list = new ArrayList();
                foreach(string Namespace in namespaces)
                { 
-                       for(int i = 0; i < standardModules.Length; i++)
-                               if (standardModules[i].Namespace == Namespace)
-                                       list.Add(LookupType(standardModules[i].ToString()));
+                       for(int i = 0; i < standardModules.Length; i++) {
+                               if (standardModules[i].Namespace == Namespace) {
+                                       string name = standardModules[i].ToString();
+                                       Type t = LookupType(name);
+                                       if (t == null) {
+                                               System.Console.WriteLine("Could not find standard module '" + name + "'"); 
+                                       }
+                                       else {
+                                               list.Add(t);
+                                       }
+                               }
+                       }
                }
                return (Type[])list.ToArray(typeof(Type));
        }
@@ -532,7 +557,7 @@ public class TypeManager {
                                        return t;
                        }
 
-                       foreach (ModuleBuilder mb in modules) {
+                       foreach (System.Reflection.Module mb in modules) {
                                t = mb.GetType (name, false, true);
                                if (t != null){
                                        return t;
@@ -622,8 +647,8 @@ public class TypeManager {
        {
                CaseInsensitiveHashtable namespaces = new CaseInsensitiveHashtable ();
 
-               foreach (Assembly a in assemblies){
-                       foreach (Type t in a.GetTypes ()){
+               foreach (Assembly a in assemblies) {
+                       foreach (Type t in a.GetTypes ()) {
                                string ns = t.Namespace;
 
                                if (namespaces.Contains (ns))
@@ -632,8 +657,8 @@ public class TypeManager {
                        }
                }
 
-               foreach (ModuleBuilder mb in modules){
-                       foreach (Type t in mb.GetTypes ()){
+               foreach (System.Reflection.Module mb in modules) {
+                       foreach (Type t in mb.GetTypes ()) {
                                string ns = t.Namespace;
 
                                if (namespaces.Contains (ns))
@@ -641,6 +666,7 @@ public class TypeManager {
                                namespaces [ns] = ns;
                        }
                }
+
                return namespaces;
        }
        
@@ -1489,7 +1515,7 @@ public class TypeManager {
 
                        return (MethodInfo) de.Second;
                } else
-                       return pi.GetSetMethod ();
+                       return pi.GetSetMethod (true);
        }
 
        static public MethodInfo GetPropertySetter (PropertyInfo pi)
@@ -1499,7 +1525,7 @@ public class TypeManager {
 
                        return (MethodInfo) de.First;
                } else
-                       return pi.GetGetMethod ();
+                       return pi.GetGetMethod (true);
        }
 
        /// <summary>
@@ -2131,6 +2157,8 @@ public class TypeManager {
                
                ArrayList method_list = null;
                Type current_type = queried_type;
+               if (queried_type == null)
+                       throw new ArgumentNullException("queried_type");
                bool searching = (original_bf & BindingFlags.DeclaredOnly) == 0;
                bool private_ok;
                bool always_ok_flag = false;
@@ -2192,7 +2220,7 @@ public class TypeManager {
                        closure_queried_type = current_type;
 
                        Timer.StopTimer (TimerType.MemberLookup);
-bf |= BindingFlags.IgnoreCase;
+                       bf |= BindingFlags.IgnoreCase;
                        list = MemberLookup_FindMembers (current_type, mt, bf, name, out used_cache);
 
                        Timer.StartTimer (TimerType.MemberLookup);