Browse Source

Convert float/double += 1 into increment and decrement expressions

Reviving the 2020 test-cases-fp-types fixtures (compound assignment on
float, double and decimal) exposed an asymmetry: post-increment and
post-decrement on float/double round-tripped as x++/x--, but the pre
forms came back as x += 1f because the increment detection in
PrettifyAssignments only accepted integer constants. C# defines ++/--
on floating-point types as adding or subtracting exactly 1, so the
conversion is exact for a constant 1 operand. Decimal already works
through the op_Increment/op_Decrement path.

Assisted-by: Claude:claude-fable-5:Claude Code
pull/3953/head
Siegfried Pammer 2 months ago committed by Siegfried Pammer
parent
commit
87c13f99dc
  1. 803
      ICSharpCode.Decompiler.Tests/TestCases/Pretty/CompoundAssignmentTest.cs
  2. 8
      ICSharpCode.Decompiler/CSharp/Transforms/PrettifyAssignments.cs

803
ICSharpCode.Decompiler.Tests/TestCases/Pretty/CompoundAssignmentTest.cs

@ -81,6 +81,9 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
public uint UintField; public uint UintField;
public long LongField; public long LongField;
public ulong UlongField; public ulong UlongField;
public float FloatField;
public double DoubleField;
public decimal DecimalField;
public CustomClass CustomClassField; public CustomClass CustomClassField;
public CustomStruct CustomStructField; public CustomStruct CustomStructField;
@ -92,6 +95,9 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
public uint UintProp { get; set; } public uint UintProp { get; set; }
public long LongProp { get; set; } public long LongProp { get; set; }
public ulong UlongProp { get; set; } public ulong UlongProp { get; set; }
public float FloatProp { get; set; }
public double DoubleProp { get; set; }
public decimal DecimalProp { get; set; }
public string StringProp { get; set; } public string StringProp { get; set; }
public CustomClass CustomClassProp { get; set; } public CustomClass CustomClassProp { get; set; }
@ -161,6 +167,9 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
public uint UintField; public uint UintField;
public long LongField; public long LongField;
public ulong UlongField; public ulong UlongField;
public float FloatField;
public double DoubleField;
public decimal DecimalField;
public CustomClass CustomClassField; public CustomClass CustomClassField;
public CustomClass CustomClassProp { get; set; } public CustomClass CustomClassProp { get; set; }
@ -172,6 +181,9 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
public uint UintProp { get; set; } public uint UintProp { get; set; }
public long LongProp { get; set; } public long LongProp { get; set; }
public ulong UlongProp { get; set; } public ulong UlongProp { get; set; }
public float FloatProp { get; set; }
public double DoubleProp { get; set; }
public decimal DecimalProp { get; set; }
public static CustomStruct operator +(CustomStruct lhs, CustomStruct rhs) public static CustomStruct operator +(CustomStruct lhs, CustomStruct rhs)
{ {
@ -242,6 +254,9 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
public uint UintField; public uint UintField;
public long LongField; public long LongField;
public ulong UlongField; public ulong UlongField;
public float FloatField;
public double DoubleField;
public decimal DecimalField;
public CustomClass CustomClassProp { get; set; } public CustomClass CustomClassProp { get; set; }
public CustomStruct CustomStructProp { get; set; } public CustomStruct CustomStructProp { get; set; }
@ -253,6 +268,10 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
public uint UintProp { get; set; } public uint UintProp { get; set; }
public long LongProp { get; set; } public long LongProp { get; set; }
public ulong UlongProp { get; set; } public ulong UlongProp { get; set; }
public float FloatProp { get; set; }
public double DoubleProp { get; set; }
public decimal DecimalProp { get; set; }
} }
private int test1; private int test1;
@ -275,6 +294,9 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
private static uint uintField; private static uint uintField;
private static long longField; private static long longField;
private static ulong ulongField; private static ulong ulongField;
private static float floatField;
private static double doubleField;
private static decimal decimalField;
private static CustomClass CustomClassProp { get; set; } private static CustomClass CustomClassProp { get; set; }
private static CustomStruct CustomStructProp { get; set; } private static CustomStruct CustomStructProp { get; set; }
@ -286,6 +308,9 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
private static uint UintProp { get; set; } private static uint UintProp { get; set; }
private static long LongProp { get; set; } private static long LongProp { get; set; }
private static ulong UlongProp { get; set; } private static ulong UlongProp { get; set; }
private static float FloatProp { get; set; }
private static double DoubleProp { get; set; }
private static decimal DecimalProp { get; set; }
public static int StaticProperty { get; set; } public static int StaticProperty { get; set; }
@ -364,6 +389,21 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }
private static ref float GetRefFloat()
{
throw new NotImplementedException();
}
private static ref double GetRefDouble()
{
throw new NotImplementedException();
}
private static ref decimal GetRefDecimal()
{
throw new NotImplementedException();
}
#endif #endif
private static CustomClass GetClass() private static CustomClass GetClass()
@ -3879,6 +3919,769 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
X(--GetRefUlong()); X(--GetRefUlong());
#endif #endif
} }
public static void FloatAddTest(float p, CustomClass c, CustomStruct2 s)
{
float num = 0f;
p += 5f;
num += 5f;
Use(ref num);
floatField += 5f;
FloatProp += 5f;
c.FloatField += 5f;
c.FloatProp += 5f;
s.FloatField += 5f;
s.FloatProp += 5f;
customClassField.FloatField += 5f;
customClassField.FloatProp += 5f;
otherCustomStructField.FloatField += 5f;
otherCustomStructField.FloatProp += 5f;
CustomClassProp.FloatField += 5f;
CustomClassProp.FloatProp += 5f;
GetClass().FloatField += 5f;
GetClass().FloatProp += 5f;
#if CS70
GetRefStruct().FloatField += 5f;
GetRefStruct().FloatProp += 5f;
GetRefFloat() += 5f;
#endif
}
public static void FloatSubtractTest(float p, CustomClass c, CustomStruct2 s)
{
float num = 0f;
p -= 5f;
num -= 5f;
Use(ref num);
floatField -= 5f;
FloatProp -= 5f;
c.FloatField -= 5f;
c.FloatProp -= 5f;
s.FloatField -= 5f;
s.FloatProp -= 5f;
customClassField.FloatField -= 5f;
customClassField.FloatProp -= 5f;
otherCustomStructField.FloatField -= 5f;
otherCustomStructField.FloatProp -= 5f;
CustomClassProp.FloatField -= 5f;
CustomClassProp.FloatProp -= 5f;
GetClass().FloatField -= 5f;
GetClass().FloatProp -= 5f;
#if CS70
GetRefStruct().FloatField -= 5f;
GetRefStruct().FloatProp -= 5f;
GetRefFloat() -= 5f;
#endif
}
public static void FloatMultiplyTest(float p, CustomClass c, CustomStruct2 s)
{
float num = 0f;
p *= 5f;
num *= 5f;
Use(ref num);
floatField *= 5f;
FloatProp *= 5f;
c.FloatField *= 5f;
c.FloatProp *= 5f;
s.FloatField *= 5f;
s.FloatProp *= 5f;
customClassField.FloatField *= 5f;
customClassField.FloatProp *= 5f;
otherCustomStructField.FloatField *= 5f;
otherCustomStructField.FloatProp *= 5f;
CustomClassProp.FloatField *= 5f;
CustomClassProp.FloatProp *= 5f;
GetClass().FloatField *= 5f;
GetClass().FloatProp *= 5f;
#if CS70
GetRefStruct().FloatField *= 5f;
GetRefStruct().FloatProp *= 5f;
GetRefFloat() *= 5f;
#endif
}
public static void FloatDivideTest(float p, CustomClass c, CustomStruct2 s)
{
float num = 0f;
p /= 5f;
num /= 5f;
Use(ref num);
floatField /= 5f;
FloatProp /= 5f;
c.FloatField /= 5f;
c.FloatProp /= 5f;
s.FloatField /= 5f;
s.FloatProp /= 5f;
customClassField.FloatField /= 5f;
customClassField.FloatProp /= 5f;
otherCustomStructField.FloatField /= 5f;
otherCustomStructField.FloatProp /= 5f;
CustomClassProp.FloatField /= 5f;
CustomClassProp.FloatProp /= 5f;
GetClass().FloatField /= 5f;
GetClass().FloatProp /= 5f;
#if CS70
GetRefStruct().FloatField /= 5f;
GetRefStruct().FloatProp /= 5f;
GetRefFloat() /= 5f;
#endif
}
public static void FloatModulusTest(float p, CustomClass c, CustomStruct2 s)
{
float num = 0f;
p %= 5f;
num %= 5f;
Use(ref num);
floatField %= 5f;
FloatProp %= 5f;
c.FloatField %= 5f;
c.FloatProp %= 5f;
s.FloatField %= 5f;
s.FloatProp %= 5f;
customClassField.FloatField %= 5f;
customClassField.FloatProp %= 5f;
otherCustomStructField.FloatField %= 5f;
otherCustomStructField.FloatProp %= 5f;
CustomClassProp.FloatField %= 5f;
CustomClassProp.FloatProp %= 5f;
GetClass().FloatField %= 5f;
GetClass().FloatProp %= 5f;
#if CS70
GetRefStruct().FloatField %= 5f;
GetRefStruct().FloatProp %= 5f;
GetRefFloat() %= 5f;
#endif
}
public static void FloatPostIncTest(float p, CustomClass c, CustomStruct2 s)
{
float num = 0f;
X(p++);
X(num++);
Use(ref num);
X(floatField++);
X(FloatProp++);
X(c.FloatField++);
X(c.FloatProp++);
X(s.FloatField++);
X(s.FloatProp++);
X(customClassField.FloatField++);
X(customClassField.FloatProp++);
X(otherCustomStructField.FloatField++);
X(otherCustomStructField.FloatProp++);
X(CustomClassProp.FloatField++);
X(CustomClassProp.FloatProp++);
X(GetClass().FloatField++);
X(GetClass().FloatProp++);
#if CS70
X(GetRefStruct().FloatField++);
X(GetRefStruct().FloatProp++);
X(GetRefFloat()++);
#endif
}
public static void FloatPreIncTest(float p, CustomClass c, CustomStruct2 s)
{
float num = 0f;
X(++p);
X(++num);
Use(ref num);
X(++floatField);
X(++FloatProp);
X(++c.FloatField);
X(++c.FloatProp);
X(++s.FloatField);
X(++s.FloatProp);
X(++customClassField.FloatField);
X(++customClassField.FloatProp);
X(++otherCustomStructField.FloatField);
X(++otherCustomStructField.FloatProp);
X(++CustomClassProp.FloatField);
X(++CustomClassProp.FloatProp);
X(++GetClass().FloatField);
X(++GetClass().FloatProp);
#if CS70
X(++GetRefStruct().FloatField);
X(++GetRefStruct().FloatProp);
X(++GetRefFloat());
#endif
}
public static void FloatPostDecTest(float p, CustomClass c, CustomStruct2 s)
{
float num = 0f;
X(p--);
X(num--);
Use(ref num);
X(floatField--);
X(FloatProp--);
X(c.FloatField--);
X(c.FloatProp--);
X(s.FloatField--);
X(s.FloatProp--);
X(customClassField.FloatField--);
X(customClassField.FloatProp--);
X(otherCustomStructField.FloatField--);
X(otherCustomStructField.FloatProp--);
X(CustomClassProp.FloatField--);
X(CustomClassProp.FloatProp--);
X(GetClass().FloatField--);
X(GetClass().FloatProp--);
#if CS70
X(GetRefStruct().FloatField--);
X(GetRefStruct().FloatProp--);
X(GetRefFloat()--);
#endif
}
public static void FloatPreDecTest(float p, CustomClass c, CustomStruct2 s)
{
float num = 0f;
X(--p);
X(--num);
Use(ref num);
X(--floatField);
X(--FloatProp);
X(--c.FloatField);
X(--c.FloatProp);
X(--s.FloatField);
X(--s.FloatProp);
X(--customClassField.FloatField);
X(--customClassField.FloatProp);
X(--otherCustomStructField.FloatField);
X(--otherCustomStructField.FloatProp);
X(--CustomClassProp.FloatField);
X(--CustomClassProp.FloatProp);
X(--GetClass().FloatField);
X(--GetClass().FloatProp);
#if CS70
X(--GetRefStruct().FloatField);
X(--GetRefStruct().FloatProp);
X(--GetRefFloat());
#endif
}
public static void DoubleAddTest(double p, CustomClass c, CustomStruct2 s)
{
double num = 0.0;
p += 5.0;
num += 5.0;
Use(ref num);
doubleField += 5.0;
DoubleProp += 5.0;
c.DoubleField += 5.0;
c.DoubleProp += 5.0;
s.DoubleField += 5.0;
s.DoubleProp += 5.0;
customClassField.DoubleField += 5.0;
customClassField.DoubleProp += 5.0;
otherCustomStructField.DoubleField += 5.0;
otherCustomStructField.DoubleProp += 5.0;
CustomClassProp.DoubleField += 5.0;
CustomClassProp.DoubleProp += 5.0;
GetClass().DoubleField += 5.0;
GetClass().DoubleProp += 5.0;
#if CS70
GetRefStruct().DoubleField += 5.0;
GetRefStruct().DoubleProp += 5.0;
GetRefDouble() += 5.0;
#endif
}
public static void DoubleSubtractTest(double p, CustomClass c, CustomStruct2 s)
{
double num = 0.0;
p -= 5.0;
num -= 5.0;
Use(ref num);
doubleField -= 5.0;
DoubleProp -= 5.0;
c.DoubleField -= 5.0;
c.DoubleProp -= 5.0;
s.DoubleField -= 5.0;
s.DoubleProp -= 5.0;
customClassField.DoubleField -= 5.0;
customClassField.DoubleProp -= 5.0;
otherCustomStructField.DoubleField -= 5.0;
otherCustomStructField.DoubleProp -= 5.0;
CustomClassProp.DoubleField -= 5.0;
CustomClassProp.DoubleProp -= 5.0;
GetClass().DoubleField -= 5.0;
GetClass().DoubleProp -= 5.0;
#if CS70
GetRefStruct().DoubleField -= 5.0;
GetRefStruct().DoubleProp -= 5.0;
GetRefDouble() -= 5.0;
#endif
}
public static void DoubleMultiplyTest(double p, CustomClass c, CustomStruct2 s)
{
double num = 0.0;
p *= 5.0;
num *= 5.0;
Use(ref num);
doubleField *= 5.0;
DoubleProp *= 5.0;
c.DoubleField *= 5.0;
c.DoubleProp *= 5.0;
s.DoubleField *= 5.0;
s.DoubleProp *= 5.0;
customClassField.DoubleField *= 5.0;
customClassField.DoubleProp *= 5.0;
otherCustomStructField.DoubleField *= 5.0;
otherCustomStructField.DoubleProp *= 5.0;
CustomClassProp.DoubleField *= 5.0;
CustomClassProp.DoubleProp *= 5.0;
GetClass().DoubleField *= 5.0;
GetClass().DoubleProp *= 5.0;
#if CS70
GetRefStruct().DoubleField *= 5.0;
GetRefStruct().DoubleProp *= 5.0;
GetRefDouble() *= 5.0;
#endif
}
public static void DoubleDivideTest(double p, CustomClass c, CustomStruct2 s)
{
double num = 0.0;
p /= 5.0;
num /= 5.0;
Use(ref num);
doubleField /= 5.0;
DoubleProp /= 5.0;
c.DoubleField /= 5.0;
c.DoubleProp /= 5.0;
s.DoubleField /= 5.0;
s.DoubleProp /= 5.0;
customClassField.DoubleField /= 5.0;
customClassField.DoubleProp /= 5.0;
otherCustomStructField.DoubleField /= 5.0;
otherCustomStructField.DoubleProp /= 5.0;
CustomClassProp.DoubleField /= 5.0;
CustomClassProp.DoubleProp /= 5.0;
GetClass().DoubleField /= 5.0;
GetClass().DoubleProp /= 5.0;
#if CS70
GetRefStruct().DoubleField /= 5.0;
GetRefStruct().DoubleProp /= 5.0;
GetRefDouble() /= 5.0;
#endif
}
public static void DoubleModulusTest(double p, CustomClass c, CustomStruct2 s)
{
double num = 0.0;
p %= 5.0;
num %= 5.0;
Use(ref num);
doubleField %= 5.0;
DoubleProp %= 5.0;
c.DoubleField %= 5.0;
c.DoubleProp %= 5.0;
s.DoubleField %= 5.0;
s.DoubleProp %= 5.0;
customClassField.DoubleField %= 5.0;
customClassField.DoubleProp %= 5.0;
otherCustomStructField.DoubleField %= 5.0;
otherCustomStructField.DoubleProp %= 5.0;
CustomClassProp.DoubleField %= 5.0;
CustomClassProp.DoubleProp %= 5.0;
GetClass().DoubleField %= 5.0;
GetClass().DoubleProp %= 5.0;
#if CS70
GetRefStruct().DoubleField %= 5.0;
GetRefStruct().DoubleProp %= 5.0;
GetRefDouble() %= 5.0;
#endif
}
public static void DoublePostIncTest(double p, CustomClass c, CustomStruct2 s)
{
double num = 0.0;
X(p++);
X(num++);
Use(ref num);
X(doubleField++);
X(DoubleProp++);
X(c.DoubleField++);
X(c.DoubleProp++);
X(s.DoubleField++);
X(s.DoubleProp++);
X(customClassField.DoubleField++);
X(customClassField.DoubleProp++);
X(otherCustomStructField.DoubleField++);
X(otherCustomStructField.DoubleProp++);
X(CustomClassProp.DoubleField++);
X(CustomClassProp.DoubleProp++);
X(GetClass().DoubleField++);
X(GetClass().DoubleProp++);
#if CS70
X(GetRefStruct().DoubleField++);
X(GetRefStruct().DoubleProp++);
X(GetRefDouble()++);
#endif
}
public static void DoublePreIncTest(double p, CustomClass c, CustomStruct2 s)
{
double num = 0.0;
X(++p);
X(++num);
Use(ref num);
X(++doubleField);
X(++DoubleProp);
X(++c.DoubleField);
X(++c.DoubleProp);
X(++s.DoubleField);
X(++s.DoubleProp);
X(++customClassField.DoubleField);
X(++customClassField.DoubleProp);
X(++otherCustomStructField.DoubleField);
X(++otherCustomStructField.DoubleProp);
X(++CustomClassProp.DoubleField);
X(++CustomClassProp.DoubleProp);
X(++GetClass().DoubleField);
X(++GetClass().DoubleProp);
#if CS70
X(++GetRefStruct().DoubleField);
X(++GetRefStruct().DoubleProp);
X(++GetRefDouble());
#endif
}
public static void DoublePostDecTest(double p, CustomClass c, CustomStruct2 s)
{
double num = 0.0;
X(p--);
X(num--);
Use(ref num);
X(doubleField--);
X(DoubleProp--);
X(c.DoubleField--);
X(c.DoubleProp--);
X(s.DoubleField--);
X(s.DoubleProp--);
X(customClassField.DoubleField--);
X(customClassField.DoubleProp--);
X(otherCustomStructField.DoubleField--);
X(otherCustomStructField.DoubleProp--);
X(CustomClassProp.DoubleField--);
X(CustomClassProp.DoubleProp--);
X(GetClass().DoubleField--);
X(GetClass().DoubleProp--);
#if CS70
X(GetRefStruct().DoubleField--);
X(GetRefStruct().DoubleProp--);
X(GetRefDouble()--);
#endif
}
public static void DoublePreDecTest(double p, CustomClass c, CustomStruct2 s)
{
double num = 0.0;
X(--p);
X(--num);
Use(ref num);
X(--doubleField);
X(--DoubleProp);
X(--c.DoubleField);
X(--c.DoubleProp);
X(--s.DoubleField);
X(--s.DoubleProp);
X(--customClassField.DoubleField);
X(--customClassField.DoubleProp);
X(--otherCustomStructField.DoubleField);
X(--otherCustomStructField.DoubleProp);
X(--CustomClassProp.DoubleField);
X(--CustomClassProp.DoubleProp);
X(--GetClass().DoubleField);
X(--GetClass().DoubleProp);
#if CS70
X(--GetRefStruct().DoubleField);
X(--GetRefStruct().DoubleProp);
X(--GetRefDouble());
#endif
}
public static void DecimalAddTest(decimal p, CustomClass c, CustomStruct2 s)
{
#if LEGACY_CSC
decimal num = 0m;
#else
decimal num = default(decimal);
#endif
p += 5m;
num += 5m;
Use(ref num);
decimalField += 5m;
DecimalProp += 5m;
c.DecimalField += 5m;
c.DecimalProp += 5m;
s.DecimalField += 5m;
s.DecimalProp += 5m;
customClassField.DecimalField += 5m;
customClassField.DecimalProp += 5m;
otherCustomStructField.DecimalField += 5m;
otherCustomStructField.DecimalProp += 5m;
CustomClassProp.DecimalField += 5m;
CustomClassProp.DecimalProp += 5m;
GetClass().DecimalField += 5m;
GetClass().DecimalProp += 5m;
#if CS70
GetRefStruct().DecimalField += 5m;
GetRefStruct().DecimalProp += 5m;
GetRefDecimal() += 5m;
#endif
}
public static void DecimalSubtractTest(decimal p, CustomClass c, CustomStruct2 s)
{
#if LEGACY_CSC
decimal num = 0m;
#else
decimal num = default(decimal);
#endif
p -= 5m;
num -= 5m;
Use(ref num);
decimalField -= 5m;
DecimalProp -= 5m;
c.DecimalField -= 5m;
c.DecimalProp -= 5m;
s.DecimalField -= 5m;
s.DecimalProp -= 5m;
customClassField.DecimalField -= 5m;
customClassField.DecimalProp -= 5m;
otherCustomStructField.DecimalField -= 5m;
otherCustomStructField.DecimalProp -= 5m;
CustomClassProp.DecimalField -= 5m;
CustomClassProp.DecimalProp -= 5m;
GetClass().DecimalField -= 5m;
GetClass().DecimalProp -= 5m;
#if CS70
GetRefStruct().DecimalField -= 5m;
GetRefStruct().DecimalProp -= 5m;
GetRefDecimal() -= 5m;
#endif
}
public static void DecimalMultiplyTest(decimal p, CustomClass c, CustomStruct2 s)
{
#if LEGACY_CSC
decimal num = 0m;
#else
decimal num = default(decimal);
#endif
p *= 5m;
num *= 5m;
Use(ref num);
decimalField *= 5m;
DecimalProp *= 5m;
c.DecimalField *= 5m;
c.DecimalProp *= 5m;
s.DecimalField *= 5m;
s.DecimalProp *= 5m;
customClassField.DecimalField *= 5m;
customClassField.DecimalProp *= 5m;
otherCustomStructField.DecimalField *= 5m;
otherCustomStructField.DecimalProp *= 5m;
CustomClassProp.DecimalField *= 5m;
CustomClassProp.DecimalProp *= 5m;
GetClass().DecimalField *= 5m;
GetClass().DecimalProp *= 5m;
#if CS70
GetRefStruct().DecimalField *= 5m;
GetRefStruct().DecimalProp *= 5m;
GetRefDecimal() *= 5m;
#endif
}
public static void DecimalDivideTest(decimal p, CustomClass c, CustomStruct2 s)
{
#if LEGACY_CSC
decimal num = 0m;
#else
decimal num = default(decimal);
#endif
p /= 5m;
num /= 5m;
Use(ref num);
decimalField /= 5m;
DecimalProp /= 5m;
c.DecimalField /= 5m;
c.DecimalProp /= 5m;
s.DecimalField /= 5m;
s.DecimalProp /= 5m;
customClassField.DecimalField /= 5m;
customClassField.DecimalProp /= 5m;
otherCustomStructField.DecimalField /= 5m;
otherCustomStructField.DecimalProp /= 5m;
CustomClassProp.DecimalField /= 5m;
CustomClassProp.DecimalProp /= 5m;
GetClass().DecimalField /= 5m;
GetClass().DecimalProp /= 5m;
#if CS70
GetRefStruct().DecimalField /= 5m;
GetRefStruct().DecimalProp /= 5m;
GetRefDecimal() /= 5m;
#endif
}
public static void DecimalModulusTest(decimal p, CustomClass c, CustomStruct2 s)
{
#if LEGACY_CSC
decimal num = 0m;
#else
decimal num = default(decimal);
#endif
p %= 5m;
num %= 5m;
Use(ref num);
decimalField %= 5m;
DecimalProp %= 5m;
c.DecimalField %= 5m;
c.DecimalProp %= 5m;
s.DecimalField %= 5m;
s.DecimalProp %= 5m;
customClassField.DecimalField %= 5m;
customClassField.DecimalProp %= 5m;
otherCustomStructField.DecimalField %= 5m;
otherCustomStructField.DecimalProp %= 5m;
CustomClassProp.DecimalField %= 5m;
CustomClassProp.DecimalProp %= 5m;
GetClass().DecimalField %= 5m;
GetClass().DecimalProp %= 5m;
#if CS70
GetRefStruct().DecimalField %= 5m;
GetRefStruct().DecimalProp %= 5m;
GetRefDecimal() %= 5m;
#endif
}
public static void DecimalPostIncTest(decimal p, CustomClass c, CustomStruct2 s)
{
#if LEGACY_CSC
decimal num = 0m;
#else
decimal num = default(decimal);
#endif
X(p++);
X(num++);
Use(ref num);
X(decimalField++);
X(DecimalProp++);
X(c.DecimalField++);
X(c.DecimalProp++);
X(s.DecimalField++);
X(s.DecimalProp++);
X(customClassField.DecimalField++);
X(customClassField.DecimalProp++);
X(otherCustomStructField.DecimalField++);
X(otherCustomStructField.DecimalProp++);
X(CustomClassProp.DecimalField++);
X(CustomClassProp.DecimalProp++);
X(GetClass().DecimalField++);
X(GetClass().DecimalProp++);
#if CS70
X(GetRefStruct().DecimalField++);
X(GetRefStruct().DecimalProp++);
X(GetRefDecimal()++);
#endif
}
public static void DecimalPreIncTest(decimal p, CustomClass c, CustomStruct2 s)
{
#if LEGACY_CSC
decimal num = 0m;
#else
decimal num = default(decimal);
#endif
X(++p);
X(++num);
Use(ref num);
X(++decimalField);
X(++DecimalProp);
X(++c.DecimalField);
X(++c.DecimalProp);
X(++s.DecimalField);
X(++s.DecimalProp);
X(++customClassField.DecimalField);
X(++customClassField.DecimalProp);
X(++otherCustomStructField.DecimalField);
X(++otherCustomStructField.DecimalProp);
X(++CustomClassProp.DecimalField);
X(++CustomClassProp.DecimalProp);
X(++GetClass().DecimalField);
X(++GetClass().DecimalProp);
#if CS70
X(++GetRefStruct().DecimalField);
X(++GetRefStruct().DecimalProp);
X(++GetRefDecimal());
#endif
}
public static void DecimalPostDecTest(decimal p, CustomClass c, CustomStruct2 s)
{
#if LEGACY_CSC
decimal num = 0m;
#else
decimal num = default(decimal);
#endif
X(p--);
X(num--);
Use(ref num);
X(decimalField--);
X(DecimalProp--);
X(c.DecimalField--);
X(c.DecimalProp--);
X(s.DecimalField--);
X(s.DecimalProp--);
X(customClassField.DecimalField--);
X(customClassField.DecimalProp--);
X(otherCustomStructField.DecimalField--);
X(otherCustomStructField.DecimalProp--);
X(CustomClassProp.DecimalField--);
X(CustomClassProp.DecimalProp--);
X(GetClass().DecimalField--);
X(GetClass().DecimalProp--);
#if CS70
X(GetRefStruct().DecimalField--);
X(GetRefStruct().DecimalProp--);
X(GetRefDecimal()--);
#endif
}
public static void DecimalPreDecTest(decimal p, CustomClass c, CustomStruct2 s)
{
#if LEGACY_CSC
decimal num = 0m;
#else
decimal num = default(decimal);
#endif
X(--p);
X(--num);
Use(ref num);
X(--decimalField);
X(--DecimalProp);
X(--c.DecimalField);
X(--c.DecimalProp);
X(--s.DecimalField);
X(--s.DecimalProp);
X(--customClassField.DecimalField);
X(--customClassField.DecimalProp);
X(--otherCustomStructField.DecimalField);
X(--otherCustomStructField.DecimalProp);
X(--CustomClassProp.DecimalField);
X(--CustomClassProp.DecimalProp);
X(--GetClass().DecimalField);
X(--GetClass().DecimalProp);
#if CS70
X(--GetRefStruct().DecimalField);
X(--GetRefStruct().DecimalProp);
X(--GetRefDecimal());
#endif
}
public static void CustomClassAddTest(CustomClass p, CustomClass c, CustomStruct2 s) public static void CustomClassAddTest(CustomClass p, CustomClass c, CustomStruct2 s)
{ {
CustomClass num = null; CustomClass num = null;

8
ICSharpCode.Decompiler/CSharp/Transforms/PrettifyAssignments.cs

@ -76,9 +76,13 @@ namespace ICSharpCode.Decompiler.CSharp.Transforms
} }
if (context.Settings.IntroduceIncrementAndDecrement && assignment.Operator == AssignmentOperatorType.Add || assignment.Operator == AssignmentOperatorType.Subtract) if (context.Settings.IntroduceIncrementAndDecrement && assignment.Operator == AssignmentOperatorType.Add || assignment.Operator == AssignmentOperatorType.Subtract)
{ {
// detect increment/decrement // detect increment/decrement; ++/-- on float/double compiles to the same IL as
// adding/subtracting a constant 1 (which both types represent exactly), so a
// constant 1 right-hand side qualifies there just like for integers
var rr = assignment.Right.GetResolveResult(); var rr = assignment.Right.GetResolveResult();
if (rr.IsCompileTimeConstant && rr.Type.IsCSharpPrimitiveIntegerType() && CSharpPrimitiveCast.Cast(rr.Type.GetTypeCode(), 1, false).Equals(rr.ConstantValue)) if (rr.IsCompileTimeConstant
&& (rr.Type.IsCSharpPrimitiveIntegerType() || rr.Type.IsKnownType(KnownTypeCode.Single) || rr.Type.IsKnownType(KnownTypeCode.Double))
&& CSharpPrimitiveCast.Cast(rr.Type.GetTypeCode(), 1, false).Equals(rr.ConstantValue))
{ {
// only if it's not a custom operator // only if it's not a custom operator
if (assignment.Annotation<IL.CallInstruction>() == null && assignment.Annotation<IL.UserDefinedCompoundAssign>() == null && assignment.Annotation<IL.DynamicCompoundAssign>() == null) if (assignment.Annotation<IL.CallInstruction>() == null && assignment.Annotation<IL.UserDefinedCompoundAssign>() == null && assignment.Annotation<IL.DynamicCompoundAssign>() == null)

Loading…
Cancel
Save