Inheritance: TargetStructType
Beispiel #1
0
        protected void FormatProperties(TargetClassType type,
						 TargetMemberAccessibility accessibility,
						 List<string> members, string prefix, Hashtable hash)
        {
            FormatProperties (type, false, accessibility, members, prefix, hash);
            FormatProperties (type, true, accessibility, members, prefix, hash);
        }
Beispiel #2
0
        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));
        }
Beispiel #3
0
        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));
        }
Beispiel #4
0
        static TargetClassObject TryParentCast(ScriptingContext context,
							 TargetClassObject source,
							 TargetClassType source_type,
							 TargetClassType target_type)
        {
            if (source_type == target_type)
                return source;

            if (!source_type.HasParent)
                return null;

            TargetClassType parent_type = source_type.GetParentType (context.CurrentThread);
            source = TryParentCast (context, source, parent_type, target_type);
            if (source == null)
                return null;

            return source.GetParentObject (context.CurrentThread) as TargetClassObject;
        }
		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);
		}
Beispiel #6
0
        static bool ImplicitReferenceConversionExists(ScriptingContext context,
							       TargetClassType source,
							       TargetClassType target)
        {
            if (source == target)
                return true;

            if (!source.HasParent)
                return false;

            TargetClassType parent_type = source.GetParentType (context.CurrentThread);
            return ImplicitReferenceConversionExists (context, parent_type, target);
        }
Beispiel #7
0
        public static bool TryCast(ScriptingContext context, TargetType source,
					    TargetClassType target_type)
        {
            if (source == target_type)
                return true;

            TargetClassType stype = Convert.ToClassType (source);
            if (stype == null)
                return false;

            return TryParentCast (context, stype, target_type);
        }
        public override bool IsExceptionType(TargetClassType ctype)
        {
            MonoClassType mono_type = ctype as MonoClassType;
            if (mono_type == null)
                return false;

            Cecil.TypeDefinition exc_type = builtin_types.ExceptionType.Type;
            Cecil.TypeDefinition type = mono_type.Type;

            while (type != null) {
                if (exc_type == type)
                    return true;

                type = resolve_cecil_type_ref (type.BaseType);
            }

            return false;
        }
        internal void AddCoreType(Cecil.TypeDefinition typedef, TargetType type,
					   TargetClassType klass, TargetAddress klass_address)
        {
            corlib.AddType (typedef, type);
            if (!class_hash.Contains (klass_address))
                class_hash.Add (klass_address, type);
        }
Beispiel #10
0
 public abstract bool IsExceptionType(TargetClassType type);
Beispiel #11
0
 public abstract bool IsExceptionType(TargetClassType type);
