Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/mono-tools.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJb Evain <jbevain@gmail.com>2009-01-28 22:08:42 +0300
committerJb Evain <jbevain@gmail.com>2009-01-28 22:08:42 +0300
commite4b685b74fa1004506c0e888b789aae775c05610 (patch)
tree44ebf237365c79cce98d54df950caf27d13f215f /gui-compare
parent41bac47e5bd5fd20f42f60cac1762574bfb00ffb (diff)
2009-01-28 Jb Evain <jbevain@novell.com>
* AssemblyResolver.cs, CecilMetadata.cs: use directly the new Resolve methods that Cecil now provides. svn path=/trunk/mono-tools/; revision=124829
Diffstat (limited to 'gui-compare')
-rw-r--r--gui-compare/AssemblyResolver.cs158
-rw-r--r--gui-compare/CecilMetadata.cs42
-rw-r--r--gui-compare/ChangeLog5
3 files changed, 25 insertions, 180 deletions
diff --git a/gui-compare/AssemblyResolver.cs b/gui-compare/AssemblyResolver.cs
index 74052c5b..a1791b50 100644
--- a/gui-compare/AssemblyResolver.cs
+++ b/gui-compare/AssemblyResolver.cs
@@ -58,164 +58,6 @@ namespace GuiCompare {
return asm;
}
- public TypeDefinition Resolve (TypeReference type)
- {
- type = type.GetOriginalType ();
-
- if (type is TypeDefinition)
- return (TypeDefinition) type;
-
- AssemblyNameReference reference = type.Scope as AssemblyNameReference;
- if (reference != null) {
- AssemblyDefinition assembly = Resolve (reference);
- return assembly.MainModule.Types [type.FullName];
- }
-
- ModuleDefinition module = type.Scope as ModuleDefinition;
- if (module != null)
- return module.Types [type.FullName];
-
- throw new NotImplementedException ();
- }
-
- public FieldDefinition Resolve (FieldReference field)
- {
- TypeDefinition type = Resolve (field.DeclaringType);
- return GetField (type.Fields, field);
- }
-
- static FieldDefinition GetField (ICollection collection, FieldReference reference)
- {
- foreach (FieldDefinition field in collection) {
- if (field.Name != reference.Name)
- continue;
-
- if (!AreSame (field.FieldType, reference.FieldType))
- continue;
-
- return field;
- }
-
- return null;
- }
-
- public MethodDefinition Resolve (MethodReference method)
- {
- TypeDefinition type = Resolve (method.DeclaringType);
- method = method.GetOriginalMethod ();
- if (method.Name == MethodDefinition.Cctor || method.Name == MethodDefinition.Ctor)
- return GetMethod (type.Constructors, method);
- else
- return GetMethod (type, method);
- }
-
- MethodDefinition GetMethod (TypeDefinition type, MethodReference reference)
- {
- while (type != null) {
- MethodDefinition method = GetMethod (type.Methods, reference);
- if (method == null)
- type = Resolve (type.BaseType);
- else
- return method;
- }
-
- return null;
- }
-
- static MethodDefinition GetMethod (ICollection collection, MethodReference reference)
- {
- foreach (MethodDefinition meth in collection) {
- if (meth.Name != reference.Name)
- continue;
-
- if (!AreSame (meth.ReturnType.ReturnType, reference.ReturnType.ReturnType))
- continue;
-
- if (!AreSame (meth.Parameters, reference.Parameters))
- continue;
-
- return meth;
- }
-
- return null;
- }
-
- static bool AreSame (ParameterDefinitionCollection a, ParameterDefinitionCollection b)
- {
- if (a.Count != b.Count)
- return false;
-
- if (a.Count == 0)
- return true;
-
- for (int i = 0; i < a.Count; i++)
- if (!AreSame (a [i].ParameterType, b [i].ParameterType))
- return false;
-
- return true;
- }
-
- static bool AreSame (ModType a, ModType b)
- {
- if (!AreSame (a.ModifierType, b.ModifierType))
- return false;
-
- return AreSame (a.ElementType, b.ElementType);
- }
-
- static bool AreSame (TypeSpecification a, TypeSpecification b)
- {
- if (a is GenericInstanceType)
- return AreSame ((GenericInstanceType) a, (GenericInstanceType) b);
-
- if (a is ModType)
- return AreSame ((ModType) a, (ModType) b);
-
- return AreSame (a.ElementType, b.ElementType);
- }
-
- static bool AreSame (GenericInstanceType a, GenericInstanceType b)
- {
- if (!AreSame (a.ElementType, b.ElementType))
- return false;
-
- if (a.GenericArguments.Count != b.GenericArguments.Count)
- return false;
-
- if (a.GenericArguments.Count == 0)
- return true;
-
- for (int i = 0; i < a.GenericArguments.Count; i++)
- if (!AreSame (a.GenericArguments [i], b.GenericArguments [i]))
- return false;
-
- return true;
- }
-
- static bool AreSame (GenericParameter a, GenericParameter b)
- {
- return a.Position == b.Position;
- }
-
- static bool AreSame (TypeReference a, TypeReference b)
- {
- if (a is TypeSpecification || b is TypeSpecification) {
- if (a.GetType () != b.GetType ())
- return false;
-
- return AreSame ((TypeSpecification) a, (TypeSpecification) b);
- }
-
- if (a is GenericParameter || b is GenericParameter) {
- if (a.GetType () != b.GetType ())
- return false;
-
- return AreSame ((GenericParameter) a, (GenericParameter) b);
- }
-
- return a.FullName == b.FullName;
- }
-
public void CacheAssembly (AssemblyDefinition assembly)
{
_assemblies [assembly.Name.FullName] = assembly;
diff --git a/gui-compare/CecilMetadata.cs b/gui-compare/CecilMetadata.cs
index 254f3e8a..83be7931 100644
--- a/gui-compare/CecilMetadata.cs
+++ b/gui-compare/CecilMetadata.cs
@@ -118,7 +118,7 @@ namespace GuiCompare {
{
if (interface_list != null) {
foreach (TypeReference ifc in GetInterfaces (fromDef)) {
- TypeDefinition ifc_def = CecilUtils.Resolver.Resolve (ifc);
+ TypeDefinition ifc_def = ifc.Resolve ();
if (ifc_def.IsNotPublic)
continue;
@@ -186,14 +186,9 @@ namespace GuiCompare {
}
}
- static TypeDefinition Resolve (TypeReference type)
- {
- return CecilUtils.Resolver.Resolve (type);
- }
-
static IEnumerable<TypeDefinition> WalkHierarchy (TypeReference type)
{
- for (var definition = Resolve (type); definition != null; definition = GetBaseType (definition))
+ for (var definition = type.Resolve (); definition != null; definition = GetBaseType (definition))
yield return definition;
}
@@ -202,7 +197,7 @@ namespace GuiCompare {
if (type.BaseType == null)
return null;
- return Resolve (type.BaseType);
+ return type.BaseType.Resolve ();
}
static IEnumerable<TypeReference> GetInterfaces (TypeReference type)
@@ -289,7 +284,7 @@ namespace GuiCompare {
if (typedef.BaseType == null)
return false;
- return IsTODOAttribute (CecilUtils.Resolver.Resolve (typedef.BaseType));
+ return IsTODOAttribute (GetBaseType (typedef));
}
public static bool ShouldSkipAttribute (string name)
@@ -304,7 +299,7 @@ namespace GuiCompare {
{
List<CompNamed> rv = new List<CompNamed>();
foreach (CustomAttribute ca in provider.CustomAttributes) {
- TypeDefinition resolved = CecilUtils.Resolver.Resolve (ca.Constructor.DeclaringType);
+ TypeDefinition resolved = ca.Constructor.DeclaringType.Resolve ();
if (resolved != null) {
if (IsTODOAttribute (resolved)) {
@@ -330,9 +325,9 @@ namespace GuiCompare {
public CecilAssembly (string path)
: base (Path.GetFileName (path))
{
- Dictionary<string, Dictionary <string, TypeDefinition>> namespaces = new Dictionary<string, Dictionary <string, TypeDefinition>> ();
+ var namespaces = new Dictionary<string, Dictionary<string, TypeDefinition>> ();
- AssemblyDefinition assembly = AssemblyFactory.GetAssembly(path);
+ var assembly = AssemblyFactory.GetAssembly(path);
foreach (TypeDefinition t in assembly.MainModule.Types) {
if (t.Name == "<Module>")
@@ -340,27 +335,30 @@ namespace GuiCompare {
if (t.IsNotPublic)
continue;
-
+
if (t.IsNested)
continue;
-
+
if (t.IsSpecialName || t.IsRuntimeSpecialName)
continue;
if (CecilUtils.IsTODOAttribute (t))
continue;
- if (!namespaces.ContainsKey (t.Namespace))
- namespaces[t.Namespace] = new Dictionary <string, TypeDefinition> ();
+ Dictionary<string, TypeDefinition> ns;
- namespaces[t.Namespace][t.Name] = t;
- }
+ if (!namespaces.TryGetValue (t.Namespace, out ns)) {
+ ns = new Dictionary<string, TypeDefinition> ();
+ namespaces.Add (t.Namespace, ns);
+ }
- namespace_list = new List<CompNamed>();
- foreach (string ns_name in namespaces.Keys) {
- namespace_list.Add (new CecilNamespace (ns_name, namespaces[ns_name]));
+ ns [t.Name] = t;
}
-
+
+ namespace_list = new List<CompNamed> ();
+ foreach (string ns_name in namespaces.Keys)
+ namespace_list.Add (new CecilNamespace (ns_name, namespaces [ns_name]));
+
attributes = CecilUtils.GetCustomAttributes (assembly, todos);
}
diff --git a/gui-compare/ChangeLog b/gui-compare/ChangeLog
index cc3dd547..9cc7e728 100644
--- a/gui-compare/ChangeLog
+++ b/gui-compare/ChangeLog
@@ -1,3 +1,8 @@
+2009-01-28 Jb Evain <jbevain@novell.com>
+
+ * AssemblyResolver.cs, CecilMetadata.cs: use directly the new
+ Resolve methods that Cecil now provides.
+
2009-01-06 Jb Evain <jbevain@novell.com>
* CecilMetadata.cs: support some more operators.