Author: jbevain
Date: 2007-10-11 07:41:44 -0400 (Thu, 11 Oct 2007)
New Revision: 87330

Modified:
   trunk/mcs/class/Mono.Cecil/ChangeLog
   trunk/mcs/class/Mono.Cecil/Mono.Cecil.Cil/DocumentType.cs
   trunk/mcs/class/Mono.Cecil/Mono.Cecil.Signatures/SignatureWriter.cs
   trunk/mcs/class/Mono.Cecil/Mono.Cecil/ReflectionWriter.cs
   trunk/mcs/class/Mono.Cecil/Mono.Cecil/TypeReference.cs
Log:
2007-10-11  Jb Evain  <[EMAIL PROTECTED]>

        * Mono.Cecil/TypeReference.cs: add a IsNested helper property.

        * Mono.Cecil/ReflectionWriter.cs
          Mono.Cecil.Signatures/SignatureWriter.cs:
                Integrate patch for Carlo, start working on enum writing
                in custom attribute.


Modified: trunk/mcs/class/Mono.Cecil/ChangeLog
===================================================================
--- trunk/mcs/class/Mono.Cecil/ChangeLog        2007-10-11 10:29:04 UTC (rev 
87329)
+++ trunk/mcs/class/Mono.Cecil/ChangeLog        2007-10-11 11:41:44 UTC (rev 
87330)
@@ -1,3 +1,12 @@
+2007-10-11  Jb Evain  <[EMAIL PROTECTED]>
+
+       * Mono.Cecil/TypeReference.cs: add a IsNested helper property.
+
+       * Mono.Cecil/ReflectionWriter.cs
+         Mono.Cecil.Signatures/SignatureWriter.cs:
+               Integrate patch for Carlo, start working on enum writing
+               in custom attribute.
+
 2007-10-09  Nestor Salceda  <[EMAIL PROTECTED]>
 
        * mono-cecil.pc.in:  Updated the version number.

Modified: trunk/mcs/class/Mono.Cecil/Mono.Cecil/ReflectionWriter.cs
===================================================================
--- trunk/mcs/class/Mono.Cecil/Mono.Cecil/ReflectionWriter.cs   2007-10-11 
10:29:04 UTC (rev 87329)
+++ trunk/mcs/class/Mono.Cecil/Mono.Cecil/ReflectionWriter.cs   2007-10-11 
11:41:44 UTC (rev 87330)
@@ -1336,9 +1336,6 @@
                        elem.ElemType = type;
                        elem.FieldOrPropType = GetCorrespondingType 
(type.FullName);
 
-                       if (elem.FieldOrPropType == ElementType.Class)
-                               throw new NotImplementedException ("Writing 
enums");
-
                        switch (elem.FieldOrPropType) {
                        case ElementType.Boolean :
                        case ElementType.Char :

Modified: trunk/mcs/class/Mono.Cecil/Mono.Cecil/TypeReference.cs
===================================================================
--- trunk/mcs/class/Mono.Cecil/Mono.Cecil/TypeReference.cs      2007-10-11 
10:29:04 UTC (rev 87329)
+++ trunk/mcs/class/Mono.Cecil/Mono.Cecil/TypeReference.cs      2007-10-11 
11:41:44 UTC (rev 87330)
@@ -92,12 +92,16 @@
                        }
                }
 
