Author: jbevain
Date: 2007-05-17 11:38:55 -0400 (Thu, 17 May 2007)
New Revision: 77570

Removed:
   trunk/cecil/linker/Mono.Linker/LinkException.cs
Modified:
   trunk/cecil/linker/Mono.Linker.csproj
   trunk/cecil/linker/Mono.Linker/AssemblyMarker.cs
   trunk/cecil/linker/Mono.Linker/BlacklistStep.cs
   trunk/cecil/linker/Mono.Linker/CleanStep.cs
   trunk/cecil/linker/Mono.Linker/Driver.cs
   trunk/cecil/linker/Mono.Linker/MarkStep.cs
   trunk/cecil/linker/Mono.Linker/MethodMarker.cs
   trunk/cecil/linker/Mono.Linker/OutputStep.cs
   trunk/cecil/linker/Mono.Linker/Pipeline.cs
   trunk/cecil/linker/Mono.Linker/SweepStep.cs
   trunk/cecil/linker/Mono.Linker/TypeMarker.cs
   trunk/cecil/linker/monolinker.exe.sources
Log:
code massage

Modified: trunk/cecil/linker/Mono.Linker/AssemblyMarker.cs
===================================================================
--- trunk/cecil/linker/Mono.Linker/AssemblyMarker.cs    2007-05-17 15:17:41 UTC 
(rev 77569)
+++ trunk/cecil/linker/Mono.Linker/AssemblyMarker.cs    2007-05-17 15:38:55 UTC 
(rev 77570)
@@ -26,6 +26,7 @@
 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 //
 
+using System;
 using System.Collections;
 
 using Mono.Cecil;
