Author: jbevain
Date: 2005-02-26 12:59:50 -0500 (Sat, 26 Feb 2005)
New Revision: 41241
Added:
trunk/cecil/lib/Mono.Cecil.Implem/ExternTypeCollection.cs
trunk/cecil/lib/Mono.Cecil/IExternTypeCollection.cs
Modified:
trunk/cecil/lib/CodeGen/cecil.xml
trunk/cecil/lib/Mono.Cecil.Implem/CodeReader.cs
trunk/cecil/lib/Mono.Cecil.Implem/LazyReflectionReader.cs
trunk/cecil/lib/Mono.Cecil.Implem/ModuleDefinition.cs
trunk/cecil/lib/Mono.Cecil.Implem/PointerType.cs
trunk/cecil/lib/Mono.Cecil.Implem/ReferenceType.cs
trunk/cecil/lib/Mono.Cecil.Implem/ReflectionReader.cs
trunk/cecil/lib/Mono.Cecil.Signatures/SignatureReader.cs
trunk/cecil/lib/Mono.Cecil/AssemblyFactory.cs
trunk/cecil/lib/Mono.Cecil/IModuleDefinition.cs
trunk/cecil/lib/Mono.Cecil/IReflectionVisitor.cs
trunk/cecil/lib/cecil.csproj
Log:
correct bugs in signature reading and cil reading, continue the work on
supporting multi modules assemblies
Modified: trunk/cecil/lib/CodeGen/cecil.xml
===================================================================
--- trunk/cecil/lib/CodeGen/cecil.xml 2005-02-26 17:02:16 UTC (rev 41240)
+++ trunk/cecil/lib/CodeGen/cecil.xml 2005-02-26 17:59:50 UTC (rev 41241)
@@ -663,7 +663,8 @@
<collection type="IVariableDefinition" container="IMethodBody"
visit="ICode" indexed="true" target="Mono.Cecil.Cil" />
<collection type="IArrayDimension" container="IArrayType"
target="Mono.Cecil" indexed="true" />
<collection type="ISecurityDeclaration" container="IHasSecurity"
usecontainerinterface="true" target="Mono.Cecil" indexed="true"
visit="IReflection" lazyload="true" pathtoloader="ReflectionReader" />
- <collection type="ICustomAttribute"
container="ICustomAttributeProvider" usecontainerinterface="true"
target="Mono.Cecil" indexed="true" visit="IReflection" lazyload="true"
pathtoloader="ReflectionReader" />
+ <collection type="ICustomAttribute"
container="ICustomAttributeProvider" usecontainerinterface="true"
target="Mono.Cecil" indexed="true" visit="IReflection" lazyload="true"
pathtoloader="ReflectionReader" />
+ <collection type="ITypeReference" container="IModuleDefinition"
target="Mono.Cecil" visit="IReflection" name="IExternType" lazyload="true"
pathtoloader="ReflectionReader" />
</collections>
</cecil>
Modified: trunk/cecil/lib/Mono.Cecil/AssemblyFactory.cs
===================================================================
--- trunk/cecil/lib/Mono.Cecil/AssemblyFactory.cs 2005-02-26 17:02:16 UTC
(rev 41240)
+++ trunk/cecil/lib/Mono.Cecil/AssemblyFactory.cs 2005-02-26 17:59:50 UTC
(rev 41241)
@@ -12,8 +12,11 @@
namespace Mono.Cecil {
+ using System;
+
using Mono.Cecil.Binary;
using Mono.Cecil.Implem;
+ using Mono.Cecil.Metadata;
public class AssemblyFactory {
@@ -23,12 +26,22 @@
public static IAssemblyDefinition GetAssembly (string file,
LoadingType loadType)
{
- ImageReader brv = new ImageReader (file);
- StructureReader srv = new StructureReader (brv);
- AssemblyDefinition asm = new AssemblyDefinition (new
AssemblyNameDefinition (), srv, loadType);
+ try {
+ ImageReader brv = new ImageReader (file);
+ StructureReader srv = new StructureReader (brv);
+ AssemblyDefinition asm = new AssemblyDefinition (new
AssemblyNameDefinition (), srv, loadType);
- asm.Accept (srv);
- return asm;
+ asm.Accept (srv);
+ return asm;
+ } catch (ReflectionException) {
+ throw;
+ } catch (MetadataFormatException) {
+ throw;
+ } catch (ImageFormatException) {
+ throw;
+ } catch (Exception e) {
+ throw new ReflectionException ("Can not disassemble assembly",
e);
+ }
}
public static IAssemblyDefinition GetAssembly (string file)
Added: trunk/cecil/lib/Mono.Cecil/IExternTypeCollection.cs
===================================================================
--- trunk/cecil/lib/Mono.Cecil/IExternTypeCollection.cs 2005-02-26 17:02:16 UTC
(rev 41240)
+++ trunk/cecil/lib/Mono.Cecil/IExternTypeCollection.cs 2005-02-26 17:59:50 UTC
(rev 41241)
@@ -0,0 +1,30 @@
+/*
+ * Copyright (c) 2004 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
+ *
+ * Generated by /CodeGen/cecil-gen.rb do not edit
+ * Sat Feb 26 03:51:32 Paris, Madrid 2005
+ *
+ *****************************************************************************/
+
+namespace Mono.Cecil {
+
+ using System.Collections;
+
+ public interface IExternTypeCollection : ICollection, IReflectionVisitable
{
+
+ ITypeReference this [string name] { get; }
+
+ IModuleDefinition Container { get; }
+
+ void Clear ();
+ bool Contains (ITypeReference value);
+ void Remove (ITypeReference value);
+ }
+}
Modified: trunk/cecil/lib/Mono.Cecil/IModuleDefinition.cs
===================================================================
--- trunk/cecil/lib/Mono.Cecil/IModuleDefinition.cs 2005-02-26 17:02:16 UTC
(rev 41240)
+++ trunk/cecil/lib/Mono.Cecil/IModuleDefinition.cs 2005-02-26 17:59:50 UTC
(rev 41241)
@@ -30,5 +30,6 @@
void DefineLinkedResource (string name, ManifestResourceAttributes
attributes, string file);
ITypeDefinitionCollection Types { get; }
+ IExternTypeCollection ExternTypes { get; }
}
}
Modified: trunk/cecil/lib/Mono.Cecil/IReflectionVisitor.cs
===================================================================
--- trunk/cecil/lib/Mono.Cecil/IReflectionVisitor.cs 2005-02-26 17:02:16 UTC
(rev 41240)
+++ trunk/cecil/lib/Mono.Cecil/IReflectionVisitor.cs 2005-02-26 17:59:50 UTC
(rev 41241)
@@ -19,6 +19,7 @@
void Visit (ITypeReferenceCollection refs);
void Visit (ITypeReference type);
void Visit (IInterfaceCollection interfaces);
+ void Visit (IExternTypeCollection externs);
void Visit (IOverrideCollection meth);
void Visit (IParameterDefinitionCollection parameters);
void Visit (IParameterDefinition parameter);
Modified: trunk/cecil/lib/Mono.Cecil.Implem/CodeReader.cs
===================================================================
--- trunk/cecil/lib/Mono.Cecil.Implem/CodeReader.cs 2005-02-26 17:02:16 UTC
(rev 41240)
+++ trunk/cecil/lib/Mono.Cecil.Implem/CodeReader.cs 2005-02-26 17:59:50 UTC
(rev 41241)
@@ -146,8 +146,12 @@
int type = br.ReadInt32 ();
if (IsToken (type, TokenType.TypeDef))
instr.Operand = m_reflectReader.GetTypeDefAt (GetRid
(type));
+ else if (IsToken (type, TokenType.TypeRef))
+ instr.Operand = m_reflectReader.GetTypeRefAt (GetRid
(type));
+ else if (IsToken (type, TokenType.TypeSpec))
+ instr.Operand = m_reflectReader.GetTypeSpecAt (GetRid
(type));
else
- instr.Operand = m_reflectReader.GetTypeRefAt (GetRid
(type));
+ throw new ReflectionException ("Wrong token for
InlineType Operand: {0}", type.ToString ("x8"));
break;
case OperandType.InlineTok :
int token = br.ReadInt32 ();
@@ -155,12 +159,16 @@
instr.Operand = m_reflectReader.GetTypeDefAt (GetRid
(token));
else if (IsToken (token, TokenType.TypeRef))
instr.Operand = m_reflectReader.GetTypeRefAt (GetRid
(token));
+ else if (IsToken (token, TokenType.TypeSpec))
+ instr.Operand = m_reflectReader.GetTypeSpecAt (GetRid
(token));
+ else if (IsToken (token, TokenType.Field))
+ instr.Operand = m_reflectReader.GetFieldDefAt (GetRid
(token));
else if (IsToken (token, TokenType.Method))
instr.Operand = m_reflectReader.GetMethodDefAt (GetRid
(token));
else if (IsToken (token, TokenType.MemberRef))
instr.Operand = m_reflectReader.GetMemberRefAt (GetRid
(token));
else
- throw new ReflectionException ("Wrong token following
ldtoken");
+ throw new ReflectionException ("Wrong token following
ldtoken: {0}", token.ToString ("x8"));
break;
}
Added: trunk/cecil/lib/Mono.Cecil.Implem/ExternTypeCollection.cs
===================================================================
--- trunk/cecil/lib/Mono.Cecil.Implem/ExternTypeCollection.cs 2005-02-26
17:02:16 UTC (rev 41240)
+++ trunk/cecil/lib/Mono.Cecil.Implem/ExternTypeCollection.cs 2005-02-26
17:59:50 UTC (rev 41241)
@@ -0,0 +1,115 @@
+/*
+ * Copyright (c) 2004 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
+ *
+ * Generated by /CodeGen/cecil-gen.rb do not edit
+ * Sat Feb 26 03:53:51 Paris, Madrid 2005
+ *
+ *****************************************************************************/
+
+namespace Mono.Cecil.Implem {
+
+ using System;
+ using System.Collections;
+
+ using Mono.Cecil;
+ using Mono.Cecil.Cil;
+
+ internal class ExternTypeCollection : IExternTypeCollection,
ILazyLoadableCollection {
+
+ private IDictionary m_items;
+ private ModuleDefinition m_container;
+ private LazyLoader m_loader;
+
+ private bool m_loaded;
+
+ public ITypeReference this [string name] {
+ get {
+ if (m_loader != null)
+ m_loader.ReflectionReader.Visit (this);
+ return m_items [name] as ITypeReference;
+ }
+ set { m_items [name] = value; }
+ }
+
+ public IModuleDefinition Container {
+ get { return m_container; }
+ }
+
+ public int Count {
+ get {
+ if (m_loader != null)
+ m_loader.ReflectionReader.Visit (this);
+ return m_items.Count;
+ }
+ }
+
+ public bool IsSynchronized {
+ get { return false; }
+ }
+
+ public object SyncRoot {
+ get { return this; }
+ }
+
+ public bool Loaded {
+ get { return m_loaded; }
+ set { m_loaded = value; }
+ }
+
+ public ExternTypeCollection (ModuleDefinition container)
+ {
+ m_container = container;
+ m_items = new Hashtable ();
+ }
+
+ public ExternTypeCollection (ModuleDefinition container, LazyLoader
loader) : this (container)
+ {
+ m_loader = loader;
+ }
+
+ public void Clear ()
+ {
+ m_items.Clear ();
+ }
+
+ public bool Contains (ITypeReference value)
+ {
+ return m_items.Contains (value);
+ }
+
+ public void Remove (ITypeReference value)
+ {
+ m_items.Remove (value);
+ }
+
+ public void CopyTo (Array ary, int index)
+ {
+ if (m_loader != null)
+ m_loader.ReflectionReader.Visit (this);
+ m_items.Values.CopyTo (ary, index);
+ }
+
+ public IEnumerator GetEnumerator ()
+ {
+ if (m_loader != null)
+ m_loader.ReflectionReader.Visit (this);
+ return m_items.Values.GetEnumerator ();
+ }
+
+ public void Accept (IReflectionVisitor visitor)
+ {
+ visitor.Visit (this);
+ ITypeReference [] items = new ITypeReference [m_items.Count];
+ m_items.Values.CopyTo (items, 0);
+ for (int i = 0; i < items.Length; i++)
+ items [i].Accept (visitor);
+ }
+ }
+}
Modified: trunk/cecil/lib/Mono.Cecil.Implem/LazyReflectionReader.cs
===================================================================
--- trunk/cecil/lib/Mono.Cecil.Implem/LazyReflectionReader.cs 2005-02-26
17:02:16 UTC (rev 41240)
+++ trunk/cecil/lib/Mono.Cecil.Implem/LazyReflectionReader.cs 2005-02-26
17:59:50 UTC (rev 41241)
@@ -51,6 +51,25 @@
interfs.Loaded = true;
}
+ public override void Visit (IExternTypeCollection externs)
+ {
+ ExternTypeCollection ext = externs as ExternTypeCollection;
+ if (ext.Loaded)
+ return;
+
+ if (!m_root.Streams.TablesHeap.HasTable (typeof
(ExportedTypeTable))) {
+ ext.Loaded = true;
+ return;
+ }
+
+ ExportedTypeTable etTable = m_root.Streams.TablesHeap [typeof
(ExportedTypeTable)] as ExportedTypeTable;
+ for (int i = 0; i < etTable.Rows.Count; i++) {
+ ExportedTypeRow etRow = etTable [i];
+
+ //TODO: WRITE HERE
+ }
+ }
+
public override void Visit (IOverrideCollection meths)
{
OverrideCollection methods = meths as OverrideCollection;
Modified: trunk/cecil/lib/Mono.Cecil.Implem/ModuleDefinition.cs
===================================================================
--- trunk/cecil/lib/Mono.Cecil.Implem/ModuleDefinition.cs 2005-02-26
17:02:16 UTC (rev 41240)
+++ trunk/cecil/lib/Mono.Cecil.Implem/ModuleDefinition.cs 2005-02-26
17:59:50 UTC (rev 41241)
@@ -29,6 +29,7 @@
private ResourceCollection m_res;
private TypeDefinitionCollection m_types;
private TypeReferenceCollection m_refs;
+ private ExternTypeCollection m_externs;
private CustomAttributeCollection m_customAttrs;
private AssemblyDefinition m_asm;
@@ -70,6 +71,14 @@
get { return m_refs; }
}
+ public IExternTypeCollection ExternTypes {
+ get {
+ if (m_externs == null)
+ m_externs = new ExternTypeCollection (this);
+ return m_externs;
+ }
+ }
+
public ICustomAttributeCollection CustomAttributes {
get {
if (m_customAttrs == null)
Modified: trunk/cecil/lib/Mono.Cecil.Implem/PointerType.cs
===================================================================
--- trunk/cecil/lib/Mono.Cecil.Implem/PointerType.cs 2005-02-26 17:02:16 UTC
(rev 41240)
+++ trunk/cecil/lib/Mono.Cecil.Implem/PointerType.cs 2005-02-26 17:59:50 UTC
(rev 41241)
@@ -37,7 +37,7 @@
}
public override string FullName {
- get { return string.Concat (base.FullName, "*"); }
+ get { return string.Concat (m_pointedType.FullName, "*"); }
}
public PointerType (ITypeReference pType) : base (string.Empty,
string.Empty)
Modified: trunk/cecil/lib/Mono.Cecil.Implem/ReferenceType.cs
===================================================================
--- trunk/cecil/lib/Mono.Cecil.Implem/ReferenceType.cs 2005-02-26 17:02:16 UTC
(rev 41240)
+++ trunk/cecil/lib/Mono.Cecil.Implem/ReferenceType.cs 2005-02-26 17:59:50 UTC
(rev 41241)
@@ -37,7 +37,7 @@
}
public override string FullName {
- get { return string.Concat (base.FullName, "&"); }
+ get { return string.Concat (m_type.FullName, "&"); }
}
public ReferenceType (ITypeReference type) : base (string.Empty,
string.Empty)
Modified: trunk/cecil/lib/Mono.Cecil.Implem/ReflectionReader.cs
===================================================================
--- trunk/cecil/lib/Mono.Cecil.Implem/ReflectionReader.cs 2005-02-26
17:02:16 UTC (rev 41240)
+++ trunk/cecil/lib/Mono.Cecil.Implem/ReflectionReader.cs 2005-02-26
17:59:50 UTC (rev 41241)
@@ -78,6 +78,11 @@
return m_typeRefs [rid - 1];
}
+ public ITypeReference GetTypeSpecAt (int rid)
+ {
+ return m_typeSpecs [rid - 1];
+ }
+
public FieldDefinition GetFieldDefAt (int rid)
{
return m_fields [rid - 1];
@@ -303,7 +308,8 @@
for (int j = (int) tdefTable [index].MethodList; j < next;
j++) {
MethodRow methRow = methTable [j - 1];
- MethodSig msig = m_sigReader.GetMethodDefSig
(methRow.Signature);
+ MethodDefSig msig = m_sigReader.GetMethodDefSig
(methRow.Signature);
+
MethodDefinition mdef = new MethodDefinition
(m_root.Streams.StringsHeap [methRow.Name], dec,
methRow.RVA,
methRow.Flags, methRow.ImplFlags,
msig.HasThis, msig.ExplicitThis, msig.MethCallConv);
@@ -391,7 +397,7 @@
methdef.ExplicitThis, methdef.CallingConvention);
break;
case TokenType.ModuleRef :
- break; //TODO: implement that
+ break; //TODO: implement that, or not
}
m_memberRefs [i] = member;
@@ -414,6 +420,10 @@
{
}
+ public virtual void Visit (IExternTypeCollection externs)
+ {
+ }
+
public virtual void Visit (IOverrideCollection meth)
{
}
@@ -627,6 +637,8 @@
return at;
case ElementType.Ptr :
PTR pointer = t as PTR;
+ if (pointer.Void)
+ return new PointerType (SearchCoreType ("System.Void"));
return new PointerType (GetTypeRefFromSig (pointer.PtrType));
case ElementType.FnPtr :
// not very sure of this
@@ -652,7 +664,7 @@
case ElementType.Boolean :
return br.ReadByte () == 1;
case ElementType.Char :
- return br.ReadChar ();
+ return (char) br.ReadUInt16 ();
case ElementType.I1 :
return br.ReadSByte ();
case ElementType.I2 :
Modified: trunk/cecil/lib/Mono.Cecil.Signatures/SignatureReader.cs
===================================================================
--- trunk/cecil/lib/Mono.Cecil.Signatures/SignatureReader.cs 2005-02-26
17:02:16 UTC (rev 41240)
+++ trunk/cecil/lib/Mono.Cecil.Signatures/SignatureReader.cs 2005-02-26
17:59:50 UTC (rev 41241)
@@ -163,7 +163,7 @@
methodDef.MethCallConv |= MethodCallingConvention.VarArg;
methodDef.ParamCount = Utilities.ReadCompressedInteger
(m_blobData, start + 1, out start);
methodDef.RetType = this.ReadRetType (m_blobData, start, out
start);
- methodDef.Parameters = this.ReadParameters (methodDef.ParamCount,
m_blobData, start, out start);
+ methodDef.Parameters = this.ReadParameters (methodDef.ParamCount,
m_blobData, start);
}
public void Visit (MethodRefSig methodRef)
@@ -306,14 +306,13 @@
sentinelpos = -1;
for (int i = 0; i < length; i++) {
- int buf = start;
- Utilities.ReadCompressedInteger (data, start, out start);
- start = buf;
+ int curs = start;
+ int flag = Utilities.ReadCompressedInteger (data, start, out
start);
- if ((start & (int) ElementType.Sentinel) != 0)
+ if ((flag & (int) ElementType.Sentinel) != 0)
sentinelpos = i;
- ret [i] = this.ReadParameter (data, start, out start);
+ ret [i] = this.ReadParameter (data, curs, out start);
}
return ret;
@@ -323,6 +322,7 @@
{
Param p = new Param ();
start = pos;
+
p.CustomMods = this.ReadCustomMods (data, start, out start);
int curs = start;
ElementType flag = (ElementType) Utilities.ReadCompressedInteger
(data, start, out start);
@@ -364,9 +364,10 @@
PTR p = new PTR ();
int buf = start;
int flag = Utilities.ReadCompressedInteger (data, start, out
start);
- p.Void = (flag & (int) ElementType.Void) != 0;
- if (!p.Void)
- start = buf;
+ p.Void = flag == (int) ElementType.Void;
+ if (p.Void)
+ return p;
+ start = buf;
p.CustomMods = this.ReadCustomMods (data, start, out start);
p.PtrType = this.ReadType (data, start, out start);
return p;
Modified: trunk/cecil/lib/cecil.csproj
===================================================================
--- trunk/cecil/lib/cecil.csproj 2005-02-26 17:02:16 UTC (rev 41240)
+++ trunk/cecil/lib/cecil.csproj 2005-02-26 17:59:50 UTC (rev 41241)
@@ -77,6 +77,7 @@
<Compile Include="Mono.Cecil.Implem\EventDefinitionCollection.cs"/>
<Compile Include="Mono.Cecil.Implem\ExceptionHandler.cs"/>
<Compile Include="Mono.Cecil.Implem\ExceptionHandlerCollection.cs"/>
+ <Compile Include="Mono.Cecil.Implem\ExternTypeCollection.cs"/>
<Compile Include="Mono.Cecil.Implem\FieldDefinition.cs"/>
<Compile Include="Mono.Cecil.Implem\FieldDefinitionCollection.cs"/>
<Compile Include="Mono.Cecil.Implem\FieldReference.cs"/>
@@ -235,6 +236,7 @@
<Compile Include="Mono.Cecil\IEmbeddedResource.cs"/>
<Compile Include="Mono.Cecil\IEvent.cs"/>
<Compile Include="Mono.Cecil\IEventDefinitionCollection.cs"/>
+ <Compile Include="Mono.Cecil\IExternTypeCollection.cs"/>
<Compile Include="Mono.Cecil\IField.cs"/>
<Compile Include="Mono.Cecil\IFieldDefinitionCollection.cs"/>
<Compile Include="Mono.Cecil\IFieldLayoutInfo.cs"/>
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches