PERWAPI.CILInstructions.TraverseMaxDepth C# (CSharp) Method

TraverseMaxDepth() private method

private TraverseMaxDepth ( CodeBlock entryBlock ) : int
entryBlock CodeBlock
return int
        int TraverseMaxDepth(CodeBlock entryBlock)
        {
            int max = 0;
            SCG.Queue<CodeBlock> worklist = new SCG.Queue<CodeBlock>();
            entryBlock.Visited = true;
            entryBlock.LastVisitEntryDepth = 0;
            worklist.Enqueue(entryBlock);
            while (worklist.Count > 0)
            {
                int count = worklist.Count;
                CodeBlock unit = worklist.Dequeue();

                int maxDepth = unit.LastVisitEntryDepth + unit.MaxDepth;
                int exitDepth = unit.LastVisitEntryDepth + unit.DeltaDistance;

                if (maxDepth > max) max = maxDepth;

                foreach (CodeBlock succ in unit.NextBlocks)
                {
                    if (succ.Visited)
                    {
                        if (succ.LastVisitEntryDepth != exitDepth)
                            throw new InvalidStackDepth("inconsistent stack depth at offset " + succ.StartIndex.ToString());
                    }
                    else
                    {
                        succ.Visited = true;
                        succ.LastVisitEntryDepth = exitDepth;
                        worklist.Enqueue(succ);
                    }
                }
            }
            return max;
        }