mirror of https://github.com/icsharpcode/ILSpy.git
Browse Source
- add support for unknown delegate construction pattern. The method is compiler-generated, but has no compiler-generated name, we should be able to infer lambda usage from anonymous types used in the signature (i. e., the method can only be used as lambda, because that's where type names are optional). - Add CombineExitsTransform in DelegateConstruction: this allows combining lambdas with multiple return statements into a single expression (as it is expected by query expressions).pull/1405/head
3 changed files with 54 additions and 5 deletions
@ -0,0 +1,32 @@
@@ -0,0 +1,32 @@
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.Text; |
||||
|
||||
namespace ICSharpCode.Decompiler.IL.Transforms |
||||
{ |
||||
class CombineExitsTransform : IILTransform |
||||
{ |
||||
public void Run(ILFunction function, ILTransformContext context) |
||||
{ |
||||
if (!(function.Body is BlockContainer container && container.Blocks.Count == 1)) |
||||
return; |
||||
var block = container.EntryPoint; |
||||
if (block.Kind != BlockKind.ControlFlow) |
||||
return; |
||||
if (!(block.Instructions.SecondToLastOrDefault() is IfInstruction ifInst && block.Instructions.LastOrDefault() is Leave leave)) |
||||
return; |
||||
if (!ifInst.FalseInst.MatchNop()) |
||||
return; |
||||
if (!(Block.Unwrap(ifInst.TrueInst) is Leave leave2)) |
||||
return; |
||||
if (!(leave.IsLeavingFunction && leave2.IsLeavingFunction)) |
||||
return; |
||||
if (leave.Value.MatchNop() || leave2.Value.MatchNop()) |
||||
return; |
||||
IfInstruction value = new IfInstruction(ifInst.Condition, leave.Value, leave2.Value); |
||||
Leave combinedLeave = new Leave(leave.TargetContainer, value); |
||||
ifInst.ReplaceWith(combinedLeave); |
||||
block.Instructions.RemoveAt(combinedLeave.ChildIndex + 1); |
||||
} |
||||
} |
||||
} |
Loading…
Reference in new issue