Browse Source

Always use hex in flags enums and in bit-wise operations.

pull/987/head
Siegfried Pammer 8 years ago
parent
commit
70e56c4b4d
  1. 6
      ICSharpCode.Decompiler/CSharp/CSharpDecompiler.cs
  2. 4
      ICSharpCode.Decompiler/CSharp/ExpressionBuilder.cs

6
ICSharpCode.Decompiler/CSharp/CSharpDecompiler.cs

@ -830,7 +830,11 @@ namespace ICSharpCode.Decompiler.CSharp @@ -830,7 +830,11 @@ namespace ICSharpCode.Decompiler.CSharp
}
long initValue = (long)CSharpPrimitiveCast.Cast(TypeCode.Int64, field.ConstantValue, false);
var enumDec = new EnumMemberDeclaration { Name = field.Name };
if (previousValue + 1 != initValue || decompilationContext.CurrentTypeDefinition.Attributes.Any(a => a.AttributeType.FullName == "System.FlagsAttribute")) {
if (decompilationContext.CurrentTypeDefinition.Attributes.Any(a => a.AttributeType.FullName == "System.FlagsAttribute")) {
enumDec.Initializer = typeSystemAstBuilder.ConvertConstantValue(decompilationContext.CurrentTypeDefinition.EnumUnderlyingType, field.ConstantValue);
if (enumDec.Initializer is PrimitiveExpression primitive && initValue > 9)
primitive.SetValue(initValue, $"0x{initValue:X}");
} else if (previousValue + 1 != initValue) {
enumDec.Initializer = typeSystemAstBuilder.ConvertConstantValue(decompilationContext.CurrentTypeDefinition.EnumUnderlyingType, field.ConstantValue);
if (enumDec.Initializer is PrimitiveExpression primitive && initValue > 9 && ((initValue & (initValue - 1)) == 0 || (initValue & (initValue + 1)) == 0)) {
primitive.SetValue(initValue, $"0x{initValue:X}");

4
ICSharpCode.Decompiler/CSharp/ExpressionBuilder.cs

@ -296,10 +296,6 @@ namespace ICSharpCode.Decompiler.CSharp @@ -296,10 +296,6 @@ namespace ICSharpCode.Decompiler.CSharp
parent = conv.Parent;
if (value <= 9)
return false;
if (value < long.MaxValue) {
if (!((value & (value - 1)) == 0 || (value & (value + 1)) == 0))
return false;
}
switch (parent) {
case BinaryNumericInstruction bni:
if (bni.Operator == BinaryNumericOperator.BitAnd

Loading…
Cancel
Save