diff options
author | Jb Evain <jbevain@gmail.com> | 2010-11-03 19:30:58 +0300 |
---|---|---|
committer | Jb Evain <jbevain@gmail.com> | 2010-11-03 19:30:58 +0300 |
commit | e68e72b62896c85db309f1fa26c79e615df67d66 (patch) | |
tree | c69305119c57619ca052a3aafb0ae5f7bbc010d1 /gui-compare | |
parent | 3ad162865ee06b4909730b252383fd6fa3a1dc0f (diff) |
port gui-compare to cecil-light
Diffstat (limited to 'gui-compare')
-rw-r--r-- | gui-compare/AssemblyResolver.cs | 67 | ||||
-rw-r--r-- | gui-compare/CecilMetadata.cs | 46 | ||||
-rw-r--r-- | gui-compare/Makefile.am | 1 |
3 files changed, 22 insertions, 92 deletions
diff --git a/gui-compare/AssemblyResolver.cs b/gui-compare/AssemblyResolver.cs deleted file mode 100644 index a1791b50..00000000 --- a/gui-compare/AssemblyResolver.cs +++ /dev/null @@ -1,67 +0,0 @@ -// -// AssemblyResolver.cs -// -// Author: -// Jb Evain (jbevain@novell.com) -// -// (C) 2007 Novell, Inc. -// -// 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. -// - -using System; -using System.Collections; - -using Mono.Cecil; - -namespace GuiCompare { - - public class AssemblyResolver : BaseAssemblyResolver { - - Hashtable _assemblies; - - public IDictionary AssemblyCache { - get { return _assemblies; } - } - - public AssemblyResolver () - { - _assemblies = new Hashtable (); - } - - public override AssemblyDefinition Resolve (AssemblyNameReference name) - { - AssemblyDefinition asm = (AssemblyDefinition) _assemblies [name.Name]; - if (asm == null) { - asm = base.Resolve (name); - asm.Resolver = this; - _assemblies [name.Name] = asm; - } - - return asm; - } - - public void CacheAssembly (AssemblyDefinition assembly) - { - _assemblies [assembly.Name.FullName] = assembly; - assembly.Resolver = this; - } - } -} diff --git a/gui-compare/CecilMetadata.cs b/gui-compare/CecilMetadata.cs index 65e6c040..f35ad86b 100644 --- a/gui-compare/CecilMetadata.cs +++ b/gui-compare/CecilMetadata.cs @@ -28,6 +28,7 @@ using System.Collections; using System.Collections.Generic; using System.Runtime.CompilerServices; using System.IO; +using System.Linq; using System.Text; using Mono.Cecil; @@ -62,7 +63,7 @@ namespace GuiCompare { if (array != null) return PrettyType (array.ElementType) + "[]"; - var reference = type as ReferenceType; + var reference = type as ByReferenceType; if (reference != null) return PrettyType (reference.ElementType) + "&"; @@ -153,14 +154,14 @@ namespace GuiCompare { } if (constructor_list != null) { - foreach (MethodDefinition md in fromDef.Constructors) { + foreach (MethodDefinition md in fromDef.Methods.Where (m => m.IsConstructor)) { if (md.IsPrivate || md.IsAssembly) continue; constructor_list.Add (new CecilMethod (md)); } } if (method_list != null) { - foreach (MethodDefinition md in fromDef.Methods) { + foreach (MethodDefinition md in fromDef.Methods.Where (m => !m.IsConstructor)) { if (md.IsSpecialName) { if (!md.Name.StartsWith("op_")) continue; @@ -289,11 +290,11 @@ namespace GuiCompare { { StringBuilder sb = new StringBuilder(); bool first = true; - foreach (object o in ca.ConstructorParameters) { + foreach (var argument in ca.ConstructorArguments) { if (!first) sb.Append (", "); first = false; - sb.Append (o.ToString()); + sb.Append (argument.Value.ToString()); } return sb.ToString(); @@ -350,7 +351,7 @@ namespace GuiCompare { return l; } - public static readonly AssemblyResolver Resolver = new AssemblyResolver(); + public static readonly IAssemblyResolver Resolver = new DefaultAssemblyResolver(); } public class CecilAssembly : CompAssembly { @@ -359,7 +360,7 @@ namespace GuiCompare { { var namespaces = new Dictionary<string, Dictionary<string, TypeDefinition>> (); - var assembly = AssemblyFactory.GetAssembly (path); + var assembly = AssemblyDefinition.ReadAssembly (path, new ReaderParameters { AssemblyResolver = CecilUtils.Resolver }); foreach (TypeDefinition t in assembly.MainModule.Types) { if (t.Name == "<Module>") @@ -368,9 +369,6 @@ namespace GuiCompare { if (t.IsNotPublic) continue; - if (t.IsNested) - continue; - if (t.IsSpecialName || t.IsRuntimeSpecialName) continue; @@ -395,8 +393,8 @@ namespace GuiCompare { // TypeForwardedToAttributes are created by checking if assembly contains // extern forwarder types and using them to construct fake custom attributes - foreach (TypeReference t in assembly.MainModule.ExternTypes) { - if (((uint)t.Resolve ().Attributes & 0x200000u) != 0) + foreach (ExportedType t in assembly.MainModule.ExportedTypes) { + if (t.IsForwarder) attributes.Add (new PseudoCecilAttribute (t)); } } @@ -862,7 +860,7 @@ namespace GuiCompare { if (method_def.IsConstructor) return null; - return CecilUtils.FormatTypeLikeCorCompare (method_def.ReturnType.ReturnType); + return CecilUtils.FormatTypeLikeCorCompare (method_def.ReturnType); } public override bool ThrowsNotImplementedException () @@ -909,8 +907,8 @@ namespace GuiCompare { StringBuilder sb = new StringBuilder (); if (!method_def.IsConstructor) sb.Append (beautify - ? CecilUtils.PrettyType (method_def.ReturnType.ReturnType) - : CecilUtils.FormatTypeLikeCorCompare (method_def.ReturnType.ReturnType)); + ? CecilUtils.PrettyType (method_def.ReturnType) + : CecilUtils.FormatTypeLikeCorCompare (method_def.ReturnType)); sb.Append (" "); if (beautify) { if (method_def.IsSpecialName && method_def.Name.StartsWith ("op_")) { @@ -1136,30 +1134,30 @@ namespace GuiCompare { var sb = new StringBuilder ("[" + ca.Constructor.DeclaringType.FullName); bool first = true; - IList cparams = ca.ConstructorParameters; - if (cparams != null && cparams.Count > 0) { - foreach (object o in cparams) { + var cargs = ca.ConstructorArguments; + if (cargs != null && cargs.Count > 0) { + foreach (var argument in cargs) { if (first) { sb.Append (" ("); first = false; } else sb.Append (", "); - sb.Append (FormatValue (o)); + sb.Append (FormatValue (argument.Value)); } } - IDictionary properties = ca.Properties; + var properties = ca.Properties; if (properties != null && properties.Count > 0) { - foreach (DictionaryEntry de in properties) { + foreach (var namedArg in properties) { if (first) { sb.Append (" ("); first = false; } else sb.Append (", "); - sb.AppendFormat ("{0}={1}", de.Key, FormatValue (de.Value)); + sb.AppendFormat ("{0}={1}", namedArg.Name, FormatValue (namedArg.Argument.Value)); } } @@ -1187,10 +1185,10 @@ namespace GuiCompare { public class PseudoCecilAttribute : CompAttribute { - public PseudoCecilAttribute (TypeReference tref) + public PseudoCecilAttribute (ExportedType type) : base (typeof (TypeForwardedToAttribute).FullName) { - ExtraInfo = "[assembly: TypeForwardedToAttribute (typeof (" + tref.ToString () + "))]"; + ExtraInfo = "[assembly: TypeForwardedToAttribute (typeof (" + type.ToString () + "))]"; } } diff --git a/gui-compare/Makefile.am b/gui-compare/Makefile.am index f790dd51..ef805eba 100644 --- a/gui-compare/Makefile.am +++ b/gui-compare/Makefile.am @@ -19,7 +19,6 @@ gui_compare_sources = \ $(srcdir)/CecilMetadata.cs \ $(srcdir)/ProviderSelector.cs \ $(srcdir)/gtk-gui/guicompare.ProviderSelector.cs\ - $(srcdir)/AssemblyResolver.cs \ $(srcdir)/Config.cs \ $(srcdir)/CustomCompare.cs \ $(srcdir)/gtk-gui/GuiCompare.CustomCompare.cs |