|
|
|
@ -26,8 +26,18 @@ namespace ICSharpCode.Decompiler.Ast.Transforms
@@ -26,8 +26,18 @@ namespace ICSharpCode.Decompiler.Ast.Transforms
|
|
|
|
|
{ |
|
|
|
|
public class PushNegation: DepthFirstAstVisitor<object, object>, IAstTransform |
|
|
|
|
{ |
|
|
|
|
sealed class LiftedOperator { } |
|
|
|
|
/// <summary>
|
|
|
|
|
/// Annotation for lifted operators that cannot be transformed by PushNegation
|
|
|
|
|
/// </summary>
|
|
|
|
|
public static readonly object LiftedOperatorAnnotation = new LiftedOperator(); |
|
|
|
|
|
|
|
|
|
public override object VisitUnaryOperatorExpression(UnaryOperatorExpression unary, object data) |
|
|
|
|
{ |
|
|
|
|
// lifted operators can't be transformed
|
|
|
|
|
if (unary.Annotation<LiftedOperator>() != null || unary.Expression.Annotation<LiftedOperator>() != null) |
|
|
|
|
return base.VisitUnaryOperatorExpression(unary, data); |
|
|
|
|
|
|
|
|
|
// Remove double negation
|
|
|
|
|
// !!a
|
|
|
|
|
if (unary.Operator == UnaryOperatorType.Not && |
|
|
|
@ -108,6 +118,10 @@ namespace ICSharpCode.Decompiler.Ast.Transforms
@@ -108,6 +118,10 @@ namespace ICSharpCode.Decompiler.Ast.Transforms
|
|
|
|
|
|
|
|
|
|
public override object VisitBinaryOperatorExpression(BinaryOperatorExpression binaryOperatorExpression, object data) |
|
|
|
|
{ |
|
|
|
|
// lifted operators can't be transformed
|
|
|
|
|
if (binaryOperatorExpression.Annotation<LiftedOperator>() != null) |
|
|
|
|
return base.VisitBinaryOperatorExpression(binaryOperatorExpression, data); |
|
|
|
|
|
|
|
|
|
BinaryOperatorType op = binaryOperatorExpression.Operator; |
|
|
|
|
bool? rightOperand = null; |
|
|
|
|
if (binaryOperatorExpression.Right is PrimitiveExpression) |
|
|
|
@ -146,16 +160,5 @@ namespace ICSharpCode.Decompiler.Ast.Transforms
@@ -146,16 +160,5 @@ namespace ICSharpCode.Decompiler.Ast.Transforms
|
|
|
|
|
{ |
|
|
|
|
node.AcceptVisitor(this, null); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public override object VisitParenthesizedExpression(ParenthesizedExpression expr, object data) |
|
|
|
|
{ |
|
|
|
|
// extra parentheses are redundant after this transformation
|
|
|
|
|
if(expr.Annotation<InvisibleParenthesis>() != null) { |
|
|
|
|
var res = expr.Expression; |
|
|
|
|
expr.ReplaceWith(res); |
|
|
|
|
return res.AcceptVisitor(this, data); |
|
|
|
|
} |
|
|
|
|
return base.VisitParenthesizedExpression(expr, data); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|