Exemplo n.º 1
0
 protected TargetMethodInfo(TargetFunctionType type, string name, int index,
                            bool is_static, TargetMemberAccessibility accessibility,
                            string full_name)
     : base(type, name, index, is_static, accessibility)
 {
     this.Type     = type;
     this.FullName = full_name;
 }
Exemplo n.º 2
0
 protected TargetPropertyInfo(TargetType type, string name, int index,
                              bool is_static, TargetMemberAccessibility accessibility,
                              TargetFunctionType getter, TargetFunctionType setter)
     : base(type, name, index, is_static, accessibility)
 {
     this.Getter = getter;
     this.Setter = setter;
 }
Exemplo n.º 3
0
        public ML.TargetObject RuntimeInvoke(MdbEvaluationContext ctx, ML.TargetFunctionType function,
                                             ML.TargetStructObject object_argument,
                                             params ML.TargetObject[] param_objects)
        {
            MethodCall mc = new MethodCall(ctx, function, object_argument, param_objects);

            ctx.Adapter.AsyncExecute(mc, ctx.Options.EvaluationTimeout);
            return(mc.ReturnValue);
        }
Exemplo n.º 4
0
 protected TargetEventInfo(TargetType type, string name, int index,
                           bool is_static, TargetMemberAccessibility accessibility,
                           TargetFunctionType add, TargetFunctionType remove,
                           TargetFunctionType raise)
     : base(type, name, index, is_static, accessibility)
 {
     this.Add    = add;
     this.Remove = remove;
     this.Raise  = raise;
 }
Exemplo n.º 5
0
        protected TargetEventInfo(TargetType type, string name, int index,
					   bool is_static, TargetMemberAccessibility accessibility,
					   TargetFunctionType add, TargetFunctionType remove,
					   TargetFunctionType raise)
            : base(type, name, index, is_static, accessibility)
        {
            this.Add = add;
            this.Remove = remove;
            this.Raise = raise;
        }
Exemplo n.º 6
0
        public SourceLocation(TargetFunctionType function)
            : this(new DynamicSourceLocation (function, -1, -1))
        {
            Module = function.Module.Name;
            Method = function.FullName;
            Name = function.FullName;

            MethodSource source = function.GetSourceCode ();
            if (source != null)
                FileName = source.SourceFile.FileName;
        }
Exemplo n.º 7
0
        public RuntimeInvokeResult RuntimeInvoke(Thread thread,
							  TargetFunctionType function,
							  TargetStructObject object_argument,
							  TargetObject[] param_objects,
							  RuntimeInvokeFlags flags)
        {
            IInterruptionHandler interruption = InterruptionHandler ?? Interpreter;
            if (interruption.CheckInterruption ())
                throw new EvaluationTimeoutException ();

            RuntimeInvokeResult result = thread.RuntimeInvoke (
                function, object_argument, param_objects, flags);

            WaitHandle[] handles = new WaitHandle [2];
            handles [0] = interruption.InterruptionEvent;
            handles [1] = result.CompletedEvent;

            int ret = WaitHandle.WaitAny (handles);

            if (ret == 0) {
                result.Abort ();
                throw new EvaluationTimeoutException ();
            }

            return result;
        }
Exemplo n.º 8
0
        public RuntimeInvokeResult RuntimeInvoke(TargetFunctionType function,
							  TargetStructObject object_argument,
							  TargetObject[] param_objects,
							  RuntimeInvokeFlags flags)
        {
            lock (this) {
                check_alive ();
                RuntimeInvokeResult result = new RuntimeInvokeResult (this);
                servant.RuntimeInvoke (
                    function, object_argument, param_objects,
                    flags, result);
                return result;
            }
        }
Exemplo n.º 9
0
        public RuntimeInvokeResult RuntimeInvoke(TargetFunctionType function,
							  TargetStructObject object_argument,
							  TargetObject[] param_objects,
							  bool is_virtual, bool debug)
        {
            RuntimeInvokeFlags flags = RuntimeInvokeFlags.None;
            if (is_virtual)
                flags |= RuntimeInvokeFlags.VirtualMethod;
            if (debug)
                flags |= RuntimeInvokeFlags.BreakOnEntry;
            return RuntimeInvoke (function, object_argument, param_objects, flags);
        }
