Beispiel #1
0
        public static List <C_VARIABLE> getVars(JObject jo)
        {
            List <C_VARIABLE> list = new List <C_VARIABLE>();

            foreach (var item in jo)
            {
                string name     = item.Key;
                JArray contents = (JArray)item.Value;
                string type     = contents[0].ToString();
                if (type == "C_DATA")
                {
                    C_DATA cd = mkDATA(name, contents);
                    list.Add(cd);
                }
                else if (type == "C_ARRAY")
                {
                    List <C_DATA> values = new List <C_DATA>();
                    for (int i = 2; i < contents.Count; i++)
                    {
                        JArray idx = (JArray)contents[i];
                        values.Add(mkDATA((i - 2).ToString(), idx));
                    }
                    C_ARRAY ca = new C_ARRAY(name, contents[1].ToString(), values);
                    list.Add(ca);
                }
            }

            return(list);
        }
        //public Trace Draw_All(Visual visual, int run_current_count)
        //{
        //    foreach (Trace step in visual.Trace)
        //    {
        //        if (run_current_count == step.Line)
        //        {
        //            init();

        //            Dictionary<string, UserControl_variableItem> dict = new Dictionary<string, UserControl_variableItem>();

        //            // Global Variables
        //            UserControl_funcPanel f1 = makeFuncPanel("Global Frame", step.Globals, dict);
        //            myVariable.Children.Add(f1);

        //            // Local Variables
        //            List<List<C_VARIABLE>> stack = step.getLocals();
        //            List<string> func_names = step.getFuncs();
        //            for (int i = 0; i < stack.Count; i++)
        //            {
        //                UserControl_funcPanel f2 = makeFuncPanel(func_names[i], stack[i], dict);
        //                myVariable.Children.Add(f2);
        //            }

        //            // Heap
        //            List<C_VARIABLE> heap = step.Heap;
        //            UserControl_funcPanel f3 = makeFuncPanel("Heap", heap, dict);
        //            myHeap.Children.Add(f3);


        //            // Pointer to Value
        //            RandomColorGenerator rcg = new RandomColorGenerator();
        //            foreach (var funcPanel in myVariable.Children)  //VARIABLES PART
        //            {
        //                UserControl_funcPanel uc = funcPanel as UserControl_funcPanel;
        //                pointerProcess(uc, dict, rcg);
        //            }
        //            foreach (var funcPanel in myHeap.Children)  //HEAP PART
        //            {
        //                UserControl_funcPanel uc = funcPanel as UserControl_funcPanel;
        //                pointerProcess(uc, dict, rcg);
        //            }

        //            return step;

        //        }
        //        else if (run_current_count == 0)
        //        {
        //            init();

        //            Dictionary<string, UserControl_variableItem> dict = new Dictionary<string, UserControl_variableItem>();

        //            // Global Variables
        //            UserControl_funcPanel f1 = makeFuncPanel("Global Frame", step.Globals, dict);
        //            myVariable.Children.Add(f1);

        //            // Heap
        //            List<C_VARIABLE> heap = step.Heap;
        //            UserControl_funcPanel f3 = makeFuncPanel("Heap", heap, dict);
        //            myHeap.Children.Add(f3);


        //            // Pointer to Value
        //            RandomColorGenerator rcg = new RandomColorGenerator();
        //            foreach (var funcPanel in myVariable.Children)  //VARIABLES PART
        //            {
        //                UserControl_funcPanel uc = funcPanel as UserControl_funcPanel;
        //                pointerProcess(uc, dict, rcg);
        //            }
        //            foreach (var funcPanel in myHeap.Children)  //HEAP PART
        //            {
        //                UserControl_funcPanel uc = funcPanel as UserControl_funcPanel;
        //                pointerProcess(uc, dict, rcg);
        //            }
        //        }
        //    }

        //    return null;
        //}


        private UserControl_funcPanel makeFuncPanel(string name, List <C_VARIABLE> vars, Dictionary <string, UserControl_variableItem> dict)
        {
            UserControl_funcPanel f = new UserControl_funcPanel();

            f.setLabel(name);

            foreach (var item in vars)
            {
                if (item is C_DATA) //primitive
                {
                    UserControl_variable uc = new UserControl_variable();
                    C_DATA variable         = item as C_DATA;

                    List <C_DATA> list = new List <C_DATA>();
                    list.Add(variable);

                    uc.AddValues(list, dict);

                    uc.setName(variable.Name);

                    f.Add(uc);
                }
                else
                {
                    UserControl_variable uc = new UserControl_variable();
                    C_ARRAY ca = item as C_ARRAY;

                    uc.AddValues(ca.Values, dict);

                    uc.setName(ca.Name);

                    f.Add(uc);
                }
            }

            return(f);
        }