EvaluateType() public method

public EvaluateType ( ScriptingContext context ) : TargetType
context ScriptingContext
return Mono.Debugger.Languages.TargetType
コード例 #1
0
ファイル: Expression.cs プロジェクト: baulig/debugger
        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
ファイル: Expression.cs プロジェクト: baulig/debugger
        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
ファイル: EmonicCommand.cs プロジェクト: visual000/misc
        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;
            }
        }