Exemple #1
0
        private static bool ExtractLastIf(DoStatement stat)
        {
            // search for an if condition at the end of the loop
            Statement last = stat.GetFirst();

            while (last.type == Statement.Type_Sequence)
            {
                last = last.GetStats().GetLast();
            }
            if (last.type == Statement.Type_If)
            {
                IfStatement lastif = (IfStatement)last;
                if (lastif.iftype == IfStatement.Iftype_If && lastif.GetIfstat() != null)
                {
                    Statement ifstat   = lastif.GetIfstat();
                    StatEdge  elseedge = lastif.GetAllSuccessorEdges()[0];
                    if (elseedge.GetType() == StatEdge.Type_Continue && elseedge.closure == stat)
                    {
                        HashSet <Statement> set = stat.GetNeighboursSet(StatEdge.Type_Continue, Statement.
                                                                        Direction_Backward);
                        set.Remove(last);
                        if ((set.Count == 0))
                        {
                            // no direct continues in a do{}while loop
                            if (IsExternStatement(stat, ifstat, ifstat))
                            {
                                ExtractIfBlock(stat, lastif);
                                return(true);
                            }
                        }
                    }
                }
            }
            return(false);
        }
Exemple #2
0
        private static Statement IsExitEdge(StatEdge edge)
        {
            Statement dest = edge.GetDestination();

            if (edge.GetType() == StatEdge.Type_Break && dest.type == Statement.Type_Basicblock &&
                edge.@explicit && (edge.labeled || IsOnlyEdge(edge)))
            {
                List <Exprent> data = dest.GetExprents();
                if (data != null && data.Count == 1)
                {
                    if (data[0].type == Exprent.Exprent_Exit)
                    {
                        return(dest);
                    }
                }
            }
            return(null);
        }
