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(); } }