Browse Source

Move PatternMatchingTransform after LoopDetection.

pull/2461/head
Siegfried Pammer 4 years ago
parent
commit
665c731cfc
  1. 19
      ICSharpCode.Decompiler.Tests/TestCases/Pretty/PatternMatching.cs
  2. 2
      ICSharpCode.Decompiler/CSharp/CSharpDecompiler.cs
  3. 2
      ICSharpCode.Decompiler/IL/Transforms/PatternMatchingTransform.cs

19
ICSharpCode.Decompiler.Tests/TestCases/Pretty/PatternMatching.cs

@ -212,6 +212,25 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -212,6 +212,25 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
}
}
public static void NotTypePatternBecauseVarIsNotDefAssignedInCaseOfFallthrough(object x)
{
#if OPT
string obj = x as string;
if (obj == null)
{
Console.WriteLine("pattern doesn't match");
}
Console.WriteLine(obj == null);
#else
string text = x as string;
if (text == null)
{
Console.WriteLine("pattern doesn't match");
}
Console.WriteLine(text == null);
#endif
}
private bool F()
{
return true;

2
ICSharpCode.Decompiler/CSharp/CSharpDecompiler.cs

@ -103,7 +103,6 @@ namespace ICSharpCode.Decompiler.CSharp @@ -103,7 +103,6 @@ namespace ICSharpCode.Decompiler.CSharp
new RemoveDeadVariableInit(),
new ControlFlowSimplification(), //split variables may enable new branch to leave inlining
new DynamicCallSiteTransform(),
new PatternMatchingTransform(),
new SwitchDetection(),
new SwitchOnStringTransform(),
new SwitchOnNullableTransform(),
@ -121,6 +120,7 @@ namespace ICSharpCode.Decompiler.CSharp @@ -121,6 +120,7 @@ namespace ICSharpCode.Decompiler.CSharp
},
// re-run DetectExitPoints after loop detection
new DetectExitPoints(),
new PatternMatchingTransform(), // must run after LoopDetection and before ConditionDetection
new BlockILTransform { // per-block transforms
PostOrderTransforms = {
new ConditionDetection(),

2
ICSharpCode.Decompiler/IL/Transforms/PatternMatchingTransform.cs

@ -193,6 +193,8 @@ namespace ICSharpCode.Decompiler.IL.Transforms @@ -193,6 +193,8 @@ namespace ICSharpCode.Decompiler.IL.Transforms
if (targetBlock.Parent != container)
return false;
if (targetBlock.IncomingEdgeCount != 1)
return false;
cfg ??= new ControlFlowGraph(container, context.CancellationToken);
var targetBlockNode = cfg.GetNode(targetBlock);
var uses = v.LoadInstructions.Concat<ILInstruction>(v.AddressInstructions)

Loading…
Cancel
Save