From 13227e433ee136d6ac0d8b43fa0fe28a9a6458eb Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Sun, 11 Jun 2023 22:02:54 +0200 Subject: [PATCH] Fix compound assignments with local variables. --- .../Pretty/CompoundAssignmentTest.cs | 992 ++++++++++-------- .../CSharp/ExpressionBuilder.cs | 2 +- .../CSharp/Transforms/PrettifyAssignments.cs | 25 +- 3 files changed, 595 insertions(+), 424 deletions(-) diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/CompoundAssignmentTest.cs b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/CompoundAssignmentTest.cs index e9c391ae3..1a0f2b6b2 100644 --- a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/CompoundAssignmentTest.cs +++ b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/CompoundAssignmentTest.cs @@ -287,6 +287,18 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty public static string StaticStringProperty { get; set; } + private static void Use(ref byte b) + { + } + + private static void Use(ref sbyte b) + { + } + + private static void Use(ref T num) + { + } + private static CustomStruct2 GetStruct() { throw new NotImplementedException(); @@ -781,9 +793,10 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty public static void ByteAddTest(byte p, CustomClass c, CustomStruct2 s) { - //byte l = 0; - //p += 5; - //l += 5; + byte b = 0; + p += 5; + b += 5; + Use(ref b); byteField += 5; ByteProp += 5; c.ByteField += 5; @@ -807,9 +820,10 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty public static void ByteSubtractTest(byte p, CustomClass c, CustomStruct2 s) { - //byte l = 0; - //p -= 5; - //l -= 5; + byte b = 0; + p -= 5; + b -= 5; + Use(ref b); byteField -= 5; ByteProp -= 5; c.ByteField -= 5; @@ -833,9 +847,10 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty public static void ByteMultiplyTest(byte p, CustomClass c, CustomStruct2 s) { - //byte l = 0; - //p *= 5; - //l *= 5; + byte b = 0; + p *= 5; + b *= 5; + Use(ref b); byteField *= 5; ByteProp *= 5; c.ByteField *= 5; @@ -859,9 +874,10 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty public static void ByteDivideTest(byte p, CustomClass c, CustomStruct2 s) { - //byte l = 0; - //p /= 5; - //l /= 5; + byte b = 0; + p /= 5; + b /= 5; + Use(ref b); byteField /= 5; ByteProp /= 5; c.ByteField /= 5; @@ -885,9 +901,10 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty public static void ByteModulusTest(byte p, CustomClass c, CustomStruct2 s) { - //byte l = 0; - //p %= 5; - //l %= 5; + byte b = 0; + p %= 5; + b %= 5; + Use(ref b); byteField %= 5; ByteProp %= 5; c.ByteField %= 5; @@ -911,9 +928,10 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty public static void ByteLeftShiftTest(byte p, CustomClass c, CustomStruct2 s) { - //byte l = 0; - //p <<= 5; - //l <<= 5; + byte b = 0; + p <<= 5; + b <<= 5; + Use(ref b); byteField <<= 5; ByteProp <<= 5; c.ByteField <<= 5; @@ -937,9 +955,10 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty public static void ByteRightShiftTest(byte p, CustomClass c, CustomStruct2 s) { - //byte l = 0; - //p >>= 5; - //l >>= 5; + byte b = 0; + p >>= 5; + b >>= 5; + Use(ref b); byteField >>= 5; ByteProp >>= 5; c.ByteField >>= 5; @@ -963,9 +982,10 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty public static void ByteBitAndTest(byte p, CustomClass c, CustomStruct2 s) { - //byte l = 0; - //p &= 5; - //l &= 5; + byte b = 0; + p &= c.ByteField; + b &= c.ByteField; + Use(ref b); byteField &= 5; ByteProp &= 5; c.ByteField &= 5; @@ -989,9 +1009,10 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty public static void ByteBitOrTest(byte p, CustomClass c, CustomStruct2 s) { - //byte l = 0; - //p |= 5; - //l |= 5; + byte b = 0; + p |= c.ByteField; + b |= c.ByteField; + Use(ref b); byteField |= 5; ByteProp |= 5; c.ByteField |= 5; @@ -1015,9 +1036,10 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty public static void ByteBitXorTest(byte p, CustomClass c, CustomStruct2 s) { - //byte l = 0; - //p ^= 5; - //l ^= 5; + byte b = 0; + p ^= c.ByteField; + b ^= c.ByteField; + Use(ref b); byteField ^= 5; ByteProp ^= 5; c.ByteField ^= 5; @@ -1041,9 +1063,10 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty public static void BytePostIncTest(byte p, CustomClass c, CustomStruct2 s) { - //byte l = 0; - //X(p++); - //X(l++); + byte b = 0; + X(p++); + X(b++); + Use(ref b); X(byteField++); X(ByteProp++); X(c.ByteField++); @@ -1067,9 +1090,10 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty public static void BytePreIncTest(byte p, CustomClass c, CustomStruct2 s) { - //byte l = 0; - //X(++p); - //X(++l); + byte b = 0; + X(++p); + X(++b); + Use(ref b); X(++byteField); X(++ByteProp); X(++c.ByteField); @@ -1092,9 +1116,10 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty } public static void BytePostDecTest(byte p, CustomClass c, CustomStruct2 s) { - //byte l = 0; - //X(p--); - //X(l--); + byte b = 0; + X(p--); + X(b--); + Use(ref b); X(byteField--); X(ByteProp--); X(c.ByteField--); @@ -1118,9 +1143,10 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty public static void BytePreDecTest(byte p, CustomClass c, CustomStruct2 s) { - //byte l = 0; - //X(--p); - //X(--l); + byte b = 0; + X(--p); + X(--b); + Use(ref b); X(--byteField); X(--ByteProp); X(--c.ByteField); @@ -1143,9 +1169,10 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty } public static void SbyteAddTest(sbyte p, CustomClass c, CustomStruct2 s) { - //sbyte l = 0; - //p += 5; - //l += 5; + sbyte b = 0; + p += 5; + b += 5; + Use(ref b); sbyteField += 5; SbyteProp += 5; c.SbyteField += 5; @@ -1169,9 +1196,10 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty public static void SbyteSubtractTest(sbyte p, CustomClass c, CustomStruct2 s) { - //sbyte l = 0; - //p -= 5; - //l -= 5; + sbyte b = 0; + p -= 5; + b -= 5; + Use(ref b); sbyteField -= 5; SbyteProp -= 5; c.SbyteField -= 5; @@ -1195,9 +1223,10 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty public static void SbyteMultiplyTest(sbyte p, CustomClass c, CustomStruct2 s) { - //sbyte l = 0; - //p *= 5; - //l *= 5; + sbyte b = 0; + p *= 5; + b *= 5; + Use(ref b); sbyteField *= 5; SbyteProp *= 5; c.SbyteField *= 5; @@ -1221,9 +1250,10 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty public static void SbyteDivideTest(sbyte p, CustomClass c, CustomStruct2 s) { - //sbyte l = 0; - //p /= 5; - //l /= 5; + sbyte b = 0; + p /= 5; + b /= 5; + Use(ref b); sbyteField /= 5; SbyteProp /= 5; c.SbyteField /= 5; @@ -1247,9 +1277,10 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty public static void SbyteModulusTest(sbyte p, CustomClass c, CustomStruct2 s) { - //sbyte l = 0; - //p %= 5; - //l %= 5; + sbyte b = 0; + p %= 5; + b %= 5; + Use(ref b); sbyteField %= 5; SbyteProp %= 5; c.SbyteField %= 5; @@ -1273,9 +1304,10 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty public static void SbyteLeftShiftTest(sbyte p, CustomClass c, CustomStruct2 s) { - //sbyte l = 0; - //p <<= 5; - //l <<= 5; + sbyte b = 0; + p <<= 5; + b <<= 5; + Use(ref b); sbyteField <<= 5; SbyteProp <<= 5; c.SbyteField <<= 5; @@ -1299,9 +1331,10 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty public static void SbyteRightShiftTest(sbyte p, CustomClass c, CustomStruct2 s) { - //sbyte l = 0; - //p >>= 5; - //l >>= 5; + sbyte b = 0; + p >>= 5; + b >>= 5; + Use(ref b); sbyteField >>= 5; SbyteProp >>= 5; c.SbyteField >>= 5; @@ -1325,9 +1358,10 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty public static void SbyteBitAndTest(sbyte p, CustomClass c, CustomStruct2 s) { - //sbyte l = 0; - //p &= 5; - //l &= 5; + sbyte b = 0; + p &= 5; + b &= 5; + Use(ref b); sbyteField &= 5; SbyteProp &= 5; c.SbyteField &= 5; @@ -1351,9 +1385,10 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty public static void SbyteBitOrTest(sbyte p, CustomClass c, CustomStruct2 s) { - //sbyte l = 0; - //p |= 5; - //l |= 5; + sbyte b = 0; + p |= 5; + b |= 5; + Use(ref b); sbyteField |= 5; SbyteProp |= 5; c.SbyteField |= 5; @@ -1377,9 +1412,10 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty public static void SbyteBitXorTest(sbyte p, CustomClass c, CustomStruct2 s) { - //sbyte l = 0; - //p ^= 5; - //l ^= 5; + sbyte b = 0; + p ^= 5; + b ^= 5; + Use(ref b); sbyteField ^= 5; SbyteProp ^= 5; c.SbyteField ^= 5; @@ -1403,9 +1439,10 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty public static void SbytePostIncTest(sbyte p, CustomClass c, CustomStruct2 s) { - //sbyte l = 0; - //X(p++); - //X(l++); + sbyte b = 0; + X(p++); + X(b++); + Use(ref b); X(sbyteField++); X(SbyteProp++); X(c.SbyteField++); @@ -1429,9 +1466,10 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty public static void SbytePreIncTest(sbyte p, CustomClass c, CustomStruct2 s) { - //sbyte l = 0; - //X(++p); - //X(++l); + sbyte b = 0; + X(++p); + X(++b); + Use(ref b); X(++sbyteField); X(++SbyteProp); X(++c.SbyteField); @@ -1454,9 +1492,10 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty } public static void SbytePostDecTest(sbyte p, CustomClass c, CustomStruct2 s) { - //sbyte l = 0; - //X(p--); - //X(l--); + sbyte b = 0; + X(p--); + X(b--); + Use(ref b); X(sbyteField--); X(SbyteProp--); X(c.SbyteField--); @@ -1480,9 +1519,10 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty public static void SbytePreDecTest(sbyte p, CustomClass c, CustomStruct2 s) { - //sbyte l = 0; - //X(--p); - //X(--l); + sbyte b = 0; + X(--p); + X(--b); + Use(ref b); X(--sbyteField); X(--SbyteProp); X(--c.SbyteField); @@ -1505,9 +1545,10 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty } public static void ShortAddTest(short p, CustomClass c, CustomStruct2 s) { - //short l = 0; - //p += 5; - //l += 5; + short num = 0; + p += 5; + num += 5; + Use(ref num); shortField += 5; ShortProp += 5; c.ShortField += 5; @@ -1531,9 +1572,10 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty public static void ShortSubtractTest(short p, CustomClass c, CustomStruct2 s) { - //short l = 0; - //p -= 5; - //l -= 5; + short num = 0; + p -= 5; + num -= 5; + Use(ref num); shortField -= 5; ShortProp -= 5; c.ShortField -= 5; @@ -1557,9 +1599,10 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty public static void ShortMultiplyTest(short p, CustomClass c, CustomStruct2 s) { - //short l = 0; - //p *= 5; - //l *= 5; + short num = 0; + p *= 5; + num *= 5; + Use(ref num); shortField *= 5; ShortProp *= 5; c.ShortField *= 5; @@ -1583,9 +1626,10 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty public static void ShortDivideTest(short p, CustomClass c, CustomStruct2 s) { - //short l = 0; - //p /= 5; - //l /= 5; + short num = 0; + p /= 5; + num /= 5; + Use(ref num); shortField /= 5; ShortProp /= 5; c.ShortField /= 5; @@ -1609,9 +1653,10 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty public static void ShortModulusTest(short p, CustomClass c, CustomStruct2 s) { - //short l = 0; - //p %= 5; - //l %= 5; + short num = 0; + p %= 5; + num %= 5; + Use(ref num); shortField %= 5; ShortProp %= 5; c.ShortField %= 5; @@ -1635,9 +1680,10 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty public static void ShortLeftShiftTest(short p, CustomClass c, CustomStruct2 s) { - //short l = 0; - //p <<= 5; - //l <<= 5; + short num = 0; + p <<= 5; + num <<= 5; + Use(ref num); shortField <<= 5; ShortProp <<= 5; c.ShortField <<= 5; @@ -1661,9 +1707,10 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty public static void ShortRightShiftTest(short p, CustomClass c, CustomStruct2 s) { - //short l = 0; - //p >>= 5; - //l >>= 5; + short num = 0; + p >>= 5; + num >>= 5; + Use(ref num); shortField >>= 5; ShortProp >>= 5; c.ShortField >>= 5; @@ -1687,9 +1734,10 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty public static void ShortBitAndTest(short p, CustomClass c, CustomStruct2 s) { - //short l = 0; - //p &= 5; - //l &= 5; + short num = 0; + p &= 5; + num &= 5; + Use(ref num); shortField &= 5; ShortProp &= 5; c.ShortField &= 5; @@ -1713,9 +1761,10 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty public static void ShortBitOrTest(short p, CustomClass c, CustomStruct2 s) { - //short l = 0; - //p |= 5; - //l |= 5; + short num = 0; + p |= 5; + num |= 5; + Use(ref num); shortField |= 5; ShortProp |= 5; c.ShortField |= 5; @@ -1739,9 +1788,10 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty public static void ShortBitXorTest(short p, CustomClass c, CustomStruct2 s) { - //short l = 0; - //p ^= 5; - //l ^= 5; + short num = 0; + p ^= 5; + num ^= 5; + Use(ref num); shortField ^= 5; ShortProp ^= 5; c.ShortField ^= 5; @@ -1765,9 +1815,10 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty public static void ShortPostIncTest(short p, CustomClass c, CustomStruct2 s) { - //short l = 0; - //X(p++); - //X(l++); + short num = 0; + X(p++); + X(num++); + Use(ref num); X(shortField++); X(ShortProp++); X(c.ShortField++); @@ -1791,9 +1842,10 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty public static void ShortPreIncTest(short p, CustomClass c, CustomStruct2 s) { - //short l = 0; - //X(++p); - //X(++l); + short num = 0; + X(++p); + X(++num); + Use(ref num); X(++shortField); X(++ShortProp); X(++c.ShortField); @@ -1816,9 +1868,10 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty } public static void ShortPostDecTest(short p, CustomClass c, CustomStruct2 s) { - //short l = 0; - //X(p--); - //X(l--); + short num = 0; + X(p--); + X(num--); + Use(ref num); X(shortField--); X(ShortProp--); X(c.ShortField--); @@ -1842,9 +1895,10 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty public static void ShortPreDecTest(short p, CustomClass c, CustomStruct2 s) { - //short l = 0; - //X(--p); - //X(--l); + short num = 0; + X(--p); + X(--num); + Use(ref num); X(--shortField); X(--ShortProp); X(--c.ShortField); @@ -1867,9 +1921,10 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty } public static void UshortAddTest(ushort p, CustomClass c, CustomStruct2 s) { - //ushort l = 0; - //p += 5; - //l += 5; + ushort num = 0; + p += 5; + num += 5; + Use(ref num); ushortField += 5; UshortProp += 5; c.UshortField += 5; @@ -1893,9 +1948,10 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty public static void UshortSubtractTest(ushort p, CustomClass c, CustomStruct2 s) { - //ushort l = 0; - //p -= 5; - //l -= 5; + ushort num = 0; + p -= 5; + num -= 5; + Use(ref num); ushortField -= 5; UshortProp -= 5; c.UshortField -= 5; @@ -1919,9 +1975,10 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty public static void UshortMultiplyTest(ushort p, CustomClass c, CustomStruct2 s) { - //ushort l = 0; - //p *= 5; - //l *= 5; + ushort num = 0; + p *= 5; + num *= 5; + Use(ref num); ushortField *= 5; UshortProp *= 5; c.UshortField *= 5; @@ -1945,9 +2002,10 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty public static void UshortDivideTest(ushort p, CustomClass c, CustomStruct2 s) { - //ushort l = 0; - //p /= 5; - //l /= 5; + ushort num = 0; + p /= 5; + num /= 5; + Use(ref num); ushortField /= 5; UshortProp /= 5; c.UshortField /= 5; @@ -1971,9 +2029,10 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty public static void UshortModulusTest(ushort p, CustomClass c, CustomStruct2 s) { - //ushort l = 0; - //p %= 5; - //l %= 5; + ushort num = 0; + p %= 5; + num %= 5; + Use(ref num); ushortField %= 5; UshortProp %= 5; c.UshortField %= 5; @@ -1997,9 +2056,10 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty public static void UshortLeftShiftTest(ushort p, CustomClass c, CustomStruct2 s) { - //ushort l = 0; - //p <<= 5; - //l <<= 5; + ushort num = 0; + p <<= 5; + num <<= 5; + Use(ref num); ushortField <<= 5; UshortProp <<= 5; c.UshortField <<= 5; @@ -2023,9 +2083,10 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty public static void UshortRightShiftTest(ushort p, CustomClass c, CustomStruct2 s) { - //ushort l = 0; - //p >>= 5; - //l >>= 5; + ushort num = 0; + p >>= 5; + num >>= 5; + Use(ref num); ushortField >>= 5; UshortProp >>= 5; c.UshortField >>= 5; @@ -2049,9 +2110,10 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty public static void UshortBitAndTest(ushort p, CustomClass c, CustomStruct2 s) { - //ushort l = 0; - //p &= 5; - //l &= 5; + ushort num = 0; + p &= c.UshortField; + num &= c.UshortField; + Use(ref num); ushortField &= 5; UshortProp &= 5; c.UshortField &= 5; @@ -2075,9 +2137,10 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty public static void UshortBitOrTest(ushort p, CustomClass c, CustomStruct2 s) { - //ushort l = 0; - //p |= 5; - //l |= 5; + ushort num = 0; + p |= c.UshortField; + num |= c.UshortField; + Use(ref num); ushortField |= 5; UshortProp |= 5; c.UshortField |= 5; @@ -2101,9 +2164,10 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty public static void UshortBitXorTest(ushort p, CustomClass c, CustomStruct2 s) { - //ushort l = 0; - //p ^= 5; - //l ^= 5; + ushort num = 0; + p ^= c.UshortField; + num ^= c.UshortField; + Use(ref num); ushortField ^= 5; UshortProp ^= 5; c.UshortField ^= 5; @@ -2127,9 +2191,10 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty public static void UshortPostIncTest(ushort p, CustomClass c, CustomStruct2 s) { - //ushort l = 0; - //X(p++); - //X(l++); + ushort num = 0; + X(p++); + X(num++); + Use(ref num); X(ushortField++); X(UshortProp++); X(c.UshortField++); @@ -2153,9 +2218,10 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty public static void UshortPreIncTest(ushort p, CustomClass c, CustomStruct2 s) { - //ushort l = 0; - //X(++p); - //X(++l); + ushort num = 0; + X(++p); + X(++num); + Use(ref num); X(++ushortField); X(++UshortProp); X(++c.UshortField); @@ -2178,9 +2244,10 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty } public static void UshortPostDecTest(ushort p, CustomClass c, CustomStruct2 s) { - //ushort l = 0; - //X(p--); - //X(l--); + ushort num = 0; + X(p--); + X(num--); + Use(ref num); X(ushortField--); X(UshortProp--); X(c.UshortField--); @@ -2204,9 +2271,10 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty public static void UshortPreDecTest(ushort p, CustomClass c, CustomStruct2 s) { - //ushort l = 0; - //X(--p); - //X(--l); + ushort num = 0; + X(--p); + X(--num); + Use(ref num); X(--ushortField); X(--UshortProp); X(--c.UshortField); @@ -2229,9 +2297,10 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty } public static void IntAddTest(int p, CustomClass c, CustomStruct2 s) { - //int l = 0; - //p += 5; - //l += 5; + int num = 0; + p += 5; + num += 5; + Use(ref num); intField += 5; IntProp += 5; c.IntField += 5; @@ -2255,9 +2324,10 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty public static void IntSubtractTest(int p, CustomClass c, CustomStruct2 s) { - //int l = 0; - //p -= 5; - //l -= 5; + int num = 0; + p -= 5; + num -= 5; + Use(ref num); intField -= 5; IntProp -= 5; c.IntField -= 5; @@ -2281,9 +2351,10 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty public static void IntMultiplyTest(int p, CustomClass c, CustomStruct2 s) { - //int l = 0; - //p *= 5; - //l *= 5; + int num = 0; + p *= 5; + num *= 5; + Use(ref num); intField *= 5; IntProp *= 5; c.IntField *= 5; @@ -2307,9 +2378,10 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty public static void IntDivideTest(int p, CustomClass c, CustomStruct2 s) { - //int l = 0; - //p /= 5; - //l /= 5; + int num = 0; + p /= 5; + num /= 5; + Use(ref num); intField /= 5; IntProp /= 5; c.IntField /= 5; @@ -2333,9 +2405,10 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty public static void IntModulusTest(int p, CustomClass c, CustomStruct2 s) { - //int l = 0; - //p %= 5; - //l %= 5; + int num = 0; + p %= 5; + num %= 5; + Use(ref num); intField %= 5; IntProp %= 5; c.IntField %= 5; @@ -2359,9 +2432,10 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty public static void IntLeftShiftTest(int p, CustomClass c, CustomStruct2 s) { - //int l = 0; - //p <<= 5; - //l <<= 5; + int num = 0; + p <<= 5; + num <<= 5; + Use(ref num); intField <<= 5; IntProp <<= 5; c.IntField <<= 5; @@ -2385,9 +2459,10 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty public static void IntRightShiftTest(int p, CustomClass c, CustomStruct2 s) { - //int l = 0; - //p >>= 5; - //l >>= 5; + int num = 0; + p >>= 5; + num >>= 5; + Use(ref num); intField >>= 5; IntProp >>= 5; c.IntField >>= 5; @@ -2411,9 +2486,10 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty public static void IntBitAndTest(int p, CustomClass c, CustomStruct2 s) { - //int l = 0; - //p &= 5; - //l &= 5; + int num = 0; + p &= 5; + num &= 5; + Use(ref num); intField &= 5; IntProp &= 5; c.IntField &= 5; @@ -2437,9 +2513,10 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty public static void IntBitOrTest(int p, CustomClass c, CustomStruct2 s) { - //int l = 0; - //p |= 5; - //l |= 5; + int num = 0; + p |= 5; + num |= 5; + Use(ref num); intField |= 5; IntProp |= 5; c.IntField |= 5; @@ -2463,9 +2540,10 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty public static void IntBitXorTest(int p, CustomClass c, CustomStruct2 s) { - //int l = 0; - //p ^= 5; - //l ^= 5; + int num = 0; + p ^= 5; + num ^= 5; + Use(ref num); intField ^= 5; IntProp ^= 5; c.IntField ^= 5; @@ -2489,9 +2567,10 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty public static void IntPostIncTest(int p, CustomClass c, CustomStruct2 s) { - //int l = 0; - //X(p++); - //X(l++); + int num = 0; + X(p++); + X(num++); + Use(ref num); X(intField++); X(IntProp++); X(c.IntField++); @@ -2515,9 +2594,10 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty public static void IntPreIncTest(int p, CustomClass c, CustomStruct2 s) { - //int l = 0; - //X(++p); - //X(++l); + int num = 0; + X(++p); + X(++num); + Use(ref num); X(++intField); X(++IntProp); X(++c.IntField); @@ -2540,9 +2620,10 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty } public static void IntPostDecTest(int p, CustomClass c, CustomStruct2 s) { - //int l = 0; - //X(p--); - //X(l--); + int num = 0; + X(p--); + X(num--); + Use(ref num); X(intField--); X(IntProp--); X(c.IntField--); @@ -2566,9 +2647,10 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty public static void IntPreDecTest(int p, CustomClass c, CustomStruct2 s) { - //int l = 0; - //X(--p); - //X(--l); + int num = 0; + X(--p); + X(--num); + Use(ref num); X(--intField); X(--IntProp); X(--c.IntField); @@ -2591,9 +2673,10 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty } public static void UintAddTest(uint p, CustomClass c, CustomStruct2 s) { - //uint l = 0; - //p += 5u; - //l += 5u; + uint num = 0u; + p += 5; + num += 5; + Use(ref num); uintField += 5u; UintProp += 5u; c.UintField += 5u; @@ -2617,9 +2700,10 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty public static void UintSubtractTest(uint p, CustomClass c, CustomStruct2 s) { - //uint l = 0; - //p -= 5u; - //l -= 5u; + uint num = 0u; + p -= 5; + num -= 5; + Use(ref num); uintField -= 5u; UintProp -= 5u; c.UintField -= 5u; @@ -2643,9 +2727,10 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty public static void UintMultiplyTest(uint p, CustomClass c, CustomStruct2 s) { - //uint l = 0; - //p *= 5u; - //l *= 5u; + uint num = 0u; + p *= 5; + num *= 5; + Use(ref num); uintField *= 5u; UintProp *= 5u; c.UintField *= 5u; @@ -2669,9 +2754,10 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty public static void UintDivideTest(uint p, CustomClass c, CustomStruct2 s) { - //uint l = 0; - //p /= 5u; - //l /= 5u; + uint num = 0u; + p /= 5; + num /= 5; + Use(ref num); uintField /= 5u; UintProp /= 5u; c.UintField /= 5u; @@ -2695,9 +2781,10 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty public static void UintModulusTest(uint p, CustomClass c, CustomStruct2 s) { - //uint l = 0; - //p %= 5u; - //l %= 5u; + uint num = 0u; + p %= 5; + num %= 5; + Use(ref num); uintField %= 5u; UintProp %= 5u; c.UintField %= 5u; @@ -2721,9 +2808,10 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty public static void UintLeftShiftTest(uint p, CustomClass c, CustomStruct2 s) { - //uint l = 0; - //p <<= 5; - //l <<= 5; + uint num = 0u; + p <<= 5; + num <<= 5; + Use(ref num); uintField <<= 5; UintProp <<= 5; c.UintField <<= 5; @@ -2747,9 +2835,10 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty public static void UintRightShiftTest(uint p, CustomClass c, CustomStruct2 s) { - //uint l = 0; - //p >>= 5; - //l >>= 5; + uint num = 0u; + p >>= 5; + num >>= 5; + Use(ref num); uintField >>= 5; UintProp >>= 5; c.UintField >>= 5; @@ -2773,9 +2862,10 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty public static void UintBitAndTest(uint p, CustomClass c, CustomStruct2 s) { - //uint l = 0; - //p &= 5u; - //l &= 5u; + uint num = 0u; + p &= 5u; + num &= 5u; + Use(ref num); uintField &= 5u; UintProp &= 5u; c.UintField &= 5u; @@ -2799,9 +2889,10 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty public static void UintBitOrTest(uint p, CustomClass c, CustomStruct2 s) { - //uint l = 0; - //p |= 5u; - //l |= 5u; + uint num = 0u; + p |= 5u; + num |= 5u; + Use(ref num); uintField |= 5u; UintProp |= 5u; c.UintField |= 5u; @@ -2825,9 +2916,10 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty public static void UintBitXorTest(uint p, CustomClass c, CustomStruct2 s) { - //uint l = 0; - //p ^= 5u; - //l ^= 5u; + uint num = 0u; + p ^= 5u; + num ^= 5u; + Use(ref num); uintField ^= 5u; UintProp ^= 5u; c.UintField ^= 5u; @@ -2851,9 +2943,10 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty public static void UintPostIncTest(uint p, CustomClass c, CustomStruct2 s) { - //uint l = 0; - //X(p++); - //X(l++); + uint num = 0u; + X(p++); + X(num++); + Use(ref num); X(uintField++); X(UintProp++); X(c.UintField++); @@ -2877,9 +2970,10 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty public static void UintPreIncTest(uint p, CustomClass c, CustomStruct2 s) { - //uint l = 0; - //X(++p); - //X(++l); + uint num = 0u; + X(++p); + X(++num); + Use(ref num); X(++uintField); X(++UintProp); X(++c.UintField); @@ -2902,9 +2996,10 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty } public static void UintPostDecTest(uint p, CustomClass c, CustomStruct2 s) { - //uint l = 0; - //X(p--); - //X(l--); + uint num = 0u; + X(p--); + X(num--); + Use(ref num); X(uintField--); X(UintProp--); X(c.UintField--); @@ -2928,9 +3023,10 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty public static void UintPreDecTest(uint p, CustomClass c, CustomStruct2 s) { - //uint l = 0; - //X(--p); - //X(--l); + uint num = 0u; + X(--p); + X(--num); + Use(ref num); X(--uintField); X(--UintProp); X(--c.UintField); @@ -2953,9 +3049,10 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty } public static void LongAddTest(long p, CustomClass c, CustomStruct2 s) { - //long l = 0; - //p += 5L; - //l += 5L; + long num = 0L; + p += 5; + num += 5; + Use(ref num); longField += 5L; LongProp += 5L; c.LongField += 5L; @@ -2979,9 +3076,10 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty public static void LongSubtractTest(long p, CustomClass c, CustomStruct2 s) { - //long l = 0; - //p -= 5L; - //l -= 5L; + long num = 0L; + p -= 5; + num -= 5; + Use(ref num); longField -= 5L; LongProp -= 5L; c.LongField -= 5L; @@ -3005,9 +3103,10 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty public static void LongMultiplyTest(long p, CustomClass c, CustomStruct2 s) { - //long l = 0; - //p *= 5L; - //l *= 5L; + long num = 0L; + p *= 5; + num *= 5; + Use(ref num); longField *= 5L; LongProp *= 5L; c.LongField *= 5L; @@ -3031,9 +3130,10 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty public static void LongDivideTest(long p, CustomClass c, CustomStruct2 s) { - //long l = 0; - //p /= 5L; - //l /= 5L; + long num = 0L; + p /= 5; + num /= 5; + Use(ref num); longField /= 5L; LongProp /= 5L; c.LongField /= 5L; @@ -3057,9 +3157,10 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty public static void LongModulusTest(long p, CustomClass c, CustomStruct2 s) { - //long l = 0; - //p %= 5L; - //l %= 5L; + long num = 0L; + p %= 5; + num %= 5; + Use(ref num); longField %= 5L; LongProp %= 5L; c.LongField %= 5L; @@ -3083,9 +3184,10 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty public static void LongLeftShiftTest(long p, CustomClass c, CustomStruct2 s) { - //long l = 0; - //p <<= 5; - //l <<= 5; + long num = 0L; + p <<= 5; + num <<= 5; + Use(ref num); longField <<= 5; LongProp <<= 5; c.LongField <<= 5; @@ -3109,9 +3211,10 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty public static void LongRightShiftTest(long p, CustomClass c, CustomStruct2 s) { - //long l = 0; - //p >>= 5; - //l >>= 5; + long num = 0L; + p >>= 5; + num >>= 5; + Use(ref num); longField >>= 5; LongProp >>= 5; c.LongField >>= 5; @@ -3135,9 +3238,10 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty public static void LongBitAndTest(long p, CustomClass c, CustomStruct2 s) { - //long l = 0; - //p &= 5L; - //l &= 5L; + long num = 0L; + p &= 5; + num &= 5; + Use(ref num); longField &= 5L; LongProp &= 5L; c.LongField &= 5L; @@ -3161,9 +3265,10 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty public static void LongBitOrTest(long p, CustomClass c, CustomStruct2 s) { - //long l = 0; - //p |= 5L; - //l |= 5L; + long num = 0L; + p |= 5; + num |= 5; + Use(ref num); longField |= 5L; LongProp |= 5L; c.LongField |= 5L; @@ -3187,9 +3292,10 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty public static void LongBitXorTest(long p, CustomClass c, CustomStruct2 s) { - //long l = 0; - //p ^= 5L; - //l ^= 5L; + long num = 0L; + p ^= 5; + num ^= 5; + Use(ref num); longField ^= 5L; LongProp ^= 5L; c.LongField ^= 5L; @@ -3213,9 +3319,10 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty public static void LongPostIncTest(long p, CustomClass c, CustomStruct2 s) { - //long l = 0; - //X(p++); - //X(l++); + long num = 0L; + X(p++); + X(num++); + Use(ref num); X(longField++); X(LongProp++); X(c.LongField++); @@ -3239,9 +3346,10 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty public static void LongPreIncTest(long p, CustomClass c, CustomStruct2 s) { - //long l = 0; - //X(++p); - //X(++l); + long num = 0L; + X(++p); + X(++num); + Use(ref num); X(++longField); X(++LongProp); X(++c.LongField); @@ -3264,9 +3372,10 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty } public static void LongPostDecTest(long p, CustomClass c, CustomStruct2 s) { - //long l = 0; - //X(p--); - //X(l--); + long num = 0L; + X(p--); + X(num--); + Use(ref num); X(longField--); X(LongProp--); X(c.LongField--); @@ -3290,9 +3399,10 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty public static void LongPreDecTest(long p, CustomClass c, CustomStruct2 s) { - //long l = 0; - //X(--p); - //X(--l); + long num = 0L; + X(--p); + X(--num); + Use(ref num); X(--longField); X(--LongProp); X(--c.LongField); @@ -3315,9 +3425,10 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty } public static void UlongAddTest(ulong p, CustomClass c, CustomStruct2 s) { - //ulong l = 0; - //p += 5uL; - //l += 5uL; + ulong num = 0uL; + p += 5; + num += 5; + Use(ref num); ulongField += 5uL; UlongProp += 5uL; c.UlongField += 5uL; @@ -3341,9 +3452,10 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty public static void UlongSubtractTest(ulong p, CustomClass c, CustomStruct2 s) { - //ulong l = 0; - //p -= 5uL; - //l -= 5uL; + ulong num = 0uL; + p -= 5; + num -= 5; + Use(ref num); ulongField -= 5uL; UlongProp -= 5uL; c.UlongField -= 5uL; @@ -3367,9 +3479,10 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty public static void UlongMultiplyTest(ulong p, CustomClass c, CustomStruct2 s) { - //ulong l = 0; - //p *= 5uL; - //l *= 5uL; + ulong num = 0uL; + p *= 5; + num *= 5; + Use(ref num); ulongField *= 5uL; UlongProp *= 5uL; c.UlongField *= 5uL; @@ -3393,9 +3506,10 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty public static void UlongDivideTest(ulong p, CustomClass c, CustomStruct2 s) { - //ulong l = 0; - //p /= 5uL; - //l /= 5uL; + ulong num = 0uL; + p /= 5; + num /= 5; + Use(ref num); ulongField /= 5uL; UlongProp /= 5uL; c.UlongField /= 5uL; @@ -3419,9 +3533,10 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty public static void UlongModulusTest(ulong p, CustomClass c, CustomStruct2 s) { - //ulong l = 0; - //p %= 5uL; - //l %= 5uL; + ulong num = 0uL; + p %= 5; + num %= 5; + Use(ref num); ulongField %= 5uL; UlongProp %= 5uL; c.UlongField %= 5uL; @@ -3445,9 +3560,10 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty public static void UlongLeftShiftTest(ulong p, CustomClass c, CustomStruct2 s) { - //ulong l = 0; - //p <<= 5; - //l <<= 5; + ulong num = 0uL; + p <<= 5; + num <<= 5; + Use(ref num); ulongField <<= 5; UlongProp <<= 5; c.UlongField <<= 5; @@ -3471,9 +3587,10 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty public static void UlongRightShiftTest(ulong p, CustomClass c, CustomStruct2 s) { - //ulong l = 0; - //p >>= 5; - //l >>= 5; + ulong num = 0uL; + p >>= 5; + num >>= 5; + Use(ref num); ulongField >>= 5; UlongProp >>= 5; c.UlongField >>= 5; @@ -3497,9 +3614,10 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty public static void UlongBitAndTest(ulong p, CustomClass c, CustomStruct2 s) { - //ulong l = 0; - //p &= 5uL; - //l &= 5uL; + ulong num = 0uL; + p &= 5; + num &= 5; + Use(ref num); ulongField &= 5uL; UlongProp &= 5uL; c.UlongField &= 5uL; @@ -3523,9 +3641,10 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty public static void UlongBitOrTest(ulong p, CustomClass c, CustomStruct2 s) { - //ulong l = 0; - //p |= 5uL; - //l |= 5uL; + ulong num = 0uL; + p |= 5; + num |= 5; + Use(ref num); ulongField |= 5uL; UlongProp |= 5uL; c.UlongField |= 5uL; @@ -3549,9 +3668,10 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty public static void UlongBitXorTest(ulong p, CustomClass c, CustomStruct2 s) { - //ulong l = 0; - //p ^= 5uL; - //l ^= 5uL; + ulong num = 0uL; + p ^= 5; + num ^= 5; + Use(ref num); ulongField ^= 5uL; UlongProp ^= 5uL; c.UlongField ^= 5uL; @@ -3575,9 +3695,10 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty public static void UlongPostIncTest(ulong p, CustomClass c, CustomStruct2 s) { - //ulong l = 0; - //X(p++); - //X(l++); + ulong num = 0uL; + X(p++); + X(num++); + Use(ref num); X(ulongField++); X(UlongProp++); X(c.UlongField++); @@ -3601,9 +3722,10 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty public static void UlongPreIncTest(ulong p, CustomClass c, CustomStruct2 s) { - //ulong l = 0; - //X(++p); - //X(++l); + ulong num = 0uL; + X(++p); + X(++num); + Use(ref num); X(++ulongField); X(++UlongProp); X(++c.UlongField); @@ -3626,9 +3748,10 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty } public static void UlongPostDecTest(ulong p, CustomClass c, CustomStruct2 s) { - //ulong l = 0; - //X(p--); - //X(l--); + ulong num = 0uL; + X(p--); + X(num--); + Use(ref num); X(ulongField--); X(UlongProp--); X(c.UlongField--); @@ -3652,9 +3775,10 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty public static void UlongPreDecTest(ulong p, CustomClass c, CustomStruct2 s) { - //ulong l = 0; - //X(--p); - //X(--l); + ulong num = 0uL; + X(--p); + X(--num); + Use(ref num); X(--ulongField); X(--UlongProp); X(--c.UlongField); @@ -3677,9 +3801,10 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty } public static void CustomClassAddTest(CustomClass p, CustomClass c, CustomStruct2 s) { - //CustomClass l = null; - //p += (CustomClass)null; - //l += (CustomClass)null; + CustomClass num = null; + p += (CustomClass)null; + num += (CustomClass)null; + Use(ref num); customClassField += (CustomClass)null; CustomClassProp += (CustomClass)null; c.CustomClassField += (CustomClass)null; @@ -3703,9 +3828,10 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty public static void CustomClassSubtractTest(CustomClass p, CustomClass c, CustomStruct2 s) { - //CustomClass l = null; - //p -= (CustomClass)null; - //l -= (CustomClass)null; + CustomClass num = null; + p -= (CustomClass)null; + num -= (CustomClass)null; + Use(ref num); customClassField -= (CustomClass)null; CustomClassProp -= (CustomClass)null; c.CustomClassField -= (CustomClass)null; @@ -3729,9 +3855,10 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty public static void CustomClassMultiplyTest(CustomClass p, CustomClass c, CustomStruct2 s) { - //CustomClass l = null; - //p *= (CustomClass)null; - //l *= (CustomClass)null; + CustomClass num = null; + p *= (CustomClass)null; + num *= (CustomClass)null; + Use(ref num); customClassField *= (CustomClass)null; CustomClassProp *= (CustomClass)null; c.CustomClassField *= (CustomClass)null; @@ -3755,9 +3882,10 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty public static void CustomClassDivideTest(CustomClass p, CustomClass c, CustomStruct2 s) { - //CustomClass l = null; - //p /= (CustomClass)null; - //l /= (CustomClass)null; + CustomClass num = null; + p /= (CustomClass)null; + num /= (CustomClass)null; + Use(ref num); customClassField /= (CustomClass)null; CustomClassProp /= (CustomClass)null; c.CustomClassField /= (CustomClass)null; @@ -3781,9 +3909,10 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty public static void CustomClassModulusTest(CustomClass p, CustomClass c, CustomStruct2 s) { - //CustomClass l = null; - //p %= (CustomClass)null; - //l %= (CustomClass)null; + CustomClass num = null; + p %= (CustomClass)null; + num %= (CustomClass)null; + Use(ref num); customClassField %= (CustomClass)null; CustomClassProp %= (CustomClass)null; c.CustomClassField %= (CustomClass)null; @@ -3807,9 +3936,10 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty public static void CustomClassLeftShiftTest(CustomClass p, CustomClass c, CustomStruct2 s) { - //CustomClass l = null; - //p <<= 5; - //l <<= 5; + CustomClass num = null; + p <<= 5; + num <<= 5; + Use(ref num); customClassField <<= 5; CustomClassProp <<= 5; c.CustomClassField <<= 5; @@ -3833,9 +3963,10 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty public static void CustomClassRightShiftTest(CustomClass p, CustomClass c, CustomStruct2 s) { - //CustomClass l = null; - //p >>= 5; - //l >>= 5; + CustomClass num = null; + p >>= 5; + num >>= 5; + Use(ref num); customClassField >>= 5; CustomClassProp >>= 5; c.CustomClassField >>= 5; @@ -3859,9 +3990,10 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty public static void CustomClassBitAndTest(CustomClass p, CustomClass c, CustomStruct2 s) { - //CustomClass l = null; - //p &= (CustomClass)null; - //l &= (CustomClass)null; + CustomClass num = null; + p &= (CustomClass)null; + num &= (CustomClass)null; + Use(ref num); customClassField &= (CustomClass)null; CustomClassProp &= (CustomClass)null; c.CustomClassField &= (CustomClass)null; @@ -3885,9 +4017,10 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty public static void CustomClassBitOrTest(CustomClass p, CustomClass c, CustomStruct2 s) { - //CustomClass l = null; - //p |= (CustomClass)null; - //l |= (CustomClass)null; + CustomClass num = null; + p |= (CustomClass)null; + num |= (CustomClass)null; + Use(ref num); customClassField |= (CustomClass)null; CustomClassProp |= (CustomClass)null; c.CustomClassField |= (CustomClass)null; @@ -3911,9 +4044,10 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty public static void CustomClassBitXorTest(CustomClass p, CustomClass c, CustomStruct2 s) { - //CustomClass l = null; - //p ^= (CustomClass)null; - //l ^= (CustomClass)null; + CustomClass num = null; + p ^= (CustomClass)null; + num ^= (CustomClass)null; + Use(ref num); customClassField ^= (CustomClass)null; CustomClassProp ^= (CustomClass)null; c.CustomClassField ^= (CustomClass)null; @@ -3937,9 +4071,10 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty public static void CustomClassPostIncTest(CustomClass p, CustomClass c, CustomStruct2 s) { - //CustomClass l = null; - //X(p++); - //X(l++); + CustomClass num = null; + X(p++); + X(num++); + Use(ref num); X(customClassField++); X(CustomClassProp++); X(c.CustomClassField++); @@ -3963,9 +4098,10 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty public static void CustomClassPreIncTest(CustomClass p, CustomClass c, CustomStruct2 s) { - //CustomClass l = null; - //X(++p); - //X(++l); + CustomClass num = null; + X(++p); + X(++num); + Use(ref num); X(++customClassField); X(++CustomClassProp); X(++c.CustomClassField); @@ -3988,9 +4124,10 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty } public static void CustomClassPostDecTest(CustomClass p, CustomClass c, CustomStruct2 s) { - //CustomClass l = null; - //X(p--); - //X(l--); + CustomClass num = null; + X(p--); + X(num--); + Use(ref num); X(customClassField--); X(CustomClassProp--); X(c.CustomClassField--); @@ -4014,9 +4151,10 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty public static void CustomClassPreDecTest(CustomClass p, CustomClass c, CustomStruct2 s) { - //CustomClass l = null; - //X(--p); - //X(--l); + CustomClass num = null; + X(--p); + X(--num); + Use(ref num); X(--customClassField); X(--CustomClassProp); X(--c.CustomClassField); @@ -4039,9 +4177,10 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty } public static void CustomStructAddTest(CustomStruct p, CustomClass c, CustomStruct2 s) { - //CustomStruct l = default(CustomStruct); - //p += default(CustomStruct); - //l += default(CustomStruct); + CustomStruct num = default(CustomStruct); + p += default(CustomStruct); + num += default(CustomStruct); + Use(ref num); customStructField += default(CustomStruct); CustomStructProp += default(CustomStruct); c.CustomStructField += default(CustomStruct); @@ -4065,9 +4204,10 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty public static void CustomStructSubtractTest(CustomStruct p, CustomClass c, CustomStruct2 s) { - //CustomStruct l = default(CustomStruct); - //p -= default(CustomStruct); - //l -= default(CustomStruct); + CustomStruct num = default(CustomStruct); + p -= default(CustomStruct); + num -= default(CustomStruct); + Use(ref num); customStructField -= default(CustomStruct); CustomStructProp -= default(CustomStruct); c.CustomStructField -= default(CustomStruct); @@ -4091,9 +4231,10 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty public static void CustomStructMultiplyTest(CustomStruct p, CustomClass c, CustomStruct2 s) { - //CustomStruct l = default(CustomStruct); - //p *= default(CustomStruct); - //l *= default(CustomStruct); + CustomStruct num = default(CustomStruct); + p *= default(CustomStruct); + num *= default(CustomStruct); + Use(ref num); customStructField *= default(CustomStruct); CustomStructProp *= default(CustomStruct); c.CustomStructField *= default(CustomStruct); @@ -4117,9 +4258,10 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty public static void CustomStructDivideTest(CustomStruct p, CustomClass c, CustomStruct2 s) { - //CustomStruct l = default(CustomStruct); - //p /= default(CustomStruct); - //l /= default(CustomStruct); + CustomStruct num = default(CustomStruct); + p /= default(CustomStruct); + num /= default(CustomStruct); + Use(ref num); customStructField /= default(CustomStruct); CustomStructProp /= default(CustomStruct); c.CustomStructField /= default(CustomStruct); @@ -4143,9 +4285,10 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty public static void CustomStructModulusTest(CustomStruct p, CustomClass c, CustomStruct2 s) { - //CustomStruct l = default(CustomStruct); - //p %= default(CustomStruct); - //l %= default(CustomStruct); + CustomStruct num = default(CustomStruct); + p %= default(CustomStruct); + num %= default(CustomStruct); + Use(ref num); customStructField %= default(CustomStruct); CustomStructProp %= default(CustomStruct); c.CustomStructField %= default(CustomStruct); @@ -4169,9 +4312,10 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty public static void CustomStructLeftShiftTest(CustomStruct p, CustomClass c, CustomStruct2 s) { - //CustomStruct l = default(CustomStruct); - //p <<= 5; - //l <<= 5; + CustomStruct num = default(CustomStruct); + p <<= 5; + num <<= 5; + Use(ref num); customStructField <<= 5; CustomStructProp <<= 5; c.CustomStructField <<= 5; @@ -4195,9 +4339,10 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty public static void CustomStructRightShiftTest(CustomStruct p, CustomClass c, CustomStruct2 s) { - //CustomStruct l = default(CustomStruct); - //p >>= 5; - //l >>= 5; + CustomStruct num = default(CustomStruct); + p >>= 5; + num >>= 5; + Use(ref num); customStructField >>= 5; CustomStructProp >>= 5; c.CustomStructField >>= 5; @@ -4221,9 +4366,10 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty public static void CustomStructBitAndTest(CustomStruct p, CustomClass c, CustomStruct2 s) { - //CustomStruct l = default(CustomStruct); - //p &= default(CustomStruct); - //l &= default(CustomStruct); + CustomStruct num = default(CustomStruct); + p &= default(CustomStruct); + num &= default(CustomStruct); + Use(ref num); customStructField &= default(CustomStruct); CustomStructProp &= default(CustomStruct); c.CustomStructField &= default(CustomStruct); @@ -4247,9 +4393,10 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty public static void CustomStructBitOrTest(CustomStruct p, CustomClass c, CustomStruct2 s) { - //CustomStruct l = default(CustomStruct); - //p |= default(CustomStruct); - //l |= default(CustomStruct); + CustomStruct num = default(CustomStruct); + p |= default(CustomStruct); + num |= default(CustomStruct); + Use(ref num); customStructField |= default(CustomStruct); CustomStructProp |= default(CustomStruct); c.CustomStructField |= default(CustomStruct); @@ -4273,9 +4420,10 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty public static void CustomStructBitXorTest(CustomStruct p, CustomClass c, CustomStruct2 s) { - //CustomStruct l = default(CustomStruct); - //p ^= default(CustomStruct); - //l ^= default(CustomStruct); + CustomStruct num = default(CustomStruct); + p ^= default(CustomStruct); + num ^= default(CustomStruct); + Use(ref num); customStructField ^= default(CustomStruct); CustomStructProp ^= default(CustomStruct); c.CustomStructField ^= default(CustomStruct); @@ -4299,9 +4447,10 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty public static void CustomStructPostIncTest(CustomStruct p, CustomClass c, CustomStruct2 s) { - //CustomStruct l = default(CustomStruct); - //X(p++); - //X(l++); + CustomStruct num = default(CustomStruct); + X(p++); + X(num++); + Use(ref num); X(customStructField++); X(CustomStructProp++); X(c.CustomStructField++); @@ -4325,9 +4474,10 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty public static void CustomStructPreIncTest(CustomStruct p, CustomClass c, CustomStruct2 s) { - //CustomStruct l = default(CustomStruct); - //X(++p); - //X(++l); + CustomStruct num = default(CustomStruct); + X(++p); + X(++num); + Use(ref num); X(++customStructField); X(++CustomStructProp); X(++c.CustomStructField); @@ -4350,9 +4500,10 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty } public static void CustomStructPostDecTest(CustomStruct p, CustomClass c, CustomStruct2 s) { - //CustomStruct l = default(CustomStruct); - //X(p--); - //X(l--); + CustomStruct num = default(CustomStruct); + X(p--); + X(num--); + Use(ref num); X(customStructField--); X(CustomStructProp--); X(c.CustomStructField--); @@ -4376,9 +4527,10 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty public static void CustomStructPreDecTest(CustomStruct p, CustomClass c, CustomStruct2 s) { - //CustomStruct l = default(CustomStruct); - //X(--p); - //X(--l); + CustomStruct num = default(CustomStruct); + X(--p); + X(--num); + Use(ref num); X(--customStructField); X(--CustomStructProp); X(--c.CustomStructField); diff --git a/ICSharpCode.Decompiler/CSharp/ExpressionBuilder.cs b/ICSharpCode.Decompiler/CSharp/ExpressionBuilder.cs index 0972105f1..761a4d6b9 100644 --- a/ICSharpCode.Decompiler/CSharp/ExpressionBuilder.cs +++ b/ICSharpCode.Decompiler/CSharp/ExpressionBuilder.cs @@ -1587,7 +1587,7 @@ namespace ICSharpCode.Decompiler.CSharp var rr = resolverWithOverflowCheck.ResolveBinaryOperator(op, left.ResolveResult, right.ResolveResult); if (rr.IsError || NullableType.GetUnderlyingType(rr.Type).GetStackType() != inst.UnderlyingResultType - || !IsCompatibleWithSign(left.Type, inst.Sign) || !IsCompatibleWithSign(right.Type, inst.Sign)) + || !IsCompatibleWithSign(rr.Type, inst.Sign)) { // Left and right operands are incompatible, so convert them to a common type Sign sign = inst.Sign; diff --git a/ICSharpCode.Decompiler/CSharp/Transforms/PrettifyAssignments.cs b/ICSharpCode.Decompiler/CSharp/Transforms/PrettifyAssignments.cs index d2ae9b2d5..d76604530 100644 --- a/ICSharpCode.Decompiler/CSharp/Transforms/PrettifyAssignments.cs +++ b/ICSharpCode.Decompiler/CSharp/Transforms/PrettifyAssignments.cs @@ -19,6 +19,7 @@ using System; using System.Linq; +using ICSharpCode.Decompiler.CSharp.Resolver; using ICSharpCode.Decompiler.CSharp.Syntax; using ICSharpCode.Decompiler.CSharp.Syntax.PatternMatching; using ICSharpCode.Decompiler.TypeSystem; @@ -44,10 +45,19 @@ namespace ICSharpCode.Decompiler.CSharp.Transforms { base.VisitAssignmentExpression(assignment); // Combine "x = x op y" into "x op= y" - BinaryOperatorExpression binary = assignment.Right as BinaryOperatorExpression; - if (binary != null && assignment.Operator == AssignmentOperatorType.Assign) + // Also supports "x = (T)(x op y)" -> "x op= y", if x.GetType() == T + // and y is implicitly convertible to T. + Expression rhs = assignment.Right; + IType expectedType = null; + if (assignment.Right is CastExpression { Type: var astType } cast) { - if (CanConvertToCompoundAssignment(assignment.Left) && assignment.Left.IsMatch(binary.Left)) + rhs = cast.Expression; + expectedType = astType.GetResolveResult().Type; + } + if (rhs is BinaryOperatorExpression binary && assignment.Operator == AssignmentOperatorType.Assign) + { + if (CanConvertToCompoundAssignment(assignment.Left) && assignment.Left.IsMatch(binary.Left) + && IsImplicitlyConvertible(binary.Right, expectedType)) { assignment.Operator = GetAssignmentOperatorForBinaryOperator(binary.Operator); if (assignment.Operator != AssignmentOperatorType.Assign) @@ -78,6 +88,15 @@ namespace ICSharpCode.Decompiler.CSharp.Transforms } } } + + bool IsImplicitlyConvertible(Expression rhs, IType expectedType) + { + if (expectedType == null) + return true; + + var conversions = CSharpConversions.Get(context.TypeSystem); + return conversions.ImplicitConversion(rhs.GetResolveResult(), expectedType).IsImplicit; + } } public static AssignmentOperatorType GetAssignmentOperatorForBinaryOperator(BinaryOperatorType bop)