Exemple #3
0
        private static bool BuildIff(Statement stat, SSAConstructorSparseEx ssa)
        {
            if (stat.type == Statement.Type_If && stat.GetExprents() == null)
            {
                IfStatement   statement          = (IfStatement)stat;
                Exprent       ifHeadExpr         = statement.GetHeadexprent();
                HashSet <int> ifHeadExprBytecode = (ifHeadExpr == null ? null : ifHeadExpr.bytecode
                                                    );
                if (statement.iftype == IfStatement.Iftype_Ifelse)
                {
                    Statement ifStatement   = statement.GetIfstat();
                    Statement elseStatement = statement.GetElsestat();
                    if (ifStatement.GetExprents() != null && ifStatement.GetExprents().Count == 1 &&
                        elseStatement.GetExprents() != null && elseStatement.GetExprents().Count == 1 &&
                        ifStatement.GetAllSuccessorEdges().Count == 1 && elseStatement.GetAllSuccessorEdges
                            ().Count == 1 && ifStatement.GetAllSuccessorEdges()[0].GetDestination() == elseStatement
                        .GetAllSuccessorEdges()[0].GetDestination())
                    {
                        Exprent ifExpr   = ifStatement.GetExprents()[0];
                        Exprent elseExpr = elseStatement.GetExprents()[0];
                        if (ifExpr.type == Exprent.Exprent_Assignment && elseExpr.type == Exprent.Exprent_Assignment)
                        {
                            AssignmentExprent ifAssign   = (AssignmentExprent)ifExpr;
                            AssignmentExprent elseAssign = (AssignmentExprent)elseExpr;
                            if (ifAssign.GetLeft().type == Exprent.Exprent_Var && elseAssign.GetLeft().type ==
                                Exprent.Exprent_Var)
                            {
                                VarExprent ifVar   = (VarExprent)ifAssign.GetLeft();
                                VarExprent elseVar = (VarExprent)elseAssign.GetLeft();
                                if (ifVar.GetIndex() == elseVar.GetIndex() && ifVar.IsStack())
                                {
                                    // ifVar.getIndex() >= VarExprent.STACK_BASE) {
                                    bool found = false;
                                    foreach (KeyValuePair <VarVersionPair, FastSparseSetFactory <int> .FastSparseSet <int> > ent
                                             in ssa.GetPhi())
                                    {
                                        if (ent.Key.var == ifVar.GetIndex())
                                        {
                                            if (ent.Value.Contains(ifVar.GetVersion()) && ent.Value.Contains(elseVar.GetVersion
                                                                                                                 ()))
                                            {
                                                found = true;
                                                break;
                                            }
                                        }
                                    }
                                    if (found)
                                    {
                                        List <Exprent> data     = new List <Exprent>(statement.GetFirst().GetExprents());
                                        List <Exprent> operands = Sharpen.Arrays.AsList(statement.GetHeadexprent().GetCondition
                                                                                            (), ifAssign.GetRight(), elseAssign.GetRight());
                                        data.Add(new AssignmentExprent(ifVar, new FunctionExprent(FunctionExprent.Function_Iif
                                                                                                  , operands, ifHeadExprBytecode), ifHeadExprBytecode));
                                        statement.SetExprents(data);
                                        if ((statement.GetAllSuccessorEdges().Count == 0))
                                        {
                                            StatEdge ifEdge = ifStatement.GetAllSuccessorEdges()[0];
                                            StatEdge edge   = new StatEdge(ifEdge.GetType(), statement, ifEdge.GetDestination()
                                                                           );
                                            statement.AddSuccessor(edge);
                                            if (ifEdge.closure != null)
                                            {
                                                ifEdge.closure.AddLabeledEdge(edge);
                                            }
                                        }
                                        SequenceHelper.DestroyAndFlattenStatement(statement);
                                        return(true);
                                    }
                                }
                            }
                        }
                        else if (ifExpr.type == Exprent.Exprent_Exit && elseExpr.type == Exprent.Exprent_Exit)
                        {
                            ExitExprent ifExit   = (ExitExprent)ifExpr;
                            ExitExprent elseExit = (ExitExprent)elseExpr;
                            if (ifExit.GetExitType() == elseExit.GetExitType() && ifExit.GetValue() != null &&
                                elseExit.GetValue() != null && ifExit.GetExitType() == ExitExprent.Exit_Return)
                            {
                                // throw is dangerous, because of implicit casting to a common superclass
                                // e.g. throws IOException and throw true?new RuntimeException():new IOException(); won't work
                                if (ifExit.GetExitType() == ExitExprent.Exit_Throw && !ifExit.GetValue().GetExprType
                                        ().Equals(elseExit.GetValue().GetExprType()))
                                {
                                    // note: getExprType unreliable at this point!
                                    return(false);
                                }
                                // avoid flattening to 'iff' if any of the branches is an 'iff' already
                                if (IsIff(ifExit.GetValue()) || IsIff(elseExit.GetValue()))
                                {
                                    return(false);
                                }
                                List <Exprent> data = new List <Exprent>(statement.GetFirst().GetExprents());
                                data.Add(new ExitExprent(ifExit.GetExitType(), new FunctionExprent(FunctionExprent
                                                                                                   .Function_Iif, Sharpen.Arrays.AsList(statement.GetHeadexprent().GetCondition(),
                                                                                                                                        ifExit.GetValue(), elseExit.GetValue()), ifHeadExprBytecode), ifExit.GetRetType(
                                                             ), ifHeadExprBytecode));
                                statement.SetExprents(data);
                                StatEdge  retEdge = ifStatement.GetAllSuccessorEdges()[0];
                                Statement closure = retEdge.closure == statement?statement.GetParent() : retEdge
                                                        .closure;

                                statement.AddSuccessor(new StatEdge(StatEdge.Type_Break, statement, retEdge.GetDestination
                                                                        (), closure));
                                SequenceHelper.DestroyAndFlattenStatement(statement);
                                return(true);
                            }
                        }
                    }
                }
            }
            return(false);
        }
