Example #1
0
        public void CallFunc(int mark)
        {
            checkBreak = false;
            while (true)
            {
                var e = SaveDefList
                        .Where(s => s.markLine == mark)
                        .ToList();
                string     defName = e[0].defName;
                List <int> res     = new List <int>();
                if (!stepOverIgnor)
                {
                    res = breakLine
                          .Where(s => s == e[0].markLine)
                          .ToList();
                }
                if (res.Count != 0 && !breakIgnor)
                {
                    lastBreak  = e[0].markLine;
                    checkBreak = true;
                    break;
                }
                else
                {
                    if (e[0].saveCom == "call")
                    {
                        var firstLineNewDef = SaveDefList
                                              .Where(s => s.defName == e[0].saveVar)
                                              .ToList();
                        defName = e[0].saveVar;
                        if (firstLineNewDef.Count != 0)
                        {
                            StackSave tempSaveStack = new StackSave
                            {
                                index   = mark,
                                defName = defName
                            };
                            StackSaves.Push(tempSaveStack);
                            mark = firstLineNewDef[0].markLine;
                            e[0] = firstLineNewDef[0];
                        }
                        else
                        {
                            _writer.WriteLine("Переменная отсутствует в памяти");
                            mark++;
                            var checkNext = SaveDefList
                                            .Where(s => s.markLine == mark)
                                            .ToList();
                            if (checkNext.Count == 1)
                            {
                                if (checkNext[0].defName != defName)
                                {
                                    var result = StackSaves.Pop();
                                    if (StackSaves.Count > 0)
                                    {
                                        SearchLastBreak(SaveDefList, result.index);
                                    }
                                    else
                                    {
                                        SearchLastBreak(SaveComList, result.index);
                                    }
                                }
                            }
                        }
                    }
                    if (e[0].defName == defName)
                    {
                        string temp = string.Format("{0} {1} {2}", e[0].saveCom, e[0].saveVar, e[0].saveVal);
                        SwithInterpreter(temp);
                        LastEditVar(e[0]);
                    }

                    for (int i = 0; i < SaveDefList.Count; i++)
                    {
                        if (SaveDefList[i].markLine == e[0].markLine && i + 1 < SaveDefList.Count)
                        {
                            mark = SaveDefList[i + 1].markLine;
                            break;
                        }
                    }
                    if (mark == e[0].markLine)
                    {
                        mark++;
                    }

                    var checkNextLine = SaveDefList
                                        .Where(s => s.markLine == mark)
                                        .ToList();
                    if (checkNextLine.Count == 1)
                    {
                        if (checkNextLine[0].defName != defName)
                        {
                            var result = StackSaves.Pop();
                            mark    = result.index;
                            defName = result.defName;
                            if (StackSaves.Count == 0)
                            {
                                break;
                            }
                        }
                        if (breakIgnor)
                        {
                            lastBreak  = checkNextLine[0].markLine;
                            breakIgnor = false;
                            break;
                        }
                    }
                    else
                    {
                        var mark2 = mark;
                        while (mark == mark2)
                        {
                            if (StackSaves.Count > 1)
                            {
                                var result = StackSaves.Pop();
                                mark    = result.index;
                                mark2   = result.index;
                                defName = result.defName;
                                for (int i = 0; i < SaveDefList.Count; i++)
                                {
                                    if (SaveDefList[i].markLine == e[0].markLine && i + 1 < SaveDefList.Count)
                                    {
                                        mark = SaveDefList[i + 1].markLine;
                                        break;
                                    }
                                }
                            }
                            else if (StackSaves.Count == 1)
                            {
                                lastBreak  = firstCallDef + 1;
                                breakIgnor = false;
                                var result = StackSaves.Pop();
                                return;
                            }
                        }
                    }
                }
            }
        }
