Example #1
0
        AbstractVariable[] GetChilds()
        {
            ArrayList rootVariables = new ArrayList();

            StackFrame currentFrame;

            try {
                currentFrame = interpreter.CurrentThread.GetBacktrace().CurrentFrame;
            } catch {
                return(new AbstractVariable[0]);
            }

            foreach (TargetVariable variable in currentFrame.Method.Parameters)
            {
                rootVariables.Add(VariableFactory.Create(variable, currentFrame));
            }

            foreach (TargetVariable variable in currentFrame.Locals)
            {
                rootVariables.Add(VariableFactory.Create(variable, currentFrame));
            }

            if (currentFrame.Method.HasThis)
            {
                rootVariables.Add(VariableFactory.Create(currentFrame.Method.This, currentFrame));
            }

            return((AbstractVariable[])rootVariables.ToArray(typeof(AbstractVariable)));
        }
Example #2
0
        public static AbstractVariable Create(string name, TargetObject obj, StackFrame stackFrame)
        {
            if (obj == null)
            {
                return(new ErrorVariable(name, "Object is null"));
            }

            try {
                switch (obj.Kind)
                {
                case TargetObjectKind.Array:
                    return(new ArrayVariable(name, stackFrame, (TargetArrayObject)obj));

                case TargetObjectKind.Pointer:
                    TargetPointerObject pobj = (TargetPointerObject)obj;
                    if (!pobj.Type.IsTypesafe)
                    {
                        return(new ErrorVariable(name, "Pointer is not typesafe"));
                    }
                    try {
                        TargetObject deref = pobj.GetDereferencedObject(stackFrame.Thread);
                        return(VariableFactory.Create(name, deref, stackFrame));
                    } catch {
                        return(new ErrorVariable(name, "Can not dereference object"));
                    }

                case TargetObjectKind.Object:
                    try {
                        TargetObject deref = ((TargetObjectObject)obj).GetDereferencedObject(stackFrame.Thread);
                        return(VariableFactory.Create(name, deref, stackFrame));
                    } catch {
                        return(new ErrorVariable(name, "Can not dereference object"));
                    }

                case TargetObjectKind.Struct:
                case TargetObjectKind.Class:
                    return(new ClassVariable(name, stackFrame, (TargetClassObject)obj));

                case TargetObjectKind.Fundamental:
                    return(new FundamentalVariable(name, stackFrame, (TargetFundamentalObject)obj));

                case TargetObjectKind.Enum:
                    return(new EnumVariable(name, stackFrame, (TargetEnumObject)obj));

                default:
                    return(new ErrorVariable(name, "Unknown kind of object"));
                }
            } catch (Exception e) {
                return(new ErrorVariable(name, e.Message));
            }
        }
        AbstractVariable[] FieldsToNodes(TargetFieldInfo[] fields)
        {
            ArrayList nodes = new ArrayList();

            foreach (TargetFieldInfo field in fields)
            {
                AbstractVariable node;
                try {
                    TargetObject fobj = obj.GetField(stackFrame.Thread, field);
                    node = VariableFactory.Create(field.Name, fobj, stackFrame);
                } catch {
                    node = new ErrorVariable(field.Name, "Can not get field value");
                }
                nodes.Add(node);
            }

            return((AbstractVariable[])nodes.ToArray(typeof(AbstractVariable)));
        }
Example #4
0
        AbstractVariable GetChildNode(int index)
        {
            int[] newIndices = new int[dimension + 1];
            indicesPefix.CopyTo(newIndices, 0);
            newIndices[dimension] = index;

            if (newIndices.Length == obj.Type.Rank)
            {
                // We have reached the last dimension - create the element
                TargetObject element;
                try {
                    element = obj.GetElement(stackFrame.Thread, newIndices);
                } catch {
                    return(new ErrorVariable(IndicesToString(newIndices), "Can not get array element"));
                }
                return(VariableFactory.Create(IndicesToString(newIndices), element, stackFrame));
            }
            else
            {
                // Create a subset for the next dimension
                return(new ArraySubsetVariable(stackFrame, obj, newIndices));
            }
        }