Browse Source

Fix void and no-arguments methods

pull/903/head
mohe2015 8 years ago
parent
commit
d95d131071
  1. 21
      ICSharpCode.Decompiler/IL/Transforms/ProxyCallReplacer.cs

21
ICSharpCode.Decompiler/IL/Transforms/ProxyCallReplacer.cs

@ -36,12 +36,25 @@ namespace ICSharpCode.Decompiler.IL.Transforms
if (blockContainer.Blocks.Count != 1) if (blockContainer.Blocks.Count != 1)
return; return;
var block = blockContainer.Blocks[0]; var block = blockContainer.Blocks[0];
if (block.Instructions.Count != 1) Call call = null;
return; if (block.Instructions.Count == 1) {
// leave IL_0000 (call Test(ldloc this, ldloc A_1))
if (!block.Instructions[0].MatchLeave(blockContainer, out ILInstruction returnValue)) if (!block.Instructions[0].MatchLeave(blockContainer, out ILInstruction returnValue))
return; return;
if (!(returnValue is Call call)) call = returnValue as Call;
} else if (block.Instructions.Count == 2) {
// call Test(ldloc this, ldloc A_1)
// leave IL_0000(nop)
call = block.Instructions[0] as Call;
if (!block.Instructions[1].MatchLeave(blockContainer, out ILInstruction returnValue))
return;
if (!returnValue.MatchNop())
return;
}
if (call == null) {
return; return;
}
// check if original arguments are only correct ldloc calls // check if original arguments are only correct ldloc calls
for (int i = 0; i < call.Arguments.Count; i++) { for (int i = 0; i < call.Arguments.Count; i++) {
var originalArg = call.Arguments[i]; var originalArg = call.Arguments[i];
@ -56,6 +69,7 @@ namespace ICSharpCode.Decompiler.IL.Transforms
newInst.Arguments.Clear(); newInst.Arguments.Clear();
if (inst.Arguments.Count > 0) {
ILInstruction thisArg = inst.Arguments[0]; ILInstruction thisArg = inst.Arguments[0];
// special handling for first argument (this) - the underlying issue may be somewhere else // special handling for first argument (this) - the underlying issue may be somewhere else
@ -76,6 +90,7 @@ namespace ICSharpCode.Decompiler.IL.Transforms
for (int i = 1; i < inst.Arguments.Count; i++) { for (int i = 1; i < inst.Arguments.Count; i++) {
newInst.Arguments.Add(inst.Arguments[i]); newInst.Arguments.Add(inst.Arguments[i]);
} }
}
inst.ReplaceWith(newInst); inst.ReplaceWith(newInst);
} }
} }

Loading…
Cancel
Save