Author: jbevain
Date: 2007-06-06 06:51:02 -0400 (Wed, 06 Jun 2007)
New Revision: 78719

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

        * Mono.Linker.Steps/MarkStep.cs:
                Mark default constructor for serializable types.


Modified: trunk/cecil/linker/ChangeLog
===================================================================
--- trunk/cecil/linker/ChangeLog        2007-06-06 10:40:14 UTC (rev 78718)
+++ trunk/cecil/linker/ChangeLog        2007-06-06 10:51:02 UTC (rev 78719)
@@ -1,5 +1,8 @@
 2007-06-06  Jb Evain  <[EMAIL PROTECTED]>
 
+       * Mono.Linker.Steps/MarkStep.cs:
+               Mark default constructor for serializable types.
+
        * Mono.Linker/LinkContext.cs:
          Mono.Linker.Steps/LoadReferences.cs:
                Use the name of the assembly as a key

Modified: trunk/cecil/linker/Mono.Linker.Steps/MarkStep.cs
===================================================================
--- trunk/cecil/linker/Mono.Linker.Steps/MarkStep.cs    2007-06-06 10:40:14 UTC 
(rev 78718)
+++ trunk/cecil/linker/Mono.Linker.Steps/MarkStep.cs    2007-06-06 10:51:02 UTC 
(rev 78719)
@@ -205,6 +205,9 @@
                        if (IsMulticastDelegate (td))
                                MarkMethodCollection (td.Constructors);
 
+                       if (IsSerializable (td))
+                               MarkMethodsIf (td.Constructors, new 
MethodPredicate (IsDefaultConstructor));
+
                        MarkGenericParameters (td);
 
                        if (td.IsValueType)
@@ -213,19 +216,46 @@
                        foreach (TypeReference iface in td.Interfaces)
                                MarkType (iface);
 
-                       foreach (MethodDefinition ctor in td.Constructors)
-                               if (ctor.Name == MethodDefinition.Cctor)
-                                       MarkMethod (ctor);
+                       MarkMethodsIf (td.Constructors, new MethodPredicate 
(IsStaticConstructor));
 
-                       foreach (MethodDefinition meth in td.Methods)
-                               if (meth.IsVirtual)
-                                       MarkMethod (meth);
+                       MarkMethodsIf (td.Methods, new MethodPredicate 
(IsVirtual));
 
                        Annotations.Mark (td);
 
                        ApplyPreserveInfo (td);
                }
 
+               delegate bool MethodPredicate (MethodDefinition method);
+
+               void MarkMethodsIf (ICollection methods, MethodPredicate 
predicate)
+               {
+                       foreach (MethodDefinition method in methods)
+                               if (predicate (method))
+                                       MarkMethod (method);
+               }
+
+               static bool IsDefaultConstructor (MethodDefinition method)
+               {
+                       return method.Name == MethodDefinition.Ctor && 
method.IsSpecialName &&
+                               method.IsRuntimeSpecialName && 
method.Parameters.Count == 0;
+               }
+
+               static bool IsVirtual (MethodDefinition method)
+               {
+                       return method.IsVirtual;
+               }
+
+               static bool IsStaticConstructor (MethodDefinition method)
+               {
+                       return method.Name == MethodDefinition.Cctor && 
method.IsSpecialName &&
+                               method.IsRuntimeSpecialName;
+               }
+
+               static bool IsSerializable (TypeDefinition td)
+               {
+                       return (td.Attributes & TypeAttributes.Serializable) != 
0;
+               }
+
                static bool IsMulticastDelegate (TypeDefinition td)
                {
                        return td.BaseType != null && td.BaseType.FullName == 
"System.MulticastDelegate";

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

Reply via email to