Browse Source

Fix #917: InvalidCastException: Cast from Int64 to Boolean not supported.

pull/909/merge
Siegfried Pammer 8 years ago
parent
commit
086325afdf
  1. 35
      ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.cs
  2. 83
      ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.il
  3. 75
      ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.opt.il
  4. 51
      ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.opt.roslyn.il
  5. 64
      ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.roslyn.il
  6. 6
      ICSharpCode.Decompiler/CSharp/StatementBuilder.cs

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

@ -39,6 +39,41 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -39,6 +39,41 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
}
}
public enum State
{
False = 0,
True = 1,
Null = 2
}
public static State SwitchOverNullableBool(bool? value)
{
switch (value) {
case false:
return State.False;
case true:
return State.True;
case null:
return State.Null;
default:
throw new InvalidOperationException();
}
}
//public static bool? SwitchOverNullableEnum(State? state)
//{
// switch (state) {
// case State.False:
// return false;
// case State.True:
// return true;
// case State.Null:
// return null;
// default:
// throw new InvalidOperationException();
// }
//}
public static string SparseIntegerSwitch(int i)
{
Console.WriteLine("SparseIntegerSwitch: " + i);

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

@ -10,7 +10,7 @@ @@ -10,7 +10,7 @@
.publickeytoken = (B7 7A 5C 56 19 34 E0 89 ) // .z\V.4..
.ver 4:0:0:0
}
.assembly '4doqvnxq'
.assembly mhfw1ujx
{
.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 @@ @@ -20,15 +20,15 @@
.hash algorithm 0x00008004
.ver 0:0:0:0
}
.module '4doqvnxq.dll'
// MVID: {5E65DF13-3C5E-44CA-97E7-5B58ACBAF9BF}
.module mhfw1ujx.dll
// MVID: {2E35825E-3352-4C5E-B230-3B3F7055B304}
.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: 0x03320000
// Image base: 0x005A0000
// =============== CLASS MEMBERS DECLARATION ===================
@ -93,6 +93,55 @@ @@ -93,6 +93,55 @@
} // end of property SetProperty::Set
} // end of class SetProperty
.class auto ansi sealed nested public State
extends [mscorlib]System.Enum
{
.field public specialname rtspecialname int32 value__
.field public static literal valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/State False = int32(0x00000000)
.field public static literal valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/State True = int32(0x00000001)
.field public static literal valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/State Null = int32(0x00000002)
} // end of class State
.method public hidebysig static valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/State
SwitchOverNullableBool(valuetype [mscorlib]System.Nullable`1<bool> 'value') cil managed
{
// Code size 53 (0x35)
.maxstack 2
.locals init (valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/State V_0,
bool V_1)
IL_0000: nop
IL_0001: ldarga.s 'value'
IL_0003: dup
IL_0004: call instance !0 valuetype [mscorlib]System.Nullable`1<bool>::GetValueOrDefault()
IL_0009: stloc.1
IL_000a: call instance bool valuetype [mscorlib]System.Nullable`1<bool>::get_HasValue()
IL_000f: brfalse.s IL_0029
IL_0011: ldloc.1
IL_0012: switch (
IL_0021,
IL_0025)
IL_001f: br.s IL_002d
IL_0021: ldc.i4.0
IL_0022: stloc.0
IL_0023: br.s IL_0033
IL_0025: ldc.i4.1
IL_0026: stloc.0
IL_0027: br.s IL_0033
IL_0029: ldc.i4.2
IL_002a: stloc.0
IL_002b: br.s IL_0033
IL_002d: newobj instance void [mscorlib]System.InvalidOperationException::.ctor()
IL_0032: throw
IL_0033: ldloc.0
IL_0034: ret
} // end of method Switch::SwitchOverNullableBool
.method public hidebysig static string
SparseIntegerSwitch(int32 i) cil managed
{
@ -785,7 +834,7 @@ @@ -785,7 +834,7 @@
IL_0015: brfalse IL_00e9
IL_001a: volatile.
IL_001c: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2<string,int32> '<PrivateImplementationDetails>{5E65DF13-3C5E-44CA-97E7-5B58ACBAF9BF}'::'$$method0x600000b-1'
IL_001c: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2<string,int32> '<PrivateImplementationDetails>{2E35825E-3352-4C5E-B230-3B3F7055B304}'::'$$method0x600000c-1'
IL_0021: brtrue.s IL_0084
IL_0023: ldc.i4.7
@ -826,9 +875,9 @@ @@ -826,9 +875,9 @@
IL_0078: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2<string,int32>::Add(!0,
!1)
IL_007d: volatile.
IL_007f: stsfld class [mscorlib]System.Collections.Generic.Dictionary`2<string,int32> '<PrivateImplementationDetails>{5E65DF13-3C5E-44CA-97E7-5B58ACBAF9BF}'::'$$method0x600000b-1'
IL_007f: stsfld class [mscorlib]System.Collections.Generic.Dictionary`2<string,int32> '<PrivateImplementationDetails>{2E35825E-3352-4C5E-B230-3B3F7055B304}'::'$$method0x600000c-1'
IL_0084: volatile.
IL_0086: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2<string,int32> '<PrivateImplementationDetails>{5E65DF13-3C5E-44CA-97E7-5B58ACBAF9BF}'::'$$method0x600000b-1'
IL_0086: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2<string,int32> '<PrivateImplementationDetails>{2E35825E-3352-4C5E-B230-3B3F7055B304}'::'$$method0x600000c-1'
IL_008b: ldloc.1
IL_008c: ldloca.s V_2
IL_008e: call instance bool class [mscorlib]System.Collections.Generic.Dictionary`2<string,int32>::TryGetValue(!0,
@ -900,7 +949,7 @@ @@ -900,7 +949,7 @@
IL_0013: brfalse IL_0158
IL_0018: volatile.
IL_001a: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2<string,int32> '<PrivateImplementationDetails>{5E65DF13-3C5E-44CA-97E7-5B58ACBAF9BF}'::'$$method0x600000c-1'
IL_001a: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2<string,int32> '<PrivateImplementationDetails>{2E35825E-3352-4C5E-B230-3B3F7055B304}'::'$$method0x600000d-1'
IL_001f: brtrue IL_00b8
IL_0024: ldc.i4.s 11
@ -961,9 +1010,9 @@ @@ -961,9 +1010,9 @@
IL_00ac: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2<string,int32>::Add(!0,
!1)
IL_00b1: volatile.
IL_00b3: stsfld class [mscorlib]System.Collections.Generic.Dictionary`2<string,int32> '<PrivateImplementationDetails>{5E65DF13-3C5E-44CA-97E7-5B58ACBAF9BF}'::'$$method0x600000c-1'
IL_00b3: stsfld class [mscorlib]System.Collections.Generic.Dictionary`2<string,int32> '<PrivateImplementationDetails>{2E35825E-3352-4C5E-B230-3B3F7055B304}'::'$$method0x600000d-1'
IL_00b8: volatile.
IL_00ba: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2<string,int32> '<PrivateImplementationDetails>{5E65DF13-3C5E-44CA-97E7-5B58ACBAF9BF}'::'$$method0x600000c-1'
IL_00ba: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2<string,int32> '<PrivateImplementationDetails>{2E35825E-3352-4C5E-B230-3B3F7055B304}'::'$$method0x600000d-1'
IL_00bf: ldloc.1
IL_00c0: ldloca.s V_2
IL_00c2: call instance bool class [mscorlib]System.Collections.Generic.Dictionary`2<string,int32>::TryGetValue(!0,
@ -1248,7 +1297,7 @@ @@ -1248,7 +1297,7 @@
IL_0030: brfalse IL_0121
IL_0035: volatile.
IL_0037: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2<string,int32> '<PrivateImplementationDetails>{5E65DF13-3C5E-44CA-97E7-5B58ACBAF9BF}'::'$$method0x6000011-1'
IL_0037: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2<string,int32> '<PrivateImplementationDetails>{2E35825E-3352-4C5E-B230-3B3F7055B304}'::'$$method0x6000012-1'
IL_003c: brtrue.s IL_0093
IL_003e: ldc.i4.6
@ -1284,9 +1333,9 @@ @@ -1284,9 +1333,9 @@
IL_0087: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2<string,int32>::Add(!0,
!1)
IL_008c: volatile.
IL_008e: stsfld class [mscorlib]System.Collections.Generic.Dictionary`2<string,int32> '<PrivateImplementationDetails>{5E65DF13-3C5E-44CA-97E7-5B58ACBAF9BF}'::'$$method0x6000011-1'
IL_008e: stsfld class [mscorlib]System.Collections.Generic.Dictionary`2<string,int32> '<PrivateImplementationDetails>{2E35825E-3352-4C5E-B230-3B3F7055B304}'::'$$method0x6000012-1'
IL_0093: volatile.
IL_0095: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2<string,int32> '<PrivateImplementationDetails>{5E65DF13-3C5E-44CA-97E7-5B58ACBAF9BF}'::'$$method0x6000011-1'
IL_0095: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2<string,int32> '<PrivateImplementationDetails>{2E35825E-3352-4C5E-B230-3B3F7055B304}'::'$$method0x6000012-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<string,int32>::TryGetValue(!0,
@ -1513,14 +1562,14 @@ @@ -1513,14 +1562,14 @@
} // end of class ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch
.class private auto ansi '<PrivateImplementationDetails>{5E65DF13-3C5E-44CA-97E7-5B58ACBAF9BF}'
.class private auto ansi '<PrivateImplementationDetails>{2E35825E-3352-4C5E-B230-3B3F7055B304}'
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<string,int32> '$$method0x600000b-1'
.field static assembly class [mscorlib]System.Collections.Generic.Dictionary`2<string,int32> '$$method0x600000c-1'
.field static assembly class [mscorlib]System.Collections.Generic.Dictionary`2<string,int32> '$$method0x6000011-1'
} // end of class '<PrivateImplementationDetails>{5E65DF13-3C5E-44CA-97E7-5B58ACBAF9BF}'
.field static assembly class [mscorlib]System.Collections.Generic.Dictionary`2<string,int32> '$$method0x600000d-1'
.field static assembly class [mscorlib]System.Collections.Generic.Dictionary`2<string,int32> '$$method0x6000012-1'
} // end of class '<PrivateImplementationDetails>{2E35825E-3352-4C5E-B230-3B3F7055B304}'
// =============================================================

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

@ -10,7 +10,7 @@ @@ -10,7 +10,7 @@
.publickeytoken = (B7 7A 5C 56 19 34 E0 89 ) // .z\V.4..
.ver 4:0:0:0
}
.assembly jfao3dmb
.assembly okac2jza
{
.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 @@ @@ -20,15 +20,15 @@
.hash algorithm 0x00008004
.ver 0:0:0:0
}
.module jfao3dmb.dll
// MVID: {96F356C7-71A4-48B4-BE55-B48554E94654}
.module okac2jza.dll
// MVID: {7ED4313F-4304-4C85-87F6-5AD4A6E6AA1F}
.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: 0x01900000
// Image base: 0x01A40000
// =============== CLASS MEMBERS DECLARATION ===================
@ -85,6 +85,47 @@ @@ -85,6 +85,47 @@
} // end of property SetProperty::Set
} // end of class SetProperty
.class auto ansi sealed nested public State
extends [mscorlib]System.Enum
{
.field public specialname rtspecialname int32 value__
.field public static literal valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/State False = int32(0x00000000)
.field public static literal valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/State True = int32(0x00000001)
.field public static literal valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/State Null = int32(0x00000002)
} // end of class State
.method public hidebysig static valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/State
SwitchOverNullableBool(valuetype [mscorlib]System.Nullable`1<bool> 'value') cil managed
{
// Code size 44 (0x2c)
.maxstack 2
.locals init (bool V_0)
IL_0000: ldarga.s 'value'
IL_0002: dup
IL_0003: call instance !0 valuetype [mscorlib]System.Nullable`1<bool>::GetValueOrDefault()
IL_0008: stloc.0
IL_0009: call instance bool valuetype [mscorlib]System.Nullable`1<bool>::get_HasValue()
IL_000e: brfalse.s IL_0024
IL_0010: ldloc.0
IL_0011: switch (
IL_0020,
IL_0022)
IL_001e: br.s IL_0026
IL_0020: ldc.i4.0
IL_0021: ret
IL_0022: ldc.i4.1
IL_0023: ret
IL_0024: ldc.i4.2
IL_0025: ret
IL_0026: newobj instance void [mscorlib]System.InvalidOperationException::.ctor()
IL_002b: throw
} // end of method Switch::SwitchOverNullableBool
.method public hidebysig static string
SparseIntegerSwitch(int32 i) cil managed
{
@ -670,7 +711,7 @@ @@ -670,7 +711,7 @@
IL_0013: brfalse IL_00db
IL_0018: volatile.
IL_001a: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2<string,int32> '<PrivateImplementationDetails>{96F356C7-71A4-48B4-BE55-B48554E94654}'::'$$method0x600000b-1'
IL_001a: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2<string,int32> '<PrivateImplementationDetails>{7ED4313F-4304-4C85-87F6-5AD4A6E6AA1F}'::'$$method0x600000c-1'
IL_001f: brtrue.s IL_0082
IL_0021: ldc.i4.7
@ -711,9 +752,9 @@ @@ -711,9 +752,9 @@
IL_0076: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2<string,int32>::Add(!0,
!1)
IL_007b: volatile.
IL_007d: stsfld class [mscorlib]System.Collections.Generic.Dictionary`2<string,int32> '<PrivateImplementationDetails>{96F356C7-71A4-48B4-BE55-B48554E94654}'::'$$method0x600000b-1'
IL_007d: stsfld class [mscorlib]System.Collections.Generic.Dictionary`2<string,int32> '<PrivateImplementationDetails>{7ED4313F-4304-4C85-87F6-5AD4A6E6AA1F}'::'$$method0x600000c-1'
IL_0082: volatile.
IL_0084: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2<string,int32> '<PrivateImplementationDetails>{96F356C7-71A4-48B4-BE55-B48554E94654}'::'$$method0x600000b-1'
IL_0084: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2<string,int32> '<PrivateImplementationDetails>{7ED4313F-4304-4C85-87F6-5AD4A6E6AA1F}'::'$$method0x600000c-1'
IL_0089: ldloc.0
IL_008a: ldloca.s V_1
IL_008c: call instance bool class [mscorlib]System.Collections.Generic.Dictionary`2<string,int32>::TryGetValue(!0,
@ -771,7 +812,7 @@ @@ -771,7 +812,7 @@
IL_0011: brfalse IL_013d
IL_0016: volatile.
IL_0018: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2<string,int32> '<PrivateImplementationDetails>{96F356C7-71A4-48B4-BE55-B48554E94654}'::'$$method0x600000c-1'
IL_0018: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2<string,int32> '<PrivateImplementationDetails>{7ED4313F-4304-4C85-87F6-5AD4A6E6AA1F}'::'$$method0x600000d-1'
IL_001d: brtrue IL_00b6
IL_0022: ldc.i4.s 11
@ -832,9 +873,9 @@ @@ -832,9 +873,9 @@
IL_00aa: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2<string,int32>::Add(!0,
!1)
IL_00af: volatile.
IL_00b1: stsfld class [mscorlib]System.Collections.Generic.Dictionary`2<string,int32> '<PrivateImplementationDetails>{96F356C7-71A4-48B4-BE55-B48554E94654}'::'$$method0x600000c-1'
IL_00b1: stsfld class [mscorlib]System.Collections.Generic.Dictionary`2<string,int32> '<PrivateImplementationDetails>{7ED4313F-4304-4C85-87F6-5AD4A6E6AA1F}'::'$$method0x600000d-1'
IL_00b6: volatile.
IL_00b8: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2<string,int32> '<PrivateImplementationDetails>{96F356C7-71A4-48B4-BE55-B48554E94654}'::'$$method0x600000c-1'
IL_00b8: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2<string,int32> '<PrivateImplementationDetails>{7ED4313F-4304-4C85-87F6-5AD4A6E6AA1F}'::'$$method0x600000d-1'
IL_00bd: ldloc.0
IL_00be: ldloca.s V_1
IL_00c0: call instance bool class [mscorlib]System.Collections.Generic.Dictionary`2<string,int32>::TryGetValue(!0,
@ -1058,7 +1099,7 @@ @@ -1058,7 +1099,7 @@
IL_002d: brfalse IL_0115
IL_0032: volatile.
IL_0034: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2<string,int32> '<PrivateImplementationDetails>{96F356C7-71A4-48B4-BE55-B48554E94654}'::'$$method0x6000011-1'
IL_0034: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2<string,int32> '<PrivateImplementationDetails>{7ED4313F-4304-4C85-87F6-5AD4A6E6AA1F}'::'$$method0x6000012-1'
IL_0039: brtrue.s IL_0090
IL_003b: ldc.i4.6
@ -1094,9 +1135,9 @@ @@ -1094,9 +1135,9 @@
IL_0084: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2<string,int32>::Add(!0,
!1)
IL_0089: volatile.
IL_008b: stsfld class [mscorlib]System.Collections.Generic.Dictionary`2<string,int32> '<PrivateImplementationDetails>{96F356C7-71A4-48B4-BE55-B48554E94654}'::'$$method0x6000011-1'
IL_008b: stsfld class [mscorlib]System.Collections.Generic.Dictionary`2<string,int32> '<PrivateImplementationDetails>{7ED4313F-4304-4C85-87F6-5AD4A6E6AA1F}'::'$$method0x6000012-1'
IL_0090: volatile.
IL_0092: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2<string,int32> '<PrivateImplementationDetails>{96F356C7-71A4-48B4-BE55-B48554E94654}'::'$$method0x6000011-1'
IL_0092: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2<string,int32> '<PrivateImplementationDetails>{7ED4313F-4304-4C85-87F6-5AD4A6E6AA1F}'::'$$method0x6000012-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<string,int32>::TryGetValue(!0,
@ -1290,14 +1331,14 @@ @@ -1290,14 +1331,14 @@
} // end of class ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch
.class private auto ansi '<PrivateImplementationDetails>{96F356C7-71A4-48B4-BE55-B48554E94654}'
.class private auto ansi '<PrivateImplementationDetails>{7ED4313F-4304-4C85-87F6-5AD4A6E6AA1F}'
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<string,int32> '$$method0x600000b-1'
.field static assembly class [mscorlib]System.Collections.Generic.Dictionary`2<string,int32> '$$method0x600000c-1'
.field static assembly class [mscorlib]System.Collections.Generic.Dictionary`2<string,int32> '$$method0x6000011-1'
} // end of class '<PrivateImplementationDetails>{96F356C7-71A4-48B4-BE55-B48554E94654}'
.field static assembly class [mscorlib]System.Collections.Generic.Dictionary`2<string,int32> '$$method0x600000d-1'
.field static assembly class [mscorlib]System.Collections.Generic.Dictionary`2<string,int32> '$$method0x6000012-1'
} // end of class '<PrivateImplementationDetails>{7ED4313F-4304-4C85-87F6-5AD4A6E6AA1F}'
// =============================================================

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

