示例#1
0
            public override void CaseAIfThenElseStm(AIfThenElseStm node)
            {
                //Create graph node
                Node graphNode = GetNode(node);

                //Process inner if
                node.GetThenBody().Apply(this);
                node.GetElseBody().Apply(this);
                //Add successor and predessors
                PStm stm = GetFirst(node.GetThenBody());

                if (stm != null)
                {
                    graphNode.AddSucc(GetNode(stm));
                }
                stm = GetFirst(node.GetElseBody());
                if (stm != null)
                {
                    graphNode.AddSucc(GetNode(stm));
                }

                stm = GetNext(node);
                if (stm != null)
                {
                    Node nextGraphNode = GetNode(stm);

                    List <PStm> stms = GetLast(node.GetThenBody());
                    if (stms.Count > 0)
                    {
                        foreach (PStm pStm in stms)
                        {
                            nextGraphNode.AddPred(GetNode(pStm));
                        }
                    }
                    else
                    {
                        graphNode.AddSucc(nextGraphNode);
                    }

                    stms = GetLast(node.GetElseBody());
                    if (stms.Count > 0)
                    {
                        foreach (PStm pStm in stms)
                        {
                            nextGraphNode.AddPred(GetNode(pStm));
                        }
                    }
                    else
                    {
                        graphNode.AddSucc(nextGraphNode);
                    }
                }
            }
示例#2
0
 public override void CaseAIfThenElseStm(AIfThenElseStm node)
 {
     Write("if(");
     node.GetCondition().Apply(this);
     Write(")\n");
     node.GetThenBody().Apply(this);
     Write("else\n");
     node.GetElseBody().Apply(this);
 }
        public override void OutAIfThenElseStm(AIfThenElseStm node)
        {
            bool value;

            if (IsConst(node.GetCondition(), out value))
            {
                if (value)
                {
                    node.ReplaceBy(node.GetThenBody());
                }
                else
                {
                    node.ReplaceBy(node.GetElseBody());
                }
                changedSomething = true;
            }
        }
示例#4
0
 //Returns true if execution cannot continue after the stm
 private bool removeDeadCode(PStm stm)
 {
     if (stm is ABreakStm || stm is AContinueStm || stm is AVoidReturnStm || stm is AValueReturnStm)
     {
         return(true);
     }
     if (stm is AIfThenStm)
     {
         AIfThenStm aStm    = (AIfThenStm)stm;
         bool       stopped = removeDeadCode(aStm.GetBody());
         if (IsBoolConst(aStm.GetCondition(), true))
         {
             return(stopped);
         }
         return(false);
     }
     if (stm is AIfThenElseStm)
     {
         AIfThenElseStm aStm     = (AIfThenElseStm)stm;
         bool           stopped1 = removeDeadCode(aStm.GetThenBody());
         if (IsBoolConst(aStm.GetCondition(), true))
         {
             return(stopped1);
         }
         bool stopped2 = removeDeadCode(aStm.GetElseBody());
         if (IsBoolConst(aStm.GetCondition(), false))
         {
             return(stopped2);
         }
         return(stopped1 && stopped2);
     }
     if (stm is AWhileStm)
     {
         AWhileStm aStm = (AWhileStm)stm;
         removeDeadCode(aStm.GetBody());
         return(false);
     }
     if (stm is ABlockStm)
     {
         ABlockStm aStm = (ABlockStm)stm;
         return(removeDeadCode((AABlock)aStm.GetBlock()));
     }
     return(false);
 }
示例#5
0
 public override void CaseAIfThenElseStm(AIfThenElseStm node)
 {
     node.GetThenBody().Apply(this);
     node.GetElseBody().Apply(this);
 }