Browse Source

Fix #1084: Decompiling constants of the target type

pull/1087/head
Siegfried Pammer 7 years ago
parent
commit
eac591a7d7
  1. 2
      ICSharpCode.Decompiler.Tests/CustomAttributes/S_CustomAttributes.cs
  2. 1
      ICSharpCode.Decompiler.Tests/ICSharpCode.Decompiler.Tests.csproj
  3. 6
      ICSharpCode.Decompiler.Tests/PrettyTestRunner.cs
  4. 2
      ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.cs
  5. 34
      ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.il
  6. 34
      ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.opt.il
  7. 4
      ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.opt.roslyn.il
  8. 4
      ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.roslyn.il
  9. 68
      ICSharpCode.Decompiler.Tests/TestCases/Pretty/WellKnownConstants.cs
  10. 131
      ICSharpCode.Decompiler.Tests/TestCases/Pretty/WellKnownConstants.il
  11. 131
      ICSharpCode.Decompiler.Tests/TestCases/Pretty/WellKnownConstants.opt.il
  12. 134
      ICSharpCode.Decompiler.Tests/TestCases/Pretty/WellKnownConstants.opt.roslyn.il
  13. 135
      ICSharpCode.Decompiler.Tests/TestCases/Pretty/WellKnownConstants.roslyn.il
  14. 1
      ICSharpCode.Decompiler/CSharp/CSharpDecompiler.cs
  15. 5
      ICSharpCode.Decompiler/CSharp/ExpressionBuilder.cs
  16. 120
      ICSharpCode.Decompiler/CSharp/Syntax/TypeSystemAstBuilder.cs
  17. 2
      ICSharpCode.Decompiler/TypeSystem/ReflectionHelper.cs

2
ICSharpCode.Decompiler.Tests/CustomAttributes/S_CustomAttributes.cs

@ -44,7 +44,7 @@ namespace CustomAttributes @@ -44,7 +44,7 @@ namespace CustomAttributes
public enum ULongEnum : ulong
{
[My(null)]
MaxUInt64 = 18446744073709551615uL
MaxUInt64 = ulong.MaxValue
}
[AttributeUsage(AttributeTargets.Field)]
public class TypesAttribute : Attribute

1
ICSharpCode.Decompiler.Tests/ICSharpCode.Decompiler.Tests.csproj

@ -65,6 +65,7 @@ @@ -65,6 +65,7 @@
<Compile Include="DataFlowTest.cs" />
<Compile Include="TestCases\Correctness\RefLocalsAndReturns.cs" />
<Compile Include="TestCases\Pretty\RefLocalsAndReturns.cs" />
<Compile Include="TestCases\Pretty\WellKnownConstants.cs" />
<Compile Include="VBPrettyTestRunner.cs" />
<Compile Include="TestCases\VBPretty\Async.cs" />
<Compile Include="UglyTestRunner.cs" />

6
ICSharpCode.Decompiler.Tests/PrettyTestRunner.cs

