Inheritance: Statement, IGotoStatement
Example #1
0
 private GotoStatement MakeGoto(IOperation currentOperation)
 {
     GotoStatement gotoStatement = new GotoStatement();
       gotoStatement.TargetStatement = this.GetTargetStatement(currentOperation.Value);
       List<IGotoStatement> values;
       var found = this.predecessors.TryGetValue(gotoStatement.TargetStatement, out values);
       if (!found) {
     var l = new List<IGotoStatement>();
     l.Add(gotoStatement);
     this.predecessors.Add(gotoStatement.TargetStatement, l);
       } else {
     values.Add(gotoStatement);
       }
       return gotoStatement;
 }
 private GotoStatement MakeGoto(IOperation currentOperation) {
   Contract.Requires(currentOperation != null);
   GotoStatement gotoStatement = new GotoStatement();
   Contract.Assume(currentOperation.Value is uint);
   gotoStatement.TargetStatement = this.GetTargetStatement((uint)currentOperation.Value);
   var key = (uint)gotoStatement.TargetStatement.Label.UniqueKey;
   List<IGotoStatement> gotos = this.gotosThatTarget[key];
   if (gotos == null) this.gotosThatTarget[key] = gotos = new List<IGotoStatement>();
   gotos.Add(gotoStatement);
   return gotoStatement;
 }
Example #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;
 }
Example #4
0
 /// <summary>
 /// Visits the specified goto statement.
 /// </summary>
 /// <param name="gotoStatement">The goto statement.</param>
 /// <returns></returns>
 protected virtual IStatement DeepCopy(GotoStatement gotoStatement)
 {
     return gotoStatement;
 }
 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;
 }
Example #6
0
 /// <summary>
 /// Visits the specified goto statement.
 /// </summary>
 /// <param name="gotoStatement">The goto statement.</param>
 public override void Visit(IGotoStatement gotoStatement)
 {
     GotoStatement mutableGotoStatement = new GotoStatement(gotoStatement);
     this.resultStatement = this.myCodeCopier.DeepCopy(mutableGotoStatement);
 }
    private bool RemoveEndFinallyFrom(DecompiledBlock block, LabeledStatement labelToGoto) {
      Contract.Requires(block != null);
      Contract.Requires(labelToGoto != null);

      for (int i = 0; i < block.Statements.Count; i++) {
        if (block.Statements[i] is EndFinally) {
          var gotoFinally = new GotoStatement() { TargetStatement = labelToGoto };
          block.Statements[i] = gotoFinally;
          var gotos = new List<IGotoStatement>(1);
          gotos.Add(gotoFinally);
          this.gotosThatTarget[(uint)labelToGoto.Label.UniqueKey] = gotos;
          return true;
        }
        var nestedBlock = block.Statements[i] as DecompiledBlock;
        if (nestedBlock != null && this.RemoveEndFinallyFrom(nestedBlock, labelToGoto)) return true;
      }
      return false;
    }
Example #8
0
 /// <summary>
 /// Rewrites the children of the given goto statement.
 /// </summary>
 public virtual void RewriteChildren(GotoStatement gotoStatement)
 {
     this.RewriteChildren((Statement)gotoStatement);
 }
Example #9
0
 /// <summary>
 /// Visits the specified goto statement.
 /// </summary>
 /// <param name="gotoStatement">The goto statement.</param>
 /// <returns></returns>
 public virtual IStatement Visit(GotoStatement gotoStatement)
 {
     return gotoStatement;
 }
Example #10
0
 /// <summary>
 /// Visits the specified goto statement.
 /// </summary>
 /// <param name="gotoStatement">The goto statement.</param>
 public override void Visit(IGotoStatement gotoStatement)
 {
     GotoStatement mutableGotoStatement = gotoStatement as GotoStatement;
     if (alwaysMakeACopy || mutableGotoStatement == null) mutableGotoStatement = new GotoStatement(gotoStatement);
     this.resultStatement = this.myCodeMutator.Visit(mutableGotoStatement);
 }