예제 #1
0
 public Zelse AddElseIf(Zelse _if)
 {
     _if.Parent  = this.Parent;
     _if.CurLine = this.CurLine;
     elseIf.Add(_if);
     return(_if);
 }
예제 #2
0
        static void AddChildChunk(Zchunk zfun, int chindMaxNum, int childCurCount = 0)
        {
            Type   randomType = randomTypeList[Tools.RandomNum(0, randomTypeList.Count)];  //随机类型
            Zchunk newChunk   = Activator.CreateInstance(randomType) as Zchunk;

            zfun.AddChunk(newChunk);
            int randomIdx = 0;

            if (randomType.Name == "Zif")
            {
                Zif newIf = newChunk as Zif;
                randomIdx = Tools.RandomNum(0, 100);
                while (randomIdx > 70)
                {
                    randomIdx = Tools.RandomNum(0, 100);
                    if (randomIdx > 50)
                    {
                        ZelseIf newElseIf = newIf.AddElseIf(new ZelseIf());
                        randomIdx = Tools.RandomNum(0, 3);  //嵌套的elseif有多少个代码行
                        for (int ii = 0; ii < randomIdx; ii++)
                        {
                            newElseIf.AddChunk(Zchunk.New <Zcode>());
                        }
                    }
                    else
                    {
                        Zelse newElse = newIf.AddElseIf(new Zelse());
                        randomIdx = Tools.RandomNum(0, 3);  //嵌套的else有多少个代码行
                        for (int ii = 0; ii < randomIdx; ii++)
                        {
                            newElse.AddChunk(Zchunk.New <Zcode>());
                        }
                        break;   //if的嵌套到else结束
                    }
                    randomIdx = Tools.RandomNum(0, 100);
                }
            }
            if (randomType.Name != "Zcode")
            {
                randomIdx = Tools.RandomNum(0, 3);  //语句块里嵌套的有多少个代码行
                for (int ii = 0; ii < randomIdx; ii++)
                {
                    newChunk.AddChunk(Zchunk.New <Zcode>());
                }
                randomIdx = Tools.RandomNum(0, 100);    // 有多少的几率会继续嵌套
                if (childCurCount < chindMaxNum && randomIdx > 40)
                {
                    AddChildChunk(newChunk, chindMaxNum, childCurCount + 1);
                }
            }
        }