Example #2
0
        public void SwithDebugOrRun(string command)
        {
            if (command == "step over")
            {
                if (run)
                {
                    //while (true)
                    //{
                    stepOverIgnor = true;
                    string temp     = "";
                    var    lastLine = SaveDefList
                                      .Where(s => s.markLine == lastBreak)
                                      .ToList();
                    if (lastLine.Count == 0)
                    {
                        lastLine = SaveComList
                                   .Where(s => s.markLine == lastBreak)
                                   .ToList();
                        if (lastLine.Count != 0)
                        {
                            if (lastLine[0].saveCom == "call")
                            {
                                var templ = SaveDefList
                                            .Where(s => s.defName == lastLine[0].saveVar)
                                            .ToList();
                                if (templ.Count != 0)
                                {
                                    lastBreak    = templ[0].markLine;
                                    firstCallDef = lastLine[0].markLine;
                                    StackSave tempSaveStack = new StackSave
                                    {
                                        index   = lastLine[0].markLine,
                                        defName = lastLine[0].saveVar
                                    };
                                    StackSaves.Push(tempSaveStack);
                                }
                            }
                            temp          = string.Format("{0} {1} {2}", lastLine[0].saveCom, lastLine[0].saveVar, lastLine[0].saveVal);
                            firstCallDef  = lastLine[0].markLine;
                            stepOverIgnor = true;
                            SwithInterpreter(temp);
                            LastEditVar(lastLine[0]);
                            SearchLastBreak(SaveComList, lastLine[0].markLine);
                        }
                        else
                        {
                            ResetMemory();
                            start = true;
                        }
                    }
                    else
                    {
                        breakIgnor = true;
                        CallFunc(lastLine[0].markLine);
                    }
                    if (lastLine[0].markLine + 1 == lastBreak)
                    {
                    }
                    //}
                    stepOverIgnor = false;
                }
            }

            if (command == "step")
            {
                if (run)
                {
                    breakIgnor = true;
                    string temp     = "";
                    var    lastLine = SaveDefList
                                      .Where(s => s.markLine == lastBreak)
                                      .ToList();
                    if (lastLine.Count == 0)
                    {
                        lastLine = SaveComList
                                   .Where(s => s.markLine == lastBreak)
                                   .ToList();
                        if (lastLine.Count != 0)
                        {
                            if (lastLine[0].saveCom == "call")
                            {
                                var templ = SaveDefList
                                            .Where(s => s.defName == lastLine[0].saveVar)
                                            .ToList();
                                if (templ.Count != 0)
                                {
                                    lastBreak    = templ[0].markLine;
                                    firstCallDef = lastLine[0].markLine;
                                    StackSave tempSaveStack = new StackSave
                                    {
                                        index   = lastLine[0].markLine,
                                        defName = lastLine[0].saveVar
                                    };
                                    StackSaves.Push(tempSaveStack);
                                }
                                else
                                {
                                    _writer.WriteLine("Переменная отсутсвует в памяти");
                                    SearchLastBreak(SaveComList, lastLine[0].markLine);
                                }
                            }
                            else
                            {
                                temp = string.Format("{0} {1} {2}", lastLine[0].saveCom, lastLine[0].saveVar, lastLine[0].saveVal);
                                SwithInterpreter(temp);
                                LastEditVar(lastLine[0]);
                                SearchLastBreak(SaveComList, lastLine[0].markLine);
                                if (lastBreak == lastLine[0].markLine)
                                {
                                    ResetMemory();
                                }
                            }
                        }
                        else
                        {
                            ResetMemory();
                        }
                    }
                    else
                    {
                        CallFunc(lastLine[0].markLine);
                    }
                }
            }

            if (command == "print mem")
            {
                foreach (var e in dictionary)
                {
                    if (dicLine.ContainsKey(e.Key))
                    {
                        _writer.WriteLine("{0} {1} {2}", e.Key, e.Value, dicLine[e.Key]);
                    }
                }
            }

            if (command == "print trace")
            {
                var printStack = StackSaves.ToArray();
                for (int i = 0; i < printStack.Length; i++)
                {
                    _writer.WriteLine("{0} {1} ", printStack[i].index, printStack[i].defName);
                }
            }

            if (command == "run" && SaveComList.Count > 0)
            {
                run = true;
                if (start)
                {
                    foreach (var e in SaveComList)
                    {
                        checkBreak = true;
                        start      = false;
                        var res = breakLine
                                  .Where(s => s == e.markLine)
                                  .ToList();
                        if (res.Count == 0)
                        {
                            if (e.saveCom == "call")
                            {
                                var firstLineNewDef = SaveDefList
                                                      .Where(s => s.defName == e.saveVar)
                                                      .ToList();
                                if (firstLineNewDef.Count != 0)
                                {
                                    firstCallDef = e.markLine;
                                    StackSave tempSaveStack = new StackSave
                                    {
                                        index   = e.markLine,
                                        defName = e.saveVar
                                    };
                                    StackSaves.Push(tempSaveStack);
                                }
                            }
                            string temp = string.Format("{0} {1} {2}", e.saveCom, e.saveVar, e.saveVal);
                            SwithInterpreter(temp);
                            LastEditVar(e);
                            if (checkBreak)
                            {
                                break;
                            }
                        }
                        else
                        {
                            lastBreak = e.markLine;
                            break;
                        }
                        start = true;
                    }
                    if (!checkBreak)
                    {
                        ResetMemory();
                    }
                }
                else
                {
                    while (true)
                    {
                        string temp     = "";
                        var    lastLine = SaveDefList
                                          .Where(s => s.markLine == lastBreak)
                                          .ToList();
                        if (lastLine.Count == 0)
                        {
                            lastLine = SaveComList
                                       .Where(s => s.markLine == lastBreak)
                                       .ToList();
                            if (lastLine.Count != 0)
                            {
                                if (lastLine[0].saveCom == "call")
                                {
                                    var firstLineNewDef = SaveDefList
                                                          .Where(s => s.defName == lastLine[0].saveVar)
                                                          .ToList();
                                    if (firstLineNewDef.Count == 0)
                                    {
                                        //_writer.WriteLine("Переменная отсутсвует в памяти");
                                    }
                                    else
                                    {
                                        firstCallDef = lastLine[0].markLine;
                                        StackSave tempSaveStack = new StackSave
                                        {
                                            index   = lastLine[0].markLine,
                                            defName = lastLine[0].saveVar
                                        };
                                        StackSaves.Push(tempSaveStack);
                                    }
                                }
                                temp = string.Format("{0} {1} {2}", lastLine[0].saveCom, lastLine[0].saveVar, lastLine[0].saveVal);
                                SwithInterpreter(temp);
                                LastEditVar(lastLine[0]);
                                SearchLastBreak(SaveComList, lastLine[0].markLine);
                                if (lastBreak == lastLine[0].markLine)
                                {
                                    lastBreak++;
                                }
                            }
                            else
                            {
                                ResetMemory();
                                break;
                            }
                        }
                        else
                        {
                            breakIgnor = true;
                            CallFunc(lastLine[0].markLine);
                        }
                        var res = breakLine
                                  .Where(s => s == lastBreak)
                                  .ToList();
                        if (res.Count != 0)
                        {
                            break;
                        }
                    }
                }
            }
        }