@ -267,6 +267,12 @@ namespace ICSharpCode.Decompiler.Tests @@ -267,6 +267,12 @@ namespace ICSharpCode.Decompiler.Tests
RunForLibrary(cscOptions: cscOptions);
}
[Test]
public void WellKnownConstants([ValueSource("defaultOptions")] CSharpCompilerOptions cscOptions)
{
RunForLibrary(cscOptions: cscOptions);
}
void RunForLibrary([CallerMemberName] string testName = null, AssemblerOptions asmOptions = AssemblerOptions.None, CSharpCompilerOptions cscOptions = CSharpCompilerOptions.None, DecompilerSettings decompilerSettings = null)
{
Run(testName, asmOptions | AssemblerOptions.Library, cscOptions | CSharpCompilerOptions.Library, decompilerSettings);

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

@ -98,7 +98,7 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -98,7 +98,7 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
return "ten thousand";
case 10001:
return "ten thousand and one";
case 2147483647:
case int.MaxValue:
return "int.MaxValue";
default:
return "something else";

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

@ -1,6 +1,6 @@ @@ -1,6 +1,6 @@
// Microsoft (R) .NET Framework IL Disassembler. Version 4.6.1055.0
// Copyright (c) Microsoft Corporation. Alle Rechte vorbehalten.
// Copyright (c) Microsoft Corporation. All rights reserved.
@ -10,7 +10,7 @@ @@ -10,7 +10,7 @@
.publickeytoken = (B7 7A 5C 56 19 34 E0 89 ) // .z\V.4..
.ver 4:0:0:0
}
.assembly rqt3qv2j
.assembly eo05gpu0
{
.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 rqt3qv2j.dll
// MVID: {0220E31A-C196-4C4B-B009-AED9A1DDD0BE}
.module eo05gpu0.dll
// MVID: {9D56DD8F-56CC-4AA5-939D-F5DC041F1927}
.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: 0x02D40000
// Image base: 0x04BA0000
// =============== CLASS MEMBERS DECLARATION ===================
@ -880,7 +880,7 @@ @@ -880,7 +880,7 @@
IL_0015: brfalse IL_00e9
IL_001a: volatile.
IL_001c: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2<string,int32> '<PrivateImplementationDetails>{0220E31A-C196-4C4B-B009-AED9A1DDD0BE}'::'$$method0x600000d-1'
IL_001c: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2<string,int32> '<PrivateImplementationDetails>{9D56DD8F-56CC-4AA5-939D-F5DC041F1927}'::'$$method0x600000d-1'
IL_0021: brtrue.s IL_0084
IL_0023: ldc.i4.7
@ -921,9 +921,9 @@ @@ -921,9 +921,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>{0220E31A-C196-4C4B-B009-AED9A1DDD0BE}'::'$$method0x600000d-1'
IL_007f: stsfld class [mscorlib]System.Collections.Generic.Dictionary`2<string,int32> '<PrivateImplementationDetails>{9D56DD8F-56CC-4AA5-939D-F5DC041F1927}'::'$$method0x600000d-1'
IL_0084: volatile.
IL_0086: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2<string,int32> '<PrivateImplementationDetails>{0220E31A-C196-4C4B-B009-AED9A1DDD0BE}'::'$$method0x600000d-1'
IL_0086: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2<string,int32> '<PrivateImplementationDetails>{9D56DD8F-56CC-4AA5-939D-F5DC041F1927}'::'$$method0x600000d-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,
@ -995,7 +995,7 @@ @@ -995,7 +995,7 @@
IL_0013: brfalse IL_0158
IL_0018: volatile.
IL_001a: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2<string,int32> '<PrivateImplementationDetails>{0220E31A-C196-4C4B-B009-AED9A1DDD0BE}'::'$$method0x600000e-1'
IL_001a: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2<string,int32> '<PrivateImplementationDetails>{9D56DD8F-56CC-4AA5-939D-F5DC041F1927}'::'$$method0x600000e-1'
IL_001f: brtrue IL_00b8
IL_0024: ldc.i4.s 11
@ -1056,9 +1056,9 @@ @@ -1056,9 +1056,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>{0220E31A-C196-4C4B-B009-AED9A1DDD0BE}'::'$$method0x600000e-1'
IL_00b3: stsfld class [mscorlib]System.Collections.Generic.Dictionary`2<string,int32> '<PrivateImplementationDetails>{9D56DD8F-56CC-4AA5-939D-F5DC041F1927}'::'$$method0x600000e-1'
IL_00b8: volatile.
IL_00ba: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2<string,int32> '<PrivateImplementationDetails>{0220E31A-C196-4C4B-B009-AED9A1DDD0BE}'::'$$method0x600000e-1'
IL_00ba: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2<string,int32> '<PrivateImplementationDetails>{9D56DD8F-56CC-4AA5-939D-F5DC041F1927}'::'$$method0x600000e-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,
@ -1346,7 +1346,7 @@ @@ -1346,7 +1346,7 @@
IL_003b: brfalse IL_012c
IL_0040: volatile.
IL_0042: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2<string,int32> '<PrivateImplementationDetails>{0220E31A-C196-4C4B-B009-AED9A1DDD0BE}'::'$$method0x6000013-1'
IL_0042: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2<string,int32> '<PrivateImplementationDetails>{9D56DD8F-56CC-4AA5-939D-F5DC041F1927}'::'$$method0x6000013-1'
IL_0047: brtrue.s IL_009e
IL_0049: ldc.i4.6
@ -1382,9 +1382,9 @@ @@ -1382,9 +1382,9 @@
IL_0092: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2<string,int32>::Add(!0,
!1)
IL_0097: volatile.
IL_0099: stsfld class [mscorlib]System.Collections.Generic.Dictionary`2<string,int32> '<PrivateImplementationDetails>{0220E31A-C196-4C4B-B009-AED9A1DDD0BE}'::'$$method0x6000013-1'
IL_0099: stsfld class [mscorlib]System.Collections.Generic.Dictionary`2<string,int32> '<PrivateImplementationDetails>{9D56DD8F-56CC-4AA5-939D-F5DC041F1927}'::'$$method0x6000013-1'
IL_009e: volatile.
IL_00a0: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2<string,int32> '<PrivateImplementationDetails>{0220E31A-C196-4C4B-B009-AED9A1DDD0BE}'::'$$method0x6000013-1'
IL_00a0: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2<string,int32> '<PrivateImplementationDetails>{9D56DD8F-56CC-4AA5-939D-F5DC041F1927}'::'$$method0x6000013-1'
IL_00a5: ldloc.s V_5
IL_00a7: ldloca.s V_6
IL_00a9: call instance bool class [mscorlib]System.Collections.Generic.Dictionary`2<string,int32>::TryGetValue(!0,
@ -1611,17 +1611,17 @@ @@ -1611,17 +1611,17 @@
} // end of class ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch
.class private auto ansi '<PrivateImplementationDetails>{0220E31A-C196-4C4B-B009-AED9A1DDD0BE}'
.class private auto ansi '<PrivateImplementationDetails>{9D56DD8F-56CC-4AA5-939D-F5DC041F1927}'
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> '$$method0x600000d-1'
.field static assembly class [mscorlib]System.Collections.Generic.Dictionary`2<string,int32> '$$method0x600000e-1'
.field static assembly class [mscorlib]System.Collections.Generic.Dictionary`2<string,int32> '$$method0x6000013-1'
} // end of class '<PrivateImplementationDetails>{0220E31A-C196-4C4B-B009-AED9A1DDD0BE}'
} // end of class '<PrivateImplementationDetails>{9D56DD8F-56CC-4AA5-939D-F5DC041F1927}'
// =============================================================
// *********** DISASSEMBLY COMPLETE ***********************
// Warnung: Win32-Ressourcendatei "../../../TestCases/Pretty\Switch.res" wurde erstellt.
// WARNING: Created Win32 resource file C:\Users\Siegfried\Projects\ILSpy master\ICSharpCode.Decompiler.Tests\bin\Debug\net46\../../../TestCases/Pretty\Switch.res

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

@ -1,6 +1,6 @@ @@ -1,6 +1,6 @@
// Microsoft (R) .NET Framework IL Disassembler. Version 4.6.1055.0
// Copyright (c) Microsoft Corporation. Alle Rechte vorbehalten.
// Copyright (c) Microsoft Corporation. All rights reserved.
@ -10,7 +10,7 @@ @@ -10,7 +10,7 @@
.publickeytoken = (B7 7A 5C 56 19 34 E0 89 ) // .z\V.4..
.ver 4:0:0:0
}
.assembly wn5i3ung
.assembly '1cqmq4ya'
{
.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 wn5i3ung.dll
// MVID: {DBA055A4-E95E-43C4-8BA9-D8F45F1AB075}
.module '1cqmq4ya.dll'
// MVID: {F6D6A0F8-249B-42E0-A06F-7A75134FD239}
.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: 0x00AB0000
// Image base: 0x05550000
// =============== CLASS MEMBERS DECLARATION ===================
@ -749,7 +749,7 @@ @@ -749,7 +749,7 @@
IL_0013: brfalse IL_00db
IL_0018: volatile.
IL_001a: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2<string,int32> '<PrivateImplementationDetails>{DBA055A4-E95E-43C4-8BA9-D8F45F1AB075}'::'$$method0x600000d-1'
IL_001a: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2<string,int32> '<PrivateImplementationDetails>{F6D6A0F8-249B-42E0-A06F-7A75134FD239}'::'$$method0x600000d-1'
IL_001f: brtrue.s IL_0082
IL_0021: ldc.i4.7
@ -790,9 +790,9 @@ @@ -790,9 +790,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>{DBA055A4-E95E-43C4-8BA9-D8F45F1AB075}'::'$$method0x600000d-1'
IL_007d: stsfld class [mscorlib]System.Collections.Generic.Dictionary`2<string,int32> '<PrivateImplementationDetails>{F6D6A0F8-249B-42E0-A06F-7A75134FD239}'::'$$method0x600000d-1'
IL_0082: volatile.
IL_0084: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2<string,int32> '<PrivateImplementationDetails>{DBA055A4-E95E-43C4-8BA9-D8F45F1AB075}'::'$$method0x600000d-1'
IL_0084: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2<string,int32> '<PrivateImplementationDetails>{F6D6A0F8-249B-42E0-A06F-7A75134FD239}'::'$$method0x600000d-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,
@ -850,7 +850,7 @@ @@ -850,7 +850,7 @@
IL_0011: brfalse IL_013d
IL_0016: volatile.
IL_0018: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2<string,int32> '<PrivateImplementationDetails>{DBA055A4-E95E-43C4-8BA9-D8F45F1AB075}'::'$$method0x600000e-1'
IL_0018: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2<string,int32> '<PrivateImplementationDetails>{F6D6A0F8-249B-42E0-A06F-7A75134FD239}'::'$$method0x600000e-1'
IL_001d: brtrue IL_00b6
IL_0022: ldc.i4.s 11
@ -911,9 +911,9 @@ @@ -911,9 +911,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>{DBA055A4-E95E-43C4-8BA9-D8F45F1AB075}'::'$$method0x600000e-1'
IL_00b1: stsfld class [mscorlib]System.Collections.Generic.Dictionary`2<string,int32> '<PrivateImplementationDetails>{F6D6A0F8-249B-42E0-A06F-7A75134FD239}'::'$$method0x600000e-1'
IL_00b6: volatile.
IL_00b8: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2<string,int32> '<PrivateImplementationDetails>{DBA055A4-E95E-43C4-8BA9-D8F45F1AB075}'::'$$method0x600000e-1'
IL_00b8: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2<string,int32> '<PrivateImplementationDetails>{F6D6A0F8-249B-42E0-A06F-7A75134FD239}'::'$$method0x600000e-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,
@ -1139,7 +1139,7 @@ @@ -1139,7 +1139,7 @@
IL_0037: brfalse IL_011f
IL_003c: volatile.
IL_003e: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2<string,int32> '<PrivateImplementationDetails>{DBA055A4-E95E-43C4-8BA9-D8F45F1AB075}'::'$$method0x6000013-1'
IL_003e: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2<string,int32> '<PrivateImplementationDetails>{F6D6A0F8-249B-42E0-A06F-7A75134FD239}'::'$$method0x6000013-1'
IL_0043: brtrue.s IL_009a
IL_0045: ldc.i4.6
@ -1175,9 +1175,9 @@ @@ -1175,9 +1175,9 @@
IL_008e: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2<string,int32>::Add(!0,
!1)
IL_0093: volatile.
IL_0095: stsfld class [mscorlib]System.Collections.Generic.Dictionary`2<string,int32> '<PrivateImplementationDetails>{DBA055A4-E95E-43C4-8BA9-D8F45F1AB075}'::'$$method0x6000013-1'
IL_0095: stsfld class [mscorlib]System.Collections.Generic.Dictionary`2<string,int32> '<PrivateImplementationDetails>{F6D6A0F8-249B-42E0-A06F-7A75134FD239}'::'$$method0x6000013-1'
IL_009a: volatile.
IL_009c: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2<string,int32> '<PrivateImplementationDetails>{DBA055A4-E95E-43C4-8BA9-D8F45F1AB075}'::'$$method0x6000013-1'
IL_009c: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2<string,int32> '<PrivateImplementationDetails>{F6D6A0F8-249B-42E0-A06F-7A75134FD239}'::'$$method0x6000013-1'
IL_00a1: ldloc.s V_5
IL_00a3: ldloca.s V_6
IL_00a5: call instance bool class [mscorlib]System.Collections.Generic.Dictionary`2<string,int32>::TryGetValue(!0,
@ -1371,17 +1371,17 @@ @@ -1371,17 +1371,17 @@
} // end of class ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch
.class private auto ansi '<PrivateImplementationDetails>{DBA055A4-E95E-43C4-8BA9-D8F45F1AB075}'
.class private auto ansi '<PrivateImplementationDetails>{F6D6A0F8-249B-42E0-A06F-7A75134FD239}'
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> '$$method0x600000d-1'
.field static assembly class [mscorlib]System.Collections.Generic.Dictionary`2<string,int32> '$$method0x600000e-1'
.field static assembly class [mscorlib]System.Collections.Generic.Dictionary`2<string,int32> '$$method0x6000013-1'
} // end of class '<PrivateImplementationDetails>{DBA055A4-E95E-43C4-8BA9-D8F45F1AB075}'
} // end of class '<PrivateImplementationDetails>{F6D6A0F8-249B-42E0-A06F-7A75134FD239}'
// =============================================================
// *********** DISASSEMBLY COMPLETE ***********************
// Warnung: Win32-Ressourcendatei "../../../TestCases/Pretty\Switch.opt.res" wurde erstellt.
// WARNING: Created Win32 resource file C:\Users\Siegfried\Projects\ILSpy master\ICSharpCode.Decompiler.Tests\bin\Debug\net46\../../../TestCases/Pretty\Switch.opt.res

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

