Browse Source

Add an annotation to redundant ParenthesizedExpressions for PushNegation transform

pull/205/head
Pent Ploompuu 14 years ago
parent
commit
0e993afe58
  1. 7
      ICSharpCode.Decompiler/Ast/Annotations.cs
  2. 2
      ICSharpCode.Decompiler/Ast/AstMethodBodyBuilder.cs
  3. 9
      ICSharpCode.Decompiler/Ast/Transforms/PushNegation.cs

7
ICSharpCode.Decompiler/Ast/Annotations.cs

@ -12,4 +12,11 @@ namespace ICSharpCode.Decompiler.Ast @@ -12,4 +12,11 @@ namespace ICSharpCode.Decompiler.Ast
this.InferredType = inferredType;
}
}
sealed class InvisibleParenthesis
{
InvisibleParenthesis() { }
public static readonly InvisibleParenthesis Value = new InvisibleParenthesis();
}
}

2
ICSharpCode.Decompiler/Ast/AstMethodBodyBuilder.cs

@ -809,7 +809,7 @@ namespace ICSharpCode.Decompiler.Ast @@ -809,7 +809,7 @@ namespace ICSharpCode.Decompiler.Ast
case ILCode.InitializedObject:
return new InitializedObjectExpression();
case ILCode.Wrap:
return new ParenthesizedExpression(arg1);
return new ParenthesizedExpression(arg1).WithAnnotation(InvisibleParenthesis.Value);
case ILCode.AddressOf:
return MakeRef(arg1);
case ILCode.NullableOf:

9
ICSharpCode.Decompiler/Ast/Transforms/PushNegation.cs

@ -150,9 +150,12 @@ namespace ICSharpCode.Decompiler.Ast.Transforms @@ -150,9 +150,12 @@ namespace ICSharpCode.Decompiler.Ast.Transforms
public override object VisitParenthesizedExpression(ParenthesizedExpression expr, object data)
{
// extra parentheses are redundant after this transformation
var res = expr.Expression;
expr.ReplaceWith(res);
return res.AcceptVisitor(this, data);
if(expr.Annotation<InvisibleParenthesis>() != null) {
var res = expr.Expression;
expr.ReplaceWith(res);
return res.AcceptVisitor(this, data);
}
return base.VisitParenthesizedExpression(expr, data);
}
}
}

Loading…
Cancel
Save