Browse Source

Fix SwitchOnStringTransform.SimplifyCascadingIfStatements: do not remove statements unrelated to switch pattern.

pull/1686/head
Siegfried Pammer 6 years ago
parent
commit
05454bd741
  1. 17
      ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.cs
  2. 2
      ICSharpCode.Decompiler/IL/Transforms/SwitchOnStringTransform.cs
  3. 2
      ICSharpCode.Decompiler/Metadata/UniversalAssemblyResolver.cs

17
ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.cs

@ -1192,5 +1192,22 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -1192,5 +1192,22 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
throw new ArgumentOutOfRangeException();
}
}
public static bool DoNotRemoveAssignmentBeforeSwitch(string x, out ConsoleKey key)
{
key = (ConsoleKey)0;
switch (x) {
case "A":
key = ConsoleKey.A;
break;
case "B":
key = ConsoleKey.B;
break;
case "C":
key = ConsoleKey.C;
break;
}
return key != (ConsoleKey)0;
}
}
}

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

@ -203,6 +203,8 @@ namespace ICSharpCode.Decompiler.IL.Transforms @@ -203,6 +203,8 @@ namespace ICSharpCode.Decompiler.IL.Transforms
switchValue = new LdLoc(switchValueVar);
}
} else {
// Instruction before the start of the switch is not related to the switch.
keepAssignmentBefore = true;
switchValue = new LdLoc(switchValueVar);
}
// if instruction must be followed by a branch to the next case

2
ICSharpCode.Decompiler/Metadata/UniversalAssemblyResolver.cs

@ -26,7 +26,7 @@ using System.Text; @@ -26,7 +26,7 @@ using System.Text;
namespace ICSharpCode.Decompiler.Metadata
{
// This inspired by Mono.Cecil's BaseAssemblyResolver/DefaultAssemblyResolver.
// This is inspired by Mono.Cecil's BaseAssemblyResolver/DefaultAssemblyResolver.
public class UniversalAssemblyResolver : IAssemblyResolver
{
static UniversalAssemblyResolver()

Loading…
Cancel
Save