예제 #1
0
        private static void ExtractIfBlock(DoStatement loop, IfStatement ifstat)
        {
            Statement target = ifstat.GetIfstat();
            StatEdge  ifedge = ifstat.GetIfEdge();

            ifstat.SetIfstat(null);
            ifedge.GetSource().ChangeEdgeType(Statement.Direction_Forward, ifedge, StatEdge.Type_Break
                                              );
            ifedge.closure = loop;
            ifstat.GetStats().RemoveWithKey(target.id);
            loop.AddLabeledEdge(ifedge);
            SequenceStatement block = new SequenceStatement(Sharpen.Arrays.AsList(loop, target
                                                                                  ));

            loop.GetParent().ReplaceStatement(loop, block);
            block.SetAllParent();
            loop.AddSuccessor(new StatEdge(StatEdge.Type_Regular, loop, target));
            foreach (StatEdge edge in new List <StatEdge>(block.GetLabelEdges()))
            {
                if (edge.GetType() == StatEdge.Type_Continue || edge == ifedge)
                {
                    loop.AddLabeledEdge(edge);
                }
            }
            foreach (StatEdge edge in block.GetPredecessorEdges(StatEdge.Type_Continue))
            {
                if (loop.ContainsStatementStrict(edge.GetSource()))
                {
                    block.RemovePredecessor(edge);
                    edge.GetSource().ChangeEdgeNode(Statement.Direction_Forward, edge, loop);
                    loop.AddPredecessor(edge);
                }
            }
        }
예제 #2
0
 private static void RemoveLastEmptyStatement(DoStatement dostat, Statement stat)
 {
     if (stat == dostat.GetFirst())
     {
         BasicBlockStatement bstat = new BasicBlockStatement(new BasicBlock(DecompilerContext
                                                                            .GetCounterContainer().GetCounterAndIncrement(CounterContainer.Statement_Counter
                                                                                                                          )));
         bstat.SetExprents(new List <Exprent>());
         dostat.ReplaceStatement(stat, bstat);
     }
     else
     {
         foreach (StatEdge edge in stat.GetAllPredecessorEdges())
         {
             edge.GetSource().ChangeEdgeType(Statement.Direction_Forward, edge, StatEdge.Type_Continue
                                             );
             stat.RemovePredecessor(edge);
             edge.GetSource().ChangeEdgeNode(Statement.Direction_Forward, edge, dostat);
             dostat.AddPredecessor(edge);
             dostat.AddLabeledEdge(edge);
         }
         // parent is a sequence statement
         stat.GetParent().GetStats().RemoveWithKey(stat.id);
     }
 }