private Statement FixSwitchingStatement(Statement statement)
 {
     if (statement is SwitchStatement)
     {
         SwitchStatement theSwitch = statement as SwitchStatement;
         if (theSwitch.Condition.Equals(theIntVariable))
         {
             theSwitch.Condition = theStringVariable.CloneExpressionOnly();
         }
         foreach (SwitchCase @case in theSwitch.Cases)
         {
             if (@case is ConditionCase)
             {
                 ConditionCase condCase  = @case as ConditionCase;
                 int           caseValue = (int)(condCase.Condition as LiteralExpression).Value;
                 condCase.Condition = new LiteralExpression(valueDictionary[caseValue], theTypeSystem, null);
             }
         }
     }
     else if (statement is IfElseIfStatement)
     {
         IfElseIfStatement irregularSwitch = statement as IfElseIfStatement;
         foreach (KeyValuePair <Expression, BlockStatement> condPair in irregularSwitch.ConditionBlocks)
         {
             FixConditionExpression(condPair.Key as BinaryExpression);
         }
     }
     return(statement);
 }
Exemple #2
0
 private void MoveInCase(IfStatement gotoStatement, SwitchCase switchCase, string label)
 {
     V_0             = new VariableReferenceExpression(this.GetLabelVariable(label), null);
     V_1             = this.GetOuterBlock(gotoStatement);
     V_2             = switchCase.get_Parent() as SwitchStatement;
     V_3             = V_1.get_Statements().IndexOf(gotoStatement);
     V_4             = V_1.get_Statements().IndexOf(V_2);
     V_12            = V_2.get_ConditionBlock().get_First().get_Offset();
     stackVariable26 = String.Concat("switch", V_12.ToString());
     V_5             = this.GetSwitchType(V_2);
     V_6             = new VariableDefinition(stackVariable26, V_5, this.methodContext.get_Method());
     this.switchVariables.Add(V_6);
     V_7 = new VariableReferenceExpression(V_6, null);
     this.ExtractConditionIntoVariable(V_7, V_2, V_1);
     V_8  = this.CollectStatements(V_3 + 1, V_4 + 1, V_1);
     V_9  = new BlockStatement();
     V_10 = new BinaryExpression(26, V_7.CloneExpressionOnly(), this.GetCaseConditionExpression(switchCase), this.typeSystem, null, false);
     V_9.AddStatement(new ExpressionStatement(V_10));
     V_11 = new IfStatement(new UnaryExpression(1, V_0, null), V_8, V_9);
     if (V_11.get_Then().get_Statements().get_Count() != 0)
     {
         V_1.AddStatementAt(V_3, V_11);
     }
     dummyVar0 = V_1.get_Statements().Remove(gotoStatement);
     switchCase.get_Body().AddStatementAt(0, gotoStatement);
     return;
 }
Exemple #3
0
 private void ExtractConditionIntoVariable(VariableReferenceExpression conditionVar, ConditionStatement statement, BlockStatement containingBlock)
 {
     V_0 = new ExpressionStatement(new BinaryExpression(26, conditionVar, statement.get_Condition(), this.typeSystem, null, false));
     containingBlock.AddStatementAt(containingBlock.get_Statements().IndexOf(statement), V_0);
     statement.set_Condition(conditionVar.CloneExpressionOnly());
     return;
 }
