예제 #1
0
 private void EliminateViaIf(IfStatement gotoStatement, Statement labeledStatement)
 {
     V_0 = labeledStatement.get_Parent() as BlockStatement;
     V_1 = V_0.get_Statements().IndexOf(gotoStatement);
     V_2 = V_0.get_Statements().IndexOf(labeledStatement);
     if (V_1 == V_2 - 1)
     {
         V_0.get_Statements().RemoveAt(V_1);
         return;
     }
     V_3 = this.CollectStatements(V_1 + 1, V_2, V_0);
     V_4 = Negator.Negate(gotoStatement.get_Condition(), this.typeSystem);
     while (V_3.get_Statements().get_Item(0) as IfStatement != null)
     {
         V_5 = V_3.get_Statements().get_Item(0) as IfStatement;
         if (!this.AreEqual(V_5.get_Condition(), V_4) || V_5.get_Else() != null)
         {
             break;
         }
         V_3.get_Statements().RemoveAt(0);
         V_6 = 0;
         while (V_6 < V_5.get_Then().get_Statements().get_Count())
         {
             V_3.AddStatement(V_5.get_Then().get_Statements().get_Item(V_6));
             V_6 = V_6 + 1;
         }
     }
     gotoStatement.set_Then(V_3);
     gotoStatement.set_Condition(V_4);
     return;
 }
예제 #2
0
 private void CleanupEmptyIfs(BlockStatement body)
 {
     do
     {
         V_0 = this.emptyThenIfs.GetEnumerator();
         try
         {
             while (V_0.MoveNext())
             {
                 V_1 = V_0.get_Current();
                 if (V_1.get_Else() == null || V_1.get_Else().get_Statements().get_Count() == 0)
                 {
                     dummyVar0 = (V_1.get_Parent() as BlockStatement).get_Statements().Remove(V_1);
                 }
                 else
                 {
                     V_1.set_Then(V_1.get_Else());
                     V_1.set_Else(null);
                     dummyVar1 = Negator.Negate(V_1.get_Condition(), this.typeSystem);
                 }
             }
         }
         finally
         {
             ((IDisposable)V_0).Dispose();
         }
         this.emptyThenIfs = new List <IfStatement>();
         this.Visit(body);
     }while (this.emptyThenIfs.get_Count() != 0);
     return;
 }
예제 #3
0
 public void Negate(TypeSystem typeSystem)
 {
     V_0 = this.get_TrueCFGSuccessor();
     this.set_TrueCFGSuccessor(this.get_FalseCFGSuccessor());
     this.set_FalseCFGSuccessor(V_0);
     this.set_ConditionExpression(Negator.Negate(this.get_ConditionExpression(), typeSystem));
     return;
 }
        /// <summary>
        /// Negates the expression of the construct and switches the true and false successors.
        /// </summary>
        public void Negate(TypeSystem typeSystem)
        {
            CFGBlockLogicalConstruct successorHolder = TrueCFGSuccessor;

            TrueCFGSuccessor  = FalseCFGSuccessor;
            FalseCFGSuccessor = successorHolder;

            ConditionExpression = Negator.Negate(ConditionExpression, typeSystem);
        }
 public override ICodeNode VisitUnaryExpression(UnaryExpression node)
 {
     if (this.status == 2)
     {
         throw new Exception("Invalid state");
     }
     V_0 = node.get_Operand();
     node.set_Operand((Expression)this.Visit(node.get_Operand()));
     if (node.get_Operator() != 1 || V_0 == node.get_Operand())
     {
         return(node);
     }
     return(Negator.Negate(node.get_Operand(), this.typeSystem));
 }
예제 #6
0
        public override ICodeNode VisitUnaryExpression(UnaryExpression node)
        {
            if (status == InliningResult.Abort)
            {
                //sanity check
                throw new Exception("Invalid state");
            }

            Expression originalOperand = node.Operand;

            node.Operand = (Expression)Visit(node.Operand);
            if (node.Operator == UnaryOperator.LogicalNot && originalOperand != node.Operand)
            {
                return(Negator.Negate(node.Operand, typeSystem));
            }
            return(node);
        }
        private void CleanupEmptyIfs(BlockStatement body)
        {
            do
            {
                foreach (IfStatement @if in emptyThenIfs)
                {
                    if (@if.Else == null || @if.Else.Statements.Count == 0)
                    {
                        (@if.Parent as BlockStatement).Statements.Remove(@if);
                    }
                    else
                    {
                        @if.Then = @if.Else;
                        @if.Else = null;
                        Negator.Negate(@if.Condition, typeSystem);
                    }
                }

                emptyThenIfs = new List <IfStatement>();
                Visit(body);
            } while (emptyThenIfs.Count != 0);
        }