@ -1,6 +1,6 @@ @@ -1,6 +1,6 @@
// Microsoft (R) .NET Framework IL Disassembler. Version 4.6.1055.0
// Copyright (c) Microsoft Corporation. Alle Rechte vorbehalten.
// Copyright (c) Microsoft Corporation. All rights reserved.
@ -32,7 +32,7 @@ @@ -32,7 +32,7 @@
.stackreserve 0x00100000
.subsystem 0x0003 // WINDOWS_CUI
.corflags 0x00000001 // ILONLY
// Image base: 0x01380000
// Image base: 0x031B0000
// =============== CLASS MEMBERS DECLARATION ===================

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

@ -1,6 +1,6 @@ @@ -1,6 +1,6 @@
// Microsoft (R) .NET Framework IL Disassembler. Version 4.6.1055.0
// Copyright (c) Microsoft Corporation. Alle Rechte vorbehalten.
// Copyright (c) Microsoft Corporation. All rights reserved.
@ -32,7 +32,7 @@ @@ -32,7 +32,7 @@
.stackreserve 0x00100000
.subsystem 0x0003 // WINDOWS_CUI
.corflags 0x00000001 // ILONLY
// Image base: 0x02460000
// Image base: 0x04490000
// =============== CLASS MEMBERS DECLARATION ===================

68
ICSharpCode.Decompiler.Tests/TestCases/Pretty/WellKnownConstants.cs

@ -0,0 +1,68 @@ @@ -0,0 +1,68 @@
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of this
// software and associated documentation files (the "Software"), to deal in the Software
// without restriction, including without limitation the rights to use, copy, modify, merge,
// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
// to whom the Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all copies or
// substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
{
public class WellKnownConstants
{
public const byte ByteMaxValue = byte.MaxValue;
public const byte ByteMinValue = 0;
public const sbyte SByteMaxValue = sbyte.MaxValue;
public const sbyte SByteMinValue = sbyte.MinValue;
public const ushort UShortMaxValue = ushort.MaxValue;
public const ushort UShortMinValue = 0;
public const short ShortMaxValue = short.MinValue;
public const short ShortMinValue = short.MaxValue;
public const uint UIntMaxValue = uint.MaxValue;
public const uint UIntMinValue = 0u;
public const int IntMaxValue = int.MaxValue;
public const int IntMinValue = int.MinValue;
public const ulong ULongMaxValue = ulong.MaxValue;
public const ulong ULongMinValue = 0uL;
public const long LongMaxValue = long.MaxValue;
public const long LongMinValue = long.MinValue;
public const float FloatZero = 0f;
public const float FloatMinusZero = -0f;
public const float FloatNaN = float.NaN;
public const float FloatPositiveInfinity = float.PositiveInfinity;
public const float FloatNegativeInfinity = float.NegativeInfinity;
public const float FloatMaxValue = float.MaxValue;
public const float FloatMinValue = float.MinValue;
public const float FloatEpsilon = float.Epsilon;
public const double DoubleZero = 0.0;
public const double DoubleMinusZero = -0.0;
public const double DoubleNaN = double.NaN;
public const double DoublePositiveInfinity = double.PositiveInfinity;
public const double DoubleNegativeInfinity = double.NegativeInfinity;
public const double DoubleMaxValue = double.MaxValue;
public const double DoubleMinValue = double.MinValue;
public const double DoubleEpsilon = double.Epsilon;
public const decimal DecimalMaxValue = decimal.MaxValue;
public const decimal DecimalMinValue = decimal.MinValue;
}
}

131
ICSharpCode.Decompiler.Tests/TestCases/Pretty/WellKnownConstants.il