Exemple #4
0
 private void MoveOut(IfStatement gotoStatement, string label)
 {
     V_0 = gotoStatement.get_Parent() as BlockStatement;
     V_1 = this.GetOuterBlock(V_0);
     V_2 = new VariableReferenceExpression(this.GetLabelVariable(label), null);
     this.ExtractConditionIntoVariable(V_2.CloneExpressionOnly() as VariableReferenceExpression, gotoStatement, V_0);
     V_3 = V_0.get_Parent();
     if (V_3 as SwitchCase != null)
     {
         V_3 = V_3.get_Parent();
     }
     if (V_0.get_Parent() as SwitchCase != null || V_0.get_Parent() as WhileStatement != null || V_0.get_Parent() as DoWhileStatement != null || V_0.get_Parent() as ForStatement != null || V_0.get_Parent() as ForEachStatement != null)
     {
         V_4 = new BlockStatement();
         V_4.AddStatement(new BreakStatement(null));
         V_5       = new IfStatement(V_2.CloneExpressionOnly(), V_4, null);
         V_6       = V_0.get_Statements().IndexOf(gotoStatement);
         dummyVar0 = V_0.get_Statements().Remove(gotoStatement);
         V_0.AddStatementAt(V_6, V_5);
     }
     else
     {
         if (V_0.get_Parent() as IfStatement == null && V_0.get_Parent() as TryStatement == null && V_0.get_Parent() as IfElseIfStatement == null)
         {
             throw new ArgumentOutOfRangeException("Goto statement can not leave this parent construct.");
         }
         V_7 = V_0.get_Statements().IndexOf(gotoStatement) + 1;
         V_8 = new BlockStatement();
         while (V_7 < V_0.get_Statements().get_Count())
         {
             V_8.AddStatement(V_0.get_Statements().get_Item(V_7));
             V_0.get_Statements().RemoveAt(V_7);
         }
         V_9       = new IfStatement(new UnaryExpression(1, V_2.CloneExpressionOnly(), null), V_8, null);
         dummyVar1 = V_0.get_Statements().Remove(gotoStatement);
         if (V_9.get_Then().get_Statements().get_Count() != 0)
         {
             V_0.AddStatement(V_9);
         }
     }
     V_1.AddStatementAt(V_1.get_Statements().IndexOf(V_3) + 1, gotoStatement);
     return;
 }
Exemple #5
0
 private void MoveIn(IfStatement gotoStatement, Statement targetStatement, string label)
 {
     V_0 = gotoStatement.get_Parent() as BlockStatement;
     V_1 = new VariableReferenceExpression(this.GetLabelVariable(label), null);
     this.ExtractConditionIntoVariable(V_1.CloneExpressionOnly() as VariableReferenceExpression, gotoStatement, V_0);
     V_2 = V_0.get_Statements().IndexOf(gotoStatement);
     V_3 = V_0.get_Statements().IndexOf(targetStatement);
     V_4 = this.CollectStatements(V_2 + 1, V_3, V_0);
     V_5 = new IfStatement(new UnaryExpression(1, V_1.CloneExpressionOnly(), null), V_4, null);
     if (V_5.get_Then().get_Statements().get_Count() > 0)
     {
         V_0.AddStatementAt(V_2, V_5);
     }
     dummyVar0 = V_0.get_Statements().Remove(gotoStatement);
     if (targetStatement as DoWhileStatement != null)
     {
         (targetStatement as DoWhileStatement).get_Body().AddStatementAt(0, gotoStatement);
         return;
     }
     if (targetStatement as IfStatement != null)
     {
         V_6 = targetStatement as IfStatement;
         V_6.set_Condition(this.UpdateCondition(V_6.get_Condition(), V_1.CloneExpressionOnly() as VariableReferenceExpression));
         V_6.get_Then().AddStatementAt(0, gotoStatement);
         return;
     }
     if (targetStatement as SwitchCase != null)
     {
         this.MoveInCase(gotoStatement, targetStatement as SwitchCase, label);
         return;
     }
     if (targetStatement as WhileStatement == null)
     {
         throw new NotSupportedException("Unsupported target statement for goto jump.");
     }
     V_7 = targetStatement as WhileStatement;
     V_7.get_Body().AddStatementAt(0, gotoStatement);
     V_7.set_Condition(this.UpdateCondition(V_7.get_Condition(), V_1.CloneExpressionOnly() as VariableReferenceExpression));
     return;
 }