EvaluateType() 공개 메소드

public EvaluateType ( ScriptingContext context ) : TargetType
context ScriptingContext
리턴 Mono.Debugger.Languages.TargetType
예제 #1
0
        TargetObject DoCast(ScriptingContext context, Expression expr,
				     TargetType target_type)
        {
            TargetObject source = expr.EvaluateObject (context);
            if (source == null)
                return null;

            if (target_type is TargetObjectType) {
                if (((source is TargetClassObject) && !source.Type.IsByRef) ||
                    (source is TargetFundamentalObject))
                    return target_type.Language.CreateBoxedObject (context.CurrentThread, source);

                if (source is TargetObjectObject)
                    return source;

                throw new ScriptingException (
                    "Cannot box object `{0}': not a value-type", expr.Name);
            }

            if (target_type is TargetPointerType) {
                TargetAddress address;

                PointerExpression pexpr = expr as PointerExpression;
                if (pexpr != null)
                    address = pexpr.EvaluateAddress (context);
                else {
                    TargetPointerType ptype = expr.EvaluateType (context)
                        as TargetPointerType;
                    if ((ptype == null) || ptype.IsTypesafe)
                        return null;

                    pexpr = new AddressOfExpression (expr);
                    pexpr.Resolve (context);

                    address = pexpr.EvaluateAddress (context);
                }

                return ((TargetPointerType) target_type).GetObject (address);
            }

            if (target_type is TargetFundamentalType) {
                TargetFundamentalObject fobj = expr.EvaluateObject (context)
                    as TargetFundamentalObject;
                if (fobj == null)
                    return null;

                TargetFundamentalType ftype = target_type as TargetFundamentalType;
                return Convert.ExplicitFundamentalConversion (context, fobj, ftype);
            }

            TargetClassType ctype = Convert.ToClassType (target_type);
            TargetClassObject source_cobj = Convert.ToClassObject (context.CurrentThread, source);

            if (source_cobj == null)
                throw new ScriptingException (
                    "Variable {0} is not a class type.", expr.Name);

            return TryCast (context, source_cobj, ctype);
        }
예제 #2
0
파일: Command.cs 프로젝트: baulig/debugger
        protected override string Execute(ScriptingContext context,
						   Expression expression, DisplayFormat format)
        {
            TargetType type = expression.EvaluateType (context);
            string text = context.FormatType (type);
            context.Print (text);
            return text;
        }
예제 #3
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;
        }
예제 #4
0
        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;
            }
        }