Пример #1
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);
 }
Пример #2
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);
 }
Пример #3
0
        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;
            }
        }