Exemplo n.º 10
0
            public override void RuntimeInvoke(TargetFunctionType function,
							    TargetStructObject object_argument,
							    TargetObject[] param_objects,
							    RuntimeInvokeFlags flags,
							    RuntimeInvokeResult result)
            {
                throw new InvalidOperationException ();
            }
Exemplo n.º 11
0
 protected MethodGroupExpression CreateMethodGroup(TargetFunctionType func)
 {
     return new MethodGroupExpression (
         func.DeclaringType, instance, func.Name,
         new TargetFunctionType[] { func },
         !func.IsStatic, func.IsStatic);
 }
Exemplo n.º 12
0
        protected override TargetObject DoEvaluateObject(ScriptingContext context)
        {
            Thread target = context.CurrentThread;
            TargetObject obj = expr.EvaluateObject (context);

            // array[int]
            TargetArrayObject aobj = obj as TargetArrayObject;
            if (aobj != null) {
                int[] int_indices = GetIntIndices (target, context);
                try {
                    return aobj.GetElement (target, int_indices);
                } catch (ArgumentException) {
                    throw new ScriptingException (
                        "Index of array expression `{0}' out of bounds.",
                        expr.Name);
                }
            }

            // pointer[int]
            TargetPointerObject pobj = obj as TargetPointerObject;
            if (pobj != null) {
                // single dimensional array only at present
                int[] int_indices = GetIntIndices (target, context);
                if (int_indices.Length != 1)
                    throw new ScriptingException (
                        "Multi-dimensial arrays of type {0} are not yet supported",
                        expr.Name);

                if (pobj.Type.IsArray)
                    return pobj.GetArrayElement (target, int_indices [0]);

                throw new ScriptingException (
                               "Variable {0} is not an array type.", expr.Name);
            }

            // indexers
            TargetClassObject sobj = Convert.ToClassObject (target, obj);
            if (sobj != null) {
                ArrayList props = new ArrayList ();
                foreach (TargetPropertyInfo prop in sobj.Type.Properties) {
                    if (!prop.CanRead)
                        continue;

                    props.Add (prop.Getter);
                }

                if (props.Count == 0)
                    throw new ScriptingException (
                        "Indexer `{0}' doesn't have a getter.", expr.Name);

                TargetFunctionType[] funcs = new TargetFunctionType [props.Count];
                props.CopyTo (funcs, 0);

                MethodGroupExpression mg = new MethodGroupExpression (
                    sobj.Type, sobj, expr.Name + ".this", funcs, true, false);

                InvocationExpression invocation = new InvocationExpression (
                    mg, indices);
                invocation.Resolve (context);

                return invocation.EvaluateObject (context);
            }

            throw new ScriptingException (
                "{0} is neither an array/pointer type, nor is it " +
                "an object with a valid indexer.", expr);
        }
Exemplo n.º 13
0
        public static bool IsApplicable(ScriptingContext context, TargetFunctionType method,
						 TargetType[] types, out string error)
        {
            TargetMethodSignature sig = method.GetSignature (context.CurrentThread);

            for (int i = 0; i < types.Length; i++) {
                TargetType param_type = sig.ParameterTypes [i];

                if (param_type == types [i])
                    continue;

                if (Convert.ImplicitConversionExists (context, types [i], param_type))
                    continue;

                error = String.Format (
                    "Argument {0}: Cannot implicitly convert `{1}' to `{2}'",
                    i, types [i].Name, param_type.Name);
                return false;
            }

            error = null;
            return true;
        }
