Inheritance: Microsoft.Cci.MutableCodeModel.EmptyStatement
Ejemplo n.º 1
0
 internal SwitchInstruction(SwitchInstruction switchInstruction)
     : base(switchInstruction)
 {
     Contract.Requires(switchInstruction != null);
     this.switchExpression = switchInstruction.switchExpression;
     Contract.Assume(switchInstruction.switchCases != null);
     this.switchCases = switchInstruction.switchCases;
 }
Ejemplo n.º 2
0
        private void DecompileSwitch(List <IStatement> statements, int i)
        {
            if (i >= statements.Count - 1)
            {
                return;
            }
            SwitchInstruction /*?*/ switchInstruction = statements[i] as SwitchInstruction;

            if (switchInstruction == null)
            {
                return;
            }
            SwitchStatement result = new SwitchStatement();

            result.Expression = switchInstruction.switchExpression;
            statements[i]     = result;
            for (int j = 0, n = switchInstruction.switchCases.Count; j < n; j++)
            {
                CompileTimeConstant caseLabel = new CompileTimeConstant()
                {
                    Value = j, Type = this.platformType.SystemInt32
                };
                var        gotoCaseBody = switchInstruction.switchCases[j];
                SwitchCase currentCase  = new SwitchCase()
                {
                    Expression = caseLabel
                };
                result.Cases.Add(currentCase);
                if (j < n - 1 && gotoCaseBody.TargetStatement == switchInstruction.switchCases[j + 1].TargetStatement)
                {
                    continue;
                }
                currentCase.Body.Add(gotoCaseBody);
            }
            if (i == statements.Count - 1)
            {
                return;
            }
            var gotoStatement = statements[i + 1] as IGotoStatement;

            if (gotoStatement != null)
            {
                SwitchCase defaultCase = new SwitchCase()
                {
                };                                     // Default case is represented by a dummy Expression.
                defaultCase.Body.Add(statements[i + 1]);
                statements.RemoveAt(i + 1);
                result.Cases.Add(defaultCase);
            }
        }
Ejemplo n.º 3
0
 private Statement ParseSwitchInstruction(IOperation operation)
 {
     SwitchInstruction result = new SwitchInstruction();
       result.switchExpression = this.PopOperandStack();
       uint[] branches = (uint[])operation.Value;
       foreach (uint targetAddress in branches) {
     BasicBlock bb = this.GetOrCreateBlock(targetAddress, true);
     var gotoBB = new GotoStatement() { TargetStatement = (LabeledStatement)bb.Statements[0] };
     result.switchCases.Add(gotoBB);
       }
       return result;
 }
Ejemplo n.º 4
0
 private Statement ParseSwitchInstruction(IOperation currentOperation) {
   Contract.Requires(currentOperation != null);
   SwitchInstruction result = new SwitchInstruction();
   result.switchExpression = this.PopOperandStack();
   Contract.Assume(currentOperation.Value is uint[]);
   uint[] branches = (uint[])currentOperation.Value;
   foreach (uint targetAddress in branches) {
     var target = this.GetTargetStatement(targetAddress);
     var gotoBB = new GotoStatement() { TargetStatement = target };
     var key = (uint)gotoBB.TargetStatement.Label.UniqueKey;
     List<IGotoStatement> gotos = this.gotosThatTarget[key];
     if (gotos == null) this.gotosThatTarget[key] = gotos = new List<IGotoStatement>();
     gotos.Add(gotoBB);
     result.SwitchCases.Add(gotoBB);
   }
   return result;
 }
Ejemplo n.º 5
0
 internal SwitchInstruction(SwitchInstruction switchInstruction)
   : base(switchInstruction) {
   Contract.Requires(switchInstruction != null);
   this.switchExpression = switchInstruction.switchExpression;
   Contract.Assume(switchInstruction.switchCases != null);
   this.switchCases = switchInstruction.switchCases;
 }