Browse Source

Fix missing cast in C# ExpressionBuilder, and add nop removal.

pull/728/head
Daniel Grunwald 11 years ago
parent
commit
7a47f118e7
  1. 2
      ICSharpCode.Decompiler/CSharp/ExpressionBuilder.cs
  2. 3
      ICSharpCode.Decompiler/IL/Instructions/Branch.cs
  3. 4
      ICSharpCode.Decompiler/IL/TransformingVisitor.cs

2
ICSharpCode.Decompiler/CSharp/ExpressionBuilder.cs

@ -391,7 +391,7 @@ namespace ICSharpCode.Decompiler.CSharp
.WithILInstruction(argInstruction) .WithILInstruction(argInstruction)
.WithRR(new ThisResolveResult(inst.Method.DeclaringType, causesNonVirtualInvocation: true)); .WithRR(new ThisResolveResult(inst.Method.DeclaringType, causesNonVirtualInvocation: true));
} else { } else {
target = Translate(argInstruction); target = Translate(argInstruction).ConvertTo(inst.Method.DeclaringType, this);
} }
} else { } else {
target = new TypeReferenceExpression(ConvertType(inst.Method.DeclaringType)) target = new TypeReferenceExpression(ConvertType(inst.Method.DeclaringType))

3
ICSharpCode.Decompiler/IL/Instructions/Branch.cs

@ -123,6 +123,9 @@ namespace ICSharpCode.Decompiler.IL
} else { } else {
state.MergeVariables(state.Variables, initialVariables.ToStack()); state.MergeVariables(state.Variables, initialVariables.ToStack());
} }
// No one is supposed to use the variable stack after an unconditional branch,
// but let's clear it just to be safe.
state.Variables.Clear();
} }
} }
} }

4
ICSharpCode.Decompiler/IL/TransformingVisitor.cs

@ -57,7 +57,7 @@ namespace ICSharpCode.Decompiler.IL
} }
*/ */
protected bool removeNops; protected bool removeNops = true;
sealed class InliningStack : Stack<ILInstruction>, IInlineContext sealed class InliningStack : Stack<ILInstruction>, IInlineContext
{ {
@ -114,6 +114,8 @@ namespace ICSharpCode.Decompiler.IL
List<ILInstruction> output = new List<ILInstruction>(); List<ILInstruction> output = new List<ILInstruction>();
for (int i = 0; i < block.Instructions.Count; i++) { for (int i = 0; i < block.Instructions.Count; i++) {
var inst = block.Instructions[i]; var inst = block.Instructions[i];
if (removeNops && inst.OpCode == OpCode.Nop)
continue;
inst = DoInline(stack, inst); inst = DoInline(stack, inst);
if (inst.HasFlag(InstructionFlags.MayBranch | InstructionFlags.MayPop if (inst.HasFlag(InstructionFlags.MayBranch | InstructionFlags.MayPop
| InstructionFlags.MayReadEvaluationStack | InstructionFlags.MayWriteEvaluationStack)) { | InstructionFlags.MayReadEvaluationStack | InstructionFlags.MayWriteEvaluationStack)) {

Loading…
Cancel
Save