@ -25,14 +25,14 @@ @@ -25,14 +25,14 @@
.ver 0:0:0:0
}
.module Switch.dll
// MVID: {4366DF41-DCD0-42E1-B99D-7B67787ECEA9}
// MVID: {6F3B5958-B8BE-48C6-82B8-5D3026DEACD1}
.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: 0x00690000
// Image base: 0x03160000
// =============== CLASS MEMBERS DECLARATION ===================
@ -89,6 +89,53 @@ @@ -89,6 +89,53 @@
} // end of property SetProperty::Set
} // end of class SetProperty
.class auto ansi sealed nested public State
extends [mscorlib]System.Enum
{
.field public specialname rtspecialname int32 value__
.field public static literal valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/State False = int32(0x00000000)
.field public static literal valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/State True = int32(0x00000001)
.field public static literal valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/State Null = int32(0x00000002)
} // end of class State
.method public hidebysig static valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/State
SwitchOverNullableBool(valuetype [mscorlib]System.Nullable`1<bool> 'value') cil managed
{
// Code size 40 (0x28)
.maxstack 2
.locals init (valuetype [mscorlib]System.Nullable`1<bool> V_0,
bool 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<bool>::get_HasValue()
IL_0009: brfalse.s IL_0020
IL_000b: ldloca.s V_0
IL_000d: call instance !0 valuetype [mscorlib]System.Nullable`1<bool>::GetValueOrDefault()
IL_0012: stloc.1
IL_0013: ldloc.1
IL_0014: brfalse.s IL_001c
IL_0016: ldloc.1
IL_0017: ldc.i4.1
IL_0018: beq.s IL_001e
IL_001a: br.s IL_0022
IL_001c: ldc.i4.0
IL_001d: ret
IL_001e: ldc.i4.1
IL_001f: ret
IL_0020: ldc.i4.2
IL_0021: ret
IL_0022: newobj instance void [mscorlib]System.InvalidOperationException::.ctor()
IL_0027: throw
} // end of method Switch::SwitchOverNullableBool
.method public hidebysig static string
SparseIntegerSwitch(int32 i) cil managed
{

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

@ -25,14 +25,14 @@ @@ -25,14 +25,14 @@
.ver 0:0:0:0
}
.module Switch.dll
// MVID: {0EBEAA6B-55A7-4255-9CA2-CE888E0F54BA}
// MVID: {7ADDBD28-42D6-469D-B92D-065C803347D0}
.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: 0x00690000
// Image base: 0x00C40000
// =============== CLASS MEMBERS DECLARATION ===================
@ -92,6 +92,66 @@ @@ -92,6 +92,66 @@
} // end of property SetProperty::Set
} // end of class SetProperty
.class auto ansi sealed nested public State
extends [mscorlib]System.Enum
{
.field public specialname rtspecialname int32 value__
.field public static literal valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/State False = int32(0x00000000)
.field public static literal valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/State True = int32(0x00000001)
.field public static literal valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/State Null = int32(0x00000002)
} // end of class State
.method public hidebysig static valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/State
SwitchOverNullableBool(valuetype [mscorlib]System.Nullable`1<bool> 'value') cil managed
{
// Code size 53 (0x35)
.maxstack 2
.locals init (valuetype [mscorlib]System.Nullable`1<bool> V_0,
valuetype [mscorlib]System.Nullable`1<bool> V_1,
bool V_2,
valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch/State 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<bool>::get_HasValue()
IL_000c: brfalse.s IL_0029
IL_000e: ldloca.s V_0
IL_0010: call instance !0 valuetype [mscorlib]System.Nullable`1<bool>::GetValueOrDefault()
IL_0015: stloc.2
IL_0016: ldloc.2
IL_0017: brfalse.s IL_0021
IL_0019: br.s IL_001b
IL_001b: ldloc.2
IL_001c: ldc.i4.1
IL_001d: beq.s IL_0025
IL_001f: br.s IL_002d
IL_0021: ldc.i4.0
IL_0022: stloc.3
IL_0023: br.s IL_0033
IL_0025: ldc.i4.1
IL_0026: stloc.3
IL_0027: br.s IL_0033
IL_0029: ldc.i4.2
IL_002a: stloc.3
IL_002b: br.s IL_0033
IL_002d: newobj instance void [mscorlib]System.InvalidOperationException::.ctor()
IL_0032: throw
IL_0033: ldloc.3
IL_0034: ret
} // end of method Switch::SwitchOverNullableBool
.method public hidebysig static string
SparseIntegerSwitch(int32 i) cil managed
{

6
ICSharpCode.Decompiler/CSharp/StatementBuilder.cs

@ -86,6 +86,9 @@ namespace ICSharpCode.Decompiler.CSharp @@ -86,6 +86,9 @@ namespace ICSharpCode.Decompiler.CSharp
ConstantResolveResult CreateTypedCaseLabel(long i, IType type, string[] map = null)
{
object value;
// unpack nullable type, if necessary:
// we need to do this in all cases, because there are nullable bools and enum types as well.
type = NullableType.GetUnderlyingType(type);
if (type.IsKnownType(KnownTypeCode.Boolean)) {
value = i != 0;
} else if (type.IsKnownType(KnownTypeCode.String) && map != null) {
@ -93,9 +96,6 @@ namespace ICSharpCode.Decompiler.CSharp @@ -93,9 +96,6 @@ namespace ICSharpCode.Decompiler.CSharp
} else if (type.Kind == TypeKind.Enum) {
var enumType = type.GetDefinition().EnumUnderlyingType;
value = CSharpPrimitiveCast.Cast(ReflectionHelper.GetTypeCode(enumType), i, false);
} else if (type.IsKnownType(KnownTypeCode.NullableOfT)) {
var nullableType = NullableType.GetUnderlyingType(type);
value = CSharpPrimitiveCast.Cast(ReflectionHelper.GetTypeCode(nullableType), i, false);
} else {
value = CSharpPrimitiveCast.Cast(ReflectionHelper.GetTypeCode(type), i, false);
}

Loading…
Cancel
Save