Browse Source

TSAB: Add option to display integral literals as hexadecimal numbers.

pull/1322/head
Siegfried Pammer 7 years ago
parent
commit
7919ce8dd7
  1. 1
      ICSharpCode.Decompiler.Tests/ICSharpCode.Decompiler.Tests.csproj
  2. 6
      ICSharpCode.Decompiler.Tests/PrettyTestRunner.cs
  3. 25
      ICSharpCode.Decompiler.Tests/TestCases/Pretty/ConstantsTests.cs
  4. 141
      ICSharpCode.Decompiler.Tests/TestCases/Pretty/ConstantsTests.il
  5. 130
      ICSharpCode.Decompiler.Tests/TestCases/Pretty/ConstantsTests.opt.il
  6. 134
      ICSharpCode.Decompiler.Tests/TestCases/Pretty/ConstantsTests.opt.roslyn.il
  7. 146
      ICSharpCode.Decompiler.Tests/TestCases/Pretty/ConstantsTests.roslyn.il
  8. 18
      ICSharpCode.Decompiler/CSharp/ExpressionBuilder.cs
  9. 14
      ICSharpCode.Decompiler/CSharp/Syntax/TypeSystemAstBuilder.cs

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

@ -73,6 +73,7 @@ @@ -73,6 +73,7 @@
<Compile Include="TestCases\Correctness\RefLocalsAndReturns.cs" />
<Compile Include="TestCases\ILPretty\Issue1256.cs" />
<Compile Include="TestCases\ILPretty\Issue1323.cs" />
<Compile Include="TestCases\Pretty\ConstantsTests.cs" />
<Compile Include="TestCases\Pretty\CS73_StackAllocInitializers.cs" />
<Compile Include="TestCases\Pretty\OptionalArguments.cs" />
<Compile Include="TestCases\Pretty\CustomShortCircuitOperators.cs" />

6
ICSharpCode.Decompiler.Tests/PrettyTestRunner.cs