Beispiel #12
0
            void do_read_variables(TargetMemoryAccess memory)
            {
                if (!is_loaded)
                    throw new TargetException (TargetError.MethodNotLoaded);
                if (has_variables)
                    return;

                MonoLanguageBackend mono = file.MonoLanguage;

                TargetAddress decl_klass = mono.MetadataHelper.MonoMethodGetClass (
                    memory, address.MonoMethod);
                TargetType decl = mono.ReadMonoClass (memory, decl_klass);
                if (decl.HasClassType)
                    decl_type = decl.ClassType;
                else
                    decl_type = (TargetClassType) decl;

                do_read_blocks ();

                locals = new List<TargetVariable> ();
                parameters = new List<TargetVariable> ();
                scopes = new Dictionary<int,ScopeInfo> ();

                var captured_vars = new Dictionary<string,CapturedVariable> ();

                if (address.HasThis)
                    this_var = new MonoVariable (
                        "this", decl_type, true, true, this,
                        address.ThisVariableInfo);

                var scope_list = new List<ScopeInfo> ();

                C.ScopeVariable[] scope_vars = method.GetScopeVariables ();
                int num_scope_vars = scope_vars != null ? scope_vars.Length : 0;
                for (int i = 0; i < num_scope_vars; i++) {
                    C.ScopeVariable sv = scope_vars [i];

                    VariableInfo var;
                    if (sv.Index < 0) {
                        var = address.ThisVariableInfo;
                        this_is_captured = true;
                        this_var = null;
                    } else
                        var = address.LocalVariableInfo [sv.Index];

                    try {
                        TargetClassType type = mono.ReadStructType (memory, var.MonoType);
                        MonoVariable scope_var = new MonoVariable (
                            "$__" + sv.Scope, type, true, type.IsByRef, this, var);

                        ScopeInfo info = new ScopeInfo (sv.Scope, scope_var, type);
                        scopes.Add (sv.Scope, info);
                        scope_list.Add (info);
                    } catch (Exception ex) {
                        Report.Error ("Cannot read scope variable: {0}\n{1}", var, ex);
                    }
                }

                foreach (ScopeInfo scope in scope_list) {
                    read_scope (scope);
                }

                foreach (ScopeInfo scope in scopes.Values) {
                    C.AnonymousScopeEntry entry = file.File.GetAnonymousScope (scope.ID);
                    foreach (C.CapturedVariable captured in entry.CapturedVariables) {
                        CapturedVariable cv = new CapturedVariable (
                            scope, this, captured.Name, captured.CapturedName);

                        switch (captured.Kind) {
                        case C.CapturedVariable.CapturedKind.Local:
                            locals.Add (cv);
                            break;
                        case C.CapturedVariable.CapturedKind.Parameter:
                            parameters.Add (cv);
                            break;
                        case C.CapturedVariable.CapturedKind.This:
                            if (!cv.Resolve (memory))
                                throw new InternalError ();
                            if (cv.Type.HasClassType)
                                decl_type = cv.Type.ClassType;
                            else
                                decl_type = (TargetClassType) cv.Type;
                            this_var = cv;
                            continue;
                        default:
                            throw new InternalError ();
                        }

                        captured_vars.Add (captured.Name, cv);
                    }
                }

                var param_info = mdef.Parameters;
                for (int i = 0; i < param_info.Count; i++) {
                    if (captured_vars.ContainsKey (param_info [i].Name))
                        continue;

                    VariableInfo var = address.ParamVariableInfo [i];
                    TargetType type = mono.ReadType (memory, var.MonoType);
                    if (type == null)
                        type = mono.VoidType;

                    parameters.Add (new MonoVariable (
                        param_info [i].Name, type, false, type.IsByRef,
                        this, var, 0, 0));
                }

                C.LocalVariableEntry[] symfile_locals = method.GetLocals ();
                for (int i = 0; i < symfile_locals.Length; i++) {
                    C.LocalVariableEntry local = symfile_locals [i];

                    if (captured_vars.ContainsKey (local.Name))
                        continue;

                    VariableInfo var = address.LocalVariableInfo [local.Index];
                    TargetType type = mono.ReadType (memory, var.MonoType);
                    if (type == null)
                        type = mono.VoidType;

                    if (local.BlockIndex > 0) {
                        int index = local.BlockIndex - 1;
                        MonoCodeBlock block = code_blocks [index];
                        locals.Add (new MonoVariable (
                            local.Name, type, true, type.IsByRef, this, var,
                            block.StartAddress, block.EndAddress));
                    } else {
                        locals.Add (new MonoVariable (
                            local.Name, type, true, type.IsByRef, this, var));
                    }
                }

                has_variables = true;
            }
		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);
		}
		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);
		}
Beispiel #15
0
        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 ();
        }
Beispiel #16
0
        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;
        }
Beispiel #17
0
        static TargetObject ImplicitReferenceConversion(ScriptingContext context,
								 TargetClassObject obj,
								 TargetClassType type)
        {
            if (obj.Type == type)
                return obj;

            if (!obj.Type.HasParent)
                return null;

            return obj.GetParentObject (context.CurrentThread);
        }
Beispiel #18
0
        protected override bool DoResolve(ScriptingContext context)
        {
            Language language = CurrentFrame.Language;
            if (CurrentFrame.Language == null)
                throw new ScriptingException ("Current frame doesn't have a language.");

            TargetType exception_type = language.ExceptionType;
            if (exception_type == null)
                throw new ScriptingException ("Current language doesn't have any exceptions.");

            Expression expr = ParseExpression (context);
            if (expr == null)
                return false;

            expr = expr.ResolveType (context);
            if (expr == null)
                return false;

            type = expr.EvaluateType (context) as TargetClassType;
            if (!language.IsExceptionType (type))
                throw new ScriptingException ("Type `{0}' is not an exception type.", expr.Name);

            if (tgroup == null)
                tgroup = context.Interpreter.GetThreadGroup (Group, false);

            return true;
        }
Beispiel #19
0
        public static TargetObject TryCast(ScriptingContext context, TargetObject source,
						    TargetClassType target_type)
        {
            if (source.Type == target_type)
                return source;

            TargetClassObject sobj = Convert.ToClassObject (context.CurrentThread, source);
            if (sobj == null)
                return null;

            TargetClassObject result = TryParentCast (context, sobj, sobj.Type, target_type);
            if (result != null)
                return result;

            return TryCurrentCast (context, sobj, target_type);
        }
Beispiel #20
0
        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));
        }
Beispiel #21
0
        static TargetClassObject TryCurrentCast(ScriptingContext context,
							  TargetClassObject source,
							  TargetClassType target_type)
        {
            TargetClassObject current = source.GetCurrentObject (context.CurrentThread);
            if (current == null)
                return null;

            return TryParentCast (context, current, current.Type, target_type);
        }
Beispiel #22
0
        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");
        }
Beispiel #23
0
        static bool TryParentCast(ScriptingContext context,
					   TargetClassType source_type,
					   TargetClassType target_type)
        {
            if (source_type == target_type)
                return true;

            if (!source_type.HasParent)
                return false;

            TargetClassType parent_type = source_type.GetParentType (context.CurrentThread);
            return TryParentCast (context, parent_type, target_type);
        }
		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;
		}