Evaluate() public method

public Evaluate ( ScriptingContext context ) : object
context ScriptingContext
return object
Example #1
0
        private long GetValue(ScriptingContext context, Expression expr)
        {
            object val = expr.Evaluate (context);
            again:
            if (val is int)
                return (long) (int) val;
            else if (val is uint)
                return (long) (uint) val;
            else if (val is ulong)
                return (long) (ulong) val;
            else if (val is long)
                return (long) val;
            else if (val is TargetPointerObject) {
                TargetPointerObject pobj = (TargetPointerObject) val;
                return pobj.GetAddress (context.CurrentThread).Address;
            } else if (val is TargetFundamentalObject) {
                TargetFundamentalObject fobj = (TargetFundamentalObject) val;
                val = fobj.GetObject (context.CurrentThread);
                if (!(val is TargetFundamentalObject))
                    goto again;
            }

            throw new ScriptingException ("Cannot evaluate expression `{0}'", expr.Name);
        }
Example #2
0
        protected override string Execute(ScriptingContext context,
						   Expression expression, DisplayFormat format)
        {
            if (NestedBreakStates)
                context.ScriptingFlags |= ScriptingFlags.NestedBreakStates;

            if (expression is TypeExpression)
                throw new ScriptingException (
                    "`{0}' is a type, not a variable.", expression.Name);
            object retval = expression.Evaluate (context);
            string text = context.FormatObject (retval, format);
            context.Print (text);
            return text;
        }
Example #3
0
        int GetIntIndex(Thread target, Expression index, ScriptingContext context)
        {
            try {
                object idx = index.Evaluate (context);

                if (idx is int)
                    return (int) idx;
                else if (idx is long)
                    return (int) (long) idx;

                TargetFundamentalObject obj = (TargetFundamentalObject) idx;
                return (int) obj.GetObject (target);
            } catch (Exception e) {
                throw new ScriptingException (
                    "Cannot convert {0} to an integer for indexing: {1}",
                    index, e);
            }
        }
Example #4
0
        protected override string Execute(ScriptingContext context,
		                                   Expression expression, DisplayFormat format)
        {
            try {
                if (expression is TypeExpression)
                    throw new ScriptingException (
                                                  "`{0}' is a type, not a variable.", expression.Name);
                object retval = expression.Evaluate (context);

                EmonicInterpreter.printData output = new EmonicInterpreter.printData();
                output.type = "";
                output.varValue = "";
                output.varNames = "";

                if (retval != null) {
                    output.type = ((TargetObject)retval).TypeName;
                    if (output.type == null)
                        output.type = "";

                    switch (((TargetObject)retval).Kind) {
                        case TargetObjectKind.Fundamental:
                        // we send the value of the fundamental type
                        TargetFundamentalObject tfo = retval as TargetFundamentalObject;
                        if (tfo == null) {
                            // element is "null"
                            output.varValue = "<null>";
                            break;
                        }
                        output.varValue = tfo.GetObject(context.CurrentThread).ToString();
                        if (output.varValue == null)
                            output.varValue = "";
                        break;
                        case TargetObjectKind.Array:
                        // we send back the number of array elements
                        TargetArrayObject tao = retval as TargetArrayObject;
                        if (tao == null) {
                            // element is "null"
                            output.varValue = "<null>";
                            break;
                        }
                        int lower = tao.GetLowerBound (context.CurrentThread, 0);
                        int upper = tao.GetUpperBound (context.CurrentThread, 0);
                        output.varNames = (upper-lower).ToString();
                        break;
                        // same for struct and class
                        case TargetObjectKind.Struct:
                        case TargetObjectKind.Class:
                        // we send back the member's names
                        // NOTE! we also show static and constant fields
                        TargetObject obj = retval as TargetObject;
                        if (obj.HasAddress && obj.GetAddress(context.CurrentThread).IsNull) {
                            output.varValue = "<null>";
                            break;
                        }
                        Mono.Debugger.Thread thread = context.CurrentThread;
                        TargetClass tc = ((TargetClassObject)retval).Type.GetClass(thread);
                        if (tc == null)
                            break;
                        TargetFieldInfo[] tfi = tc.GetFields(thread);
                        if (tfi == null)
                            break;
                        output.varNames = "";
                        for (int i=0; i<tfi.Length; i++) {
                            if (tfi[i].IsStatic) // do not show static fields, they're not accessible via the instance!
                                continue;
                            output.varNames += tfi[i].Name;
                            output.varNames += " ";
                        }
                        output.varNames = output.varNames.Trim();
                        break;
                        case TargetObjectKind.Object:
                        case TargetObjectKind.Pointer:
                        case TargetObjectKind.Unknown:
                        case TargetObjectKind.Function:
                        case TargetObjectKind.Alias:
                        case TargetObjectKind.Enum:
                        context.Print("ERROR: Print Command will return no values because of an implementation error");
                        break;
                    }
                }
                string text = context.FormatObject (retval, format);
                context.Print (text);

                EmonicInterpreter.printOutput = output;
                EmonicInterpreter.printSem.Release();

                return text;
            } catch {
                EmonicInterpreter.printData output = new EmonicInterpreter.printData();
                output.type = "";
                output.varValue = "";
                output.varNames = "";
                EmonicInterpreter.printOutput = output;
                EmonicInterpreter.printSem.Release();
                throw;
            }
        }