Author: raja
Date: 2005-12-09 06:23:51 -0500 (Fri, 09 Dec 2005)
New Revision: 54157

Modified:
   trunk/mcs/gmcs/ChangeLog
   trunk/mcs/gmcs/attribute.cs
   trunk/mcs/gmcs/class.cs
   trunk/mcs/gmcs/decl.cs
   trunk/mcs/gmcs/ecore.cs
   trunk/mcs/gmcs/generic.cs
   trunk/mcs/gmcs/report.cs
   trunk/mcs/gmcs/typemanager.cs
Log:
* generic.cs (DropGenericTypeArguments): New.  Captures the common
pattern: if (t.IsGenericInstance) t = t.GetGenericTypeDefinition ();
* attribute.cs, class.cs, decl.cs, ecore.cs: Use it.
* generic.cs, report.cs, typemanager.cs: Likewise.


Modified: trunk/mcs/gmcs/ChangeLog
===================================================================
--- trunk/mcs/gmcs/ChangeLog    2005-12-09 11:17:30 UTC (rev 54156)
+++ trunk/mcs/gmcs/ChangeLog    2005-12-09 11:23:51 UTC (rev 54157)
@@ -1,3 +1,10 @@
+2005-12-09  Raja R Harinath  <[EMAIL PROTECTED]>
+
+       * generic.cs (DropGenericTypeArguments): New.  Captures the common
+       pattern: if (t.IsGenericInstance) t = t.GetGenericTypeDefinition ();
+       * attribute.cs, class.cs, decl.cs, ecore.cs: Use it.
+       * generic.cs, report.cs, typemanager.cs: Likewise.
+
 2005-12-08  Martin Baulig  <[EMAIL PROTECTED]>
 
        * generic.cs (TypeArguments.Resolve): Added CS1547 check.