Exemplo n.º 14
0
        protected override bool DoAssign(ScriptingContext context, TargetObject right)
        {
            Thread target = context.CurrentThread;
            TargetObject obj = expr.EvaluateObject (context);

            // array[int]
            TargetArrayObject aobj = obj as TargetArrayObject;
            if (aobj != null) {
                int[] int_indices = GetIntIndices (target, context);
                try {
                    aobj.SetElement (target, int_indices, right);
                } catch (ArgumentException) {
                    throw new ScriptingException (
                        "Index of array expression `{0}' out of bounds.",
                        expr.Name);
                }

                return true;
            }

            // indexers
            TargetClassObject sobj = Convert.ToClassObject (target, obj);
            if (sobj != null) {
                ArrayList props = new ArrayList ();
                foreach (TargetPropertyInfo prop in sobj.Type.Properties) {
                    if (!prop.CanWrite)
                        continue;

                    props.Add (prop.Setter);
                }

                if (props.Count == 0)
                    throw new ScriptingException (
                        "Indexer `{0}' doesn't have a setter.", expr.Name);

                TargetFunctionType[] funcs = new TargetFunctionType [props.Count];
                props.CopyTo (funcs, 0);

                MethodGroupExpression mg = new MethodGroupExpression (
                    sobj.Type, sobj, expr.Name + "[]", funcs, true, false);

                Expression[] indexargs = new Expression [indices.Length + 1];
                indices.CopyTo (indexargs, 0);
                indexargs [indices.Length] = new ArgumentExpression (right);

                InvocationExpression invocation = new InvocationExpression (
                    mg, indexargs);
                invocation.Resolve (context);

                invocation.Invoke (context, false);
                return true;
            }

            throw new ScriptingException (
                "{0} is neither an array/pointer type, nor is it " +
                "an object with a valid indexer.", expr);
        }
Exemplo n.º 15
0
        public static MethodGroupExpression ResolveDelegate(ScriptingContext context,
								     Expression expr)
        {
            TargetClassType ctype = Convert.ToClassType (expr.EvaluateType (context));
            if (ctype == null)
                return null;

            TargetClassObject cobj;
            try {
                cobj = Convert.ToClassObject (
                    context.CurrentThread, expr.EvaluateObject (context));
            } catch {
                cobj = null;
            }

            TargetClassType delegate_type = ctype.Language.DelegateType;
            if (!CastExpression.TryCast (context, ctype, delegate_type))
                return null;

            TargetFunctionType invoke = null;
            foreach (TargetMethodInfo method in ctype.Methods) {
                if (method.Name == "Invoke") {
                    invoke = method.Type;
                    break;
                }
            }

            if (invoke == null)
                return null;

            TargetFunctionType[] methods = new TargetFunctionType[] { invoke };

            MethodGroupExpression mg = new MethodGroupExpression (
                ctype, cobj, "Invoke", methods, true, false);
            return mg;
        }
		public MethodCall (MdbEvaluationContext ctx, TargetFunctionType function, TargetStructObject object_argument, TargetObject[] param_objects)
		{
			this.ctx = ctx;
			this.function = function;
			this.object_argument = object_argument;
			this.param_objects = param_objects;
		}
Exemplo n.º 17
0
        internal BreakpointHandle ResolveBreakpoint(Breakpoint breakpoint)
        {
            if (!module.IsLoaded)
                return null;

            if ((function == null) && (source == null)) {
                if (file != null) {
                    source = file.FindMethod (line);
                } else {
                    throw new TargetException (TargetError.LocationInvalid);
                }

                if ((source != null) && source.IsManaged)
                    function = source.Function;
            }

            if (function != null)
                return function.GetBreakpointHandle (breakpoint, line, column);

            if ((source == null) || source.IsManaged)
                throw new TargetException (TargetError.LocationInvalid);

            TargetAddress address = GetAddress ();
            if (!address.IsNull)
                return new AddressBreakpointHandle (breakpoint, address);

            return null;
        }
Exemplo n.º 18
0
        public DynamicSourceLocation(TargetFunctionType function, int line, int column)
        {
            this.function = function;
            this.file = null;
            this.module = function.Module;

            this.line = line;
            this.column = column;
        }
Exemplo n.º 19
0
        public DynamicSourceLocation(MethodSource source, SourceFile file, int line, int column)
        {
            if (source.IsManaged) {
                this.function = source.Function;
                this.module = function.Module;
            } else {
                this.module = source.Module;
                this.source = source;
            }

            this.file = file;
            this.line = line;
            this.column = column;
        }
		static bool IsApplicable (MdbEvaluationContext ctx, TargetFunctionType method, TargetType[] types, out string error, out int matchCount)
		{
			TargetMethodSignature sig = method.GetSignature (ctx.Thread);
			matchCount = 0;

			for (int i = 0; i < types.Length; i++) {
				TargetType param_type = sig.ParameterTypes [i];

				if (param_type == types [i]) {
					matchCount++;
					continue;
				}

				if (TargetObjectConvert.ImplicitConversionExists (ctx, types [i], param_type))
					continue;

				error = String.Format (
					"Argument {0}: Cannot implicitly convert `{1}' to `{2}'",
					i, types [i].Name, param_type.Name);
				return false;
			}

			error = null;
			return true;
		}
