diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Loops.cs b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Loops.cs index 8345eaf1c..38ed5fb5b 100644 --- a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Loops.cs +++ b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Loops.cs @@ -409,13 +409,22 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty } return result; } + + public void ForEachOverArray(string[] array) + { + foreach (string text in array) { + Console.WriteLine(text.ToLower() + text.ToUpper()); + } + } + + public unsafe void ForEachOverArrayOfPointers(int*[] array) + { + foreach (int* value in array) { + Console.WriteLine(new IntPtr(value)); + Console.WriteLine(new IntPtr(value)); + } + } #endregion - //public void ForEachOverArray(string[] array) - //{ - // foreach (string text in array) { - // text.ToLower(); - // } - //} public void ForOverArray(string[] array) { @@ -424,6 +433,16 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty } } + public void NoForeachOverArray(string[] array) + { + for (int i = 0; i < array.Length; i++) { + string value = array[i]; + if (i % 5 == 0) { + Console.WriteLine(value); + } + } + } + public void NestedLoops() { for (int i = 0; i < 10; i++) { diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Loops.il b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Loops.il index 030f6bd46..90c44f2f8 100644 --- a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Loops.il +++ b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Loops.il @@ -1,6 +1,6 @@ // Microsoft (R) .NET Framework IL Disassembler. Version 4.6.1055.0 -// Copyright (c) Microsoft Corporation. Alle Rechte vorbehalten. +// Copyright (c) Microsoft Corporation. All rights reserved. @@ -10,7 +10,7 @@ .publickeytoken = (B7 7A 5C 56 19 34 E0 89 ) // .z\V.4.. .ver 4:0:0:0 } -.assembly ic2bztjj +.assembly vsvybxtk { .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilationRelaxationsAttribute::.ctor(int32) = ( 01 00 08 00 00 00 00 00 ) .custom instance void [mscorlib]System.Runtime.CompilerServices.RuntimeCompatibilityAttribute::.ctor() = ( 01 00 01 00 54 02 16 57 72 61 70 4E 6F 6E 45 78 // ....T..WrapNonEx @@ -20,15 +20,15 @@ .hash algorithm 0x00008004 .ver 0:0:0:0 } -.module ic2bztjj.dll -// MVID: {821665CB-F67F-4600-8C6C-27617D873D36} +.module vsvybxtk.dll +// MVID: {6C5236E6-826F-4D2D-AF03-574254796A89} .custom instance void [mscorlib]System.Security.UnverifiableCodeAttribute::.ctor() = ( 01 00 00 00 ) .imagebase 0x10000000 .file alignment 0x00000200 .stackreserve 0x00100000 .subsystem 0x0003 // WINDOWS_CUI .corflags 0x00000001 // ILONLY -// Image base: 0x01550000 +// Image base: 0x02F80000 // =============== CLASS MEMBERS DECLARATION =================== @@ -1498,6 +1498,102 @@ IL_0044: ret } // end of method Loops::LastOrDefault + .method public hidebysig instance void + ForEachOverArray(string[] 'array') cil managed + { + // Code size 52 (0x34) + .maxstack 2 + .locals init (string V_0, + string[] V_1, + int32 V_2, + bool V_3) + IL_0000: nop + IL_0001: nop + IL_0002: ldarg.1 + IL_0003: stloc.1 + IL_0004: ldc.i4.0 + IL_0005: stloc.2 + IL_0006: br.s IL_0029 + + IL_0008: ldloc.1 + IL_0009: ldloc.2 + IL_000a: ldelem.ref + IL_000b: stloc.0 + IL_000c: nop + IL_000d: ldloc.0 + IL_000e: callvirt instance string [mscorlib]System.String::ToLower() + IL_0013: ldloc.0 + IL_0014: callvirt instance string [mscorlib]System.String::ToUpper() + IL_0019: call string [mscorlib]System.String::Concat(string, + string) + IL_001e: call void [mscorlib]System.Console::WriteLine(string) + IL_0023: nop + IL_0024: nop + IL_0025: ldloc.2 + IL_0026: ldc.i4.1 + IL_0027: add + IL_0028: stloc.2 + IL_0029: ldloc.2 + IL_002a: ldloc.1 + IL_002b: ldlen + IL_002c: conv.i4 + IL_002d: clt + IL_002f: stloc.3 + IL_0030: ldloc.3 + IL_0031: brtrue.s IL_0008 + + IL_0033: ret + } // end of method Loops::ForEachOverArray + + .method public hidebysig instance void + ForEachOverArrayOfPointers(int32*[] 'array') cil managed + { + // Code size 63 (0x3f) + .maxstack 2 + .locals init (int32* V_0, + int32*[] V_1, + int32 V_2, + bool V_3) + IL_0000: nop + IL_0001: nop + IL_0002: ldarg.1 + IL_0003: stloc.1 + IL_0004: ldc.i4.0 + IL_0005: stloc.2 + IL_0006: br.s IL_0034 + + IL_0008: ldloc.1 + IL_0009: ldloc.2 + IL_000a: ldelem.i + IL_000b: stloc.0 + IL_000c: nop + IL_000d: ldloc.0 + IL_000e: newobj instance void [mscorlib]System.IntPtr::.ctor(void*) + IL_0013: box [mscorlib]System.IntPtr + IL_0018: call void [mscorlib]System.Console::WriteLine(object) + IL_001d: nop + IL_001e: ldloc.0 + IL_001f: newobj instance void [mscorlib]System.IntPtr::.ctor(void*) + IL_0024: box [mscorlib]System.IntPtr + IL_0029: call void [mscorlib]System.Console::WriteLine(object) + IL_002e: nop + IL_002f: nop + IL_0030: ldloc.2 + IL_0031: ldc.i4.1 + IL_0032: add + IL_0033: stloc.2 + IL_0034: ldloc.2 + IL_0035: ldloc.1 + IL_0036: ldlen + IL_0037: conv.i4 + IL_0038: clt + IL_003a: stloc.3 + IL_003b: ldloc.3 + IL_003c: brtrue.s IL_0008 + + IL_003e: ret + } // end of method Loops::ForEachOverArrayOfPointers + .method public hidebysig instance void ForOverArray(string[] 'array') cil managed { @@ -1533,6 +1629,57 @@ IL_001e: ret } // end of method Loops::ForOverArray + .method public hidebysig instance void + NoForeachOverArray(string[] 'array') cil managed + { + // Code size 48 (0x30) + .maxstack 2 + .locals init (int32 V_0, + string V_1, + bool V_2) + IL_0000: nop + IL_0001: ldc.i4.0 + IL_0002: stloc.0 + IL_0003: br.s IL_0025 + + IL_0005: nop + IL_0006: ldarg.1 + IL_0007: ldloc.0 + IL_0008: ldelem.ref + IL_0009: stloc.1 + IL_000a: ldloc.0 + IL_000b: ldc.i4.5 + IL_000c: rem + IL_000d: ldc.i4.0 + IL_000e: ceq + IL_0010: ldc.i4.0 + IL_0011: ceq + IL_0013: stloc.2 + IL_0014: ldloc.2 + IL_0015: brtrue.s IL_0020 + + IL_0017: nop + IL_0018: ldloc.1 + IL_0019: call void [mscorlib]System.Console::WriteLine(string) + IL_001e: nop + IL_001f: nop + IL_0020: nop + IL_0021: ldloc.0 + IL_0022: ldc.i4.1 + IL_0023: add + IL_0024: stloc.0 + IL_0025: ldloc.0 + IL_0026: ldarg.1 + IL_0027: ldlen + IL_0028: conv.i4 + IL_0029: clt + IL_002b: stloc.2 + IL_002c: ldloc.2 + IL_002d: brtrue.s IL_0005 + + IL_002f: ret + } // end of method Loops::NoForeachOverArray + .method public hidebysig instance void NestedLoops() cil managed { @@ -1804,4 +1951,4 @@ // ============================================================= // *********** DISASSEMBLY COMPLETE *********************** -// Warnung: Win32-Ressourcendatei "../../../TestCases/Pretty\Loops.res" wurde erstellt. +// WARNING: Created Win32 resource file ../../../TestCases/Pretty\Loops.res diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Loops.opt.il b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Loops.opt.il index 50a8785a7..a16562df5 100644 --- a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Loops.opt.il +++ b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Loops.opt.il @@ -1,6 +1,6 @@ // Microsoft (R) .NET Framework IL Disassembler. Version 4.6.1055.0 -// Copyright (c) Microsoft Corporation. Alle Rechte vorbehalten. +// Copyright (c) Microsoft Corporation. All rights reserved. @@ -10,7 +10,7 @@ .publickeytoken = (B7 7A 5C 56 19 34 E0 89 ) // .z\V.4.. .ver 4:0:0:0 } -.assembly fabjeeha +.assembly hrizu0iy { .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilationRelaxationsAttribute::.ctor(int32) = ( 01 00 08 00 00 00 00 00 ) .custom instance void [mscorlib]System.Runtime.CompilerServices.RuntimeCompatibilityAttribute::.ctor() = ( 01 00 01 00 54 02 16 57 72 61 70 4E 6F 6E 45 78 // ....T..WrapNonEx @@ -20,15 +20,15 @@ .hash algorithm 0x00008004 .ver 0:0:0:0 } -.module fabjeeha.dll -// MVID: {4FB3AE1F-ECE0-4E7D-84DC-E693282CA0AF} +.module hrizu0iy.dll +// MVID: {8FC80EBC-E149-454A-A769-13F3C07EB46F} .custom instance void [mscorlib]System.Security.UnverifiableCodeAttribute::.ctor() = ( 01 00 00 00 ) .imagebase 0x10000000 .file alignment 0x00000200 .stackreserve 0x00100000 .subsystem 0x0003 // WINDOWS_CUI .corflags 0x00000001 // ILONLY -// Image base: 0x00D90000 +// Image base: 0x02CE0000 // =============== CLASS MEMBERS DECLARATION =================== @@ -1202,6 +1202,83 @@ IL_002f: ret } // end of method Loops::LastOrDefault + .method public hidebysig instance void + ForEachOverArray(string[] 'array') cil managed + { + // Code size 43 (0x2b) + .maxstack 2 + .locals init (string V_0, + string[] V_1, + int32 V_2) + IL_0000: ldarg.1 + IL_0001: stloc.1 + IL_0002: ldc.i4.0 + IL_0003: stloc.2 + IL_0004: br.s IL_0024 + + IL_0006: ldloc.1 + IL_0007: ldloc.2 + IL_0008: ldelem.ref + IL_0009: stloc.0 + IL_000a: ldloc.0 + IL_000b: callvirt instance string [mscorlib]System.String::ToLower() + IL_0010: ldloc.0 + IL_0011: callvirt instance string [mscorlib]System.String::ToUpper() + IL_0016: call string [mscorlib]System.String::Concat(string, + string) + IL_001b: call void [mscorlib]System.Console::WriteLine(string) + IL_0020: ldloc.2 + IL_0021: ldc.i4.1 + IL_0022: add + IL_0023: stloc.2 + IL_0024: ldloc.2 + IL_0025: ldloc.1 + IL_0026: ldlen + IL_0027: conv.i4 + IL_0028: blt.s IL_0006 + + IL_002a: ret + } // end of method Loops::ForEachOverArray + + .method public hidebysig instance void + ForEachOverArrayOfPointers(int32*[] 'array') cil managed + { + // Code size 53 (0x35) + .maxstack 2 + .locals init (int32* V_0, + int32*[] V_1, + int32 V_2) + IL_0000: ldarg.1 + IL_0001: stloc.1 + IL_0002: ldc.i4.0 + IL_0003: stloc.2 + IL_0004: br.s IL_002e + + IL_0006: ldloc.1 + IL_0007: ldloc.2 + IL_0008: ldelem.i + IL_0009: stloc.0 + IL_000a: ldloc.0 + IL_000b: newobj instance void [mscorlib]System.IntPtr::.ctor(void*) + IL_0010: box [mscorlib]System.IntPtr + IL_0015: call void [mscorlib]System.Console::WriteLine(object) + IL_001a: ldloc.0 + IL_001b: newobj instance void [mscorlib]System.IntPtr::.ctor(void*) + IL_0020: box [mscorlib]System.IntPtr + IL_0025: call void [mscorlib]System.Console::WriteLine(object) + IL_002a: ldloc.2 + IL_002b: ldc.i4.1 + IL_002c: add + IL_002d: stloc.2 + IL_002e: ldloc.2 + IL_002f: ldloc.1 + IL_0030: ldlen + IL_0031: conv.i4 + IL_0032: blt.s IL_0006 + + IL_0034: ret + } // end of method Loops::ForEachOverArrayOfPointers + .method public hidebysig instance void ForOverArray(string[] 'array') cil managed { @@ -1230,6 +1307,41 @@ IL_0017: ret } // end of method Loops::ForOverArray + .method public hidebysig instance void + NoForeachOverArray(string[] 'array') cil managed + { + // Code size 30 (0x1e) + .maxstack 2 + .locals init (int32 V_0, + string V_1) + IL_0000: ldc.i4.0 + IL_0001: stloc.0 + IL_0002: br.s IL_0017 + + IL_0004: ldarg.1 + IL_0005: ldloc.0 + IL_0006: ldelem.ref + IL_0007: stloc.1 + IL_0008: ldloc.0 + IL_0009: ldc.i4.5 + IL_000a: rem + IL_000b: brtrue.s IL_0013 + + IL_000d: ldloc.1 + IL_000e: call void [mscorlib]System.Console::WriteLine(string) + IL_0013: ldloc.0 + IL_0014: ldc.i4.1 + IL_0015: add + IL_0016: stloc.0 + IL_0017: ldloc.0 + IL_0018: ldarg.1 + IL_0019: ldlen + IL_001a: conv.i4 + IL_001b: blt.s IL_0004 + + IL_001d: ret + } // end of method Loops::NoForeachOverArray + .method public hidebysig instance void NestedLoops() cil managed { @@ -1402,4 +1514,4 @@ // ============================================================= // *********** DISASSEMBLY COMPLETE *********************** -// Warnung: Win32-Ressourcendatei "../../../TestCases/Pretty\Loops.opt.res" wurde erstellt. +// WARNING: Created Win32 resource file ../../../TestCases/Pretty\Loops.opt.res diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Loops.opt.roslyn.il b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Loops.opt.roslyn.il index 8fc3ae3c4..4ab40094f 100644 --- a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Loops.opt.roslyn.il +++ b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Loops.opt.roslyn.il @@ -1,6 +1,6 @@ // Microsoft (R) .NET Framework IL Disassembler. Version 4.6.1055.0 -// Copyright (c) Microsoft Corporation. Alle Rechte vorbehalten. +// Copyright (c) Microsoft Corporation. All rights reserved. @@ -25,14 +25,14 @@ .ver 0:0:0:0 } .module Loops.dll -// MVID: {F03B196B-9B00-49BE-A335-2D460586E39A} +// MVID: {30F4646B-D900-420C-89F2-283C178D2EAC} .custom instance void [mscorlib]System.Security.UnverifiableCodeAttribute::.ctor() = ( 01 00 00 00 ) .imagebase 0x10000000 .file alignment 0x00000200 .stackreserve 0x00100000 .subsystem 0x0003 // WINDOWS_CUI .corflags 0x00000001 // ILONLY -// Image base: 0x02D60000 +// Image base: 0x00E90000 // =============== CLASS MEMBERS DECLARATION =================== @@ -1164,6 +1164,80 @@ IL_002d: ret } // end of method Loops::LastOrDefault + .method public hidebysig instance void + ForEachOverArray(string[] 'array') cil managed + { + // Code size 43 (0x2b) + .maxstack 2 + .locals init (string[] V_0, + int32 V_1, + string V_2) + IL_0000: ldarg.1 + IL_0001: stloc.0 + IL_0002: ldc.i4.0 + IL_0003: stloc.1 + IL_0004: br.s IL_0024 + + IL_0006: ldloc.0 + IL_0007: ldloc.1 + IL_0008: ldelem.ref + IL_0009: stloc.2 + IL_000a: ldloc.2 + IL_000b: callvirt instance string [mscorlib]System.String::ToLower() + IL_0010: ldloc.2 + IL_0011: callvirt instance string [mscorlib]System.String::ToUpper() + IL_0016: call string [mscorlib]System.String::Concat(string, + string) + IL_001b: call void [mscorlib]System.Console::WriteLine(string) + IL_0020: ldloc.1 + IL_0021: ldc.i4.1 + IL_0022: add + IL_0023: stloc.1 + IL_0024: ldloc.1 + IL_0025: ldloc.0 + IL_0026: ldlen + IL_0027: conv.i4 + IL_0028: blt.s IL_0006 + + IL_002a: ret + } // end of method Loops::ForEachOverArray + + .method public hidebysig instance void + ForEachOverArrayOfPointers(int32*[] 'array') cil managed + { + // Code size 51 (0x33) + .maxstack 2 + .locals init (int32*[] V_0, + int32 V_1) + IL_0000: ldarg.1 + IL_0001: stloc.0 + IL_0002: ldc.i4.0 + IL_0003: stloc.1 + IL_0004: br.s IL_002c + + IL_0006: ldloc.0 + IL_0007: ldloc.1 + IL_0008: ldelem.i + IL_0009: dup + IL_000a: newobj instance void [mscorlib]System.IntPtr::.ctor(void*) + IL_000f: box [mscorlib]System.IntPtr + IL_0014: call void [mscorlib]System.Console::WriteLine(object) + IL_0019: newobj instance void [mscorlib]System.IntPtr::.ctor(void*) + IL_001e: box [mscorlib]System.IntPtr + IL_0023: call void [mscorlib]System.Console::WriteLine(object) + IL_0028: ldloc.1 + IL_0029: ldc.i4.1 + IL_002a: add + IL_002b: stloc.1 + IL_002c: ldloc.1 + IL_002d: ldloc.0 + IL_002e: ldlen + IL_002f: conv.i4 + IL_0030: blt.s IL_0006 + + IL_0032: ret + } // end of method Loops::ForEachOverArrayOfPointers + .method public hidebysig instance void ForOverArray(string[] 'array') cil managed { @@ -1192,6 +1266,41 @@ IL_0017: ret } // end of method Loops::ForOverArray + .method public hidebysig instance void + NoForeachOverArray(string[] 'array') cil managed + { + // Code size 30 (0x1e) + .maxstack 2 + .locals init (int32 V_0, + string V_1) + IL_0000: ldc.i4.0 + IL_0001: stloc.0 + IL_0002: br.s IL_0017 + + IL_0004: ldarg.1 + IL_0005: ldloc.0 + IL_0006: ldelem.ref + IL_0007: stloc.1 + IL_0008: ldloc.0 + IL_0009: ldc.i4.5 + IL_000a: rem + IL_000b: brtrue.s IL_0013 + + IL_000d: ldloc.1 + IL_000e: call void [mscorlib]System.Console::WriteLine(string) + IL_0013: ldloc.0 + IL_0014: ldc.i4.1 + IL_0015: add + IL_0016: stloc.0 + IL_0017: ldloc.0 + IL_0018: ldarg.1 + IL_0019: ldlen + IL_001a: conv.i4 + IL_001b: blt.s IL_0004 + + IL_001d: ret + } // end of method Loops::NoForeachOverArray + .method public hidebysig instance void NestedLoops() cil managed { diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Loops.roslyn.il b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Loops.roslyn.il index f10e2f5ff..3a9841da1 100644 --- a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Loops.roslyn.il +++ b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Loops.roslyn.il @@ -1,6 +1,6 @@ // Microsoft (R) .NET Framework IL Disassembler. Version 4.6.1055.0 -// Copyright (c) Microsoft Corporation. Alle Rechte vorbehalten. +// Copyright (c) Microsoft Corporation. All rights reserved. @@ -25,14 +25,14 @@ .ver 0:0:0:0 } .module Loops.dll -// MVID: {F66BA703-8DC0-4A56-81BC-D288A1D83D30} +// MVID: {721D369B-DC6E-425B-AE0E-46C242DEFDF5} .custom instance void [mscorlib]System.Security.UnverifiableCodeAttribute::.ctor() = ( 01 00 00 00 ) .imagebase 0x10000000 .file alignment 0x00000200 .stackreserve 0x00100000 .subsystem 0x0003 // WINDOWS_CUI .corflags 0x00000001 // ILONLY -// Image base: 0x02D60000 +// Image base: 0x00480000 // =============== CLASS MEMBERS DECLARATION =================== @@ -1400,6 +1400,94 @@ IL_0038: ret } // end of method Loops::LastOrDefault + .method public hidebysig instance void + ForEachOverArray(string[] 'array') cil managed + { + // Code size 48 (0x30) + .maxstack 2 + .locals init (string[] V_0, + int32 V_1, + string V_2) + IL_0000: nop + IL_0001: nop + IL_0002: ldarg.1 + IL_0003: stloc.0 + IL_0004: ldc.i4.0 + IL_0005: stloc.1 + IL_0006: br.s IL_0029 + + IL_0008: ldloc.0 + IL_0009: ldloc.1 + IL_000a: ldelem.ref + IL_000b: stloc.2 + IL_000c: nop + IL_000d: ldloc.2 + IL_000e: callvirt instance string [mscorlib]System.String::ToLower() + IL_0013: ldloc.2 + IL_0014: callvirt instance string [mscorlib]System.String::ToUpper() + IL_0019: call string [mscorlib]System.String::Concat(string, + string) + IL_001e: call void [mscorlib]System.Console::WriteLine(string) + IL_0023: nop + IL_0024: nop + IL_0025: ldloc.1 + IL_0026: ldc.i4.1 + IL_0027: add + IL_0028: stloc.1 + IL_0029: ldloc.1 + IL_002a: ldloc.0 + IL_002b: ldlen + IL_002c: conv.i4 + IL_002d: blt.s IL_0008 + + IL_002f: ret + } // end of method Loops::ForEachOverArray + + .method public hidebysig instance void + ForEachOverArrayOfPointers(int32*[] 'array') cil managed + { + // Code size 59 (0x3b) + .maxstack 2 + .locals init (int32*[] V_0, + int32 V_1, + int32* V_2) + IL_0000: nop + IL_0001: nop + IL_0002: ldarg.1 + IL_0003: stloc.0 + IL_0004: ldc.i4.0 + IL_0005: stloc.1 + IL_0006: br.s IL_0034 + + IL_0008: ldloc.0 + IL_0009: ldloc.1 + IL_000a: ldelem.i + IL_000b: stloc.2 + IL_000c: nop + IL_000d: ldloc.2 + IL_000e: newobj instance void [mscorlib]System.IntPtr::.ctor(void*) + IL_0013: box [mscorlib]System.IntPtr + IL_0018: call void [mscorlib]System.Console::WriteLine(object) + IL_001d: nop + IL_001e: ldloc.2 + IL_001f: newobj instance void [mscorlib]System.IntPtr::.ctor(void*) + IL_0024: box [mscorlib]System.IntPtr + IL_0029: call void [mscorlib]System.Console::WriteLine(object) + IL_002e: nop + IL_002f: nop + IL_0030: ldloc.1 + IL_0031: ldc.i4.1 + IL_0032: add + IL_0033: stloc.1 + IL_0034: ldloc.1 + IL_0035: ldloc.0 + IL_0036: ldlen + IL_0037: conv.i4 + IL_0038: blt.s IL_0008 + + IL_003a: ret + } // end of method Loops::ForEachOverArrayOfPointers + .method public hidebysig instance void ForOverArray(string[] 'array') cil managed { @@ -1435,6 +1523,56 @@ IL_001e: ret } // end of method Loops::ForOverArray + .method public hidebysig instance void + NoForeachOverArray(string[] 'array') cil managed + { + // Code size 45 (0x2d) + .maxstack 2 + .locals init (int32 V_0, + string V_1, + bool V_2, + bool V_3) + IL_0000: nop + IL_0001: ldc.i4.0 + IL_0002: stloc.0 + IL_0003: br.s IL_0022 + + IL_0005: nop + IL_0006: ldarg.1 + IL_0007: ldloc.0 + IL_0008: ldelem.ref + IL_0009: stloc.1 + IL_000a: ldloc.0 + IL_000b: ldc.i4.5 + IL_000c: rem + IL_000d: ldc.i4.0 + IL_000e: ceq + IL_0010: stloc.2 + IL_0011: ldloc.2 + IL_0012: brfalse.s IL_001d + + IL_0014: nop + IL_0015: ldloc.1 + IL_0016: call void [mscorlib]System.Console::WriteLine(string) + IL_001b: nop + IL_001c: nop + IL_001d: nop + IL_001e: ldloc.0 + IL_001f: ldc.i4.1 + IL_0020: add + IL_0021: stloc.0 + IL_0022: ldloc.0 + IL_0023: ldarg.1 + IL_0024: ldlen + IL_0025: conv.i4 + IL_0026: clt + IL_0028: stloc.3 + IL_0029: ldloc.3 + IL_002a: brtrue.s IL_0005 + + IL_002c: ret + } // end of method Loops::NoForeachOverArray + .method public hidebysig instance void NestedLoops() cil managed { diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.cs b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.cs index 0b118981a..a80f12a2f 100644 --- a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.cs +++ b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.cs @@ -380,6 +380,7 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty List list2 = new List(); SetProperty[] properties = Switch.GetProperties(); for (int i = 0; i < properties.Length; i++) { + Console.WriteLine("In for-loop"); SetProperty setProperty = properties[i]; switch (setProperty.Property.Name) { case "Name1": diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.il b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.il index 9db363234..4cf8d7ecc 100644 --- a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.il +++ b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.il @@ -10,7 +10,7 @@ .publickeytoken = (B7 7A 5C 56 19 34 E0 89 ) // .z\V.4.. .ver 4:0:0:0 } -.assembly o03zflju +.assembly rqt3qv2j { .custom instance void [mscorlib]System.Runtime.CompilerServices.RuntimeCompatibilityAttribute::.ctor() = ( 01 00 01 00 54 02 16 57 72 61 70 4E 6F 6E 45 78 // ....T..WrapNonEx 63 65 70 74 69 6F 6E 54 68 72 6F 77 73 01 ) // ceptionThrows. @@ -20,15 +20,15 @@ .hash algorithm 0x00008004 .ver 0:0:0:0 } -.module o03zflju.dll -// MVID: {0EF64C57-A49E-4138-9C3F-BDAB86B2E450} +.module rqt3qv2j.dll +// MVID: {0220E31A-C196-4C4B-B009-AED9A1DDD0BE} .custom instance void [mscorlib]System.Security.UnverifiableCodeAttribute::.ctor() = ( 01 00 00 00 ) .imagebase 0x10000000 .file alignment 0x00000200 .stackreserve 0x00100000 .subsystem 0x0003 // WINDOWS_CUI .corflags 0x00000001 // ILONLY -// Image base: 0x01330000 +// Image base: 0x02D40000 // =============== CLASS MEMBERS DECLARATION =================== @@ -880,7 +880,7 @@ IL_0015: brfalse IL_00e9 IL_001a: volatile. - IL_001c: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{0EF64C57-A49E-4138-9C3F-BDAB86B2E450}'::'$$method0x600000d-1' + IL_001c: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{0220E31A-C196-4C4B-B009-AED9A1DDD0BE}'::'$$method0x600000d-1' IL_0021: brtrue.s IL_0084 IL_0023: ldc.i4.7 @@ -921,9 +921,9 @@ IL_0078: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2::Add(!0, !1) IL_007d: volatile. - IL_007f: stsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{0EF64C57-A49E-4138-9C3F-BDAB86B2E450}'::'$$method0x600000d-1' + IL_007f: stsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{0220E31A-C196-4C4B-B009-AED9A1DDD0BE}'::'$$method0x600000d-1' IL_0084: volatile. - IL_0086: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{0EF64C57-A49E-4138-9C3F-BDAB86B2E450}'::'$$method0x600000d-1' + IL_0086: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{0220E31A-C196-4C4B-B009-AED9A1DDD0BE}'::'$$method0x600000d-1' IL_008b: ldloc.1 IL_008c: ldloca.s V_2 IL_008e: call instance bool class [mscorlib]System.Collections.Generic.Dictionary`2::TryGetValue(!0, @@ -995,7 +995,7 @@ IL_0013: brfalse IL_0158 IL_0018: volatile. - IL_001a: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{0EF64C57-A49E-4138-9C3F-BDAB86B2E450}'::'$$method0x600000e-1' + IL_001a: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{0220E31A-C196-4C4B-B009-AED9A1DDD0BE}'::'$$method0x600000e-1' IL_001f: brtrue IL_00b8 IL_0024: ldc.i4.s 11 @@ -1056,9 +1056,9 @@ IL_00ac: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2::Add(!0, !1) IL_00b1: volatile. - IL_00b3: stsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{0EF64C57-A49E-4138-9C3F-BDAB86B2E450}'::'$$method0x600000e-1' + IL_00b3: stsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{0220E31A-C196-4C4B-B009-AED9A1DDD0BE}'::'$$method0x600000e-1' IL_00b8: volatile. - IL_00ba: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{0EF64C57-A49E-4138-9C3F-BDAB86B2E450}'::'$$method0x600000e-1' + IL_00ba: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{0220E31A-C196-4C4B-B009-AED9A1DDD0BE}'::'$$method0x600000e-1' IL_00bf: ldloc.1 IL_00c0: ldloca.s V_2 IL_00c2: call instance bool class [mscorlib]System.Collections.Generic.Dictionary`2::TryGetValue(!0, @@ -1309,7 +1309,7 @@ .method public hidebysig static void SwitchOnStringInForLoop() cil managed { - // Code size 321 (0x141) + // Code size 332 (0x14c) .maxstack 4 .locals init (class [mscorlib]System.Collections.Generic.List`1 V_0, class [mscorlib]System.Collections.Generic.List`1 V_1, @@ -1328,143 +1328,146 @@ IL_0012: stloc.2 IL_0013: ldc.i4.0 IL_0014: stloc.3 - IL_0015: br IL_0131 + IL_0015: br IL_013c IL_001a: nop - IL_001b: ldloc.2 - IL_001c: ldloc.3 - IL_001d: ldelem.ref - IL_001e: stloc.s V_4 - IL_0020: ldloc.s V_4 - IL_0022: ldfld class [mscorlib]System.Reflection.PropertyInfo ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/SetProperty::Property - IL_0027: callvirt instance string [mscorlib]System.Reflection.MemberInfo::get_Name() - IL_002c: stloc.s V_5 - IL_002e: ldloc.s V_5 - IL_0030: brfalse IL_0121 - - IL_0035: volatile. - IL_0037: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{0EF64C57-A49E-4138-9C3F-BDAB86B2E450}'::'$$method0x6000013-1' - IL_003c: brtrue.s IL_0093 - - IL_003e: ldc.i4.6 - IL_003f: newobj instance void class [mscorlib]System.Collections.Generic.Dictionary`2::.ctor(int32) - IL_0044: dup - IL_0045: ldstr "Name1" - IL_004a: ldc.i4.0 - IL_004b: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2::Add(!0, + IL_001b: ldstr "In for-loop" + IL_0020: call void [mscorlib]System.Console::WriteLine(string) + IL_0025: nop + IL_0026: ldloc.2 + IL_0027: ldloc.3 + IL_0028: ldelem.ref + IL_0029: stloc.s V_4 + IL_002b: ldloc.s V_4 + IL_002d: ldfld class [mscorlib]System.Reflection.PropertyInfo ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/SetProperty::Property + IL_0032: callvirt instance string [mscorlib]System.Reflection.MemberInfo::get_Name() + IL_0037: stloc.s V_5 + IL_0039: ldloc.s V_5 + IL_003b: brfalse IL_012c + + IL_0040: volatile. + IL_0042: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{0220E31A-C196-4C4B-B009-AED9A1DDD0BE}'::'$$method0x6000013-1' + IL_0047: brtrue.s IL_009e + + IL_0049: ldc.i4.6 + IL_004a: newobj instance void class [mscorlib]System.Collections.Generic.Dictionary`2::.ctor(int32) + IL_004f: dup + IL_0050: ldstr "Name1" + IL_0055: ldc.i4.0 + IL_0056: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2::Add(!0, !1) - IL_0050: dup - IL_0051: ldstr "Name2" - IL_0056: ldc.i4.1 - IL_0057: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2::Add(!0, + IL_005b: dup + IL_005c: ldstr "Name2" + IL_0061: ldc.i4.1 + IL_0062: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2::Add(!0, !1) - IL_005c: dup - IL_005d: ldstr "Name3" - IL_0062: ldc.i4.2 - IL_0063: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2::Add(!0, + IL_0067: dup + IL_0068: ldstr "Name3" + IL_006d: ldc.i4.2 + IL_006e: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2::Add(!0, !1) - IL_0068: dup - IL_0069: ldstr "Name4" - IL_006e: ldc.i4.3 - IL_006f: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2::Add(!0, + IL_0073: dup + IL_0074: ldstr "Name4" + IL_0079: ldc.i4.3 + IL_007a: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2::Add(!0, !1) - IL_0074: dup - IL_0075: ldstr "Name5" - IL_007a: ldc.i4.4 - IL_007b: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2::Add(!0, + IL_007f: dup + IL_0080: ldstr "Name5" + IL_0085: ldc.i4.4 + IL_0086: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2::Add(!0, !1) - IL_0080: dup - IL_0081: ldstr "Name6" - IL_0086: ldc.i4.5 - IL_0087: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2::Add(!0, + IL_008b: dup + IL_008c: ldstr "Name6" + IL_0091: ldc.i4.5 + IL_0092: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2::Add(!0, !1) - IL_008c: volatile. - IL_008e: stsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{0EF64C57-A49E-4138-9C3F-BDAB86B2E450}'::'$$method0x6000013-1' - IL_0093: volatile. - IL_0095: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{0EF64C57-A49E-4138-9C3F-BDAB86B2E450}'::'$$method0x6000013-1' - IL_009a: ldloc.s V_5 - IL_009c: ldloca.s V_6 - IL_009e: call instance bool class [mscorlib]System.Collections.Generic.Dictionary`2::TryGetValue(!0, + IL_0097: volatile. + IL_0099: stsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{0220E31A-C196-4C4B-B009-AED9A1DDD0BE}'::'$$method0x6000013-1' + IL_009e: volatile. + IL_00a0: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{0220E31A-C196-4C4B-B009-AED9A1DDD0BE}'::'$$method0x6000013-1' + IL_00a5: ldloc.s V_5 + IL_00a7: ldloca.s V_6 + IL_00a9: call instance bool class [mscorlib]System.Collections.Generic.Dictionary`2::TryGetValue(!0, !1&) - IL_00a3: brfalse.s IL_0121 - - IL_00a5: ldloc.s V_6 - IL_00a7: switch ( - IL_00c6, - IL_00da, - IL_00ee, - IL_0102, - IL_0116, - IL_0116) - IL_00c4: br.s IL_0121 - - IL_00c6: ldloc.s V_4 - IL_00c8: ldc.i4.1 - IL_00c9: callvirt instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/SetProperty::set_Set(int32) - IL_00ce: nop - IL_00cf: ldloc.0 - IL_00d0: ldloc.s V_4 - IL_00d2: callvirt instance void class [mscorlib]System.Collections.Generic.List`1::Add(!0) - IL_00d7: nop - IL_00d8: br.s IL_012c - - IL_00da: ldloc.s V_4 - IL_00dc: ldc.i4.2 - IL_00dd: callvirt instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/SetProperty::set_Set(int32) + IL_00ae: brfalse.s IL_012c + + IL_00b0: ldloc.s V_6 + IL_00b2: switch ( + IL_00d1, + IL_00e5, + IL_00f9, + IL_010d, + IL_0121, + IL_0121) + IL_00cf: br.s IL_012c + + IL_00d1: ldloc.s V_4 + IL_00d3: ldc.i4.1 + IL_00d4: callvirt instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/SetProperty::set_Set(int32) + IL_00d9: nop + IL_00da: ldloc.0 + IL_00db: ldloc.s V_4 + IL_00dd: callvirt instance void class [mscorlib]System.Collections.Generic.List`1::Add(!0) IL_00e2: nop - IL_00e3: ldloc.0 - IL_00e4: ldloc.s V_4 - IL_00e6: callvirt instance void class [mscorlib]System.Collections.Generic.List`1::Add(!0) - IL_00eb: nop - IL_00ec: br.s IL_012c - - IL_00ee: ldloc.s V_4 - IL_00f0: ldc.i4.3 - IL_00f1: callvirt instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/SetProperty::set_Set(int32) + IL_00e3: br.s IL_0137 + + IL_00e5: ldloc.s V_4 + IL_00e7: ldc.i4.2 + IL_00e8: callvirt instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/SetProperty::set_Set(int32) + IL_00ed: nop + IL_00ee: ldloc.0 + IL_00ef: ldloc.s V_4 + IL_00f1: callvirt instance void class [mscorlib]System.Collections.Generic.List`1::Add(!0) IL_00f6: nop - IL_00f7: ldloc.0 - IL_00f8: ldloc.s V_4 - IL_00fa: callvirt instance void class [mscorlib]System.Collections.Generic.List`1::Add(!0) - IL_00ff: nop - IL_0100: br.s IL_012c - - IL_0102: ldloc.s V_4 - IL_0104: ldc.i4.4 - IL_0105: callvirt instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/SetProperty::set_Set(int32) + IL_00f7: br.s IL_0137 + + IL_00f9: ldloc.s V_4 + IL_00fb: ldc.i4.3 + IL_00fc: callvirt instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/SetProperty::set_Set(int32) + IL_0101: nop + IL_0102: ldloc.0 + IL_0103: ldloc.s V_4 + IL_0105: callvirt instance void class [mscorlib]System.Collections.Generic.List`1::Add(!0) IL_010a: nop - IL_010b: ldloc.0 - IL_010c: ldloc.s V_4 - IL_010e: callvirt instance void class [mscorlib]System.Collections.Generic.List`1::Add(!0) - IL_0113: nop - IL_0114: br.s IL_012c + IL_010b: br.s IL_0137 + IL_010d: ldloc.s V_4 + IL_010f: ldc.i4.4 + IL_0110: callvirt instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/SetProperty::set_Set(int32) + IL_0115: nop IL_0116: ldloc.0 IL_0117: ldloc.s V_4 IL_0119: callvirt instance void class [mscorlib]System.Collections.Generic.List`1::Add(!0) IL_011e: nop - IL_011f: br.s IL_012c + IL_011f: br.s IL_0137 - IL_0121: ldloc.1 + IL_0121: ldloc.0 IL_0122: ldloc.s V_4 IL_0124: callvirt instance void class [mscorlib]System.Collections.Generic.List`1::Add(!0) IL_0129: nop - IL_012a: br.s IL_012c - - IL_012c: nop - IL_012d: ldloc.3 - IL_012e: ldc.i4.1 - IL_012f: add - IL_0130: stloc.3 - IL_0131: ldloc.3 - IL_0132: ldloc.2 - IL_0133: ldlen - IL_0134: conv.i4 - IL_0135: clt - IL_0137: stloc.s V_7 - IL_0139: ldloc.s V_7 - IL_013b: brtrue IL_001a - - IL_0140: ret + IL_012a: br.s IL_0137 + + IL_012c: ldloc.1 + IL_012d: ldloc.s V_4 + IL_012f: callvirt instance void class [mscorlib]System.Collections.Generic.List`1::Add(!0) + IL_0134: nop + IL_0135: br.s IL_0137 + + IL_0137: nop + IL_0138: ldloc.3 + IL_0139: ldc.i4.1 + IL_013a: add + IL_013b: stloc.3 + IL_013c: ldloc.3 + IL_013d: ldloc.2 + IL_013e: ldlen + IL_013f: conv.i4 + IL_0140: clt + IL_0142: stloc.s V_7 + IL_0144: ldloc.s V_7 + IL_0146: brtrue IL_001a + + IL_014b: ret } // end of method Switch::SwitchOnStringInForLoop .method public hidebysig static void SwitchWithComplexCondition(string[] args) cil managed @@ -1608,14 +1611,14 @@ } // end of class ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch -.class private auto ansi '{0EF64C57-A49E-4138-9C3F-BDAB86B2E450}' +.class private auto ansi '{0220E31A-C196-4C4B-B009-AED9A1DDD0BE}' extends [mscorlib]System.Object { .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) .field static assembly class [mscorlib]System.Collections.Generic.Dictionary`2 '$$method0x600000d-1' .field static assembly class [mscorlib]System.Collections.Generic.Dictionary`2 '$$method0x600000e-1' .field static assembly class [mscorlib]System.Collections.Generic.Dictionary`2 '$$method0x6000013-1' -} // end of class '{0EF64C57-A49E-4138-9C3F-BDAB86B2E450}' +} // end of class '{0220E31A-C196-4C4B-B009-AED9A1DDD0BE}' // ============================================================= diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.opt.il b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.opt.il index c4fc03c00..ea89fd982 100644 --- a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.opt.il +++ b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.opt.il @@ -10,7 +10,7 @@ .publickeytoken = (B7 7A 5C 56 19 34 E0 89 ) // .z\V.4.. .ver 4:0:0:0 } -.assembly pryqrprl +.assembly wn5i3ung { .custom instance void [mscorlib]System.Runtime.CompilerServices.RuntimeCompatibilityAttribute::.ctor() = ( 01 00 01 00 54 02 16 57 72 61 70 4E 6F 6E 45 78 // ....T..WrapNonEx 63 65 70 74 69 6F 6E 54 68 72 6F 77 73 01 ) // ceptionThrows. @@ -20,15 +20,15 @@ .hash algorithm 0x00008004 .ver 0:0:0:0 } -.module pryqrprl.dll -// MVID: {FFEEBB9C-152A-467A-A4B4-51CF03878E20} +.module wn5i3ung.dll +// MVID: {DBA055A4-E95E-43C4-8BA9-D8F45F1AB075} .custom instance void [mscorlib]System.Security.UnverifiableCodeAttribute::.ctor() = ( 01 00 00 00 ) .imagebase 0x10000000 .file alignment 0x00000200 .stackreserve 0x00100000 .subsystem 0x0003 // WINDOWS_CUI .corflags 0x00000001 // ILONLY -// Image base: 0x00B70000 +// Image base: 0x00AB0000 // =============== CLASS MEMBERS DECLARATION =================== @@ -749,7 +749,7 @@ IL_0013: brfalse IL_00db IL_0018: volatile. - IL_001a: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{FFEEBB9C-152A-467A-A4B4-51CF03878E20}'::'$$method0x600000d-1' + IL_001a: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{DBA055A4-E95E-43C4-8BA9-D8F45F1AB075}'::'$$method0x600000d-1' IL_001f: brtrue.s IL_0082 IL_0021: ldc.i4.7 @@ -790,9 +790,9 @@ IL_0076: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2::Add(!0, !1) IL_007b: volatile. - IL_007d: stsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{FFEEBB9C-152A-467A-A4B4-51CF03878E20}'::'$$method0x600000d-1' + IL_007d: stsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{DBA055A4-E95E-43C4-8BA9-D8F45F1AB075}'::'$$method0x600000d-1' IL_0082: volatile. - IL_0084: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{FFEEBB9C-152A-467A-A4B4-51CF03878E20}'::'$$method0x600000d-1' + IL_0084: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{DBA055A4-E95E-43C4-8BA9-D8F45F1AB075}'::'$$method0x600000d-1' IL_0089: ldloc.0 IL_008a: ldloca.s V_1 IL_008c: call instance bool class [mscorlib]System.Collections.Generic.Dictionary`2::TryGetValue(!0, @@ -850,7 +850,7 @@ IL_0011: brfalse IL_013d IL_0016: volatile. - IL_0018: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{FFEEBB9C-152A-467A-A4B4-51CF03878E20}'::'$$method0x600000e-1' + IL_0018: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{DBA055A4-E95E-43C4-8BA9-D8F45F1AB075}'::'$$method0x600000e-1' IL_001d: brtrue IL_00b6 IL_0022: ldc.i4.s 11 @@ -911,9 +911,9 @@ IL_00aa: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2::Add(!0, !1) IL_00af: volatile. - IL_00b1: stsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{FFEEBB9C-152A-467A-A4B4-51CF03878E20}'::'$$method0x600000e-1' + IL_00b1: stsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{DBA055A4-E95E-43C4-8BA9-D8F45F1AB075}'::'$$method0x600000e-1' IL_00b6: volatile. - IL_00b8: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{FFEEBB9C-152A-467A-A4B4-51CF03878E20}'::'$$method0x600000e-1' + IL_00b8: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{DBA055A4-E95E-43C4-8BA9-D8F45F1AB075}'::'$$method0x600000e-1' IL_00bd: ldloc.0 IL_00be: ldloca.s V_1 IL_00c0: call instance bool class [mscorlib]System.Collections.Generic.Dictionary`2::TryGetValue(!0, @@ -1106,7 +1106,7 @@ .method public hidebysig static void SwitchOnStringInForLoop() cil managed { - // Code size 299 (0x12b) + // Code size 309 (0x135) .maxstack 4 .locals init (class [mscorlib]System.Collections.Generic.List`1 V_0, class [mscorlib]System.Collections.Generic.List`1 V_1, @@ -1123,126 +1123,128 @@ IL_0011: stloc.2 IL_0012: ldc.i4.0 IL_0013: stloc.3 - IL_0014: br IL_0121 - - IL_0019: ldloc.2 - IL_001a: ldloc.3 - IL_001b: ldelem.ref - IL_001c: stloc.s V_4 - IL_001e: ldloc.s V_4 - IL_0020: ldfld class [mscorlib]System.Reflection.PropertyInfo ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/SetProperty::Property - IL_0025: callvirt instance string [mscorlib]System.Reflection.MemberInfo::get_Name() - IL_002a: dup - IL_002b: stloc.s V_5 - IL_002d: brfalse IL_0115 - - IL_0032: volatile. - IL_0034: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{FFEEBB9C-152A-467A-A4B4-51CF03878E20}'::'$$method0x6000013-1' - IL_0039: brtrue.s IL_0090 - - IL_003b: ldc.i4.6 - IL_003c: newobj instance void class [mscorlib]System.Collections.Generic.Dictionary`2::.ctor(int32) - IL_0041: dup - IL_0042: ldstr "Name1" - IL_0047: ldc.i4.0 - IL_0048: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2::Add(!0, + IL_0014: br IL_012b + + IL_0019: ldstr "In for-loop" + IL_001e: call void [mscorlib]System.Console::WriteLine(string) + IL_0023: ldloc.2 + IL_0024: ldloc.3 + IL_0025: ldelem.ref + IL_0026: stloc.s V_4 + IL_0028: ldloc.s V_4 + IL_002a: ldfld class [mscorlib]System.Reflection.PropertyInfo ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/SetProperty::Property + IL_002f: callvirt instance string [mscorlib]System.Reflection.MemberInfo::get_Name() + IL_0034: dup + IL_0035: stloc.s V_5 + IL_0037: brfalse IL_011f + + IL_003c: volatile. + IL_003e: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{DBA055A4-E95E-43C4-8BA9-D8F45F1AB075}'::'$$method0x6000013-1' + IL_0043: brtrue.s IL_009a + + IL_0045: ldc.i4.6 + IL_0046: newobj instance void class [mscorlib]System.Collections.Generic.Dictionary`2::.ctor(int32) + IL_004b: dup + IL_004c: ldstr "Name1" + IL_0051: ldc.i4.0 + IL_0052: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2::Add(!0, !1) - IL_004d: dup - IL_004e: ldstr "Name2" - IL_0053: ldc.i4.1 - IL_0054: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2::Add(!0, + IL_0057: dup + IL_0058: ldstr "Name2" + IL_005d: ldc.i4.1 + IL_005e: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2::Add(!0, !1) - IL_0059: dup - IL_005a: ldstr "Name3" - IL_005f: ldc.i4.2 - IL_0060: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2::Add(!0, + IL_0063: dup + IL_0064: ldstr "Name3" + IL_0069: ldc.i4.2 + IL_006a: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2::Add(!0, !1) - IL_0065: dup - IL_0066: ldstr "Name4" - IL_006b: ldc.i4.3 - IL_006c: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2::Add(!0, + IL_006f: dup + IL_0070: ldstr "Name4" + IL_0075: ldc.i4.3 + IL_0076: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2::Add(!0, !1) - IL_0071: dup - IL_0072: ldstr "Name5" - IL_0077: ldc.i4.4 - IL_0078: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2::Add(!0, + IL_007b: dup + IL_007c: ldstr "Name5" + IL_0081: ldc.i4.4 + IL_0082: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2::Add(!0, !1) - IL_007d: dup - IL_007e: ldstr "Name6" - IL_0083: ldc.i4.5 - IL_0084: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2::Add(!0, + IL_0087: dup + IL_0088: ldstr "Name6" + IL_008d: ldc.i4.5 + IL_008e: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2::Add(!0, !1) - IL_0089: volatile. - IL_008b: stsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{FFEEBB9C-152A-467A-A4B4-51CF03878E20}'::'$$method0x6000013-1' - IL_0090: volatile. - IL_0092: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{FFEEBB9C-152A-467A-A4B4-51CF03878E20}'::'$$method0x6000013-1' - IL_0097: ldloc.s V_5 - IL_0099: ldloca.s V_6 - IL_009b: call instance bool class [mscorlib]System.Collections.Generic.Dictionary`2::TryGetValue(!0, + IL_0093: volatile. + IL_0095: stsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{DBA055A4-E95E-43C4-8BA9-D8F45F1AB075}'::'$$method0x6000013-1' + IL_009a: volatile. + IL_009c: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{DBA055A4-E95E-43C4-8BA9-D8F45F1AB075}'::'$$method0x6000013-1' + IL_00a1: ldloc.s V_5 + IL_00a3: ldloca.s V_6 + IL_00a5: call instance bool class [mscorlib]System.Collections.Generic.Dictionary`2::TryGetValue(!0, !1&) - IL_00a0: brfalse.s IL_0115 - - IL_00a2: ldloc.s V_6 - IL_00a4: switch ( - IL_00c3, - IL_00d5, - IL_00e7, - IL_00f9, - IL_010b, - IL_010b) - IL_00c1: br.s IL_0115 - - IL_00c3: ldloc.s V_4 - IL_00c5: ldc.i4.1 - IL_00c6: callvirt instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/SetProperty::set_Set(int32) - IL_00cb: ldloc.0 - IL_00cc: ldloc.s V_4 - IL_00ce: callvirt instance void class [mscorlib]System.Collections.Generic.List`1::Add(!0) - IL_00d3: br.s IL_011d - - IL_00d5: ldloc.s V_4 - IL_00d7: ldc.i4.2 - IL_00d8: callvirt instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/SetProperty::set_Set(int32) - IL_00dd: ldloc.0 - IL_00de: ldloc.s V_4 - IL_00e0: callvirt instance void class [mscorlib]System.Collections.Generic.List`1::Add(!0) - IL_00e5: br.s IL_011d - - IL_00e7: ldloc.s V_4 - IL_00e9: ldc.i4.3 - IL_00ea: callvirt instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/SetProperty::set_Set(int32) - IL_00ef: ldloc.0 - IL_00f0: ldloc.s V_4 - IL_00f2: callvirt instance void class [mscorlib]System.Collections.Generic.List`1::Add(!0) - IL_00f7: br.s IL_011d - - IL_00f9: ldloc.s V_4 - IL_00fb: ldc.i4.4 - IL_00fc: callvirt instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/SetProperty::set_Set(int32) - IL_0101: ldloc.0 - IL_0102: ldloc.s V_4 - IL_0104: callvirt instance void class [mscorlib]System.Collections.Generic.List`1::Add(!0) - IL_0109: br.s IL_011d - + IL_00aa: brfalse.s IL_011f + + IL_00ac: ldloc.s V_6 + IL_00ae: switch ( + IL_00cd, + IL_00df, + IL_00f1, + IL_0103, + IL_0115, + IL_0115) + IL_00cb: br.s IL_011f + + IL_00cd: ldloc.s V_4 + IL_00cf: ldc.i4.1 + IL_00d0: callvirt instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/SetProperty::set_Set(int32) + IL_00d5: ldloc.0 + IL_00d6: ldloc.s V_4 + IL_00d8: callvirt instance void class [mscorlib]System.Collections.Generic.List`1::Add(!0) + IL_00dd: br.s IL_0127 + + IL_00df: ldloc.s V_4 + IL_00e1: ldc.i4.2 + IL_00e2: callvirt instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/SetProperty::set_Set(int32) + IL_00e7: ldloc.0 + IL_00e8: ldloc.s V_4 + IL_00ea: callvirt instance void class [mscorlib]System.Collections.Generic.List`1::Add(!0) + IL_00ef: br.s IL_0127 + + IL_00f1: ldloc.s V_4 + IL_00f3: ldc.i4.3 + IL_00f4: callvirt instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/SetProperty::set_Set(int32) + IL_00f9: ldloc.0 + IL_00fa: ldloc.s V_4 + IL_00fc: callvirt instance void class [mscorlib]System.Collections.Generic.List`1::Add(!0) + IL_0101: br.s IL_0127 + + IL_0103: ldloc.s V_4 + IL_0105: ldc.i4.4 + IL_0106: callvirt instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/SetProperty::set_Set(int32) IL_010b: ldloc.0 IL_010c: ldloc.s V_4 IL_010e: callvirt instance void class [mscorlib]System.Collections.Generic.List`1::Add(!0) - IL_0113: br.s IL_011d + IL_0113: br.s IL_0127 - IL_0115: ldloc.1 + IL_0115: ldloc.0 IL_0116: ldloc.s V_4 IL_0118: callvirt instance void class [mscorlib]System.Collections.Generic.List`1::Add(!0) - IL_011d: ldloc.3 - IL_011e: ldc.i4.1 - IL_011f: add - IL_0120: stloc.3 - IL_0121: ldloc.3 - IL_0122: ldloc.2 - IL_0123: ldlen - IL_0124: conv.i4 - IL_0125: blt IL_0019 - - IL_012a: ret + IL_011d: br.s IL_0127 + + IL_011f: ldloc.1 + IL_0120: ldloc.s V_4 + IL_0122: callvirt instance void class [mscorlib]System.Collections.Generic.List`1::Add(!0) + IL_0127: ldloc.3 + IL_0128: ldc.i4.1 + IL_0129: add + IL_012a: stloc.3 + IL_012b: ldloc.3 + IL_012c: ldloc.2 + IL_012d: ldlen + IL_012e: conv.i4 + IL_012f: blt IL_0019 + + IL_0134: ret } // end of method Switch::SwitchOnStringInForLoop .method public hidebysig static void SwitchWithComplexCondition(string[] args) cil managed @@ -1369,14 +1371,14 @@ } // end of class ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch -.class private auto ansi '{FFEEBB9C-152A-467A-A4B4-51CF03878E20}' +.class private auto ansi '{DBA055A4-E95E-43C4-8BA9-D8F45F1AB075}' extends [mscorlib]System.Object { .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) .field static assembly class [mscorlib]System.Collections.Generic.Dictionary`2 '$$method0x600000d-1' .field static assembly class [mscorlib]System.Collections.Generic.Dictionary`2 '$$method0x600000e-1' .field static assembly class [mscorlib]System.Collections.Generic.Dictionary`2 '$$method0x6000013-1' -} // end of class '{FFEEBB9C-152A-467A-A4B4-51CF03878E20}' +} // end of class '{DBA055A4-E95E-43C4-8BA9-D8F45F1AB075}' // ============================================================= diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.opt.roslyn.il b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.opt.roslyn.il index c2c1f5cae..9de091f62 100644 --- a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.opt.roslyn.il +++ b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.opt.roslyn.il @@ -25,14 +25,14 @@ .ver 0:0:0:0 } .module Switch.dll -// MVID: {5D628BA5-FC59-43EC-A162-63729510F134} +// MVID: {3AC777A3-6335-478F-868C-4297490D6D49} .custom instance void [mscorlib]System.Security.UnverifiableCodeAttribute::.ctor() = ( 01 00 00 00 ) .imagebase 0x10000000 .file alignment 0x00000200 .stackreserve 0x00100000 .subsystem 0x0003 // WINDOWS_CUI .corflags 0x00000001 // ILONLY -// Image base: 0x01390000 +// Image base: 0x01380000 // =============== CLASS MEMBERS DECLARATION =================== @@ -1219,7 +1219,7 @@ .method public hidebysig static void SwitchOnStringInForLoop() cil managed { - // Code size 234 (0xea) + // Code size 244 (0xf4) .maxstack 2 .locals init (class [mscorlib]System.Collections.Generic.List`1 V_0, class [mscorlib]System.Collections.Generic.List`1 V_1, @@ -1235,105 +1235,107 @@ IL_0011: stloc.2 IL_0012: ldc.i4.0 IL_0013: stloc.3 - IL_0014: br IL_00e0 - - IL_0019: ldloc.2 - IL_001a: ldloc.3 - IL_001b: ldelem.ref - IL_001c: stloc.s V_4 - IL_001e: ldloc.s V_4 - IL_0020: ldfld class [mscorlib]System.Reflection.PropertyInfo ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/SetProperty::Property - IL_0025: callvirt instance string [mscorlib]System.Reflection.MemberInfo::get_Name() - IL_002a: stloc.s V_5 - IL_002c: ldloc.s V_5 - IL_002e: ldstr "Name1" - IL_0033: call bool [mscorlib]System.String::op_Equality(string, + IL_0014: br IL_00ea + + IL_0019: ldstr "In for-loop" + IL_001e: call void [mscorlib]System.Console::WriteLine(string) + IL_0023: ldloc.2 + IL_0024: ldloc.3 + IL_0025: ldelem.ref + IL_0026: stloc.s V_4 + IL_0028: ldloc.s V_4 + IL_002a: ldfld class [mscorlib]System.Reflection.PropertyInfo ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/SetProperty::Property + IL_002f: callvirt instance string [mscorlib]System.Reflection.MemberInfo::get_Name() + IL_0034: stloc.s V_5 + IL_0036: ldloc.s V_5 + IL_0038: ldstr "Name1" + IL_003d: call bool [mscorlib]System.String::op_Equality(string, string) - IL_0038: brtrue.s IL_0082 + IL_0042: brtrue.s IL_008c - IL_003a: ldloc.s V_5 - IL_003c: ldstr "Name2" - IL_0041: call bool [mscorlib]System.String::op_Equality(string, + IL_0044: ldloc.s V_5 + IL_0046: ldstr "Name2" + IL_004b: call bool [mscorlib]System.String::op_Equality(string, string) - IL_0046: brtrue.s IL_0094 + IL_0050: brtrue.s IL_009e - IL_0048: ldloc.s V_5 - IL_004a: ldstr "Name3" - IL_004f: call bool [mscorlib]System.String::op_Equality(string, + IL_0052: ldloc.s V_5 + IL_0054: ldstr "Name3" + IL_0059: call bool [mscorlib]System.String::op_Equality(string, string) - IL_0054: brtrue.s IL_00a6 + IL_005e: brtrue.s IL_00b0 - IL_0056: ldloc.s V_5 - IL_0058: ldstr "Name4" - IL_005d: call bool [mscorlib]System.String::op_Equality(string, + IL_0060: ldloc.s V_5 + IL_0062: ldstr "Name4" + IL_0067: call bool [mscorlib]System.String::op_Equality(string, string) - IL_0062: brtrue.s IL_00b8 + IL_006c: brtrue.s IL_00c2 - IL_0064: ldloc.s V_5 - IL_0066: ldstr "Name5" - IL_006b: call bool [mscorlib]System.String::op_Equality(string, + IL_006e: ldloc.s V_5 + IL_0070: ldstr "Name5" + IL_0075: call bool [mscorlib]System.String::op_Equality(string, string) - IL_0070: brtrue.s IL_00ca + IL_007a: brtrue.s IL_00d4 - IL_0072: ldloc.s V_5 - IL_0074: ldstr "Name6" - IL_0079: call bool [mscorlib]System.String::op_Equality(string, + IL_007c: ldloc.s V_5 + IL_007e: ldstr "Name6" + IL_0083: call bool [mscorlib]System.String::op_Equality(string, string) - IL_007e: brtrue.s IL_00ca - - IL_0080: br.s IL_00d4 - - IL_0082: ldloc.s V_4 - IL_0084: ldc.i4.1 - IL_0085: callvirt instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/SetProperty::set_Set(int32) - IL_008a: ldloc.0 - IL_008b: ldloc.s V_4 - IL_008d: callvirt instance void class [mscorlib]System.Collections.Generic.List`1::Add(!0) - IL_0092: br.s IL_00dc - - IL_0094: ldloc.s V_4 - IL_0096: ldc.i4.2 - IL_0097: callvirt instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/SetProperty::set_Set(int32) - IL_009c: ldloc.0 - IL_009d: ldloc.s V_4 - IL_009f: callvirt instance void class [mscorlib]System.Collections.Generic.List`1::Add(!0) - IL_00a4: br.s IL_00dc - - IL_00a6: ldloc.s V_4 - IL_00a8: ldc.i4.3 - IL_00a9: callvirt instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/SetProperty::set_Set(int32) - IL_00ae: ldloc.0 - IL_00af: ldloc.s V_4 - IL_00b1: callvirt instance void class [mscorlib]System.Collections.Generic.List`1::Add(!0) - IL_00b6: br.s IL_00dc - - IL_00b8: ldloc.s V_4 - IL_00ba: ldc.i4.4 - IL_00bb: callvirt instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/SetProperty::set_Set(int32) - IL_00c0: ldloc.0 - IL_00c1: ldloc.s V_4 - IL_00c3: callvirt instance void class [mscorlib]System.Collections.Generic.List`1::Add(!0) - IL_00c8: br.s IL_00dc - + IL_0088: brtrue.s IL_00d4 + + IL_008a: br.s IL_00de + + IL_008c: ldloc.s V_4 + IL_008e: ldc.i4.1 + IL_008f: callvirt instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/SetProperty::set_Set(int32) + IL_0094: ldloc.0 + IL_0095: ldloc.s V_4 + IL_0097: callvirt instance void class [mscorlib]System.Collections.Generic.List`1::Add(!0) + IL_009c: br.s IL_00e6 + + IL_009e: ldloc.s V_4 + IL_00a0: ldc.i4.2 + IL_00a1: callvirt instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/SetProperty::set_Set(int32) + IL_00a6: ldloc.0 + IL_00a7: ldloc.s V_4 + IL_00a9: callvirt instance void class [mscorlib]System.Collections.Generic.List`1::Add(!0) + IL_00ae: br.s IL_00e6 + + IL_00b0: ldloc.s V_4 + IL_00b2: ldc.i4.3 + IL_00b3: callvirt instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/SetProperty::set_Set(int32) + IL_00b8: ldloc.0 + IL_00b9: ldloc.s V_4 + IL_00bb: callvirt instance void class [mscorlib]System.Collections.Generic.List`1::Add(!0) + IL_00c0: br.s IL_00e6 + + IL_00c2: ldloc.s V_4 + IL_00c4: ldc.i4.4 + IL_00c5: callvirt instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/SetProperty::set_Set(int32) IL_00ca: ldloc.0 IL_00cb: ldloc.s V_4 IL_00cd: callvirt instance void class [mscorlib]System.Collections.Generic.List`1::Add(!0) - IL_00d2: br.s IL_00dc + IL_00d2: br.s IL_00e6 - IL_00d4: ldloc.1 + IL_00d4: ldloc.0 IL_00d5: ldloc.s V_4 IL_00d7: callvirt instance void class [mscorlib]System.Collections.Generic.List`1::Add(!0) - IL_00dc: ldloc.3 - IL_00dd: ldc.i4.1 - IL_00de: add - IL_00df: stloc.3 - IL_00e0: ldloc.3 - IL_00e1: ldloc.2 - IL_00e2: ldlen - IL_00e3: conv.i4 - IL_00e4: blt IL_0019 - - IL_00e9: ret + IL_00dc: br.s IL_00e6 + + IL_00de: ldloc.1 + IL_00df: ldloc.s V_4 + IL_00e1: callvirt instance void class [mscorlib]System.Collections.Generic.List`1::Add(!0) + IL_00e6: ldloc.3 + IL_00e7: ldc.i4.1 + IL_00e8: add + IL_00e9: stloc.3 + IL_00ea: ldloc.3 + IL_00eb: ldloc.2 + IL_00ec: ldlen + IL_00ed: conv.i4 + IL_00ee: blt IL_0019 + + IL_00f3: ret } // end of method Switch::SwitchOnStringInForLoop .method public hidebysig static void SwitchWithComplexCondition(string[] args) cil managed diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.roslyn.il b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.roslyn.il index ea25c483e..aa0d6cada 100644 --- a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.roslyn.il +++ b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.roslyn.il @@ -25,14 +25,14 @@ .ver 0:0:0:0 } .module Switch.dll -// MVID: {EF7D776C-0F54-445C-8A74-2D49ADE35F46} +// MVID: {02FDDCA9-8509-4A55-A2B4-ECC54A6801AF} .custom instance void [mscorlib]System.Security.UnverifiableCodeAttribute::.ctor() = ( 01 00 00 00 ) .imagebase 0x10000000 .file alignment 0x00000200 .stackreserve 0x00100000 .subsystem 0x0003 // WINDOWS_CUI .corflags 0x00000001 // ILONLY -// Image base: 0x00C40000 +// Image base: 0x02460000 // =============== CLASS MEMBERS DECLARATION =================== @@ -1533,7 +1533,7 @@ .method public hidebysig static void SwitchOnStringInForLoop() cil managed { - // Code size 255 (0xff) + // Code size 266 (0x10a) .maxstack 2 .locals init (class [mscorlib]System.Collections.Generic.List`1 V_0, class [mscorlib]System.Collections.Generic.List`1 V_1, @@ -1551,122 +1551,125 @@ IL_0012: stloc.2 IL_0013: ldc.i4.0 IL_0014: stloc.3 - IL_0015: br IL_00ef + IL_0015: br IL_00fa IL_001a: nop - IL_001b: ldloc.2 - IL_001c: ldloc.3 - IL_001d: ldelem.ref - IL_001e: stloc.s V_4 - IL_0020: ldloc.s V_4 - IL_0022: ldfld class [mscorlib]System.Reflection.PropertyInfo ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/SetProperty::Property - IL_0027: callvirt instance string [mscorlib]System.Reflection.MemberInfo::get_Name() - IL_002c: stloc.s V_5 - IL_002e: ldloc.s V_5 - IL_0030: ldstr "Name1" - IL_0035: call bool [mscorlib]System.String::op_Equality(string, + IL_001b: ldstr "In for-loop" + IL_0020: call void [mscorlib]System.Console::WriteLine(string) + IL_0025: nop + IL_0026: ldloc.2 + IL_0027: ldloc.3 + IL_0028: ldelem.ref + IL_0029: stloc.s V_4 + IL_002b: ldloc.s V_4 + IL_002d: ldfld class [mscorlib]System.Reflection.PropertyInfo ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/SetProperty::Property + IL_0032: callvirt instance string [mscorlib]System.Reflection.MemberInfo::get_Name() + IL_0037: stloc.s V_5 + IL_0039: ldloc.s V_5 + IL_003b: ldstr "Name1" + IL_0040: call bool [mscorlib]System.String::op_Equality(string, string) - IL_003a: brtrue.s IL_0084 + IL_0045: brtrue.s IL_008f - IL_003c: ldloc.s V_5 - IL_003e: ldstr "Name2" - IL_0043: call bool [mscorlib]System.String::op_Equality(string, + IL_0047: ldloc.s V_5 + IL_0049: ldstr "Name2" + IL_004e: call bool [mscorlib]System.String::op_Equality(string, string) - IL_0048: brtrue.s IL_0098 + IL_0053: brtrue.s IL_00a3 - IL_004a: ldloc.s V_5 - IL_004c: ldstr "Name3" - IL_0051: call bool [mscorlib]System.String::op_Equality(string, + IL_0055: ldloc.s V_5 + IL_0057: ldstr "Name3" + IL_005c: call bool [mscorlib]System.String::op_Equality(string, string) - IL_0056: brtrue.s IL_00ac + IL_0061: brtrue.s IL_00b7 - IL_0058: ldloc.s V_5 - IL_005a: ldstr "Name4" - IL_005f: call bool [mscorlib]System.String::op_Equality(string, + IL_0063: ldloc.s V_5 + IL_0065: ldstr "Name4" + IL_006a: call bool [mscorlib]System.String::op_Equality(string, string) - IL_0064: brtrue.s IL_00c0 + IL_006f: brtrue.s IL_00cb - IL_0066: ldloc.s V_5 - IL_0068: ldstr "Name5" - IL_006d: call bool [mscorlib]System.String::op_Equality(string, + IL_0071: ldloc.s V_5 + IL_0073: ldstr "Name5" + IL_0078: call bool [mscorlib]System.String::op_Equality(string, string) - IL_0072: brtrue.s IL_00d4 + IL_007d: brtrue.s IL_00df - IL_0074: ldloc.s V_5 - IL_0076: ldstr "Name6" - IL_007b: call bool [mscorlib]System.String::op_Equality(string, + IL_007f: ldloc.s V_5 + IL_0081: ldstr "Name6" + IL_0086: call bool [mscorlib]System.String::op_Equality(string, string) - IL_0080: brtrue.s IL_00d4 - - IL_0082: br.s IL_00df - - IL_0084: ldloc.s V_4 - IL_0086: ldc.i4.1 - IL_0087: callvirt instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/SetProperty::set_Set(int32) - IL_008c: nop - IL_008d: ldloc.0 - IL_008e: ldloc.s V_4 - IL_0090: callvirt instance void class [mscorlib]System.Collections.Generic.List`1::Add(!0) - IL_0095: nop - IL_0096: br.s IL_00ea - - IL_0098: ldloc.s V_4 - IL_009a: ldc.i4.2 - IL_009b: callvirt instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/SetProperty::set_Set(int32) + IL_008b: brtrue.s IL_00df + + IL_008d: br.s IL_00ea + + IL_008f: ldloc.s V_4 + IL_0091: ldc.i4.1 + IL_0092: callvirt instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/SetProperty::set_Set(int32) + IL_0097: nop + IL_0098: ldloc.0 + IL_0099: ldloc.s V_4 + IL_009b: callvirt instance void class [mscorlib]System.Collections.Generic.List`1::Add(!0) IL_00a0: nop - IL_00a1: ldloc.0 - IL_00a2: ldloc.s V_4 - IL_00a4: callvirt instance void class [mscorlib]System.Collections.Generic.List`1::Add(!0) - IL_00a9: nop - IL_00aa: br.s IL_00ea - - IL_00ac: ldloc.s V_4 - IL_00ae: ldc.i4.3 - IL_00af: callvirt instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/SetProperty::set_Set(int32) + IL_00a1: br.s IL_00f5 + + IL_00a3: ldloc.s V_4 + IL_00a5: ldc.i4.2 + IL_00a6: callvirt instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/SetProperty::set_Set(int32) + IL_00ab: nop + IL_00ac: ldloc.0 + IL_00ad: ldloc.s V_4 + IL_00af: callvirt instance void class [mscorlib]System.Collections.Generic.List`1::Add(!0) IL_00b4: nop - IL_00b5: ldloc.0 - IL_00b6: ldloc.s V_4 - IL_00b8: callvirt instance void class [mscorlib]System.Collections.Generic.List`1::Add(!0) - IL_00bd: nop - IL_00be: br.s IL_00ea - - IL_00c0: ldloc.s V_4 - IL_00c2: ldc.i4.4 - IL_00c3: callvirt instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/SetProperty::set_Set(int32) + IL_00b5: br.s IL_00f5 + + IL_00b7: ldloc.s V_4 + IL_00b9: ldc.i4.3 + IL_00ba: callvirt instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/SetProperty::set_Set(int32) + IL_00bf: nop + IL_00c0: ldloc.0 + IL_00c1: ldloc.s V_4 + IL_00c3: callvirt instance void class [mscorlib]System.Collections.Generic.List`1::Add(!0) IL_00c8: nop - IL_00c9: ldloc.0 - IL_00ca: ldloc.s V_4 - IL_00cc: callvirt instance void class [mscorlib]System.Collections.Generic.List`1::Add(!0) - IL_00d1: nop - IL_00d2: br.s IL_00ea + IL_00c9: br.s IL_00f5 + IL_00cb: ldloc.s V_4 + IL_00cd: ldc.i4.4 + IL_00ce: callvirt instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/SetProperty::set_Set(int32) + IL_00d3: nop IL_00d4: ldloc.0 IL_00d5: ldloc.s V_4 IL_00d7: callvirt instance void class [mscorlib]System.Collections.Generic.List`1::Add(!0) IL_00dc: nop - IL_00dd: br.s IL_00ea + IL_00dd: br.s IL_00f5 - IL_00df: ldloc.1 + IL_00df: ldloc.0 IL_00e0: ldloc.s V_4 IL_00e2: callvirt instance void class [mscorlib]System.Collections.Generic.List`1::Add(!0) IL_00e7: nop - IL_00e8: br.s IL_00ea - - IL_00ea: nop - IL_00eb: ldloc.3 - IL_00ec: ldc.i4.1 - IL_00ed: add - IL_00ee: stloc.3 - IL_00ef: ldloc.3 - IL_00f0: ldloc.2 - IL_00f1: ldlen - IL_00f2: conv.i4 - IL_00f3: clt - IL_00f5: stloc.s V_6 - IL_00f7: ldloc.s V_6 - IL_00f9: brtrue IL_001a - - IL_00fe: ret + IL_00e8: br.s IL_00f5 + + IL_00ea: ldloc.1 + IL_00eb: ldloc.s V_4 + IL_00ed: callvirt instance void class [mscorlib]System.Collections.Generic.List`1::Add(!0) + IL_00f2: nop + IL_00f3: br.s IL_00f5 + + IL_00f5: nop + IL_00f6: ldloc.3 + IL_00f7: ldc.i4.1 + IL_00f8: add + IL_00f9: stloc.3 + IL_00fa: ldloc.3 + IL_00fb: ldloc.2 + IL_00fc: ldlen + IL_00fd: conv.i4 + IL_00fe: clt + IL_0100: stloc.s V_6 + IL_0102: ldloc.s V_6 + IL_0104: brtrue IL_001a + + IL_0109: ret } // end of method Switch::SwitchOnStringInForLoop .method public hidebysig static void SwitchWithComplexCondition(string[] args) cil managed diff --git a/ICSharpCode.Decompiler/CSharp/Transforms/PatternStatementTransform.cs b/ICSharpCode.Decompiler/CSharp/Transforms/PatternStatementTransform.cs index a8e29430e..10ad3be3d 100644 --- a/ICSharpCode.Decompiler/CSharp/Transforms/PatternStatementTransform.cs +++ b/ICSharpCode.Decompiler/CSharp/Transforms/PatternStatementTransform.cs @@ -72,8 +72,7 @@ namespace ICSharpCode.Decompiler.CSharp.Transforms public override AstNode VisitExpressionStatement(ExpressionStatement expressionStatement) { - AstNode result; - result = TransformFor(expressionStatement); + AstNode result = TransformFor(expressionStatement); if (result != null) return result; if (context.Settings.AutomaticProperties) { @@ -88,12 +87,20 @@ namespace ICSharpCode.Decompiler.CSharp.Transforms } return base.VisitExpressionStatement(expressionStatement); } - + + public override AstNode VisitForStatement(ForStatement forStatement) + { + AstNode result = TransformForeachOnArray(forStatement); + if (result != null) + return result; + return base.VisitForStatement(forStatement); + } + public override AstNode VisitWhileStatement(WhileStatement whileStatement) { return TransformDoWhile(whileStatement) ?? base.VisitWhileStatement(whileStatement); } - + public override AstNode VisitIfElseStatement(IfElseStatement ifElseStatement) { AstNode simplifiedIfElse = SimplifyCascadingIfElseStatements(ifElseStatement); @@ -203,7 +210,70 @@ namespace ICSharpCode.Decompiler.CSharp.Transforms return forStatement; } #endregion - + + #region foreach + + static readonly ForStatement forOnArrayPattern = new ForStatement { + Initializers = { + new ExpressionStatement( + new AssignmentExpression( + new NamedNode("indexVariable", new IdentifierExpression(Pattern.AnyString)), + new PrimitiveExpression(0) + )) + }, + Condition = new BinaryOperatorExpression( + new IdentifierExpressionBackreference("indexVariable"), + BinaryOperatorType.LessThan, + new MemberReferenceExpression(new NamedNode("arrayVariable", new IdentifierExpression(Pattern.AnyString)), "Length") + ), + Iterators = { + new ExpressionStatement( + new AssignmentExpression( + new IdentifierExpressionBackreference("indexVariable"), + new BinaryOperatorExpression(new IdentifierExpressionBackreference("indexVariable"), BinaryOperatorType.Add, new PrimitiveExpression(1)) + )) + }, + EmbeddedStatement = new BlockStatement { + Statements = { + new ExpressionStatement(new AssignmentExpression( + new NamedNode("itemVariable", new IdentifierExpression(Pattern.AnyString)), + new IndexerExpression(new IdentifierExpressionBackreference("arrayVariable"), new IdentifierExpressionBackreference("indexVariable")) + )), + new Repeat(new AnyNode("statements")) + } + } + }; + + Statement TransformForeachOnArray(ForStatement forStatement) + { + Match m = forOnArrayPattern.Match(forStatement); + if (!m.Success) return null; + var itemVariable = m.Get("itemVariable").Single().GetILVariable(); + var indexVariable = m.Get("indexVariable").Single().GetILVariable(); + var arrayVariable = m.Get("arrayVariable").Single().GetILVariable(); + if (!itemVariable.IsSingleDefinition) + return null; + if (indexVariable.StoreCount != 2 || indexVariable.LoadCount != 3 || indexVariable.AddressCount != 0) + return null; + var body = new BlockStatement(); + foreach (var statement in m.Get("statements")) + body.Statements.Add(statement.Detach()); + var foreachStmt = new ForeachStatement { + VariableType = context.Settings.AnonymousTypes && itemVariable.Type.ContainsAnonymousType() ? new SimpleType("var") : context.TypeSystemAstBuilder.ConvertType(itemVariable.Type), + VariableName = itemVariable.Name, + InExpression = m.Get("arrayVariable").Single().Detach(), + EmbeddedStatement = body + }; + itemVariable.Kind = IL.VariableKind.ForeachLocal; + // Add the variable annotation for highlighting (TokenTextWriter expects it directly on the ForeachStatement). + foreachStmt.AddAnnotation(new ILVariableResolveResult(itemVariable, itemVariable.Type)); + // TODO : add ForeachAnnotation + forStatement.ReplaceWith(foreachStmt); + return foreachStmt; + } + + #endregion + #region doWhile static readonly WhileStatement doWhilePattern = new WhileStatement { Condition = new PrimitiveExpression(true),