Ejemplo n.º 1
0
        // *****************************************************************************
        // public methods
        // *****************************************************************************
        public static Statement IsHead2Block(Statement head)
        {
            if (head.GetLastBasicType() != Statement.Lastbasictype_General)
            {
                return(null);
            }
            // at most one outgoing edge
            StatEdge        edge     = null;
            List <StatEdge> lstSuccs = head.GetSuccessorEdges(Statedge_Direct_All);

            if (!(lstSuccs.Count == 0))
            {
                edge = lstSuccs[0];
            }
            if (edge != null && edge.GetType() == StatEdge.Type_Regular)
            {
                Statement stat = edge.GetDestination();
                if (stat != head && stat.GetPredecessorEdges(StatEdge.Type_Regular).Count == 1 &&
                    !stat.IsMonitorEnter())
                {
                    if (stat.GetLastBasicType() == Statement.Lastbasictype_General)
                    {
                        if (DecHelper.CheckStatementExceptions(Sharpen.Arrays.AsList(head, stat)))
                        {
                            return(new SequenceStatement(head, stat));
                        }
                    }
                }
            }
            return(null);
        }
Ejemplo n.º 2
0
        // *****************************************************************************
        // public methods
        // *****************************************************************************
        public static Statement IsHead(Statement head)
        {
            if (head.GetLastBasicType() != Statement.Lastbasictype_General)
            {
                return(null);
            }
            HashSet <Statement> setHandlers = DecHelper.GetUniquePredExceptions(head);

            if (setHandlers.Count != 1)
            {
                return(null);
            }
            foreach (StatEdge edge in head.GetSuccessorEdges(StatEdge.Type_Exception))
            {
                Statement exc = edge.GetDestination();
                if (edge.GetExceptions() == null && exc.GetLastBasicType() == Lastbasictype_General &&
                    setHandlers.Contains(exc))
                {
                    List <StatEdge> lstSuccs = exc.GetSuccessorEdges(Statedge_Direct_All);
                    if ((lstSuccs.Count == 0) || lstSuccs[0].GetType() != StatEdge.Type_Regular)
                    {
                        if (head.IsMonitorEnter() || exc.IsMonitorEnter())
                        {
                            return(null);
                        }
                        if (DecHelper.CheckStatementExceptions(Sharpen.Arrays.AsList(head, exc)))
                        {
                            return(new CatchAllStatement(head, exc));
                        }
                    }
                }
            }
            return(null);
        }
Ejemplo n.º 3
0
 // *****************************************************************************
 // public methods
 // *****************************************************************************
 public static Statement IsHead(Statement head)
 {
     if (head.type == Type_Basicblock && head.GetLastBasicType() == Lastbasictype_If)
     {
         int       regsize = head.GetSuccessorEdges(StatEdge.Type_Regular).Count;
         Statement p       = null;
         bool      ok      = (regsize < 2);
         if (!ok)
         {
             List <Statement> lst = new List <Statement>();
             if (DecHelper.IsChoiceStatement(head, lst))
             {
                 p = lst.RemoveAtReturningValue(0);
                 foreach (Statement st in lst)
                 {
                     if (st.IsMonitorEnter())
                     {
                         return(null);
                     }
                 }
                 ok = DecHelper.CheckStatementExceptions(lst);
             }
         }
         if (ok)
         {
             return(new IfStatement(head, regsize, p));
         }
     }
     return(null);
 }
Ejemplo n.º 4
0
 // *****************************************************************************
 // public methods
 // *****************************************************************************
 public static Statement IsHead(Statement head)
 {
     if (head.type == Statement.Type_Basicblock && head.GetLastBasicType() == Statement
         .Lastbasictype_Switch)
     {
         List <Statement> lst = new List <Statement>();
         if (DecHelper.IsChoiceStatement(head, lst))
         {
             Statement post = lst.RemoveAtReturningValue(0);
             foreach (Statement st in lst)
             {
                 if (st.IsMonitorEnter())
                 {
                     return(null);
                 }
             }
             if (DecHelper.CheckStatementExceptions(lst))
             {
                 return(new SwitchStatement(head, post));
             }
         }
     }
     return(null);
 }
Ejemplo n.º 5
0
        // *****************************************************************************
        // public methods
        // *****************************************************************************
        public static Statement IsHead(Statement head)
        {
            if (head.GetLastBasicType() != Lastbasictype_General)
            {
                return(null);
            }
            HashSet <Statement> setHandlers = DecHelper.GetUniquePredExceptions(head);

            if (!(setHandlers.Count == 0))
            {
                int hnextcount = 0;
                // either no statements with connection to next, or more than 1
                Statement       next         = null;
                List <StatEdge> lstHeadSuccs = head.GetSuccessorEdges(Statedge_Direct_All);
                if (!(lstHeadSuccs.Count == 0) && lstHeadSuccs[0].GetType() == StatEdge.Type_Regular)
                {
                    next       = lstHeadSuccs[0].GetDestination();
                    hnextcount = 2;
                }
                foreach (StatEdge edge in head.GetSuccessorEdges(StatEdge.Type_Exception))
                {
                    Statement stat      = edge.GetDestination();
                    bool      handlerok = true;
                    if (edge.GetExceptions() != null && setHandlers.Contains(stat))
                    {
                        if (stat.GetLastBasicType() != Lastbasictype_General)
                        {
                            handlerok = false;
                        }
                        else
                        {
                            List <StatEdge> lstStatSuccs = stat.GetSuccessorEdges(Statedge_Direct_All);
                            if (!(lstStatSuccs.Count == 0) && lstStatSuccs[0].GetType() == StatEdge.Type_Regular)
                            {
                                Statement statn = lstStatSuccs[0].GetDestination();
                                if (next == null)
                                {
                                    next = statn;
                                }
                                else if (next != statn)
                                {
                                    handlerok = false;
                                }
                                if (handlerok)
                                {
                                    hnextcount++;
                                }
                            }
                        }
                    }
                    else
                    {
                        handlerok = false;
                    }
                    if (!handlerok)
                    {
                        setHandlers.Remove(stat);
                    }
                }
                if (hnextcount != 1 && !(setHandlers.Count == 0))
                {
                    List <Statement> lst = new List <Statement>();
                    lst.Add(head);
                    Sharpen.Collections.AddAll(lst, setHandlers);
                    foreach (Statement st in lst)
                    {
                        if (st.IsMonitorEnter())
                        {
                            return(null);
                        }
                    }
                    if (DecHelper.CheckStatementExceptions(lst))
                    {
                        return(new CatchStatement(head, next, setHandlers));
                    }
                }
            }
            return(null);
        }