Browse Source

Merge pull request #1350 from icsharpcode/floating-point-literals-pretty-print

Pretty print floating point literals; fix #517; fix #1314
pull/1405/head
Siegfried Pammer 7 years ago committed by GitHub
parent
commit
75523e7178
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 26
      ICSharpCode.Decompiler.Tests/TestCases/Pretty/InitializerTests.cs
  2. 30
      ICSharpCode.Decompiler.Tests/TestCases/Pretty/InitializerTests.il
  3. 24
      ICSharpCode.Decompiler.Tests/TestCases/Pretty/InitializerTests.opt.il
  4. 97
      ICSharpCode.Decompiler.Tests/TestCases/Pretty/InitializerTests.opt.roslyn.il
  5. 108
      ICSharpCode.Decompiler.Tests/TestCases/Pretty/InitializerTests.roslyn.il
  6. 87
      ICSharpCode.Decompiler.Tests/TestCases/Pretty/WellKnownConstants.cs
  7. 80
      ICSharpCode.Decompiler.Tests/TestCases/Pretty/WellKnownConstants.il
  8. 80
      ICSharpCode.Decompiler.Tests/TestCases/Pretty/WellKnownConstants.opt.il
  9. 80
      ICSharpCode.Decompiler.Tests/TestCases/Pretty/WellKnownConstants.opt.roslyn.il
  10. 80
      ICSharpCode.Decompiler.Tests/TestCases/Pretty/WellKnownConstants.roslyn.il
  11. 3
      ICSharpCode.Decompiler/CSharp/CSharpDecompiler.cs
  12. 19
      ICSharpCode.Decompiler/CSharp/ExpressionBuilder.cs
  13. 253
      ICSharpCode.Decompiler/CSharp/Syntax/TypeSystemAstBuilder.cs

26
ICSharpCode.Decompiler.Tests/TestCases/Pretty/InitializerTests.cs

@ -605,32 +605,32 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests
7, 7,
8, 8,
254, 254,
byte.MaxValue 255
}); });
} }
public static void ArraySByte() public static void ArraySByte()
{ {
X(Y(), new sbyte[8] { X(Y(), new sbyte[8] {
sbyte.MinValue, -128,
-127, -127,
0, 0,
1, 1,
2, 2,
3, 3,
4, 4,
sbyte.MaxValue 127
}); });
} }
public static void ArrayShort() public static void ArrayShort()
{ {
X(Y(), new short[5] { X(Y(), new short[5] {
short.MinValue, -32768,
-1, -1,
0, 0,
1, 1,
short.MaxValue 32767
}); });
} }
@ -642,7 +642,7 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests
32767, 32767,
32768, 32768,
65534, 65534,
ushort.MaxValue 65535
}); });
} }
@ -735,8 +735,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests
-100m, -100m,
0m, 0m,
100m, 100m,
decimal.MinValue, -79228162514264337593543950335m,
decimal.MaxValue, 79228162514264337593543950335m,
0.0000001m 0.0000001m
}); });
} }
@ -1414,6 +1414,16 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests
}); });
} }
private byte[] Issue1314()
{
return new byte[4] {
0,
1,
2,
255
};
}
private void Issue1251_Test(List<Item> list, OtherItem otherItem) private void Issue1251_Test(List<Item> list, OtherItem otherItem)
{ {
list.Add(new Item { list.Add(new Item {

30
ICSharpCode.Decompiler.Tests/TestCases/Pretty/InitializerTests.il

@ -3115,6 +3115,26 @@
IL_001a: ret IL_001a: ret
} // end of method TestCases::Issue1250_Test1 } // end of method TestCases::Issue1250_Test1
.method private hidebysig instance uint8[]
Issue1314() cil managed
{
// Code size 23 (0x17)
.maxstack 3
.locals init (uint8[] V_0)
IL_0000: nop
IL_0001: ldc.i4.4
IL_0002: newarr [mscorlib]System.Byte
IL_0007: dup
IL_0008: ldtoken field int32 '<PrivateImplementationDetails>'::'$$method0x6000040-1'
IL_000d: call void [mscorlib]System.Runtime.CompilerServices.RuntimeHelpers::InitializeArray(class [mscorlib]System.Array,
valuetype [mscorlib]System.RuntimeFieldHandle)
IL_0012: stloc.0
IL_0013: br.s IL_0015
IL_0015: ldloc.0
IL_0016: ret
} // end of method TestCases::Issue1314
.method private hidebysig instance void .method private hidebysig instance void
Issue1251_Test(class [mscorlib]System.Collections.Generic.List`1<class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/Item> list, Issue1251_Test(class [mscorlib]System.Collections.Generic.List`1<class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/Item> list,
class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/OtherItem otherItem) cil managed class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/OtherItem otherItem) cil managed
@ -4370,7 +4390,7 @@
IL_0787: newobj instance void int32[0...,0...]::.ctor(int32, IL_0787: newobj instance void int32[0...,0...]::.ctor(int32,
int32) int32)
IL_078c: dup IL_078c: dup
IL_078d: ldtoken field valuetype '<PrivateImplementationDetails>'/'__StaticArrayInitTypeSize=36' '<PrivateImplementationDetails>'::'$$method0x600008e-1' IL_078d: ldtoken field valuetype '<PrivateImplementationDetails>'/'__StaticArrayInitTypeSize=36' '<PrivateImplementationDetails>'::'$$method0x600008f-1'
IL_0792: call void [mscorlib]System.Runtime.CompilerServices.RuntimeHelpers::InitializeArray(class [mscorlib]System.Array, IL_0792: call void [mscorlib]System.Runtime.CompilerServices.RuntimeHelpers::InitializeArray(class [mscorlib]System.Array,
valuetype [mscorlib]System.RuntimeFieldHandle) valuetype [mscorlib]System.RuntimeFieldHandle)
IL_0797: stsfld int32[0...,0...] ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases::Issue1336_rg2 IL_0797: stsfld int32[0...,0...] ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases::Issue1336_rg2
@ -4474,7 +4494,8 @@
.field static assembly valuetype '<PrivateImplementationDetails>'/'__StaticArrayInitTypeSize=64' '$$method0x600001e-4' at I_000029A8 .field static assembly valuetype '<PrivateImplementationDetails>'/'__StaticArrayInitTypeSize=64' '$$method0x600001e-4' at I_000029A8
.field static assembly valuetype '<PrivateImplementationDetails>'/'__StaticArrayInitTypeSize=72' '$$method0x600001f-1' at I_00002A58 .field static assembly valuetype '<PrivateImplementationDetails>'/'__StaticArrayInitTypeSize=72' '$$method0x600001f-1' at I_00002A58
.field static assembly valuetype '<PrivateImplementationDetails>'/'__StaticArrayInitTypeSize=72' '$$method0x600001f-2' at I_00002AA0 .field static assembly valuetype '<PrivateImplementationDetails>'/'__StaticArrayInitTypeSize=72' '$$method0x600001f-2' at I_00002AA0
.field static assembly valuetype '<PrivateImplementationDetails>'/'__StaticArrayInitTypeSize=36' '$$method0x600008e-1' at I_000035A0 .field static assembly int32 '$$method0x6000040-1' at I_000032E0
.field static assembly valuetype '<PrivateImplementationDetails>'/'__StaticArrayInitTypeSize=36' '$$method0x600008f-1' at I_000035C8
} // end of class '<PrivateImplementationDetails>' } // end of class '<PrivateImplementationDetails>'
@ -4583,7 +4604,10 @@
22 00 00 00 23 00 00 00 24 00 00 00 25 00 00 00 // "...#...$...%... 22 00 00 00 23 00 00 00 24 00 00 00 25 00 00 00 // "...#...$...%...
26 00 00 00 27 00 00 00) // &...'... 26 00 00 00 27 00 00 00) // &...'...
.data cil I_00002AE8 = int8[24] .data cil I_00002AE8 = int8[24]
.data cil I_000035A0 = bytearray ( .data cil I_000032E0 = bytearray (
00 01 02 FF)
.data cil I_000032E4 = int8[4]
.data cil I_000035C8 = bytearray (
01 00 00 00 01 00 00 00 01 00 00 00 01 00 00 00 01 00 00 00 01 00 00 00 01 00 00 00 01 00 00 00
01 00 00 00 01 00 00 00 01 00 00 00 01 00 00 00 01 00 00 00 01 00 00 00 01 00 00 00 01 00 00 00
01 00 00 00) 01 00 00 00)

24
ICSharpCode.Decompiler.Tests/TestCases/Pretty/InitializerTests.opt.il

@ -2733,6 +2733,20 @@
IL_0018: ret IL_0018: ret
} // end of method TestCases::Issue1250_Test1 } // end of method TestCases::Issue1250_Test1
.method private hidebysig instance uint8[]
Issue1314() cil managed
{
// Code size 18 (0x12)
.maxstack 8
IL_0000: ldc.i4.4
IL_0001: newarr [mscorlib]System.Byte
IL_0006: dup
IL_0007: ldtoken field int32 '<PrivateImplementationDetails>'::'$$method0x6000040-1'
IL_000c: call void [mscorlib]System.Runtime.CompilerServices.RuntimeHelpers::InitializeArray(class [mscorlib]System.Array,
valuetype [mscorlib]System.RuntimeFieldHandle)
IL_0011: ret
} // end of method TestCases::Issue1314
.method private hidebysig instance void .method private hidebysig instance void
Issue1251_Test(class [mscorlib]System.Collections.Generic.List`1<class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/Item> list, Issue1251_Test(class [mscorlib]System.Collections.Generic.List`1<class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/Item> list,
class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/OtherItem otherItem) cil managed class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/OtherItem otherItem) cil managed
@ -3938,7 +3952,7 @@
IL_07df: newobj instance void int32[0...,0...]::.ctor(int32, IL_07df: newobj instance void int32[0...,0...]::.ctor(int32,
int32) int32)
IL_07e4: dup IL_07e4: dup
IL_07e5: ldtoken field valuetype '<PrivateImplementationDetails>'/'__StaticArrayInitTypeSize=36' '<PrivateImplementationDetails>'::'$$method0x600008e-1' IL_07e5: ldtoken field valuetype '<PrivateImplementationDetails>'/'__StaticArrayInitTypeSize=36' '<PrivateImplementationDetails>'::'$$method0x600008f-1'
IL_07ea: call void [mscorlib]System.Runtime.CompilerServices.RuntimeHelpers::InitializeArray(class [mscorlib]System.Array, IL_07ea: call void [mscorlib]System.Runtime.CompilerServices.RuntimeHelpers::InitializeArray(class [mscorlib]System.Array,
valuetype [mscorlib]System.RuntimeFieldHandle) valuetype [mscorlib]System.RuntimeFieldHandle)
IL_07ef: stsfld int32[0...,0...] ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases::Issue1336_rg2 IL_07ef: stsfld int32[0...,0...] ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases::Issue1336_rg2
@ -4042,7 +4056,8 @@
.field static assembly valuetype '<PrivateImplementationDetails>'/'__StaticArrayInitTypeSize=64' '$$method0x600001e-4' at I_00002938 .field static assembly valuetype '<PrivateImplementationDetails>'/'__StaticArrayInitTypeSize=64' '$$method0x600001e-4' at I_00002938
.field static assembly valuetype '<PrivateImplementationDetails>'/'__StaticArrayInitTypeSize=72' '$$method0x600001f-1' at I_000029E8 .field static assembly valuetype '<PrivateImplementationDetails>'/'__StaticArrayInitTypeSize=72' '$$method0x600001f-1' at I_000029E8
.field static assembly valuetype '<PrivateImplementationDetails>'/'__StaticArrayInitTypeSize=72' '$$method0x600001f-2' at I_00002A30 .field static assembly valuetype '<PrivateImplementationDetails>'/'__StaticArrayInitTypeSize=72' '$$method0x600001f-2' at I_00002A30
.field static assembly valuetype '<PrivateImplementationDetails>'/'__StaticArrayInitTypeSize=36' '$$method0x600008e-1' at I_00003450 .field static assembly int32 '$$method0x6000040-1' at I_000031D0
.field static assembly valuetype '<PrivateImplementationDetails>'/'__StaticArrayInitTypeSize=36' '$$method0x600008f-1' at I_00003470
} // end of class '<PrivateImplementationDetails>' } // end of class '<PrivateImplementationDetails>'
@ -4149,7 +4164,10 @@
22 00 00 00 23 00 00 00 24 00 00 00 25 00 00 00 // "...#...$...%... 22 00 00 00 23 00 00 00 24 00 00 00 25 00 00 00 // "...#...$...%...
26 00 00 00 27 00 00 00) // &...'... 26 00 00 00 27 00 00 00) // &...'...
.data cil I_00002A78 = int8[8] .data cil I_00002A78 = int8[8]
.data cil I_00003450 = bytearray ( .data cil I_000031D0 = bytearray (
00 01 02 FF)
.data cil I_000031D4 = int8[12]
.data cil I_00003470 = bytearray (
01 00 00 00 01 00 00 00 01 00 00 00 01 00 00 00 01 00 00 00 01 00 00 00 01 00 00 00 01 00 00 00
01 00 00 00 01 00 00 00 01 00 00 00 01 00 00 00 01 00 00 00 01 00 00 00 01 00 00 00 01 00 00 00
01 00 00 00) 01 00 00 00)