@@ -61,7 +62,7 @@
                public TypeMarker Mark (TypeDefinition type)
                {
                        if (type.Module != _assembly.MainModule)
-                               throw new LinkException ("Could not get a 
marker for a different assembly");
+                               throw new ArgumentException ("Could not get a 
marker for a different assembly");
 
                        TypeMarker marker = (TypeMarker) _typeMarkers 
[type.FullName];
                        if (marker == null) {

Modified: trunk/cecil/linker/Mono.Linker/BlacklistStep.cs
===================================================================
--- trunk/cecil/linker/Mono.Linker/BlacklistStep.cs     2007-05-17 15:17:41 UTC 
(rev 77569)
+++ trunk/cecil/linker/Mono.Linker/BlacklistStep.cs     2007-05-17 15:38:55 UTC 
(rev 77570)
@@ -46,9 +46,14 @@
 
                public void Process (LinkContext context)
                {
+                       if (context.CoreAction != AssemblyAction.Link)
+                               return;
+
                        foreach (DictionaryEntry entry in blacklists) {
-                               if (IsReferenced ((string) entry.Key, context))
-                                       context.Pipeline.AddStepBefore (typeof 
(MarkStep), GetResolveStep ((string) entry.Value));
+                               if (!IsReferenced ((string) entry.Key, context))
+                                       continue;
+
+                               context.Pipeline.AddStepBefore (typeof 
(MarkStep), GetResolveStep ((string) entry.Value));
                        }
                }
 

Modified: trunk/cecil/linker/Mono.Linker/CleanStep.cs
===================================================================
--- trunk/cecil/linker/Mono.Linker/CleanStep.cs 2007-05-17 15:17:41 UTC (rev 
77569)
+++ trunk/cecil/linker/Mono.Linker/CleanStep.cs 2007-05-17 15:38:55 UTC (rev 
77570)
@@ -88,34 +88,45 @@
                                        type.NestedTypes.Remove (nested);
                }
 
+               static MethodDefinition CheckMethod (TypeDefinition type, 
MethodDefinition method)
+               {
+                       if (method == null)
+                               return null;
+
+                       return type.Methods.Contains (method) ? method : null;
+               }
+
                static void CleanEvents (TypeDefinition type)
                {
-                       ArrayList events = new ArrayList (type.Events);
-                       foreach (EventDefinition evt in events) {
-                               if (evt.AddMethod != null && 
!type.Methods.Contains (evt.AddMethod))
-                                       evt.AddMethod = null;
-                               if (evt.InvokeMethod != null && 
!type.Methods.Contains (evt.InvokeMethod))
-                                       evt.InvokeMethod = null;
-                               if (evt.RemoveMethod != null && 
!type.Methods.Contains (evt.RemoveMethod))
-                                       evt.RemoveMethod = null;
+                       foreach (EventDefinition evt in new ArrayList 
(type.Events)) {
+                               evt.AddMethod = CheckMethod (type, 
evt.AddMethod);
+                               evt.InvokeMethod = CheckMethod (type, 
evt.InvokeMethod);
+                               evt.RemoveMethod = CheckMethod (type, 
evt.RemoveMethod);
 
-                               if (evt.AddMethod == null && evt.InvokeMethod 
== null && evt.RemoveMethod == null)
+                               if (!IsEventUsed (evt))
                                        type.Events.Remove (evt);
                        }
                }
 
+               static bool IsEventUsed (EventDefinition evt)
+               {
+                       return evt.AddMethod != null || evt.InvokeMethod != 
null || evt.RemoveMethod != null;
+               }
+
                static void CleanProperties (TypeDefinition type)
                {
-                       ArrayList properties = new ArrayList (type.Properties);
-                       foreach (PropertyDefinition prop in properties) {
-                               if (prop.GetMethod != null && 
!type.Methods.Contains (prop.GetMethod))
-                                       prop.GetMethod = null;
-                               if (prop.SetMethod != null && 
!type.Methods.Contains (prop.SetMethod))
-                                       prop.SetMethod = null;
+                       foreach (PropertyDefinition prop in new ArrayList 
(type.Properties)) {
+                               prop.GetMethod = CheckMethod (type, 
prop.GetMethod);
+                               prop.SetMethod = CheckMethod (type, 
prop.SetMethod);
 
-                               if (prop.GetMethod == null && prop.SetMethod == 
null)
+                               if (IsPropertyUsed (prop))
                                        type.Properties.Remove (prop);
                        }
                }
+
+               static bool IsPropertyUsed (PropertyDefinition prop)
+               {
+                       return prop.GetMethod != null || prop.SetMethod != null;
+               }
        }
 }

Modified: trunk/cecil/linker/Mono.Linker/Driver.cs
===================================================================
--- trunk/cecil/linker/Mono.Linker/Driver.cs    2007-05-17 15:17:41 UTC (rev 
77569)
+++ trunk/cecil/linker/Mono.Linker/Driver.cs    2007-05-17 15:38:55 UTC (rev 
77570)
@@ -142,7 +142,7 @@
                static void Usage ()
                {
                        Console.WriteLine (_linker);
-                       Console.WriteLine ("linker [options] -x|-a file 
[files...]");
+                       Console.WriteLine ("monolinker [options] -x|-a file 
[files...]");
 
                        Console.WriteLine ("   --about     About the {0}", 
_linker);
                        Console.WriteLine ("   --version   Print the version 
number of the {0}", _linker);

Deleted: trunk/cecil/linker/Mono.Linker/LinkException.cs
===================================================================
--- trunk/cecil/linker/Mono.Linker/LinkException.cs     2007-05-17 15:17:41 UTC 
(rev 77569)
+++ trunk/cecil/linker/Mono.Linker/LinkException.cs     2007-05-17 15:38:55 UTC 
(rev 77570)
@@ -1,43 +0,0 @@
-//
-// LinkException.cs
-//
-// Author:
-//   Jb Evain ([EMAIL PROTECTED])
-//
-// (C) 2006 Jb Evain
-//
-// Permission is hereby granted, free of charge, to any person obtaining
-// a copy of this software and associated documentation files (the
-// "Software"), to deal in the Software without restriction, including
-// without limitation the rights to use, copy, modify, merge, publish,
-// distribute, sublicense, and/or sell copies of the Software, and to
-// permit persons to whom the Software is furnished to do so, subject to
-// the following conditions:
-//
-// The above copyright notice and this permission notice shall be
-// included in all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
-// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
-// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
-// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-//
-
-namespace Mono.Linker {
-
-       using System;
-
-       public class LinkException : Exception {
-
-               internal LinkException (string s) : base (s)
-               {
-               }
-
-               internal LinkException (string s, Exception e) : base (s, e)
-               {
-               }
-       }
-}
\ No newline at end of file

Modified: trunk/cecil/linker/Mono.Linker/MarkStep.cs
===================================================================
--- trunk/cecil/linker/Mono.Linker/MarkStep.cs  2007-05-17 15:17:41 UTC (rev 
77569)
+++ trunk/cecil/linker/Mono.Linker/MarkStep.cs  2007-05-17 15:38:55 UTC (rev 
77570)
@@ -26,13 +26,13 @@
 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 //
 
+using System;
+using System.Collections;
+using Mono.Cecil;
+using Mono.Cecil.Cil;
+
 namespace Mono.Linker {
 
-       using System.Collections;
-
-       using Mono.Cecil;
-       using Mono.Cecil.Cil;
-
        public class MarkStep : IStep {
 
                LinkContext _context;
@@ -62,7 +62,7 @@
                void Process ()
                {
                        if (_queue.Count == 0)
-                               throw new LinkException ("No entry methods");
+                               throw new InvalidOperationException ("No entry 
methods");
 
                        while (_queue.Count > 0) {
                                MethodMarker method = (MethodMarker) 
_queue.Dequeue ();
@@ -93,9 +93,9 @@
                {
                        if (am.Processed)
                                return;
-                       else
-                               am.Processed = true;
 
+                       am.Processed = true;
+
                        MarkCustomAttributes (am.Assembly);
 
                        foreach (ModuleDefinition module in 
am.Assembly.Modules) {
@@ -124,9 +124,9 @@
                        FieldMarker fm = tm.Mark (fd);
                        if (fm.Processed)
                                return;
-                       else
-                               fm.Processed = true;
 
+                       fm.Processed = true;
+
                        MarkType (fd.DeclaringType);
                        MarkType (fd.FieldType);
                        MarkCustomAttributes (fd);
@@ -155,9 +155,9 @@
                        TypeMarker tm = am.Mark (td);
                        if (tm.Processed)
                                return;
-                       else
-                               tm.Processed = true;
 
+                       tm.Processed = true;
+
                        MarkType (td.BaseType);
                        if (td.DeclaringType != null)
                                MarkType (td.DeclaringType);
@@ -254,9 +254,9 @@
 
                        if (mm.Processed)
                                return;
-                       else
-                               mm.Processed = true;
 
+                       mm.Processed = true;
+
                        MarkType (md.DeclaringType);
                        MarkCustomAttributes (md);
 
@@ -276,13 +276,16 @@
                        MarkType (md.ReturnType.ReturnType);
                        MarkCustomAttributes (md.ReturnType);
 
-                       if (md.HasBody && (mm.Action == MethodAction.ForceParse 
||
-                               (am.Action == AssemblyAction.Link && mm.Action 
== MethodAction.Parse))) {
-
+                       if (md.HasBody && ShouldParseMethodBody (am, mm))
                                MarkMethodBody (md.Body);
-                       }
                }
 
+               static bool ShouldParseMethodBody (AssemblyMarker am, 
MethodMarker mm)
+               {
+                       return (mm.Action == MethodAction.ForceParse ||
+                               (am.Action == AssemblyAction.Link && mm.Action 
== MethodAction.Parse));
+               }
+
                static bool IsPropertyMethod (MethodDefinition md)
                {
                        return (md.SemanticsAttributes & 
MethodSemanticsAttributes.Getter) != 0 ||
@@ -324,14 +327,19 @@
                void MarkEvent (EventDefinition evt)
                {
                        MarkCustomAttributes (evt);
-                       if (evt.AddMethod != null)
-                               MarkMethod (evt.AddMethod);
-                       if (evt.InvokeMethod != null)
-                               MarkMethod (evt.InvokeMethod);
-                       if (evt.RemoveMethod != null)
-                               MarkMethod (evt.RemoveMethod);
+                       MarkMethodIfNotNull (evt.AddMethod);
+                       MarkMethodIfNotNull (evt.InvokeMethod);
+                       MarkMethodIfNotNull (evt.RemoveMethod);
                }
 
+               void MarkMethodIfNotNull (MethodReference method)
+               {
+                       if (method == null)
+                               return;
+
+                       MarkMethod (method);
+               }
+
                void MarkInstruction (Instruction instruction)
                {
                        switch (instruction.OpCode.OperandType) {

Modified: trunk/cecil/linker/Mono.Linker/MethodMarker.cs
===================================================================
--- trunk/cecil/linker/Mono.Linker/MethodMarker.cs      2007-05-17 15:17:41 UTC 
(rev 77569)
+++ trunk/cecil/linker/Mono.Linker/MethodMarker.cs      2007-05-17 15:38:55 UTC 
(rev 77570)
@@ -26,10 +26,10 @@
 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 //
 
+using Mono.Cecil;
+
 namespace Mono.Linker {
 
-       using Mono.Cecil;
-
        public class MethodMarker : Marker {
 
                MethodDefinition _method;

Modified: trunk/cecil/linker/Mono.Linker/OutputStep.cs
===================================================================
--- trunk/cecil/linker/Mono.Linker/OutputStep.cs        2007-05-17 15:17:41 UTC 
(rev 77569)
+++ trunk/cecil/linker/Mono.Linker/OutputStep.cs        2007-05-17 15:38:55 UTC 
(rev 77570)
@@ -36,18 +36,25 @@
 
                public void Process (LinkContext context)
                {
-                       if (!Directory.Exists(context.OutputDirectory))
-                               Directory.CreateDirectory 
(context.OutputDirectory);
+                       CheckOutputDirectory (context);
 
                        foreach (AssemblyMarker am in context.GetAssemblies())
                                OutputAssembly (am, context.OutputDirectory);
                }
 
+               static void CheckOutputDirectory (LinkContext context)
+               {
+                       if (Directory.Exists (context.OutputDirectory))
+                               return;
+
+                       Directory.CreateDirectory (context.OutputDirectory);
+               }
+
                static void OutputAssembly (AssemblyMarker am, string directory)
                {
                        switch (am.Action) {
                        case AssemblyAction.Link:
-                               AssemblyFactory.SaveAssembly (am.Assembly, 
GetAssemblyFile (am.Assembly, directory));
+                               AssemblyFactory.SaveAssembly (am.Assembly, 
GetAssemblyFileName (am.Assembly, directory));
                                break;
                        case AssemblyAction.Copy:
                                CopyAssembly 
(am.Assembly.MainModule.Image.FileInformation, directory);
@@ -60,7 +67,7 @@
                        File.Copy (fi.FullName, Path.Combine (directory, 
fi.Name), true);
                }
 
-               static string GetAssemblyFile (AssemblyDefinition assembly, 
string directory)
+               static string GetAssemblyFileName (AssemblyDefinition assembly, 
string directory)
                {
                        string file = assembly.Name.Name + (assembly.Kind == 
AssemblyKind.Dll ? ".dll" : ".exe");
                        return Path.Combine (directory, file);

Modified: trunk/cecil/linker/Mono.Linker/Pipeline.cs
===================================================================
--- trunk/cecil/linker/Mono.Linker/Pipeline.cs  2007-05-17 15:17:41 UTC (rev 
77569)
+++ trunk/cecil/linker/Mono.Linker/Pipeline.cs  2007-05-17 15:38:55 UTC (rev 
77570)
@@ -26,11 +26,11 @@
 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 //
 
+using System;
+using System.Collections;
+
 namespace Mono.Linker {
 
-       using System;
-       using System.Collections;
-
        public class Pipeline {
 
                ArrayList _steps;
@@ -84,11 +84,9 @@
 
                public IStep GetStep (Type type)
                {
-                       for (int i = 0; i < _steps.Count; i++) {
-                               IStep step = (IStep) _steps [i];
+                       foreach (IStep step in _steps)
                                if (type.IsAssignableFrom (step.GetType ()))
                                        return step;
-                       }
 
                        return null;
                }

Modified: trunk/cecil/linker/Mono.Linker/SweepStep.cs
===================================================================
--- trunk/cecil/linker/Mono.Linker/SweepStep.cs 2007-05-17 15:17:41 UTC (rev 
77569)
+++ trunk/cecil/linker/Mono.Linker/SweepStep.cs 2007-05-17 15:38:55 UTC (rev 
77570)
@@ -26,11 +26,11 @@
 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 //
 
-namespace Mono.Linker {
+using System.Collections;
 
-       using System.Collections;
+using Mono.Cecil;
 
-       using Mono.Cecil;
+namespace Mono.Linker {
 
        public class SweepStep : IStep {
 

Modified: trunk/cecil/linker/Mono.Linker/TypeMarker.cs
===================================================================
--- trunk/cecil/linker/Mono.Linker/TypeMarker.cs        2007-05-17 15:17:41 UTC 
(rev 77569)
+++ trunk/cecil/linker/Mono.Linker/TypeMarker.cs        2007-05-17 15:38:55 UTC 
(rev 77570)
@@ -26,11 +26,11 @@
 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 //
 
-namespace Mono.Linker {
+using System.Collections;
 
-       using System.Collections;
+using Mono.Cecil;
 
-       using Mono.Cecil;
+namespace Mono.Linker {
 
        public class TypeMarker : Marker {
 
@@ -53,7 +53,7 @@
                        _methods = new Hashtable ();
                }
 
-               string Sig (MemberReference member)
+               static string Sig (MemberReference member)
                {
                        return member.ToString ();
                }
@@ -87,14 +87,14 @@
 
                public FieldMarker [] GetFields ()
                {
-                       FieldMarker [] markers = new FieldMarker[_fields.Count];
+                       FieldMarker [] markers = new FieldMarker 
[_fields.Count];
                        _fields.Values.CopyTo (markers, 0);
                        return markers;
                }
 
                public MethodMarker [] GetMethods ()
                {
-                       MethodMarker [] markers = new 
MethodMarker[_methods.Count];
+                       MethodMarker [] markers = new MethodMarker 
[_methods.Count];
                        _methods.Values.CopyTo (markers, 0);
                        return markers;
                }

Modified: trunk/cecil/linker/Mono.Linker.csproj
===================================================================
--- trunk/cecil/linker/Mono.Linker.csproj       2007-05-17 15:17:41 UTC (rev 
77569)
+++ trunk/cecil/linker/Mono.Linker.csproj       2007-05-17 15:38:55 UTC (rev 
77570)
@@ -52,7 +52,6 @@
     <Compile Include="Mono.Linker\FieldMarker.cs" />
     <Compile Include="Mono.Linker\IStep.cs" />
     <Compile Include="Mono.Linker\LinkContext.cs" />
-    <Compile Include="Mono.Linker\LinkException.cs" />
     <Compile Include="Mono.Linker\MarkStep.cs" />
     <Compile Include="Mono.Linker\Marker.cs" />
     <Compile Include="Mono.Linker\MethodAction.cs" />

Modified: trunk/cecil/linker/monolinker.exe.sources
===================================================================
--- trunk/cecil/linker/monolinker.exe.sources   2007-05-17 15:17:41 UTC (rev 
77569)
+++ trunk/cecil/linker/monolinker.exe.sources   2007-05-17 15:38:55 UTC (rev 
77570)
@@ -7,7 +7,6 @@
 ./Mono.Linker/FieldMarker.cs
 ./Mono.Linker/IStep.cs
 ./Mono.Linker/LinkContext.cs
-./Mono.Linker/LinkException.cs
 ./Mono.Linker/MarkStep.cs
 ./Mono.Linker/Marker.cs
 ./Mono.Linker/MethodAction.cs

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

Reply via email to