Esempio n. 1
0
 public virtual void RemoveBlock(BasicBlock block)
 {
     while (block.GetSuccs().Count > 0)
     {
         block.RemoveSuccessor(block.GetSuccs()[0]);
     }
     while (block.GetSuccExceptions().Count > 0)
     {
         block.RemoveSuccessorException(block.GetSuccExceptions()[0]);
     }
     while (block.GetPreds().Count > 0)
     {
         block.GetPreds()[0].RemoveSuccessor(block);
     }
     while (block.GetPredExceptions().Count > 0)
     {
         block.GetPredExceptions()[0].RemoveSuccessorException(block);
     }
     last.RemovePredecessor(block);
     blocks.RemoveWithKey(block.id);
     for (int i = exceptions.Count - 1; i >= 0; i--)
     {
         ExceptionRangeCFG range = exceptions[i];
         if (range.GetHandler() == block)
         {
             exceptions.RemoveAtReturningValue(i);
         }
         else
         {
             List <BasicBlock> lstRange = range.GetProtectedRange();
             lstRange.Remove(block);
             if ((lstRange.Count == 0))
             {
                 exceptions.RemoveAtReturningValue(i);
             }
         }
     }
     subroutines.RemoveIf(ent => ent.Key == block ||
                          ent.Value == block);
 }
Esempio n. 2
0
        public virtual void CollapseNodesToStatement(Statement stat)
        {
            Statement head = stat.GetFirst();
            Statement post = stat.GetPost();
            VBStyleCollection <Statement, int> setNodes = stat.GetStats();

            // post edges
            if (post != null)
            {
                foreach (StatEdge edge in post.GetEdges(Statedge_Direct_All, Direction_Backward))
                {
                    if (stat.ContainsStatementStrict(edge.GetSource()))
                    {
                        edge.GetSource().ChangeEdgeType(Direction_Forward, edge, StatEdge.Type_Break);
                        stat.AddLabeledEdge(edge);
                    }
                }
            }
            // regular head edges
            foreach (StatEdge prededge in head.GetAllPredecessorEdges())
            {
                if (prededge.GetType() != StatEdge.Type_Exception && stat.ContainsStatementStrict
                        (prededge.GetSource()))
                {
                    prededge.GetSource().ChangeEdgeType(Direction_Forward, prededge, StatEdge.Type_Continue
                                                        );
                    stat.AddLabeledEdge(prededge);
                }
                head.RemovePredecessor(prededge);
                prededge.GetSource().ChangeEdgeNode(Direction_Forward, prededge, stat);
                stat.AddPredecessor(prededge);
            }
            if (setNodes.ContainsKey(first.id))
            {
                first = stat;
            }
            // exception edges
            HashSet <Statement> setHandlers = new HashSet <Statement>(head.GetNeighbours(StatEdge
                                                                                         .Type_Exception, Direction_Forward));

            foreach (Statement node in setNodes)
            {
                setHandlers.UnionWith(node.GetNeighbours(StatEdge.Type_Exception, Direction_Forward
                                                         ));
            }
            if (!(setHandlers.Count == 0))
            {
                foreach (StatEdge edge in head.GetEdges(StatEdge.Type_Exception, Direction_Forward
                                                        ))
                {
                    Statement handler = edge.GetDestination();
                    if (setHandlers.Contains(handler))
                    {
                        if (!setNodes.ContainsKey(handler.id))
                        {
                            stat.AddSuccessor(new StatEdge(stat, handler, edge.GetExceptions()));
                        }
                    }
                }
                foreach (Statement node in setNodes)
                {
                    foreach (StatEdge edge in node.GetEdges(StatEdge.Type_Exception, Direction_Forward
                                                            ))
                    {
                        if (setHandlers.Contains(edge.GetDestination()))
                        {
                            node.RemoveSuccessor(edge);
                        }
                    }
                }
            }
            if (post != null && !stat.GetNeighbours(StatEdge.Type_Exception, Direction_Forward
                                                    ).Contains(post))
            {
                // TODO: second condition redundant?
                stat.AddSuccessor(new StatEdge(StatEdge.Type_Regular, stat, post));
            }
            // adjust statement collection
            foreach (Statement st in setNodes)
            {
                stats.RemoveWithKey(st.id);
            }
            stats.AddWithKey(stat, stat.id);
            stat.SetAllParent();
            stat.SetParent(this);
            stat.BuildContinueSet();
            // monitorenter and monitorexit
            stat.BuildMonitorFlags();
            if (stat.type == Type_Switch)
            {
                // special case switch, sorting leaf nodes
                ((SwitchStatement)stat).SortEdgesAndNodes();
            }
        }