Exemple #4
0
        private static void ProcessEdgesWithNext(Statement stat, Dictionary <Statement, List <StatEdge> > mapEdges, Statement next)
        {
            StatEdge        statedge = null;
            List <StatEdge> lstSuccs = stat.GetAllSuccessorEdges();

            if (!(lstSuccs.Count == 0))
            {
                statedge = lstSuccs[0];
                if (statedge.GetDestination() == next)
                {
                    statedge.@explicit = false;
                    statedge           = null;
                }
                else
                {
                    next = statedge.GetDestination();
                }
            }
            // no next for a do statement
            if (stat.type == Statement.Type_Do && ((DoStatement)stat).GetLooptype() == DoStatement
                .Loop_Do)
            {
                next = null;
            }
            if (next == null)
            {
                if (mapEdges.Count == 1)
                {
                    List <StatEdge> lstEdges = new Sharpen.EnumeratorAdapter <List <StatEdge> >(mapEdges.Values.GetEnumerator()).Next();
                    if (lstEdges.Count > 1 && new Sharpen.EnumeratorAdapter <Statement>(mapEdges.Keys.GetEnumerator()).Next().type != Statement
                        .Type_Dummyexit)
                    {
                        StatEdge  edge_example = lstEdges[0];
                        Statement closure      = stat.GetParent();
                        if (!closure.ContainsStatementStrict(edge_example.closure))
                        {
                            closure = edge_example.closure;
                        }
                        StatEdge newedge = new StatEdge(edge_example.GetType(), stat, edge_example.GetDestination
                                                            (), closure);
                        stat.AddSuccessor(newedge);
                        foreach (StatEdge edge in lstEdges)
                        {
                            edge.@explicit = false;
                        }
                        Sharpen.Collections.Put(mapEdges, newedge.GetDestination(), new List <StatEdge>(System.Linq.Enumerable.ToList(new [] {
                            newedge
                        })));
                    }
                }
            }
            else
            {
                bool implfound = false;
                foreach (KeyValuePair <Statement, List <StatEdge> > entr in mapEdges)
                {
                    if (entr.Key == next)
                    {
                        foreach (StatEdge edge in entr.Value)
                        {
                            edge.@explicit = false;
                        }
                        implfound = true;
                        break;
                    }
                }
                if ((stat.GetAllSuccessorEdges().Count == 0) && !implfound)
                {
                    List <StatEdge> lstEdges = null;
                    foreach (KeyValuePair <Statement, List <StatEdge> > entr in mapEdges)
                    {
                        if (entr.Key.type != Statement.Type_Dummyexit && (lstEdges == null || entr.Value.
                                                                          Count > lstEdges.Count))
                        {
                            lstEdges = entr.Value;
                        }
                    }
                    if (lstEdges != null && lstEdges.Count > 1)
                    {
                        StatEdge  edge_example = lstEdges[0];
                        Statement closure      = stat.GetParent();
                        if (!closure.ContainsStatementStrict(edge_example.closure))
                        {
                            closure = edge_example.closure;
                        }
                        StatEdge newedge = new StatEdge(edge_example.GetType(), stat, edge_example.GetDestination
                                                            (), closure);
                        stat.AddSuccessor(newedge);
                        foreach (StatEdge edge in lstEdges)
                        {
                            edge.@explicit = false;
                        }
                    }
                }
                mapEdges.Clear();
            }
            if (statedge != null)
            {
                Sharpen.Collections.Put(mapEdges, statedge.GetDestination(), new List <StatEdge>(System.Linq.Enumerable.ToList(new [] {
                    statedge
                })));
            }
        }
Exemple #5
0
 private static void RemoveEmptyStatements(SequenceStatement sequence)
 {
     if (sequence.GetStats().Count <= 1)
     {
         return;
     }
     MergeFlatStatements(sequence);
     while (true)
     {
         bool found = false;
         foreach (Statement st in sequence.GetStats())
         {
             if (st.GetExprents() != null && (st.GetExprents().Count == 0))
             {
                 if ((st.GetAllSuccessorEdges().Count == 0))
                 {
                     List <StatEdge> lstBreaks = st.GetPredecessorEdges(StatEdge.Type_Break);
                     if ((lstBreaks.Count == 0))
                     {
                         foreach (StatEdge edge in st.GetAllPredecessorEdges())
                         {
                             edge.GetSource().RemoveSuccessor(edge);
                         }
                         found = true;
                     }
                 }
                 else
                 {
                     StatEdge sucedge = st.GetAllSuccessorEdges()[0];
                     if (sucedge.GetType() != StatEdge.Type_Finallyexit)
                     {
                         st.RemoveSuccessor(sucedge);
                         foreach (StatEdge edge in st.GetAllPredecessorEdges())
                         {
                             if (sucedge.GetType() != StatEdge.Type_Regular)
                             {
                                 edge.GetSource().ChangeEdgeType(Statement.Direction_Forward, edge, sucedge.GetType
                                                                     ());
                             }
                             st.RemovePredecessor(edge);
                             edge.GetSource().ChangeEdgeNode(Statement.Direction_Forward, edge, sucedge.GetDestination
                                                                 ());
                             sucedge.GetDestination().AddPredecessor(edge);
                             if (sucedge.closure != null)
                             {
                                 sucedge.closure.AddLabeledEdge(edge);
                             }
                         }
                         found = true;
                     }
                 }
                 if (found)
                 {
                     sequence.GetStats().RemoveWithKey(st.id);
                     break;
                 }
             }
         }
         if (!found)
         {
             break;
         }
     }
     sequence.SetFirst(sequence.GetStats()[0]);
 }
