コード例 #1
0
        private void BuildDominatorTree()
        {
            VBStyleCollection <int?, int> orderedIDoms = domEngine.GetOrderedIDoms();
            List <int> lstKeys = orderedIDoms.GetLstKeys();

            for (int index = lstKeys.Count - 1; index >= 0; index--)
            {
                int key  = lstKeys[index];
                int?idom = orderedIDoms[index];
                mapTreeBranches.ComputeIfAbsent(idom, (k) => new HashSet <int>()).Add(key);
            }
            int firstid = statement.GetFirst().id;

            mapTreeBranches.GetOrNull(firstid).Remove(firstid);
        }
コード例 #2
0
        private void CalcIDoms()
        {
            OrderNodes();
            List <IGraphNode> lstNodes = colOrderedIDoms.GetLstKeys();

            while (true)
            {
                bool changed = false;
                foreach (IGraphNode node in lstNodes)
                {
                    IGraphNode idom = null;
                    if (!setRoots.Contains(node))
                    {
                        foreach (var pred in node.GetPredecessors())
                        {
                            if (colOrderedIDoms.GetWithKey(pred) != null)
                            {
                                idom = GetCommonIDom(idom, pred, colOrderedIDoms);
                                if (idom == null)
                                {
                                    break;
                                }
                            }
                        }
                    }
                    // no idom found: merging point of two trees
                    if (idom == null)
                    {
                        idom = node;
                    }
                    IGraphNode oldidom = colOrderedIDoms.PutWithKey(idom, node);
                    if (!idom.Equals(oldidom))
                    {
                        // oldidom is null iff the node is touched for the first time
                        changed = true;
                    }
                }
                if (!changed)
                {
                    break;
                }
            }
        }