private static void MatchFor(DoStatement stat) { Exprent lastDoExprent; Exprent initDoExprent; Statement lastData; Statement preData = null; // get last exprent lastData = GetLastDirectData(stat.GetFirst()); if (lastData == null || (lastData.GetExprents().Count == 0)) { return; } List <Exprent> lstExpr = lastData.GetExprents(); lastDoExprent = lstExpr[lstExpr.Count - 1]; bool issingle = false; if (lstExpr.Count == 1) { // single exprent if (lastData.GetAllPredecessorEdges().Count > 1) { // break edges issingle = true; } } bool haslast = issingle || lastDoExprent.type == Exprent.Exprent_Assignment || lastDoExprent .type == Exprent.Exprent_Function; if (!haslast) { return; } bool hasinit = false; // search for an initializing exprent Statement current = stat; while (true) { Statement parent = current.GetParent(); if (parent == null) { break; } if (parent.type == Statement.Type_Sequence) { if (current == parent.GetFirst()) { current = parent; } else { preData = current.GetNeighbours(StatEdge.Type_Regular, Statement.Direction_Backward )[0]; preData = GetLastDirectData(preData); if (preData != null && !(preData.GetExprents().Count == 0)) { initDoExprent = preData.GetExprents()[preData.GetExprents().Count - 1]; if (initDoExprent.type == Exprent.Exprent_Assignment) { hasinit = true; } } break; } } else { break; } } if (hasinit || issingle) { // FIXME: issingle sufficient? HashSet <Statement> set = stat.GetNeighboursSet(StatEdge.Type_Continue, Statement. Direction_Backward); set.Remove(lastData); if (!(set.Count == 0)) { return; } stat.SetLooptype(DoStatement.Loop_For); if (hasinit) { stat.SetInitExprent(preData.GetExprents().RemoveAtReturningValue(preData.GetExprents ().Count - 1)); } stat.SetIncExprent(lastData.GetExprents().RemoveAtReturningValue(lastData.GetExprents ().Count - 1)); } if ((lastData.GetExprents().Count == 0)) { List <StatEdge> lst = lastData.GetAllSuccessorEdges(); if (!(lst.Count == 0)) { lastData.RemoveSuccessor(lst[0]); } RemoveLastEmptyStatement(stat, lastData); } }