Exemple #6
0
        private static void MatchDoWhile(DoStatement stat)
        {
            // search for an if condition at the end of the loop
            Statement last = stat.GetFirst();

            while (last.type == Statement.Type_Sequence)
            {
                last = last.GetStats().GetLast();
            }
            if (last.type == Statement.Type_If)
            {
                IfStatement lastif = (IfStatement)last;
                if (lastif.iftype == IfStatement.Iftype_If && lastif.GetIfstat() == null)
                {
                    StatEdge ifedge   = lastif.GetIfEdge();
                    StatEdge elseedge = lastif.GetAllSuccessorEdges()[0];
                    if ((ifedge.GetType() == StatEdge.Type_Break && elseedge.GetType() == StatEdge.Type_Continue &&
                         elseedge.closure == stat && IsDirectPath(stat, ifedge.GetDestination())) ||
                        (ifedge.GetType() == StatEdge.Type_Continue && elseedge.GetType() == StatEdge.Type_Break &&
                         ifedge.closure == stat && IsDirectPath(stat, elseedge.GetDestination())))
                    {
                        HashSet <Statement> set = stat.GetNeighboursSet(StatEdge.Type_Continue, Statement.
                                                                        Direction_Backward);
                        set.Remove(last);
                        if (!(set.Count == 0))
                        {
                            return;
                        }
                        stat.SetLooptype(DoStatement.Loop_Dowhile);
                        IfExprent ifexpr = (IfExprent)lastif.GetHeadexprent().Copy();
                        if (ifedge.GetType() == StatEdge.Type_Break)
                        {
                            ifexpr.NegateIf();
                        }
                        stat.SetConditionExprent(ifexpr.GetCondition());
                        lastif.GetFirst().RemoveSuccessor(ifedge);
                        lastif.RemoveSuccessor(elseedge);
                        // remove empty if
                        if ((lastif.GetFirst().GetExprents().Count == 0))
                        {
                            RemoveLastEmptyStatement(stat, lastif);
                        }
                        else
                        {
                            lastif.SetExprents(lastif.GetFirst().GetExprents());
                            StatEdge newedge = new StatEdge(StatEdge.Type_Continue, lastif, stat);
                            lastif.AddSuccessor(newedge);
                            stat.AddLabeledEdge(newedge);
                        }
                        if ((stat.GetAllSuccessorEdges().Count == 0))
                        {
                            StatEdge edge = elseedge.GetType() == StatEdge.Type_Continue ? ifedge : elseedge;
                            edge.SetSource(stat);
                            if (edge.closure == stat)
                            {
                                edge.closure = stat.GetParent();
                            }
                            stat.AddSuccessor(edge);
                        }
                    }
                }
            }
        }
