|
|
|
@ -37,6 +37,8 @@ namespace ICSharpCode.Decompiler.CSharp.Transforms
@@ -37,6 +37,8 @@ namespace ICSharpCode.Decompiler.CSharp.Transforms
|
|
|
|
|
/// </remarks>
|
|
|
|
|
class PrettifyAssignments : DepthFirstAstVisitor, IAstTransform |
|
|
|
|
{ |
|
|
|
|
TransformContext context; |
|
|
|
|
|
|
|
|
|
public override void VisitAssignmentExpression(AssignmentExpression assignment) |
|
|
|
|
{ |
|
|
|
|
base.VisitAssignmentExpression(assignment); |
|
|
|
@ -52,13 +54,12 @@ namespace ICSharpCode.Decompiler.CSharp.Transforms
@@ -52,13 +54,12 @@ namespace ICSharpCode.Decompiler.CSharp.Transforms
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
// TODO: context.Settings.IntroduceIncrementAndDecrement
|
|
|
|
|
if (assignment.Operator == AssignmentOperatorType.Add || assignment.Operator == AssignmentOperatorType.Subtract) { |
|
|
|
|
if (context.Settings.IntroduceIncrementAndDecrement && assignment.Operator == AssignmentOperatorType.Add || assignment.Operator == AssignmentOperatorType.Subtract) { |
|
|
|
|
// detect increment/decrement
|
|
|
|
|
var rr = assignment.Right.GetResolveResult(); |
|
|
|
|
if (rr.IsCompileTimeConstant && rr.Type.IsCSharpPrimitiveIntegerType() && CSharpPrimitiveCast.Cast(rr.Type.GetTypeCode(), 1, false).Equals(rr.ConstantValue)) { |
|
|
|
|
// only if it's not a custom operator
|
|
|
|
|
if (assignment.Annotation<IL.CallInstruction>() == null && assignment.Annotation<IL.UserDefinedCompoundAssign>() == null) { |
|
|
|
|
if (assignment.Annotation<IL.CallInstruction>() == null && assignment.Annotation<IL.UserDefinedCompoundAssign>() == null && assignment.Annotation<IL.DynamicCompoundAssign>() == null) { |
|
|
|
|
UnaryOperatorType type; |
|
|
|
|
// When the parent is an expression statement, pre- or post-increment doesn't matter;
|
|
|
|
|
// so we can pick post-increment which is more commonly used (for (int i = 0; i < x; i++))
|
|
|
|
@ -121,6 +122,7 @@ namespace ICSharpCode.Decompiler.CSharp.Transforms
@@ -121,6 +122,7 @@ namespace ICSharpCode.Decompiler.CSharp.Transforms
|
|
|
|
|
|
|
|
|
|
void IAstTransform.Run(AstNode node, TransformContext context) |
|
|
|
|
{ |
|
|
|
|
this.context = context; |
|
|
|
|
node.AcceptVisitor(this); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|