public virtual void ReplaceStatement(Statement oldstat, Statement newstat) { foreach (StatEdge edge in oldstat.GetAllPredecessorEdges()) { oldstat.RemovePredecessor(edge); edge.GetSource().ChangeEdgeNode(Direction_Forward, edge, newstat); newstat.AddPredecessor(edge); } foreach (StatEdge edge in oldstat.GetAllSuccessorEdges()) { oldstat.RemoveSuccessor(edge); edge.SetSource(newstat); newstat.AddSuccessor(edge); } int statindex = stats.GetIndexByKey(oldstat.id); stats.RemoveWithKey(oldstat.id); stats.AddWithKeyAndIndex(statindex, newstat, newstat.id); newstat.SetParent(this); newstat.post = oldstat.post; if (first == oldstat) { first = newstat; } List <StatEdge> lst = new List <StatEdge>(oldstat.GetLabelEdges()); for (int i = lst.Count - 1; i >= 0; i--) { StatEdge edge = lst[i]; if (edge.GetSource() != newstat) { newstat.AddLabeledEdge(edge); } else if (this == edge.GetDestination() || this.ContainsStatementStrict(edge.GetDestination ())) { edge.closure = null; } else { this.AddLabeledEdge(edge); } } oldstat.GetLabelEdges().Clear(); }
private IfStatement(Statement head, int regedges, Statement postst) : this() { first = head; stats.AddWithKey(head, head.id); List <StatEdge> lstHeadSuccs = head.GetSuccessorEdges(Statedge_Direct_All); switch (regedges) { case 0: { ifstat = null; elsestat = null; break; } case 1: { ifstat = null; elsestat = null; StatEdge edgeif = lstHeadSuccs[1]; if (edgeif.GetType() != StatEdge.Type_Regular) { post = lstHeadSuccs[0].GetDestination(); } else { post = edgeif.GetDestination(); negated = true; } break; } case 2: { elsestat = lstHeadSuccs[0].GetDestination(); ifstat = lstHeadSuccs[1].GetDestination(); List <StatEdge> lstSucc = ifstat.GetSuccessorEdges(StatEdge.Type_Regular); List <StatEdge> lstSucc1 = elsestat.GetSuccessorEdges(StatEdge.Type_Regular); if (ifstat.GetPredecessorEdges(StatEdge.Type_Regular).Count > 1 || lstSucc.Count > 1) { post = ifstat; } else if (elsestat.GetPredecessorEdges(StatEdge.Type_Regular).Count > 1 || lstSucc1 .Count > 1) { post = elsestat; } else if (lstSucc.Count == 0) { post = elsestat; } else if (lstSucc1.Count == 0) { post = ifstat; } if (ifstat == post) { if (elsestat != post) { ifstat = elsestat; negated = true; } else { ifstat = null; } elsestat = null; } else if (elsestat == post) { elsestat = null; } else { post = postst; } if (elsestat == null) { regedges = 1; } break; } } // if without else ifedge = lstHeadSuccs[negated ? 0 : 1]; elseedge = (regedges == 2) ? lstHeadSuccs[negated ? 1 : 0] : null; iftype = (regedges == 2) ? Iftype_Ifelse : Iftype_If; if (iftype == Iftype_If) { if (regedges == 0) { StatEdge edge = lstHeadSuccs[0]; head.RemoveSuccessor(edge); edge.SetSource(this); this.AddSuccessor(edge); } else if (regedges == 1) { StatEdge edge = lstHeadSuccs[negated ? 1 : 0]; head.RemoveSuccessor(edge); } } if (ifstat != null) { stats.AddWithKey(ifstat, ifstat.id); } if (elsestat != null) { stats.AddWithKey(elsestat, elsestat.id); } if (post == head) { post = this; } }