Author: jbevain
Date: 2005-04-29 12:16:37 -0400 (Fri, 29 Apr 2005)
New Revision: 43793

Modified:
   trunk/cecil/lib/Mono.Cecil.Implem/AggressiveReflectionReader.cs
   trunk/cecil/lib/Mono.Cecil.Implem/EventDefinition.cs
   trunk/cecil/lib/Mono.Cecil.Implem/FieldDefinition.cs
   trunk/cecil/lib/Mono.Cecil.Implem/IDetailReader.cs
   trunk/cecil/lib/Mono.Cecil.Implem/LazyReflectionReader.cs
   trunk/cecil/lib/Mono.Cecil.Implem/ParameterDefinition.cs
   trunk/cecil/lib/Mono.Cecil.Implem/PropertyDefinition.cs
   trunk/cecil/lib/Mono.Cecil.Implem/ReflectionReader.cs
   trunk/cecil/lib/Mono.Cecil.Implem/TypeDefinition.cs
Log:
improved details reading

Modified: trunk/cecil/lib/Mono.Cecil.Implem/AggressiveReflectionReader.cs
===================================================================
--- trunk/cecil/lib/Mono.Cecil.Implem/AggressiveReflectionReader.cs     
2005-04-29 15:54:58 UTC (rev 43792)
+++ trunk/cecil/lib/Mono.Cecil.Implem/AggressiveReflectionReader.cs     
2005-04-29 16:16:37 UTC (rev 43793)
@@ -172,7 +172,7 @@
                         evt.InvokeMethod = semMeth;
                     else if ((semRow.Semantics & 
MethodSemanticsAttributes.RemoveOn) != 0)
                         evt.RemoveMethod = semMeth;
-                    evt.Readed = true;
+                    evt.SemanticLoaded = true;
                     break;
                 case TokenType.Property :
                     PropertyDefinition prop = m_properties 
[semRow.Association.RID - 1];
@@ -180,7 +180,7 @@
                         prop.GetMethod = semMeth;
                     else if ((semRow.Semantics & 
MethodSemanticsAttributes.Setter) != 0)
                         prop.SetMethod = semMeth;
-                    prop.Readed = true;
+                    prop.SemanticLoaded = true;
                     break;
                 }
             }
@@ -321,13 +321,19 @@
 
                 switch (csRow.Parent.TokenType) {
                 case TokenType.Field :
-                    m_fields [csRow.Parent.RID - 1].Constant = constant;
+                    FieldDefinition field = m_fields [csRow.Parent.RID - 1];
+                    field.Constant = constant;
+                    field.ConstantLoaded = true;
                     break;
                 case TokenType.Property :
-                    m_properties [csRow.Parent.RID - 1].Constant = constant;
+                    PropertyDefinition prop = m_properties [csRow.Parent.RID - 
1];
+                    prop.Constant = constant;
+                    prop.ConstantLoaded = true;
                     break;
                 case TokenType.Param :
-                    m_parameters [csRow.Parent.RID - 1].Constant = constant;
+                    ParameterDefinition param = m_parameters [csRow.Parent.RID 
- 1];
+                    param.Constant = constant;
+                    param.ConstantLoaded = true;
                     break;
                 }
             }

Modified: trunk/cecil/lib/Mono.Cecil.Implem/EventDefinition.cs
===================================================================
--- trunk/cecil/lib/Mono.Cecil.Implem/EventDefinition.cs        2005-04-29 
15:54:58 UTC (rev 43792)
+++ trunk/cecil/lib/Mono.Cecil.Implem/EventDefinition.cs        2005-04-29 
16:16:37 UTC (rev 43793)
@@ -23,12 +23,11 @@
 
         private CustomAttributeCollection m_customAttrs;
 
+        private bool m_semanticLoaded;
         private IMethodDefinition m_addMeth;
         private IMethodDefinition m_invMeth;
         private IMethodDefinition m_remMeth;
 
-        private bool m_readed;
-
         public ITypeReference EventType {
             get { return m_eventType; }
             set { m_eventType = value; }
@@ -63,9 +62,9 @@
             set { m_remMeth = value; }
         }
 
