diff --git a/ICSharpCode.Decompiler.Tests/CustomAttributes/S_CustomAttributes.cs b/ICSharpCode.Decompiler.Tests/CustomAttributes/S_CustomAttributes.cs index 415d106dc8..ee89268a93 100644 --- a/ICSharpCode.Decompiler.Tests/CustomAttributes/S_CustomAttributes.cs +++ b/ICSharpCode.Decompiler.Tests/CustomAttributes/S_CustomAttributes.cs @@ -44,7 +44,7 @@ public MyAttribute(object val) public enum ULongEnum : ulong { [My(null)] - MaxUInt64 = 18446744073709551615uL + MaxUInt64 = ulong.MaxValue } [AttributeUsage(AttributeTargets.Field)] public class TypesAttribute : Attribute diff --git a/ICSharpCode.Decompiler.Tests/ICSharpCode.Decompiler.Tests.csproj b/ICSharpCode.Decompiler.Tests/ICSharpCode.Decompiler.Tests.csproj index b5ed3d1ddd..3e6dac73ce 100644 --- a/ICSharpCode.Decompiler.Tests/ICSharpCode.Decompiler.Tests.csproj +++ b/ICSharpCode.Decompiler.Tests/ICSharpCode.Decompiler.Tests.csproj @@ -65,6 +65,7 @@ + diff --git a/ICSharpCode.Decompiler.Tests/PrettyTestRunner.cs b/ICSharpCode.Decompiler.Tests/PrettyTestRunner.cs index 0f7e227c90..898d27b8e7 100644 --- a/ICSharpCode.Decompiler.Tests/PrettyTestRunner.cs +++ b/ICSharpCode.Decompiler.Tests/PrettyTestRunner.cs @@ -267,6 +267,12 @@ public void RefLocalsAndReturns([ValueSource("roslynOnlyOptions")] CSharpCompile 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); diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.cs b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.cs index ccadff6232..143824d0b4 100644 --- a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.cs +++ b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.cs @@ -98,7 +98,7 @@ public static string SparseIntegerSwitch(int i) return "ten thousand"; case 10001: return "ten thousand and one"; - case 2147483647: + case int.MaxValue: return "int.MaxValue"; default: return "something else"; diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.il b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.il index 4cf8d7ecc8..daad6b12d2 100644 --- a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.il +++ b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.il @@ -1,6 +1,6 @@ // Microsoft (R) .NET Framework IL Disassembler. Version 4.6.1055.0 -// Copyright (c) Microsoft Corporation. Alle Rechte vorbehalten. +// Copyright (c) Microsoft Corporation. All rights reserved. @@ -10,7 +10,7 @@ .publickeytoken = (B7 7A 5C 56 19 34 E0 89 ) // .z\V.4.. .ver 4:0:0:0 } -.assembly 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 @@ .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 @@ IL_0015: brfalse IL_00e9 IL_001a: volatile. - IL_001c: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{0220E31A-C196-4C4B-B009-AED9A1DDD0BE}'::'$$method0x600000d-1' + IL_001c: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{9D56DD8F-56CC-4AA5-939D-F5DC041F1927}'::'$$method0x600000d-1' IL_0021: brtrue.s IL_0084 IL_0023: ldc.i4.7 @@ -921,9 +921,9 @@ IL_0078: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2::Add(!0, !1) IL_007d: volatile. - IL_007f: stsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{0220E31A-C196-4C4B-B009-AED9A1DDD0BE}'::'$$method0x600000d-1' + IL_007f: stsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{9D56DD8F-56CC-4AA5-939D-F5DC041F1927}'::'$$method0x600000d-1' IL_0084: volatile. - IL_0086: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{0220E31A-C196-4C4B-B009-AED9A1DDD0BE}'::'$$method0x600000d-1' + IL_0086: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{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::TryGetValue(!0, @@ -995,7 +995,7 @@ IL_0013: brfalse IL_0158 IL_0018: volatile. - IL_001a: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{0220E31A-C196-4C4B-B009-AED9A1DDD0BE}'::'$$method0x600000e-1' + IL_001a: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{9D56DD8F-56CC-4AA5-939D-F5DC041F1927}'::'$$method0x600000e-1' IL_001f: brtrue IL_00b8 IL_0024: ldc.i4.s 11 @@ -1056,9 +1056,9 @@ IL_00ac: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2::Add(!0, !1) IL_00b1: volatile. - IL_00b3: stsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{0220E31A-C196-4C4B-B009-AED9A1DDD0BE}'::'$$method0x600000e-1' + IL_00b3: stsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{9D56DD8F-56CC-4AA5-939D-F5DC041F1927}'::'$$method0x600000e-1' IL_00b8: volatile. - IL_00ba: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{0220E31A-C196-4C4B-B009-AED9A1DDD0BE}'::'$$method0x600000e-1' + IL_00ba: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{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::TryGetValue(!0, @@ -1346,7 +1346,7 @@ IL_003b: brfalse IL_012c IL_0040: volatile. - IL_0042: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{0220E31A-C196-4C4B-B009-AED9A1DDD0BE}'::'$$method0x6000013-1' + IL_0042: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{9D56DD8F-56CC-4AA5-939D-F5DC041F1927}'::'$$method0x6000013-1' IL_0047: brtrue.s IL_009e IL_0049: ldc.i4.6 @@ -1382,9 +1382,9 @@ IL_0092: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2::Add(!0, !1) IL_0097: volatile. - IL_0099: stsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{0220E31A-C196-4C4B-B009-AED9A1DDD0BE}'::'$$method0x6000013-1' + IL_0099: stsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{9D56DD8F-56CC-4AA5-939D-F5DC041F1927}'::'$$method0x6000013-1' IL_009e: volatile. - IL_00a0: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{0220E31A-C196-4C4B-B009-AED9A1DDD0BE}'::'$$method0x6000013-1' + IL_00a0: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{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::TryGetValue(!0, @@ -1611,17 +1611,17 @@ } // end of class ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch -.class private auto ansi '{0220E31A-C196-4C4B-B009-AED9A1DDD0BE}' +.class private auto ansi '{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 '$$method0x600000d-1' .field static assembly class [mscorlib]System.Collections.Generic.Dictionary`2 '$$method0x600000e-1' .field static assembly class [mscorlib]System.Collections.Generic.Dictionary`2 '$$method0x6000013-1' -} // end of class '{0220E31A-C196-4C4B-B009-AED9A1DDD0BE}' +} // end of class '{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 diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.opt.il b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.opt.il index ea89fd982f..d039e72569 100644 --- a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.opt.il +++ b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.opt.il @@ -1,6 +1,6 @@ // Microsoft (R) .NET Framework IL Disassembler. Version 4.6.1055.0 -// Copyright (c) Microsoft Corporation. Alle Rechte vorbehalten. +// Copyright (c) Microsoft Corporation. All rights reserved. @@ -10,7 +10,7 @@ .publickeytoken = (B7 7A 5C 56 19 34 E0 89 ) // .z\V.4.. .ver 4:0:0:0 } -.assembly 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 @@ .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 @@ IL_0013: brfalse IL_00db IL_0018: volatile. - IL_001a: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{DBA055A4-E95E-43C4-8BA9-D8F45F1AB075}'::'$$method0x600000d-1' + IL_001a: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{F6D6A0F8-249B-42E0-A06F-7A75134FD239}'::'$$method0x600000d-1' IL_001f: brtrue.s IL_0082 IL_0021: ldc.i4.7 @@ -790,9 +790,9 @@ IL_0076: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2::Add(!0, !1) IL_007b: volatile. - IL_007d: stsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{DBA055A4-E95E-43C4-8BA9-D8F45F1AB075}'::'$$method0x600000d-1' + IL_007d: stsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{F6D6A0F8-249B-42E0-A06F-7A75134FD239}'::'$$method0x600000d-1' IL_0082: volatile. - IL_0084: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{DBA055A4-E95E-43C4-8BA9-D8F45F1AB075}'::'$$method0x600000d-1' + IL_0084: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{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::TryGetValue(!0, @@ -850,7 +850,7 @@ IL_0011: brfalse IL_013d IL_0016: volatile. - IL_0018: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{DBA055A4-E95E-43C4-8BA9-D8F45F1AB075}'::'$$method0x600000e-1' + IL_0018: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{F6D6A0F8-249B-42E0-A06F-7A75134FD239}'::'$$method0x600000e-1' IL_001d: brtrue IL_00b6 IL_0022: ldc.i4.s 11 @@ -911,9 +911,9 @@ IL_00aa: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2::Add(!0, !1) IL_00af: volatile. - IL_00b1: stsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{DBA055A4-E95E-43C4-8BA9-D8F45F1AB075}'::'$$method0x600000e-1' + IL_00b1: stsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{F6D6A0F8-249B-42E0-A06F-7A75134FD239}'::'$$method0x600000e-1' IL_00b6: volatile. - IL_00b8: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{DBA055A4-E95E-43C4-8BA9-D8F45F1AB075}'::'$$method0x600000e-1' + IL_00b8: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{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::TryGetValue(!0, @@ -1139,7 +1139,7 @@ IL_0037: brfalse IL_011f IL_003c: volatile. - IL_003e: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{DBA055A4-E95E-43C4-8BA9-D8F45F1AB075}'::'$$method0x6000013-1' + IL_003e: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{F6D6A0F8-249B-42E0-A06F-7A75134FD239}'::'$$method0x6000013-1' IL_0043: brtrue.s IL_009a IL_0045: ldc.i4.6 @@ -1175,9 +1175,9 @@ IL_008e: call instance void class [mscorlib]System.Collections.Generic.Dictionary`2::Add(!0, !1) IL_0093: volatile. - IL_0095: stsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{DBA055A4-E95E-43C4-8BA9-D8F45F1AB075}'::'$$method0x6000013-1' + IL_0095: stsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{F6D6A0F8-249B-42E0-A06F-7A75134FD239}'::'$$method0x6000013-1' IL_009a: volatile. - IL_009c: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{DBA055A4-E95E-43C4-8BA9-D8F45F1AB075}'::'$$method0x6000013-1' + IL_009c: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2 '{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::TryGetValue(!0, @@ -1371,17 +1371,17 @@ } // end of class ICSharpCode.Decompiler.Tests.TestCases.Pretty.Switch -.class private auto ansi '{DBA055A4-E95E-43C4-8BA9-D8F45F1AB075}' +.class private auto ansi '{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 '$$method0x600000d-1' .field static assembly class [mscorlib]System.Collections.Generic.Dictionary`2 '$$method0x600000e-1' .field static assembly class [mscorlib]System.Collections.Generic.Dictionary`2 '$$method0x6000013-1' -} // end of class '{DBA055A4-E95E-43C4-8BA9-D8F45F1AB075}' +} // end of class '{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 diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.opt.roslyn.il b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.opt.roslyn.il index 9de091f627..17bfbec049 100644 --- a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.opt.roslyn.il +++ b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.opt.roslyn.il @@ -1,6 +1,6 @@ // Microsoft (R) .NET Framework IL Disassembler. Version 4.6.1055.0 -// Copyright (c) Microsoft Corporation. Alle Rechte vorbehalten. +// Copyright (c) Microsoft Corporation. All rights reserved. @@ -32,7 +32,7 @@ .stackreserve 0x00100000 .subsystem 0x0003 // WINDOWS_CUI .corflags 0x00000001 // ILONLY -// Image base: 0x01380000 +// Image base: 0x031B0000 // =============== CLASS MEMBERS DECLARATION =================== diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.roslyn.il b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.roslyn.il index aa0d6cada6..57477cdaec 100644 --- a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.roslyn.il +++ b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.roslyn.il @@ -1,6 +1,6 @@ // Microsoft (R) .NET Framework IL Disassembler. Version 4.6.1055.0 -// Copyright (c) Microsoft Corporation. Alle Rechte vorbehalten. +// Copyright (c) Microsoft Corporation. All rights reserved. @@ -32,7 +32,7 @@ .stackreserve 0x00100000 .subsystem 0x0003 // WINDOWS_CUI .corflags 0x00000001 // ILONLY -// Image base: 0x02460000 +// Image base: 0x04490000 // =============== CLASS MEMBERS DECLARATION =================== diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/WellKnownConstants.cs b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/WellKnownConstants.cs new file mode 100644 index 0000000000..fe839a7f63 --- /dev/null +++ b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/WellKnownConstants.cs @@ -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; + } +} \ No newline at end of file diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/WellKnownConstants.il b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/WellKnownConstants.il new file mode 100644 index 0000000000..c5df8965b6 --- /dev/null +++ b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/WellKnownConstants.il @@ -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 diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/WellKnownConstants.opt.il b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/WellKnownConstants.opt.il new file mode 100644 index 0000000000..b22b292ebb --- /dev/null +++ b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/WellKnownConstants.opt.il @@ -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 diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/WellKnownConstants.opt.roslyn.il b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/WellKnownConstants.opt.roslyn.il new file mode 100644 index 0000000000..75908595b6 --- /dev/null +++ b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/WellKnownConstants.opt.roslyn.il @@ -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 *********************** diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/WellKnownConstants.roslyn.il b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/WellKnownConstants.roslyn.il new file mode 100644 index 0000000000..38c2fc5fc3 --- /dev/null +++ b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/WellKnownConstants.roslyn.il @@ -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 *********************** diff --git a/ICSharpCode.Decompiler/CSharp/CSharpDecompiler.cs b/ICSharpCode.Decompiler/CSharp/CSharpDecompiler.cs index 0ce4e3426b..0d794260c3 100644 --- a/ICSharpCode.Decompiler/CSharp/CSharpDecompiler.cs +++ b/ICSharpCode.Decompiler/CSharp/CSharpDecompiler.cs @@ -895,6 +895,7 @@ EntityDeclaration DoDecompile(FieldDefinition fieldDefinition, IField field, ITy 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)) { diff --git a/ICSharpCode.Decompiler/CSharp/ExpressionBuilder.cs b/ICSharpCode.Decompiler/CSharp/ExpressionBuilder.cs index 3738bf375e..aa1efd8509 100644 --- a/ICSharpCode.Decompiler/CSharp/ExpressionBuilder.cs +++ b/ICSharpCode.Decompiler/CSharp/ExpressionBuilder.cs @@ -324,9 +324,8 @@ protected internal override TranslatedExpression VisitLdcF8(LdcF8 inst, Translat 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) diff --git a/ICSharpCode.Decompiler/CSharp/Syntax/TypeSystemAstBuilder.cs b/ICSharpCode.Decompiler/CSharp/Syntax/TypeSystemAstBuilder.cs index b75feb53fc..3d1af30aca 100644 --- a/ICSharpCode.Decompiler/CSharp/Syntax/TypeSystemAstBuilder.cs +++ b/ICSharpCode.Decompiler/CSharp/Syntax/TypeSystemAstBuilder.cs @@ -71,6 +71,7 @@ void InitProperties() this.ShowParameterNames = true; this.ShowConstantValues = true; this.UseAliases = true; + this.UseSpecialConstants = true; } /// @@ -171,6 +172,12 @@ void InitProperties() /// The default value is true. /// public bool UseAliases { get; set; } + + /// + /// Controls if constants like int.MaxValue are converted to a or . + /// The default value is true. + /// + public bool UseSpecialConstants { get; set; } #endregion #region Convert Type @@ -519,19 +526,130 @@ public Expression ConvertConstantValue(IType type, object constantValue) } 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 specialConstants = new Dictionary() { + // 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)); diff --git a/ICSharpCode.Decompiler/TypeSystem/ReflectionHelper.cs b/ICSharpCode.Decompiler/TypeSystem/ReflectionHelper.cs index df99fa91e8..9f0b82f6ff 100644 --- a/ICSharpCode.Decompiler/TypeSystem/ReflectionHelper.cs +++ b/ICSharpCode.Decompiler/TypeSystem/ReflectionHelper.cs @@ -175,7 +175,7 @@ public static ITypeReference ToTypeReference(this TypeCode typeCode) /// /// Gets the type code for the specified type, or TypeCode.Empty if none of the other type codes match. /// - public static TypeCode GetTypeCode(IType type) + public static TypeCode GetTypeCode(this IType type) { ITypeDefinition def = type as ITypeDefinition; if (def != null) {