|
|
@ -64,6 +64,8 @@ namespace ICSharpCode.Decompiler.CSharp.OutputVisitor |
|
|
|
return Primary; |
|
|
|
return Primary; |
|
|
|
case UnaryOperatorType.NullConditionalRewrap: |
|
|
|
case UnaryOperatorType.NullConditionalRewrap: |
|
|
|
return NullableRewrap; |
|
|
|
return NullableRewrap; |
|
|
|
|
|
|
|
case UnaryOperatorType.IsTrue: |
|
|
|
|
|
|
|
return Conditional; |
|
|
|
default: |
|
|
|
default: |
|
|
|
return Unary; |
|
|
|
return Unary; |
|
|
|
} |
|
|
|
} |
|
|
@ -264,12 +266,13 @@ namespace ICSharpCode.Decompiler.CSharp.OutputVisitor |
|
|
|
if (InsertParenthesesForReadability && precedence < Equality) { |
|
|
|
if (InsertParenthesesForReadability && precedence < Equality) { |
|
|
|
// In readable mode, boost the priority of the left-hand side if the operator
|
|
|
|
// In readable mode, boost the priority of the left-hand side if the operator
|
|
|
|
// there isn't the same as the operator on this expression.
|
|
|
|
// there isn't the same as the operator on this expression.
|
|
|
|
|
|
|
|
int boostTo = IsBitwise(binaryOperatorExpression.Operator) ? Unary : Equality; |
|
|
|
if (GetBinaryOperatorType(binaryOperatorExpression.Left) == binaryOperatorExpression.Operator) { |
|
|
|
if (GetBinaryOperatorType(binaryOperatorExpression.Left) == binaryOperatorExpression.Operator) { |
|
|
|
ParenthesizeIfRequired(binaryOperatorExpression.Left, precedence); |
|
|
|
ParenthesizeIfRequired(binaryOperatorExpression.Left, precedence); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
ParenthesizeIfRequired(binaryOperatorExpression.Left, Equality); |
|
|
|
ParenthesizeIfRequired(binaryOperatorExpression.Left, boostTo); |
|
|
|
} |
|
|
|
} |
|
|
|
ParenthesizeIfRequired(binaryOperatorExpression.Right, Equality); |
|
|
|
ParenthesizeIfRequired(binaryOperatorExpression.Right, boostTo); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
// all other binary operators are left-associative
|
|
|
|
// all other binary operators are left-associative
|
|
|
|
ParenthesizeIfRequired(binaryOperatorExpression.Left, precedence); |
|
|
|
ParenthesizeIfRequired(binaryOperatorExpression.Left, precedence); |
|
|
@ -278,7 +281,14 @@ namespace ICSharpCode.Decompiler.CSharp.OutputVisitor |
|
|
|
} |
|
|
|
} |
|
|
|
base.VisitBinaryOperatorExpression(binaryOperatorExpression); |
|
|
|
base.VisitBinaryOperatorExpression(binaryOperatorExpression); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static bool IsBitwise(BinaryOperatorType op) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
return op == BinaryOperatorType.BitwiseAnd |
|
|
|
|
|
|
|
|| op == BinaryOperatorType.BitwiseOr |
|
|
|
|
|
|
|
|| op == BinaryOperatorType.ExclusiveOr; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
BinaryOperatorType? GetBinaryOperatorType(Expression expr) |
|
|
|
BinaryOperatorType? GetBinaryOperatorType(Expression expr) |
|
|
|
{ |
|
|
|
{ |
|
|
|
BinaryOperatorExpression boe = expr as BinaryOperatorExpression; |
|
|
|
BinaryOperatorExpression boe = expr as BinaryOperatorExpression; |
|
|
|