ecore.cs : Added support for Implicit numeric conversions
[mono.git] / mcs / mbas / typemanager.cs
index ee70fbfb37f1b5b3b7a231441955891e80fd2d0f..608ee89dfee433cef07a380b7c1808b59821cd9c 100644 (file)
@@ -148,6 +148,7 @@ public class TypeManager {
        static public ConstructorInfo void_decimal_ctor_five_args;
        static public ConstructorInfo void_datetime_ctor_ticks_arg;
        static public ConstructorInfo unverifiable_code_ctor;
+       static public ConstructorInfo default_member_ctor;
        
        // <remarks>
        //   Holds the Array of Assemblies that have been loaded
@@ -212,12 +213,6 @@ public class TypeManager {
        // <remarks>
        static Hashtable method_internal_params;
 
-       // <remarks>
-       //  Keeps track of attribute types
-       // </remarks>
-
-       static Hashtable builder_to_attr;
-
        // <remarks>
        //  Keeps track of methods
        // </remarks>
@@ -306,10 +301,10 @@ public class TypeManager {
                user_types = new ArrayList ();
                
                types = new CaseInsensitiveHashtable ();
+               negative_hits = new CaseInsensitiveHashtable ();
                typecontainers = new CaseInsensitiveHashtable ();
                
                builder_to_declspace = new PtrHashtable ();
-               builder_to_attr = new PtrHashtable ();
                builder_to_method = new PtrHashtable ();
                method_arguments = new PtrHashtable ();
                method_internal_params = new PtrHashtable ();
@@ -393,11 +388,6 @@ public class TypeManager {
                builder_to_method.Add (builder, method);
        }
 
-       public static void RegisterAttrType (Type t, TypeContainer tc)
-       {
-               builder_to_attr.Add (t, tc);
-       }
-
        /// <summary>
        ///   Returns the TypeContainer whose Type is 't' or null if there is no
        ///   TypeContainer for 't' (ie, the Type comes from a library)
@@ -432,10 +422,10 @@ public class TypeManager {
        {
                return builder_to_declspace [t] as Enum;
        }
-       
-       public static TypeContainer LookupAttr (Type t)
+
+       public static TypeContainer LookupClass (Type t)
        {
-               return (TypeContainer) builder_to_attr [t];
+               return builder_to_declspace [t] as TypeContainer;
        }
        
        /// <summary>
@@ -574,6 +564,7 @@ public class TypeManager {
                return null;
        }
 
+       static CaseInsensitiveHashtable negative_hits;
        //
        // This function is used when you want to avoid the lookups, and want to go
        // directly to the source.  This will use the cache.
@@ -588,11 +579,13 @@ public class TypeManager {
                if (t != null)
                        return t;
 
+               if (negative_hits.Contains (name))
+                       return null;
                t = LookupTypeReflection (name);
                if (t == null)
-                       return null;
-
-               types [name] = t;
+                       negative_hits [name] = null;
+               else
+                       types [name] = t;
                return t;
        }
        
@@ -613,6 +606,9 @@ public class TypeManager {
                if (t != null)
                        return t;
 
+               if (negative_hits.Contains (name))
+                       return null;
+
                //
                // 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.
@@ -624,11 +620,16 @@ public class TypeManager {
                for (int n = 1; n <= count; n++){
                        string top_level_type = String.Join (".", elements, 0, n);
 
+                       if (negative_hits.Contains (top_level_type))
+                               continue;
+
                        t = (Type) types [top_level_type];
                        if (t == null){
                                t = LookupTypeReflection (top_level_type);
-                               if (t == null)
+                               if (t == null){
+                                       negative_hits [top_level_type] = null;
                                        continue;
+                               }
                        }
                        
                        if (count == n){
@@ -637,11 +638,14 @@ public class TypeManager {
                        } 
                        
                        string newt = top_level_type + "+" + String.Join ("+", elements, n, count - n);
-                       t = LookupTypeDirect (newt);
-                       if (t != null)
-                               types [newt] = t;
+                       t = LookupTypeReflection (newt);
+                       if (t == null)
+                               negative_hits [name] = null;
+                       else
+                               types [name] = t;
                        return t;
                }
+               negative_hits [name] = null;
                return null;
        }
 
@@ -1030,6 +1034,8 @@ public class TypeManager {
                unverifiable_code_ctor = GetConstructor (
                        unverifiable_code_type, void_arg);
                
+               default_member_ctor = GetConstructor (
+                       default_member_type, string_);
        }
 
        const BindingFlags instance_and_static = BindingFlags.Static | BindingFlags.Instance;
@@ -1402,7 +1408,7 @@ public class TypeManager {
                        indexer_arguments.Add (indexer, types);
                        return types;
                }
-               /*else \r
+               /*else 
                {
                        ParameterInfo [] pi = indexer.GetIndexParameters ();
                        // Property, not an indexer.
@@ -1863,17 +1869,17 @@ public class TypeManager {
                        if (t.IsInterface) {
                                Interface i = LookupInterface (t);
 
-                               if ((i == null) || (i.IndexerName == null))
+                               if ((i == null) || (i.DefaultPropName == null))
                                        return "Item";
 
-                               return i.IndexerName;
+                               return i.DefaultPropName;
                        } else {
                                TypeContainer tc = LookupTypeContainer (t);
 
-                               if ((tc == null) || (tc.IndexerName == null))
+                               if ((tc == null) || (tc.DefaultPropName == null))
                                        return "Item";
 
-                               return tc.IndexerName;
+                               return tc.DefaultPropName;
                        }
                }