Exemplo n.º 21
0
        internal StackFrame(Thread thread, FrameType type, TargetAddress address,
				     TargetAddress stack_ptr, TargetAddress frame_address,
				     Registers registers, TargetFunctionType function,
				     SourceLocation location)
            : this(thread, type, address, stack_ptr, frame_address, registers)
        {
            this.function = function;
            this.language = function.DeclaringType.Language;
            this.name = new Symbol (function.FullName, address, 0);
            this.location = location;
        }
Exemplo n.º 22
0
        protected override Expression DoResolve(ScriptingContext context)
        {
            method_expr = (MethodGroupExpression) expr.ResolveMethod (
                context, LocationType.Method);
            if (method_expr == null)
                return null;

            argtypes = new TargetType [arguments.Length];

            for (int i = 0; i < arguments.Length; i++) {
                arguments [i] = arguments [i].Resolve (context);
                if (arguments [i] == null)
                    return null;

                argtypes [i] = arguments [i].EvaluateType (context);
            }

            method = method_expr.OverloadResolve (context, argtypes);

            resolved = true;
            return this;
        }
Exemplo n.º 23
0
        protected TargetMethodInfo(TargetFunctionType type, string name, int index,
					    bool is_static, TargetMemberAccessibility accessibility,
					    string full_name)
            : base(type, name, index, is_static, accessibility)
        {
            this.Type = type;
            this.FullName = full_name;
        }
Exemplo n.º 24
0
        public MethodGroupExpression(TargetStructType stype, TargetStructObject instance,
					      string name, TargetFunctionType[] methods,
					      bool is_instance, bool is_static)
        {
            this.stype = stype;
            this.instance = instance;
            this.name = name;
            this.methods = methods;
            this.is_instance = is_instance;
            this.is_static = is_static;
            resolved = true;
        }
Exemplo n.º 25
0
        protected TargetPropertyInfo(TargetType type, string name, int index,
					      bool is_static, TargetMemberAccessibility accessibility,
					      TargetFunctionType getter, TargetFunctionType setter)
            : base(type, name, index, is_static, accessibility)
        {
            this.Getter = getter;
            this.Setter = setter;
        }
Exemplo n.º 26
0
        public TargetObject Invoke(ScriptingContext context)
        {
            TargetClassType stype = Convert.ToClassType (
                type_expr.EvaluateType (context));

            TargetMethodInfo[] ctors = stype.Constructors;
            TargetFunctionType[] funcs = new TargetFunctionType [ctors.Length];
            for (int i = 0; i < ctors.Length; i++)
                funcs [i] = ctors [i].Type;

            MethodGroupExpression mg = new MethodGroupExpression (
                stype, null, ".ctor", funcs, false, true);

            InvocationExpression invocation = new InvocationExpression (mg, arguments);
            invocation.Resolve (context);

            return invocation.EvaluateObject (context);
        }
Exemplo n.º 27
0
            public OperationRuntimeInvoke(SingleSteppingEngine sse,
					       TargetFunctionType function,
					       TargetStructObject instance,
					       TargetObject[] param_objects,
					       RuntimeInvokeFlags flags,
					       RuntimeInvokeResult result)
                : base(sse, result)
            {
                this.Result = result;
                this.Function = (MonoFunctionType) function;
                this.Instance = instance;
                this.ParamObjects = param_objects;
                this.Flags = flags;
            }
