Browse Source

Fix #567: switch statement not properly decompile

pull/887/head
Siegfried Pammer 8 years ago
parent
commit
0fa58c3d53
  1. 256
      ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.cs
  2. 563
      ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.il
  3. 474
      ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.opt.il
  4. 419
      ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.opt.roslyn.il
  5. 533
      ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.roslyn.il
  6. 18
      ICSharpCode.Decompiler/IL/Transforms/SwitchOnStringTransform.cs

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

@ -17,11 +17,28 @@
// DEALINGS IN THE SOFTWARE. // DEALINGS IN THE SOFTWARE.
using System; using System;
using System.Collections.Generic;
using System.Reflection;
namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
{ {
public static class Switch public static class Switch
{ {
public class SetProperty
{
public readonly PropertyInfo Property;
public int Set {
get;
set;
}
public SetProperty(PropertyInfo property)
{
this.Property = property;
}
}
public static string SparseIntegerSwitch(int i) public static string SparseIntegerSwitch(int i)
{ {
Console.WriteLine("SparseIntegerSwitch: " + i); Console.WriteLine("SparseIntegerSwitch: " + i);
@ -65,83 +82,83 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
} }
} }
public static string SwitchOverNullableInt(int? i) //public static string SwitchOverNullableInt(int? i)
{ //{
switch (i) { // switch (i) {
case null: { // case null: {
return "null"; // return "null";
} // }
case 0: { // case 0: {
return "zero"; // return "zero";
} // }
case 5: { // case 5: {
return "five"; // return "five";
} // }
case 10: { // case 10: {
return "ten"; // return "ten";
} // }
default: { // default: {
return "large"; // return "large";
} // }
} // }
} //}
public static string SwitchOverNullableIntShifted(int? i) //public static string SwitchOverNullableIntShifted(int? i)
{ //{
switch (i + 5) { // switch (i + 5) {
case null: { // case null: {
return "null"; // return "null";
} // }
case 0: { // case 0: {
return "zero"; // return "zero";
} // }
case 5: { // case 5: {
return "five"; // return "five";
} // }
case 10: { // case 10: {
return "ten"; // return "ten";
} // }
default: { // default: {
return "large"; // return "large";
} // }
} // }
} //}
public static string SwitchOverNullableIntNoNullCase(int? i) //public static string SwitchOverNullableIntNoNullCase(int? i)
{ //{
switch (i) { // switch (i) {
case 0: { // case 0: {
return "zero"; // return "zero";
} // }
case 5: { // case 5: {
return "five"; // return "five";
} // }
case 10: { // case 10: {
return "ten"; // return "ten";
} // }
default: { // default: {
return "other"; // return "other";
} // }
} // }
} //}
public static string SwitchOverNullableIntNoNullCaseShifted(int? i) //public static string SwitchOverNullableIntNoNullCaseShifted(int? i)
{ //{
switch (i + 5) { // switch (i + 5) {
case 0: { // case 0: {
return "zero"; // return "zero";
} // }
case 5: { // case 5: {
return "five"; // return "five";
} // }
case 10: { // case 10: {
return "ten"; // return "ten";
} // }
default: { // default: {
return "other"; // return "other";
} // }
} // }
} //}
public static string ShortSwitchOverString(string text) public static string ShortSwitchOverString(string text)
{ {
@ -285,29 +302,76 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
} }
} }
public static void SwitchWithGoto(int i) //public static void SwitchWithGoto(int i)
//{
// Console.WriteLine("SwitchWithGoto: " + i);
// switch (i) {
// case 1: {
// Console.WriteLine("one");
// goto default;
// }
// case 2: {
// Console.WriteLine("two");
// goto case 3;
// }
// case 3: {
// Console.WriteLine("three");
// break;
// }
// case 4: {
// Console.WriteLine("four");
// return;
// }
// default: {
// Console.WriteLine("default");
// break;
// }
// }
//}
private static SetProperty[] GetProperties()
{ {
Console.WriteLine("SwitchWithGoto: " + i); return new SetProperty[0];
switch (i) { }
case 1: {
Console.WriteLine("one"); public static void SwitchOnStringInForLoop()
goto default; {
} List<SetProperty> list = new List<SetProperty>();
case 2: { List<SetProperty> list2 = new List<SetProperty>();
Console.WriteLine("two"); SetProperty[] properties = Switch.GetProperties();
goto case 3; for (int i = 0; i < properties.Length; i++) {
} SetProperty setProperty = properties[i];
case 3: { string name = setProperty.Property.Name;
Console.WriteLine("three"); switch (name) {
break; case "Name1": {
} setProperty.Set = 1;
case 4: { list.Add(setProperty);
Console.WriteLine("four"); break;
return; }
} case "Name2": {
default: { setProperty.Set = 2;
Console.WriteLine("default"); list.Add(setProperty);
break; break;
}
case "Name3": {
setProperty.Set = 3;
list.Add(setProperty);
break;
}
case "Name4": {
setProperty.Set = 4;
list.Add(setProperty);
break;
}
case "Name5":
case "Name6": {
list.Add(setProperty);
break;
}
default: {
list2.Add(setProperty);
break;
}
} }
} }
} }

563
ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.il