@ -0,0 +1,131 @@ @@ -0,0 +1,131 @@
// Microsoft (R) .NET Framework IL Disassembler. Version 4.6.1055.0
// Copyright (c) Microsoft Corporation. All rights reserved.
// Metadata version: v4.0.30319
.assembly extern mscorlib
{
.publickeytoken = (B7 7A 5C 56 19 34 E0 89 ) // .z\V.4..
.ver 4:0:0:0
}
.assembly '44dbunlx'
{
.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.
.custom instance void [mscorlib]System.Runtime.CompilerServices.CompilationRelaxationsAttribute::.ctor(int32) = ( 01 00 08 00 00 00 00 00 )
.permissionset reqmin
= {[mscorlib]System.Security.Permissions.SecurityPermissionAttribute = {property bool 'SkipVerification' = bool(true)}}
.hash algorithm 0x00008004
.ver 0:0:0:0
}
.module '44dbunlx.dll'
// MVID: {084D6FE7-6C94-46BC-9CF1-21040E4EE5EA}
.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: 0x03200000
// =============== CLASS MEMBERS DECLARATION ===================
.class public auto ansi beforefieldinit ICSharpCode.Decompiler.Tests.TestCases.Pretty.WellKnownConstants
extends [mscorlib]System.Object
{
.field public static literal uint8 ByteMaxValue = uint8(0xFF)
.field public static literal uint8 ByteMinValue = uint8(0x00)
.field public static literal int8 SByteMaxValue = int8(0x7F)
.field public static literal int8 SByteMinValue = int8(0x80)
.field public static literal uint16 UShortMaxValue = uint16(0xFFFF)
.field public static literal uint16 UShortMinValue = uint16(0x0000)
.field public static literal int16 ShortMaxValue = int16(0x8000)
.field public static literal int16 ShortMinValue = int16(0x7FFF)
.field public static literal uint32 UIntMaxValue = uint32(0xFFFFFFFF)
.field public static literal uint32 UIntMinValue = uint32(0x00000000)
.field public static literal int32 IntMaxValue = int32(0x7FFFFFFF)
.field public static literal int32 IntMinValue = int32(0x80000000)
.field public static literal uint64 ULongMaxValue = uint64(0xFFFFFFFFFFFFFFFF)
.field public static literal uint64 ULongMinValue = uint64(0x0)
.field public static literal int64 LongMaxValue = int64(0x7FFFFFFFFFFFFFFF)
.field public static literal int64 LongMinValue = int64(0x8000000000000000)
.field public static literal float32 FloatZero = float32(0.)
.field public static literal float32 FloatMinusZero = float32(-0.)
.field public static literal float32 FloatNaN = float32(0xFFC00000)
.field public static literal float32 FloatPositiveInfinity = float32(0x7F800000)
.field public static literal float32 FloatNegativeInfinity = float32(0xFF800000)
.field public static literal float32 FloatMaxValue = float32(3.4028235e+038)
.field public static literal float32 FloatMinValue = float32(-3.4028235e+038)
.field public static literal float32 FloatEpsilon = float32(1.4012985e-045)
.field public static literal float64 DoubleZero = float64(0.)
.field public static literal float64 DoubleMinusZero = float64(-0.)
.field public static literal float64 DoubleNaN = float64(0xFFF8000000000000) // -1.#IND
.field public static literal float64 DoublePositiveInfinity = float64(0x7FF0000000000000) // 1.#INF
.field public static literal float64 DoubleNegativeInfinity = float64(0xFFF0000000000000) // -1.#INF
.field public static literal float64 DoubleMaxValue = float64(1.7976931348623157e+308)
.field public static literal float64 DoubleMinValue = float64(-1.7976931348623157e+308)
.field public static literal float64 DoubleEpsilon = float64(4.9406564584124654e-324)
.field public static initonly valuetype [mscorlib]System.Decimal DecimalMaxValue
.custom instance void [mscorlib]System.Runtime.CompilerServices.DecimalConstantAttribute::.ctor(uint8,
uint8,
uint32,
uint32,
uint32) = ( 01 00 00 00 FF FF FF FF FF FF FF FF FF FF FF FF
00 00 )
.field public static initonly valuetype [mscorlib]System.Decimal DecimalMinValue
.custom instance void [mscorlib]System.Runtime.CompilerServices.DecimalConstantAttribute::.ctor(uint8,
uint8,
uint32,
uint32,
uint32) = ( 01 00 00 80 FF FF FF FF FF FF FF FF FF FF FF FF
00 00 )
.method public hidebysig specialname rtspecialname
instance void .ctor() cil managed
{
// Code size 7 (0x7)
.maxstack 8
IL_0000: ldarg.0
IL_0001: call instance void [mscorlib]System.Object::.ctor()
IL_0006: ret
} // end of method WellKnownConstants::.ctor
.method private hidebysig specialname rtspecialname static
void .cctor() cil managed
{
// Code size 35 (0x23)
.maxstack 8
IL_0000: ldc.i4.m1
IL_0001: ldc.i4.m1
IL_0002: ldc.i4.m1
IL_0003: ldc.i4.0
IL_0004: ldc.i4.0
IL_0005: newobj instance void [mscorlib]System.Decimal::.ctor(int32,
int32,
int32,
bool,
uint8)
IL_000a: stsfld valuetype [mscorlib]System.Decimal ICSharpCode.Decompiler.Tests.TestCases.Pretty.WellKnownConstants::DecimalMaxValue
IL_000f: ldc.i4.m1
IL_0010: ldc.i4.m1
IL_0011: ldc.i4.m1
IL_0012: ldc.i4 0x80
IL_0017: ldc.i4.0
IL_0018: newobj instance void [mscorlib]System.Decimal::.ctor(int32,
int32,
int32,
bool,
uint8)
IL_001d: stsfld valuetype [mscorlib]System.Decimal ICSharpCode.Decompiler.Tests.TestCases.Pretty.WellKnownConstants::DecimalMinValue
IL_0022: ret
} // end of method WellKnownConstants::.cctor
} // end of class ICSharpCode.Decompiler.Tests.TestCases.Pretty.WellKnownConstants
// =============================================================
// *********** DISASSEMBLY COMPLETE ***********************
// WARNING: Created Win32 resource file C:\Users\Siegfried\Projects\ILSpy master\ICSharpCode.Decompiler.Tests\bin\Debug\net46\../../../TestCases/Pretty\WellKnownConstants.res

131
ICSharpCode.Decompiler.Tests/TestCases/Pretty/WellKnownConstants.opt.il

