2002-11-16 Martin Baulig <martin@ximian.com>
[mono.git] / mcs / mcs / typemanager.cs
index b0ec7da1a07bcead28921d3676c5f912c91f178c..e8d3e9bbd1ee6e9ec3ea9fdc1f2564babf0e52a5 100755 (executable)
@@ -9,6 +9,14 @@
 // (C) 2001 Ximian, Inc (http://www.ximian.com)
 //
 //
+
+//
+// We will eventually remove the SIMPLE_SPEEDUP, and should never change 
+// the behavior of the compilation.  This can be removed if we rework
+// the code to get a list of namespaces available.
+//
+#define SIMPLE_SPEEDUP
+
 using System;
 using System.Globalization;
 using System.Collections;
@@ -478,6 +486,8 @@ public class TypeManager {
                return null;
        }
 
+       static Hashtable negative_hits = new Hashtable ();
+       
        //
        // This function is used when you want to avoid the lookups, and want to go
        // directly to the source.  This will use the cache.
@@ -517,6 +527,11 @@ public class TypeManager {
                if (t != null)
                        return t;
 
+#if SIMPLE_SPEEDUP
+               if (negative_hits.Contains (name))
+                       return null;
+#endif
+               
                //
                // Optimization: ComposedCast will work with an existing type, and might already have the
                // full name of the type, so the full system lookup can probably be avoided.
@@ -539,6 +554,13 @@ public class TypeManager {
                                types [name] = t;
                                return t;
                        } 
+
+                       //
+                       // We know that System.Object does not have children, and since its the parent of 
+                       // all the objects, it always gets probbed for inner classes. 
+                       //
+                       if (top_level_type == "System.Object")
+                               return null;
                        
                        string newt = top_level_type + "+" + String.Join ("+", elements, n, count - n);
                        t = LookupTypeDirect (newt);
@@ -546,6 +568,10 @@ public class TypeManager {
                                types [newt] = t;
                        return t;
                }
+
+#if SIMPLE_SPEEDUP
+               negative_hits [name] = true;
+#endif
                return null;
        }
 
@@ -575,8 +601,24 @@ public class TypeManager {
                                namespaces [ns] = ns;
                        }
                }
+               Console.WriteLine ("Namespaces: " + namespaces.Count);
                return namespaces;
        }
+
+       public static void GetAllTypes ()
+       {
+               Hashtable namespaces = new Hashtable ();
+
+               foreach (Assembly a in assemblies){
+                       foreach (Type t in a.GetTypes ()){
+                       }
+               }
+
+               foreach (ModuleBuilder mb in modules){
+                       foreach (Type t in mb.GetTypes ()){
+                       }
+               }
+       }
        
        /// <summary>
        ///   Returns the C# name of a type if possible, or the full type name otherwise
@@ -1416,57 +1458,6 @@ public class TypeManager {
                return true;
        }
 
-       //
-       // FIXME: we need to return the accessors depending on whether
-       // they are visible or not.
-       //
-       static public MethodInfo [] GetAccessors (PropertyInfo pi)
-       {
-               MethodInfo [] ret;
-
-               if (pi is PropertyBuilder){
-                       Pair pair = (Pair) properties [pi];
-
-                       ret = new MethodInfo [2];
-                       ret [0] = (MethodInfo) pair.First;
-                       ret [1] = (MethodInfo) pair.Second;
-
-                       return ret;
-               } else {
-                       MethodInfo [] mi = new MethodInfo [2];
-
-                       //
-                       // Why this and not pi.GetAccessors?
-                       // Because sometimes index 0 is the getter
-                       // sometimes it is 1
-                       //
-                       mi [0] = pi.GetGetMethod (true);
-                       mi [1] = pi.GetSetMethod (true);
-
-                       return mi;
-               }
-       }
-
-       static public MethodInfo GetPropertyGetter (PropertyInfo pi)
-       {
-               if (pi is PropertyBuilder){
-                       Pair de = (Pair) properties [pi];
-
-                       return (MethodInfo) de.Second;
-               } else
-                       return pi.GetSetMethod ();
-       }
-
-       static public MethodInfo GetPropertySetter (PropertyInfo pi)
-       {
-               if (pi is PropertyBuilder){
-                       Pair de = (Pair) properties [pi];
-
-                       return (MethodInfo) de.First;
-               } else
-                       return pi.GetGetMethod ();
-       }
-
        /// <summary>
        ///   Given an array of interface types, expand and eliminate repeated ocurrences
        ///   of an interface.  
@@ -2005,7 +1996,7 @@ public class TypeManager {
 
                                // Although a derived class can access protected members of its base class
                                // it cannot do so through an instance of the base class (CS1540).
-                               if ((closure_invocation_type != closure_start_type) &&
+                               if (!mb.IsStatic && (closure_invocation_type != closure_start_type) &&
                                    closure_invocation_type.IsSubclassOf (closure_start_type))
                                        return false;
 
@@ -2052,7 +2043,7 @@ public class TypeManager {
 
                                // Although a derived class can access protected members of its base class
                                // it cannot do so through an instance of the base class (CS1540).
-                               if ((closure_invocation_type != closure_start_type) &&
+                               if (!fi.IsStatic && (closure_invocation_type != closure_start_type) &&
                                    closure_invocation_type.IsSubclassOf (closure_start_type))
                                        return false;
 
@@ -2064,7 +2055,8 @@ public class TypeManager {
                }
 
                //
-               // EventInfos and PropertyInfos, return true
+               // EventInfos and PropertyInfos, return true because they lack permission
+               // informaiton, so we need to check later on the methods.
                //
                return true;
        }
@@ -2143,7 +2135,7 @@ public class TypeManager {
                        //
                        if (invocation_type != null){
                                if (invocation_type == current_type){
-                                       private_ok = (bf & BindingFlags.NonPublic) != 0;
+                                       private_ok = true;
                                } else
                                        private_ok = always_ok_flag;