-        public bool Readed {
-            get { return m_readed; }
-            set { m_readed = value; }
+        public bool SemanticLoaded {
+            get { return m_semanticLoaded; }
+            set { m_semanticLoaded = value; }
         }
 
         public ICustomAttributeCollection CustomAttributes {

Modified: trunk/cecil/lib/Mono.Cecil.Implem/FieldDefinition.cs
===================================================================
--- trunk/cecil/lib/Mono.Cecil.Implem/FieldDefinition.cs        2005-04-29 
15:54:58 UTC (rev 43792)
+++ trunk/cecil/lib/Mono.Cecil.Implem/FieldDefinition.cs        2005-04-29 
16:16:37 UTC (rev 43793)
@@ -21,18 +21,28 @@
 
         private CustomAttributeCollection m_customAttrs;
 
+        private bool m_layoutLoaded;
         private bool m_hasInfo;
         private uint m_offset;
 
+        private bool m_constLoaded;
         private object m_const;
 
         private bool m_marshalLoaded;
         private MarshalDesc m_marshalDesc;
 
         public IFieldLayoutInfo LayoutInfo {
-            get { return this; }
+            get {
+                (this.DeclaringType as 
TypeDefinition).Module.Loader.DetailReader.ReadLayout (this);
+                return this;
+            }
         }
 
+        public bool LayoutLoaded {
+            get { return m_layoutLoaded; }
+            set { m_layoutLoaded = value; }
+        }
+
         public bool HasLayoutInfo {
             get { return m_hasInfo; }
         }
@@ -55,8 +65,16 @@
             set { m_attributes = value; }
         }
 
+        public bool ConstantLoaded {
+            get { return m_constLoaded; }
+            set { m_constLoaded = value; }
+        }
+
         public object Constant {
-            get { return m_const; }
+            get {
+                (this.DeclaringType as 
TypeDefinition).Module.Loader.DetailReader.ReadConstant (this);
+                return m_const;
+            }
             set { m_const = value; }
         }
 

Modified: trunk/cecil/lib/Mono.Cecil.Implem/IDetailReader.cs
===================================================================
--- trunk/cecil/lib/Mono.Cecil.Implem/IDetailReader.cs  2005-04-29 15:54:58 UTC 
(rev 43792)
+++ trunk/cecil/lib/Mono.Cecil.Implem/IDetailReader.cs  2005-04-29 16:16:37 UTC 
(rev 43793)
@@ -19,5 +19,12 @@
 
         void ReadMarshalSpec (ParameterDefinition param);
         void ReadMarshalSpec (FieldDefinition field);
+
+        void ReadLayout (TypeDefinition type);
+        void ReadLayout (FieldDefinition field);
+
+        void ReadConstant (FieldDefinition field);
+        void ReadConstant (PropertyDefinition prop);
+        void ReadConstant (ParameterDefinition param);
     }
 }

Modified: trunk/cecil/lib/Mono.Cecil.Implem/LazyReflectionReader.cs
===================================================================
--- trunk/cecil/lib/Mono.Cecil.Implem/LazyReflectionReader.cs   2005-04-29 
15:54:58 UTC (rev 43792)
+++ trunk/cecil/lib/Mono.Cecil.Implem/LazyReflectionReader.cs   2005-04-29 
16:16:37 UTC (rev 43793)
@@ -326,34 +326,13 @@
             props.Loaded = true;
         }
 
-        public override void Visit (IPropertyDefinition property)
-        {
-            //TODO: read constant
-        }
-
-        public override void Visit (ITypeDefinition type)
-        {
-            //TODO: read type layout
-        }
-
-        public override void Visit (IFieldDefinition field)
-        {
-            //TODO: read field layout
-            //TODO: read constant
-        }
-
-        public override void Visit (IParameterDefinition parameter)
-        {
-            //TODO: read constant
-        }
-
         public override void ReadSemantic (EventDefinition evt)
         {
-            if (evt.Readed)
+            if (evt.SemanticLoaded)
                 return;
 
             if (!m_tHeap.HasTable (typeof (MethodSemanticsTable))) {
-                evt.Readed = true;
+                evt.SemanticLoaded = true;
                 return;
             }
 
@@ -374,16 +353,16 @@
                 }
             }
 
-            evt.Readed = true;
+            evt.SemanticLoaded = true;
         }
 
         public override void ReadSemantic (PropertyDefinition prop)
         {
-            if (prop.Readed)
+            if (prop.SemanticLoaded)
                 return;
 
             if (!m_tHeap.HasTable (typeof (MethodSemanticsTable))) {
-                prop.Readed = true;
+                prop.SemanticLoaded = true;
                 return;
             }
 
@@ -402,7 +381,7 @@
                 }
             }
 
-            prop.Readed = true;
+            prop.SemanticLoaded = true;
         }
 
         public override void ReadMarshalSpec (ParameterDefinition param)
@@ -423,7 +402,7 @@
             field.MarshalSpecLoaded = true;
         }
 