Modified: trunk/mcs/gmcs/attribute.cs
===================================================================
--- trunk/mcs/gmcs/attribute.cs 2005-12-09 11:17:30 UTC (rev 54156)
+++ trunk/mcs/gmcs/attribute.cs 2005-12-09 11:23:51 UTC (rev 54157)
@@ -1663,8 +1663,7 @@
 
                static bool AnalyzeTypeCompliance (Type type)
                {
-                       if (type.IsGenericInstance)
-                               type = type.GetGenericTypeDefinition ();
+                       type = TypeManager.DropGenericTypeArguments (type);
                        DeclSpace ds = TypeManager.LookupDeclSpace (type);
                        if (ds != null)
                                return ds.IsClsComplianceRequired (ds);

Modified: trunk/mcs/gmcs/class.cs
===================================================================
--- trunk/mcs/gmcs/class.cs     2005-12-09 11:17:30 UTC (rev 54156)
+++ trunk/mcs/gmcs/class.cs     2005-12-09 11:23:51 UTC (rev 54157)
@@ -1467,9 +1467,7 @@
 
                        Type parent = ptype;
                        if (parent != null) {
-                               if (parent.IsGenericInstance)
-                                       parent = 
parent.GetGenericTypeDefinition ();
-
+                               parent = TypeManager.DropGenericTypeArguments 
(parent);
                                TypeContainer ptc = 
TypeManager.LookupTypeContainer (parent);
                                if ((ptc != null) && 
!ptc.CheckRecursiveDefinition (this))
                                        return false;
@@ -1477,11 +1475,7 @@
 
                        if (iface_exprs != null) {
                                foreach (TypeExpr iface in iface_exprs) {
-                                       Type itype = iface.Type;
-
-                                       if (itype.IsGenericInstance)
-                                               itype = 
itype.GetGenericTypeDefinition ();
-
+                                       Type itype = 
TypeManager.DropGenericTypeArguments (iface.Type);
                                        TypeContainer ptc = 
TypeManager.LookupTypeContainer (itype);
                                        if ((ptc != null) && 
!ptc.CheckRecursiveDefinition (this))
                                                return false;

Modified: trunk/mcs/gmcs/decl.cs
===================================================================
--- trunk/mcs/gmcs/decl.cs      2005-12-09 11:17:30 UTC (rev 54156)
+++ trunk/mcs/gmcs/decl.cs      2005-12-09 11:23:51 UTC (rev 54157)
@@ -889,9 +889,7 @@
                        else
                                tb = TypeBuilder;
 
-                       if (check_type.IsGenericInstance)
-                               check_type = 
check_type.GetGenericTypeDefinition ();
-
+                       check_type = TypeManager.DropGenericTypeArguments 
(check_type);
                        if (check_type == tb)
                                return true;
 
@@ -1098,8 +1096,7 @@
                        for (Type current_type = TypeBuilder;
                             current_type != null && current_type != 
TypeManager.object_type;
                             current_type = current_type.BaseType) {
-                               if (current_type.IsGenericInstance)
-                                       current_type = 
current_type.GetGenericTypeDefinition ();
+                               current_type = 
TypeManager.DropGenericTypeArguments (current_type);
                                if (current_type is TypeBuilder) {
                                        DeclSpace decl = this;
                                        if (current_type != TypeBuilder)

Modified: trunk/mcs/gmcs/ecore.cs
===================================================================
--- trunk/mcs/gmcs/ecore.cs     2005-12-09 11:17:30 UTC (rev 54156)
+++ trunk/mcs/gmcs/ecore.cs     2005-12-09 11:23:51 UTC (rev 54157)
@@ -1931,9 +1931,7 @@
                                return false;
 
                        while (parent != null) {
-                               if (parent.IsGenericInstance)
-                                       parent = 
parent.GetGenericTypeDefinition ();
-
+                               parent = TypeManager.DropGenericTypeArguments 
(parent);
                                if (TypeManager.IsNestedChildOf (t, parent))
                                        return true;
 

Modified: trunk/mcs/gmcs/generic.cs
===================================================================
--- trunk/mcs/gmcs/generic.cs   2005-12-09 11:17:30 UTC (rev 54156)
+++ trunk/mcs/gmcs/generic.cs   2005-12-09 11:23:51 UTC (rev 54157)
@@ -1967,9 +1967,7 @@
 
                public static TypeContainer LookupGenericTypeContainer (Type t)
                {
-                       while (t.IsGenericInstance)
-                               t = t.GetGenericTypeDefinition ();
-
+                       t = DropGenericTypeArguments (t);
                        return LookupTypeContainer (t);
                }
 
@@ -2033,6 +2031,16 @@
                                return t.GetGenericArguments ();
                }
 
+               public static Type DropGenericTypeArguments (Type t)
+               {
+                       if (!t.IsGenericType)
+                               return t;
+                       // Micro-optimization: a generic typebuilder is always 
a generic type definition
+                       if (t is TypeBuilder)
+                               return t;
+                       return t.GetGenericTypeDefinition ();
+               }
+
                //
                // Whether `array' is an array of T and `enumerator' is 
`IEnumerable<T>'.
                // For instance "string[]" -> "IEnumerable<string>".
@@ -2260,14 +2268,12 @@
                        int tcount = GetNumberOfTypeArguments (type);
                        int pcount = GetNumberOfTypeArguments (parent);
 
-                       if (type.IsGenericInstance)
-                               type = type.GetGenericTypeDefinition ();
-                       if (parent.IsGenericInstance)
-                               parent = parent.GetGenericTypeDefinition ();
-
                        if (tcount != pcount)
                                return false;
 
+                       type = DropGenericTypeArguments (type);
+                       parent = DropGenericTypeArguments (parent);
+
                        return type.Equals (parent);
                }
 
@@ -2582,11 +2588,7 @@
 
                public static bool IsNullableType (Type t)
                {
-                       if (!t.IsGenericInstance)
-                               return false;
-
-                       Type gt = t.GetGenericTypeDefinition ();
-                       return gt == generic_nullable_type;
+                       return generic_nullable_type == 
DropGenericTypeArguments (t);
                }
        }
 

Modified: trunk/mcs/gmcs/report.cs
===================================================================
--- trunk/mcs/gmcs/report.cs    2005-12-09 11:17:30 UTC (rev 54156)
+++ trunk/mcs/gmcs/report.cs    2005-12-09 11:23:51 UTC (rev 54157)
@@ -335,8 +335,7 @@
 
                static public void SymbolRelatedToPreviousError (Type type)
                {
-                       if (type.IsGenericInstance)
-                               type = type.GetGenericTypeDefinition ();
+                       type = TypeManager.DropGenericTypeArguments (type);
 
                        if (type.IsGenericParameter) {
                                TypeParameter tp = 
TypeManager.LookupTypeParameter (type);

Modified: trunk/mcs/gmcs/typemanager.cs
===================================================================
--- trunk/mcs/gmcs/typemanager.cs       2005-12-09 11:17:30 UTC (rev 54156)
+++ trunk/mcs/gmcs/typemanager.cs       2005-12-09 11:23:51 UTC (rev 54157)
@@ -1428,9 +1428,7 @@
 
        public static bool IsDelegateType (Type t)
        {
-               if (t.IsGenericInstance)
-                       t = t.GetGenericTypeDefinition ();
-
+               t = DropGenericTypeArguments (t);
                if (t.IsSubclassOf (TypeManager.delegate_type))
                        return true;
                else
@@ -1600,14 +1598,7 @@
                        return true;
                }
 
-               if (type.IsGenericInstance && parent.IsGenericInstance) {
-                       if (type.GetGenericTypeDefinition () != 
parent.GetGenericTypeDefinition ())
-                               return false;
-
-                       return true;
-               }
-
-               return false;
+               return DropGenericTypeArguments (type) == 
DropGenericTypeArguments (parent);
        }
 
        public static bool IsFamilyAccessible (Type type, Type parent)
@@ -2341,9 +2332,7 @@
        /// </remarks>
        public static string IndexerPropertyName (Type t)
        {
-               if (t.IsGenericInstance)
-                       t = t.GetGenericTypeDefinition ();
-
+               t = DropGenericTypeArguments (t);
                if (t is TypeBuilder) {
                        TypeContainer tc = t.IsInterface ? LookupInterface (t) 
: LookupTypeContainer (t);
                        return tc == null ? TypeContainer.DefaultIndexerName : 
tc.IndexerName;

_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches

Reply via email to