Browse Source

Fix bug in TransformRoslynPostIncDecOperatorOnAddress;

Add DelegateConstruction tests
pull/892/merge
Siegfried Pammer 8 years ago
parent
commit
ab1598c547
  1. 2
      ICSharpCode.Decompiler.Tests/PrettyTestRunner.cs
  2. 8
      ICSharpCode.Decompiler/IL/Transforms/DelegateConstruction.cs
  3. 4
      ICSharpCode.Decompiler/IL/Transforms/TransformAssignment.cs

2
ICSharpCode.Decompiler.Tests/PrettyTestRunner.cs

@ -97,7 +97,7 @@ namespace ICSharpCode.Decompiler.Tests
Run(cscOptions: cscOptions); Run(cscOptions: cscOptions);
} }
[Test, Ignore]
[Test]
public void DelegateConstruction([ValueSource("defaultOptions")] CompilerOptions cscOptions) public void DelegateConstruction([ValueSource("defaultOptions")] CompilerOptions cscOptions)
{ {
Run(cscOptions: cscOptions); Run(cscOptions: cscOptions);

8
ICSharpCode.Decompiler/IL/Transforms/DelegateConstruction.cs

@ -319,6 +319,14 @@ namespace ICSharpCode.Decompiler.IL.Transforms
throw new NotImplementedException(); throw new NotImplementedException();
} }
} }
protected internal override void VisitCompoundAssignmentInstruction(CompoundAssignmentInstruction inst)
{
base.VisitCompoundAssignmentInstruction(inst);
if (inst.Target.MatchLdLoc(out var v)) {
inst.ReplaceWith(new StLoc(v, new BinaryNumericInstruction(inst.Operator, inst.Target, inst.Value, inst.CheckForOverflow, inst.Sign)));
}
}
} }
#endregion #endregion
} }

4
ICSharpCode.Decompiler/IL/Transforms/TransformAssignment.cs

@ -338,6 +338,8 @@ namespace ICSharpCode.Decompiler.IL.Transforms
var stobj = block.Instructions.ElementAtOrDefault(i + 1) as StObj; var stobj = block.Instructions.ElementAtOrDefault(i + 1) as StObj;
if (inst == null || stobj == null) if (inst == null || stobj == null)
return false; return false;
if (!inst.Variable.IsSingleDefinition || inst.Variable.LoadCount != 1)
return false;
if (!inst.Value.MatchLdObj(out var loadTarget, out var loadType) || !loadTarget.MatchLdFlda(out var fieldTarget, out var field)) if (!inst.Value.MatchLdObj(out var loadTarget, out var loadType) || !loadTarget.MatchLdFlda(out var fieldTarget, out var field))
return false; return false;
if (!stobj.Target.MatchLdFlda(out var fieldTarget2, out var field2)) if (!stobj.Target.MatchLdFlda(out var fieldTarget2, out var field2))
@ -348,7 +350,7 @@ namespace ICSharpCode.Decompiler.IL.Transforms
if (binary == null || !binary.Left.MatchLdLoc(inst.Variable) || !binary.Right.MatchLdcI4(1) if (binary == null || !binary.Left.MatchLdLoc(inst.Variable) || !binary.Right.MatchLdcI4(1)
|| (binary.Operator != BinaryNumericOperator.Add && binary.Operator != BinaryNumericOperator.Sub)) || (binary.Operator != BinaryNumericOperator.Add && binary.Operator != BinaryNumericOperator.Sub))
return false; return false;
context.Step($"TransformRoslynPostIncDecOperator", inst);
context.Step("TransformRoslynPostIncDecOperator", inst);
stobj.ReplaceWith(new CompoundAssignmentInstruction(binary, inst.Value, binary.Right, loadType, CompoundAssignmentType.EvaluatesToOldValue)); stobj.ReplaceWith(new CompoundAssignmentInstruction(binary, inst.Value, binary.Right, loadType, CompoundAssignmentType.EvaluatesToOldValue));
block.Instructions.RemoveAt(i); block.Instructions.RemoveAt(i);
return true; return true;

Loading…
Cancel
Save