Exemple #7
0
        public static bool IsChoiceStatement(Statement head, List <Statement> lst)
        {
            Statement           post    = null;
            HashSet <Statement> setDest = head.GetNeighboursSet(StatEdge.Type_Regular, Statement
                                                                .Direction_Forward);

            if (setDest.Contains(head))
            {
                return(false);
            }
            while (true)
            {
                lst.Clear();
                bool repeat = false;
                setDest.Remove(post);
                foreach (Statement stat in setDest)
                {
                    if (stat.GetLastBasicType() != Statement.Lastbasictype_General)
                    {
                        if (post == null)
                        {
                            post   = stat;
                            repeat = true;
                            break;
                        }
                        else
                        {
                            return(false);
                        }
                    }
                    // preds
                    HashSet <Statement> setPred = stat.GetNeighboursSet(StatEdge.Type_Regular, Statement
                                                                        .Direction_Backward);
                    setPred.Remove(head);
                    if (setPred.Contains(stat))
                    {
                        return(false);
                    }
                    if (!setPred.All(setDest.Contains) || setPred.Count > 1)
                    {
                        if (post == null)
                        {
                            post   = stat;
                            repeat = true;
                            break;
                        }
                        else
                        {
                            return(false);
                        }
                    }
                    else if (setPred.Count == 1)
                    {
                        Statement pred = new Sharpen.EnumeratorAdapter <Statement>(setPred.GetEnumerator()).Next();
                        while (lst.Contains(pred))
                        {
                            HashSet <Statement> setPredTemp = pred.GetNeighboursSet(StatEdge.Type_Regular, Statement
                                                                                    .Direction_Backward);
                            setPredTemp.Remove(head);
                            if (!(setPredTemp.Count == 0))
                            {
                                // at most 1 predecessor
                                pred = new Sharpen.EnumeratorAdapter <Statement>(setPredTemp.GetEnumerator()).Next();
                                if (pred == stat)
                                {
                                    return(false);
                                }
                            }
                            else
                            {
                                // loop found
                                break;
                            }
                        }
                    }
                    // succs
                    List <StatEdge> lstEdges = stat.GetSuccessorEdges(Statement.Statedge_Direct_All);
                    if (lstEdges.Count > 1)
                    {
                        HashSet <Statement> setSucc = stat.GetNeighboursSet(Statement.Statedge_Direct_All,
                                                                            Statement.Direction_Forward);
                        setSucc.RetainAll(setDest);
                        if (setSucc.Count > 0)
                        {
                            return(false);
                        }
                        else if (post == null)
                        {
                            post   = stat;
                            repeat = true;
                            break;
                        }
                        else
                        {
                            return(false);
                        }
                    }
                    else if (lstEdges.Count == 1)
                    {
                        StatEdge edge = lstEdges[0];
                        if (edge.GetType() == StatEdge.Type_Regular)
                        {
                            Statement statd = edge.GetDestination();
                            if (head == statd)
                            {
                                return(false);
                            }
                            if (post != statd && !setDest.Contains(statd))
                            {
                                if (post != null)
                                {
                                    return(false);
                                }
                                else
                                {
                                    HashSet <Statement> set = statd.GetNeighboursSet(StatEdge.Type_Regular, Statement.
                                                                                     Direction_Backward);
                                    if (set.Count > 1)
                                    {
                                        post   = statd;
                                        repeat = true;
                                        break;
                                    }
                                    else
                                    {
                                        return(false);
                                    }
                                }
                            }
                        }
                    }
                    lst.Add(stat);
                }
                if (!repeat)
                {
                    break;
                }
            }
            lst.Add(head);
            lst.Remove(post);
            lst.Add(0, post);
            return(true);
        }
Exemple #8
0
        private static IfHelper.IfNode BuildGraph(IfStatement stat, bool stsingle)
        {
            if (stat.iftype == IfStatement.Iftype_Ifelse)
            {
                return(null);
            }
            IfHelper.IfNode res = new IfHelper.IfNode(stat);
            // if branch
            Statement ifchild = stat.GetIfstat();

            if (ifchild == null)
            {
                StatEdge edge = stat.GetIfEdge();
                res.AddChild(new IfHelper.IfNode(edge.GetDestination()), 1);
            }
            else
            {
                IfHelper.IfNode ifnode = new IfHelper.IfNode(ifchild);
                res.AddChild(ifnode, 0);
                if (ifchild.type == Statement.Type_If && ((IfStatement)ifchild).iftype == IfStatement
                    .Iftype_If)
                {
                    IfStatement stat2    = (IfStatement)ifchild;
                    Statement   ifchild2 = stat2.GetIfstat();
                    if (ifchild2 == null)
                    {
                        StatEdge edge = stat2.GetIfEdge();
                        ifnode.AddChild(new IfHelper.IfNode(edge.GetDestination()), 1);
                    }
                    else
                    {
                        ifnode.AddChild(new IfHelper.IfNode(ifchild2), 0);
                    }
                }
                if (!(ifchild.GetAllSuccessorEdges().Count == 0))
                {
                    ifnode.AddChild(new IfHelper.IfNode(ifchild.GetAllSuccessorEdges()[0].GetDestination
                                                            ()), 1);
                }
            }
            // else branch
            StatEdge  edge_1    = stat.GetAllSuccessorEdges()[0];
            Statement elsechild = edge_1.GetDestination();

            IfHelper.IfNode elsenode = new IfHelper.IfNode(elsechild);
            if (stsingle || edge_1.GetType() != StatEdge.Type_Regular)
            {
                res.AddChild(elsenode, 1);
            }
            else
            {
                res.AddChild(elsenode, 0);
                if (elsechild.type == Statement.Type_If && ((IfStatement)elsechild).iftype == IfStatement
                    .Iftype_If)
                {
                    IfStatement stat2    = (IfStatement)elsechild;
                    Statement   ifchild2 = stat2.GetIfstat();
                    if (ifchild2 == null)
                    {
                        elsenode.AddChild(new IfHelper.IfNode(stat2.GetIfEdge().GetDestination()), 1);
                    }
                    else
                    {
                        elsenode.AddChild(new IfHelper.IfNode(ifchild2), 0);
                    }
                }
                if (!(elsechild.GetAllSuccessorEdges().Count == 0))
                {
                    elsenode.AddChild(new IfHelper.IfNode(elsechild.GetAllSuccessorEdges()[0].GetDestination
                                                              ()), 1);
                }
            }
            return(res);
        }
