Browse Source

NumericCompoundAssign: implement ILiftableInstruction

pull/1129/head
Daniel Grunwald 8 years ago
parent
commit
f021ec4383
  1. 7
      ICSharpCode.Decompiler/IL/Instructions/CompoundAssignmentInstruction.cs
  2. 6
      ICSharpCode.Decompiler/IL/Transforms/TransformAssignment.cs

7
ICSharpCode.Decompiler/IL/Instructions/CompoundAssignmentInstruction.cs

@ -56,7 +56,7 @@ namespace ICSharpCode.Decompiler.IL
} }
} }
public partial class NumericCompoundAssign : CompoundAssignmentInstruction public partial class NumericCompoundAssign : CompoundAssignmentInstruction, ILiftableInstruction
{ {
/// <summary> /// <summary>
/// Gets whether the instruction checks for overflow. /// Gets whether the instruction checks for overflow.
@ -195,13 +195,12 @@ namespace ICSharpCode.Decompiler.IL
public partial class UserDefinedCompoundAssign : CompoundAssignmentInstruction public partial class UserDefinedCompoundAssign : CompoundAssignmentInstruction
{ {
public readonly IMethod Method; public readonly IMethod Method;
public readonly bool IsLifted; public bool IsLifted => false; // TODO: implement ILi
public UserDefinedCompoundAssign(IMethod method, CompoundAssignmentType compoundAssignmentType, ILInstruction target, ILInstruction value, bool isLifted) public UserDefinedCompoundAssign(IMethod method, CompoundAssignmentType compoundAssignmentType, ILInstruction target, ILInstruction value)
: base(OpCode.UserDefinedCompoundAssign, compoundAssignmentType, target, value) : base(OpCode.UserDefinedCompoundAssign, compoundAssignmentType, target, value)
{ {
this.Method = method; this.Method = method;
this.IsLifted = isLifted;
Debug.Assert(Method.IsOperator); Debug.Assert(Method.IsOperator);
Debug.Assert(compoundAssignmentType == CompoundAssignmentType.EvaluatesToNewValue || (Method.Name == "op_Increment" || Method.Name == "op_Decrement")); Debug.Assert(compoundAssignmentType == CompoundAssignmentType.EvaluatesToNewValue || (Method.Name == "op_Increment" || Method.Name == "op_Decrement"));
Debug.Assert(IsValidCompoundAssignmentTarget(Target)); Debug.Assert(IsValidCompoundAssignmentTarget(Target));

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

@ -292,7 +292,7 @@ namespace ICSharpCode.Decompiler.IL.Transforms
return false; // TODO: add tests and think about whether nullables need special considerations return false; // TODO: add tests and think about whether nullables need special considerations
context.Step($"Compound assignment (user-defined binary)", compoundStore); context.Step($"Compound assignment (user-defined binary)", compoundStore);
newInst = new UserDefinedCompoundAssign(operatorCall.Method, CompoundAssignmentType.EvaluatesToNewValue, newInst = new UserDefinedCompoundAssign(operatorCall.Method, CompoundAssignmentType.EvaluatesToNewValue,
operatorCall.Arguments[0], rhs, operatorCall.IsLifted); operatorCall.Arguments[0], rhs);
} else { } else {
return false; return false;
} }
@ -539,7 +539,7 @@ namespace ICSharpCode.Decompiler.IL.Transforms
} else { } else {
Call operatorCall = (Call)value; Call operatorCall = (Call)value;
block.Instructions[pos] = new StLoc(stloc.Variable, new UserDefinedCompoundAssign( block.Instructions[pos] = new StLoc(stloc.Variable, new UserDefinedCompoundAssign(
operatorCall.Method, CompoundAssignmentType.EvaluatesToOldValue, stloc.Value, new LdcI4(1), operatorCall.IsLifted)); operatorCall.Method, CompoundAssignmentType.EvaluatesToOldValue, stloc.Value, new LdcI4(1)));
} }
return true; return true;
} }
@ -587,7 +587,7 @@ namespace ICSharpCode.Decompiler.IL.Transforms
return false; // TODO: add tests and think about whether nullables need special considerations return false; // TODO: add tests and think about whether nullables need special considerations
context.Step("TransformPostIncDecOperator (user-defined)", inst); context.Step("TransformPostIncDecOperator (user-defined)", inst);
inst.Value = new UserDefinedCompoundAssign(operatorCall.Method, inst.Value = new UserDefinedCompoundAssign(operatorCall.Method,
CompoundAssignmentType.EvaluatesToOldValue, inst.Value, new LdcI4(1), operatorCall.IsLifted); CompoundAssignmentType.EvaluatesToOldValue, inst.Value, new LdcI4(1));
} else { } else {
return false; return false;
} }

Loading…
Cancel
Save