97
ICSharpCode.Decompiler.Tests/TestCases/Pretty/InitializerTests.opt.roslyn.il

@ -2684,6 +2684,20 @@
IL_0016: ret IL_0016: ret
} // end of method TestCases::Issue1250_Test1 } // end of method TestCases::Issue1250_Test1
.method private hidebysig instance uint8[]
Issue1314() cil managed
{
// Code size 18 (0x12)
.maxstack 8
IL_0000: ldc.i4.4
IL_0001: newarr [mscorlib]System.Byte
IL_0006: dup
IL_0007: ldtoken field int32 '<PrivateImplementationDetails>'::C62C27924F4C967F5EDDB1850C091D54C7A2AB58
IL_000c: call void [mscorlib]System.Runtime.CompilerServices.RuntimeHelpers::InitializeArray(class [mscorlib]System.Array,
valuetype [mscorlib]System.RuntimeFieldHandle)
IL_0011: ret
} // end of method TestCases::Issue1314
.method private hidebysig instance void .method private hidebysig instance void
Issue1251_Test(class [mscorlib]System.Collections.Generic.List`1<class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/Item> list, Issue1251_Test(class [mscorlib]System.Collections.Generic.List`1<class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/Item> list,
class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/OtherItem otherItem) cil managed class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/OtherItem otherItem) cil managed
@ -3996,66 +4010,67 @@
.size 256 .size 256
} // end of class '__StaticArrayInitTypeSize=256' } // end of class '__StaticArrayInitTypeSize=256'
.field static assembly initonly valuetype '<PrivateImplementationDetails>'/'__StaticArrayInitTypeSize=72' '1535117EC92E41D4A6B7CA00F965357B05B5DC35' at I_00006B94 .field static assembly initonly valuetype '<PrivateImplementationDetails>'/'__StaticArrayInitTypeSize=72' '1535117EC92E41D4A6B7CA00F965357B05B5DC35' at I_00006BF4
.field static assembly initonly valuetype '<PrivateImplementationDetails>'/'__StaticArrayInitTypeSize=10' '20E3FF489634E18F3F7EB292AD504DBAE9519293' at I_00006BDC .field static assembly initonly valuetype '<PrivateImplementationDetails>'/'__StaticArrayInitTypeSize=10' '20E3FF489634E18F3F7EB292AD504DBAE9519293' at I_00006C3C
.field static assembly initonly valuetype '<PrivateImplementationDetails>'/'__StaticArrayInitTypeSize=72' '39E94835525CF7B71CD4595742EF462642FBF1B2' at I_00006BEC .field static assembly initonly valuetype '<PrivateImplementationDetails>'/'__StaticArrayInitTypeSize=72' '39E94835525CF7B71CD4595742EF462642FBF1B2' at I_00006C4C
.field static assembly initonly valuetype '<PrivateImplementationDetails>'/'__StaticArrayInitTypeSize=10' '56D9EEC8EF899644C40B9BE9D886DF2367A5D078' at I_00006C34 .field static assembly initonly valuetype '<PrivateImplementationDetails>'/'__StaticArrayInitTypeSize=10' '56D9EEC8EF899644C40B9BE9D886DF2367A5D078' at I_00006C94
.field static assembly initonly valuetype '<PrivateImplementationDetails>'/'__StaticArrayInitTypeSize=12' '735E5A21849E86F68D220F06163E8C5C6376B9C9' at I_00006C44 .field static assembly initonly valuetype '<PrivateImplementationDetails>'/'__StaticArrayInitTypeSize=12' '735E5A21849E86F68D220F06163E8C5C6376B9C9' at I_00006CA4
.field static assembly initonly valuetype '<PrivateImplementationDetails>'/'__StaticArrayInitTypeSize=64' '7C39B7B06DD624A17F875AB8E9651554BE6E74D2' at I_00006C54 .field static assembly initonly valuetype '<PrivateImplementationDetails>'/'__StaticArrayInitTypeSize=64' '7C39B7B06DD624A17F875AB8E9651554BE6E74D2' at I_00006CB4
.field static assembly initonly valuetype '<PrivateImplementationDetails>'/'__StaticArrayInitTypeSize=40' '8D903ECAD8D9D75B3183B23AF79F6D2E607369E3' at I_00006C94 .field static assembly initonly valuetype '<PrivateImplementationDetails>'/'__StaticArrayInitTypeSize=40' '8D903ECAD8D9D75B3183B23AF79F6D2E607369E3' at I_00006CF4
.field static assembly initonly valuetype '<PrivateImplementationDetails>'/'__StaticArrayInitTypeSize=80' '9B1F6E56D755443CC39C1969CE38FD41FD4EF4B7' at I_00006CBC .field static assembly initonly valuetype '<PrivateImplementationDetails>'/'__StaticArrayInitTypeSize=80' '9B1F6E56D755443CC39C1969CE38FD41FD4EF4B7' at I_00006D1C
.field static assembly initonly valuetype '<PrivateImplementationDetails>'/'__StaticArrayInitTypeSize=256' A1EA7DC3FE43B3A54F5B729A92B92AF54181A3EB at I_00006D0C .field static assembly initonly valuetype '<PrivateImplementationDetails>'/'__StaticArrayInitTypeSize=256' A1EA7DC3FE43B3A54F5B729A92B92AF54181A3EB at I_00006D6C
.field static assembly initonly int64 A6296CAC471BE2954899600137940479D8073C7C at I_00006E0C .field static assembly initonly int64 A6296CAC471BE2954899600137940479D8073C7C at I_00006E6C
.field static assembly initonly valuetype '<PrivateImplementationDetails>'/'__StaticArrayInitTypeSize=36' B62E59D20E3D69F06A6D9BD5E3C518FF7093EDAB at I_00006E14 .field static assembly initonly valuetype '<PrivateImplementationDetails>'/'__StaticArrayInitTypeSize=36' B62E59D20E3D69F06A6D9BD5E3C518FF7093EDAB at I_00006E74
.field static assembly initonly valuetype '<PrivateImplementationDetails>'/'__StaticArrayInitTypeSize=40' B9583930B842DBCEF0D7B8E57D4D3F1E8055C39E at I_00006E3C .field static assembly initonly valuetype '<PrivateImplementationDetails>'/'__StaticArrayInitTypeSize=40' B9583930B842DBCEF0D7B8E57D4D3F1E8055C39E at I_00006E9C
.field static assembly initonly valuetype '<PrivateImplementationDetails>'/'__StaticArrayInitTypeSize=24' C4E70AB31EF6C8908F896CAD1C6BC75F7FA65E27 at I_00006E64 .field static assembly initonly valuetype '<PrivateImplementationDetails>'/'__StaticArrayInitTypeSize=24' C4E70AB31EF6C8908F896CAD1C6BC75F7FA65E27 at I_00006EC4
.field static assembly initonly valuetype '<PrivateImplementationDetails>'/'__StaticArrayInitTypeSize=48' DC7043B0114737ACE19A23DD755893795FD48A23 at I_00006E7C .field static assembly initonly int32 C62C27924F4C967F5EDDB1850C091D54C7A2AB58 at I_00006EDC
.field static assembly initonly valuetype '<PrivateImplementationDetails>'/'__StaticArrayInitTypeSize=64' DCF557B883E6FE0AEC05B7F0290F0EF47D0AC2E3 at I_00006EAC .field static assembly initonly valuetype '<PrivateImplementationDetails>'/'__StaticArrayInitTypeSize=48' DC7043B0114737ACE19A23DD755893795FD48A23 at I_00006EE4
.field static assembly initonly valuetype '<PrivateImplementationDetails>'/'__StaticArrayInitTypeSize=40' E0D2592373A0C161E56E266306CD8405CD719D19 at I_00006EEC .field static assembly initonly valuetype '<PrivateImplementationDetails>'/'__StaticArrayInitTypeSize=64' DCF557B883E6FE0AEC05B7F0290F0EF47D0AC2E3 at I_00006F14
.field static assembly initonly int64 EB0715DBB235F3F696F2C404F5839C6650640898 at I_00006F14 .field static assembly initonly valuetype '<PrivateImplementationDetails>'/'__StaticArrayInitTypeSize=40' E0D2592373A0C161E56E266306CD8405CD719D19 at I_00006F54
.field static assembly initonly valuetype '<PrivateImplementationDetails>'/'__StaticArrayInitTypeSize=40' F514FF55B79BCAA2CEC9B56C062D976E45F89AB7 at I_00006F1C .field static assembly initonly int64 EB0715DBB235F3F696F2C404F5839C6650640898 at I_00006F7C
.field static assembly initonly valuetype '<PrivateImplementationDetails>'/'__StaticArrayInitTypeSize=24' FBCB49C1A244C1B5781AA1DB02C5A11F68908526 at I_00006F44 .field static assembly initonly valuetype '<PrivateImplementationDetails>'/'__StaticArrayInitTypeSize=40' F514FF55B79BCAA2CEC9B56C062D976E45F89AB7 at I_00006F84
.field static assembly initonly valuetype '<PrivateImplementationDetails>'/'__StaticArrayInitTypeSize=24' FBCB49C1A244C1B5781AA1DB02C5A11F68908526 at I_00006FAC
} // end of class '<PrivateImplementationDetails>' } // end of class '<PrivateImplementationDetails>'
// ============================================================= // =============================================================
.data cil I_00006B94 = bytearray ( .data cil I_00006BF4 = bytearray (
01 00 00 00 02 00 00 00 03 00 00 00 04 00 00 00 01 00 00 00 02 00 00 00 03 00 00 00 04 00 00 00
05 00 00 00 06 00 00 00 07 00 00 00 08 00 00 00 05 00 00 00 06 00 00 00 07 00 00 00 08 00 00 00
09 00 00 00 0B 00 00 00 0C 00 00 00 0D 00 00 00 09 00 00 00 0B 00 00 00 0C 00 00 00 0D 00 00 00
0E 00 00 00 0F 00 00 00 10 00 00 00 11 00 00 00 0E 00 00 00 0F 00 00 00 10 00 00 00 11 00 00 00
12 00 00 00 13 00 00 00) 12 00 00 00 13 00 00 00)
.data cil I_00006BDC = bytearray ( .data cil I_00006C3C = bytearray (
01 02 03 04 05 06 07 08 FE FF) 01 02 03 04 05 06 07 08 FE FF)
.data cil I_00006BE6 = int8[2] .data cil I_00006C46 = int8[2]
.data cil I_00006BEC = bytearray ( .data cil I_00006C4C = bytearray (
15 00 00 00 16 00 00 00 17 00 00 00 18 00 00 00 15 00 00 00 16 00 00 00 17 00 00 00 18 00 00 00
19 00 00 00 1A 00 00 00 1B 00 00 00 1C 00 00 00 19 00 00 00 1A 00 00 00 1B 00 00 00 1C 00 00 00
1D 00 00 00 1F 00 00 00 20 00 00 00 21 00 00 00 // ........ ...!... 1D 00 00 00 1F 00 00 00 20 00 00 00 21 00 00 00 // ........ ...!...
22 00 00 00 23 00 00 00 24 00 00 00 25 00 00 00 // "...#...$...%... 22 00 00 00 23 00 00 00 24 00 00 00 25 00 00 00 // "...#...$...%...
26 00 00 00 27 00 00 00) // &...'... 26 00 00 00 27 00 00 00) // &...'...
.data cil I_00006C34 = bytearray ( .data cil I_00006C94 = bytearray (
00 80 FF FF 00 00 01 00 FF 7F) 00 80 FF FF 00 00 01 00 FF 7F)
.data cil I_00006C3E = int8[2] .data cil I_00006C9E = int8[2]
.data cil I_00006C44 = bytearray ( .data cil I_00006CA4 = bytearray (
00 00 01 00 FF 7F 00 80 FE FF FF FF) 00 00 01 00 FF 7F 00 80 FE FF FF FF)
.data cil I_00006C54 = bytearray ( .data cil I_00006CB4 = bytearray (
00 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00) 00 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00)
.data cil I_00006C94 = bytearray ( .data cil I_00006CF4 = bytearray (
01 00 0C BB 7D 6E 9C BA FF FF FF FF FF FF FF FF // ....}n.......... 01 00 0C BB 7D 6E 9C BA FF FF FF FF FF FF FF FF // ....}n..........
00 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00
FF FF F3 44 82 91 63 45) // ...D..cE FF FF F3 44 82 91 63 45) // ...D..cE
.data cil I_00006CBC = bytearray ( .data cil I_00006D1C = bytearray (
01 00 00 00 00 00 00 00 00 94 35 77 00 00 00 00 // ..........5w.... 01 00 00 00 00 00 00 00 00 94 35 77 00 00 00 00 // ..........5w....
00 5E D0 B2 00 00 00 00 04 00 00 00 00 00 00 00 // .^.............. 00 5E D0 B2 00 00 00 00 04 00 00 00 00 00 00 00 // .^..............
05 00 00 00 00 00 00 00 06 00 00 00 00 00 00 00 05 00 00 00 00 00 00 00 06 00 00 00 00 00 00 00
07 00 00 00 00 00 00 00 08 00 00 00 00 00 00 00 07 00 00 00 00 00 00 00 08 00 00 00 00 00 00 00
FF FF F3 44 82 91 63 45 FF FF E7 89 04 23 C7 8A) // ...D..cE.....#.. FF FF F3 44 82 91 63 45 FF FF E7 89 04 23 C7 8A) // ...D..cE.....#..
.data cil I_00006D0C = bytearray ( .data cil I_00006D6C = bytearray (
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
01 00 00 00 01 00 00 00 01 00 00 00 01 00 00 00 01 00 00 00 01 00 00 00 01 00 00 00 01 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
@ -4072,39 +4087,41 @@
00 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00) 00 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00)
.data cil I_00006E0C = bytearray ( .data cil I_00006E6C = bytearray (
80 81 00 01 02 03 04 7F) 80 81 00 01 02 03 04 7F)
.data cil I_00006E14 = bytearray ( .data cil I_00006E74 = bytearray (
01 00 00 00 01 00 00 00 01 00 00 00 01 00 00 00 01 00 00 00 01 00 00 00 01 00 00 00 01 00 00 00
01 00 00 00 01 00 00 00 01 00 00 00 01 00 00 00 01 00 00 00 01 00 00 00 01 00 00 00 01 00 00 00
01 00 00 00) 01 00 00 00)
.data cil I_00006E3C = bytearray ( .data cil I_00006E9C = bytearray (
01 00 00 00 00 94 35 77 00 5E D0 B2 04 00 00 00 // ......5w.^...... 01 00 00 00 00 94 35 77 00 5E D0 B2 04 00 00 00 // ......5w.^......
05 00 00 00 06 00 00 00 07 00 00 00 08 00 00 00 05 00 00 00 06 00 00 00 07 00 00 00 08 00 00 00
09 00 00 00 0A 00 00 00) 09 00 00 00 0A 00 00 00)
.data cil I_00006E64 = bytearray ( .data cil I_00006EC4 = bytearray (
01 00 00 00 02 00 00 00 03 00 00 00 04 00 00 00 01 00 00 00 02 00 00 00 03 00 00 00 04 00 00 00
05 00 00 00 06 00 00 00) 05 00 00 00 06 00 00 00)
.data cil I_00006E7C = bytearray ( .data cil I_00006EDC = bytearray (
00 01 02 FF)
.data cil I_00006EE4 = bytearray (
00 00 00 00 00 00 F8 BF 00 00 00 00 00 00 00 00 00 00 00 00 00 00 F8 BF 00 00 00 00 00 00 00 00
00 00 00 00 00 00 F8 3F 00 00 00 00 00 00 F0 FF // .......?........ 00 00 00 00 00 00 F8 3F 00 00 00 00 00 00 F0 FF // .......?........
00 00 00 00 00 00 F0 7F 00 00 00 00 00 00 F8 FF) 00 00 00 00 00 00 F0 7F 00 00 00 00 00 00 F8 FF)
.data cil I_00006EAC = bytearray ( .data cil I_00006F14 = bytearray (
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
01 00 00 00 01 00 00 00 01 00 00 00 01 00 00 00 01 00 00 00 01 00 00 00 01 00 00 00 01 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00) 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00)
.data cil I_00006EEC = bytearray ( .data cil I_00006F54 = bytearray (
01 00 00 00 02 00 00 00 03 00 00 00 04 00 00 00 01 00 00 00 02 00 00 00 03 00 00 00 04 00 00 00
05 00 00 00 06 00 00 00 07 00 00 00 08 00 00 00 05 00 00 00 06 00 00 00 07 00 00 00 08 00 00 00
09 00 00 00 0A 00 00 00) 09 00 00 00 0A 00 00 00)
.data cil I_00006F14 = bytearray ( .data cil I_00006F7C = bytearray (
01 00 01 00 00 00 01 01) 01 00 01 00 00 00 01 01)
.data cil I_00006F1C = bytearray ( .data cil I_00006F84 = bytearray (
01 00 00 00 FE FF FF FF 00 94 35 77 04 00 00 00 // ..........5w.... 01 00 00 00 FE FF FF FF 00 94 35 77 04 00 00 00 // ..........5w....
05 00 00 00 FA FF FF FF 07 00 00 00 08 00 00 00 05 00 00 00 FA FF FF FF 07 00 00 00 08 00 00 00
09 00 00 00 0A 00 00 00) 09 00 00 00 0A 00 00 00)
.data cil I_00006F44 = bytearray ( .data cil I_00006FAC = bytearray (
00 00 C0 BF 00 00 00 00 00 00 C0 3F 00 00 80 FF // ...........?.... 00 00 C0 BF 00 00 00 00 00 00 C0 3F 00 00 80 FF // ...........?....
00 00 80 7F 00 00 C0 FF) 00 00 80 7F 00 00 C0 FF)
// *********** DISASSEMBLY COMPLETE *********************** // *********** DISASSEMBLY COMPLETE ***********************

108
ICSharpCode.Decompiler.Tests/TestCases/Pretty/InitializerTests.roslyn.il

@ -3015,6 +3015,26 @@
IL_0018: ret IL_0018: ret
} // end of method TestCases::Issue1250_Test1 } // end of method TestCases::Issue1250_Test1
.method private hidebysig instance uint8[]
Issue1314() cil managed
{
// Code size 23 (0x17)
.maxstack 3
.locals init (uint8[] V_0)
IL_0000: nop
IL_0001: ldc.i4.4
IL_0002: newarr [mscorlib]System.Byte
IL_0007: dup
IL_0008: ldtoken field int32 '<PrivateImplementationDetails>'::C62C27924F4C967F5EDDB1850C091D54C7A2AB58
IL_000d: call void [mscorlib]System.Runtime.CompilerServices.RuntimeHelpers::InitializeArray(class [mscorlib]System.Array,
valuetype [mscorlib]System.RuntimeFieldHandle)
IL_0012: stloc.0
IL_0013: br.s IL_0015
IL_0015: ldloc.0
IL_0016: ret
} // end of method TestCases::Issue1314
.method private hidebysig instance void .method private hidebysig instance void
Issue1251_Test(class [mscorlib]System.Collections.Generic.List`1<class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/Item> list, Issue1251_Test(class [mscorlib]System.Collections.Generic.List`1<class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/Item> list,
class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/OtherItem otherItem) cil managed class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/OtherItem otherItem) cil managed
@ -4421,67 +4441,68 @@
.size 256 .size 256
} // end of class '__StaticArrayInitTypeSize=256' } // end of class '__StaticArrayInitTypeSize=256'
.field static assembly initonly valuetype '<PrivateImplementationDetails>'/'__StaticArrayInitTypeSize=72' '1535117EC92E41D4A6B7CA00F965357B05B5DC35' at I_00006F58 .field static assembly initonly valuetype '<PrivateImplementationDetails>'/'__StaticArrayInitTypeSize=72' '1535117EC92E41D4A6B7CA00F965357B05B5DC35' at I_00006FD8
.field static assembly initonly valuetype '<PrivateImplementationDetails>'/'__StaticArrayInitTypeSize=10' '20E3FF489634E18F3F7EB292AD504DBAE9519293' at I_00006FA0 .field static assembly initonly valuetype '<PrivateImplementationDetails>'/'__StaticArrayInitTypeSize=10' '20E3FF489634E18F3F7EB292AD504DBAE9519293' at I_00007020
.field static assembly initonly valuetype '<PrivateImplementationDetails>'/'__StaticArrayInitTypeSize=72' '39E94835525CF7B71CD4595742EF462642FBF1B2' at I_00006FB0 .field static assembly initonly valuetype '<PrivateImplementationDetails>'/'__StaticArrayInitTypeSize=72' '39E94835525CF7B71CD4595742EF462642FBF1B2' at I_00007030
.field static assembly initonly valuetype '<PrivateImplementationDetails>'/'__StaticArrayInitTypeSize=10' '56D9EEC8EF899644C40B9BE9D886DF2367A5D078' at I_00006FF8 .field static assembly initonly valuetype '<PrivateImplementationDetails>'/'__StaticArrayInitTypeSize=10' '56D9EEC8EF899644C40B9BE9D886DF2367A5D078' at I_00007078
.field static assembly initonly valuetype '<PrivateImplementationDetails>'/'__StaticArrayInitTypeSize=12' '735E5A21849E86F68D220F06163E8C5C6376B9C9' at I_00007008 .field static assembly initonly valuetype '<PrivateImplementationDetails>'/'__StaticArrayInitTypeSize=12' '735E5A21849E86F68D220F06163E8C5C6376B9C9' at I_00007088
.field static assembly initonly valuetype '<PrivateImplementationDetails>'/'__StaticArrayInitTypeSize=64' '7C39B7B06DD624A17F875AB8E9651554BE6E74D2' at I_00007018 .field static assembly initonly valuetype '<PrivateImplementationDetails>'/'__StaticArrayInitTypeSize=64' '7C39B7B06DD624A17F875AB8E9651554BE6E74D2' at I_00007098
.field static assembly initonly valuetype '<PrivateImplementationDetails>'/'__StaticArrayInitTypeSize=40' '8D903ECAD8D9D75B3183B23AF79F6D2E607369E3' at I_00007058 .field static assembly initonly valuetype '<PrivateImplementationDetails>'/'__StaticArrayInitTypeSize=40' '8D903ECAD8D9D75B3183B23AF79F6D2E607369E3' at I_000070D8
.field static assembly initonly valuetype '<PrivateImplementationDetails>'/'__StaticArrayInitTypeSize=80' '9B1F6E56D755443CC39C1969CE38FD41FD4EF4B7' at I_00007080 .field static assembly initonly valuetype '<PrivateImplementationDetails>'/'__StaticArrayInitTypeSize=80' '9B1F6E56D755443CC39C1969CE38FD41FD4EF4B7' at I_00007100
.field static assembly initonly valuetype '<PrivateImplementationDetails>'/'__StaticArrayInitTypeSize=256' A1EA7DC3FE43B3A54F5B729A92B92AF54181A3EB at I_000070D0 .field static assembly initonly valuetype '<PrivateImplementationDetails>'/'__StaticArrayInitTypeSize=256' A1EA7DC3FE43B3A54F5B729A92B92AF54181A3EB at I_00007150
.field static assembly initonly int64 A6296CAC471BE2954899600137940479D8073C7C at I_000071D0 .field static assembly initonly int64 A6296CAC471BE2954899600137940479D8073C7C at I_00007250
.field static assembly initonly valuetype '<PrivateImplementationDetails>'/'__StaticArrayInitTypeSize=36' B62E59D20E3D69F06A6D9BD5E3C518FF7093EDAB at I_000071D8 .field static assembly initonly valuetype '<PrivateImplementationDetails>'/'__StaticArrayInitTypeSize=36' B62E59D20E3D69F06A6D9BD5E3C518FF7093EDAB at I_00007258
.field static assembly initonly valuetype '<PrivateImplementationDetails>'/'__StaticArrayInitTypeSize=40' B9583930B842DBCEF0D7B8E57D4D3F1E8055C39E at I_00007200 .field static assembly initonly valuetype '<PrivateImplementationDetails>'/'__StaticArrayInitTypeSize=40' B9583930B842DBCEF0D7B8E57D4D3F1E8055C39E at I_00007280
.field static assembly initonly valuetype '<PrivateImplementationDetails>'/'__StaticArrayInitTypeSize=24' C4E70AB31EF6C8908F896CAD1C6BC75F7FA65E27 at I_00007228 .field static assembly initonly valuetype '<PrivateImplementationDetails>'/'__StaticArrayInitTypeSize=24' C4E70AB31EF6C8908F896CAD1C6BC75F7FA65E27 at I_000072A8
.field static assembly initonly valuetype '<PrivateImplementationDetails>'/'__StaticArrayInitTypeSize=48' DC7043B0114737ACE19A23DD755893795FD48A23 at I_00007240 .field static assembly initonly int32 C62C27924F4C967F5EDDB1850C091D54C7A2AB58 at I_000072C0
.field static assembly initonly valuetype '<PrivateImplementationDetails>'/'__StaticArrayInitTypeSize=64' DCF557B883E6FE0AEC05B7F0290F0EF47D0AC2E3 at I_00007270 .field static assembly initonly valuetype '<PrivateImplementationDetails>'/'__StaticArrayInitTypeSize=48' DC7043B0114737ACE19A23DD755893795FD48A23 at I_000072C8
.field static assembly initonly valuetype '<PrivateImplementationDetails>'/'__StaticArrayInitTypeSize=40' E0D2592373A0C161E56E266306CD8405CD719D19 at I_000072B0 .field static assembly initonly valuetype '<PrivateImplementationDetails>'/'__StaticArrayInitTypeSize=64' DCF557B883E6FE0AEC05B7F0290F0EF47D0AC2E3 at I_000072F8
.field static assembly initonly int64 EB0715DBB235F3F696F2C404F5839C6650640898 at I_000072D8 .field static assembly initonly valuetype '<PrivateImplementationDetails>'/'__StaticArrayInitTypeSize=40' E0D2592373A0C161E56E266306CD8405CD719D19 at I_00007338
.field static assembly initonly valuetype '<PrivateImplementationDetails>'/'__StaticArrayInitTypeSize=40' F514FF55B79BCAA2CEC9B56C062D976E45F89AB7 at I_000072E0 .field static assembly initonly int64 EB0715DBB235F3F696F2C404F5839C6650640898 at I_00007360
.field static assembly initonly valuetype '<PrivateImplementationDetails>'/'__StaticArrayInitTypeSize=24' FBCB49C1A244C1B5781AA1DB02C5A11F68908526 at I_00007308 .field static assembly initonly valuetype '<PrivateImplementationDetails>'/'__StaticArrayInitTypeSize=40' F514FF55B79BCAA2CEC9B56C062D976E45F89AB7 at I_00007368
.field static assembly initonly valuetype '<PrivateImplementationDetails>'/'__StaticArrayInitTypeSize=24' FBCB49C1A244C1B5781AA1DB02C5A11F68908526 at I_00007390
} // end of class '<PrivateImplementationDetails>' } // end of class '<PrivateImplementationDetails>'
// ============================================================= // =============================================================
.data cil I_00006F58 = bytearray ( .data cil I_00006FD8 = bytearray (
01 00 00 00 02 00 00 00 03 00 00 00 04 00 00 00 01 00 00 00 02 00 00 00 03 00 00 00 04 00 00 00
05 00 00 00 06 00 00 00 07 00 00 00 08 00 00 00 05 00 00 00 06 00 00 00 07 00 00 00 08 00 00 00
09 00 00 00 0B 00 00 00 0C 00 00 00 0D 00 00 00 09 00 00 00 0B 00 00 00 0C 00 00 00 0D 00 00 00
0E 00 00 00 0F 00 00 00 10 00 00 00 11 00 00 00 0E 00 00 00 0F 00 00 00 10 00 00 00 11 00 00 00
12 00 00 00 13 00 00 00) 12 00 00 00 13 00 00 00)
.data cil I_00006FA0 = bytearray ( .data cil I_00007020 = bytearray (
01 02 03 04 05 06 07 08 FE FF) 01 02 03 04 05 06 07 08 FE FF)
.data cil I_00006FAA = int8[6] .data cil I_0000702A = int8[6]
.data cil I_00006FB0 = bytearray ( .data cil I_00007030 = bytearray (
15 00 00 00 16 00 00 00 17 00 00 00 18 00 00 00 15 00 00 00 16 00 00 00 17 00 00 00 18 00 00 00
19 00 00 00 1A 00 00 00 1B 00 00 00 1C 00 00 00 19 00 00 00 1A 00 00 00 1B 00 00 00 1C 00 00 00
1D 00 00 00 1F 00 00 00 20 00 00 00 21 00 00 00 // ........ ...!... 1D 00 00 00 1F 00 00 00 20 00 00 00 21 00 00 00 // ........ ...!...
22 00 00 00 23 00 00 00 24 00 00 00 25 00 00 00 // "...#...$...%... 22 00 00 00 23 00 00 00 24 00 00 00 25 00 00 00 // "...#...$...%...
26 00 00 00 27 00 00 00) // &...'... 26 00 00 00 27 00 00 00) // &...'...
.data cil I_00006FF8 = bytearray ( .data cil I_00007078 = bytearray (
00 80 FF FF 00 00 01 00 FF 7F) 00 80 FF FF 00 00 01 00 FF 7F)
.data cil I_00007002 = int8[6] .data cil I_00007082 = int8[6]
.data cil I_00007008 = bytearray ( .data cil I_00007088 = bytearray (
00 00 01 00 FF 7F 00 80 FE FF FF FF) 00 00 01 00 FF 7F 00 80 FE FF FF FF)
.data cil I_00007014 = int8[4] .data cil I_00007094 = int8[4]
.data cil I_00007018 = bytearray ( .data cil I_00007098 = bytearray (
00 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00) 00 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00)
.data cil I_00007058 = bytearray ( .data cil I_000070D8 = bytearray (
01 00 0C BB 7D 6E 9C BA FF FF FF FF FF FF FF FF // ....}n.......... 01 00 0C BB 7D 6E 9C BA FF FF FF FF FF FF FF FF // ....}n..........
00 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00
FF FF F3 44 82 91 63 45) // ...D..cE FF FF F3 44 82 91 63 45) // ...D..cE
.data cil I_00007080 = bytearray ( .data cil I_00007100 = bytearray (
01 00 00 00 00 00 00 00 00 94 35 77 00 00 00 00 // ..........5w.... 01 00 00 00 00 00 00 00 00 94 35 77 00 00 00 00 // ..........5w....
00 5E D0 B2 00 00 00 00 04 00 00 00 00 00 00 00 // .^.............. 00 5E D0 B2 00 00 00 00 04 00 00 00 00 00 00 00 // .^..............
05 00 00 00 00 00 00 00 06 00 00 00 00 00 00 00 05 00 00 00 00 00 00 00 06 00 00 00 00 00 00 00
07 00 00 00 00 00 00 00 08 00 00 00 00 00 00 00 07 00 00 00 00 00 00 00 08 00 00 00 00 00 00 00
FF FF F3 44 82 91 63 45 FF FF E7 89 04 23 C7 8A) // ...D..cE.....#.. FF FF F3 44 82 91 63 45 FF FF E7 89 04 23 C7 8A) // ...D..cE.....#..
.data cil I_000070D0 = bytearray ( .data cil I_00007150 = bytearray (
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
01 00 00 00 01 00 00 00 01 00 00 00 01 00 00 00 01 00 00 00 01 00 00 00 01 00 00 00 01 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
@ -4498,40 +4519,43 @@
00 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00) 00 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00)
.data cil I_000071D0 = bytearray ( .data cil I_00007250 = bytearray (
80 81 00 01 02 03 04 7F) 80 81 00 01 02 03 04 7F)
.data cil I_000071D8 = bytearray ( .data cil I_00007258 = bytearray (
01 00 00 00 01 00 00 00 01 00 00 00 01 00 00 00 01 00 00 00 01 00 00 00 01 00 00 00 01 00 00 00
01 00 00 00 01 00 00 00 01 00 00 00 01 00 00 00 01 00 00 00 01 00 00 00 01 00 00 00 01 00 00 00
01 00 00 00) 01 00 00 00)
.data cil I_000071FC = int8[4] .data cil I_0000727C = int8[4]
.data cil I_00007200 = bytearray ( .data cil I_00007280 = bytearray (
01 00 00 00 00 94 35 77 00 5E D0 B2 04 00 00 00 // ......5w.^...... 01 00 00 00 00 94 35 77 00 5E D0 B2 04 00 00 00 // ......5w.^......
05 00 00 00 06 00 00 00 07 00 00 00 08 00 00 00 05 00 00 00 06 00 00 00 07 00 00 00 08 00 00 00
09 00 00 00 0A 00 00 00) 09 00 00 00 0A 00 00 00)
.data cil I_00007228 = bytearray ( .data cil I_000072A8 = bytearray (
01 00 00 00 02 00 00 00 03 00 00 00 04 00 00 00 01 00 00 00 02 00 00 00 03 00 00 00 04 00 00 00
05 00 00 00 06 00 00 00) 05 00 00 00 06 00 00 00)
.data cil I_00007240 = bytearray ( .data cil I_000072C0 = bytearray (
00 01 02 FF)
.data cil I_000072C4 = int8[4]
.data cil I_000072C8 = bytearray (
00 00 00 00 00 00 F8 BF 00 00 00 00 00 00 00 00 00 00 00 00 00 00 F8 BF 00 00 00 00 00 00 00 00
00 00 00 00 00 00 F8 3F 00 00 00 00 00 00 F0 FF // .......?........ 00 00 00 00 00 00 F8 3F 00 00 00 00 00 00 F0 FF // .......?........
00 00 00 00 00 00 F0 7F 00 00 00 00 00 00 F8 FF) 00 00 00 00 00 00 F0 7F 00 00 00 00 00 00 F8 FF)
.data cil I_00007270 = bytearray ( .data cil I_000072F8 = bytearray (
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
01 00 00 00 01 00 00 00 01 00 00 00 01 00 00 00 01 00 00 00 01 00 00 00 01 00 00 00 01 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00) 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00)
.data cil I_000072B0 = bytearray ( .data cil I_00007338 = bytearray (
01 00 00 00 02 00 00 00 03 00 00 00 04 00 00 00 01 00 00 00 02 00 00 00 03 00 00 00 04 00 00 00
05 00 00 00 06 00 00 00 07 00 00 00 08 00 00 00 05 00 00 00 06 00 00 00 07 00 00 00 08 00 00 00
09 00 00 00 0A 00 00 00) 09 00 00 00 0A 00 00 00)
.data cil I_000072D8 = bytearray ( .data cil I_00007360 = bytearray (
01 00 01 00 00 00 01 01) 01 00 01 00 00 00 01 01)
.data cil I_000072E0 = bytearray ( .data cil I_00007368 = bytearray (
01 00 00 00 FE FF FF FF 00 94 35 77 04 00 00 00 // ..........5w.... 01 00 00 00 FE FF FF FF 00 94 35 77 04 00 00 00 // ..........5w....
05 00 00 00 FA FF FF FF 07 00 00 00 08 00 00 00 05 00 00 00 FA FF FF FF 07 00 00 00 08 00 00 00
09 00 00 00 0A 00 00 00) 09 00 00 00 0A 00 00 00)
.data cil I_00007308 = bytearray ( .data cil I_00007390 = bytearray (
00 00 C0 BF 00 00 00 00 00 00 C0 3F 00 00 80 FF // ...........?.... 00 00 C0 BF 00 00 00 00 00 00 C0 3F 00 00 80 FF // ...........?....
00 00 80 7F 00 00 C0 FF) 00 00 80 7F 00 00 C0 FF)
// *********** DISASSEMBLY COMPLETE *********************** // *********** DISASSEMBLY COMPLETE ***********************

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

@ -16,6 +16,8 @@
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE. // DEALINGS IN THE SOFTWARE.
using System;
namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
{ {
public class WellKnownConstants public class WellKnownConstants
@ -64,5 +66,90 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
public const decimal DecimalMaxValue = decimal.MaxValue; public const decimal DecimalMaxValue = decimal.MaxValue;
public const decimal DecimalMinValue = decimal.MinValue; public const decimal DecimalMinValue = decimal.MinValue;
public const float Float_One = 1f;
public const double Double_One = 1.0;
public const float Float_Two = 2f;
public const double Double_Two = 2.0;
public const float Float_PI = (float)Math.PI;
public const float Float_HalfOfPI = (float)Math.PI / 2f;
public const float Float_QuarterOfPI = (float)Math.PI / 4f;
public const float Float_PITimes2 = (float)Math.PI * 2f;
public const float Float_3QuartersOfPI = (float)Math.PI * 3f / 4f;
public const float Float_PIDiv360 = (float)Math.PI / 360f;
public const float Float_PIDiv16 = (float)Math.PI / 16f;
public const float Float_PIDiv32 = (float)Math.PI / 32f;
public const float Float_PIInverseFraction = 1f / (float)Math.PI;
public const float Float_PIInverseFraction2 = 2f / (float)Math.PI;
public const float Float_PIInverseFraction5 = 5f / (float)Math.PI;
public const float Float_PITimes90 = (float)Math.PI * 90f;
public const float Float_PITimes180 = (float)Math.PI * 180f;
public const float Float_LooksLikePI = 3.1415925f;
public const float Float_LooksLikePI2 = 3.14159f;
public const float Float_LooksLikePI3 = 3.141f;
public const float Float_BeforePI = 3.1415925f;
public const float Float_AfterPI = 3.141593f;
public const float Float_Negated_PI = -(float)Math.PI;
public const float Float_Negated_HalfOfPI = -(float)Math.PI / 2f;
public const float Float_Negated_QuarterOfPI = -(float)Math.PI / 4f;
public const float Float_Negated_PITimes2 = (float)Math.PI * -2f;
public const float Float_Negated_3QuartersOfPI = (float)Math.PI * -3f / 4f;
public const float Float_Negated_PIDiv360 = -(float)Math.PI / 360f;
public const float Float_Negated_PIDiv16 = -(float)Math.PI / 16f;
public const float Float_Negated_PIDiv32 = -(float)Math.PI / 32f;
public const float Float_Negated_PIInverseFraction = -1f / (float)Math.PI;
public const float Float_Negated_PIInverseFraction2 = -2f / (float)Math.PI;
public const float Float_Negated_PIInverseFraction5 = -5f / (float)Math.PI;
public const float Float_Negated_PITimes90 = (float)Math.PI * -90f;
public const float Float_Negated_PITimes180 = (float)Math.PI * -180f;
public const float Float_Negated_LooksLikePI = -3.141f;
public const float Float_Negated_BeforePI = -3.1415925f;
public const float Float_Negated_AfterPI = -3.141593f;
public const float Float_E = (float)Math.E;
public const float Float_Negated_E = -(float)Math.E;
public const double Double_PI = Math.PI;
public const double Double_HalfOfPI = Math.PI / 2.0;
public const double Double_QuarterOfPI = Math.PI / 4.0;
public const double Double_PITimes2 = Math.PI * 2.0;
public const double Double_3QuartersOfPI = Math.PI * 3.0 / 4.0;
public const double Double_PIDiv360 = Math.PI / 360.0;
public const double Double_PIDiv16 = Math.PI / 16.0;
public const double Double_PIDiv32 = Math.PI / 32.0;
public const double Double_PIInverseFraction = 1.0 / Math.PI;
public const double Double_PIInverseFraction2 = 2.0 / Math.PI;
public const double Double_PIInverseFraction5 = 5.0 / Math.PI;
public const double Double_PITimes90 = Math.PI * 90.0;
public const double Double_PITimes180 = Math.PI * 180.0;
public const double Double_LooksLikePI = 3.1415926;
public const double Double_LooksLikePI2 = 3.14159;
public const double Double_LooksLikePI3 = 3.141;
public const double Double_BeforePI = 3.1415926535897927;
public const double Double_AfterPI = 3.1415926535897936;
public const double Double_Negated_PI = -Math.PI;
public const double Double_Negated_HalfOfPI = -Math.PI / 2.0;
public const double Double_Negated_QuarterOfPI = -Math.PI / 4.0;
public const double Double_Negated_PITimes2 = Math.PI * -2.0;
public const double Double_Negated_3QuartersOfPI = Math.PI * -3.0 / 4.0;
public const double Double_Negated_PIDiv360 = -Math.PI / 360.0;
public const double Double_Negated_PIDiv16 = -Math.PI / 16.0;
public const double Double_Negated_PIDiv32 = -Math.PI / 32.0;
public const double Double_Negated_PIInverseFraction = -1.0 / Math.PI;
public const double Double_Negated_PIInverseFraction2 = -2.0 / Math.PI;
public const double Double_Negated_PIInverseFraction5 = -5.0 / Math.PI;
public const double Double_Negated_PITimes90 = Math.PI * -90.0;
public const double Double_Negated_PITimes180 = Math.PI * -180.0;
public const double Double_Negated_LooksLikePI = -3.141;
public const double Double_Negated_BeforePI = -3.1415926535897927;
public const double Double_Negated_AfterPI = -3.1415926535897936;
public const double Double_E = Math.E;
public const double Double_BeforeE = 2.7182818284590446;
public const double Double_AfterE = 2.7182818284590455;
public const double Double_Negated_E = -Math.E;
public const double Double_Negated_BeforeE = -2.7182818284590446;
public const double Double_Negated_AfterE = -2.7182818284590455;
} }
} }

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

@ -78,6 +78,86 @@
uint32, uint32,
uint32) = ( 01 00 00 80 FF FF FF FF FF FF FF FF FF FF FF FF uint32) = ( 01 00 00 80 FF FF FF FF FF FF FF FF FF FF FF FF
00 00 ) 00 00 )
.field public static literal float32 Float_One = float32(1.)
.field public static literal float64 Double_One = float64(1.)
.field public static literal float32 Float_Two = float32(2.)
.field public static literal float64 Double_Two = float64(2.)
.field public static literal float32 Float_PI = float32(3.1415927)
.field public static literal float32 Float_HalfOfPI = float32(1.5707964)
.field public static literal float32 Float_QuarterOfPI = float32(0.78539819)
.field public static literal float32 Float_PITimes2 = float32(6.2831855)
.field public static literal float32 Float_3QuartersOfPI = float32(2.3561945)
.field public static literal float32 Float_PIDiv360 = float32(8.7266462e-003)
.field public static literal float32 Float_PIDiv16 = float32(0.19634955)
.field public static literal float32 Float_PIDiv32 = float32(9.8174773e-002)
.field public static literal float32 Float_PIInverseFraction = float32(0.31830987)
.field public static literal float32 Float_PIInverseFraction2 = float32(0.63661975)
.field public static literal float32 Float_PIInverseFraction5 = float32(1.5915494)
.field public static literal float32 Float_PITimes90 = float32(282.74335)
.field public static literal float32 Float_PITimes180 = float32(565.48669)
.field public static literal float32 Float_LooksLikePI = float32(3.1415925)
.field public static literal float32 Float_LooksLikePI2 = float32(3.1415901)
.field public static literal float32 Float_LooksLikePI3 = float32(3.141)
.field public static literal float32 Float_BeforePI = float32(3.1415925)
.field public static literal float32 Float_AfterPI = float32(3.141593)
.field public static literal float32 Float_Negated_PI = float32(-3.1415927)
.field public static literal float32 Float_Negated_HalfOfPI = float32(-1.5707964)
.field public static literal float32 Float_Negated_QuarterOfPI = float32(-0.78539819)
.field public static literal float32 Float_Negated_PITimes2 = float32(-6.2831855)
.field public static literal float32 Float_Negated_3QuartersOfPI = float32(-2.3561945)
.field public static literal float32 Float_Negated_PIDiv360 = float32(-8.7266462e-003)
.field public static literal float32 Float_Negated_PIDiv16 = float32(-0.19634955)
.field public static literal float32 Float_Negated_PIDiv32 = float32(-9.8174773e-002)
.field public static literal float32 Float_Negated_PIInverseFraction = float32(-0.31830987)
.field public static literal float32 Float_Negated_PIInverseFraction2 = float32(-0.63661975)
.field public static literal float32 Float_Negated_PIInverseFraction5 = float32(-1.5915494)
.field public static literal float32 Float_Negated_PITimes90 = float32(-282.74335)
.field public static literal float32 Float_Negated_PITimes180 = float32(-565.48669)
.field public static literal float32 Float_Negated_LooksLikePI = float32(-3.141)
.field public static literal float32 Float_Negated_BeforePI = float32(-3.1415925)
.field public static literal float32 Float_Negated_AfterPI = float32(-3.141593)
.field public static literal float32 Float_E = float32(2.7182817)
.field public static literal float32 Float_Negated_E = float32(-2.7182817)
.field public static literal float64 Double_PI = float64(3.1415926535897931)
.field public static literal float64 Double_HalfOfPI = float64(1.5707963267948966)
.field public static literal float64 Double_QuarterOfPI = float64(0.78539816339744828)
.field public static literal float64 Double_PITimes2 = float64(6.2831853071795862)
.field public static literal float64 Double_3QuartersOfPI = float64(2.3561944901923448)
.field public static literal float64 Double_PIDiv360 = float64(8.7266462599716477e-003)
.field public static literal float64 Double_PIDiv16 = float64(0.19634954084936207)
.field public static literal float64 Double_PIDiv32 = float64(9.8174770424681035e-002)
.field public static literal float64 Double_PIInverseFraction = float64(0.31830988618379069)
.field public static literal float64 Double_PIInverseFraction2 = float64(0.63661977236758138)
.field public static literal float64 Double_PIInverseFraction5 = float64(1.5915494309189535)
.field public static literal float64 Double_PITimes90 = float64(282.74333882308139)
.field public static literal float64 Double_PITimes180 = float64(565.48667764616278)
.field public static literal float64 Double_LooksLikePI = float64(3.1415926000000001)
.field public static literal float64 Double_LooksLikePI2 = float64(3.1415899999999999)
.field public static literal float64 Double_LooksLikePI3 = float64(3.141)
.field public static literal float64 Double_BeforePI = float64(3.1415926535897927)
.field public static literal float64 Double_AfterPI = float64(3.1415926535897936)
.field public static literal float64 Double_Negated_PI = float64(-3.1415926535897931)
.field public static literal float64 Double_Negated_HalfOfPI = float64(-1.5707963267948966)
.field public static literal float64 Double_Negated_QuarterOfPI = float64(-0.78539816339744828)
.field public static literal float64 Double_Negated_PITimes2 = float64(-6.2831853071795862)
.field public static literal float64 Double_Negated_3QuartersOfPI = float64(-2.3561944901923448)
.field public static literal float64 Double_Negated_PIDiv360 = float64(-8.7266462599716477e-003)
.field public static literal float64 Double_Negated_PIDiv16 = float64(-0.19634954084936207)
.field public static literal float64 Double_Negated_PIDiv32 = float64(-9.8174770424681035e-002)
.field public static literal float64 Double_Negated_PIInverseFraction = float64(-0.31830988618379069)
.field public static literal float64 Double_Negated_PIInverseFraction2 = float64(-0.63661977236758138)
.field public static literal float64 Double_Negated_PIInverseFraction5 = float64(-1.5915494309189535)
.field public static literal float64 Double_Negated_PITimes90 = float64(-282.74333882308139)
.field public static literal float64 Double_Negated_PITimes180 = float64(-565.48667764616278)
.field public static literal float64 Double_Negated_LooksLikePI = float64(-3.141)
.field public static literal float64 Double_Negated_BeforePI = float64(-3.1415926535897927)
.field public static literal float64 Double_Negated_AfterPI = float64(-3.1415926535897936)
.field public static literal float64 Double_E = float64(2.7182818284590451)
.field public static literal float64 Double_BeforeE = float64(2.7182818284590446)
.field public static literal float64 Double_AfterE = float64(2.7182818284590455)
.field public static literal float64 Double_Negated_E = float64(-2.7182818284590451)
.field public static literal float64 Double_Negated_BeforeE = float64(-2.7182818284590446)
.field public static literal float64 Double_Negated_AfterE = float64(-2.7182818284590455)
.method public hidebysig specialname rtspecialname .method public hidebysig specialname rtspecialname
instance void .ctor() cil managed instance void .ctor() cil managed
{ {

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

@ -78,6 +78,86 @@
uint32, uint32,
uint32) = ( 01 00 00 80 FF FF FF FF FF FF FF FF FF FF FF FF uint32) = ( 01 00 00 80 FF FF FF FF FF FF FF FF FF FF FF FF
00 00 ) 00 00 )
.field public static literal float32 Float_One = float32(1.)
.field public static literal float64 Double_One = float64(1.)
.field public static literal float32 Float_Two = float32(2.)
.field public static literal float64 Double_Two = float64(2.)
.field public static literal float32 Float_PI = float32(3.1415927)
.field public static literal float32 Float_HalfOfPI = float32(1.5707964)
.field public static literal float32 Float_QuarterOfPI = float32(0.78539819)
.field public static literal float32 Float_PITimes2 = float32(6.2831855)
.field public static literal float32 Float_3QuartersOfPI = float32(2.3561945)
.field public static literal float32 Float_PIDiv360 = float32(8.7266462e-003)
.field public static literal float32 Float_PIDiv16 = float32(0.19634955)
.field public static literal float32 Float_PIDiv32 = float32(9.8174773e-002)
.field public static literal float32 Float_PIInverseFraction = float32(0.31830987)
.field public static literal float32 Float_PIInverseFraction2 = float32(0.63661975)
.field public static literal float32 Float_PIInverseFraction5 = float32(1.5915494)
.field public static literal float32 Float_PITimes90 = float32(282.74335)
.field public static literal float32 Float_PITimes180 = float32(565.48669)
.field public static literal float32 Float_LooksLikePI = float32(3.1415925)
.field public static literal float32 Float_LooksLikePI2 = float32(3.1415901)
.field public static literal float32 Float_LooksLikePI3 = float32(3.141)
.field public static literal float32 Float_BeforePI = float32(3.1415925)
.field public static literal float32 Float_AfterPI = float32(3.141593)
.field public static literal float32 Float_Negated_PI = float32(-3.1415927)
.field public static literal float32 Float_Negated_HalfOfPI = float32(-1.5707964)
.field public static literal float32 Float_Negated_QuarterOfPI = float32(-0.78539819)
.field public static literal float32 Float_Negated_PITimes2 = float32(-6.2831855)
.field public static literal float32 Float_Negated_3QuartersOfPI = float32(-2.3561945)
.field public static literal float32 Float_Negated_PIDiv360 = float32(-8.7266462e-003)
.field public static literal float32 Float_Negated_PIDiv16 = float32(-0.19634955)
.field public static literal float32 Float_Negated_PIDiv32 = float32(-9.8174773e-002)
.field public static literal float32 Float_Negated_PIInverseFraction = float32(-0.31830987)
.field public static literal float32 Float_Negated_PIInverseFraction2 = float32(-0.63661975)
.field public static literal float32 Float_Negated_PIInverseFraction5 = float32(-1.5915494)
.field public static literal float32 Float_Negated_PITimes90 = float32(-282.74335)
.field public static literal float32 Float_Negated_PITimes180 = float32(-565.48669)
.field public static literal float32 Float_Negated_LooksLikePI = float32(-3.141)
.field public static literal float32 Float_Negated_BeforePI = float32(-3.1415925)
.field public static literal float32 Float_Negated_AfterPI = float32(-3.141593)
.field public static literal float32 Float_E = float32(2.7182817)
.field public static literal float32 Float_Negated_E = float32(-2.7182817)
.field public static literal float64 Double_PI = float64(3.1415926535897931)
.field public static literal float64 Double_HalfOfPI = float64(1.5707963267948966)
.field public static literal float64 Double_QuarterOfPI = float64(0.78539816339744828)
.field public static literal float64 Double_PITimes2 = float64(6.2831853071795862)
.field public static literal float64 Double_3QuartersOfPI = float64(2.3561944901923448)
.field public static literal float64 Double_PIDiv360 = float64(8.7266462599716477e-003)
.field public static literal float64 Double_PIDiv16 = float64(0.19634954084936207)
.field public static literal float64 Double_PIDiv32 = float64(9.8174770424681035e-002)
.field public static literal float64 Double_PIInverseFraction = float64(0.31830988618379069)
.field public static literal float64 Double_PIInverseFraction2 = float64(0.63661977236758138)
.field public static literal float64 Double_PIInverseFraction5 = float64(1.5915494309189535)
.field public static literal float64 Double_PITimes90 = float64(282.74333882308139)
.field public static literal float64 Double_PITimes180 = float64(565.48667764616278)
.field public static literal float64 Double_LooksLikePI = float64(3.1415926000000001)
.field public static literal float64 Double_LooksLikePI2 = float64(3.1415899999999999)
.field public static literal float64 Double_LooksLikePI3 = float64(3.141)
.field public static literal float64 Double_BeforePI = float64(3.1415926535897927)
.field public static literal float64 Double_AfterPI = float64(3.1415926535897936)
.field public static literal float64 Double_Negated_PI = float64(-3.1415926535897931)
.field public static literal float64 Double_Negated_HalfOfPI = float64(-1.5707963267948966)
.field public static literal float64 Double_Negated_QuarterOfPI = float64(-0.78539816339744828)
.field public static literal float64 Double_Negated_PITimes2 = float64(-6.2831853071795862)
.field public static literal float64 Double_Negated_3QuartersOfPI = float64(-2.3561944901923448)
.field public static literal float64 Double_Negated_PIDiv360 = float64(-8.7266462599716477e-003)
.field public static literal float64 Double_Negated_PIDiv16 = float64(-0.19634954084936207)
.field public static literal float64 Double_Negated_PIDiv32 = float64(-9.8174770424681035e-002)
.field public static literal float64 Double_Negated_PIInverseFraction = float64(-0.31830988618379069)
.field public static literal float64 Double_Negated_PIInverseFraction2 = float64(-0.63661977236758138)
.field public static literal float64 Double_Negated_PIInverseFraction5 = float64(-1.5915494309189535)
.field public static literal float64 Double_Negated_PITimes90 = float64(-282.74333882308139)
.field public static literal float64 Double_Negated_PITimes180 = float64(-565.48667764616278)
.field public static literal float64 Double_Negated_LooksLikePI = float64(-3.141)
.field public static literal float64 Double_Negated_BeforePI = float64(-3.1415926535897927)
.field public static literal float64 Double_Negated_AfterPI = float64(-3.1415926535897936)
.field public static literal float64 Double_E = float64(2.7182818284590451)
.field public static literal float64 Double_BeforeE = float64(2.7182818284590446)
.field public static literal float64 Double_AfterE = float64(2.7182818284590455)
.field public static literal float64 Double_Negated_E = float64(-2.7182818284590451)
.field public static literal float64 Double_Negated_BeforeE = float64(-2.7182818284590446)
.field public static literal float64 Double_Negated_AfterE = float64(-2.7182818284590455)
.method public hidebysig specialname rtspecialname .method public hidebysig specialname rtspecialname
instance void .ctor() cil managed instance void .ctor() cil managed
{ {

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

@ -82,6 +82,86 @@
uint32, uint32,
uint32) = ( 01 00 00 80 FF FF FF FF FF FF FF FF FF FF FF FF uint32) = ( 01 00 00 80 FF FF FF FF FF FF FF FF FF FF FF FF
00 00 ) 00 00 )
.field public static literal float32 Float_One = float32(1.)
.field public static literal float64 Double_One = float64(1.)
.field public static literal float32 Float_Two = float32(2.)
.field public static literal float64 Double_Two = float64(2.)
.field public static literal float32 Float_PI = float32(3.1415927)
.field public static literal float32 Float_HalfOfPI = float32(1.5707964)
.field public static literal float32 Float_QuarterOfPI = float32(0.78539819)
.field public static literal float32 Float_PITimes2 = float32(6.2831855)
.field public static literal float32 Float_3QuartersOfPI = float32(2.3561945)
.field public static literal float32 Float_PIDiv360 = float32(8.7266462e-003)
.field public static literal float32 Float_PIDiv16 = float32(0.19634955)
.field public static literal float32 Float_PIDiv32 = float32(9.8174773e-002)
.field public static literal float32 Float_PIInverseFraction = float32(0.31830987)
.field public static literal float32 Float_PIInverseFraction2 = float32(0.63661975)
.field public static literal float32 Float_PIInverseFraction5 = float32(1.5915494)
.field public static literal float32 Float_PITimes90 = float32(282.74335)
.field public static literal float32 Float_PITimes180 = float32(565.48669)
.field public static literal float32 Float_LooksLikePI = float32(3.1415925)
.field public static literal float32 Float_LooksLikePI2 = float32(3.1415901)
.field public static literal float32 Float_LooksLikePI3 = float32(3.141)
.field public static literal float32 Float_BeforePI = float32(3.1415925)
.field public static literal float32 Float_AfterPI = float32(3.141593)
.field public static literal float32 Float_Negated_PI = float32(-3.1415927)
.field public static literal float32 Float_Negated_HalfOfPI = float32(-1.5707964)
.field public static literal float32 Float_Negated_QuarterOfPI = float32(-0.78539819)
.field public static literal float32 Float_Negated_PITimes2 = float32(-6.2831855)
.field public static literal float32 Float_Negated_3QuartersOfPI = float32(-2.3561945)
.field public static literal float32 Float_Negated_PIDiv360 = float32(-8.7266462e-003)
.field public static literal float32 Float_Negated_PIDiv16 = float32(-0.19634955)
.field public static literal float32 Float_Negated_PIDiv32 = float32(-9.8174773e-002)
.field public static literal float32 Float_Negated_PIInverseFraction = float32(-0.31830987)
.field public static literal float32 Float_Negated_PIInverseFraction2 = float32(-0.63661975)
.field public static literal float32 Float_Negated_PIInverseFraction5 = float32(-1.5915494)
.field public static literal float32 Float_Negated_PITimes90 = float32(-282.74335)
.field public static literal float32 Float_Negated_PITimes180 = float32(-565.48669)
.field public static literal float32 Float_Negated_LooksLikePI = float32(-3.141)
.field public static literal float32 Float_Negated_BeforePI = float32(-3.1415925)
.field public static literal float32 Float_Negated_AfterPI = float32(-3.141593)
.field public static literal float32 Float_E = float32(2.7182817)
.field public static literal float32 Float_Negated_E = float32(-2.7182817)
.field public static literal float64 Double_PI = float64(3.1415926535897931)
.field public static literal float64 Double_HalfOfPI = float64(1.5707963267948966)
.field public static literal float64 Double_QuarterOfPI = float64(0.78539816339744828)
.field public static literal float64 Double_PITimes2 = float64(6.2831853071795862)
.field public static literal float64 Double_3QuartersOfPI = float64(2.3561944901923448)
.field public static literal float64 Double_PIDiv360 = float64(8.7266462599716477e-003)
.field public static literal float64 Double_PIDiv16 = float64(0.19634954084936207)
.field public static literal float64 Double_PIDiv32 = float64(9.8174770424681035e-002)
.field public static literal float64 Double_PIInverseFraction = float64(0.31830988618379069)
.field public static literal float64 Double_PIInverseFraction2 = float64(0.63661977236758138)
.field public static literal float64 Double_PIInverseFraction5 = float64(1.5915494309189535)
.field public static literal float64 Double_PITimes90 = float64(282.74333882308139)
.field public static literal float64 Double_PITimes180 = float64(565.48667764616278)
.field public static literal float64 Double_LooksLikePI = float64(3.1415926000000001)
.field public static literal float64 Double_LooksLikePI2 = float64(3.1415899999999999)
.field public static literal float64 Double_LooksLikePI3 = float64(3.141)
.field public static literal float64 Double_BeforePI = float64(3.1415926535897927)
.field public static literal float64 Double_AfterPI = float64(3.1415926535897936)
.field public static literal float64 Double_Negated_PI = float64(-3.1415926535897931)
.field public static literal float64 Double_Negated_HalfOfPI = float64(-1.5707963267948966)
.field public static literal float64 Double_Negated_QuarterOfPI = float64(-0.78539816339744828)
.field public static literal float64 Double_Negated_PITimes2 = float64(-6.2831853071795862)
.field public static literal float64 Double_Negated_3QuartersOfPI = float64(-2.3561944901923448)
.field public static literal float64 Double_Negated_PIDiv360 = float64(-8.7266462599716477e-003)
.field public static literal float64 Double_Negated_PIDiv16 = float64(-0.19634954084936207)
.field public static literal float64 Double_Negated_PIDiv32 = float64(-9.8174770424681035e-002)
.field public static literal float64 Double_Negated_PIInverseFraction = float64(-0.31830988618379069)
.field public static literal float64 Double_Negated_PIInverseFraction2 = float64(-0.63661977236758138)
.field public static literal float64 Double_Negated_PIInverseFraction5 = float64(-1.5915494309189535)
.field public static literal float64 Double_Negated_PITimes90 = float64(-282.74333882308139)
.field public static literal float64 Double_Negated_PITimes180 = float64(-565.48667764616278)
.field public static literal float64 Double_Negated_LooksLikePI = float64(-3.141)
.field public static literal float64 Double_Negated_BeforePI = float64(-3.1415926535897927)
.field public static literal float64 Double_Negated_AfterPI = float64(-3.1415926535897936)
.field public static literal float64 Double_E = float64(2.7182818284590451)
.field public static literal float64 Double_BeforeE = float64(2.7182818284590446)
.field public static literal float64 Double_AfterE = float64(2.7182818284590455)
.field public static literal float64 Double_Negated_E = float64(-2.7182818284590451)
.field public static literal float64 Double_Negated_BeforeE = float64(-2.7182818284590446)
.field public static literal float64 Double_Negated_AfterE = float64(-2.7182818284590455)
.method public hidebysig specialname rtspecialname .method public hidebysig specialname rtspecialname
instance void .ctor() cil managed instance void .ctor() cil managed
{ {

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

@ -82,6 +82,86 @@
uint32, uint32,
uint32) = ( 01 00 00 80 FF FF FF FF FF FF FF FF FF FF FF FF uint32) = ( 01 00 00 80 FF FF FF FF FF FF FF FF FF FF FF FF
00 00 ) 00 00 )
.field public static literal float32 Float_One = float32(1.)
.field public static literal float64 Double_One = float64(1.)
.field public static literal float32 Float_Two = float32(2.)
.field public static literal float64 Double_Two = float64(2.)
.field public static literal float32 Float_PI = float32(3.1415927)
.field public static literal float32 Float_HalfOfPI = float32(1.5707964)
.field public static literal float32 Float_QuarterOfPI = float32(0.78539819)
.field public static literal float32 Float_PITimes2 = float32(6.2831855)
.field public static literal float32 Float_3QuartersOfPI = float32(2.3561945)
.field public static literal float32 Float_PIDiv360 = float32(8.7266462e-003)
.field public static literal float32 Float_PIDiv16 = float32(0.19634955)
.field public static literal float32 Float_PIDiv32 = float32(9.8174773e-002)
.field public static literal float32 Float_PIInverseFraction = float32(0.31830987)
.field public static literal float32 Float_PIInverseFraction2 = float32(0.63661975)
.field public static literal float32 Float_PIInverseFraction5 = float32(1.5915494)
.field public static literal float32 Float_PITimes90 = float32(282.74335)
.field public static literal float32 Float_PITimes180 = float32(565.48669)
.field public static literal float32 Float_LooksLikePI = float32(3.1415925)
.field public static literal float32 Float_LooksLikePI2 = float32(3.1415901)
.field public static literal float32 Float_LooksLikePI3 = float32(3.141)
.field public static literal float32 Float_BeforePI = float32(3.1415925)
.field public static literal float32 Float_AfterPI = float32(3.141593)
.field public static literal float32 Float_Negated_PI = float32(-3.1415927)
.field public static literal float32 Float_Negated_HalfOfPI = float32(-1.5707964)
.field public static literal float32 Float_Negated_QuarterOfPI = float32(-0.78539819)
.field public static literal float32 Float_Negated_PITimes2 = float32(-6.2831855)
.field public static literal float32 Float_Negated_3QuartersOfPI = float32(-2.3561945)
.field public static literal float32 Float_Negated_PIDiv360 = float32(-8.7266462e-003)
.field public static literal float32 Float_Negated_PIDiv16 = float32(-0.19634955)
.field public static literal float32 Float_Negated_PIDiv32 = float32(-9.8174773e-002)
.field public static literal float32 Float_Negated_PIInverseFraction = float32(-0.31830987)
.field public static literal float32 Float_Negated_PIInverseFraction2 = float32(-0.63661975)
.field public static literal float32 Float_Negated_PIInverseFraction5 = float32(-1.5915494)
.field public static literal float32 Float_Negated_PITimes90 = float32(-282.74335)
.field public static literal float32 Float_Negated_PITimes180 = float32(-565.48669)
.field public static literal float32 Float_Negated_LooksLikePI = float32(-3.141)
.field public static literal float32 Float_Negated_BeforePI = float32(-3.1415925)
.field public static literal float32 Float_Negated_AfterPI = float32(-3.141593)
.field public static literal float32 Float_E = float32(2.7182817)
.field public static literal float32 Float_Negated_E = float32(-2.7182817)
.field public static literal float64 Double_PI = float64(3.1415926535897931)
.field public static literal float64 Double_HalfOfPI = float64(1.5707963267948966)
.field public static literal float64 Double_QuarterOfPI = float64(0.78539816339744828)
.field public static literal float64 Double_PITimes2 = float64(6.2831853071795862)
.field public static literal float64 Double_3QuartersOfPI = float64(2.3561944901923448)
.field public static literal float64 Double_PIDiv360 = float64(8.7266462599716477e-003)
.field public static literal float64 Double_PIDiv16 = float64(0.19634954084936207)
.field public static literal float64 Double_PIDiv32 = float64(9.8174770424681035e-002)
.field public static literal float64 Double_PIInverseFraction = float64(0.31830988618379069)
.field public static literal float64 Double_PIInverseFraction2 = float64(0.63661977236758138)
.field public static literal float64 Double_PIInverseFraction5 = float64(1.5915494309189535)
.field public static literal float64 Double_PITimes90 = float64(282.74333882308139)
.field public static literal float64 Double_PITimes180 = float64(565.48667764616278)
.field public static literal float64 Double_LooksLikePI = float64(3.1415926000000001)
.field public static literal float64 Double_LooksLikePI2 = float64(3.1415899999999999)
.field public static literal float64 Double_LooksLikePI3 = float64(3.141)
.field public static literal float64 Double_BeforePI = float64(3.1415926535897927)
.field public static literal float64 Double_AfterPI = float64(3.1415926535897936)
.field public static literal float64 Double_Negated_PI = float64(-3.1415926535897931)
.field public static literal float64 Double_Negated_HalfOfPI = float64(-1.5707963267948966)
.field public static literal float64 Double_Negated_QuarterOfPI = float64(-0.78539816339744828)
.field public static literal float64 Double_Negated_PITimes2 = float64(-6.2831853071795862)
.field public static literal float64 Double_Negated_3QuartersOfPI = float64(-2.3561944901923448)
.field public static literal float64 Double_Negated_PIDiv360 = float64(-8.7266462599716477e-003)
.field public static literal float64 Double_Negated_PIDiv16 = float64(-0.19634954084936207)
.field public static literal float64 Double_Negated_PIDiv32 = float64(-9.8174770424681035e-002)
.field public static literal float64 Double_Negated_PIInverseFraction = float64(-0.31830988618379069)
.field public static literal float64 Double_Negated_PIInverseFraction2 = float64(-0.63661977236758138)
.field public static literal float64 Double_Negated_PIInverseFraction5 = float64(-1.5915494309189535)
.field public static literal float64 Double_Negated_PITimes90 = float64(-282.74333882308139)
.field public static literal float64 Double_Negated_PITimes180 = float64(-565.48667764616278)
.field public static literal float64 Double_Negated_LooksLikePI = float64(-3.141)
.field public static literal float64 Double_Negated_BeforePI = float64(-3.1415926535897927)
.field public static literal float64 Double_Negated_AfterPI = float64(-3.1415926535897936)
.field public static literal float64 Double_E = float64(2.7182818284590451)
.field public static literal float64 Double_BeforeE = float64(2.7182818284590446)
.field public static literal float64 Double_AfterE = float64(2.7182818284590455)
.field public static literal float64 Double_Negated_E = float64(-2.7182818284590451)
.field public static literal float64 Double_Negated_BeforeE = float64(-2.7182818284590446)
.field public static literal float64 Double_Negated_AfterE = float64(-2.7182818284590455)
.method public hidebysig specialname rtspecialname .method public hidebysig specialname rtspecialname
instance void .ctor() cil managed instance void .ctor() cil managed
{ {

3
ICSharpCode.Decompiler/CSharp/CSharpDecompiler.cs

@ -1278,7 +1278,8 @@ namespace ICSharpCode.Decompiler.CSharp
enumDec.AddAnnotation(new MemberResolveResult(null, field)); enumDec.AddAnnotation(new MemberResolveResult(null, field));
return enumDec; return enumDec;
} }
typeSystemAstBuilder.UseSpecialConstants = !field.DeclaringType.Equals(field.ReturnType); bool isMathPIOrE = ((field.Name == "PI" || field.Name == "E") && (field.DeclaringType.FullName == "System.Math" || field.DeclaringType.FullName == "System.MathF"));
typeSystemAstBuilder.UseSpecialConstants = !(field.DeclaringType.Equals(field.ReturnType) || isMathPIOrE);
var fieldDecl = typeSystemAstBuilder.ConvertEntity(field); var fieldDecl = typeSystemAstBuilder.ConvertEntity(field);
SetNewModifier(fieldDecl); SetNewModifier(fieldDecl);
if (settings.FixedBuffers && IsFixedField(field, out var elementType, out var elementCount)) { if (settings.FixedBuffers && IsFixedField(field, out var elementType, out var elementCount)) {

19
ICSharpCode.Decompiler/CSharp/ExpressionBuilder.cs

@ -435,16 +435,14 @@ namespace ICSharpCode.Decompiler.CSharp
protected internal override TranslatedExpression VisitLdcF4(LdcF4 inst, TranslationContext context) protected internal override TranslatedExpression VisitLdcF4(LdcF4 inst, TranslationContext context)
{ {
return new PrimitiveExpression(inst.Value) var expr = astBuilder.ConvertConstantValue(compilation.FindType(KnownTypeCode.Single), inst.Value);
.WithILInstruction(inst) return new TranslatedExpression(expr.WithILInstruction(inst));
.WithRR(new ConstantResolveResult(compilation.FindType(KnownTypeCode.Single), inst.Value));
} }
protected internal override TranslatedExpression VisitLdcF8(LdcF8 inst, TranslationContext context) protected internal override TranslatedExpression VisitLdcF8(LdcF8 inst, TranslationContext context)
{ {
return new PrimitiveExpression(inst.Value) var expr = astBuilder.ConvertConstantValue(compilation.FindType(KnownTypeCode.Double), inst.Value);
.WithILInstruction(inst) return new TranslatedExpression(expr.WithILInstruction(inst));
.WithRR(new ConstantResolveResult(compilation.FindType(KnownTypeCode.Double), inst.Value));
} }
protected internal override TranslatedExpression VisitLdcDecimal(LdcDecimal inst, TranslationContext context) protected internal override TranslatedExpression VisitLdcDecimal(LdcDecimal inst, TranslationContext context)
@ -2272,7 +2270,14 @@ namespace ICSharpCode.Decompiler.CSharp
container.Peek().Elements.Add(aie); container.Peek().Elements.Add(aie);
container.Push(aie); container.Push(aie);
} }
var val = Translate(value, typeHint: type).ConvertTo(type, this, allowImplicitConversion: true); TranslatedExpression val;
var old = astBuilder.UseSpecialConstants;
try {
astBuilder.UseSpecialConstants = !type.IsCSharpPrimitiveIntegerType() && !type.IsKnownType(KnownTypeCode.Decimal);
val = Translate(value, typeHint: type).ConvertTo(type, this, allowImplicitConversion: true);
} finally {
astBuilder.UseSpecialConstants = old;
}
container.Peek().Elements.Add(val); container.Peek().Elements.Add(val);
elementResolveResults.Add(val.ResolveResult); elementResolveResults.Add(val.ResolveResult);
while (container.Count > 0 && container.Peek().Elements.Count == dimensionSizes[container.Count - 1]) { while (container.Count > 0 && container.Peek().Elements.Count == dimensionSizes[container.Count - 1]) {

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

@ -713,6 +713,8 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax
} else { } else {
if (IsSpecialConstant(type, constantValue, out var expr)) if (IsSpecialConstant(type, constantValue, out var expr))
return expr; return expr;
if (type.IsKnownType(KnownTypeCode.Double) || type.IsKnownType(KnownTypeCode.Single))
return ConvertFloatingPointLiteral(type, constantValue);
IType literalType = type; IType literalType = type;
bool smallInteger = type.IsCSharpSmallIntegerType(); bool smallInteger = type.IsCSharpSmallIntegerType();
if (smallInteger) { if (smallInteger) {
@ -919,9 +921,256 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax
} }
return new CastExpression(ConvertType(type), new PrimitiveExpression(CSharpPrimitiveCast.Cast(enumBaseTypeCode, val, false))); return new CastExpression(ConvertType(type), new PrimitiveExpression(CSharpPrimitiveCast.Cast(enumBaseTypeCode, val, false)));
} }
static bool IsValidFraction(long num, long den)
{
if (!(den > 0 && num != 0))
return false;
if (den == 1 || Math.Abs(num) == 1)
return true;
return Math.Abs(num) < den && new int[] { 2, 3, 5 }.Any(x => den % x == 0);
}
static bool IsEqual(long num, long den, object constantValue, bool isDouble)
{
if (isDouble) {
return (double)constantValue == num / (double)den;
} else {
return (float)constantValue == num / (float)den;
}
}
const int MAX_DENOMINATOR = 1000;
Expression ConvertFloatingPointLiteral(IType type, object constantValue)
{
bool isDouble = type.IsKnownType(KnownTypeCode.Double);
ICompilation compilation = type.GetDefinition().Compilation;
Expression expr = null;
string str;
if (isDouble) {
if (Math.Floor((double)constantValue) == (double)constantValue) {
expr = new PrimitiveExpression(constantValue);
}
str = ((double)constantValue).ToString("r");
} else {
if (Math.Floor((float)constantValue) == (float)constantValue) {
expr = new PrimitiveExpression(constantValue);
}
str = ((float)constantValue).ToString("r");
}
bool useFraction = (str.Length - (str.StartsWith("-", StringComparison.OrdinalIgnoreCase) ? 2 : 1) > 5);
if (useFraction && expr == null && UseSpecialConstants) {
IType mathType;
if (isDouble)
mathType = compilation.FindType(typeof(Math));
else
mathType = compilation.FindType(new TopLevelTypeName("System", "MathF")).GetDefinition()
?? compilation.FindType(typeof(Math));
expr = TryExtractExpression(mathType, type, constantValue, "PI", isDouble)
?? TryExtractExpression(mathType, type, constantValue, "E", isDouble);
}
if (useFraction && expr == null) {
(long num, long den) = isDouble
? FractionApprox((double)constantValue, MAX_DENOMINATOR)
: FractionApprox((float)constantValue, MAX_DENOMINATOR);
if (IsValidFraction(num, den) && IsEqual(num, den, constantValue, isDouble) && Math.Abs(num) != 1 && Math.Abs(den) != 1) {
var left = MakeConstant(type, num);
var right = MakeConstant(type, den);
return new BinaryOperatorExpression(left, BinaryOperatorType.Divide, right).WithoutILInstruction()
.WithRR(new ConstantResolveResult(type, constantValue));
}
}
if (expr == null)
expr = new PrimitiveExpression(constantValue);
if (AddResolveResultAnnotations)
expr.AddAnnotation(new ConstantResolveResult(type, constantValue));
return expr;
}
Expression MakeConstant(IType type, long c)
{
return new PrimitiveExpression(CSharpPrimitiveCast.Cast(type.GetTypeCode(), c, checkForOverflow: true));
}
const float MathF_PI = 3.14159274f;
const float MathF_E = 2.71828175f;
Expression TryExtractExpression(IType mathType, IType type, object literalValue, string memberName, bool isDouble)
{
Expression MakeFieldReference()
{
AstType mathAstType = ConvertType(mathType);
var fieldRef = new MemberReferenceExpression(new TypeReferenceExpression(mathAstType), memberName);
if (AddResolveResultAnnotations)
fieldRef.WithRR(new MemberResolveResult(mathAstType.GetResolveResult(), mathType.GetFields(f => f.Name == memberName).Single()));
if (type.IsKnownType(KnownTypeCode.Double))
return fieldRef;
if (mathType.Name == "MathF")
return fieldRef;
return new CastExpression(ConvertType(type), fieldRef);
}
Expression ExtractExpression(long n, long d)
{
Expression fieldReference = MakeFieldReference();
// Math.PI or Math.E or (float)Math.PI or (float)Math.E or MathF.PI or MathF.E
Expression expr = fieldReference;
if (n != 1) {
if (n == -1) {
// -field
expr = new UnaryOperatorExpression(UnaryOperatorType.Minus, expr);
} else {
// field * n
expr = new BinaryOperatorExpression(expr, BinaryOperatorType.Multiply, MakeConstant(type, n));
}
}
if (d != 1) {
// field * n / d or -field / d or field / d
expr = new BinaryOperatorExpression(expr, BinaryOperatorType.Divide, MakeConstant(type, d));
}
if (isDouble) {
double field = memberName == "PI" ? Math.PI : Math.E;
double approxValue = field * n / d;
if (approxValue == (double)literalValue)
return expr;
} else {
float field = memberName == "PI" ? MathF_PI : MathF_E;
float approxValue = field * n / d;
if (approxValue == (float)literalValue)
return expr;
}
// Math.PI or Math.E or (float)Math.PI or (float)Math.E or MathF.PI or MathF.E
expr = fieldReference.Detach();
if (d == 1) {
// n / field
expr = new BinaryOperatorExpression(MakeConstant(type, n), BinaryOperatorType.Divide, expr);
} else {
// n / (d * field)
expr = new BinaryOperatorExpression(MakeConstant(type, d), BinaryOperatorType.Multiply, expr);
expr = new BinaryOperatorExpression(MakeConstant(type, n), BinaryOperatorType.Divide, expr);
}
if (isDouble) {
double field = memberName == "PI" ? Math.PI : Math.E;
double approxValue = (double)n / ((double)d * field);
if (approxValue == (double)literalValue)
return expr;
} else {
float field = memberName == "PI" ? MathF_PI : MathF_E;
float approxValue = (float)n / ((float)d * field);
if (approxValue == (float)literalValue)
return expr;
}
return null;
}
(long num, long den) = isDouble
? FractionApprox((double)literalValue / (memberName == "PI" ? Math.PI : Math.E), MAX_DENOMINATOR)
: FractionApprox((float)literalValue / (memberName == "PI" ? MathF_PI : MathF_E), MAX_DENOMINATOR);
if (IsValidFraction(num, den)) {
return ExtractExpression(num, den);
}
(num, den) = isDouble
? FractionApprox((double)literalValue * (memberName == "PI" ? Math.PI : Math.E), MAX_DENOMINATOR)
: FractionApprox((float)literalValue * (memberName == "PI" ? MathF_PI : MathF_E), MAX_DENOMINATOR);
if (IsValidFraction(num, den)) {
return ExtractExpression(num, den);
}
return null;
}
// based on https://www.ics.uci.edu/~eppstein/numth/frap.c
// find rational approximation to given real number
// David Eppstein / UC Irvine / 8 Aug 1993
//
// With corrections from Arno Formella, May 2008
//
// usage: a.out r d
// r is real number to approx
// d is the maximum denominator allowed
//
// based on the theory of continued fractions
// if x = a1 + 1/(a2 + 1/(a3 + 1/(a4 + ...)))
// then best approximation is found by truncating this series
// (with some adjustments in the last term).
//
// Note the fraction can be recovered as the first column of the matrix
// ( a1 1 ) ( a2 1 ) ( a3 1 ) ...
// ( 1 0 ) ( 1 0 ) ( 1 0 )
// Instead of keeping the sequence of continued fraction terms,
// we just keep the last partial product of these matrices.
static (long Num, long Den) FractionApprox(double value, int maxDenominator)
{
if (value > 0x7FFFFFFF)
return (0, 0);
double startValue = value;
if (value < 0)
value = -value;
long ai;
long[,] m = new long[2, 2];
m[0, 0] = m[1, 1] = 1;
m[0, 1] = m[1, 0] = 0;
double v = value;
while (m[1, 0] * (ai = (long)v) + m[1, 1] <= maxDenominator) {
long t = m[0, 0] * ai + m[0, 1];
m[0, 1] = m[0, 0];
m[0, 0] = t;
t = m[1, 0] * ai + m[1, 1];
m[1, 1] = m[1, 0];
m[1, 0] = t;
if (v - ai == 0) break;
v = 1 / (v - ai);
if (Math.Abs(v) > long.MaxValue) break; // value cannot be stored in fraction without overflow
}
if (m[1, 0] == 0)
return (0, 0);
long firstN = m[0, 0];
long firstD = m[1, 0];
ai = (maxDenominator - m[1, 1]) / m[1, 0];
long secondN = m[0, 0] * ai + m[0, 1];
long secondD = m[1, 0] * ai + m[1, 1];
double firstDelta = Math.Abs(value - firstN / (double)firstD);
double secondDelta = Math.Abs(value - secondN / (double)secondD);
if (firstDelta < secondDelta)
return (startValue < 0 ? -firstN : firstN, firstD);
return (startValue < 0 ? -secondN : secondN, secondD);
}
#endregion #endregion
#region Convert Parameter #region Convert Parameter
public ParameterDeclaration ConvertParameter(IParameter parameter) public ParameterDeclaration ConvertParameter(IParameter parameter)
{ {

Loading…
Cancel
Save