@ -329,6 +329,12 @@ namespace ICSharpCode.Decompiler.Tests @@ -329,6 +329,12 @@ namespace ICSharpCode.Decompiler.Tests
RunForLibrary(cscOptions: cscOptions);
}
[Test]
public void ConstantsTests([ValueSource(nameof(defaultOptions))] CSharpCompilerOptions cscOptions)
{
RunForLibrary(cscOptions: cscOptions);
}
[Test]
public void Issue1080([ValueSource(nameof(roslynOnlyOptions))] CSharpCompilerOptions cscOptions)
{

25
ICSharpCode.Decompiler.Tests/TestCases/Pretty/ConstantsTests.cs

@ -0,0 +1,25 @@ @@ -0,0 +1,25 @@
namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
{
internal class ConstantsTests
{
public void Byte_BitmaskingInCondition(byte v)
{
Test((v & 0xF) == 0);
Test((v & 0x123) == 0);
Test((v | 0xF) == 0);
Test((v | 0x123) == 0);
}
public void SByte_BitmaskingInCondition(sbyte v)
{
Test((v & 0xF) == 0);
Test((v & 0x123) == 0);
Test((v | 0xF) == 0);
Test((v | 0x123) == 0);
}
private void Test(bool expr)
{
}
}
}

141
ICSharpCode.Decompiler.Tests/TestCases/Pretty/ConstantsTests.il

@ -0,0 +1,141 @@ @@ -0,0 +1,141 @@
// 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 ConstantsTests
{
.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.
.permissionset reqmin
= {[mscorlib]System.Security.Permissions.SecurityPermissionAttribute = {property bool 'SkipVerification' = bool(true)}}
.hash algorithm 0x00008004
.ver 0:0:0:0
}
.module ConstantsTests.dll
.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
// =============== CLASS MEMBERS DECLARATION ===================
.class private auto ansi beforefieldinit ICSharpCode.Decompiler.Tests.TestCases.Pretty.ConstantsTests
extends [mscorlib]System.Object
{
.method public hidebysig instance void
Byte_BitmaskingInCondition(uint8 v) cil managed
{
// Code size 64 (0x40)
.maxstack 3
IL_0000: nop
IL_0001: ldarg.0
IL_0002: ldarg.1
IL_0003: ldc.i4.s 15
IL_0005: and
IL_0006: ldc.i4.0
IL_0007: ceq
IL_0009: call instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.ConstantsTests::Test(bool)
IL_000e: nop
IL_000f: ldarg.0
IL_0010: ldarg.1
IL_0011: ldc.i4 0x123
IL_0016: and
IL_0017: ldc.i4.0
IL_0018: ceq
IL_001a: call instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.ConstantsTests::Test(bool)
IL_001f: nop
IL_0020: ldarg.0
IL_0021: ldarg.1
IL_0022: ldc.i4.s 15
IL_0024: or
IL_0025: ldc.i4.0
IL_0026: ceq
IL_0028: call instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.ConstantsTests::Test(bool)
IL_002d: nop
IL_002e: ldarg.0
IL_002f: ldarg.1
IL_0030: ldc.i4 0x123
IL_0035: or
IL_0036: ldc.i4.0
IL_0037: ceq
IL_0039: call instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.ConstantsTests::Test(bool)
IL_003e: nop
IL_003f: ret
} // end of method ConstantsTests::Byte_BitmaskingInCondition
.method public hidebysig instance void
SByte_BitmaskingInCondition(int8 v) cil managed
{
// Code size 64 (0x40)
.maxstack 3
IL_0000: nop
IL_0001: ldarg.0
IL_0002: ldarg.1
IL_0003: ldc.i4.s 15
IL_0005: and
IL_0006: ldc.i4.0
IL_0007: ceq
IL_0009: call instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.ConstantsTests::Test(bool)
IL_000e: nop
IL_000f: ldarg.0
IL_0010: ldarg.1
IL_0011: ldc.i4 0x123
IL_0016: and
IL_0017: ldc.i4.0
IL_0018: ceq
IL_001a: call instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.ConstantsTests::Test(bool)
IL_001f: nop
IL_0020: ldarg.0
IL_0021: ldarg.1
IL_0022: ldc.i4.s 15
IL_0024: or
IL_0025: ldc.i4.0
IL_0026: ceq
IL_0028: call instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.ConstantsTests::Test(bool)
IL_002d: nop
IL_002e: ldarg.0
IL_002f: ldarg.1
IL_0030: ldc.i4 0x123
IL_0035: or
IL_0036: ldc.i4.0
IL_0037: ceq
IL_0039: call instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.ConstantsTests::Test(bool)
IL_003e: nop
IL_003f: ret
} // end of method ConstantsTests::SByte_BitmaskingInCondition
.method private hidebysig instance void
Test(bool expr) cil managed
{
// Code size 2 (0x2)
.maxstack 8
IL_0000: nop
IL_0001: ret
} // end of method ConstantsTests::Test
.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 ConstantsTests::.ctor
} // end of class ICSharpCode.Decompiler.Tests.TestCases.Pretty.ConstantsTests
// =============================================================
// *********** DISASSEMBLY COMPLETE ***********************

130
ICSharpCode.Decompiler.Tests/TestCases/Pretty/ConstantsTests.opt.il

@ -0,0 +1,130 @@ @@ -0,0 +1,130 @@
// 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 ConstantsTests.opt
{
.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.
.permissionset reqmin
= {[mscorlib]System.Security.Permissions.SecurityPermissionAttribute = {property bool 'SkipVerification' = bool(true)}}
.hash algorithm 0x00008004
.ver 0:0:0:0
}
.module ConstantsTests.opt.dll
.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
// =============== CLASS MEMBERS DECLARATION ===================
.class private auto ansi beforefieldinit ICSharpCode.Decompiler.Tests.TestCases.Pretty.ConstantsTests
extends [mscorlib]System.Object
{
.method public hidebysig instance void
Byte_BitmaskingInCondition(uint8 v) cil managed
{
// Code size 59 (0x3b)
.maxstack 8
IL_0000: ldarg.0
IL_0001: ldarg.1
IL_0002: ldc.i4.s 15
IL_0004: and
IL_0005: ldc.i4.0
IL_0006: ceq
IL_0008: call instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.ConstantsTests::Test(bool)
IL_000d: ldarg.0
IL_000e: ldarg.1
IL_000f: ldc.i4 0x123
IL_0014: and
IL_0015: ldc.i4.0
IL_0016: ceq
IL_0018: call instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.ConstantsTests::Test(bool)
IL_001d: ldarg.0
IL_001e: ldarg.1
IL_001f: ldc.i4.s 15
IL_0021: or
IL_0022: ldc.i4.0
IL_0023: ceq
IL_0025: call instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.ConstantsTests::Test(bool)
IL_002a: ldarg.0
IL_002b: ldarg.1
IL_002c: ldc.i4 0x123
IL_0031: or
IL_0032: ldc.i4.0
IL_0033: ceq
IL_0035: call instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.ConstantsTests::Test(bool)
IL_003a: ret
} // end of method ConstantsTests::Byte_BitmaskingInCondition
.method public hidebysig instance void
SByte_BitmaskingInCondition(int8 v) cil managed
{
// Code size 59 (0x3b)
.maxstack 8
IL_0000: ldarg.0
IL_0001: ldarg.1
IL_0002: ldc.i4.s 15
IL_0004: and
IL_0005: ldc.i4.0
IL_0006: ceq
IL_0008: call instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.ConstantsTests::Test(bool)
IL_000d: ldarg.0
IL_000e: ldarg.1
IL_000f: ldc.i4 0x123
IL_0014: and
IL_0015: ldc.i4.0
IL_0016: ceq
IL_0018: call instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.ConstantsTests::Test(bool)
IL_001d: ldarg.0
IL_001e: ldarg.1
IL_001f: ldc.i4.s 15
IL_0021: or
IL_0022: ldc.i4.0
IL_0023: ceq
IL_0025: call instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.ConstantsTests::Test(bool)
IL_002a: ldarg.0
IL_002b: ldarg.1
IL_002c: ldc.i4 0x123
IL_0031: or
IL_0032: ldc.i4.0
IL_0033: ceq
IL_0035: call instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.ConstantsTests::Test(bool)
IL_003a: ret
} // end of method ConstantsTests::SByte_BitmaskingInCondition
.method private hidebysig instance void
Test(bool expr) cil managed
{
// Code size 1 (0x1)
.maxstack 8
IL_0000: ret
} // end of method ConstantsTests::Test
.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 ConstantsTests::.ctor
} // end of class ICSharpCode.Decompiler.Tests.TestCases.Pretty.ConstantsTests
// =============================================================
// *********** DISASSEMBLY COMPLETE ***********************

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

@ -0,0 +1,134 @@ @@ -0,0 +1,134 @@
// 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 ConstantsTests
{
.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 ConstantsTests.dll
.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
// =============== CLASS MEMBERS DECLARATION ===================
.class private auto ansi beforefieldinit ICSharpCode.Decompiler.Tests.TestCases.Pretty.ConstantsTests
extends [mscorlib]System.Object
{
.method public hidebysig instance void
Byte_BitmaskingInCondition(uint8 v) cil managed
{
// Code size 59 (0x3b)
.maxstack 8
IL_0000: ldarg.0
IL_0001: ldarg.1
IL_0002: ldc.i4.s 15
IL_0004: and
IL_0005: ldc.i4.0
IL_0006: ceq
IL_0008: call instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.ConstantsTests::Test(bool)
IL_000d: ldarg.0
IL_000e: ldarg.1
IL_000f: ldc.i4 0x123
IL_0014: and
IL_0015: ldc.i4.0
IL_0016: ceq
IL_0018: call instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.ConstantsTests::Test(bool)
IL_001d: ldarg.0
IL_001e: ldarg.1
IL_001f: ldc.i4.s 15
IL_0021: or
IL_0022: ldc.i4.0
IL_0023: ceq
IL_0025: call instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.ConstantsTests::Test(bool)
IL_002a: ldarg.0
IL_002b: ldarg.1
IL_002c: ldc.i4 0x123
IL_0031: or
IL_0032: ldc.i4.0
IL_0033: ceq
IL_0035: call instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.ConstantsTests::Test(bool)
IL_003a: ret
} // end of method ConstantsTests::Byte_BitmaskingInCondition
.method public hidebysig instance void
SByte_BitmaskingInCondition(int8 v) cil managed
{
// Code size 59 (0x3b)
.maxstack 8
IL_0000: ldarg.0
IL_0001: ldarg.1
IL_0002: ldc.i4.s 15
IL_0004: and
IL_0005: ldc.i4.0
IL_0006: ceq
IL_0008: call instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.ConstantsTests::Test(bool)
IL_000d: ldarg.0
IL_000e: ldarg.1
IL_000f: ldc.i4 0x123
IL_0014: and
IL_0015: ldc.i4.0
IL_0016: ceq
IL_0018: call instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.ConstantsTests::Test(bool)
IL_001d: ldarg.0
IL_001e: ldarg.1
IL_001f: ldc.i4.s 15
IL_0021: or
IL_0022: ldc.i4.0
IL_0023: ceq
IL_0025: call instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.ConstantsTests::Test(bool)
IL_002a: ldarg.0
IL_002b: ldarg.1
IL_002c: ldc.i4 0x123
IL_0031: or
IL_0032: ldc.i4.0
IL_0033: ceq
IL_0035: call instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.ConstantsTests::Test(bool)
IL_003a: ret
} // end of method ConstantsTests::SByte_BitmaskingInCondition
.method private hidebysig instance void
Test(bool expr) cil managed
{
// Code size 1 (0x1)
.maxstack 8
IL_0000: ret
} // end of method ConstantsTests::Test
.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 ConstantsTests::.ctor
} // end of class ICSharpCode.Decompiler.Tests.TestCases.Pretty.ConstantsTests
// =============================================================
// *********** DISASSEMBLY COMPLETE ***********************

146
ICSharpCode.Decompiler.Tests/TestCases/Pretty/ConstantsTests.roslyn.il

@ -0,0 +1,146 @@ @@ -0,0 +1,146 @@
// 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 ConstantsTests
{
.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 ConstantsTests.dll
.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
// =============== CLASS MEMBERS DECLARATION ===================
.class private auto ansi beforefieldinit ICSharpCode.Decompiler.Tests.TestCases.Pretty.ConstantsTests
extends [mscorlib]System.Object
{
.method public hidebysig instance void
Byte_BitmaskingInCondition(uint8 v) cil managed
{
// Code size 64 (0x40)
.maxstack 3
IL_0000: nop
IL_0001: ldarg.0
IL_0002: ldarg.1
IL_0003: ldc.i4.s 15
IL_0005: and
IL_0006: ldc.i4.0
IL_0007: ceq
IL_0009: call instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.ConstantsTests::Test(bool)
IL_000e: nop
IL_000f: ldarg.0
IL_0010: ldarg.1
IL_0011: ldc.i4 0x123
IL_0016: and
IL_0017: ldc.i4.0
IL_0018: ceq
IL_001a: call instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.ConstantsTests::Test(bool)
IL_001f: nop
IL_0020: ldarg.0
IL_0021: ldarg.1
IL_0022: ldc.i4.s 15
IL_0024: or
IL_0025: ldc.i4.0
IL_0026: ceq
IL_0028: call instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.ConstantsTests::Test(bool)
IL_002d: nop
IL_002e: ldarg.0
IL_002f: ldarg.1
IL_0030: ldc.i4 0x123
IL_0035: or
IL_0036: ldc.i4.0
IL_0037: ceq
IL_0039: call instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.ConstantsTests::Test(bool)
IL_003e: nop
IL_003f: ret
} // end of method ConstantsTests::Byte_BitmaskingInCondition
.method public hidebysig instance void
SByte_BitmaskingInCondition(int8 v) cil managed
{
// Code size 64 (0x40)
.maxstack 3
IL_0000: nop
IL_0001: ldarg.0
IL_0002: ldarg.1
IL_0003: ldc.i4.s 15
IL_0005: and
IL_0006: ldc.i4.0
IL_0007: ceq
IL_0009: call instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.ConstantsTests::Test(bool)
IL_000e: nop
IL_000f: ldarg.0
IL_0010: ldarg.1
IL_0011: ldc.i4 0x123
IL_0016: and
IL_0017: ldc.i4.0
IL_0018: ceq
IL_001a: call instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.ConstantsTests::Test(bool)
IL_001f: nop
IL_0020: ldarg.0
IL_0021: ldarg.1
IL_0022: ldc.i4.s 15
IL_0024: or
IL_0025: ldc.i4.0
IL_0026: ceq
IL_0028: call instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.ConstantsTests::Test(bool)
IL_002d: nop
IL_002e: ldarg.0
IL_002f: ldarg.1
IL_0030: ldc.i4 0x123
IL_0035: or
IL_0036: ldc.i4.0
IL_0037: ceq
IL_0039: call instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.ConstantsTests::Test(bool)
IL_003e: nop
IL_003f: ret
} // end of method ConstantsTests::SByte_BitmaskingInCondition
.method private hidebysig instance void
Test(bool expr) cil managed
{
// Code size 2 (0x2)
.maxstack 8
IL_0000: nop
IL_0001: ret
} // end of method ConstantsTests::Test
.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 ConstantsTests::.ctor
} // end of class ICSharpCode.Decompiler.Tests.TestCases.Pretty.ConstantsTests
// =============================================================
// *********** DISASSEMBLY COMPLETE ***********************

18
ICSharpCode.Decompiler/CSharp/ExpressionBuilder.cs

@ -383,8 +383,13 @@ namespace ICSharpCode.Decompiler.CSharp @@ -383,8 +383,13 @@ namespace ICSharpCode.Decompiler.CSharp
);
}
rr = AdjustConstantToType(rr, context.TypeHint);
return ConvertConstantValue(rr, allowImplicitConversion: true)
.WithILInstruction(inst);
astBuilder.PrintIntegralValuesAsHex = ShouldDisplayAsHex(inst.Value, inst.Parent);
try {
return ConvertConstantValue(rr, allowImplicitConversion: true)
.WithILInstruction(inst);
} finally {
astBuilder.PrintIntegralValuesAsHex = false;
}
}
protected internal override TranslatedExpression VisitLdcI8(LdcI8 inst, TranslationContext context)
@ -402,8 +407,13 @@ namespace ICSharpCode.Decompiler.CSharp @@ -402,8 +407,13 @@ namespace ICSharpCode.Decompiler.CSharp
);
}
rr = AdjustConstantToType(rr, context.TypeHint);
return ConvertConstantValue(rr, allowImplicitConversion: true)
.WithILInstruction(inst);
astBuilder.PrintIntegralValuesAsHex = ShouldDisplayAsHex(inst.Value, inst.Parent);
try {
return ConvertConstantValue(rr, allowImplicitConversion: true)
.WithILInstruction(inst);
} finally {
astBuilder.PrintIntegralValuesAsHex = false;
}
}
private bool ShouldDisplayAsHex(long value, ILInstruction parent)

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

@ -186,8 +186,14 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax @@ -186,8 +186,14 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax
/// The default value is <c>true</c>.
/// </summary>
public bool UseSpecialConstants { get; set; }
/// <summary>
/// Controls if integral constants should be printed in hexadecimal format.
/// The default value is <c>false</c>.
/// </summary>
public bool PrintIntegralValuesAsHex { get; set; }
#endregion
#region Convert Type
public AstType ConvertType(IType type)
{
@ -715,7 +721,11 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax @@ -715,7 +721,11 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax
constantValue = CSharpPrimitiveCast.Cast(TypeCode.Int32, constantValue, false);
literalType = type.GetDefinition().Compilation.FindType(KnownTypeCode.Int32);
}
expr = new PrimitiveExpression(constantValue);
string literalValue = null;
if (PrintIntegralValuesAsHex) {
literalValue = $"0x{constantValue:X}";
}
expr = new PrimitiveExpression(constantValue, literalValue);
if (AddResolveResultAnnotations)
expr.AddAnnotation(new ConstantResolveResult(literalType, constantValue));
if (smallInteger && !type.Equals(expectedType)) {

Loading…
Cancel
Save