Example #1
0
 public override void VisitCycleNode(CycleNode c)
 {
     ++CurNest;
     MaxNest = Math.Max(CurNest, MaxNest);
     c.Stat.Visit(this);
     --CurNest;
 }
Example #2
0
 public override void VisitCycleNode(CycleNode c)
 {
     ++CycleCount;
     ++CycleOpenedBodyCount;
     c.Stat.Visit(this);
     --CycleOpenedBodyCount;
 }
Example #3
0
 public override void VisitCycleNode(CycleNode c)
 {
     CycleCount += 1;
     depth      += 1;
     c.Stat.Visit(this);
     depth -= 1;
 }
Example #4
0
 public override void VisitCycleNode(CycleNode c)
 {
     Text.Append(IndentStr() + "for (var i = 0; i < ");
     c.Expr.Visit(this);
     Text.Append("; i++)\n");
     c.Stat.Visit(this);
 }
Example #5
0
 public override void VisitCycleNode(CycleNode c)
 {
     NestExpr++;
     c.Expr.Visit(this);
     NestExpr--;
     c.Stat.Visit(this);
 }
Example #6
0
 public override void VisitCycleNode(CycleNode c)
 {
     ++CurrNestExprs;
     c.Expr.Visit(this);
     --CurrNestExprs;
     c.Stat.Visit(this);
 }
Example #7
0
        public override void VisitCycleNode(CycleNode c)
        {
            Console.WriteLine(Tag + " VisitCycleNode");

            var startLoopLabel = GenNewLabel();

            c.Expr.Visit(this);

            var whileLine = new ThreeAddrLine();

            whileLine.Label  = GenNewLabel();
            whileLine.LeftOp = GetLastLine().Accum;
            whileLine.OpType = ThreeAddrOpType.IfGoto;
            Data.Add(whileLine);

            var outsideWhileLine = new ThreeAddrLine();

            outsideWhileLine.Label  = GenNewLabel();
            outsideWhileLine.OpType = ThreeAddrOpType.Goto;
            Data.Add(outsideWhileLine);
            whileLine.RightOp = GenNewLabel();
            c.Stat.Visit(this);

            var gotoStartLine = new ThreeAddrLine();

            gotoStartLine.Label   = GenNewLabel();
            gotoStartLine.OpType  = ThreeAddrOpType.Goto;
            gotoStartLine.RightOp = startLoopLabel;
            Data.Add(gotoStartLine);

            InsertNop();
            outsideWhileLine.RightOp = GetLastLine().Label;
        }
 public override void VisitCycleNode(CycleNode c)
 {
     Text += IndentStr() + "cycle ";
     c.Expr.Visit(this);
     Text += Environment.NewLine;
     c.Stat.Visit(this);
 }
Example #9
0
        public override void VisitCycleNode(CycleNode c)
        {
            var i = genc.DeclareLocal(typeof(int)); // переменная цикла cycle

            c.Expr.Visit(this);                     // сгенерировать команды, связанные с вычислением количества итераций цикла
            genc.Emit(OpCodes.Stloc, i);            // i := кво итераций

            Label startLoop = genc.DefineLabel();
            Label endLoop   = genc.DefineLabel();

            genc.MarkLabel(startLoop);

            genc.Emit(OpCodes.Ldloc, i);
            genc.Emit(OpCodes.Ldc_I4_0);
            genc.Emit(OpCodes.Ble, endLoop); // if i<=0 then goto endLoop

            c.Stat.Visit(this);              // выполнить тело цикла

            genc.Emit(OpCodes.Ldloc, i);     // положить i на стек
            genc.Emit(OpCodes.Ldc_I4_1);     // положить 1 на стек
            genc.Emit(OpCodes.Sub);
            genc.Emit(OpCodes.Stloc, i);     // i := i - 1;

            genc.Emit(OpCodes.Br, startLoop);

            genc.MarkLabel(endLoop);
        }
 public override void VisitCycleNode(CycleNode c)
 {
     CurrentComplexity = 0;
     c.Expr.Visit(this);
     Complexities.Add(CurrentComplexity);
     c.Stat.Visit(this);
 }
 public override void VisitCycleNode(CycleNode c)
 {
     ++cycleCnt;
     --depth;
     c.Stat.Visit(this);
     ++depth;
 }
 public override void VisitCycleNode(CycleNode c)
 {
     OpenBody();
     //c.Expr.Visit(this);
     c.Stat.Visit(this);
     CloseBody();
 }
Example #13
0
 public override void VisitCycleNode(CycleNode c)
 {
     if (WithinIf)
     {
         HasCycleNestedToIf = true;
     }
     base.VisitCycleNode(c);
 }
Example #14
0
 public override void VisitCycleNode(CycleNode c)
 {
     ++CycleOpenedBodyCount;
     if (CycleOpenedBodyCount > MaxNest) MaxNest = CycleOpenedBodyCount;
     c.Expr.Visit(this);
     c.Stat.Visit(this);
     --CycleOpenedBodyCount;
 }
 public override void VisitCycleNode(CycleNode c)
 {
     CycleCount++;
     CycleDepth++;
     c.Expr.Visit(this);
     c.Stat.Visit(this);
     CycleDepth--;
 }
Example #16
0
 public override void VisitCycleNode(CycleNode c)
 {
     if (c == null)
     {
         return;
     }
     c.Expr.Visit(this);
     c.Stat.Visit(this);
 }
Example #17
0
 public override void VisitCycleNode(CycleNode c)
 {
     levelVisted += 1;
     if (levelVisted > MaxNest)
     {
         MaxNest = levelVisted;
     }
     base.VisitCycleNode(c);
     levelVisted -= 1;
 }