-        private MarshalDesc GetMarshalDesc (int rid, TokenType tt, 
IHasMarshalSpec container)
+        private MarshalDesc GetMarshalDesc (int rid, TokenType target, 
IHasMarshalSpec container)
         {
             if (!m_tHeap.HasTable (typeof (FieldMarshalTable)))
                 return null;
@@ -431,12 +410,93 @@
             FieldMarshalTable fmTable = m_tHeap [typeof (FieldMarshalTable)] 
as FieldMarshalTable;
             for (int i = 0; i < fmTable.Rows.Count; i++) {
                 FieldMarshalRow fmRow = fmTable [i];
-                if (fmRow.Parent.TokenType == tt && fmRow.Parent.RID == rid) {
+                if (fmRow.Parent.TokenType == target && fmRow.Parent.RID == 
rid) {
                     return BuildMarshalDesc (m_sigReader.GetMarshalSig 
(fmRow.NativeType), container);
                 }
             }
 
             return null;
         }
+
+        public override void ReadLayout (TypeDefinition type)
+        {
+            if (type.LayoutLoaded || !m_tHeap.HasTable (typeof 
(ClassLayoutTable)))
+                return;
+
+            uint rid = (uint) GetRidForTypeDef (type);
+
+            ClassLayoutTable clTable = MetadataRoot.Streams.TablesHeap [typeof 
(ClassLayoutTable)] as ClassLayoutTable;
+            for (int i = 0; i < clTable.Rows.Count; i++) {
+                ClassLayoutRow clRow = clTable [i];
+                if (clRow.Parent == rid) {
+                    type.ClassSize = clRow.ClassSize;
+                    type.PackingSize = clRow.PackingSize;
+                    break;
+                }
+            }
+
+            type.LayoutLoaded = true;
+        }
+
+        public override void ReadLayout (FieldDefinition field)
+        {
+            if (field.LayoutLoaded || !m_tHeap.HasTable (typeof 
(FieldLayoutTable)))
+                return;
+
+            uint rid = (uint) Array.IndexOf (m_fields, field) + 1;
+
+            FieldLayoutTable flTable = MetadataRoot.Streams.TablesHeap [typeof 
(FieldLayoutTable)] as FieldLayoutTable;
+            for (int i = 0; i < flTable.Rows.Count; i++) {
+                FieldLayoutRow flRow = flTable [i];
+                if (flRow.Field == rid) {
+                    field.Offset = flRow.Offset;
+                    break;
+                }
+            }
+
+            field.LayoutLoaded = true;
+        }
+
+        public override void ReadConstant (FieldDefinition field)
+        {
+            if (field.ConstantLoaded)
+                return;
+
+            field.Constant = GetConstant (Array.IndexOf (m_fields, field) + 1, 
TokenType.Field);
+            field.ConstantLoaded = true;
+        }
+
+        public override void ReadConstant (PropertyDefinition prop)
+        {
+            if (prop.ConstantLoaded)
+                return;
+
+            prop.Constant = GetConstant (Array.IndexOf (m_properties, prop) + 
1, TokenType.Property);
+            prop.ConstantLoaded = true;
+        }
+
+        public override void ReadConstant (ParameterDefinition param)
+        {
+            if (param.ConstantLoaded)
+                return;
+
+            param.Constant = GetConstant (Array.IndexOf (m_parameters, param) 
+ 1, TokenType.Param);
+            param.ConstantLoaded = true;
+        }
+
+        public object GetConstant (int rid, TokenType target)
+        {
+            if (!m_tHeap.HasTable (typeof (ConstantTable)))
+                return null;
+
+            ConstantTable csTable = m_tHeap [typeof (ConstantTable)] as 
ConstantTable;
+            for (int i = 0; i < csTable.Rows.Count; i++) {
+                ConstantRow csRow = csTable [i];
+                if (csRow.Parent.TokenType == target && csRow.Parent.RID == 
rid)
+                    return GetConstant (csRow.Value, csRow.Type);
+            }
+
+            return null;
+        }
     }
 }

Modified: trunk/cecil/lib/Mono.Cecil.Implem/ParameterDefinition.cs
===================================================================
--- trunk/cecil/lib/Mono.Cecil.Implem/ParameterDefinition.cs    2005-04-29 
15:54:58 UTC (rev 43792)
+++ trunk/cecil/lib/Mono.Cecil.Implem/ParameterDefinition.cs    2005-04-29 
16:16:37 UTC (rev 43793)
@@ -22,6 +22,8 @@
         private int m_sequence;
         private ParamAttributes m_attributes;
         private ITypeReference m_paramType;