@ -0,0 +1,131 @@ @@ -0,0 +1,131 @@
// Microsoft (R) .NET Framework IL Disassembler. Version 4.6.1055.0
// Copyright (c) Microsoft Corporation. All rights reserved.
// Metadata version: v4.0.30319
.assembly extern mscorlib
{
.publickeytoken = (B7 7A 5C 56 19 34 E0 89 ) // .z\V.4..
.ver 4:0:0:0
}
.assembly '2a1zmun4'
{
.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.
.custom instance void [mscorlib]System.Runtime.CompilerServices.CompilationRelaxationsAttribute::.ctor(int32) = ( 01 00 08 00 00 00 00 00 )
.permissionset reqmin
= {[mscorlib]System.Security.Permissions.SecurityPermissionAttribute = {property bool 'SkipVerification' = bool(true)}}
.hash algorithm 0x00008004
.ver 0:0:0:0
}
.module '2a1zmun4.dll'
// MVID: {68191A55-6426-48F1-B0FE-6B515D64B18A}
.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: 0x03170000
// =============== CLASS MEMBERS DECLARATION ===================
.class public auto ansi beforefieldinit ICSharpCode.Decompiler.Tests.TestCases.Pretty.WellKnownConstants
extends [mscorlib]System.Object
{
.field public static literal uint8 ByteMaxValue = uint8(0xFF)
.field public static literal uint8 ByteMinValue = uint8(0x00)
.field public static literal int8 SByteMaxValue = int8(0x7F)
.field public static literal int8 SByteMinValue = int8(0x80)
.field public static literal uint16 UShortMaxValue = uint16(0xFFFF)
.field public static literal uint16 UShortMinValue = uint16(0x0000)
.field public static literal int16 ShortMaxValue = int16(0x8000)
.field public static literal int16 ShortMinValue = int16(0x7FFF)
.field public static literal uint32 UIntMaxValue = uint32(0xFFFFFFFF)
.field public static literal uint32 UIntMinValue = uint32(0x00000000)
.field public static literal int32 IntMaxValue = int32(0x7FFFFFFF)
.field public static literal int32 IntMinValue = int32(0x80000000)
.field public static literal uint64 ULongMaxValue = uint64(0xFFFFFFFFFFFFFFFF)
.field public static literal uint64 ULongMinValue = uint64(0x0)
.field public static literal int64 LongMaxValue = int64(0x7FFFFFFFFFFFFFFF)
.field public static literal int64 LongMinValue = int64(0x8000000000000000)
.field public static literal float32 FloatZero = float32(0.)
.field public static literal float32 FloatMinusZero = float32(-0.)
.field public static literal float32 FloatNaN = float32(0xFFC00000)
.field public static literal float32 FloatPositiveInfinity = float32(0x7F800000)
.field public static literal float32 FloatNegativeInfinity = float32(0xFF800000)
.field public static literal float32 FloatMaxValue = float32(3.4028235e+038)
.field public static literal float32 FloatMinValue = float32(-3.4028235e+038)
.field public static literal float32 FloatEpsilon = float32(1.4012985e-045)
.field public static literal float64 DoubleZero = float64(0.)
.field public static literal float64 DoubleMinusZero = float64(-0.)
.field public static literal float64 DoubleNaN = float64(0xFFF8000000000000) // -1.#IND
.field public static literal float64 DoublePositiveInfinity = float64(0x7FF0000000000000) // 1.#INF
.field public static literal float64 DoubleNegativeInfinity = float64(0xFFF0000000000000) // -1.#INF
.field public static literal float64 DoubleMaxValue = float64(1.7976931348623157e+308)
.field public static literal float64 DoubleMinValue = float64(-1.7976931348623157e+308)
.field public static literal float64 DoubleEpsilon = float64(4.9406564584124654e-324)
.field public static initonly valuetype [mscorlib]System.Decimal DecimalMaxValue
.custom instance void [mscorlib]System.Runtime.CompilerServices.DecimalConstantAttribute::.ctor(uint8,
uint8,
uint32,
uint32,
uint32) = ( 01 00 00 00 FF FF FF FF FF FF FF FF FF FF FF FF
00 00 )
.field public static initonly valuetype [mscorlib]System.Decimal DecimalMinValue
.custom instance void [mscorlib]System.Runtime.CompilerServices.DecimalConstantAttribute::.ctor(uint8,
uint8,
uint32,
uint32,
uint32) = ( 01 00 00 80 FF FF FF FF FF FF FF FF FF FF FF FF
00 00 )
.method public hidebysig specialname rtspecialname
instance void .ctor() cil managed
{
// Code size 7 (0x7)
.maxstack 8
IL_0000: ldarg.0
IL_0001: call instance void [mscorlib]System.Object::.ctor()
IL_0006: ret
} // end of method WellKnownConstants::.ctor
.method private hidebysig specialname rtspecialname static
void .cctor() cil managed
{
// Code size 35 (0x23)
.maxstack 8
IL_0000: ldc.i4.m1
IL_0001: ldc.i4.m1
IL_0002: ldc.i4.m1
IL_0003: ldc.i4.0
IL_0004: ldc.i4.0
IL_0005: newobj instance void [mscorlib]System.Decimal::.ctor(int32,
int32,
int32,
bool,
uint8)
IL_000a: stsfld valuetype [mscorlib]System.Decimal ICSharpCode.Decompiler.Tests.TestCases.Pretty.WellKnownConstants::DecimalMaxValue
IL_000f: ldc.i4.m1
IL_0010: ldc.i4.m1
IL_0011: ldc.i4.m1
IL_0012: ldc.i4 0x80
IL_0017: ldc.i4.0
IL_0018: newobj instance void [mscorlib]System.Decimal::.ctor(int32,
int32,
int32,
bool,
uint8)
IL_001d: stsfld valuetype [mscorlib]System.Decimal ICSharpCode.Decompiler.Tests.TestCases.Pretty.WellKnownConstants::DecimalMinValue
IL_0022: ret
} // end of method WellKnownConstants::.cctor
} // end of class ICSharpCode.Decompiler.Tests.TestCases.Pretty.WellKnownConstants
// =============================================================
// *********** DISASSEMBLY COMPLETE ***********************
// WARNING: Created Win32 resource file C:\Users\Siegfried\Projects\ILSpy master\ICSharpCode.Decompiler.Tests\bin\Debug\net46\../../../TestCases/Pretty\WellKnownConstants.opt.res

134
ICSharpCode.Decompiler.Tests/TestCases/Pretty/WellKnownConstants.opt.roslyn.il

