Author: jbevain
Date: 2007-06-13 05:24:50 -0400 (Wed, 13 Jun 2007)
New Revision: 79388

Modified:
   trunk/cecil/linker/ChangeLog
   trunk/cecil/linker/Mono.Linker.Steps/CleanStep.cs
Log:
2007-06-12  Jb Evain  <[EMAIL PROTECTED]>

        * Mono.Linker.Steps/CleanStep.cs:
                Clean memberref that are not used anymore.


Modified: trunk/cecil/linker/ChangeLog
===================================================================
--- trunk/cecil/linker/ChangeLog        2007-06-13 09:22:52 UTC (rev 79387)
+++ trunk/cecil/linker/ChangeLog        2007-06-13 09:24:50 UTC (rev 79388)
@@ -1,5 +1,10 @@
 2007-06-12  Jb Evain  <[EMAIL PROTECTED]>
 
+       * Mono.Linker.Steps/CleanStep.cs:
+               Clean memberref that are not used anymore.
+
+2007-06-12  Jb Evain  <[EMAIL PROTECTED]>
+
        * Mono.Linker.Steps/AdjustVisibilityStep.cs,
          Mono.Linker.Steps/ResolveFromApiInfoStep.cs,
          Mono.Linker/Drivers.cs:

Modified: trunk/cecil/linker/Mono.Linker.Steps/CleanStep.cs
===================================================================
--- trunk/cecil/linker/Mono.Linker.Steps/CleanStep.cs   2007-06-13 09:22:52 UTC 
(rev 79387)
+++ trunk/cecil/linker/Mono.Linker.Steps/CleanStep.cs   2007-06-13 09:24:50 UTC 
(rev 79388)
@@ -42,10 +42,37 @@
 
                static void CleanAssembly (AssemblyDefinition asm)
                {
+                       CleanMemberReferences (asm.MainModule);
                        foreach (TypeDefinition type in asm.MainModule.Types)
                                CleanType (type);
                }
 
+               static void CleanMemberReferences (ModuleDefinition module)
+               {
+                       foreach (MemberReference reference in new ArrayList 
(module.MemberReferences)) {
+                               GenericInstanceType git = 
reference.DeclaringType as GenericInstanceType;
+                               if (git == null)
+                                       continue;
+
+                               foreach (TypeReference arg in 
git.GenericArguments)
+                                       if (!CheckType (module, arg))
+                                               module.MemberReferences.Remove 
(reference);
+                       }
+               }
+
+               static bool CheckType (ModuleDefinition module, TypeReference 
reference)
+               {
+                       TypeSpecification spec = reference as TypeSpecification;
+                       if (spec != null)
+                               return CheckType (module, spec.ElementType);
+
+                       TypeDefinition type = reference as TypeDefinition;
+                       if (type == null)
+                               return true;
+
+                       return module.Types.Contains (type);
+               }
+
                static void CleanType (TypeDefinition type)
                {
                        CleanNestedTypes (type);

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

Reply via email to