public static TargetClassType ToClassType(TargetType type) { TargetClassType ctype = type as TargetClassType; if (ctype != null) { return(ctype); } TargetObjectType otype = type as TargetObjectType; if (otype != null && otype.HasClassType) { ctype = otype.ClassType; if (ctype != null) { return(ctype); } } TargetArrayType atype = type as TargetArrayType; if (atype != null) { if (atype.Language.ArrayType != null) { return(atype.Language.ArrayType); } } throw new Exception(string.Format("Type `{0}' is not a struct or class.", type.Name)); }
protected void FormatEvents(TargetClassType type, bool is_static, TargetMemberAccessibility accessibility, List <string> members, string prefix, Hashtable hash) { List <TargetEventInfo> list = new List <TargetEventInfo> (); foreach (TargetEventInfo einfo in type.Events) { if (einfo.IsStatic != is_static) { continue; } if (einfo.Accessibility != accessibility) { continue; } list.Add(einfo); } if (list.Count == 0) { return; } foreach (TargetEventInfo einfo in list) { members.Add(FormatEvent(prefix, einfo, is_static, hash)); } }
protected void FormatMethods(TargetClassType type, bool is_ctor, bool is_static, TargetMemberAccessibility accessibility, List <string> members, string prefix, Hashtable hash) { List <TargetMethodInfo> list = new List <TargetMethodInfo> (); TargetMethodInfo[] methods = is_ctor ? type.Constructors : type.Methods; foreach (TargetMethodInfo method in methods) { if (method.IsStatic != is_static) { continue; } if (method.Accessibility != accessibility) { continue; } list.Add(method); } if (list.Count == 0) { return; } foreach (TargetMethodInfo method in list) { members.Add(FormatMethod(prefix, method, is_static, is_ctor, hash)); } }
protected void FormatFields(TargetClassType type, bool is_static, TargetMemberAccessibility accessibility, List <string> members, string prefix, Hashtable hash) { List <TargetFieldInfo> list = new List <TargetFieldInfo> (); foreach (TargetFieldInfo field in type.Fields) { if (field.IsStatic != is_static) { continue; } if (field.Accessibility != accessibility) { continue; } list.Add(field); } if (list.Count == 0) { return; } foreach (TargetFieldInfo field in list) { members.Add(FormatMember(prefix, field, is_static, hash) + ";\n"); } }
static TargetObject ImplicitReferenceConversion(MdbEvaluationContext ctx, TargetClassObject obj, TargetClassType type) { if (obj.Type == type) { return(obj); } if (obj.Type.HasParent) { TargetObject pobj = obj.GetParentObject(ctx.Thread); if (pobj != null) { pobj = ImplicitConversion(ctx, pobj, type); if (pobj != null) { return(pobj); } } } if (ImplicitReferenceConversionExists(ctx, obj.Type, type)) { return(obj); } return(null); }
protected void FormatProperties(TargetClassType type, bool is_static, TargetMemberAccessibility accessibility, List <string> members, string prefix, Hashtable hash) { List <TargetPropertyInfo> list = new List <TargetPropertyInfo> (); foreach (TargetPropertyInfo property in type.Properties) { if (property.IsStatic != is_static) { continue; } if (property.Accessibility != accessibility) { continue; } list.Add(property); } if (list.Count == 0) { return; } foreach (TargetPropertyInfo property in list) { members.Add(FormatProperty(prefix, property, is_static, hash)); } }
protected void FormatEvents(TargetClassType type, TargetMemberAccessibility accessibility, List <string> members, string prefix, Hashtable hash) { FormatEvents(type, false, accessibility, members, prefix, hash); FormatEvents(type, true, accessibility, members, prefix, hash); }
internal override TargetClassObject GetParentObject(TargetMemoryAccess target) { if (!type.HasParent || !type.IsByRef) { return(null); } TargetClassType sparent = type.GetParentType(target); if (sparent == null) { return(null); } return((TargetClassObject)sparent.GetObject(target, Location)); }
public static bool TryCast(MdbEvaluationContext ctx, TargetType source, TargetClassType target_type) { if (source == target_type) { return(true); } TargetClassType stype = ToClassType(source); if (stype == null) { return(false); } return(TryParentCast(ctx, stype, target_type)); }
bool IsSubclassOf(TargetMemoryAccess target, TargetClassType type, TargetType parent) { while (type != null) { if (type == parent) { return(true); } if (!type.HasParent) { return(false); } type = type.GetParentType(target); } return(false); }
protected override string Execute(ScriptingContext context, Expression expression, DisplayFormat format) { // try-catch block for whole method: if an exception occurs, we are able to // release the semaphore waiting for the command answer try { TargetType type = expression.EvaluateType(context); string fieldNames = ""; string fieldNamesStaticOnly = ""; if (type.Kind == TargetObjectKind.Class || type.Kind == TargetObjectKind.Struct) { TargetClassType stype = (TargetClassType)type; foreach (TargetFieldInfo field in stype.Fields) { fieldNames += field.Name; fieldNames += " "; if (field.IsStatic) { fieldNamesStaticOnly += field.Name; fieldNamesStaticOnly += " "; } } fieldNames = fieldNames.Trim(); fieldNamesStaticOnly = fieldNamesStaticOnly.Trim(); } string text = context.FormatType(type); context.Print(text); EmonicInterpreter.ptypeOutput = fieldNames; EmonicInterpreter.ptypeOutputStaticOnly = fieldNamesStaticOnly; EmonicInterpreter.ptypeSem.Release(); return(text); } catch { EmonicInterpreter.ptypeOutput = "--"; EmonicInterpreter.ptypeOutputStaticOnly = "--"; EmonicInterpreter.ptypeSem.Release(); throw; } }
protected bool DoResolve(TargetMemoryAccess target) { if (Parent != null) { if (!Parent.Resolve(target)) { return(false); } type = (TargetClassType)Parent.Type; } klass = (MonoClassInfo)type.GetClass(target); if (klass == null) { return(false); } fields = klass.GetFields(target); return(true); }
string MonoObjectToString(TargetClassObject obj) { TargetClassType ctype = obj.Type; if ((ctype.Name == "System.Object") || (ctype.Name == "System.ValueType")) { return(null); } string text, dummy; EE.EvaluationResult result; if (ctype.DebuggerDisplayAttribute != null) { result = HandleDebuggerDisplay(Interpreter, CurrentThread, obj, ctype.DebuggerDisplayAttribute, -1, out text, out dummy); if (result == EE.EvaluationResult.Ok) { return(String.Format("{{ {0} }}", text)); } else if (result == EE.EvaluationResult.InvalidExpression) { if (text != null) { return(text); } } } result = EE.MonoObjectToString(CurrentThread, obj, EE.EvaluationFlags.None, -1, out text); if (result == EE.EvaluationResult.Ok) { return(String.Format("{{ \"{0}\" }}", text)); } return(null); }
protected string FormatStruct(string prefix, TargetClassType type, Hashtable hash) { StringBuilder sb = new StringBuilder(); List <string> public_members = new List <string> (); List <string> protected_members = new List <string> (); List <string> internal_members = new List <string> (); List <string> private_members = new List <string> (); FormatFields(type, TargetMemberAccessibility.Public, public_members, prefix, hash); FormatFields(type, TargetMemberAccessibility.Protected, protected_members, prefix, hash); FormatFields(type, TargetMemberAccessibility.Internal, internal_members, prefix, hash); FormatFields(type, TargetMemberAccessibility.Private, private_members, prefix, hash); FormatProperties(type, TargetMemberAccessibility.Public, public_members, prefix, hash); FormatProperties(type, TargetMemberAccessibility.Protected, protected_members, prefix, hash); FormatProperties(type, TargetMemberAccessibility.Internal, internal_members, prefix, hash); FormatProperties(type, TargetMemberAccessibility.Private, private_members, prefix, hash); FormatEvents(type, TargetMemberAccessibility.Public, public_members, prefix, hash); FormatEvents(type, TargetMemberAccessibility.Protected, protected_members, prefix, hash); FormatEvents(type, TargetMemberAccessibility.Internal, internal_members, prefix, hash); FormatEvents(type, TargetMemberAccessibility.Private, private_members, prefix, hash); FormatMethods(type, TargetMemberAccessibility.Public, public_members, prefix, hash); FormatMethods(type, TargetMemberAccessibility.Protected, protected_members, prefix, hash); FormatMethods(type, TargetMemberAccessibility.Internal, internal_members, prefix, hash); FormatMethods(type, TargetMemberAccessibility.Private, private_members, prefix, hash); if (public_members.Count > 0) { sb.Append(prefix + "public:\n"); foreach (string text in public_members) { sb.Append(text); } } if (protected_members.Count > 0) { sb.Append(prefix + "protected:\n"); foreach (string text in protected_members) { sb.Append(text); } } if (internal_members.Count > 0) { sb.Append(prefix + "internal:\n"); foreach (string text in internal_members) { sb.Append(text); } } if (private_members.Count > 0) { sb.Append(prefix + "private:\n"); foreach (string text in private_members) { sb.Append(text); } } return(sb.ToString()); }
protected string FormatType(Thread target, string prefix, TargetType type, Hashtable hash) { string retval; if (hash == null) { hash = new Hashtable(); } if (hash.Contains(type)) { return(type.Name); } else { hash.Add(type, true); } switch (type.Kind) { case TargetObjectKind.Array: { TargetArrayType atype = (TargetArrayType)type; retval = atype.Name; break; } case TargetObjectKind.Enum: { StringBuilder sb = new StringBuilder(); TargetEnumType etype = type as TargetEnumType; sb.Append("enum "); if (etype.Name != null) { sb.Append(etype.Name); } sb.Append("\n" + prefix + "{\n"); foreach (TargetEnumInfo field in etype.Members) { sb.Append(FormatEnumMember(target, prefix, field, false, hash)); if (field != etype.Members[etype.Members.Length - 1]) { sb.Append(","); } sb.Append("\n"); } sb.Append(prefix + "}"); retval = sb.ToString(); break; } case TargetObjectKind.Class: case TargetObjectKind.Struct: { StringBuilder sb = new StringBuilder(); TargetClassType ctype = (TargetClassType)type; if (type.Kind == TargetObjectKind.Struct) { sb.Append("struct "); } else { sb.Append("class "); } if (ctype.Name != null) { sb.Append(ctype.Name); sb.Append(" "); } if (ctype.HasParent) { TargetClassType parent = ctype.GetParentType(target); sb.Append(": "); sb.Append(parent.Name); } sb.Append("\n" + prefix + "{\n"); sb.Append(FormatStruct(prefix, ctype, hash)); sb.Append(prefix + "}"); retval = sb.ToString(); break; } case TargetObjectKind.Alias: { TargetTypeAlias alias = (TargetTypeAlias)type; string name; if (alias.TargetType != null) { name = FormatType(target, prefix, alias.TargetType, hash); } else { name = "<unknown type>"; } retval = String.Format("typedef {0} = {1}", alias.Name, name); break; } case TargetObjectKind.GenericInstance: { TargetGenericInstanceType gtype = (TargetGenericInstanceType)type; StringBuilder sb = new StringBuilder(); if (gtype.ContainerType.Kind == TargetObjectKind.Struct) { sb.Append("struct "); } else { sb.Append("class "); } sb.Append(String.Format("{0} = ", gtype.Name)); TargetClassType parent = gtype.ContainerType.GetParentType(target); sb.Append(String.Format("{0}", gtype.ContainerType.Name)); if (parent != null) { sb.Append(String.Format(" : {0}", parent.Name)); } sb.Append("\n" + prefix + "{\n"); sb.Append(FormatStruct(prefix, gtype.ContainerType, hash)); sb.Append(prefix + "}"); retval = sb.ToString(); break; } default: retval = type.Name; break; } hash.Remove(type); return(retval); }
internal TargetClassObject(TargetClassType type, TargetLocation location) : base(type, location) { this.Type = type; }
public override bool IsExceptionType(TargetClassType type) { return(false); }
static TargetStructObject TryCurrentCast(MdbEvaluationContext ctx, TargetClassObject source, TargetClassType target_type) { TargetStructObject current = source.GetCurrentObject(ctx.Thread); if (current == null) { return(null); } return(TryParentCast(ctx, current, current.Type, target_type)); }
public override bool IsExceptionType(TargetClassType type) { return false; }
public static TargetObject TryCast(MdbEvaluationContext ctx, TargetObject source, TargetClassType target_type) { if (source.Type == target_type) { return(source); } TargetClassObject sobj = ToClassObject(ctx, source); if (sobj == null) { return(null); } TargetStructObject result = TryParentCast(ctx, sobj, sobj.Type, target_type); if (result != null) { return(result); } return(TryCurrentCast(ctx, sobj, target_type)); }
public ScopeInfo(int id, TargetVariable var, TargetClassType type) { this.ID = id; this.var = var; this.type = type; }
public static TargetObject Cast(MdbEvaluationContext ctx, TargetObject obj, TargetType targetType) { obj = ObjectUtil.GetRealObject(ctx, obj); if (obj.Type == targetType) { return(obj); } if (targetType is TargetObjectType || ObjectUtil.FixTypeName(targetType.Name) == "System.Object") { if (obj.Type.IsByRef) { return(obj); } return(BoxValue(ctx, obj)); } if (targetType is TargetPointerType) { throw new NotSupportedException(); } if (targetType is TargetFundamentalType) { TargetFundamentalObject fobj = obj as TargetFundamentalObject; if (fobj == null) { throw new NotSupportedException(); } TargetFundamentalType ftype = targetType as TargetFundamentalType; TargetObject ob = ExplicitFundamentalConversion(ctx, fobj, ftype); if (ob == null) { throw new NotSupportedException(); } return(ob); } if (targetType is TargetNullableType) { TargetNullableType ntype = (TargetNullableType)targetType; if (obj.Kind == TargetObjectKind.Null) { return(obj); } else if (obj.Kind != TargetObjectKind.Nullable) { return(ImplicitConversion(ctx, obj, ntype.ElementType)); } TargetNullableType ntype2 = (TargetNullableType)obj.Type; if (ImplicitConversionExists(ctx, ntype2.ElementType, ntype.ElementType)) { return(obj); } } TargetClassType ctype = ToClassType(targetType); TargetClassObject source = ToClassObject(ctx, obj); if (source == null) { throw new Exception(string.Format("Variable is not a class type.")); } return(TryCast(ctx, source, ctype)); }
protected bool DoResolve(TargetMemoryAccess target) { if (Parent != null) { if (!Parent.Resolve (target)) return false; type = (TargetClassType) Parent.Type; } klass = (MonoClassInfo) type.GetClass (target); if (klass == null) return false; fields = klass.GetFields (target); return true; }
public MonoStructType(MonoSymbolFile file, TargetClassType type, Cecil.TypeDefinition typedef) { this.File = file; this.Type = type; this.TypeDef = typedef; }