+               public bool IsNested {
+                       get { return this.DeclaringType != null; }
+               }
+
                public virtual string FullName {
                        get {
                                if (m_fullName != null && !m_fullNameDiscarded)
                                        return m_fullName;
 
-                               if (this.DeclaringType != null)
+                               if (this.IsNested)
                                        return string.Concat 
(this.DeclaringType.FullName, "/", this.Name);
 
                                if (m_namespace == null || m_namespace.Length 
== 0)

Modified: trunk/mcs/class/Mono.Cecil/Mono.Cecil.Cil/DocumentType.cs
===================================================================
--- trunk/mcs/class/Mono.Cecil/Mono.Cecil.Cil/DocumentType.cs   2007-10-11 
10:29:04 UTC (rev 87329)
+++ trunk/mcs/class/Mono.Cecil/Mono.Cecil.Cil/DocumentType.cs   2007-10-11 
11:41:44 UTC (rev 87330)
@@ -31,7 +31,7 @@
        using System;
 
        public abstract class DocumentType {
-               
+
                public static readonly Guid Other = new Guid (0x00000000, 
0x0000, 0x0000, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00);
                public static readonly Guid Text = new Guid (0x5a869d0b, 
0x6611, 0x11d3, 0xbd, 0x2a, 0x00, 0x00, 0xf8, 0x08, 0x49, 0xbd);
        }

Modified: trunk/mcs/class/Mono.Cecil/Mono.Cecil.Signatures/SignatureWriter.cs
===================================================================
--- trunk/mcs/class/Mono.Cecil/Mono.Cecil.Signatures/SignatureWriter.cs 
2007-10-11 10:29:04 UTC (rev 87329)
+++ trunk/mcs/class/Mono.Cecil/Mono.Cecil.Signatures/SignatureWriter.cs 
2007-10-11 11:41:44 UTC (rev 87330)
@@ -414,6 +414,19 @@
                                Write (elem, writer);
                }
 
+               static string GetEnumFullName (TypeReference type)
+               {
+                       string fullname = type.FullName;
+
+                       if (type.IsNested)
+                               fullname = fullname.Replace ('/', '+');
+
+                       if (type is TypeDefinition)
+                               return fullname;
+
+                       return string.Concat (fullname, ", ", 
type.Module.Assembly.Name.FullName);
+               }
+
                void Write (CustomAttrib.NamedArg na, MemoryBinaryWriter writer)
                {
                        if (na.Field)
@@ -423,6 +436,9 @@
                        else
                                throw new MetadataFormatException ("Unknown 
kind of namedarg");
 
+                       if (na.FieldOrPropType == ElementType.Class)
+                               na.FieldOrPropType = ElementType.Enum;
+
                        if (na.FixedArg.SzArray)
                                writer.Write ((byte) ElementType.SzArray);
 
@@ -432,20 +448,48 @@
                                writer.Write ((byte) na.FieldOrPropType);
 
                        if (na.FieldOrPropType == ElementType.Enum)
-                               Write (na.FixedArg.Elems [0].ElemType.FullName);
+                               Write (GetEnumFullName (na.FixedArg.Elems 
[0].ElemType));
 
                        Write (na.FieldOrPropName);
 
                        Write (na.FixedArg, writer);
                }
 
-               void Write (CustomAttrib.Elem elem, MemoryBinaryWriter writer) 
// TODO
+               static ElementType GetElementTypeFromTypeCode (TypeCode tc)
                {
+                       switch (tc) {
+                       case TypeCode.Byte:
+                               return ElementType.U1;
+                       case TypeCode.SByte:
+                               return ElementType.I1;
+                       case TypeCode.Int16:
+                               return ElementType.I2;
+                       case TypeCode.UInt16:
+                               return ElementType.U2;
+                       case TypeCode.Int32:
+                               return ElementType.I4;
+                       case TypeCode.UInt32:
+                               return ElementType.U4;
+                       case TypeCode.Int64:
+                               return ElementType.I8;
+                       case TypeCode.UInt64:
+                               return ElementType.U8;
+                       default:
+                               throw new ArgumentException ("tc");
+                       }
+               }
+
+               void Write (CustomAttrib.Elem elem, MemoryBinaryWriter writer)
+               {
                        if (elem.String)
                                elem.FieldOrPropType = ElementType.String;
                        else if (elem.Type)
                                elem.FieldOrPropType = ElementType.Type;
-                       else if (elem.BoxedValueType)
+
+                       if (elem.FieldOrPropType == ElementType.Class) // an 
enum in fact
+                               elem.FieldOrPropType = 
GetElementTypeFromTypeCode (Type.GetTypeCode (elem.Value.GetType ()));
+
+                       if (elem.BoxedValueType)
                                Write (elem.FieldOrPropType);
 
                        switch (elem.FieldOrPropType) {

_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches

Reply via email to