@ -0,0 +1,134 @@ @@ -0,0 +1,134 @@
// Microsoft (R) .NET Framework IL Disassembler. Version 4.6.1055.0
// Copyright (c) Microsoft Corporation. All rights reserved.
// Metadata version: v4.0.30319
.assembly extern mscorlib
{
.publickeytoken = (B7 7A 5C 56 19 34 E0 89 ) // .z\V.4..
.ver 4:0:0:0
}
.assembly WellKnownConstants
{
.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
63 65 70 74 69 6F 6E 54 68 72 6F 77 73 01 ) // ceptionThrows.
// --- The following custom attribute is added automatically, do not uncomment -------
// .custom instance void [mscorlib]System.Diagnostics.DebuggableAttribute::.ctor(valuetype [mscorlib]System.Diagnostics.DebuggableAttribute/DebuggingModes) = ( 01 00 02 00 00 00 00 00 )
.permissionset reqmin
= {[mscorlib]System.Security.Permissions.SecurityPermissionAttribute = {property bool 'SkipVerification' = bool(true)}}
.hash algorithm 0x00008004
.ver 0:0:0:0
}
.module WellKnownConstants.dll
// MVID: {525756B1-8B82-4FE7-B5BC-4A4B72386961}
.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: 0x03920000
// =============== CLASS MEMBERS DECLARATION ===================
.class public auto ansi beforefieldinit ICSharpCode.Decompiler.Tests.TestCases.Pretty.WellKnownConstants
extends [mscorlib]System.Object
{
.field public static literal uint8 ByteMaxValue = uint8(0xFF)
.field public static literal uint8 ByteMinValue = uint8(0x00)
.field public static literal int8 SByteMaxValue = int8(0x7F)
.field public static literal int8 SByteMinValue = int8(0x80)
.field public static literal uint16 UShortMaxValue = uint16(0xFFFF)
.field public static literal uint16 UShortMinValue = uint16(0x0000)
.field public static literal int16 ShortMaxValue = int16(0x8000)
.field public static literal int16 ShortMinValue = int16(0x7FFF)
.field public static literal uint32 UIntMaxValue = uint32(0xFFFFFFFF)
.field public static literal uint32 UIntMinValue = uint32(0x00000000)
.field public static literal int32 IntMaxValue = int32(0x7FFFFFFF)
.field public static literal int32 IntMinValue = int32(0x80000000)
.field public static literal uint64 ULongMaxValue = uint64(0xFFFFFFFFFFFFFFFF)
.field public static literal uint64 ULongMinValue = uint64(0x0)
.field public static literal int64 LongMaxValue = int64(0x7FFFFFFFFFFFFFFF)
.field public static literal int64 LongMinValue = int64(0x8000000000000000)
.field public static literal float32 FloatZero = float32(0.)
.field public static literal float32 FloatMinusZero = float32(-0.)
.field public static literal float32 FloatNaN = float32(0xFFC00000)
.field public static literal float32 FloatPositiveInfinity = float32(0x7F800000)
.field public static literal float32 FloatNegativeInfinity = float32(0xFF800000)
.field public static literal float32 FloatMaxValue = float32(3.4028235e+038)
.field public static literal float32 FloatMinValue = float32(-3.4028235e+038)
.field public static literal float32 FloatEpsilon = float32(1.4012985e-045)
.field public static literal float64 DoubleZero = float64(0.)
.field public static literal float64 DoubleMinusZero = float64(-0.)
.field public static literal float64 DoubleNaN = float64(0xFFF8000000000000) // -1.#IND
.field public static literal float64 DoublePositiveInfinity = float64(0x7FF0000000000000) // 1.#INF
.field public static literal float64 DoubleNegativeInfinity = float64(0xFFF0000000000000) // -1.#INF
.field public static literal float64 DoubleMaxValue = float64(1.7976931348623157e+308)
.field public static literal float64 DoubleMinValue = float64(-1.7976931348623157e+308)
.field public static literal float64 DoubleEpsilon = float64(4.9406564584124654e-324)
.field public static initonly valuetype [mscorlib]System.Decimal DecimalMaxValue
.custom instance void [mscorlib]System.Runtime.CompilerServices.DecimalConstantAttribute::.ctor(uint8,
uint8,
uint32,
uint32,
uint32) = ( 01 00 00 00 FF FF FF FF FF FF FF FF FF FF FF FF
00 00 )
.field public static initonly valuetype [mscorlib]System.Decimal DecimalMinValue
.custom instance void [mscorlib]System.Runtime.CompilerServices.DecimalConstantAttribute::.ctor(uint8,
uint8,
uint32,
uint32,
uint32) = ( 01 00 00 80 FF FF FF FF FF FF FF FF FF FF FF FF
00 00 )
.method public hidebysig specialname rtspecialname
instance void .ctor() cil managed
{
// Code size 7 (0x7)
.maxstack 8
IL_0000: ldarg.0
IL_0001: call instance void [mscorlib]System.Object::.ctor()
IL_0006: ret
} // end of method WellKnownConstants::.ctor
.method private hidebysig specialname rtspecialname static
void .cctor() cil managed
{
// Code size 31 (0x1f)
.maxstack 8
IL_0000: ldc.i4.m1
IL_0001: ldc.i4.m1
IL_0002: ldc.i4.m1
IL_0003: ldc.i4.0
IL_0004: ldc.i4.0
IL_0005: newobj instance void [mscorlib]System.Decimal::.ctor(int32,
int32,
int32,
bool,
uint8)
IL_000a: stsfld valuetype [mscorlib]System.Decimal ICSharpCode.Decompiler.Tests.TestCases.Pretty.WellKnownConstants::DecimalMaxValue
IL_000f: ldc.i4.m1
IL_0010: ldc.i4.m1
IL_0011: ldc.i4.m1
IL_0012: ldc.i4.1
IL_0013: ldc.i4.0
IL_0014: newobj instance void [mscorlib]System.Decimal::.ctor(int32,
int32,
int32,
bool,
uint8)
IL_0019: stsfld valuetype [mscorlib]System.Decimal ICSharpCode.Decompiler.Tests.TestCases.Pretty.WellKnownConstants::DecimalMinValue
IL_001e: ret
} // end of method WellKnownConstants::.cctor
} // end of class ICSharpCode.Decompiler.Tests.TestCases.Pretty.WellKnownConstants
// =============================================================
// *********** DISASSEMBLY COMPLETE ***********************

135
ICSharpCode.Decompiler.Tests/TestCases/Pretty/WellKnownConstants.roslyn.il