+
+        private bool m_constLoaded;
         private object m_const;
 
         private MethodReference m_method;
@@ -50,8 +52,16 @@
             set { m_paramType = value; }
         }
 
+        public bool ConstantLoaded {
+            get { return m_constLoaded; }
+            set { m_constLoaded = value; }
+        }
+
         public object Constant {
-            get { return m_const; }
+            get {
+                (m_method.DeclaringType as 
TypeDefinition).Module.Loader.DetailReader.ReadConstant (this);
+                return m_const;
+            }
             set { m_const = value; }
         }
 

Modified: trunk/cecil/lib/Mono.Cecil.Implem/PropertyDefinition.cs
===================================================================
--- trunk/cecil/lib/Mono.Cecil.Implem/PropertyDefinition.cs     2005-04-29 
15:54:58 UTC (rev 43792)
+++ trunk/cecil/lib/Mono.Cecil.Implem/PropertyDefinition.cs     2005-04-29 
16:16:37 UTC (rev 43793)
@@ -22,11 +22,11 @@
 
         private CustomAttributeCollection m_customAttrs;
 
+        private bool m_semanticLoaded;
         private IMethodDefinition m_getMeth;
         private IMethodDefinition m_setMeth;
 
-        private bool m_readed = false;
-
+        private bool m_constLoaded;
         private object m_const;
 
         public ITypeReference PropertyType {
@@ -34,9 +34,9 @@
             set { m_propertyType = value; }
         }
 
-        public bool Readed {
-            get { return m_readed; }
-            set { m_readed = value; }
+        public bool SemanticLoaded {
+            get { return m_semanticLoaded; }
+            set { m_semanticLoaded = value; }
         }
 
         public IParameterDefinitionCollection Parameters {
@@ -80,8 +80,16 @@
             set { m_setMeth = value; }
         }
 
+        public bool ConstantLoaded {
+            get { return m_constLoaded; }
+            set { m_constLoaded = value; }
+        }
+
         public object Constant {
-            get { return m_const; }
+            get {
+                (this.DeclaringType as 
TypeDefinition).Module.Loader.DetailReader.ReadConstant (this);
+                return m_const;
+            }
             set { m_const = value; }
         }
 

Modified: trunk/cecil/lib/Mono.Cecil.Implem/ReflectionReader.cs
===================================================================
--- trunk/cecil/lib/Mono.Cecil.Implem/ReflectionReader.cs       2005-04-29 
15:54:58 UTC (rev 43792)
+++ trunk/cecil/lib/Mono.Cecil.Implem/ReflectionReader.cs       2005-04-29 
16:16:37 UTC (rev 43793)
@@ -566,6 +566,26 @@
         {
         }
 
+        public virtual void ReadLayout (TypeDefinition type)
+        {
+        }
+
+        public virtual void ReadLayout (FieldDefinition field)
+        {
+        }
+
+        public virtual void ReadConstant (FieldDefinition field)
+        {
+        }
+
+        public virtual void ReadConstant (PropertyDefinition prop)
+        {
+        }
+
+        public virtual void ReadConstant (ParameterDefinition param)
+        {
+        }
+
         private object GetFixedArgValue (CustomAttrib.FixedArg fa)
         {
             if (fa.SzArray) {

Modified: trunk/cecil/lib/Mono.Cecil.Implem/TypeDefinition.cs
===================================================================
--- trunk/cecil/lib/Mono.Cecil.Implem/TypeDefinition.cs 2005-04-29 15:54:58 UTC 
(rev 43792)
+++ trunk/cecil/lib/Mono.Cecil.Implem/TypeDefinition.cs 2005-04-29 16:16:37 UTC 
(rev 43793)
@@ -21,6 +21,7 @@
         private TypeAttributes m_attributes;
         private ITypeReference m_baseType;
 
+        private bool m_layoutLoaded;
         private bool m_hasInfo;
         private ushort m_packingSize;
         private uint m_classSize;
@@ -43,9 +44,17 @@
         }
 
         public IClassLayoutInfo LayoutInfo {
-            get { return this; }
+            get {
+                this.Module.Loader.DetailReader.ReadLayout (this);
+                return this;
+            }
         }
 
+        public bool LayoutLoaded {
+            get { return m_layoutLoaded; }
+            set { m_layoutLoaded = value; }
+        }
+
         public bool HasLayoutInfo {
             get { return m_hasInfo; }
         }

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

Reply via email to