Example #18
0
 public override void VisitCycleNode(CycleNode c)
 {
     curDepth++;
     base.VisitCycleNode(c);
     if (curDepth > MaxNest)
     {
         MaxNest = curDepth;
     }
     curDepth--;
 }
Example #19
0
 public override void VisitCycleNode(CycleNode c)
 {
     CurrentNest += 1;
     if (CurrentNest > MaxNest)
     {
         MaxNest = CurrentNest;
     }
     c.Stat.Visit(this);
     CurrentNest -= 1;
 }
Example #20
0
        /// <summary>
        /// Determine the shortest cycle which contains the vertex
        /// If the cycle does not exist returns int.MaxValue
        /// </summary>
        /// <param name="root">vertex</param>
        /// <returns>the shortest cycle which contains the vertex</returns>
        private int CycleGirthBFS(IVertexInterface root)
        {
            // Variable
            int bestGirth = int.MaxValue;
            Queue <CycleNode> nodeBFSQueue = new Queue <CycleNode>();
            Dictionary <IVertexInterface, int> nodeDictionary       = new Dictionary <IVertexInterface, int>();
            List <IVertexInterface>            vertexNeighboursList = new List <IVertexInterface>();

            CycleNode rootNode = new CycleNode(root, 0);

            nodeBFSQueue.Enqueue(rootNode);
            nodeDictionary.Add(rootNode.GetVertex(), rootNode.GetDepth());

            while (nodeBFSQueue.Count != 0)
            {
                CycleNode node  = nodeBFSQueue.Dequeue();
                int       depth = node.GetDepth() + 1;

                vertexNeighboursList = graph.Neighbours(node.GetVertex());

                foreach (IVertexInterface vertexNeighbour in vertexNeighboursList)
                {
                    // We have not seen this vertex yet
                    if (!nodeDictionary.ContainsKey(vertexNeighbour))
                    {
                        nodeBFSQueue.Enqueue(new CycleNode(vertexNeighbour, depth));
                        nodeDictionary.Add(vertexNeighbour, depth);
                    }
                    else
                    {
                        // Odd cycle
                        if (nodeDictionary[vertexNeighbour] == depth - 1)
                        {
                            if (depth * 2 - 1 < bestGirth)
                            {
                                bestGirth = depth * 2 - 1;
                            }
                        }
                        else
                        {
                            // Even cycle
                            if (nodeDictionary[vertexNeighbour] == depth)
                            {
                                if (depth * 2 < bestGirth)
                                {
                                    bestGirth = depth * 2;
                                }
                            }
                        }
                    }
                }
            }

            return(bestGirth);
        }
Example #21
0
        public override void VisitCycleNode(CycleNode c)
        {
            CycleDepth += 1;
            base.VisitCycleNode(c);

            if (CycleDepth > 1)
            {
                HasNestedCycles = true;
            }
            CycleDepth = 0;
        }
        public override void VisitCycleNode(CycleNode c)
        {
            ++Current;
            base.VisitCycleNode(c);

            if (Current > Max)
            {
                Max = Current;
            }
            --Current;
        }
Example #23
0
 public override void VisitCycleNode(CycleNode c)
 {
     if (currCyc > 0)
     {
         opCnt++;
     }
     cycCnt++;
     currCyc++;
     base.VisitCycleNode(c);
     currCyc--;
 }
 public override void VisitCycleNode(CycleNode c)
 {
     CurrentDepth++;
     c.Expr.Visit(this);
     c.Stat.Visit(this);
     if (CurrentDepth > MaxNest)
     {
         MaxNest = CurrentDepth;
     }
     CurrentDepth--;
 }
Example #25
0
        public void VisitCycleNode(CycleNode a)
        {
            string label = Mark(a);

            _nodes.AppendLine($"{label}  [label = \"Cycle\"]");

            a.Condition.Visit(this);
            a.Body.Visit(this);

            _edges.AppendLine($"{label} -> {Mark(a.Condition)}");
            _edges.AppendLine($"{label} -> {Mark(a.Body)}");
        }
Example #26
0
 public override void VisitCycleNode(CycleNode c)
 {
     if (NowCycle > 0)
     {
         CountOp += 1;
     }
     CountCycle += 1;
     NowCycle   += 1;
     c.Expr.Visit(this);
     c.Stat.Visit(this);
     NowCycle -= 1;
 }
Example #27
0
        public override void VisitCycleNode(CycleNode c)
        {
            CurNest++;
            c.Expr.Visit(this);
            c.Stat.Visit(this);

            if (CurNest > MaxNest)
            {
                MaxNest = CurNest;
            }
            CurNest--;
        }
        public override void VisitCycleNode(CycleNode c)
        {
            NowCycle += 1;

            if (NowCycle > MaxNest)
            {
                MaxNest = NowCycle;
            }

            c.Expr.Visit(this);
            c.Stat.Visit(this);
            NowCycle -= 1;
        }
        public override void VisitCycleNode(CycleNode c)
        {
            Text += IndentStr() + "cycle ";
            c.Expr.Visit(this);
            Text += Environment.NewLine;

            if (!(c.Stat is BlockNode))
            {
                IndentPlus();
            }
            c.Stat.Visit(this);
            if (!(c.Stat is BlockNode))
            {
                IndentMinus();
            }
        }
 /// <summary>
 /// Посещение узла с циклом while
 /// </summary>
 /// <param name="c">Узел CycleNode</param>
 public virtual void VisitCycleNode(CycleNode c)
 {
     Text += IndentStr() + "while(";
     c.Condition.Visit(this);
     Text += ")";
     Text += Environment.NewLine;
     if (!(c.Body is BlockNode))
     {
         IndentPlus();
         c.Body.Visit(this);
         Text += ";" + Environment.NewLine;
         IndentMinus();
     }
     else
     {
         c.Body.Visit(this);
     }
 }