Author: martin
Date: 2005-10-10 12:09:10 -0400 (Mon, 10 Oct 2005)
New Revision: 51519
Added:
trunk/cecil/lib/Mono.Cecil.Signatures/GenericInst.cs
trunk/cecil/lib/Mono.Cecil.Signatures/GenericInstSignature.cs
trunk/cecil/lib/Mono.Cecil.Signatures/MVar.cs
trunk/cecil/lib/Mono.Cecil.Signatures/Var.cs
trunk/cecil/lib/Mono.Cecil/GenericInstType.cs
trunk/cecil/lib/Mono.Cecil/IGenericArgument.cs
trunk/cecil/lib/Mono.Cecil/IGenericInstance.cs
trunk/cecil/lib/Mono.Cecil/IGenericParameterConstraints.cs
trunk/cecil/lib/Mono.Cecil/IMethodTypeParameterType.cs
trunk/cecil/lib/Mono.Cecil/ITypeParameterType.cs
trunk/cecil/lib/Mono.Cecil/MethodTypeParameterType.cs
trunk/cecil/lib/Mono.Cecil/TypeParameterType.cs
Modified:
trunk/cecil/lib/ChangeLog
trunk/cecil/lib/CodeGen/cecil.xml
trunk/cecil/lib/Mono.Cecil.Metadata/ElementType.cs
trunk/cecil/lib/Mono.Cecil.Metadata/Utilities.cs
trunk/cecil/lib/Mono.Cecil.Signatures/SignatureReader.cs
trunk/cecil/lib/Mono.Cecil.dll.sources
trunk/cecil/lib/Mono.Cecil/ReflectionReader.cs
Log:
2005-09-16 Martin Baulig <[EMAIL PROTECTED]>
Added generics support to Cecil.
* Mono.Cecil/IGenericInstType.cs: New file.
* Mono.Cecil/ITypeParameterType.cs: New file.
* Mono.Cecil/IMethodTypeParameterType.cs: New file.
* Mono.Cecil.Metadata/ElementType.cs
(ElementType): Added `Var', `MVar' and `GenericInst'.
* Mono.Cecil.Metadata/Utilities.cs
(Utilities.GetMetadataToken): .NET 2.0 also uses TypeDef's in the
MemberRefParent.
* Mono.Cecil/GenericInstType.cs: New file.
* Mono.Cecil/MethodTypeParameterType.cs: New file.
* Mono.Cecil/TypeParameterType.cs: New file.
* Mono.Cecil.Signatures/Var.cs: New file.
* Mono.Cecil.Signatures/MVar.cs: New file.
* Mono.Cecil.Signatures/GenericInst.cs: New file.
* Mono.Cecil.Signatures/GenericInstSignature.cs: New file.
* Mono.Cecil/ReflectionReader.cs
(ReflectionReader.GetTypeRefFromSig): Add the new types.
* Mono.Cecil.Signatures/SignatureReader.cs
(SignatureReader.ReadType): Add the new types.
Modified: trunk/cecil/lib/ChangeLog
===================================================================
--- trunk/cecil/lib/ChangeLog 2005-10-10 15:55:53 UTC (rev 51518)
+++ trunk/cecil/lib/ChangeLog 2005-10-10 16:09:10 UTC (rev 51519)
@@ -1,3 +1,33 @@
+2005-09-16 Martin Baulig <[EMAIL PROTECTED]>
+
+ Added generics support to Cecil.
+
+ * Mono.Cecil/IGenericInstType.cs: New file.
+ * Mono.Cecil/ITypeParameterType.cs: New file.
+ * Mono.Cecil/IMethodTypeParameterType.cs: New file.
+
+ * Mono.Cecil.Metadata/ElementType.cs
+ (ElementType): Added `Var', `MVar' and `GenericInst'.
+
+ * Mono.Cecil.Metadata/Utilities.cs
+ (Utilities.GetMetadataToken): .NET 2.0 also uses TypeDef's in the
+ MemberRefParent.
+
+ * Mono.Cecil/GenericInstType.cs: New file.
+ * Mono.Cecil/MethodTypeParameterType.cs: New file.
+ * Mono.Cecil/TypeParameterType.cs: New file.
+
+ * Mono.Cecil.Signatures/Var.cs: New file.
+ * Mono.Cecil.Signatures/MVar.cs: New file.
+ * Mono.Cecil.Signatures/GenericInst.cs: New file.
+ * Mono.Cecil.Signatures/GenericInstSignature.cs: New file.
+
+ * Mono.Cecil/ReflectionReader.cs
+ (ReflectionReader.GetTypeRefFromSig): Add the new types.
+
+ * Mono.Cecil.Signatures/SignatureReader.cs
+ (SignatureReader.ReadType): Add the new types.
+
2005-10-06 Jb Evain <[EMAIL PROTECTED]>
* Mono.Cecil/ReflectionHelper.cs
Modified: trunk/cecil/lib/CodeGen/cecil.xml
===================================================================
--- trunk/cecil/lib/CodeGen/cecil.xml 2005-10-10 15:55:53 UTC (rev 51518)
+++ trunk/cecil/lib/CodeGen/cecil.xml 2005-10-10 16:09:10 UTC (rev 51519)
@@ -382,6 +382,7 @@
<table name="Assembly" tag="2" />
</codedindex>
<codedindex name="MemberRefParent" size="3">
+ <table name="TypeDef" tag="0" />
<table name="TypeRef" tag="1" />
<table name="ModuleRef" tag="2" />
<table name="Method" tag="3" />
Added: trunk/cecil/lib/Mono.Cecil/GenericInstType.cs
===================================================================
--- trunk/cecil/lib/Mono.Cecil/GenericInstType.cs 2005-10-10 15:55:53 UTC
(rev 51518)
+++ trunk/cecil/lib/Mono.Cecil/GenericInstType.cs 2005-10-10 16:09:10 UTC
(rev 51519)
@@ -0,0 +1,46 @@
+namespace Mono.Cecil {
+
+ using System;
+
+ using Mono.Cecil;
+ using Mono.Cecil.Signatures;
+
+ public sealed class GenericInstType : TypeReference, IGenericInstance {
+
+ private TypeReference type;
+ private TypeReference[] type_argv;
+
+ public ITypeReference GenericType {
+ get { return type; }
+ }
+
+ public int Arity {
+ get { return type_argv.Length; }
+ }
+
+ public ITypeReference[] TypeArguments {
+ get { return type_argv; }
+ }
+
+ public override string Name {
+ get { return type.Name + "`" + Arity; }
+ set { throw new InvalidOperationException (); }
+ }
+
+ public override string Namespace {
+ get { return string.Empty; }
+ set { throw new InvalidOperationException (); }
+ }
+
+ public override string FullName {
+ get { return Name; }
+ }
+
+ public GenericInstType (TypeReference type, TypeReference[]
type_argv)
+ : base (string.Empty, string.Empty)
+ {
+ this.type = type;
+ this.type_argv = type_argv;
+ }
+ }
+}
Added: trunk/cecil/lib/Mono.Cecil/IGenericArgument.cs
===================================================================
--- trunk/cecil/lib/Mono.Cecil/IGenericArgument.cs 2005-10-10 15:55:53 UTC
(rev 51518)
+++ trunk/cecil/lib/Mono.Cecil/IGenericArgument.cs 2005-10-10 16:09:10 UTC
(rev 51519)
@@ -0,0 +1,7 @@
+namespace Mono.Cecil {
+
+ public interface IGenericArgument : ITypeReference
+ {
+ int Position { get; }
+ }
+}
Added: trunk/cecil/lib/Mono.Cecil/IGenericInstance.cs
===================================================================
--- trunk/cecil/lib/Mono.Cecil/IGenericInstance.cs 2005-10-10 15:55:53 UTC
(rev 51518)
+++ trunk/cecil/lib/Mono.Cecil/IGenericInstance.cs 2005-10-10 16:09:10 UTC
(rev 51519)
@@ -0,0 +1,8 @@
+namespace Mono.Cecil {
+
+ public interface IGenericInstance : ITypeReference {
+ ITypeReference GenericType { get; }
+ int Arity { get; }
+ ITypeReference[] TypeArguments { get; }
+ }
+}
Added: trunk/cecil/lib/Mono.Cecil/IGenericParameterConstraints.cs
===================================================================
--- trunk/cecil/lib/Mono.Cecil/IGenericParameterConstraints.cs 2005-10-10
15:55:53 UTC (rev 51518)
+++ trunk/cecil/lib/Mono.Cecil/IGenericParameterConstraints.cs 2005-10-10
16:09:10 UTC (rev 51519)
@@ -0,0 +1,10 @@
+namespace Mono.Cecil {
+
+ public interface IGenericParameterConstraints {
+ ITypeReference[] InterfaceConstraints { get; }
+ ITypeReference ClassConstraint { get; }
+ bool HasValueTypeConstraint { get; }
+ bool HasReferenceTypeConstraint { get; }
+ bool HasConstructorConstraint { get; }
+ }
+}
Added: trunk/cecil/lib/Mono.Cecil/IMethodTypeParameterType.cs
===================================================================
--- trunk/cecil/lib/Mono.Cecil/IMethodTypeParameterType.cs 2005-10-10
15:55:53 UTC (rev 51518)
+++ trunk/cecil/lib/Mono.Cecil/IMethodTypeParameterType.cs 2005-10-10
16:09:10 UTC (rev 51519)
@@ -0,0 +1,6 @@
+namespace Mono.Cecil {
+
+ public interface IMethodTypeParameterType : ITypeReference {
+ int Index { get; }
+ }
+}
Added: trunk/cecil/lib/Mono.Cecil/ITypeParameterType.cs
===================================================================
--- trunk/cecil/lib/Mono.Cecil/ITypeParameterType.cs 2005-10-10 15:55:53 UTC
(rev 51518)
+++ trunk/cecil/lib/Mono.Cecil/ITypeParameterType.cs 2005-10-10 16:09:10 UTC
(rev 51519)
@@ -0,0 +1,6 @@
+namespace Mono.Cecil {
+
+ public interface ITypeParameterType : ITypeReference {
+ int Index { get; }
+ }
+}
Added: trunk/cecil/lib/Mono.Cecil/MethodTypeParameterType.cs
===================================================================
--- trunk/cecil/lib/Mono.Cecil/MethodTypeParameterType.cs 2005-10-10
15:55:53 UTC (rev 51518)
+++ trunk/cecil/lib/Mono.Cecil/MethodTypeParameterType.cs 2005-10-10
16:09:10 UTC (rev 51519)
@@ -0,0 +1,37 @@
+namespace Mono.Cecil {
+
+ using System;
+
+ using Mono.Cecil;
+ using Mono.Cecil.Signatures;
+
+ public sealed class MethodTypeParameterType : TypeReference,
IMethodTypeParameterType {
+
+ private int index;
+
+ public int Index {
+ get { return index; }
+ set { index = value; }
+ }
+
+ public override string Name {
+ get { return "!!" + index; }
+ set { throw new InvalidOperationException (); }
+ }
+
+ public override string Namespace {
+ get { return string.Empty; }
+ set { throw new InvalidOperationException (); }
+ }
+
+ public override string FullName {
+ get { return Name; }
+ }
+
+ public MethodTypeParameterType (int index)
+ : base (string.Empty, string.Empty)
+ {
+ this.index = index;
+ }
+ }
+}
Modified: trunk/cecil/lib/Mono.Cecil/ReflectionReader.cs
===================================================================
--- trunk/cecil/lib/Mono.Cecil/ReflectionReader.cs 2005-10-10 15:55:53 UTC
(rev 51518)
+++ trunk/cecil/lib/Mono.Cecil/ReflectionReader.cs 2005-10-10 16:09:10 UTC
(rev 51519)
@@ -671,7 +671,10 @@
SecurityDeclaration dec = new SecurityDeclaration
(action);
PermissionSet ps = new PermissionSet
(PermissionState.None);
m_secParser.LoadXml (Encoding.Unicode.GetString
(permset));
- ps.FromXml (m_secParser.ToXml ());
+ try {
+ ps.FromXml (m_secParser.ToXml ());
+ } catch {
+ }
dec.PermissionSet = ps;
return dec;
}
@@ -824,6 +827,20 @@
return new FunctionPointerType
(funcptr.Method.HasThis, funcptr.Method.ExplicitThis,
funcptr.Method.MethCallConv,
parameters, GetMethodReturnType
(funcptr.Method));
+ case ElementType.Var:
+ VAR var = t as VAR;
+ return new TypeParameterType (var.Index);
+ case ElementType.MVar:
+ MVAR mvar = t as MVAR;
+ return new MethodTypeParameterType (mvar.Index);
+ case ElementType.GenericInst:
+ GENERICINST ginst = t as GENERICINST;
+ TypeReference[] ginst_argv = new TypeReference
[ginst.Signature.Arity];
+ for (int i = 0; i < ginst.Signature.Arity; i++)
+ ginst_argv [i] = GetTypeRefFromSig
(ginst.Signature.Types [i]);
+ return new GenericInstType (GetTypeRefFromSig
(ginst.Type), ginst_argv);
+ default:
+ break;
}
return null;
}
Added: trunk/cecil/lib/Mono.Cecil/TypeParameterType.cs
===================================================================
--- trunk/cecil/lib/Mono.Cecil/TypeParameterType.cs 2005-10-10 15:55:53 UTC
(rev 51518)
+++ trunk/cecil/lib/Mono.Cecil/TypeParameterType.cs 2005-10-10 16:09:10 UTC
(rev 51519)
@@ -0,0 +1,37 @@
+namespace Mono.Cecil {
+
+ using System;
+
+ using Mono.Cecil;
+ using Mono.Cecil.Signatures;
+
+ public sealed class TypeParameterType : TypeReference, IGenericArgument
{
+
+ private int position;
+
+ public int Position {
+ get { return position; }
+ set { position = value; }
+ }
+
+ public override string Name {
+ get { return "!" + position; }
+ set { throw new InvalidOperationException (); }
+ }
+
+ public override string Namespace {
+ get { return string.Empty; }
+ set { throw new InvalidOperationException (); }
+ }
+
+ public override string FullName {
+ get { return Name; }
+ }
+
+ public TypeParameterType (int position)
+ : base (string.Empty, string.Empty)
+ {
+ this.position = position;
+ }
+ }
+}
Modified: trunk/cecil/lib/Mono.Cecil.Metadata/ElementType.cs
===================================================================
--- trunk/cecil/lib/Mono.Cecil.Metadata/ElementType.cs 2005-10-10 15:55:53 UTC
(rev 51518)
+++ trunk/cecil/lib/Mono.Cecil.Metadata/ElementType.cs 2005-10-10 16:09:10 UTC
(rev 51519)
@@ -48,13 +48,16 @@
ByRef = 0x10, // Followed by <type> token
ValueType = 0x11, // Followed by <type> token
Class = 0x12, // Followed by <type> token
+ Var = 0x13, // Followed by generic parameter number
Array = 0x14, // <type> <rank> <boundsCount> <bound1>
<loCount> <lo1>
+ GenericInst = 0x15, // <type> <type-arg-count> <type-1> ...
<type-n> */
TypedByRef = 0x16,
I = 0x18, // System.IntPtr
U = 0x19, // System.UIntPtr
FnPtr = 0x1b, // Followed by full method signature
Object = 0x1c, // System.Object
SzArray = 0x1d, // Single-dim array with 0 lower bound
+ MVar = 0x1e, // Followed by generic parameter number
CModReqD = 0x1f, // Required modifier : followed by a
TypeDef or TypeRef token
CModOpt = 0x20, // Optional modifier : followed by a TypeDef
or TypeRef token
Internal = 0x21, // Implemented within the CLI
Modified: trunk/cecil/lib/Mono.Cecil.Metadata/Utilities.cs
===================================================================
--- trunk/cecil/lib/Mono.Cecil.Metadata/Utilities.cs 2005-10-10 15:55:53 UTC
(rev 51518)
+++ trunk/cecil/lib/Mono.Cecil.Metadata/Utilities.cs 2005-10-10 16:09:10 UTC
(rev 51519)
@@ -97,6 +97,8 @@
case CodedIndex.MemberRefParent :
rid = data >> 3;
switch (data & 7) {
+ case 0 :
+ return new MetadataToken
(TokenType.TypeDef, rid);
case 1 :
return new MetadataToken
(TokenType.TypeRef, rid);
case 2 :
Added: trunk/cecil/lib/Mono.Cecil.Signatures/GenericInst.cs
===================================================================
--- trunk/cecil/lib/Mono.Cecil.Signatures/GenericInst.cs 2005-10-10
15:55:53 UTC (rev 51518)
+++ trunk/cecil/lib/Mono.Cecil.Signatures/GenericInst.cs 2005-10-10
16:09:10 UTC (rev 51519)
@@ -0,0 +1,14 @@
+namespace Mono.Cecil.Signatures {
+
+ using Mono.Cecil.Metadata;
+
+ internal sealed class GENERICINST : SigType {
+
+ public SigType Type;
+ public GenericInstSignature Signature;
+
+ public GENERICINST () : base (ElementType.GenericInst)
+ {
+ }
+ }
+}
Added: trunk/cecil/lib/Mono.Cecil.Signatures/GenericInstSignature.cs
===================================================================
--- trunk/cecil/lib/Mono.Cecil.Signatures/GenericInstSignature.cs
2005-10-10 15:55:53 UTC (rev 51518)
+++ trunk/cecil/lib/Mono.Cecil.Signatures/GenericInstSignature.cs
2005-10-10 16:09:10 UTC (rev 51519)
@@ -0,0 +1,12 @@
+namespace Mono.Cecil.Signatures {
+
+ internal sealed class GenericInstSignature {
+
+ public int Arity;
+ public SigType[] Types;
+
+ public GenericInstSignature ()
+ {
+ }
+ }
+}
Added: trunk/cecil/lib/Mono.Cecil.Signatures/MVar.cs
===================================================================
--- trunk/cecil/lib/Mono.Cecil.Signatures/MVar.cs 2005-10-10 15:55:53 UTC
(rev 51518)
+++ trunk/cecil/lib/Mono.Cecil.Signatures/MVar.cs 2005-10-10 16:09:10 UTC
(rev 51519)
@@ -0,0 +1,13 @@
+namespace Mono.Cecil.Signatures {
+
+ using Mono.Cecil.Metadata;
+
+ internal sealed class MVAR : SigType {
+
+ public int Index;
+
+ public MVAR () : base (ElementType.MVar)
+ {
+ }
+ }
+}
Modified: trunk/cecil/lib/Mono.Cecil.Signatures/SignatureReader.cs
===================================================================
--- trunk/cecil/lib/Mono.Cecil.Signatures/SignatureReader.cs 2005-10-10
15:55:53 UTC (rev 51518)
+++ trunk/cecil/lib/Mono.Cecil.Signatures/SignatureReader.cs 2005-10-10
16:09:10 UTC (rev 51519)
@@ -429,6 +429,24 @@
SZARRAY sa = new SZARRAY ();
sa.Type = this.ReadType (data, start, out
start);
return sa;
+ case ElementType.Var:
+ VAR var = new VAR ();
+ var.Index = Utilities.ReadCompressedInteger
(data, start, out start);
+ return var;
+ case ElementType.MVar:
+ MVAR mvar = new MVAR ();
+ mvar.Index = Utilities.ReadCompressedInteger
(data, start, out start);
+ return mvar;
+ case ElementType.GenericInst:
+ GENERICINST ginst = new GENERICINST ();
+ GenericInstSignature gis = new
GenericInstSignature ();
+ ginst.Type = this.ReadType (data, start, out
start);
+ gis.Arity = Utilities.ReadCompressedInteger
(data, start, out start);
+ gis.Types = new SigType [gis.Arity];
+ for (int i = 0; i < gis.Arity; i++)
+ gis.Types [i] = this.ReadType (data,
start, out start);
+ ginst.Signature = gis;
+ return ginst;
default :
return new SigType (element);
}
Added: trunk/cecil/lib/Mono.Cecil.Signatures/Var.cs
===================================================================
--- trunk/cecil/lib/Mono.Cecil.Signatures/Var.cs 2005-10-10 15:55:53 UTC
(rev 51518)
+++ trunk/cecil/lib/Mono.Cecil.Signatures/Var.cs 2005-10-10 16:09:10 UTC
(rev 51519)
@@ -0,0 +1,13 @@
+namespace Mono.Cecil.Signatures {
+
+ using Mono.Cecil.Metadata;
+
+ internal sealed class VAR : SigType {
+
+ public int Index;
+
+ public VAR () : base (ElementType.Var)
+ {
+ }
+ }
+}
Modified: trunk/cecil/lib/Mono.Cecil.dll.sources
===================================================================
--- trunk/cecil/lib/Mono.Cecil.dll.sources 2005-10-10 15:55:53 UTC (rev
51518)
+++ trunk/cecil/lib/Mono.Cecil.dll.sources 2005-10-10 16:09:10 UTC (rev
51519)
@@ -29,6 +29,7 @@
./Mono.Cecil/FieldReference.cs
./Mono.Cecil/FileAttributes.cs
./Mono.Cecil/FunctionPointerType.cs
+./Mono.Cecil/GenericInstType.cs
./Mono.Cecil/GenericParamAttributes.cs
./Mono.Cecil/HashCodeProvider.cs
./Mono.Cecil/IArrayDimension.cs
@@ -52,6 +53,9 @@
./Mono.Cecil/IFieldDefinitionCollection.cs
./Mono.Cecil/IFieldLayoutInfo.cs
./Mono.Cecil/IFunctionPointerType.cs
+./Mono.Cecil/IGenericArgument.cs
+./Mono.Cecil/IGenericInstance.cs
+./Mono.Cecil/IGenericParameterConstraints.cs
./Mono.Cecil/IHasConstant.cs
./Mono.Cecil/IHasMarshalSpec.cs
./Mono.Cecil/IHasSecurity.cs
@@ -66,6 +70,7 @@
./Mono.Cecil/IMethodDefinitionCollection.cs
./Mono.Cecil/IMethodReturnType.cs
./Mono.Cecil/IMethodSignature.cs
+./Mono.Cecil/IMethodTypeParameterType.cs
./Mono.Cecil/IModifierOptional.cs
./Mono.Cecil/IModifierRequired.cs
./Mono.Cecil/IModifierType.cs
@@ -95,6 +100,7 @@
./Mono.Cecil/IType.cs
./Mono.Cecil/ITypeDefinition.cs
./Mono.Cecil/ITypeDefinitionCollection.cs
+./Mono.Cecil/ITypeParameterType.cs
./Mono.Cecil/ITypeReference.cs
./Mono.Cecil/ITypeReferenceCollection.cs
./Mono.Cecil/LinkedResource.cs
@@ -110,6 +116,7 @@
./Mono.Cecil/MethodImplAttributes.cs
./Mono.Cecil/MethodReference.cs
./Mono.Cecil/MethodReturnType.cs
+./Mono.Cecil/MethodTypeParameterType.cs
./Mono.Cecil/MethodSemanticsAttributes.cs
./Mono.Cecil/Modifiers.cs
./Mono.Cecil/ModuleDefinition.cs
@@ -147,6 +154,7 @@
./Mono.Cecil/TypeAttributes.cs
./Mono.Cecil/TypeDefinition.cs
./Mono.Cecil/TypeDefinitionCollection.cs
+./Mono.Cecil/TypeParameterType.cs
./Mono.Cecil/TypeReference.cs
./Mono.Cecil/TypeReferenceCollection.cs
./Mono.Cecil/VariantType.cs
@@ -301,6 +309,10 @@
./Mono.Cecil.Signatures/SzArray.cs
./Mono.Cecil.Signatures/TypeSpec.cs
./Mono.Cecil.Signatures/ValueType.cs
+./Mono.Cecil.Signatures/Var.cs
+./Mono.Cecil.Signatures/MVar.cs
+./Mono.Cecil.Signatures/GenericInst.cs
+./Mono.Cecil.Signatures/GenericInstSignature.cs
./Mono.Xml/MiniParser.cs
./Mono.Xml/SecurityParser.cs
./Mono.Xml/SmallXmlParser.cs
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches