// ***************************************************************************** // getter and setter methods // ***************************************************************************** public virtual void ChangeEdgeNode(int direction, StatEdge edge, Statement value) { Dictionary <int, List <StatEdge> > mapEdges = direction == Direction_Backward ? mapPredEdges : mapSuccEdges; Dictionary <int, List <Statement> > mapStates = direction == Direction_Backward ? mapPredStates : mapSuccStates; int type = edge.GetType(); int[] arrtypes; if (type == StatEdge.Type_Exception) { arrtypes = new int[] { Statedge_All, StatEdge.Type_Exception }; } else { arrtypes = new int[] { Statedge_All, Statedge_Direct_All, type }; } foreach (int edgetype in arrtypes) { List <StatEdge> lst = mapEdges.GetOrNull(edgetype); if (lst != null) { int index = lst.IndexOf(edge); if (index >= 0) { mapStates.GetOrNull(edgetype)[index] = value; } } } if (direction == Direction_Backward) { edge.SetSource(value); } else { edge.SetDestination(value); } }
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; } }