@ -10,25 +10,25 @@
.publickeytoken = (B7 7A 5C 56 19 34 E0 89 ) // .z\V.4.. .publickeytoken = (B7 7A 5C 56 19 34 E0 89 ) // .z\V.4..
.ver 4:0:0:0 .ver 4:0:0:0
} }
.assembly iuizqapl .assembly gn0oqkcb
{ {
.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 .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. 63 65 70 74 69 6F 6E 54 68 72 6F 77 73 01 ) // ceptionThrows.
.custom instance void [mscorlib]System.Runtime.CompilerServices.CompilationRelaxationsAttribute::.ctor(int32) = ( 01 00 08 00 00 00 00 00 )
.permissionset reqmin .permissionset reqmin
= {[mscorlib]System.Security.Permissions.SecurityPermissionAttribute = {property bool 'SkipVerification' = bool(true)}} = {[mscorlib]System.Security.Permissions.SecurityPermissionAttribute = {property bool 'SkipVerification' = bool(true)}}
.hash algorithm 0x00008004 .hash algorithm 0x00008004
.ver 0:0:0:0 .ver 0:0:0:0
} }
.module iuizqapl.dll .module gn0oqkcb.dll
// MVID: {207B14E2-2177-4CF2-8D8E-2CD85A17CF5C} // MVID: {D3E1C722-15E3-49C8-B86B-96413DA7BEEE}
.custom instance void [mscorlib]System.Security.UnverifiableCodeAttribute::.ctor() = ( 01 00 00 00 ) .custom instance void [mscorlib]System.Security.UnverifiableCodeAttribute::.ctor() = ( 01 00 00 00 )
.imagebase 0x10000000 .imagebase 0x10000000
.file alignment 0x00000200 .file alignment 0x00000200
.stackreserve 0x00100000 .stackreserve 0x00100000
.subsystem 0x0003 // WINDOWS_CUI .subsystem 0x0003 // WINDOWS_CUI
.corflags 0x00000001 // ILONLY .corflags 0x00000001 // ILONLY
// Image base: 0x027D0000 // Image base: 0x00C80000
// =============== CLASS MEMBERS DECLARATION =================== // =============== CLASS MEMBERS DECLARATION ===================
@ -36,6 +36,63 @@
.class public abstract auto ansi sealed beforefieldinit ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch .class public abstract auto ansi sealed beforefieldinit ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch
extends [mscorlib]System.Object extends [mscorlib]System.Object
{ {
.class auto ansi nested public beforefieldinit SetProperty
extends [mscorlib]System.Object
{
.field public initonly class [mscorlib]System.Reflection.PropertyInfo Property
.field private int32 '<Set>k__BackingField'
.custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 )
.method public hidebysig specialname
instance int32 get_Set() cil managed
{
.custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 )
// Code size 11 (0xb)
.maxstack 1
.locals init (int32 V_0)
IL_0000: ldarg.0
IL_0001: ldfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/SetProperty::'<Set>k__BackingField'
IL_0006: stloc.0
IL_0007: br.s IL_0009
IL_0009: ldloc.0
IL_000a: ret
} // end of method SetProperty::get_Set
.method public hidebysig specialname
instance void set_Set(int32 'value') cil managed
{
.custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 )
// Code size 8 (0x8)
.maxstack 8
IL_0000: ldarg.0
IL_0001: ldarg.1
IL_0002: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/SetProperty::'<Set>k__BackingField'
IL_0007: ret
} // end of method SetProperty::set_Set
.method public hidebysig specialname rtspecialname
instance void .ctor(class [mscorlib]System.Reflection.PropertyInfo 'property') cil managed
{
// Code size 17 (0x11)
.maxstack 8
IL_0000: ldarg.0
IL_0001: call instance void [mscorlib]System.Object::.ctor()
IL_0006: nop
IL_0007: nop
IL_0008: ldarg.0
IL_0009: ldarg.1
IL_000a: stfld class [mscorlib]System.Reflection.PropertyInfo ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/SetProperty::Property
IL_000f: nop
IL_0010: ret
} // end of method SetProperty::.ctor
.property instance int32 Set()
{
.get instance int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/SetProperty::get_Set()
.set instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/SetProperty::set_Set(int32)
} // end of property SetProperty::Set
} // end of class SetProperty
.method public hidebysig static string .method public hidebysig static string
SparseIntegerSwitch(int32 i) cil managed SparseIntegerSwitch(int32 i) cil managed
{ {
@ -157,250 +214,6 @@
IL_00df: ret IL_00df: ret
} // end of method Switch::SparseIntegerSwitch } // end of method Switch::SparseIntegerSwitch
.method public hidebysig static string
SwitchOverNullableInt(valuetype [mscorlib]System.Nullable`1<int32> i) cil managed
{
// Code size 74 (0x4a)
.maxstack 2
.locals init (string V_0,
int32 V_1)
IL_0000: nop
IL_0001: ldarga.s i
IL_0003: dup
IL_0004: call instance !0 valuetype [mscorlib]System.Nullable`1<int32>::GetValueOrDefault()
IL_0009: stloc.1
IL_000a: call instance bool valuetype [mscorlib]System.Nullable`1<int32>::get_HasValue()
IL_000f: brfalse.s IL_0020
IL_0011: ldloc.1
IL_0012: ldc.i4.0
IL_0013: beq.s IL_0028
IL_0015: ldloc.1
IL_0016: ldc.i4.5
IL_0017: beq.s IL_0030
IL_0019: ldloc.1
IL_001a: ldc.i4.s 10
IL_001c: beq.s IL_0038
IL_001e: br.s IL_0040
IL_0020: ldstr "null"
IL_0025: stloc.0
IL_0026: br.s IL_0048
IL_0028: ldstr "zero"
IL_002d: stloc.0
IL_002e: br.s IL_0048
IL_0030: ldstr "five"
IL_0035: stloc.0
IL_0036: br.s IL_0048
IL_0038: ldstr "ten"
IL_003d: stloc.0
IL_003e: br.s IL_0048
IL_0040: ldstr "large"
IL_0045: stloc.0
IL_0046: br.s IL_0048
IL_0048: ldloc.0
IL_0049: ret
} // end of method Switch::SwitchOverNullableInt
.method public hidebysig static string
SwitchOverNullableIntShifted(valuetype [mscorlib]System.Nullable`1<int32> i) cil managed
{
// Code size 112 (0x70)
.maxstack 2
.locals init (string V_0,
valuetype [mscorlib]System.Nullable`1<int32> V_1,
valuetype [mscorlib]System.Nullable`1<int32> V_2,
int32 V_3)
IL_0000: nop
IL_0001: ldarg.0
IL_0002: stloc.1
IL_0003: ldloca.s V_1
IL_0005: call instance bool valuetype [mscorlib]System.Nullable`1<int32>::get_HasValue()
IL_000a: brtrue.s IL_0017
IL_000c: ldloca.s V_2
IL_000e: initobj valuetype [mscorlib]System.Nullable`1<int32>
IL_0014: ldloc.2
IL_0015: br.s IL_0025
IL_0017: ldloca.s V_1
IL_0019: call instance !0 valuetype [mscorlib]System.Nullable`1<int32>::GetValueOrDefault()
IL_001e: ldc.i4.5
IL_001f: add
IL_0020: newobj instance void valuetype [mscorlib]System.Nullable`1<int32>::.ctor(!0)
IL_0025: nop
IL_0026: stloc.2
IL_0027: ldloca.s V_2
IL_0029: dup
IL_002a: call instance !0 valuetype [mscorlib]System.Nullable`1<int32>::GetValueOrDefault()
IL_002f: stloc.3
IL_0030: call instance bool valuetype [mscorlib]System.Nullable`1<int32>::get_HasValue()
IL_0035: brfalse.s IL_0046
IL_0037: ldloc.3
IL_0038: ldc.i4.0
IL_0039: beq.s IL_004e
IL_003b: ldloc.3
IL_003c: ldc.i4.5
IL_003d: beq.s IL_0056
IL_003f: ldloc.3
IL_0040: ldc.i4.s 10
IL_0042: beq.s IL_005e
IL_0044: br.s IL_0066
IL_0046: ldstr "null"
IL_004b: stloc.0
IL_004c: br.s IL_006e
IL_004e: ldstr "zero"
IL_0053: stloc.0
IL_0054: br.s IL_006e
IL_0056: ldstr "five"
IL_005b: stloc.0
IL_005c: br.s IL_006e
IL_005e: ldstr "ten"
IL_0063: stloc.0
IL_0064: br.s IL_006e
IL_0066: ldstr "large"
IL_006b: stloc.0
IL_006c: br.s IL_006e
IL_006e: ldloc.0
IL_006f: ret
} // end of method Switch::SwitchOverNullableIntShifted
.method public hidebysig static string
SwitchOverNullableIntNoNullCase(valuetype [mscorlib]System.Nullable`1<int32> i) cil managed
{
// Code size 66 (0x42)
.maxstack 2
.locals init (string V_0,
int32 V_1)
IL_0000: nop
IL_0001: ldarga.s i
IL_0003: dup
IL_0004: call instance !0 valuetype [mscorlib]System.Nullable`1<int32>::GetValueOrDefault()
IL_0009: stloc.1
IL_000a: call instance bool valuetype [mscorlib]System.Nullable`1<int32>::get_HasValue()
IL_000f: brfalse.s IL_0038
IL_0011: ldloc.1
IL_0012: ldc.i4.0
IL_0013: beq.s IL_0020
IL_0015: ldloc.1
IL_0016: ldc.i4.5
IL_0017: beq.s IL_0028
IL_0019: ldloc.1
IL_001a: ldc.i4.s 10
IL_001c: beq.s IL_0030
IL_001e: br.s IL_0038
IL_0020: ldstr "zero"
IL_0025: stloc.0
IL_0026: br.s IL_0040
IL_0028: ldstr "five"
IL_002d: stloc.0
IL_002e: br.s IL_0040
IL_0030: ldstr "ten"
IL_0035: stloc.0
IL_0036: br.s IL_0040
IL_0038: ldstr "other"
IL_003d: stloc.0
IL_003e: br.s IL_0040
IL_0040: ldloc.0
IL_0041: ret
} // end of method Switch::SwitchOverNullableIntNoNullCase
.method public hidebysig static string
SwitchOverNullableIntNoNullCaseShifted(valuetype [mscorlib]System.Nullable`1<int32> i) cil managed
{
// Code size 104 (0x68)
.maxstack 2
.locals init (string V_0,
valuetype [mscorlib]System.Nullable`1<int32> V_1,
valuetype [mscorlib]System.Nullable`1<int32> V_2,
int32 V_3)
IL_0000: nop
IL_0001: ldarg.0
IL_0002: stloc.1
IL_0003: ldloca.s V_1
IL_0005: call instance bool valuetype [mscorlib]System.Nullable`1<int32>::get_HasValue()
IL_000a: brtrue.s IL_0017
IL_000c: ldloca.s V_2
IL_000e: initobj valuetype [mscorlib]System.Nullable`1<int32>
IL_0014: ldloc.2
IL_0015: br.s IL_0025
IL_0017: ldloca.s V_1
IL_0019: call instance !0 valuetype [mscorlib]System.Nullable`1<int32>::GetValueOrDefault()
IL_001e: ldc.i4.5
IL_001f: add
IL_0020: newobj instance void valuetype [mscorlib]System.Nullable`1<int32>::.ctor(!0)
IL_0025: nop
IL_0026: stloc.2
IL_0027: ldloca.s V_2
IL_0029: dup
IL_002a: call instance !0 valuetype [mscorlib]System.Nullable`1<int32>::GetValueOrDefault()
IL_002f: stloc.3
IL_0030: call instance bool valuetype [mscorlib]System.Nullable`1<int32>::get_HasValue()
IL_0035: brfalse.s IL_005e
IL_0037: ldloc.3
IL_0038: ldc.i4.0
IL_0039: beq.s IL_0046
IL_003b: ldloc.3
IL_003c: ldc.i4.5
IL_003d: beq.s IL_004e
IL_003f: ldloc.3
IL_0040: ldc.i4.s 10
IL_0042: beq.s IL_0056
IL_0044: br.s IL_005e
IL_0046: ldstr "zero"
IL_004b: stloc.0
IL_004c: br.s IL_0066
IL_004e: ldstr "five"
IL_0053: stloc.0
IL_0054: br.s IL_0066
IL_0056: ldstr "ten"
IL_005b: stloc.0
IL_005c: br.s IL_0066
IL_005e: ldstr "other"
IL_0063: stloc.0
IL_0064: br.s IL_0066
IL_0066: ldloc.0
IL_0067: ret
} // end of method Switch::SwitchOverNullableIntNoNullCaseShifted
.method public hidebysig static string .method public hidebysig static string
ShortSwitchOverString(string text) cil managed ShortSwitchOverString(string text) cil managed
{ {
@ -485,7 +298,7 @@
IL_0015: brfalse IL_00ef IL_0015: brfalse IL_00ef
IL_001a: volatile. IL_001a: volatile.
IL_001c: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2<string,int32> '<PrivateImplementationDetails>{207B14E2-2177-4CF2-8D8E-2CD85A17CF5C}'::'$$method0x6000007-1' IL_001c: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2<string,int32> '<PrivateImplementationDetails>{D3E1C722-15E3-49C8-B86B-96413DA7BEEE}'::'$$method0x6000003-1'
IL_0021: brtrue.s IL_0084 IL_0021: brtrue.s IL_0084
IL_0023: ldc.i4.7 IL_0023: ldc.i4.7
@ -526,9 +339,9 @@
IL_0078: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2<string,int32>::Add(!0, IL_0078: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2<string,int32>::Add(!0,
!1) !1)
IL_007d: volatile. IL_007d: volatile.
IL_007f: stsfld class [mscorlib]System.Collections.Generic.Dictionary`2<string,int32> '<PrivateImplementationDetails>{207B14E2-2177-4CF2-8D8E-2CD85A17CF5C}'::'$$method0x6000007-1' IL_007f: stsfld class [mscorlib]System.Collections.Generic.Dictionary`2<string,int32> '<PrivateImplementationDetails>{D3E1C722-15E3-49C8-B86B-96413DA7BEEE}'::'$$method0x6000003-1'
IL_0084: volatile. IL_0084: volatile.
IL_0086: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2<string,int32> '<PrivateImplementationDetails>{207B14E2-2177-4CF2-8D8E-2CD85A17CF5C}'::'$$method0x6000007-1' IL_0086: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2<string,int32> '<PrivateImplementationDetails>{D3E1C722-15E3-49C8-B86B-96413DA7BEEE}'::'$$method0x6000003-1'
IL_008b: ldloc.1 IL_008b: ldloc.1
IL_008c: ldloca.s V_2 IL_008c: ldloca.s V_2
IL_008e: call instance bool class [mscorlib]System.Collections.Generic.Dictionary`2<string,int32>::TryGetValue(!0, IL_008e: call instance bool class [mscorlib]System.Collections.Generic.Dictionary`2<string,int32>::TryGetValue(!0,
@ -611,7 +424,7 @@
IL_0015: brfalse IL_0165 IL_0015: brfalse IL_0165
IL_001a: volatile. IL_001a: volatile.
IL_001c: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2<string,int32> '<PrivateImplementationDetails>{207B14E2-2177-4CF2-8D8E-2CD85A17CF5C}'::'$$method0x6000008-1' IL_001c: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2<string,int32> '<PrivateImplementationDetails>{D3E1C722-15E3-49C8-B86B-96413DA7BEEE}'::'$$method0x6000004-1'
IL_0021: brtrue IL_00ba IL_0021: brtrue IL_00ba
IL_0026: ldc.i4.s 11 IL_0026: ldc.i4.s 11
@ -672,9 +485,9 @@
IL_00ae: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2<string,int32>::Add(!0, IL_00ae: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2<string,int32>::Add(!0,
!1) !1)
IL_00b3: volatile. IL_00b3: volatile.
IL_00b5: stsfld class [mscorlib]System.Collections.Generic.Dictionary`2<string,int32> '<PrivateImplementationDetails>{207B14E2-2177-4CF2-8D8E-2CD85A17CF5C}'::'$$method0x6000008-1' IL_00b5: stsfld class [mscorlib]System.Collections.Generic.Dictionary`2<string,int32> '<PrivateImplementationDetails>{D3E1C722-15E3-49C8-B86B-96413DA7BEEE}'::'$$method0x6000004-1'
IL_00ba: volatile. IL_00ba: volatile.
IL_00bc: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2<string,int32> '<PrivateImplementationDetails>{207B14E2-2177-4CF2-8D8E-2CD85A17CF5C}'::'$$method0x6000008-1' IL_00bc: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2<string,int32> '<PrivateImplementationDetails>{D3E1C722-15E3-49C8-B86B-96413DA7BEEE}'::'$$method0x6000004-1'
IL_00c1: ldloc.2 IL_00c1: ldloc.2
IL_00c2: ldloca.s V_3 IL_00c2: ldloca.s V_3
IL_00c4: call instance bool class [mscorlib]System.Collections.Generic.Dictionary`2<string,int32>::TryGetValue(!0, IL_00c4: call instance bool class [mscorlib]System.Collections.Generic.Dictionary`2<string,int32>::TryGetValue(!0,
@ -876,73 +689,201 @@
IL_0091: ret IL_0091: ret
} // end of method Switch::SwitchInLoop } // end of method Switch::SwitchInLoop
.method public hidebysig static void SwitchWithGoto(int32 i) cil managed .method private hidebysig static class ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/SetProperty[]
GetProperties() cil managed
{ {
// Code size 122 (0x7a) // Code size 12 (0xc)
.maxstack 2 .maxstack 1
.locals init (int32 V_0) .locals init (class ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/SetProperty[] V_0)
IL_0000: nop IL_0000: nop
IL_0001: ldstr "SwitchWithGoto: " IL_0001: ldc.i4.0
IL_0006: ldarg.0 IL_0002: newarr ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/SetProperty
IL_0007: box [mscorlib]System.Int32 IL_0007: stloc.0
IL_000c: call string [mscorlib]System.String::Concat(object, IL_0008: br.s IL_000a
object)
IL_0011: call void [mscorlib]System.Console::WriteLine(string)
IL_0016: nop
IL_0017: ldarg.0
IL_0018: stloc.0
IL_0019: ldloc.0
IL_001a: ldc.i4.1
IL_001b: sub
IL_001c: switch (
IL_0033,
IL_0041,
IL_004f,
IL_005d)
IL_0031: br.s IL_006b
IL_0033: nop
IL_0034: ldstr "one"
IL_0039: call void [mscorlib]System.Console::WriteLine(string)
IL_003e: nop
IL_003f: br.s IL_006b
IL_0041: nop
IL_0042: ldstr "two"
IL_0047: call void [mscorlib]System.Console::WriteLine(string)
IL_004c: nop
IL_004d: br.s IL_004f
IL_004f: nop
IL_0050: ldstr "three"
IL_0055: call void [mscorlib]System.Console::WriteLine(string)
IL_005a: nop
IL_005b: br.s IL_0079
IL_005d: nop
IL_005e: ldstr "four"
IL_0063: call void [mscorlib]System.Console::WriteLine(string)
IL_0068: nop
IL_0069: br.s IL_0079
IL_006b: nop IL_000a: ldloc.0
IL_006c: ldstr "default" IL_000b: ret
IL_0071: call void [mscorlib]System.Console::WriteLine(string) } // end of method Switch::GetProperties
IL_0076: nop
IL_0077: br.s IL_0079
IL_0079: ret .method public hidebysig static void SwitchOnStringInForLoop() cil managed
} // end of method Switch::SwitchWithGoto {
// Code size 334 (0x14e)
.maxstack 4
.locals init (class [mscorlib]System.Collections.Generic.List`1<class ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/SetProperty> V_0,
class [mscorlib]System.Collections.Generic.List`1<class ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/SetProperty> V_1,
class ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/SetProperty[] V_2,
int32 V_3,
class ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/SetProperty V_4,
string V_5,
string V_6,
int32 V_7,
bool V_8)
IL_0000: nop
IL_0001: newobj instance void class [mscorlib]System.Collections.Generic.List`1<class ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/SetProperty>::.ctor()
IL_0006: stloc.0
IL_0007: newobj instance void class [mscorlib]System.Collections.Generic.List`1<class ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/SetProperty>::.ctor()
IL_000c: stloc.1
IL_000d: call class ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/SetProperty[] ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch::GetProperties()
IL_0012: stloc.2
IL_0013: ldc.i4.0
IL_0014: stloc.3
IL_0015: br IL_013e
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: stloc.s V_6
IL_0032: ldloc.s V_6
IL_0034: brfalse IL_012d
IL_0039: volatile.
IL_003b: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2<string,int32> '<PrivateImplementationDetails>{D3E1C722-15E3-49C8-B86B-96413DA7BEEE}'::'$$method0x6000008-1'
IL_0040: brtrue.s IL_0097
IL_0042: ldc.i4.6
IL_0043: newobj instance void class [mscorlib]System.Collections.Generic.Dictionary`2<string,int32>::.ctor(int32)
IL_0048: dup
IL_0049: ldstr "Name1"
IL_004e: ldc.i4.0
IL_004f: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2<string,int32>::Add(!0,
!1)
IL_0054: dup
IL_0055: ldstr "Name2"
IL_005a: ldc.i4.1
IL_005b: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2<string,int32>::Add(!0,
!1)
IL_0060: dup
IL_0061: ldstr "Name3"
IL_0066: ldc.i4.2
IL_0067: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2<string,int32>::Add(!0,
!1)
IL_006c: dup
IL_006d: ldstr "Name4"
IL_0072: ldc.i4.3
IL_0073: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2<string,int32>::Add(!0,
!1)
IL_0078: dup
IL_0079: ldstr "Name5"
IL_007e: ldc.i4.4
IL_007f: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2<string,int32>::Add(!0,
!1)
IL_0084: dup
IL_0085: ldstr "Name6"
IL_008a: ldc.i4.5
IL_008b: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2<string,int32>::Add(!0,
!1)
IL_0090: volatile.
IL_0092: stsfld class [mscorlib]System.Collections.Generic.Dictionary`2<string,int32> '<PrivateImplementationDetails>{D3E1C722-15E3-49C8-B86B-96413DA7BEEE}'::'$$method0x6000008-1'
IL_0097: volatile.
IL_0099: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2<string,int32> '<PrivateImplementationDetails>{D3E1C722-15E3-49C8-B86B-96413DA7BEEE}'::'$$method0x6000008-1'
IL_009e: ldloc.s V_6
IL_00a0: ldloca.s V_7
IL_00a2: call instance bool class [mscorlib]System.Collections.Generic.Dictionary`2<string,int32>::TryGetValue(!0,
!1&)
IL_00a7: brfalse IL_012d
IL_00ac: ldloc.s V_7
IL_00ae: switch (
IL_00cd,
IL_00e2,
IL_00f7,
IL_010c,
IL_0121,
IL_0121)
IL_00cb: br.s IL_012d
IL_00cd: nop
IL_00ce: ldloc.s V_4
IL_00d0: ldc.i4.1
IL_00d1: callvirt instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/SetProperty::set_Set(int32)
IL_00d6: nop
IL_00d7: ldloc.0
IL_00d8: ldloc.s V_4
IL_00da: callvirt instance void class [mscorlib]System.Collections.Generic.List`1<class ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/SetProperty>::Add(!0)
IL_00df: nop
IL_00e0: br.s IL_0139
IL_00e2: nop
IL_00e3: ldloc.s V_4
IL_00e5: ldc.i4.2
IL_00e6: callvirt instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/SetProperty::set_Set(int32)
IL_00eb: nop
IL_00ec: ldloc.0
IL_00ed: ldloc.s V_4
IL_00ef: callvirt instance void class [mscorlib]System.Collections.Generic.List`1<class ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/SetProperty>::Add(!0)
IL_00f4: nop
IL_00f5: br.s IL_0139
IL_00f7: nop
IL_00f8: ldloc.s V_4
IL_00fa: ldc.i4.3
IL_00fb: callvirt instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/SetProperty::set_Set(int32)
IL_0100: nop
IL_0101: ldloc.0
IL_0102: ldloc.s V_4
IL_0104: callvirt instance void class [mscorlib]System.Collections.Generic.List`1<class ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/SetProperty>::Add(!0)
IL_0109: nop
IL_010a: br.s IL_0139
IL_010c: nop
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<class ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/SetProperty>::Add(!0)
IL_011e: nop
IL_011f: br.s IL_0139
IL_0121: nop
IL_0122: ldloc.0
IL_0123: ldloc.s V_4
IL_0125: callvirt instance void class [mscorlib]System.Collections.Generic.List`1<class ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/SetProperty>::Add(!0)
IL_012a: nop
IL_012b: br.s IL_0139
IL_012d: nop
IL_012e: ldloc.1
IL_012f: ldloc.s V_4
IL_0131: callvirt instance void class [mscorlib]System.Collections.Generic.List`1<class ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/SetProperty>::Add(!0)
IL_0136: nop
IL_0137: br.s IL_0139
IL_0139: nop
IL_013a: ldloc.3
IL_013b: ldc.i4.1
IL_013c: add
IL_013d: stloc.3
IL_013e: ldloc.3
IL_013f: ldloc.2
IL_0140: ldlen
IL_0141: conv.i4
IL_0142: clt
IL_0144: stloc.s V_8
IL_0146: ldloc.s V_8
IL_0148: brtrue IL_001a
IL_014d: ret
} // end of method Switch::SwitchOnStringInForLoop
} // end of class ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch } // end of class ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch
.class private auto ansi '<PrivateImplementationDetails>{207B14E2-2177-4CF2-8D8E-2CD85A17CF5C}' .class private auto ansi '<PrivateImplementationDetails>{D3E1C722-15E3-49C8-B86B-96413DA7BEEE}'
extends [mscorlib]System.Object extends [mscorlib]System.Object
{ {
.custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 )
.field static assembly class [mscorlib]System.Collections.Generic.Dictionary`2<string,int32> '$$method0x6000007-1' .field static assembly class [mscorlib]System.Collections.Generic.Dictionary`2<string,int32> '$$method0x6000003-1'
.field static assembly class [mscorlib]System.Collections.Generic.Dictionary`2<string,int32> '$$method0x6000004-1'
.field static assembly class [mscorlib]System.Collections.Generic.Dictionary`2<string,int32> '$$method0x6000008-1' .field static assembly class [mscorlib]System.Collections.Generic.Dictionary`2<string,int32> '$$method0x6000008-1'
} // end of class '<PrivateImplementationDetails>{207B14E2-2177-4CF2-8D8E-2CD85A17CF5C}' } // end of class '<PrivateImplementationDetails>{D3E1C722-15E3-49C8-B86B-96413DA7BEEE}'
// ============================================================= // =============================================================

474
ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.opt.il

@ -10,25 +10,25 @@
.publickeytoken = (B7 7A 5C 56 19 34 E0 89 ) // .z\V.4.. .publickeytoken = (B7 7A 5C 56 19 34 E0 89 ) // .z\V.4..
.ver 4:0:0:0 .ver 4:0:0:0
} }
.assembly utwwumxi .assembly zlaei1fn
{ {
.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 .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. 63 65 70 74 69 6F 6E 54 68 72 6F 77 73 01 ) // ceptionThrows.
.custom instance void [mscorlib]System.Runtime.CompilerServices.CompilationRelaxationsAttribute::.ctor(int32) = ( 01 00 08 00 00 00 00 00 )
.permissionset reqmin .permissionset reqmin
= {[mscorlib]System.Security.Permissions.SecurityPermissionAttribute = {property bool 'SkipVerification' = bool(true)}} = {[mscorlib]System.Security.Permissions.SecurityPermissionAttribute = {property bool 'SkipVerification' = bool(true)}}
.hash algorithm 0x00008004 .hash algorithm 0x00008004
.ver 0:0:0:0 .ver 0:0:0:0
} }
.module utwwumxi.dll .module zlaei1fn.dll
// MVID: {30E98C35-5F99-4742-941F-78E7F27D8BD5} // MVID: {64CCBA80-944A-4F77-9230-24B174DEE22A}
.custom instance void [mscorlib]System.Security.UnverifiableCodeAttribute::.ctor() = ( 01 00 00 00 ) .custom instance void [mscorlib]System.Security.UnverifiableCodeAttribute::.ctor() = ( 01 00 00 00 )
.imagebase 0x10000000 .imagebase 0x10000000
.file alignment 0x00000200 .file alignment 0x00000200
.stackreserve 0x00100000 .stackreserve 0x00100000
.subsystem 0x0003 // WINDOWS_CUI .subsystem 0x0003 // WINDOWS_CUI
.corflags 0x00000001 // ILONLY .corflags 0x00000001 // ILONLY
// Image base: 0x02C70000 // Image base: 0x00680000
// =============== CLASS MEMBERS DECLARATION =================== // =============== CLASS MEMBERS DECLARATION ===================
@ -36,6 +36,55 @@
.class public abstract auto ansi sealed beforefieldinit ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch .class public abstract auto ansi sealed beforefieldinit ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch
extends [mscorlib]System.Object extends [mscorlib]System.Object
{ {
.class auto ansi nested public beforefieldinit SetProperty
extends [mscorlib]System.Object
{
.field public initonly class [mscorlib]System.Reflection.PropertyInfo Property
.field private int32 '<Set>k__BackingField'
.custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 )
.method public hidebysig specialname
instance int32 get_Set() cil managed
{
.custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 )
// Code size 7 (0x7)
.maxstack 8
IL_0000: ldarg.0
IL_0001: ldfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/SetProperty::'<Set>k__BackingField'
IL_0006: ret
} // end of method SetProperty::get_Set
.method public hidebysig specialname
instance void set_Set(int32 'value') cil managed
{
.custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 )
// Code size 8 (0x8)
.maxstack 8
IL_0000: ldarg.0
IL_0001: ldarg.1
IL_0002: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/SetProperty::'<Set>k__BackingField'
IL_0007: ret
} // end of method SetProperty::set_Set
.method public hidebysig specialname rtspecialname
instance void .ctor(class [mscorlib]System.Reflection.PropertyInfo 'property') cil managed
{
// Code size 14 (0xe)
.maxstack 8
IL_0000: ldarg.0
IL_0001: call instance void [mscorlib]System.Object::.ctor()
IL_0006: ldarg.0
IL_0007: ldarg.1
IL_0008: stfld class [mscorlib]System.Reflection.PropertyInfo ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/SetProperty::Property
IL_000d: ret
} // end of method SetProperty::.ctor
.property instance int32 Set()
{
.get instance int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/SetProperty::get_Set()
.set instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/SetProperty::set_Set(int32)
} // end of property SetProperty::Set
} // end of class SetProperty
.method public hidebysig static string .method public hidebysig static string
SparseIntegerSwitch(int32 i) cil managed SparseIntegerSwitch(int32 i) cil managed
{ {
@ -127,212 +176,6 @@
IL_00b4: ret IL_00b4: ret
} // end of method Switch::SparseIntegerSwitch } // end of method Switch::SparseIntegerSwitch
.method public hidebysig static string
SwitchOverNullableInt(valuetype [mscorlib]System.Nullable`1<int32> i) cil managed
{
// Code size 61 (0x3d)
.maxstack 2
.locals init (int32 V_0)
IL_0000: ldarga.s i
IL_0002: dup
IL_0003: call instance !0 valuetype [mscorlib]System.Nullable`1<int32>::GetValueOrDefault()
IL_0008: stloc.0
IL_0009: call instance bool valuetype [mscorlib]System.Nullable`1<int32>::get_HasValue()
IL_000e: brfalse.s IL_001f
IL_0010: ldloc.0
IL_0011: ldc.i4.0
IL_0012: beq.s IL_0025
IL_0014: ldloc.0
IL_0015: ldc.i4.5
IL_0016: beq.s IL_002b
IL_0018: ldloc.0
IL_0019: ldc.i4.s 10
IL_001b: beq.s IL_0031
IL_001d: br.s IL_0037
IL_001f: ldstr "null"
IL_0024: ret
IL_0025: ldstr "zero"
IL_002a: ret
IL_002b: ldstr "five"
IL_0030: ret
IL_0031: ldstr "ten"
IL_0036: ret
IL_0037: ldstr "large"
IL_003c: ret
} // end of method Switch::SwitchOverNullableInt
.method public hidebysig static string
SwitchOverNullableIntShifted(valuetype [mscorlib]System.Nullable`1<int32> i) cil managed
{
// Code size 98 (0x62)
.maxstack 2
.locals init (valuetype [mscorlib]System.Nullable`1<int32> V_0,
valuetype [mscorlib]System.Nullable`1<int32> V_1,
valuetype [mscorlib]System.Nullable`1<int32> V_2,
int32 V_3)
IL_0000: ldarg.0
IL_0001: stloc.0
IL_0002: ldloca.s V_0
IL_0004: call instance bool valuetype [mscorlib]System.Nullable`1<int32>::get_HasValue()
IL_0009: brtrue.s IL_0016
IL_000b: ldloca.s V_1
IL_000d: initobj valuetype [mscorlib]System.Nullable`1<int32>
IL_0013: ldloc.1
IL_0014: br.s IL_0024
IL_0016: ldloca.s V_0
IL_0018: call instance !0 valuetype [mscorlib]System.Nullable`1<int32>::GetValueOrDefault()
IL_001d: ldc.i4.5
IL_001e: add
IL_001f: newobj instance void valuetype [mscorlib]System.Nullable`1<int32>::.ctor(!0)
IL_0024: stloc.2
IL_0025: ldloca.s V_2
IL_0027: dup
IL_0028: call instance !0 valuetype [mscorlib]System.Nullable`1<int32>::GetValueOrDefault()
IL_002d: stloc.3
IL_002e: call instance bool valuetype [mscorlib]System.Nullable`1<int32>::get_HasValue()
IL_0033: brfalse.s IL_0044
IL_0035: ldloc.3
IL_0036: ldc.i4.0
IL_0037: beq.s IL_004a
IL_0039: ldloc.3
IL_003a: ldc.i4.5
IL_003b: beq.s IL_0050
IL_003d: ldloc.3
IL_003e: ldc.i4.s 10
IL_0040: beq.s IL_0056
IL_0042: br.s IL_005c
IL_0044: ldstr "null"
IL_0049: ret
IL_004a: ldstr "zero"
IL_004f: ret
IL_0050: ldstr "five"
IL_0055: ret
IL_0056: ldstr "ten"
IL_005b: ret
IL_005c: ldstr "large"
IL_0061: ret
} // end of method Switch::SwitchOverNullableIntShifted
.method public hidebysig static string
SwitchOverNullableIntNoNullCase(valuetype [mscorlib]System.Nullable`1<int32> i) cil managed
{
// Code size 55 (0x37)
.maxstack 2
.locals init (int32 V_0)
IL_0000: ldarga.s i
IL_0002: dup
IL_0003: call instance !0 valuetype [mscorlib]System.Nullable`1<int32>::GetValueOrDefault()
IL_0008: stloc.0
IL_0009: call instance bool valuetype [mscorlib]System.Nullable`1<int32>::get_HasValue()
IL_000e: brfalse.s IL_0031
IL_0010: ldloc.0
IL_0011: ldc.i4.0
IL_0012: beq.s IL_001f
IL_0014: ldloc.0
IL_0015: ldc.i4.5
IL_0016: beq.s IL_0025
IL_0018: ldloc.0
IL_0019: ldc.i4.s 10
IL_001b: beq.s IL_002b
IL_001d: br.s IL_0031
IL_001f: ldstr "zero"
IL_0024: ret
IL_0025: ldstr "five"
IL_002a: ret
IL_002b: ldstr "ten"
IL_0030: ret
IL_0031: ldstr "other"
IL_0036: ret
} // end of method Switch::SwitchOverNullableIntNoNullCase
.method public hidebysig static string
SwitchOverNullableIntNoNullCaseShifted(valuetype [mscorlib]System.Nullable`1<int32> i) cil managed
{
// Code size 92 (0x5c)
.maxstack 2
.locals init (valuetype [mscorlib]System.Nullable`1<int32> V_0,
valuetype [mscorlib]System.Nullable`1<int32> V_1,
valuetype [mscorlib]System.Nullable`1<int32> V_2,
int32 V_3)
IL_0000: ldarg.0
IL_0001: stloc.0
IL_0002: ldloca.s V_0
IL_0004: call instance bool valuetype [mscorlib]System.Nullable`1<int32>::get_HasValue()
IL_0009: brtrue.s IL_0016
IL_000b: ldloca.s V_1
IL_000d: initobj valuetype [mscorlib]System.Nullable`1<int32>
IL_0013: ldloc.1
IL_0014: br.s IL_0024
IL_0016: ldloca.s V_0
IL_0018: call instance !0 valuetype [mscorlib]System.Nullable`1<int32>::GetValueOrDefault()
IL_001d: ldc.i4.5
IL_001e: add
IL_001f: newobj instance void valuetype [mscorlib]System.Nullable`1<int32>::.ctor(!0)
IL_0024: stloc.2
IL_0025: ldloca.s V_2
IL_0027: dup
IL_0028: call instance !0 valuetype [mscorlib]System.Nullable`1<int32>::GetValueOrDefault()
IL_002d: stloc.3
IL_002e: call instance bool valuetype [mscorlib]System.Nullable`1<int32>::get_HasValue()
IL_0033: brfalse.s IL_0056
IL_0035: ldloc.3
IL_0036: ldc.i4.0
IL_0037: beq.s IL_0044
IL_0039: ldloc.3
IL_003a: ldc.i4.5
IL_003b: beq.s IL_004a
IL_003d: ldloc.3
IL_003e: ldc.i4.s 10
IL_0040: beq.s IL_0050
IL_0042: br.s IL_0056
IL_0044: ldstr "zero"
IL_0049: ret
IL_004a: ldstr "five"
IL_004f: ret
IL_0050: ldstr "ten"
IL_0055: ret
IL_0056: ldstr "other"
IL_005b: ret
} // end of method Switch::SwitchOverNullableIntNoNullCaseShifted
.method public hidebysig static string .method public hidebysig static string
ShortSwitchOverString(string text) cil managed ShortSwitchOverString(string text) cil managed
{ {
@ -400,7 +243,7 @@
IL_0013: brfalse IL_00db IL_0013: brfalse IL_00db
IL_0018: volatile. IL_0018: volatile.
IL_001a: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2<string,int32> '<PrivateImplementationDetails>{30E98C35-5F99-4742-941F-78E7F27D8BD5}'::'$$method0x6000007-1' IL_001a: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2<string,int32> '<PrivateImplementationDetails>{64CCBA80-944A-4F77-9230-24B174DEE22A}'::'$$method0x6000003-1'
IL_001f: brtrue.s IL_0082 IL_001f: brtrue.s IL_0082
IL_0021: ldc.i4.7 IL_0021: ldc.i4.7
@ -441,9 +284,9 @@
IL_0076: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2<string,int32>::Add(!0, IL_0076: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2<string,int32>::Add(!0,
!1) !1)
IL_007b: volatile. IL_007b: volatile.
IL_007d: stsfld class [mscorlib]System.Collections.Generic.Dictionary`2<string,int32> '<PrivateImplementationDetails>{30E98C35-5F99-4742-941F-78E7F27D8BD5}'::'$$method0x6000007-1' IL_007d: stsfld class [mscorlib]System.Collections.Generic.Dictionary`2<string,int32> '<PrivateImplementationDetails>{64CCBA80-944A-4F77-9230-24B174DEE22A}'::'$$method0x6000003-1'
IL_0082: volatile. IL_0082: volatile.
IL_0084: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2<string,int32> '<PrivateImplementationDetails>{30E98C35-5F99-4742-941F-78E7F27D8BD5}'::'$$method0x6000007-1' IL_0084: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2<string,int32> '<PrivateImplementationDetails>{64CCBA80-944A-4F77-9230-24B174DEE22A}'::'$$method0x6000003-1'
IL_0089: ldloc.0 IL_0089: ldloc.0
IL_008a: ldloca.s V_1 IL_008a: ldloca.s V_1
IL_008c: call instance bool class [mscorlib]System.Collections.Generic.Dictionary`2<string,int32>::TryGetValue(!0, IL_008c: call instance bool class [mscorlib]System.Collections.Generic.Dictionary`2<string,int32>::TryGetValue(!0,
@ -504,7 +347,7 @@
IL_0013: brfalse IL_013f IL_0013: brfalse IL_013f
IL_0018: volatile. IL_0018: volatile.
IL_001a: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2<string,int32> '<PrivateImplementationDetails>{30E98C35-5F99-4742-941F-78E7F27D8BD5}'::'$$method0x6000008-1' IL_001a: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2<string,int32> '<PrivateImplementationDetails>{64CCBA80-944A-4F77-9230-24B174DEE22A}'::'$$method0x6000004-1'
IL_001f: brtrue IL_00b8 IL_001f: brtrue IL_00b8
IL_0024: ldc.i4.s 11 IL_0024: ldc.i4.s 11
@ -565,9 +408,9 @@
IL_00ac: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2<string,int32>::Add(!0, IL_00ac: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2<string,int32>::Add(!0,
!1) !1)
IL_00b1: volatile. IL_00b1: volatile.
IL_00b3: stsfld class [mscorlib]System.Collections.Generic.Dictionary`2<string,int32> '<PrivateImplementationDetails>{30E98C35-5F99-4742-941F-78E7F27D8BD5}'::'$$method0x6000008-1' IL_00b3: stsfld class [mscorlib]System.Collections.Generic.Dictionary`2<string,int32> '<PrivateImplementationDetails>{64CCBA80-944A-4F77-9230-24B174DEE22A}'::'$$method0x6000004-1'
IL_00b8: volatile. IL_00b8: volatile.
IL_00ba: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2<string,int32> '<PrivateImplementationDetails>{30E98C35-5F99-4742-941F-78E7F27D8BD5}'::'$$method0x6000008-1' IL_00ba: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2<string,int32> '<PrivateImplementationDetails>{64CCBA80-944A-4F77-9230-24B174DEE22A}'::'$$method0x6000004-1'
IL_00bf: ldloc.1 IL_00bf: ldloc.1
IL_00c0: ldloca.s V_2 IL_00c0: ldloca.s V_2
IL_00c2: call instance bool class [mscorlib]System.Collections.Generic.Dictionary`2<string,int32>::TryGetValue(!0, IL_00c2: call instance bool class [mscorlib]System.Collections.Generic.Dictionary`2<string,int32>::TryGetValue(!0,
@ -708,57 +551,170 @@
IL_007a: br.s IL_0015 IL_007a: br.s IL_0015
} // end of method Switch::SwitchInLoop } // end of method Switch::SwitchInLoop
.method public hidebysig static void SwitchWithGoto(int32 i) cil managed .method private hidebysig static class ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/SetProperty[]
GetProperties() cil managed
{ {
// Code size 104 (0x68) // Code size 7 (0x7)
.maxstack 2 .maxstack 8
.locals init (int32 V_0) IL_0000: ldc.i4.0
IL_0000: ldstr "SwitchWithGoto: " IL_0001: newarr ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/SetProperty
IL_0005: ldarg.0 IL_0006: ret
IL_0006: box [mscorlib]System.Int32 } // end of method Switch::GetProperties
IL_000b: call string [mscorlib]System.String::Concat(object,
object) .method public hidebysig static void SwitchOnStringInForLoop() cil managed
IL_0010: call void [mscorlib]System.Console::WriteLine(string) {
IL_0015: ldarg.0 // Code size 303 (0x12f)
IL_0016: stloc.0 .maxstack 4
IL_0017: ldloc.0 .locals init (class [mscorlib]System.Collections.Generic.List`1<class ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/SetProperty> V_0,
IL_0018: ldc.i4.1 class [mscorlib]System.Collections.Generic.List`1<class ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/SetProperty> V_1,
IL_0019: sub class ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/SetProperty[] V_2,
IL_001a: switch ( int32 V_3,
IL_0031, class ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/SetProperty V_4,
IL_003d, string V_5,
IL_0047, string V_6,
IL_0052) int32 V_7)
IL_002f: br.s IL_005d IL_0000: newobj instance void class [mscorlib]System.Collections.Generic.List`1<class ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/SetProperty>::.ctor()
IL_0005: stloc.0
IL_0031: ldstr "one" IL_0006: newobj instance void class [mscorlib]System.Collections.Generic.List`1<class ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/SetProperty>::.ctor()
IL_0036: call void [mscorlib]System.Console::WriteLine(string) IL_000b: stloc.1
IL_003b: br.s IL_005d IL_000c: call class ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/SetProperty[] ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch::GetProperties()
IL_0011: stloc.2
IL_003d: ldstr "two" IL_0012: ldc.i4.0
IL_0042: call void [mscorlib]System.Console::WriteLine(string) IL_0013: stloc.3
IL_0047: ldstr "three" IL_0014: br IL_0125
IL_004c: call void [mscorlib]System.Console::WriteLine(string)
IL_0051: ret IL_0019: ldloc.2
IL_001a: ldloc.3
IL_0052: ldstr "four" IL_001b: ldelem.ref
IL_0057: call void [mscorlib]System.Console::WriteLine(string) IL_001c: stloc.s V_4
IL_005c: ret 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: dup
IL_002f: stloc.s V_6
IL_0031: brfalse IL_0119
IL_0036: volatile.
IL_0038: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2<string,int32> '<PrivateImplementationDetails>{64CCBA80-944A-4F77-9230-24B174DEE22A}'::'$$method0x6000008-1'
IL_003d: brtrue.s IL_0094
IL_003f: ldc.i4.6
IL_0040: newobj instance void class [mscorlib]System.Collections.Generic.Dictionary`2<string,int32>::.ctor(int32)
IL_0045: dup
IL_0046: ldstr "Name1"
IL_004b: ldc.i4.0
IL_004c: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2<string,int32>::Add(!0,
!1)
IL_0051: dup
IL_0052: ldstr "Name2"
IL_0057: ldc.i4.1
IL_0058: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2<string,int32>::Add(!0,
!1)
IL_005d: dup
IL_005e: ldstr "Name3"
IL_0063: ldc.i4.2
IL_0064: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2<string,int32>::Add(!0,
!1)
IL_0069: dup
IL_006a: ldstr "Name4"
IL_006f: ldc.i4.3
IL_0070: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2<string,int32>::Add(!0,
!1)
IL_0075: dup
IL_0076: ldstr "Name5"
IL_007b: ldc.i4.4
IL_007c: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2<string,int32>::Add(!0,
!1)
IL_0081: dup
IL_0082: ldstr "Name6"
IL_0087: ldc.i4.5
IL_0088: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2<string,int32>::Add(!0,
!1)
IL_008d: volatile.
IL_008f: stsfld class [mscorlib]System.Collections.Generic.Dictionary`2<string,int32> '<PrivateImplementationDetails>{64CCBA80-944A-4F77-9230-24B174DEE22A}'::'$$method0x6000008-1'
IL_0094: volatile.
IL_0096: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2<string,int32> '<PrivateImplementationDetails>{64CCBA80-944A-4F77-9230-24B174DEE22A}'::'$$method0x6000008-1'
IL_009b: ldloc.s V_6
IL_009d: ldloca.s V_7
IL_009f: call instance bool class [mscorlib]System.Collections.Generic.Dictionary`2<string,int32>::TryGetValue(!0,
!1&)
IL_00a4: brfalse.s IL_0119
IL_005d: ldstr "default" IL_00a6: ldloc.s V_7
IL_0062: call void [mscorlib]System.Console::WriteLine(string) IL_00a8: switch (
IL_0067: ret IL_00c7,
} // end of method Switch::SwitchWithGoto IL_00d9,
IL_00eb,
IL_00fd,
IL_010f,
IL_010f)
IL_00c5: br.s IL_0119
IL_00c7: ldloc.s V_4
IL_00c9: ldc.i4.1
IL_00ca: callvirt instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/SetProperty::set_Set(int32)
IL_00cf: ldloc.0
IL_00d0: ldloc.s V_4
IL_00d2: callvirt instance void class [mscorlib]System.Collections.Generic.List`1<class ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/SetProperty>::Add(!0)
IL_00d7: br.s IL_0121
IL_00d9: ldloc.s V_4
IL_00db: ldc.i4.2
IL_00dc: callvirt instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/SetProperty::set_Set(int32)
IL_00e1: ldloc.0
IL_00e2: ldloc.s V_4
IL_00e4: callvirt instance void class [mscorlib]System.Collections.Generic.List`1<class ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/SetProperty>::Add(!0)
IL_00e9: br.s IL_0121
IL_00eb: ldloc.s V_4
IL_00ed: ldc.i4.3
IL_00ee: callvirt instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/SetProperty::set_Set(int32)
IL_00f3: ldloc.0
IL_00f4: ldloc.s V_4
IL_00f6: callvirt instance void class [mscorlib]System.Collections.Generic.List`1<class ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/SetProperty>::Add(!0)
IL_00fb: br.s IL_0121
IL_00fd: ldloc.s V_4
IL_00ff: ldc.i4.4
IL_0100: callvirt instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/SetProperty::set_Set(int32)
IL_0105: ldloc.0
IL_0106: ldloc.s V_4
IL_0108: callvirt instance void class [mscorlib]System.Collections.Generic.List`1<class ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/SetProperty>::Add(!0)
IL_010d: br.s IL_0121
IL_010f: ldloc.0
IL_0110: ldloc.s V_4
IL_0112: callvirt instance void class [mscorlib]System.Collections.Generic.List`1<class ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/SetProperty>::Add(!0)
IL_0117: br.s IL_0121
IL_0119: ldloc.1
IL_011a: ldloc.s V_4
IL_011c: callvirt instance void class [mscorlib]System.Collections.Generic.List`1<class ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/SetProperty>::Add(!0)
IL_0121: ldloc.3
IL_0122: ldc.i4.1
IL_0123: add
IL_0124: stloc.3
IL_0125: ldloc.3
IL_0126: ldloc.2
IL_0127: ldlen
IL_0128: conv.i4
IL_0129: blt IL_0019
IL_012e: ret
} // end of method Switch::SwitchOnStringInForLoop
} // end of class ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch } // end of class ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch
.class private auto ansi '<PrivateImplementationDetails>{30E98C35-5F99-4742-941F-78E7F27D8BD5}' .class private auto ansi '<PrivateImplementationDetails>{64CCBA80-944A-4F77-9230-24B174DEE22A}'
extends [mscorlib]System.Object extends [mscorlib]System.Object
{ {
.custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 )
.field static assembly class [mscorlib]System.Collections.Generic.Dictionary`2<string,int32> '$$method0x6000007-1' .field static assembly class [mscorlib]System.Collections.Generic.Dictionary`2<string,int32> '$$method0x6000003-1'
.field static assembly class [mscorlib]System.Collections.Generic.Dictionary`2<string,int32> '$$method0x6000004-1'
.field static assembly class [mscorlib]System.Collections.Generic.Dictionary`2<string,int32> '$$method0x6000008-1' .field static assembly class [mscorlib]System.Collections.Generic.Dictionary`2<string,int32> '$$method0x6000008-1'
} // end of class '<PrivateImplementationDetails>{30E98C35-5F99-4742-941F-78E7F27D8BD5}' } // end of class '<PrivateImplementationDetails>{64CCBA80-944A-4F77-9230-24B174DEE22A}'
// ============================================================= // =============================================================

419
ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.opt.roslyn.il

@ -25,14 +25,14 @@
.ver 0:0:0:0 .ver 0:0:0:0
} }
.module Switch.dll .module Switch.dll
// MVID: {E38DFC98-1601-4EC8-896E-FC0EA87D4437} // MVID: {25FC064E-F764-4556-A3C7-F6570E457CDD}
.custom instance void [mscorlib]System.Security.UnverifiableCodeAttribute::.ctor() = ( 01 00 00 00 ) .custom instance void [mscorlib]System.Security.UnverifiableCodeAttribute::.ctor() = ( 01 00 00 00 )
.imagebase 0x10000000 .imagebase 0x10000000
.file alignment 0x00000200 .file alignment 0x00000200
.stackreserve 0x00100000 .stackreserve 0x00100000
.subsystem 0x0003 // WINDOWS_CUI .subsystem 0x0003 // WINDOWS_CUI
.corflags 0x00000001 // ILONLY .corflags 0x00000001 // ILONLY
// Image base: 0x02590000 // Image base: 0x00B30000
// =============== CLASS MEMBERS DECLARATION =================== // =============== CLASS MEMBERS DECLARATION ===================
@ -40,6 +40,55 @@
.class public abstract auto ansi sealed beforefieldinit ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch .class public abstract auto ansi sealed beforefieldinit ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch
extends [mscorlib]System.Object extends [mscorlib]System.Object
{ {
.class auto ansi nested public beforefieldinit SetProperty
extends [mscorlib]System.Object
{
.field public initonly class [mscorlib]System.Reflection.PropertyInfo Property
.field private int32 '<Set>k__BackingField'
.custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 )
.method public hidebysig specialname
instance int32 get_Set() cil managed
{
.custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 )
// Code size 7 (0x7)
.maxstack 8
IL_0000: ldarg.0
IL_0001: ldfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/SetProperty::'<Set>k__BackingField'
IL_0006: ret
} // end of method SetProperty::get_Set
.method public hidebysig specialname
instance void set_Set(int32 'value') cil managed
{
.custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 )
// Code size 8 (0x8)
.maxstack 8
IL_0000: ldarg.0
IL_0001: ldarg.1
IL_0002: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/SetProperty::'<Set>k__BackingField'
IL_0007: ret
} // end of method SetProperty::set_Set
.method public hidebysig specialname rtspecialname
instance void .ctor(class [mscorlib]System.Reflection.PropertyInfo 'property') cil managed
{
// Code size 14 (0xe)
.maxstack 8
IL_0000: ldarg.0
IL_0001: call instance void [mscorlib]System.Object::.ctor()
IL_0006: ldarg.0
IL_0007: ldarg.1
IL_0008: stfld class [mscorlib]System.Reflection.PropertyInfo ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/SetProperty::Property
IL_000d: ret
} // end of method SetProperty::.ctor
.property instance int32 Set()
{
.get instance int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/SetProperty::get_Set()
.set instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/SetProperty::set_Set(int32)
} // end of property SetProperty::Set
} // end of class SetProperty
.method public hidebysig static string .method public hidebysig static string
SparseIntegerSwitch(int32 i) cil managed SparseIntegerSwitch(int32 i) cil managed
{ {
@ -136,214 +185,6 @@
IL_00b8: ret IL_00b8: ret
} // end of method Switch::SparseIntegerSwitch } // end of method Switch::SparseIntegerSwitch
.method public hidebysig static string
SwitchOverNullableInt(valuetype [mscorlib]System.Nullable`1<int32> i) cil managed
{
// Code size 63 (0x3f)
.maxstack 2
.locals init (valuetype [mscorlib]System.Nullable`1<int32> V_0,
int32 V_1)
IL_0000: ldarg.0
IL_0001: stloc.0
IL_0002: ldloca.s V_0
IL_0004: call instance bool valuetype [mscorlib]System.Nullable`1<int32>::get_HasValue()
IL_0009: brfalse.s IL_0021
IL_000b: ldloca.s V_0
IL_000d: call instance !0 valuetype [mscorlib]System.Nullable`1<int32>::GetValueOrDefault()
IL_0012: stloc.1
IL_0013: ldloc.1
IL_0014: brfalse.s IL_0027
IL_0016: ldloc.1
IL_0017: ldc.i4.5
IL_0018: beq.s IL_002d
IL_001a: ldloc.1
IL_001b: ldc.i4.s 10
IL_001d: beq.s IL_0033
IL_001f: br.s IL_0039
IL_0021: ldstr "null"
IL_0026: ret
IL_0027: ldstr "zero"
IL_002c: ret
IL_002d: ldstr "five"
IL_0032: ret
IL_0033: ldstr "ten"
IL_0038: ret
IL_0039: ldstr "large"
IL_003e: ret
} // end of method Switch::SwitchOverNullableInt
.method public hidebysig static string
SwitchOverNullableIntShifted(valuetype [mscorlib]System.Nullable`1<int32> i) cil managed
{
// Code size 98 (0x62)
.maxstack 2
.locals init (valuetype [mscorlib]System.Nullable`1<int32> V_0,
valuetype [mscorlib]System.Nullable`1<int32> V_1,
valuetype [mscorlib]System.Nullable`1<int32> V_2,
int32 V_3)
IL_0000: ldarg.0
IL_0001: stloc.1
IL_0002: ldloca.s V_1
IL_0004: call instance bool valuetype [mscorlib]System.Nullable`1<int32>::get_HasValue()
IL_0009: brtrue.s IL_0016
IL_000b: ldloca.s V_2
IL_000d: initobj valuetype [mscorlib]System.Nullable`1<int32>
IL_0013: ldloc.2
IL_0014: br.s IL_0024
IL_0016: ldloca.s V_1
IL_0018: call instance !0 valuetype [mscorlib]System.Nullable`1<int32>::GetValueOrDefault()
IL_001d: ldc.i4.5
IL_001e: add
IL_001f: newobj instance void valuetype [mscorlib]System.Nullable`1<int32>::.ctor(!0)
IL_0024: stloc.0
IL_0025: ldloca.s V_0
IL_0027: call instance bool valuetype [mscorlib]System.Nullable`1<int32>::get_HasValue()
IL_002c: brfalse.s IL_0044
IL_002e: ldloca.s V_0
IL_0030: call instance !0 valuetype [mscorlib]System.Nullable`1<int32>::GetValueOrDefault()
IL_0035: stloc.3
IL_0036: ldloc.3
IL_0037: brfalse.s IL_004a
IL_0039: ldloc.3
IL_003a: ldc.i4.5
IL_003b: beq.s IL_0050
IL_003d: ldloc.3
IL_003e: ldc.i4.s 10
IL_0040: beq.s IL_0056
IL_0042: br.s IL_005c
IL_0044: ldstr "null"
IL_0049: ret
IL_004a: ldstr "zero"
IL_004f: ret
IL_0050: ldstr "five"
IL_0055: ret
IL_0056: ldstr "ten"
IL_005b: ret
IL_005c: ldstr "large"
IL_0061: ret
} // end of method Switch::SwitchOverNullableIntShifted
.method public hidebysig static string
SwitchOverNullableIntNoNullCase(valuetype [mscorlib]System.Nullable`1<int32> i) cil managed
{
// Code size 57 (0x39)
.maxstack 2
.locals init (valuetype [mscorlib]System.Nullable`1<int32> V_0,
int32 V_1)
IL_0000: ldarg.0
IL_0001: stloc.0
IL_0002: ldloca.s V_0
IL_0004: call instance bool valuetype [mscorlib]System.Nullable`1<int32>::get_HasValue()
IL_0009: brfalse.s IL_0033
IL_000b: ldloca.s V_0
IL_000d: call instance !0 valuetype [mscorlib]System.Nullable`1<int32>::GetValueOrDefault()
IL_0012: stloc.1
IL_0013: ldloc.1
IL_0014: brfalse.s IL_0021
IL_0016: ldloc.1
IL_0017: ldc.i4.5
IL_0018: beq.s IL_0027
IL_001a: ldloc.1
IL_001b: ldc.i4.s 10
IL_001d: beq.s IL_002d
IL_001f: br.s IL_0033
IL_0021: ldstr "zero"
IL_0026: ret
IL_0027: ldstr "five"
IL_002c: ret
IL_002d: ldstr "ten"
IL_0032: ret
IL_0033: ldstr "other"
IL_0038: ret
} // end of method Switch::SwitchOverNullableIntNoNullCase
.method public hidebysig static string
SwitchOverNullableIntNoNullCaseShifted(valuetype [mscorlib]System.Nullable`1<int32> i) cil managed
{
// Code size 92 (0x5c)
.maxstack 2
.locals init (valuetype [mscorlib]System.Nullable`1<int32> V_0,
valuetype [mscorlib]System.Nullable`1<int32> V_1,
valuetype [mscorlib]System.Nullable`1<int32> V_2,
int32 V_3)
IL_0000: ldarg.0
IL_0001: stloc.1
IL_0002: ldloca.s V_1
IL_0004: call instance bool valuetype [mscorlib]System.Nullable`1<int32>::get_HasValue()
IL_0009: brtrue.s IL_0016
IL_000b: ldloca.s V_2
IL_000d: initobj valuetype [mscorlib]System.Nullable`1<int32>
IL_0013: ldloc.2
IL_0014: br.s IL_0024
IL_0016: ldloca.s V_1
IL_0018: call instance !0 valuetype [mscorlib]System.Nullable`1<int32>::GetValueOrDefault()
IL_001d: ldc.i4.5
IL_001e: add
IL_001f: newobj instance void valuetype [mscorlib]System.Nullable`1<int32>::.ctor(!0)
IL_0024: stloc.0
IL_0025: ldloca.s V_0
IL_0027: call instance bool valuetype [mscorlib]System.Nullable`1<int32>::get_HasValue()
IL_002c: brfalse.s IL_0056
IL_002e: ldloca.s V_0
IL_0030: call instance !0 valuetype [mscorlib]System.Nullable`1<int32>::GetValueOrDefault()
IL_0035: stloc.3
IL_0036: ldloc.3
IL_0037: brfalse.s IL_0044
IL_0039: ldloc.3
IL_003a: ldc.i4.5
IL_003b: beq.s IL_004a
IL_003d: ldloc.3
IL_003e: ldc.i4.s 10
IL_0040: beq.s IL_0050
IL_0042: br.s IL_0056
IL_0044: ldstr "zero"
IL_0049: ret
IL_004a: ldstr "five"
IL_004f: ret
IL_0050: ldstr "ten"
IL_0055: ret
IL_0056: ldstr "other"
IL_005b: ret
} // end of method Switch::SwitchOverNullableIntNoNullCaseShifted
.method public hidebysig static string .method public hidebysig static string
ShortSwitchOverString(string text) cil managed ShortSwitchOverString(string text) cil managed
{ {
@ -818,44 +659,134 @@
IL_0078: br.s IL_0015 IL_0078: br.s IL_0015
} // end of method Switch::SwitchInLoop } // end of method Switch::SwitchInLoop
.method public hidebysig static void SwitchWithGoto(int32 i) cil managed .method private hidebysig static class ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/SetProperty[]
GetProperties() cil managed
{ {
// Code size 102 (0x66) // Code size 7 (0x7)
.maxstack 8
IL_0000: ldc.i4.0
IL_0001: newarr ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/SetProperty
IL_0006: ret
} // end of method Switch::GetProperties
.method public hidebysig static void SwitchOnStringInForLoop() cil managed
{
// Code size 234 (0xea)
.maxstack 2 .maxstack 2
IL_0000: ldstr "SwitchWithGoto: " .locals init (class [mscorlib]System.Collections.Generic.List`1<class ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/SetProperty> V_0,
IL_0005: ldarg.0 class [mscorlib]System.Collections.Generic.List`1<class ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/SetProperty> V_1,
IL_0006: box [mscorlib]System.Int32 class ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/SetProperty[] V_2,
IL_000b: call string [mscorlib]System.String::Concat(object, int32 V_3,
object) class ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/SetProperty V_4,
IL_0010: call void [mscorlib]System.Console::WriteLine(string) string V_5)
IL_0015: ldarg.0 IL_0000: newobj instance void class [mscorlib]System.Collections.Generic.List`1<class ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/SetProperty>::.ctor()
IL_0016: ldc.i4.1 IL_0005: stloc.0
IL_0017: sub IL_0006: newobj instance void class [mscorlib]System.Collections.Generic.List`1<class ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/SetProperty>::.ctor()
IL_0018: switch ( IL_000b: stloc.1
IL_002f, IL_000c: call class ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/SetProperty[] ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch::GetProperties()
IL_003b, IL_0011: stloc.2
IL_0045, IL_0012: ldc.i4.0
IL_0050) IL_0013: stloc.3
IL_002d: br.s IL_005b 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,
string)
IL_0038: brtrue.s IL_0082
IL_002f: ldstr "one" IL_003a: ldloc.s V_5
IL_0034: call void [mscorlib]System.Console::WriteLine(string) IL_003c: ldstr "Name2"
IL_0039: br.s IL_005b IL_0041: call bool [mscorlib]System.String::op_Equality(string,
string)
IL_0046: brtrue.s IL_0094
IL_003b: ldstr "two" IL_0048: ldloc.s V_5
IL_0040: call void [mscorlib]System.Console::WriteLine(string) IL_004a: ldstr "Name3"
IL_0045: ldstr "three" IL_004f: call bool [mscorlib]System.String::op_Equality(string,
IL_004a: call void [mscorlib]System.Console::WriteLine(string) string)
IL_004f: ret IL_0054: brtrue.s IL_00a6
IL_0050: ldstr "four" IL_0056: ldloc.s V_5
IL_0055: call void [mscorlib]System.Console::WriteLine(string) IL_0058: ldstr "Name4"
IL_005a: ret IL_005d: call bool [mscorlib]System.String::op_Equality(string,
string)
IL_005b: ldstr "default" IL_0062: brtrue.s IL_00b8
IL_0060: call void [mscorlib]System.Console::WriteLine(string)
IL_0065: ret IL_0064: ldloc.s V_5
} // end of method Switch::SwitchWithGoto IL_0066: ldstr "Name5"
IL_006b: call bool [mscorlib]System.String::op_Equality(string,
string)
IL_0070: brtrue.s IL_00ca
IL_0072: ldloc.s V_5
IL_0074: ldstr "Name6"
IL_0079: 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<class ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/SetProperty>::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<class ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/SetProperty>::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<class ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/SetProperty>::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<class ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/SetProperty>::Add(!0)
IL_00c8: br.s IL_00dc
IL_00ca: ldloc.0
IL_00cb: ldloc.s V_4
IL_00cd: callvirt instance void class [mscorlib]System.Collections.Generic.List`1<class ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/SetProperty>::Add(!0)
IL_00d2: br.s IL_00dc
IL_00d4: ldloc.1
IL_00d5: ldloc.s V_4
IL_00d7: callvirt instance void class [mscorlib]System.Collections.Generic.List`1<class ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/SetProperty>::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
} // end of method Switch::SwitchOnStringInForLoop
} // end of class ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch } // end of class ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch

533
ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.roslyn.il

@ -25,14 +25,14 @@
.ver 0:0:0:0 .ver 0:0:0:0
} }
.module Switch.dll .module Switch.dll
// MVID: {7C3CB7C3-DBBF-4EB8-ACC1-E7AFA899FD3B} // MVID: {134EA2E4-FA5A-4D44-A0FD-C4E5A18E39B1}
.custom instance void [mscorlib]System.Security.UnverifiableCodeAttribute::.ctor() = ( 01 00 00 00 ) .custom instance void [mscorlib]System.Security.UnverifiableCodeAttribute::.ctor() = ( 01 00 00 00 )
.imagebase 0x10000000 .imagebase 0x10000000
.file alignment 0x00000200 .file alignment 0x00000200
.stackreserve 0x00100000 .stackreserve 0x00100000
.subsystem 0x0003 // WINDOWS_CUI .subsystem 0x0003 // WINDOWS_CUI
.corflags 0x00000001 // ILONLY .corflags 0x00000001 // ILONLY
// Image base: 0x019E0000 // Image base: 0x00C40000
// =============== CLASS MEMBERS DECLARATION =================== // =============== CLASS MEMBERS DECLARATION ===================
@ -40,6 +40,58 @@
.class public abstract auto ansi sealed beforefieldinit ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch .class public abstract auto ansi sealed beforefieldinit ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch
extends [mscorlib]System.Object extends [mscorlib]System.Object
{ {
.class auto ansi nested public beforefieldinit SetProperty
extends [mscorlib]System.Object
{
.field public initonly class [mscorlib]System.Reflection.PropertyInfo Property
.field private int32 '<Set>k__BackingField'
.custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 )
.custom instance void [mscorlib]System.Diagnostics.DebuggerBrowsableAttribute::.ctor(valuetype [mscorlib]System.Diagnostics.DebuggerBrowsableState) = ( 01 00 00 00 00 00 00 00 )
.method public hidebysig specialname
instance int32 get_Set() cil managed
{
.custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 )
// Code size 7 (0x7)
.maxstack 8
IL_0000: ldarg.0
IL_0001: ldfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/SetProperty::'<Set>k__BackingField'
IL_0006: ret
} // end of method SetProperty::get_Set
.method public hidebysig specialname
instance void set_Set(int32 'value') cil managed
{
.custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 )
// Code size 8 (0x8)
.maxstack 8
IL_0000: ldarg.0
IL_0001: ldarg.1
IL_0002: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/SetProperty::'<Set>k__BackingField'
IL_0007: ret
} // end of method SetProperty::set_Set
.method public hidebysig specialname rtspecialname
instance void .ctor(class [mscorlib]System.Reflection.PropertyInfo 'property') cil managed
{
// Code size 16 (0x10)
.maxstack 8
IL_0000: ldarg.0
IL_0001: call instance void [mscorlib]System.Object::.ctor()
IL_0006: nop
IL_0007: nop
IL_0008: ldarg.0
IL_0009: ldarg.1
IL_000a: stfld class [mscorlib]System.Reflection.PropertyInfo ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/SetProperty::Property
IL_000f: ret
} // end of method SetProperty::.ctor
.property instance int32 Set()
{
.get instance int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/SetProperty::get_Set()
.set instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/SetProperty::set_Set(int32)
} // end of property SetProperty::Set
} // end of class SetProperty
.method public hidebysig static string .method public hidebysig static string
SparseIntegerSwitch(int32 i) cil managed SparseIntegerSwitch(int32 i) cil managed
{ {
@ -177,280 +229,6 @@
IL_00ed: ret IL_00ed: ret
} // end of method Switch::SparseIntegerSwitch } // end of method Switch::SparseIntegerSwitch
.method public hidebysig static string
SwitchOverNullableInt(valuetype [mscorlib]System.Nullable`1<int32> i) cil managed
{
// Code size 82 (0x52)
.maxstack 2
.locals init (valuetype [mscorlib]System.Nullable`1<int32> V_0,
valuetype [mscorlib]System.Nullable`1<int32> V_1,
int32 V_2,
string V_3)
IL_0000: nop
IL_0001: ldarg.0
IL_0002: stloc.1
IL_0003: ldloc.1
IL_0004: stloc.0
IL_0005: ldloca.s V_0
IL_0007: call instance bool valuetype [mscorlib]System.Nullable`1<int32>::get_HasValue()
IL_000c: brfalse.s IL_0028
IL_000e: ldloca.s V_0
IL_0010: call instance !0 valuetype [mscorlib]System.Nullable`1<int32>::GetValueOrDefault()
IL_0015: stloc.2
IL_0016: ldloc.2
IL_0017: brfalse.s IL_0030
IL_0019: br.s IL_001b
IL_001b: ldloc.2
IL_001c: ldc.i4.5
IL_001d: beq.s IL_0038
IL_001f: br.s IL_0021
IL_0021: ldloc.2
IL_0022: ldc.i4.s 10
IL_0024: beq.s IL_0040
IL_0026: br.s IL_0048
IL_0028: ldstr "null"
IL_002d: stloc.3
IL_002e: br.s IL_0050
IL_0030: ldstr "zero"
IL_0035: stloc.3
IL_0036: br.s IL_0050
IL_0038: ldstr "five"
IL_003d: stloc.3
IL_003e: br.s IL_0050
IL_0040: ldstr "ten"
IL_0045: stloc.3
IL_0046: br.s IL_0050
IL_0048: ldstr "large"
IL_004d: stloc.3
IL_004e: br.s IL_0050
IL_0050: ldloc.3
IL_0051: ret
} // end of method Switch::SwitchOverNullableInt
.method public hidebysig static string
SwitchOverNullableIntShifted(valuetype [mscorlib]System.Nullable`1<int32> i) cil managed
{
// Code size 127 (0x7f)
.maxstack 2
.locals init (valuetype [mscorlib]System.Nullable`1<int32> V_0,
valuetype [mscorlib]System.Nullable`1<int32> V_1,
valuetype [mscorlib]System.Nullable`1<int32> V_2,
valuetype [mscorlib]System.Nullable`1<int32> V_3,
int32 V_4,
string V_5)
IL_0000: nop
IL_0001: ldarg.0
IL_0002: stloc.2
IL_0003: ldloca.s V_2
IL_0005: call instance bool valuetype [mscorlib]System.Nullable`1<int32>::get_HasValue()
IL_000a: brtrue.s IL_0017
IL_000c: ldloca.s V_3
IL_000e: initobj valuetype [mscorlib]System.Nullable`1<int32>
IL_0014: ldloc.3
IL_0015: br.s IL_0025
IL_0017: ldloca.s V_2
IL_0019: call instance !0 valuetype [mscorlib]System.Nullable`1<int32>::GetValueOrDefault()
IL_001e: ldc.i4.5
IL_001f: add
IL_0020: newobj instance void valuetype [mscorlib]System.Nullable`1<int32>::.ctor(!0)
IL_0025: stloc.1
IL_0026: ldloc.1
IL_0027: stloc.0
IL_0028: ldloca.s V_0
IL_002a: call instance bool valuetype [mscorlib]System.Nullable`1<int32>::get_HasValue()
IL_002f: brfalse.s IL_004f
IL_0031: ldloca.s V_0
IL_0033: call instance !0 valuetype [mscorlib]System.Nullable`1<int32>::GetValueOrDefault()
IL_0038: stloc.s V_4
IL_003a: ldloc.s V_4
IL_003c: brfalse.s IL_0058
IL_003e: br.s IL_0040
IL_0040: ldloc.s V_4
IL_0042: ldc.i4.5
IL_0043: beq.s IL_0061
IL_0045: br.s IL_0047
IL_0047: ldloc.s V_4
IL_0049: ldc.i4.s 10
IL_004b: beq.s IL_006a
IL_004d: br.s IL_0073
IL_004f: ldstr "null"
IL_0054: stloc.s V_5
IL_0056: br.s IL_007c
IL_0058: ldstr "zero"
IL_005d: stloc.s V_5
IL_005f: br.s IL_007c
IL_0061: ldstr "five"
IL_0066: stloc.s V_5
IL_0068: br.s IL_007c
IL_006a: ldstr "ten"
IL_006f: stloc.s V_5
IL_0071: br.s IL_007c
IL_0073: ldstr "large"
IL_0078: stloc.s V_5
IL_007a: br.s IL_007c
IL_007c: ldloc.s V_5
IL_007e: ret
} // end of method Switch::SwitchOverNullableIntShifted
.method public hidebysig static string
SwitchOverNullableIntNoNullCase(valuetype [mscorlib]System.Nullable`1<int32> i) cil managed
{
// Code size 74 (0x4a)
.maxstack 2
.locals init (valuetype [mscorlib]System.Nullable`1<int32> V_0,
valuetype [mscorlib]System.Nullable`1<int32> V_1,
int32 V_2,
string V_3)
IL_0000: nop
IL_0001: ldarg.0
IL_0002: stloc.1
IL_0003: ldloc.1
IL_0004: stloc.0
IL_0005: ldloca.s V_0
IL_0007: call instance bool valuetype [mscorlib]System.Nullable`1<int32>::get_HasValue()
IL_000c: brfalse.s IL_0040
IL_000e: ldloca.s V_0
IL_0010: call instance !0 valuetype [mscorlib]System.Nullable`1<int32>::GetValueOrDefault()
IL_0015: stloc.2
IL_0016: ldloc.2
IL_0017: brfalse.s IL_0028
IL_0019: br.s IL_001b
IL_001b: ldloc.2
IL_001c: ldc.i4.5
IL_001d: beq.s IL_0030
IL_001f: br.s IL_0021
IL_0021: ldloc.2
IL_0022: ldc.i4.s 10
IL_0024: beq.s IL_0038
IL_0026: br.s IL_0040
IL_0028: ldstr "zero"
IL_002d: stloc.3
IL_002e: br.s IL_0048
IL_0030: ldstr "five"
IL_0035: stloc.3
IL_0036: br.s IL_0048
IL_0038: ldstr "ten"
IL_003d: stloc.3
IL_003e: br.s IL_0048
IL_0040: ldstr "other"
IL_0045: stloc.3
IL_0046: br.s IL_0048
IL_0048: ldloc.3
IL_0049: ret
} // end of method Switch::SwitchOverNullableIntNoNullCase
.method public hidebysig static string
SwitchOverNullableIntNoNullCaseShifted(valuetype [mscorlib]System.Nullable`1<int32> i) cil managed
{
// Code size 118 (0x76)
.maxstack 2
.locals init (valuetype [mscorlib]System.Nullable`1<int32> V_0,
valuetype [mscorlib]System.Nullable`1<int32> V_1,
valuetype [mscorlib]System.Nullable`1<int32> V_2,
valuetype [mscorlib]System.Nullable`1<int32> V_3,
int32 V_4,
string V_5)
IL_0000: nop
IL_0001: ldarg.0
IL_0002: stloc.2
IL_0003: ldloca.s V_2
IL_0005: call instance bool valuetype [mscorlib]System.Nullable`1<int32>::get_HasValue()
IL_000a: brtrue.s IL_0017
IL_000c: ldloca.s V_3
IL_000e: initobj valuetype [mscorlib]System.Nullable`1<int32>
IL_0014: ldloc.3
IL_0015: br.s IL_0025
IL_0017: ldloca.s V_2
IL_0019: call instance !0 valuetype [mscorlib]System.Nullable`1<int32>::GetValueOrDefault()
IL_001e: ldc.i4.5
IL_001f: add
IL_0020: newobj instance void valuetype [mscorlib]System.Nullable`1<int32>::.ctor(!0)
IL_0025: stloc.1
IL_0026: ldloc.1
IL_0027: stloc.0
IL_0028: ldloca.s V_0
IL_002a: call instance bool valuetype [mscorlib]System.Nullable`1<int32>::get_HasValue()
IL_002f: brfalse.s IL_006a
IL_0031: ldloca.s V_0
IL_0033: call instance !0 valuetype [mscorlib]System.Nullable`1<int32>::GetValueOrDefault()
IL_0038: stloc.s V_4
IL_003a: ldloc.s V_4
IL_003c: brfalse.s IL_004f
IL_003e: br.s IL_0040
IL_0040: ldloc.s V_4
IL_0042: ldc.i4.5
IL_0043: beq.s IL_0058
IL_0045: br.s IL_0047
IL_0047: ldloc.s V_4
IL_0049: ldc.i4.s 10
IL_004b: beq.s IL_0061
IL_004d: br.s IL_006a
IL_004f: ldstr "zero"
IL_0054: stloc.s V_5
IL_0056: br.s IL_0073
IL_0058: ldstr "five"
IL_005d: stloc.s V_5
IL_005f: br.s IL_0073
IL_0061: ldstr "ten"
IL_0066: stloc.s V_5
IL_0068: br.s IL_0073
IL_006a: ldstr "other"
IL_006f: stloc.s V_5
IL_0071: br.s IL_0073
IL_0073: ldloc.s V_5
IL_0075: ret
} // end of method Switch::SwitchOverNullableIntNoNullCaseShifted
.method public hidebysig static string .method public hidebysig static string
ShortSwitchOverString(string text) cil managed ShortSwitchOverString(string text) cil managed
{ {
@ -1066,63 +844,168 @@
IL_0091: ret IL_0091: ret
} // end of method Switch::SwitchInLoop } // end of method Switch::SwitchInLoop
.method public hidebysig static void SwitchWithGoto(int32 i) cil managed .method private hidebysig static class ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/SetProperty[]
GetProperties() cil managed
{ {
// Code size 122 (0x7a) // Code size 12 (0xc)
.maxstack 1
.locals init (class ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/SetProperty[] V_0)
IL_0000: nop
IL_0001: ldc.i4.0
IL_0002: newarr ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/SetProperty
IL_0007: stloc.0
IL_0008: br.s IL_000a
IL_000a: ldloc.0
IL_000b: ret
} // end of method Switch::GetProperties
.method public hidebysig static void SwitchOnStringInForLoop() cil managed
{
// Code size 265 (0x109)
.maxstack 2 .maxstack 2
.locals init (int32 V_0) .locals init (class [mscorlib]System.Collections.Generic.List`1<class ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/SetProperty> V_0,
class [mscorlib]System.Collections.Generic.List`1<class ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/SetProperty> V_1,
class ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/SetProperty[] V_2,
int32 V_3,
class ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/SetProperty V_4,
string V_5,
string V_6,
bool V_7)
IL_0000: nop IL_0000: nop
IL_0001: ldstr "SwitchWithGoto: " IL_0001: newobj instance void class [mscorlib]System.Collections.Generic.List`1<class ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/SetProperty>::.ctor()
IL_0006: ldarg.0 IL_0006: stloc.0
IL_0007: box [mscorlib]System.Int32 IL_0007: newobj instance void class [mscorlib]System.Collections.Generic.List`1<class ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/SetProperty>::.ctor()
IL_000c: call string [mscorlib]System.String::Concat(object, IL_000c: stloc.1
object) IL_000d: call class ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/SetProperty[] ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch::GetProperties()
IL_0011: call void [mscorlib]System.Console::WriteLine(string) IL_0012: stloc.2
IL_0016: nop IL_0013: ldc.i4.0
IL_0017: ldarg.0 IL_0014: stloc.3
IL_0018: stloc.0 IL_0015: br IL_00f9
IL_0019: ldloc.0
IL_001a: ldc.i4.1 IL_001a: nop
IL_001b: sub IL_001b: ldloc.2
IL_001c: switch ( IL_001c: ldloc.3
IL_0033, IL_001d: ldelem.ref
IL_0041, IL_001e: stloc.s V_4
IL_004f, IL_0020: ldloc.s V_4
IL_005d) IL_0022: ldfld class [mscorlib]System.Reflection.PropertyInfo ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/SetProperty::Property
IL_0031: br.s IL_006b IL_0027: callvirt instance string [mscorlib]System.Reflection.MemberInfo::get_Name()
IL_002c: stloc.s V_5
IL_0033: nop IL_002e: ldloc.s V_5
IL_0034: ldstr "one" IL_0030: stloc.s V_6
IL_0039: call void [mscorlib]System.Console::WriteLine(string) IL_0032: ldloc.s V_6
IL_003e: nop IL_0034: ldstr "Name1"
IL_003f: br.s IL_006b IL_0039: call bool [mscorlib]System.String::op_Equality(string,
string)
IL_003e: brtrue.s IL_0088
IL_0041: nop IL_0040: ldloc.s V_6
IL_0042: ldstr "two" IL_0042: ldstr "Name2"
IL_0047: call void [mscorlib]System.Console::WriteLine(string) IL_0047: call bool [mscorlib]System.String::op_Equality(string,
IL_004c: nop string)
IL_004d: br.s IL_004f IL_004c: brtrue.s IL_009d
IL_004f: nop IL_004e: ldloc.s V_6
IL_0050: ldstr "three" IL_0050: ldstr "Name3"
IL_0055: call void [mscorlib]System.Console::WriteLine(string) IL_0055: call bool [mscorlib]System.String::op_Equality(string,
IL_005a: nop string)
IL_005b: br.s IL_0079 IL_005a: brtrue.s IL_00b2
IL_005d: nop IL_005c: ldloc.s V_6
IL_005e: ldstr "four" IL_005e: ldstr "Name4"
IL_0063: call void [mscorlib]System.Console::WriteLine(string) IL_0063: call bool [mscorlib]System.String::op_Equality(string,
IL_0068: nop string)
IL_0069: br.s IL_0079 IL_0068: brtrue.s IL_00c7
IL_006b: nop IL_006a: ldloc.s V_6
IL_006c: ldstr "default" IL_006c: ldstr "Name5"
IL_0071: call void [mscorlib]System.Console::WriteLine(string) IL_0071: call bool [mscorlib]System.String::op_Equality(string,
IL_0076: nop string)
IL_0077: br.s IL_0079 IL_0076: brtrue.s IL_00dc
IL_0079: ret IL_0078: ldloc.s V_6
} // end of method Switch::SwitchWithGoto IL_007a: ldstr "Name6"
IL_007f: call bool [mscorlib]System.String::op_Equality(string,
string)
IL_0084: brtrue.s IL_00dc
IL_0086: br.s IL_00e8
IL_0088: nop
IL_0089: ldloc.s V_4
IL_008b: ldc.i4.1
IL_008c: callvirt instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/SetProperty::set_Set(int32)
IL_0091: nop
IL_0092: ldloc.0
IL_0093: ldloc.s V_4
IL_0095: callvirt instance void class [mscorlib]System.Collections.Generic.List`1<class ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/SetProperty>::Add(!0)
IL_009a: nop
IL_009b: br.s IL_00f4
IL_009d: nop
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: nop
IL_00a7: ldloc.0
IL_00a8: ldloc.s V_4
IL_00aa: callvirt instance void class [mscorlib]System.Collections.Generic.List`1<class ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/SetProperty>::Add(!0)
IL_00af: nop
IL_00b0: br.s IL_00f4
IL_00b2: nop
IL_00b3: ldloc.s V_4
IL_00b5: ldc.i4.3
IL_00b6: callvirt instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/SetProperty::set_Set(int32)
IL_00bb: nop
IL_00bc: ldloc.0
IL_00bd: ldloc.s V_4
IL_00bf: callvirt instance void class [mscorlib]System.Collections.Generic.List`1<class ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/SetProperty>::Add(!0)
IL_00c4: nop
IL_00c5: br.s IL_00f4
IL_00c7: nop
IL_00c8: ldloc.s V_4
IL_00ca: ldc.i4.4
IL_00cb: callvirt instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/SetProperty::set_Set(int32)
IL_00d0: nop
IL_00d1: ldloc.0
IL_00d2: ldloc.s V_4
IL_00d4: callvirt instance void class [mscorlib]System.Collections.Generic.List`1<class ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/SetProperty>::Add(!0)
IL_00d9: nop
IL_00da: br.s IL_00f4
IL_00dc: nop
IL_00dd: ldloc.0
IL_00de: ldloc.s V_4
IL_00e0: callvirt instance void class [mscorlib]System.Collections.Generic.List`1<class ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/SetProperty>::Add(!0)
IL_00e5: nop
IL_00e6: br.s IL_00f4
IL_00e8: nop
IL_00e9: ldloc.1
IL_00ea: ldloc.s V_4
IL_00ec: callvirt instance void class [mscorlib]System.Collections.Generic.List`1<class ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/SetProperty>::Add(!0)
IL_00f1: nop
IL_00f2: br.s IL_00f4
IL_00f4: nop
IL_00f5: ldloc.3
IL_00f6: ldc.i4.1
IL_00f7: add
IL_00f8: stloc.3
IL_00f9: ldloc.3
IL_00fa: ldloc.2
IL_00fb: ldlen
IL_00fc: conv.i4
IL_00fd: clt
IL_00ff: stloc.s V_7
IL_0101: ldloc.s V_7
IL_0103: brtrue IL_001a
IL_0108: ret
} // end of method Switch::SwitchOnStringInForLoop
} // end of class ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch } // end of class ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch

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

@ -123,9 +123,14 @@ namespace ICSharpCode.Decompiler.IL.Transforms
if (values.Count == 0) if (values.Count == 0)
return false; return false;
// All case blocks must either leave the current block container or branch to the same block after the switch statement. // All case blocks must either leave the current block container or branch to the same block after the switch statement.
if (!(values.All(b => ExtractLastJumpFromBlock(b.Item2, out var nextExit) && IsExitBlock(nextExit, container)) || if (exitBlock == null) {
(exitBlock == null && values.All(b => ExtractLastLeaveFromBlock(b.Item2, container))))) if (!values.All(b => ExtractLastLeaveFromBlock(b.Item2, container)))
return false; return false;
} else {
// Compare blocks by label as duplicated blocks should have the same label.
if (!(values.All(b => ExtractLastJumpFromBlock(b.Item2, out var nextExitBlock) && nextExitBlock.Label == exitBlock.Label)))
return false;
}
// if the block after the switch has the correct number of branches, generate the switch statement // if the block after the switch has the correct number of branches, generate the switch statement
// and return it and the block. // and return it and the block.
if (currentCaseBlock.IncomingEdgeCount == (isLegacy ? 2 : 1)) { if (currentCaseBlock.IncomingEdgeCount == (isLegacy ? 2 : 1)) {
@ -139,13 +144,6 @@ namespace ICSharpCode.Decompiler.IL.Transforms
return false; return false;
} }
bool IsExitBlock(Block nextExit, BlockContainer container)
{
if (nextExit.Instructions.Count != 1)
return false;
return nextExit.Instructions[0].MatchLeave(container, out _);
}
bool ExtractLastJumpFromBlock(Block block, out Block exitBlock) bool ExtractLastJumpFromBlock(Block block, out Block exitBlock)
{ {
exitBlock = null; exitBlock = null;

Loading…
Cancel
Save