Browse Source

Add back replacing `a & b` with `a && b` for booleans.

Now as part of ExpressionBuilder, not as a transform, because doing this too early interferes with `a &= b` compound assignments.
pull/1835/head
Daniel Grunwald 6 years ago
parent
commit
be28469ea3
  1. 12
      ICSharpCode.Decompiler/CSharp/ExpressionBuilder.cs

12
ICSharpCode.Decompiler/CSharp/ExpressionBuilder.cs

@ -1280,6 +1280,18 @@ namespace ICSharpCode.Decompiler.CSharp @@ -1280,6 +1280,18 @@ namespace ICSharpCode.Decompiler.CSharp
right.ResolveResult));
}
}
if (op.IsBitwise()
&& left.Type.IsKnownType(KnownTypeCode.Boolean)
&& right.Type.IsKnownType(KnownTypeCode.Boolean)
&& SemanticHelper.IsPure(inst.Right.Flags))
{
// Undo the C# compiler's optimization of "a && b" to "a & b".
if (op == BinaryOperatorType.BitwiseAnd) {
op = BinaryOperatorType.ConditionalAnd;
} else if (op == BinaryOperatorType.BitwiseOr) {
op = BinaryOperatorType.ConditionalOr;
}
}
if (op.IsBitwise() && (left.Type.Kind == TypeKind.Enum || right.Type.Kind == TypeKind.Enum)) {
left = AdjustConstantExpressionToType(left, right.Type);

Loading…
Cancel
Save