Author: jbevain
Date: 2005-08-18 22:17:36 -0400 (Thu, 18 Aug 2005)
New Revision: 48531
Added:
trunk/cecil/lib/Mono.Cecil.Implem/TablesComparer.cs
Modified:
trunk/cecil/lib/ChangeLog
trunk/cecil/lib/Mono.Cecil.Implem/ReflectionHelper.cs
trunk/cecil/lib/Mono.Cecil.Implem/ReflectionReader.cs
trunk/cecil/lib/Mono.Cecil.Implem/ReflectionWriter.cs
trunk/cecil/lib/Mono.Cecil.Implem/TypeDefinition.cs
trunk/cecil/lib/Mono.Cecil.Implem/TypeReference.cs
trunk/cecil/lib/Mono.Cecil.Signatures/SignatureReader.cs
trunk/cecil/lib/Mono.Cecil.dll.sources
Log:
2005-08-09 Jb Evain <[EMAIL PROTECTED]>
* Mono.Cecil.dll.sources
Mono.Cecil.Implem/ReflectionHelper.cs
Mono.Cecil.Implem/TypeReference.cs
Mono.Cecil.Implem/ReflectionReader.cs
Mono.Cecil.Implem/ReflectionWriter.cs
Mono.Cecil.Implem/TypeDefinition.cs
Mono.Cecil.Implem/TablesComparer.cs
Mono.Cecil.Signatures/SignatureReader.cs:
Fix the build.
Stop to prefix typeref by the scope.
Cecil will have buggy behaviour if it have to handle
two typeref with the same namespace+name, but for the
moment, let it like that.
Modified: trunk/cecil/lib/ChangeLog
===================================================================
--- trunk/cecil/lib/ChangeLog 2005-08-19 01:53:54 UTC (rev 48530)
+++ trunk/cecil/lib/ChangeLog 2005-08-19 02:17:36 UTC (rev 48531)
@@ -1,5 +1,19 @@
2005-08-09 Jb Evain <[EMAIL PROTECTED]>
+ * Mono.Cecil.dll.sources
+ Mono.Cecil.Implem/ReflectionHelper.cs
+ Mono.Cecil.Implem/TypeReference.cs
+ Mono.Cecil.Implem/ReflectionReader.cs
+ Mono.Cecil.Implem/ReflectionWriter.cs
+ Mono.Cecil.Implem/TypeDefinition.cs
+ Mono.Cecil.Implem/TablesComparer.cs
+ Mono.Cecil.Signatures/SignatureReader.cs:
+ Fix the build.
+ Stop to prefix typeref by the scope.
+ Cecil will have buggy behaviour if it have to handle
+ two typeref with the same namespace+name, but for the
+ moment, let it like that.
+
* Mono.Cecil/INestedTypeCollection.cs
Mono.Cecil/IModuleReference.cs
Mono.Cecil/ITypeReferenceCollection.cs
Modified: trunk/cecil/lib/Mono.Cecil.Implem/ReflectionHelper.cs
===================================================================
--- trunk/cecil/lib/Mono.Cecil.Implem/ReflectionHelper.cs 2005-08-19
01:53:54 UTC (rev 48530)
+++ trunk/cecil/lib/Mono.Cecil.Implem/ReflectionHelper.cs 2005-08-19
02:17:36 UTC (rev 48531)
@@ -55,15 +55,13 @@
private string GetTypeSignature (Type t)
{
- string fullName = string.Concat ('[',
t.Assembly.GetName ().Name, ']');
-
if (t.DeclaringType != null)
- return string.Concat (fullName,
t.DeclaringType.FullName, "/", t.Name);
+ return string.Concat (t.DeclaringType.FullName,
"/", t.Name);
if (t.Namespace == null || t.Namespace.Length == 0)
- return string.Concat (fullName, t.Name);
+ return t.Name;
- return string.Concat (fullName, t.Namespace, ".",
t.Name);
+ return string.Concat (t.Namespace, ".", t.Name);
}
public ITypeReference RegisterType (Type t)
Modified: trunk/cecil/lib/Mono.Cecil.Implem/ReflectionReader.cs
===================================================================
--- trunk/cecil/lib/Mono.Cecil.Implem/ReflectionReader.cs 2005-08-19
01:53:54 UTC (rev 48530)
+++ trunk/cecil/lib/Mono.Cecil.Implem/ReflectionReader.cs 2005-08-19
02:17:36 UTC (rev 48531)
@@ -553,11 +553,6 @@
if (etRow.Implementation.TokenType !=
TokenType.File)
continue;
- /*
- TODO get the real typeref name
- [module]Namespace.Name
- */
-
string name = m_root.Streams.StringsHeap
[etRow.TypeName];
string ns = m_root.Streams.StringsHeap
[etRow.TypeNamespace];
if (ns.Length == 0)
Modified: trunk/cecil/lib/Mono.Cecil.Implem/ReflectionWriter.cs
===================================================================
--- trunk/cecil/lib/Mono.Cecil.Implem/ReflectionWriter.cs 2005-08-19
01:53:54 UTC (rev 48530)
+++ trunk/cecil/lib/Mono.Cecil.Implem/ReflectionWriter.cs 2005-08-19
02:17:36 UTC (rev 48531)
@@ -135,11 +135,6 @@
return (uint) m_mod.ModuleReferences.IndexOf (modRef) +
1;
}
- public bool IsCoreType (ITypeReference type, string constant)
- {
- return constant == string.Concat (type.Namespace, '.',
type.Name);
- }
-
public MetadataToken GetTypeDefOrRefToken (ITypeReference type)
{
if (type is IArrayType || type is IFunctionPointerType
|| type is IPointerType) {
@@ -517,7 +512,7 @@
et = GetCorrespondingType (string.Concat
(t.Namespace, '.', t.Name));
} else
- et = GetCorrespondingType (string.Concat
(type.Namespace, '.', type.Name));
+ et = GetCorrespondingType (type.FullName);
ConstantRow cRow = m_rowWriter.CreateConstantRow (
et,
parent,
@@ -708,8 +703,7 @@
public SigType GetSigType (ITypeReference type)
{
- string name = string.Concat (
- type.Namespace, '.', type.Name);
+ string name = type.FullName;
switch (name) {
case Constants.Void :
@@ -763,7 +757,7 @@
} else if (type is IPointerType) {
PTR p = new PTR ();
ITypeReference elementType = (type as
IPointerType).ElementType;
- p.Void = IsCoreType (elementType,
Constants.Void);
+ p.Void = elementType.FullName == Constants.Void;
if (!p.Void) {
p.CustomMods = GetCustomMods
(elementType);
p.PtrType = GetSigType (elementType);
@@ -840,7 +834,7 @@
IParameterDefinition pDef =parameters [i];
Param p = new Param ();
p.CustomMods = GetCustomMods
(pDef.ParameterType);
- if (IsCoreType (pDef.ParameterType,
Constants.TypedReference))
+ if (pDef.ParameterType.FullName ==
Constants.TypedReference)
p.TypedByRef = true;
else if (pDef.ParameterType is IReferenceType) {
p.ByRef = true;
@@ -871,9 +865,9 @@
RetType rtSig = new RetType ();
rtSig.CustomMods = GetCustomMods
(meth.ReturnType.ReturnType);
- if (IsCoreType (meth.ReturnType.ReturnType,
Constants.Void))
+ if (meth.ReturnType.ReturnType.FullName ==
Constants.Void)
rtSig.Void = true;
- else if (IsCoreType (meth.ReturnType.ReturnType,
Constants.TypedReference))
+ else if (meth.ReturnType.ReturnType.FullName ==
Constants.TypedReference)
rtSig.TypedByRef = true;
else if (meth.ReturnType.ReturnType is IReferenceType) {
rtSig.ByRef = true;
@@ -885,7 +879,6 @@
sig.RetType = rtSig;
}
-
public MethodRefSig GetMethodRefSig (IMethodReference meth)
{
MethodRefSig methSig = new MethodRefSig ();
Added: trunk/cecil/lib/Mono.Cecil.Implem/TablesComparer.cs
===================================================================
--- trunk/cecil/lib/Mono.Cecil.Implem/TablesComparer.cs 2005-08-19 01:53:54 UTC
(rev 48530)
+++ trunk/cecil/lib/Mono.Cecil.Implem/TablesComparer.cs 2005-08-19 02:17:36 UTC
(rev 48531)
@@ -0,0 +1,127 @@
+/*
+ * Copyright (c) 2004, 2005 DotNetGuru and the individuals listed
+ * on the ChangeLog entries.
+ *
+ * Authors :
+ * Jb Evain ([EMAIL PROTECTED])
+ *
+ * This is a free software distributed under a MIT/X11 license
+ * See LICENSE.MIT file for more details
+ *
+ *****************************************************************************/
+
+namespace Mono.Cecil.Implem {
+
+ using System;
+ using System.Collections;
+
+ using Mono.Cecil;
+ using Mono.Cecil.Metadata;
+
+ internal sealed class TableComparers {
+
+ public sealed class TypeDef : IComparer {
+
+ public static readonly TypeDef Instance = new TypeDef
();
+
+ public void GetExtendLevel (TypeDefinition type, ref
int level)
+ {
+ if (type.BaseType != null) {
+ level++;
+ if (type.BaseType is TypeDefinition)
+ GetExtendLevel (type.BaseType
as TypeDefinition, ref level);
+ }
+ }
+
+ public int Compare (object x, object y)
+ {
+ TypeDefinition a = x as TypeDefinition;
+ TypeDefinition b = y as TypeDefinition;
+
+ if (a == null || b == null)
+ throw new ReflectionException
("TypeDefComparer can only compare TypeDefinition");
+
+ if (a == b)
+ return 0;
+
+ if (a.Name == Constants.ModuleType)
+ return -1;
+ else if (b.Name == Constants.ModuleType)
+ return 1;
+
+ int alev = 0;
+ if (a.DeclaringType != null) {
+ GetExtendLevel (a.DeclaringType as
TypeDefinition, ref alev);
+ alev++;
+ } else
+ GetExtendLevel (a, ref alev);
+
+ int blev = 0;
+ if (b.DeclaringType != null) {
+ GetExtendLevel (b.DeclaringType as
TypeDefinition, ref blev);
+ blev--;
+ } else
+ GetExtendLevel (b, ref blev);
+
+ if (alev < blev)
+ return -1;
+ else if (blev > alev)
+ return 1;
+
+ return Comparer.Default.Compare (a.FullName,
b.FullName);
+ }
+ }
+
+ public class TypeRef : IComparer {
+
+ public static readonly TypeRef Instance = new TypeRef
();
+
+ public int Compare (object x, object y)
+ {
+ TypeReference a = x as TypeReference;
+ TypeReference b = y as TypeReference;
+
+ if (a == null || b == null)
+ throw new ReflectionException
("TypeRefComparer can only compare TypeReference");
+
+ if (b.DeclaringType == a)
+ return -1;
+ else if (a.DeclaringType == b)
+ return 1;
+
+ return Comparer.Default.Compare (a.FullName,
b.FullName);
+ }
+ }
+
+ public class NestedClass : IComparer {
+
+ public static readonly NestedClass Instance = new
NestedClass ();
+
+ public int Compare (object x, object y)
+ {
+ NestedClassRow a = x as NestedClassRow;
+ NestedClassRow b = y as NestedClassRow;
+
+ return Comparer.Default.Compare (a.NestedClass,
b.NestedClass);
+ }
+ }
+
+ public class InterfaceImpl : IComparer {
+
+ public static readonly InterfaceImpl Instance = new
InterfaceImpl ();
+
+ public int Compare (object x, object y)
+ {
+ InterfaceImplRow a = x as InterfaceImplRow;
+ InterfaceImplRow b = y as InterfaceImplRow;
+
+ int klass = Comparer.Default.Compare (a.Class,
b.Class);
+ if (klass == 0) {
+ return Comparer.Default.Compare
(a.Interface.RID, b.Interface.RID);
+ }
+
+ return klass;
+ }
+ }
+ }
+}
Property changes on: trunk/cecil/lib/Mono.Cecil.Implem/TablesComparer.cs
___________________________________________________________________
Name: svn:eol-style
+ native
Modified: trunk/cecil/lib/Mono.Cecil.Implem/TypeDefinition.cs
===================================================================
--- trunk/cecil/lib/Mono.Cecil.Implem/TypeDefinition.cs 2005-08-19 01:53:54 UTC
(rev 48530)
+++ trunk/cecil/lib/Mono.Cecil.Implem/TypeDefinition.cs 2005-08-19 02:17:36 UTC
(rev 48531)
@@ -212,15 +212,13 @@
}
public bool IsEnum {
- get { return m_baseType != null &&
- m_module.Controller.Writer.IsCoreType
(m_baseType, Constants.Enum); }
+ get { return m_baseType != null && m_baseType.FullName
== Constants.Enum; }
}
public bool IsValueType {
get {
return m_baseType != null && (
- this.IsEnum ||
m_module.Controller.Writer.IsCoreType (
- m_baseType,
Constants.ValueType));
+ this.IsEnum || m_baseType.FullName ==
Constants.ValueType);
}
}
Modified: trunk/cecil/lib/Mono.Cecil.Implem/TypeReference.cs
===================================================================
--- trunk/cecil/lib/Mono.Cecil.Implem/TypeReference.cs 2005-08-19 01:53:54 UTC
(rev 48530)
+++ trunk/cecil/lib/Mono.Cecil.Implem/TypeReference.cs 2005-08-19 02:17:36 UTC
(rev 48531)
@@ -93,19 +93,13 @@
if (m_fullName != null && !m_fullNameDiscarded)
return m_fullName;
- string fullName;
- if (!(this is ITypeDefinition) && m_scope !=
null)
- fullName = string.Concat ('[',
this.Scope.Name, ']');
- else
- fullName= string.Empty;
-
if (m_decType != null)
- return string.Concat (fullName,
m_decType.FullName, "/", m_name);
+ return string.Concat
(m_decType.FullName, "/", m_name);
if (m_namespace == null || m_namespace.Length
== 0)
- return string.Concat (fullName, m_name);
+ return m_name;
- m_fullName = string.Concat (fullName,
m_namespace, ".", m_name);
+ m_fullName = string.Concat (m_namespace, ".",
m_name);
m_fullNameDiscarded = false;
return m_fullName;
}
Modified: trunk/cecil/lib/Mono.Cecil.Signatures/SignatureReader.cs
===================================================================
--- trunk/cecil/lib/Mono.Cecil.Signatures/SignatureReader.cs 2005-08-19
01:53:54 UTC (rev 48530)
+++ trunk/cecil/lib/Mono.Cecil.Signatures/SignatureReader.cs 2005-08-19
02:17:36 UTC (rev 48531)
@@ -580,7 +580,7 @@
{
CustomAttrib.Elem elem = new CustomAttrib.Elem ();
- string elemName = string.Concat (elemType.Namespace,
'.', elemType.Name);
+ string elemName = elemType.FullName;
if (elemName == Constants.Object) {
ElementType elementType = (ElementType)
br.ReadByte ();
Modified: trunk/cecil/lib/Mono.Cecil.dll.sources
===================================================================
--- trunk/cecil/lib/Mono.Cecil.dll.sources 2005-08-19 01:53:54 UTC (rev
48530)
+++ trunk/cecil/lib/Mono.Cecil.dll.sources 2005-08-19 02:17:36 UTC (rev
48531)
@@ -265,6 +265,7 @@
./Mono.Cecil.Implem/SecurityDeclarationCollection.cs
./Mono.Cecil.Implem/StructureReader.cs
./Mono.Cecil.Implem/StructureWriter.cs
+./Mono.Cecil.Implem/TablesComparer.cs
./Mono.Cecil.Implem/TypeDefinition.cs
./Mono.Cecil.Implem/TypeDefinitionCollection.cs
./Mono.Cecil.Implem/TypeReference.cs
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches