Browse Source

Fix order of ILAst debug languages.

pull/728/head
Daniel Grunwald 9 years ago
parent
commit
dfcfc8304c
  1. 2
      ICSharpCode.Decompiler/CSharp/CSharpDecompiler.cs
  2. 20
      ICSharpCode.Decompiler/Tests/TestCases/Switch.cs
  3. 6
      ILSpy/Languages/ILAstLanguage.cs

2
ICSharpCode.Decompiler/CSharp/CSharpDecompiler.cs

@ -50,7 +50,7 @@ namespace ICSharpCode.Decompiler.CSharp @@ -50,7 +50,7 @@ namespace ICSharpCode.Decompiler.CSharp
//new RemoveDeadVariableInit(),
new SplitVariables(),
new ControlFlowSimplification(),
new ILInlining(), // temporary pass, just to make the ILAst easier to read while debugging loop detection
//new ILInlining(), // temporary pass, just to make the ILAst easier to read while debugging loop detection
new LoopDetection(),
new IntroduceExitPoints(),
new ConditionDetection(),

20
ICSharpCode.Decompiler/Tests/TestCases/Switch.cs

@ -22,6 +22,7 @@ public static class Switch @@ -22,6 +22,7 @@ public static class Switch
{
public static void Main()
{
TestCase(SparseIntegerSwitch, -100, 1, 2, 3, 4);
TestCase(ShortSwitchOverString, "First case", "Else");
TestCase(SwitchOverString1, "First case", "Second case", "2nd case", "Third case", "Fourth case", "Fifth case", "Sixth case", null, "default", "else");
Console.WriteLine(SwitchOverString2());
@ -29,13 +30,30 @@ public static class Switch @@ -29,13 +30,30 @@ public static class Switch
Console.WriteLine(SwitchOverBool(false));
}
static void TestCase(Func<string, string> target, params string[] args)
static void TestCase<T>(Func<T, string> target, params T[] args)
{
foreach (var arg in args) {
Console.WriteLine(target(arg));
}
}
public static string SparseIntegerSwitch(int i)
{
switch (i) {
case -10000000: return "-10 mln";
case -100: return "-hundred";
case -1: return "-1";
case 0: return "0";
case 1: return "1";
case 2: return "2";
case 100: return "hundred";
case 10000: return "ten thousand";
case 10001: return "ten thousand and one";
case int.MaxValue: return "int.MaxValue";
default: return "something else";
}
}
public static string ShortSwitchOverString(string text)
{
switch (text) {

6
ILSpy/Languages/ILAstLanguage.cs

@ -91,13 +91,13 @@ namespace ICSharpCode.ILSpy @@ -91,13 +91,13 @@ namespace ICSharpCode.ILSpy
yield return new TypedIL();
CSharpDecompiler decompiler = new CSharpDecompiler(ModuleDefinition.CreateModule("Dummy", ModuleKind.Dll), new DecompilerSettings());
for (int i = 0; i <= decompiler.ILTransforms.Count; i++) {
yield return new BlockIL(decompiler.ILTransforms.Take(i).ToList());
var loop = decompiler.ILTransforms.ElementAtOrDefault(i) as LoopingTransform;
if (loop != null) {
for (int j = 0; j <= loop.Transforms.Count; j++) {
yield return new BlockIL(decompiler.ILTransforms.Take(i - 1).Concat(loop.Transforms.Take(j)).ToList());
for (int j = 1; j <= loop.Transforms.Count; j++) {
yield return new BlockIL(decompiler.ILTransforms.Take(i).Concat(loop.Transforms.Take(j)).ToList());
}
}
yield return new BlockIL(decompiler.ILTransforms.Take(i).ToList());
}
}

Loading…
Cancel
Save