@ -0,0 +1,135 @@ @@ -0,0 +1,135 @@
// Microsoft (R) .NET Framework IL Disassembler. Version 4.6.1055.0
// Copyright (c) Microsoft Corporation. All rights reserved.
// Metadata version: v4.0.30319
.assembly extern mscorlib
{
.publickeytoken = (B7 7A 5C 56 19 34 E0 89 ) // .z\V.4..
.ver 4:0:0:0
}
.assembly WellKnownConstants
{
.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
63 65 70 74 69 6F 6E 54 68 72 6F 77 73 01 ) // ceptionThrows.
// --- The following custom attribute is added automatically, do not uncomment -------
// .custom instance void [mscorlib]System.Diagnostics.DebuggableAttribute::.ctor(valuetype [mscorlib]System.Diagnostics.DebuggableAttribute/DebuggingModes) = ( 01 00 07 01 00 00 00 00 )
.permissionset reqmin
= {[mscorlib]System.Security.Permissions.SecurityPermissionAttribute = {property bool 'SkipVerification' = bool(true)}}
.hash algorithm 0x00008004
.ver 0:0:0:0
}
.module WellKnownConstants.dll
// MVID: {4BFA68B4-16BE-4DD5-AE82-94BCA3873C69}
.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: 0x05190000
// =============== CLASS MEMBERS DECLARATION ===================
.class public auto ansi beforefieldinit ICSharpCode.Decompiler.Tests.TestCases.Pretty.WellKnownConstants
extends [mscorlib]System.Object
{
.field public static literal uint8 ByteMaxValue = uint8(0xFF)
.field public static literal uint8 ByteMinValue = uint8(0x00)
.field public static literal int8 SByteMaxValue = int8(0x7F)
.field public static literal int8 SByteMinValue = int8(0x80)
.field public static literal uint16 UShortMaxValue = uint16(0xFFFF)
.field public static literal uint16 UShortMinValue = uint16(0x0000)
.field public static literal int16 ShortMaxValue = int16(0x8000)
.field public static literal int16 ShortMinValue = int16(0x7FFF)
.field public static literal uint32 UIntMaxValue = uint32(0xFFFFFFFF)
.field public static literal uint32 UIntMinValue = uint32(0x00000000)
.field public static literal int32 IntMaxValue = int32(0x7FFFFFFF)
.field public static literal int32 IntMinValue = int32(0x80000000)
.field public static literal uint64 ULongMaxValue = uint64(0xFFFFFFFFFFFFFFFF)
.field public static literal uint64 ULongMinValue = uint64(0x0)
.field public static literal int64 LongMaxValue = int64(0x7FFFFFFFFFFFFFFF)
.field public static literal int64 LongMinValue = int64(0x8000000000000000)
.field public static literal float32 FloatZero = float32(0.)
.field public static literal float32 FloatMinusZero = float32(-0.)
.field public static literal float32 FloatNaN = float32(0xFFC00000)
.field public static literal float32 FloatPositiveInfinity = float32(0x7F800000)
.field public static literal float32 FloatNegativeInfinity = float32(0xFF800000)
.field public static literal float32 FloatMaxValue = float32(3.4028235e+038)
.field public static literal float32 FloatMinValue = float32(-3.4028235e+038)
.field public static literal float32 FloatEpsilon = float32(1.4012985e-045)
.field public static literal float64 DoubleZero = float64(0.)
.field public static literal float64 DoubleMinusZero = float64(-0.)
.field public static literal float64 DoubleNaN = float64(0xFFF8000000000000) // -1.#IND
.field public static literal float64 DoublePositiveInfinity = float64(0x7FF0000000000000) // 1.#INF
.field public static literal float64 DoubleNegativeInfinity = float64(0xFFF0000000000000) // -1.#INF
.field public static literal float64 DoubleMaxValue = float64(1.7976931348623157e+308)
.field public static literal float64 DoubleMinValue = float64(-1.7976931348623157e+308)
.field public static literal float64 DoubleEpsilon = float64(4.9406564584124654e-324)
.field public static initonly valuetype [mscorlib]System.Decimal DecimalMaxValue
.custom instance void [mscorlib]System.Runtime.CompilerServices.DecimalConstantAttribute::.ctor(uint8,
uint8,
uint32,
uint32,
uint32) = ( 01 00 00 00 FF FF FF FF FF FF FF FF FF FF FF FF
00 00 )
.field public static initonly valuetype [mscorlib]System.Decimal DecimalMinValue
.custom instance void [mscorlib]System.Runtime.CompilerServices.DecimalConstantAttribute::.ctor(uint8,
uint8,
uint32,
uint32,
uint32) = ( 01 00 00 80 FF FF FF FF FF FF FF FF FF FF FF FF
00 00 )
.method public hidebysig specialname rtspecialname
instance void .ctor() cil managed
{
// Code size 8 (0x8)
.maxstack 8
IL_0000: ldarg.0
IL_0001: call instance void [mscorlib]System.Object::.ctor()
IL_0006: nop
IL_0007: ret
} // end of method WellKnownConstants::.ctor
.method private hidebysig specialname rtspecialname static
void .cctor() cil managed
{
// Code size 31 (0x1f)
.maxstack 8
IL_0000: ldc.i4.m1
IL_0001: ldc.i4.m1
IL_0002: ldc.i4.m1
IL_0003: ldc.i4.0
IL_0004: ldc.i4.0
IL_0005: newobj instance void [mscorlib]System.Decimal::.ctor(int32,
int32,
int32,
bool,
uint8)
IL_000a: stsfld valuetype [mscorlib]System.Decimal ICSharpCode.Decompiler.Tests.TestCases.Pretty.WellKnownConstants::DecimalMaxValue
IL_000f: ldc.i4.m1
IL_0010: ldc.i4.m1
IL_0011: ldc.i4.m1
IL_0012: ldc.i4.1
IL_0013: ldc.i4.0
IL_0014: newobj instance void [mscorlib]System.Decimal::.ctor(int32,
int32,
int32,
bool,
uint8)
IL_0019: stsfld valuetype [mscorlib]System.Decimal ICSharpCode.Decompiler.Tests.TestCases.Pretty.WellKnownConstants::DecimalMinValue
IL_001e: ret
} // end of method WellKnownConstants::.cctor
} // end of class ICSharpCode.Decompiler.Tests.TestCases.Pretty.WellKnownConstants
// =============================================================
// *********** DISASSEMBLY COMPLETE ***********************

1
ICSharpCode.Decompiler/CSharp/CSharpDecompiler.cs

