This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

initial (uncompiling) conversion to Cecil

svn path=/branches/debugger-cecil/; revision=47286
  • Loading branch information...
Chris Toshok
Chris Toshok committed Jul 13, 2005
1 parent a404711 commit f51efa6ee076878f08086e07d7ab5683e692056e
@@ -1,6 +1,7 @@
using System;
using System.Text;
using C = Mono.CompilerServices.SymbolWriter;
+using Cecil = Mono.Cecil;
namespace Mono.Debugger.Languages.Mono
{
@@ -24,13 +25,13 @@ internal class MonoArrayType : MonoType, ITargetArrayType
protected MonoType element_type;
protected MonoArrayType subarray_type;
- public MonoArrayType (MonoSymbolFile file, Type type)
+ public MonoArrayType (MonoSymbolFile file, Cecil.IArrayType type)
: base (file, TargetObjectKind.Array, type)
{
- this.Rank = type.GetArrayRank ();
+ this.Rank = type.Rank;
this.Dimension = 0;
- element_type = file.LookupMonoType (type.GetElementType ());
+ element_type = file.LookupMonoType (type.ElementType);
if (Dimension + 1 < Rank)
subarray_type = new MonoArrayType (this);
@@ -1,7 +1,7 @@
using System;
using System.Text;
-using R = System.Reflection;
using C = Mono.CompilerServices.SymbolWriter;
+using Cecil = Mono.Cecil;
namespace Mono.Debugger.Languages.Mono
{
@@ -18,11 +18,14 @@ internal class MonoClassType : MonoType, ITargetClassType
MonoMethodInfo[] constructors;
MonoMethodInfo[] static_constructors;
+ Cecil.ITypeDefinition type;
MonoClassType parent_type;
- public MonoClassType (MonoSymbolFile file, Type type)
+ public MonoClassType (MonoSymbolFile file, Cecil.ITypeDefinition type)
: base (file, TargetObjectKind.Class, type)
{
+ this.type = type;
+
if (type.BaseType != null)
parent_type = file.MonoLanguage.LookupMonoType (type.BaseType) as MonoClassType;
}
@@ -46,11 +49,11 @@ void get_fields ()
int num_fields = 0, num_sfields = 0;
- R.FieldInfo[] finfo = type.GetFields (
- R.BindingFlags.DeclaredOnly | R.BindingFlags.Static | R.BindingFlags.Instance |
- R.BindingFlags.Public | R.BindingFlags.NonPublic);
+ foreach (Cecil.IFieldDefinition field in type.Fields) {
+ if (!finfo.Attributes & (Cecil.FieldAttributes.FieldAccessMask | Cecil.FieldAttributes.Static |
+ Cecil.FieldAttributes.Instance))
+ continue;
- foreach (R.FieldInfo field in finfo) {
if (field.IsStatic)
num_sfields++;
else
@@ -60,15 +63,21 @@ void get_fields ()
fields = new MonoFieldInfo [num_fields];
static_fields = new MonoFieldInfo [num_sfields];
- int pos = 0, spos = 0;
- for (int i = 0; i < finfo.Length; i++) {
- if (finfo [i].IsStatic) {
- static_fields [spos] = new MonoFieldInfo (File, spos, i, finfo [i]);
+ int pos = 0, spos = 0, i = 0;
+ foreach (Cecil.IFieldDefinition field in type.Fields) {
+ if (!field.Attributes & (Cecil.FieldAttributes.FieldAccessMask | Cecil.FieldAttributes.Static |
+ Cecil.FieldAttributes.Instance))
+ continue;
+
+ if (field.IsStatic) {
+ static_fields [spos] = new MonoFieldInfo (File, spos, i, field);
spos++;
} else {
- fields [pos] = new MonoFieldInfo (File, pos, i, finfo [i]);
+ fields [pos] = new MonoFieldInfo (File, pos, i, field);
pos++;
}
+
+ i++;
}
}
@@ -109,13 +118,11 @@ void get_methods ()
return;
int num_methods = 0, num_smethods = 0;
-
- R.MethodInfo[] minfo = type.GetMethods (
- R.BindingFlags.DeclaredOnly | R.BindingFlags.Static | R.BindingFlags.Instance |
- R.BindingFlags.Public | R.BindingFlags.NonPublic);
-
- foreach (R.MethodInfo method in minfo) {
- if ((method.Attributes & R.MethodAttributes.SpecialName) != 0)
+ foreach (Cecil.IMethod method in type.Methods) {
+ if (!method.Attributes & (Cecil.MethodAttributes.MemberAccessMask | Cecil.MethodAttributes.Static |
+ Cecil.MethodAttributes.Instance))
+ continue;
+ if ((method.Attributes & Cecil.MethodAttributes.SpecialName) != 0)
continue;
if (method.IsStatic)
num_smethods++;
@@ -126,17 +133,22 @@ void get_methods ()
methods = new MonoMethodInfo [num_methods];
static_methods = new MonoMethodInfo [num_smethods];
- int pos = 0, spos = 0;
- for (int i = 0; i < minfo.Length; i++) {
- if ((minfo [i].Attributes & R.MethodAttributes.SpecialName) != 0)
+ int pos = 0, spos = 0, i = 0;
+ foreach (Cecil.IMethod method in type.Methods) {
+ if (!method.Attributes & (Cecil.MethodAttributes.MemberAccessMask | Cecil.MethodAttributes.Static |
+ Cecil.MethodAttributes.Instance))
+ continue;
+ if ((method.Attributes & Cecil.MethodAttributes.SpecialName) != 0)
continue;
- if (minfo [i].IsStatic) {
- static_methods [spos] = new MonoMethodInfo (this, spos, minfo [i]);
+ if (method.IsStatic) {
+ static_methods [spos] = new MonoMethodInfo (this, spos, method);
spos++;
} else {
- methods [pos] = new MonoMethodInfo (this, pos, minfo [i]);
+ methods [pos] = new MonoMethodInfo (this, pos, method);
pos++;
}
+
+ i++;
}
}
@@ -180,26 +192,50 @@ public ITargetFunctionObject GetStaticMethod (StackFrame frame, int index)
void get_properties ()
{
+ int i;
if (properties != null)
return;
- R.PropertyInfo[] pinfo = type.GetProperties (
- R.BindingFlags.DeclaredOnly | R.BindingFlags.Instance |
- R.BindingFlags.Public | R.BindingFlags.NonPublic);
+ int num_sproperties = 0, num_properties = 0;
+
+ for (i = 0; i < type.Properties.Count; i++) {
+ IMethodDefinition m = type.Properties[i].GetMethod;
+ if (m == null) m = type.Properties[i].SetMethod;
- properties = new MonoPropertyInfo [pinfo.Length];
+ if (!m.Attributes & (Cecil.MethodAttributes.MemberAccessMask | Cecil.MethodAttributes.Static |
+ Cecil.MethodAttributes.Instance))
+ continue;
- for (int i = 0; i < pinfo.Length; i++)
- properties [i] = new MonoPropertyInfo (this, i, pinfo [i], false);
+ if (m.IsStatic)
+ num_sproperties++;
+ else
+ num_properties++;
+ }
- pinfo = type.GetProperties (
- R.BindingFlags.DeclaredOnly | R.BindingFlags.Static |
- R.BindingFlags.Public | R.BindingFlags.NonPublic);
+ properties = new MonoPropertyInfo [num_properties];
+ static_properties = new MonoPropertyInfo [num_sproperties];
+
+ int pos = 0, spos = 0;
+ i = 0;
+ foreach (IPropertyDefinition prop in type.Properties) {
+ IMethodDefinition m = type.Properties[i].GetMethod;
+ if (m == null) m = type.Properties[i].SetMethod;
- static_properties = new MonoPropertyInfo [pinfo.Length];
+ if (!m.Attributes & (Cecil.MethodAttributes.MemberAccessMask | Cecil.MethodAttributes.Static |
+ Cecil.MethodAttributes.Instance))
+ continue;
+
+ if (m.IsStatic) {
+ static_properties [spos] = new MonoPropertyInfo (this, spos, prop, true);
+ spos++;
+ }
+ else {
+ static_properties [pos] = new MonoPropertyInfo (this, spos, prop, false);
+ pos++;
+ }
- for (int i = 0; i < pinfo.Length; i++)
- static_properties [i] = new MonoPropertyInfo (this, i, pinfo [i], true);
+ i ++;
+ }
}
internal MonoPropertyInfo[] Properties {
@@ -232,26 +268,47 @@ public ITargetObject GetStaticProperty (StackFrame frame, int index)
void get_events ()
{
+ int i;
if (events != null)
return;
- R.EventInfo[] einfo = type.GetEvents (
- R.BindingFlags.DeclaredOnly | R.BindingFlags.Instance |
- R.BindingFlags.Public | R.BindingFlags.NonPublic);
+ int num_sevents = 0, num_events = 0;
+ for (i = 0; i < type.Events.Count; i++) {
+ IMethodDefinition m = type.Events[i].AddMethod;
- events = new MonoEventInfo [einfo.Length];
+ if (!m.Attributes & (Cecil.MethodAttributes.MemberAccessMask | Cecil.MethodAttributes.Static |
+ Cecil.MethodAttributes.Instance))
+ continue;
- for (int i = 0; i < einfo.Length; i++)
- events [i] = new MonoEventInfo (this, i, einfo [i], false);
+ if (m.IsStatic)
+ num_sevents++;
+ else
+ num_events++;
+ }
+
+ events = new MonoEventInfo [num_events];
+ static_events = new MonoEventInfo [num_sevents];
+
+ int pos = 0, spos = 0;
+ i = 0;
+ foreach (IEventDefinition ev in type.Events) {
+ IMethodDefinition m = type.Events[i].AddMethod;
- einfo = type.GetEvents (
- R.BindingFlags.DeclaredOnly | R.BindingFlags.Static |
- R.BindingFlags.Public | R.BindingFlags.NonPublic);
+ if (!m.Attributes & (Cecil.MethodAttributes.MemberAccessMask | Cecil.MethodAttributes.Static |
+ Cecil.MethodAttributes.Instance))
+ continue;
- static_events = new MonoEventInfo [einfo.Length];
+ if (m.IsStatic) {
+ static_events [spos] = new MonoEventInfo (this, spos, ev, true);
+ spos++;
+ }
+ else {
+ static_events [pos] = new MonoEventInfo (this, spos, ev, false);
+ pos++;
+ }
- for (int i = 0; i < einfo.Length; i++)
- static_events [i] = new MonoEventInfo (this, i, einfo [i], true);
+ i ++;
+ }
}
public ITargetEventInfo[] Events {
@@ -281,29 +338,27 @@ void get_constructors ()
int num_ctors = 0, num_sctors = 0;
- R.ConstructorInfo[] minfo = type.GetConstructors (
- R.BindingFlags.DeclaredOnly | R.BindingFlags.Static | R.BindingFlags.Instance |
- R.BindingFlags.Public | R.BindingFlags.NonPublic);
-
- foreach (R.ConstructorInfo method in minfo) {
+ foreach (Cecil.IMethod method in type.Constructors) {
if (method.IsStatic)
num_sctors++;
else
num_ctors++;
}
- constructors = new MonoMethodInfo [num_ctors];
- static_constructors = new MonoMethodInfo [num_sctors];
+ constructors = new MonoMethodInfo [num_methods];
+ static_constructors = new MonoMethodInfo [num_smethods];
- int pos = 0, spos = 0;
- for (int i = 0; i < minfo.Length; i++) {
- if (minfo [i].IsStatic) {
- static_constructors [spos] = new MonoMethodInfo (this, spos, minfo [i]);
+ int pos = 0, spos = 0, i = 0;
+ foreach (Cecil.IMethod method in type.Constructors) {
+ if (method.IsStatic) {
+ static_constructors [spos] = new MonoMethodInfo (this, spos, method);
spos++;
} else {
- constructors [pos] = new MonoMethodInfo (this, pos, minfo [i]);
+ constructors [pos] = new MonoMethodInfo (this, pos, method);
pos++;
}
+
+ i++;
}
}
@@ -1,7 +1,7 @@
using System;
using System.Text;
-using R = System.Reflection;
using C = Mono.CompilerServices.SymbolWriter;
+using Cecil = Mono.Cecil;
namespace Mono.Debugger.Languages.Mono
{
@@ -10,9 +10,13 @@ internal class MonoEnumType : MonoType, ITargetEnumType
MonoFieldInfo[] fields;
MonoFieldInfo[] static_fields;
- public MonoEnumType (MonoSymbolFile file, Type type)
+ Cecil.ITypeDefinition type;
+
+ public MonoEnumType (MonoSymbolFile file, Cecil.ITypeDefinition type)
: base (file, TargetObjectKind.Enum, type)
- { }
+ {
+ this.type = type;
+ }
public override bool IsByRef {
get { return !type.IsValueType; }
@@ -25,11 +29,11 @@ void get_fields ()
int num_fields = 0, num_sfields = 0;
- R.FieldInfo[] finfo = type.GetFields (
- R.BindingFlags.DeclaredOnly | R.BindingFlags.Static | R.BindingFlags.Instance |
- R.BindingFlags.Public | R.BindingFlags.NonPublic);
+ foreach (Cecil.IFieldDefinition field in type.Fields) {
+ if (!finfo.Attributes & (Cecil.FieldAttributes.FieldAccessMask | Cecil.FieldAttributes.Static |
+ Cecil.FieldAttributes.Instance))
+ continue;
- foreach (R.FieldInfo field in finfo) {
if (field.IsStatic)
num_sfields++;
else
@@ -39,8 +43,8 @@ void get_fields ()
fields = new MonoFieldInfo [num_fields];
static_fields = new MonoFieldInfo [num_sfields];
- int pos = 0, spos = 0;
- for (int i = 0; i < finfo.Length; i++) {
+ int pos = 0, spos = 0, i = 0;
+ foreach (Cecil.IFieldDefinition field in type.Fields) {
if (finfo [i].IsStatic) {
static_fields [spos] = new MonoFieldInfo (File, spos, i, finfo [i]);
spos++;
@@ -50,6 +54,8 @@ void get_fields ()
fields [pos] = new MonoFieldInfo (File, pos, i, finfo [i]);
pos++;
}
+
+ i++;
}
if (pos > 1)
throw new InternalError ("Mono enum type has more than one instance field.");
Oops, something went wrong.

0 comments on commit f51efa6

Please sign in to comment.