public void PushState(ActionBase.ActionType ty, ExecState ex, bool pushpos = false)
 {
     execlevel++;
     exectype[execlevel]    = ty;
     execstate[execlevel]   = ex;
     execlooppos[execlevel] = (pushpos) ? (nextstepnumber - 1) : -1;
 }
 public bool IsExecutingType(ActionBase.ActionType ty)
 {
     return(exectype[execlevel] == ty);
 }
 public void PushState(ActionBase.ActionType ty, bool res, bool pushpos = false)
 {
     PushState(ty, res ? ExecState.On : ExecState.Off, pushpos);
 }
Exemple #4
0
        public string CalculateLevels()         // go thru the program, and calc some values for editing purposes. Also look for errors
        {
            string errlist = "";

            int structlevel = 0;

            int[] structcount = new int[50];
            ActionBase.ActionType[] structtype = new ActionBase.ActionType[50];

            System.Globalization.CultureInfo ct = System.Globalization.CultureInfo.InvariantCulture;
            int  step = 1;
            bool lastwaswhileafterdo = false;

            int lineno = 1;

            foreach (ActionBase act in programsteps)
            {
                if (act != null)
                {
                    act.calcAllowRight = act.calcAllowLeft = false;
                    bool indo = structtype[structlevel] == ActionBase.ActionType.Do; // if in a DO..WHILE, and we are a WHILE, we don't indent.

                    if (indo && lastwaswhileafterdo && act.LevelUp == 0)             // force back down if after do/while
                    {
                        act.LevelUp = 1;
                    }

                    if (act.LevelUp > 0)                   // if backing up
                    {
                        if (structcount[structlevel] == 0) // if we had nothing on this level, its wrong
                        {
                            errlist += "Step " + step.ToString(ct) + " no statements at indented level after " + structtype[structlevel].ToString() + " statement" + Environment.NewLine;
                        }

                        if (act.LevelUp > structlevel)            // ensure its not too big.. this may happen due to copying
                        {
                            act.LevelUp = structlevel;
                        }

                        structlevel       -= act.LevelUp;                             // back up
                        act.calcAllowRight = act.LevelUp > 1 || !lastwaswhileafterdo; // normally we can go right, but can't if its directly after do..while and only 1 level of detent
                    }

                    lastwaswhileafterdo = false;                         // records if last entry was while after do

                    structcount[structlevel]++;                          // 1 more on this level

                    if (structlevel > 0 && structcount[structlevel] > 1) // second further on can be moved back..
                    {
                        act.calcAllowLeft = true;
                    }

                    act.calcStructLevel = act.calcDisplayLevel = structlevel;

                    if (act.Type == ActionBase.ActionType.ElseIf)
                    {
                        if (structtype[structlevel] == ActionBase.ActionType.Else)
                        {
                            errlist += "Step " + step.ToString(ct) + " ElseIf after Else found" + Environment.NewLine;
                        }
                        else if (structtype[structlevel] != ActionBase.ActionType.If && structtype[structlevel] != ActionBase.ActionType.ElseIf)
                        {
                            errlist += "Step " + step.ToString(ct) + " ElseIf without IF found" + Environment.NewLine;
                        }
                    }
                    else if (act.Type == ActionBase.ActionType.Else)
                    {
                        if (structtype[structlevel] == ActionBase.ActionType.Else)
                        {
                            errlist += "Step " + step.ToString(ct) + " Else after Else found" + Environment.NewLine;
                        }
                        else if (structtype[structlevel] != ActionBase.ActionType.If && structtype[structlevel] != ActionBase.ActionType.ElseIf)
                        {
                            errlist += "Step " + step.ToString(ct) + " Else without IF found" + Environment.NewLine;
                        }
                    }

                    if (act.Type == ActionBase.ActionType.ElseIf || act.Type == ActionBase.ActionType.Else)
                    {
                        structtype[structlevel] = act.Type;

                        if (structlevel == 1)
                        {
                            act.calcAllowLeft = false; // can't move an ELSE back to level 0
                        }
                        if (structlevel > 0)           // display else artifically indented.. display only
                        {
                            act.calcDisplayLevel--;
                        }

                        structcount[structlevel] = 0;                         // restart count so we don't allow a left on next one..
                    }
                    else if (act.Type == ActionBase.ActionType.While && indo) // do..while
                    {
                        if (structlevel > 0)                                  // display else artifically indented.. display only
                        {
                            act.calcDisplayLevel--;
                        }

                        lastwaswhileafterdo = true;     // be careful backing up
                    }
                    else if (act.Type == ActionBase.ActionType.If || (act.Type == ActionBase.ActionType.While && !indo) ||
                             act.Type == ActionBase.ActionType.Do || act.Type == ActionBase.ActionType.Loop || act.Type == ActionBase.ActionType.ForEach)
                    {
                        structlevel++;
                        structcount[structlevel] = 0;
                        structtype[structlevel]  = act.Type;
                    }

                    string vmsg = act.VerifyActionCorrect();
                    if (vmsg != null)
                    {
                        errlist += "Step " + step.ToString(ct) + " " + vmsg + Environment.NewLine;
                    }

                    act.LineNumber = lineno;
                    lineno        += act.Whitespace;
                }
                else
                {
                    errlist += "Step " + step.ToString(ct) + " not defined" + Environment.NewLine;
                }

                step++;
                lineno++;
            }

            if (structlevel > 0 && structcount[structlevel] == 0)
            {
                errlist += "At End of program, no statements present after " + structtype[structlevel].ToString() + " statement" + Environment.NewLine;
            }

            return(errlist);
        }