@ -895,6 +895,7 @@ namespace ICSharpCode.Decompiler.CSharp @@ -895,6 +895,7 @@ namespace ICSharpCode.Decompiler.CSharp
enumDec.AddAnnotation(new Semantics.MemberResolveResult(null, field));
return enumDec;
}
typeSystemAstBuilder.UseSpecialConstants = !field.DeclaringType.Equals(field.ReturnType);
var fieldDecl = typeSystemAstBuilder.ConvertEntity(field);
SetNewModifier(fieldDecl);
if (settings.FixedBuffers && IsFixedField(field, out var elementType, out var elementCount)) {

5
ICSharpCode.Decompiler/CSharp/ExpressionBuilder.cs

@ -324,9 +324,8 @@ namespace ICSharpCode.Decompiler.CSharp @@ -324,9 +324,8 @@ namespace ICSharpCode.Decompiler.CSharp
protected internal override TranslatedExpression VisitLdcDecimal(LdcDecimal inst, TranslationContext context)
{
return new PrimitiveExpression(inst.Value)
.WithILInstruction(inst)
.WithRR(new ConstantResolveResult(compilation.FindType(KnownTypeCode.Decimal), inst.Value));
var expr = astBuilder.ConvertConstantValue(compilation.FindType(KnownTypeCode.Decimal), inst.Value);
return new TranslatedExpression(expr.WithILInstruction(inst));
}
protected internal override TranslatedExpression VisitLdStr(LdStr inst, TranslationContext context)

120
ICSharpCode.Decompiler/CSharp/Syntax/TypeSystemAstBuilder.cs

@ -71,6 +71,7 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax @@ -71,6 +71,7 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax
this.ShowParameterNames = true;
this.ShowConstantValues = true;
this.UseAliases = true;
this.UseSpecialConstants = true;
}
/// <summary>
@ -171,6 +172,12 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax @@ -171,6 +172,12 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax
/// The default value is <c>true</c>.
/// </summary>
public bool UseAliases { get; set; }
/// <summary>
/// Controls if constants like <c>int.MaxValue</c> are converted to a <see cref="MemberReferenceExpression"/> or <see cref="PrimitiveExpression" />.
/// The default value is <c>true</c>.
/// </summary>
public bool UseSpecialConstants { get; set; }
#endregion
#region Convert Type
@ -519,19 +526,130 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax @@ -519,19 +526,130 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax
} else if (type.Kind == TypeKind.Enum) {
return ConvertEnumValue(type, (long)CSharpPrimitiveCast.Cast(TypeCode.Int64, constantValue, false));
} else {
if (IsSpecialConstant(type, constantValue, out var expr))
return expr;
if (type.IsCSharpSmallIntegerType()) {
// C# does not have integer literals of small integer types,
// use `int` literal instead.
constantValue = CSharpPrimitiveCast.Cast(TypeCode.Int32, constantValue, false);
type = type.GetDefinition().Compilation.FindType(KnownTypeCode.Int32);
}
var expr = new PrimitiveExpression(constantValue);
expr = new PrimitiveExpression(constantValue);
if (AddResolveResultAnnotations)
expr.AddAnnotation(new ConstantResolveResult(type, constantValue));
return expr;
}
}
bool IsSpecialConstant(IType type, object constant, out Expression expression)
{
expression = null;
if (!specialConstants.TryGetValue(constant, out var info))
return false;
if (!UseSpecialConstants) {
// +Infty, -Infty and NaN, cannot be represented in their encoded form.
// Use an equivalent arithmetic expression instead.
var resolver = this.resolver ?? new CSharpResolver(type.GetDefinition().Compilation);
if (info.Type == KnownTypeCode.Double) {
switch ((double)constant) {
case double.NegativeInfinity: // (-1.0 / 0.0)
var left = new PrimitiveExpression(-1.0).WithoutILInstruction().WithRR(new ConstantResolveResult(type, -1.0));
var right = new PrimitiveExpression(0.0).WithoutILInstruction().WithRR(new ConstantResolveResult(type, 0.0));
expression = new BinaryOperatorExpression(left, BinaryOperatorType.Divide, right).WithoutILInstruction()
.WithRR(resolver.ResolveBinaryOperator(BinaryOperatorType.Divide, left.ResolveResult, right.ResolveResult));
return true;
case double.PositiveInfinity: // (1.0 / 0.0)
left = new PrimitiveExpression(1.0).WithoutILInstruction().WithRR(new ConstantResolveResult(type, 1.0));
right = new PrimitiveExpression(0.0).WithoutILInstruction().WithRR(new ConstantResolveResult(type, 0.0));
expression = new BinaryOperatorExpression(left, BinaryOperatorType.Divide, right).WithoutILInstruction()
.WithRR(resolver.ResolveBinaryOperator(BinaryOperatorType.Divide, left.ResolveResult, right.ResolveResult));
return true;
case double.NaN: // (0.0 / 0.0)
left = new PrimitiveExpression(0.0).WithoutILInstruction().WithRR(new ConstantResolveResult(type, 0.0));
right = new PrimitiveExpression(0.0).WithoutILInstruction().WithRR(new ConstantResolveResult(type, 0.0));
expression = new BinaryOperatorExpression(left, BinaryOperatorType.Divide, right).WithoutILInstruction()
.WithRR(resolver.ResolveBinaryOperator(BinaryOperatorType.Divide, left.ResolveResult, right.ResolveResult));
return true;
}
}
if (info.Type == KnownTypeCode.Single) {
switch ((float)constant) {
case float.NegativeInfinity: // (-1.0f / 0.0f)
var left = new PrimitiveExpression(-1.0f).WithoutILInstruction().WithRR(new ConstantResolveResult(type, -1.0f));
var right = new PrimitiveExpression(0.0f).WithoutILInstruction().WithRR(new ConstantResolveResult(type, 0.0f));
expression = new BinaryOperatorExpression(left, BinaryOperatorType.Divide, right).WithoutILInstruction()
.WithRR(resolver.ResolveBinaryOperator(BinaryOperatorType.Divide, left.ResolveResult, right.ResolveResult));
return true;
case float.PositiveInfinity: // (1.0f / 0.0f)
left = new PrimitiveExpression(1.0f).WithoutILInstruction().WithRR(new ConstantResolveResult(type, 1.0f));
right = new PrimitiveExpression(0.0f).WithoutILInstruction().WithRR(new ConstantResolveResult(type, 0.0f));
expression = new BinaryOperatorExpression(left, BinaryOperatorType.Divide, right).WithoutILInstruction()
.WithRR(resolver.ResolveBinaryOperator(BinaryOperatorType.Divide, left.ResolveResult, right.ResolveResult));
return true;
case float.NaN: // (0.0f / 0.0f)
left = new PrimitiveExpression(0.0f).WithoutILInstruction().WithRR(new ConstantResolveResult(type, 0.0f));
right = new PrimitiveExpression(0.0f).WithoutILInstruction().WithRR(new ConstantResolveResult(type, 0.0f));
expression = new BinaryOperatorExpression(left, BinaryOperatorType.Divide, right).WithoutILInstruction()
.WithRR(resolver.ResolveBinaryOperator(BinaryOperatorType.Divide, left.ResolveResult, right.ResolveResult));
return true;
}
}
return false;
}
expression = new TypeReferenceExpression(ConvertType(type));
if (AddResolveResultAnnotations)
expression.AddAnnotation(new TypeResolveResult(type));
expression = new MemberReferenceExpression(expression, info.Member);
if (AddResolveResultAnnotations)
expression.AddAnnotation(new MemberResolveResult(new TypeResolveResult(type), type.GetFields(p => p.Name == info.Member).Single()));
return true;
}
Dictionary<object, (KnownTypeCode Type, string Member)> specialConstants = new Dictionary<object, (KnownTypeCode Type, string Member)>() {
// byte:
{ byte.MaxValue, (KnownTypeCode.Byte, "MaxValue") },
// sbyte:
{ sbyte.MinValue, (KnownTypeCode.SByte, "MinValue") },
{ sbyte.MaxValue, (KnownTypeCode.SByte, "MaxValue") },
// short:
{ short.MinValue, (KnownTypeCode.Int16, "MinValue") },
{ short.MaxValue, (KnownTypeCode.Int16, "MaxValue") },
// ushort:
{ ushort.MaxValue, (KnownTypeCode.UInt16, "MaxValue") },
// int:
{ int.MinValue, (KnownTypeCode.Int32, "MinValue") },
{ int.MaxValue, (KnownTypeCode.Int32, "MaxValue") },
// uint:
{ uint.MaxValue, (KnownTypeCode.UInt32, "MaxValue") },
// long:
{ long.MinValue, (KnownTypeCode.Int64, "MinValue") },
{ long.MaxValue, (KnownTypeCode.Int64, "MaxValue") },
// ulong:
{ ulong.MaxValue, (KnownTypeCode.UInt64, "MaxValue") },
// float:
{ float.NaN, (KnownTypeCode.Single, "NaN") },
{ float.NegativeInfinity, (KnownTypeCode.Single, "NegativeInfinity") },
{ float.PositiveInfinity, (KnownTypeCode.Single, "PositiveInfinity") },
{ float.MinValue, (KnownTypeCode.Single, "MinValue") },
{ float.MaxValue, (KnownTypeCode.Single, "MaxValue") },
{ float.Epsilon, (KnownTypeCode.Single, "Epsilon") },
// double:
{ double.NaN, (KnownTypeCode.Double, "NaN") },
{ double.NegativeInfinity, (KnownTypeCode.Double, "NegativeInfinity") },
{ double.PositiveInfinity, (KnownTypeCode.Double, "PositiveInfinity") },
{ double.MinValue, (KnownTypeCode.Double, "MinValue") },
{ double.MaxValue, (KnownTypeCode.Double, "MaxValue") },
{ double.Epsilon, (KnownTypeCode.Double, "Epsilon") },
// decimal:
{ decimal.MinValue, (KnownTypeCode.Decimal, "MinValue") },
{ decimal.MaxValue, (KnownTypeCode.Decimal, "MaxValue") },
};
bool IsFlagsEnum(ITypeDefinition type)
{
IType flagsAttributeType = type.Compilation.FindType(typeof(System.FlagsAttribute));

2
ICSharpCode.Decompiler/TypeSystem/ReflectionHelper.cs

@ -175,7 +175,7 @@ namespace ICSharpCode.Decompiler.TypeSystem @@ -175,7 +175,7 @@ namespace ICSharpCode.Decompiler.TypeSystem
/// <summary>
/// Gets the type code for the specified type, or TypeCode.Empty if none of the other type codes match.
/// </summary>
public static TypeCode GetTypeCode(IType type)
public static TypeCode GetTypeCode(this IType type)
{
ITypeDefinition def = type as ITypeDefinition;
if (def != null) {

Loading…
Cancel
Save