2005-05-06 Martin Baulig <martin@ximian.com>
[mono.git] / mcs / gmcs / typemanager.cs
index cfd7e72fc2d41d692cfb09fca0619992537efca8..6fa5127dbe0a066c3309ff3a1668d2375a957174 100644 (file)
@@ -706,7 +706,6 @@ public partial class TypeManager {
        public static Type GetNestedType (Type t, string name)
        {
                object ret = null;
-               Report.Debug (64, "GET NESTED TYPE", t, t.FullName, t.Name, name);
                if (!type_hash.Lookup (t, name, out ret)) {
                        string lookup = t.FullName + "+" + name;
                        ret = t.Module.GetType (lookup);
@@ -912,41 +911,45 @@ public partial class TypeManager {
                return mb.DeclaringType.FullName.Replace ('+', '.') + '.' + name;
        }
 
-       static public string GetFullName (Type t)
+       private static void GetFullName_recursed (StringBuilder sb, Type t, bool recursed)
        {
-               if (t.FullName == null)
-                       return t.Name;
-
-               string name = t.FullName.Replace ('+', '.');
+               if (t.IsGenericParameter) {
+                       sb.Append (t.Name);
+                       return;
+               }
 
-               DeclSpace tc = LookupDeclSpace (t);
-               if ((tc != null) && tc.IsGeneric) {
-                       TypeParameter[] tparam = tc.TypeParameters;
+               if (t.DeclaringType != null) {
+                       GetFullName_recursed (sb, t.DeclaringType, true);
+                       sb.Append (".");
+               }
 
-                       StringBuilder sb = new StringBuilder (name);
-                       sb.Append ("<");
-                       for (int i = 0; i < tparam.Length; i++) {
-                               if (i > 0)
-                                       sb.Append (",");
-                               sb.Append (tparam [i].Name);
+               if (!recursed) {
+                       string ns = t.Namespace;
+                       if ((ns != null) && (ns != "")) {
+                               sb.Append (ns);
+                               sb.Append (".");
                        }
-                       sb.Append (">");
-                       return sb.ToString ();
-               } else if (t.HasGenericArguments && !t.IsGenericInstance) {
-                       Type[] tparam = t.GetGenericArguments ();
+               }
+
+               sb.Append (SimpleName.RemoveGenericArity (t.Name));
 
-                       StringBuilder sb = new StringBuilder (name);
+               Type[] args = GetTypeArguments (t);
+               if (args.Length > 0) {
                        sb.Append ("<");
-                       for (int i = 0; i < tparam.Length; i++) {
+                       for (int i = 0; i < args.Length; i++) {
                                if (i > 0)
                                        sb.Append (",");
-                               sb.Append (tparam [i].Name);
+                               sb.Append (GetFullName (args [i]));
                        }
                        sb.Append (">");
-                       return sb.ToString ();
                }
+       }
 
-               return name;
+       static public string GetFullName (Type t)
+       {
+               StringBuilder sb = new StringBuilder ();
+               GetFullName_recursed (sb, t, false);
+               return sb.ToString ();
        }
 
        /// <summary>
@@ -2176,11 +2179,13 @@ public partial class TypeManager {
                        if (texpr == null)
                                return null;
 
-                       if (!new_ifaces.Contains (texpr.Type))
-                               new_ifaces.Add (texpr.Type);
+                       if (new_ifaces.Contains (texpr.Type))
+                               continue;
+
+                       new_ifaces.Add (texpr.Type);
                        
                        Type [] implementing = texpr.Type.GetInterfaces ();
-                       
+
                        foreach (Type imp in implementing){
                                if (!new_ifaces.Contains (imp))
                                        new_ifaces.Add (imp);
@@ -2199,7 +2204,6 @@ public partial class TypeManager {
        /// </summary>
        public static Type [] GetInterfaces (Type t)
        {
-               
                Type [] cached = iface_cache [t] as Type [];
                if (cached != null)
                        return cached;
@@ -2217,14 +2221,18 @@ public partial class TypeManager {
                if (t.IsArray)
                        t = TypeManager.array_type;
                
-               if (t is TypeBuilder){
+               if ((t is TypeBuilder) || t.IsGenericInstance) {
                        Type [] base_ifaces;
                        
                        if (t.BaseType == null)
                                base_ifaces = NoTypes;
                        else
                                base_ifaces = GetInterfaces (t.BaseType);
-                       Type[] type_ifaces = (Type []) builder_to_ifaces [t];
+                       Type[] type_ifaces;
+                       if (t.IsGenericInstance)
+                               type_ifaces = t.GetInterfaces ();
+                       else
+                               type_ifaces = (Type []) builder_to_ifaces [t];
                        if (type_ifaces == null)
                                type_ifaces = NoTypes;
 
@@ -2515,7 +2523,7 @@ public partial class TypeManager {
                                new Type [] { typeof (Type), typeof (bool)},
                                null);
                        if (declare_local_method == null){
-                               Report.Warning (-24, new Location (-1),
+                               Report.Warning (-30, new Location (-1),
                                                "This version of the runtime does not support making pinned local variables.  " +
                                        "This code may cause errors on a runtime with a moving GC");
                                return ig.DeclareLocal (t);
@@ -2613,40 +2621,6 @@ public partial class TypeManager {
                internal Assembly invocation_assembly;
                internal IList almost_match;
 
-               private bool CheckValidFamilyAccess (bool is_static, MemberInfo m)
-               {
-                       if (invocation_type == null)
-                               return false;
-
-                       Debug.Assert (IsNestedFamilyAccessible (invocation_type, m.DeclaringType));
-
-                       if (is_static)
-                               return true;
-                       
-                       // A nested class has access to all the protected members visible
-                       // to its parent.
-                       if (qualifier_type != null
-                           && TypeManager.IsNestedChildOf (invocation_type, qualifier_type))
-                               return true;
-
-                       if (invocation_type == m.DeclaringType
-                           || invocation_type.IsSubclassOf (m.DeclaringType)) {
-                               // Although a derived class can access protected members of
-                               // its base class it cannot do so through an instance of the
-                               // base class (CS1540).
-                               // => Ancestry should be: declaring_type ->* invocation_type
-                               //      ->*  qualified_type
-                               if (qualifier_type == null
-                                   || qualifier_type == invocation_type
-                                   || qualifier_type.IsSubclassOf (invocation_type))
-                                       return true;
-                       }
-       
-                       if (almost_match != null)
-                               almost_match.Add (m);
-                       return false;
-               }
-
                bool Filter (MethodBase mb, object filter_criteria)
                {
                        MethodAttributes ma = mb.Attributes & MethodAttributes.MemberAccessMask;