Exemplo n.º 28
0
        public static MemberExpression FindMember(Thread target, TargetStructType stype,
							   TargetStructObject instance, string name,
							   bool search_static, bool search_instance)
        {
            again:
            TargetClass klass = stype.GetClass (target);
            if (klass != null) {
                TargetMemberInfo member = klass.FindMember (
                    target, name, search_static, search_instance);
                if (member != null)
                    return new StructAccessExpression (stype, instance, member);

                ArrayList methods = new ArrayList ();
                bool is_instance = false;
                bool is_static = false;

                TargetMethodInfo[] klass_methods = klass.GetMethods (target);
                if (klass_methods != null) {
                    foreach (TargetMethodInfo method in klass_methods) {
                        if (method.IsStatic && !search_static)
                            continue;
                        if (!method.IsStatic && !search_instance)
                            continue;
                        if (method.Name != name)
                            continue;

                        methods.Add (method.Type);
                        if (method.IsStatic)
                            is_static = true;
                        else
                            is_instance = true;
                    }
                }

                if (methods.Count > 0) {
                    TargetFunctionType[] funcs = new TargetFunctionType [methods.Count];
                    methods.CopyTo (funcs, 0);
                    return new MethodGroupExpression (
                        stype, instance, name, funcs, is_instance, is_static);
                }
            }

            TargetClassType ctype = stype as TargetClassType;
            if (ctype != null) {
                TargetMemberInfo member = ctype.FindMember (
                    name, search_static, search_instance);

                if (member != null)
                    return new StructAccessExpression (ctype, instance, member);

                ArrayList methods = new ArrayList ();
                bool is_instance = false;
                bool is_static = false;

                if (name == ".ctor") {
                    foreach (TargetMethodInfo method in ctype.Constructors) {
                        if (method.IsStatic)
                            continue;
                        methods.Add (method.Type);
                        is_instance = true;
                    }
                } else if (name == ".cctor") {
                    foreach (TargetMethodInfo method in ctype.Constructors) {
                        if (!method.IsStatic)
                            continue;
                        methods.Add (method.Type);
                        is_static = true;
                    }
                } else {
                    foreach (TargetMethodInfo method in ctype.Methods) {
                        if (method.IsStatic && !search_static)
                            continue;
                        if (!method.IsStatic && !search_instance)
                            continue;
                        if (method.Name != name)
                            continue;

                        methods.Add (method.Type);
                        if (method.IsStatic)
                            is_static = true;
                        else
                            is_instance = true;
                    }
                }

                if (methods.Count > 0) {
                    TargetFunctionType[] funcs = new TargetFunctionType [methods.Count];
                    methods.CopyTo (funcs, 0);
                    return new MethodGroupExpression (
                        ctype, instance, name, funcs, is_instance, is_static);
                }
            }

            if (stype.HasParent) {
                stype = stype.GetParentType (target);
                if (instance != null) {
                    instance = instance.GetParentObject (target);
                    if (instance == null)
                        return null;
                }
                goto again;
            }

            return null;
        }
Exemplo n.º 29
0
        public override void RuntimeInvoke(TargetFunctionType function,
						    TargetStructObject object_argument,
						    TargetObject[] param_objects,
						    RuntimeInvokeFlags flags,
						    RuntimeInvokeResult result)
        {
            enforce_managed_context ();
            StartOperation (new OperationRuntimeInvoke (
                this, function, object_argument, param_objects,
                flags, result));
        }
Exemplo n.º 30
0
        public TargetFunctionType QueryMethod(TargetFunctionType[] methods)
        {
            Report.Print ("More than one method matches your query:\n");

            ArrayList list = new ArrayList ();

            foreach (TargetFunctionType method in methods) {
                list.Add (method);
                Report.Print ("{0,4}  {1}\n", list.Count, method.Name);
            }

            Report.Print ("Select a method or 0 to abort: ");
            string result = Report.ReadLine ();

            uint index;
            try {
                index = UInt32.Parse (result);
            } catch {
                Report.Print ("Invalid number.");
                return null;
            }

            if (index == 0)
                return null;

            if (index > list.Count) {
                Report.Print ("No such method.");
                return null;
            }

            return (TargetFunctionType) list [(int) index];
        }
Exemplo n.º 31
0
        public abstract void RuntimeInvoke(TargetFunctionType function,
						    TargetStructObject object_argument,
						    TargetObject[] param_objects,
						    RuntimeInvokeFlags flags,
						    RuntimeInvokeResult result);