Exemple #9
0
 private static bool CollapseElse(IfHelper.IfNode rtnode)
 {
     if (rtnode.edgetypes[1] == 0)
     {
         IfHelper.IfNode elsebranch = rtnode.succs[1];
         if (elsebranch.succs.Count == 2)
         {
             // else-if or else-else branch
             int path = elsebranch.succs[1].value == rtnode.succs[0].value ? 2 : (elsebranch.succs
                                                                                  [0].value == rtnode.succs[0].value ? 1 : 0);
             if (path > 0)
             {
                 IfStatement firstif  = (IfStatement)rtnode.value;
                 IfStatement secondif = (IfStatement)elsebranch.value;
                 Statement   parent   = firstif.GetParent();
                 if ((secondif.GetFirst().GetExprents().Count == 0))
                 {
                     firstif.GetFirst().RemoveSuccessor(firstif.GetIfEdge());
                     // remove first if
                     firstif.RemoveAllSuccessors(secondif);
                     foreach (StatEdge edge in firstif.GetAllPredecessorEdges())
                     {
                         if (!firstif.ContainsStatementStrict(edge.GetSource()))
                         {
                             firstif.RemovePredecessor(edge);
                             edge.GetSource().ChangeEdgeNode(Statement.Direction_Forward, edge, secondif);
                             secondif.AddPredecessor(edge);
                         }
                     }
                     parent.GetStats().RemoveWithKey(firstif.id);
                     if (parent.GetFirst() == firstif)
                     {
                         parent.SetFirst(secondif);
                     }
                     // merge if conditions
                     IfExprent      statexpr    = secondif.GetHeadexprent();
                     List <Exprent> lstOperands = new List <Exprent>();
                     lstOperands.Add(firstif.GetHeadexprent().GetCondition());
                     if (path == 2)
                     {
                         lstOperands[0] = new FunctionExprent(FunctionExprent.Function_Bool_Not, lstOperands
                                                              [0], null);
                     }
                     lstOperands.Add(statexpr.GetCondition());
                     statexpr.SetCondition(new FunctionExprent(path == 1 ? FunctionExprent.Function_Cor
                                                          : FunctionExprent.Function_Cadd, lstOperands, null));
                     if ((secondif.GetFirst().GetExprents().Count == 0) && !(firstif.GetFirst().GetExprents
                                                                                 ().Count == 0))
                     {
                         secondif.ReplaceStatement(secondif.GetFirst(), firstif.GetFirst());
                     }
                     return(true);
                 }
             }
         }
         else if (elsebranch.succs.Count == 1)
         {
             if (elsebranch.succs[0].value == rtnode.succs[0].value)
             {
                 IfStatement firstif = (IfStatement)rtnode.value;
                 Statement   second  = elsebranch.value;
                 firstif.RemoveAllSuccessors(second);
                 foreach (StatEdge edge in second.GetAllSuccessorEdges())
                 {
                     second.RemoveSuccessor(edge);
                     edge.SetSource(firstif);
                     firstif.AddSuccessor(edge);
                 }
                 StatEdge ifedge = firstif.GetIfEdge();
                 firstif.GetFirst().RemoveSuccessor(ifedge);
                 second.AddSuccessor(new StatEdge(ifedge.GetType(), second, ifedge.GetDestination(
                                                      ), ifedge.closure));
                 StatEdge newifedge = new StatEdge(StatEdge.Type_Regular, firstif.GetFirst(), second
                                                   );
                 firstif.GetFirst().AddSuccessor(newifedge);
                 firstif.SetIfstat(second);
                 firstif.GetStats().AddWithKey(second, second.id);
                 second.SetParent(firstif);
                 firstif.GetParent().GetStats().RemoveWithKey(second.id);
                 // negate the if condition
                 IfExprent statexpr = firstif.GetHeadexprent();
                 statexpr.SetCondition(new FunctionExprent(FunctionExprent.Function_Bool_Not, statexpr
                                                           .GetCondition(), null));
                 return(true);
             }
         }
     }
     return(false);
 }