Browse Source

ILAst: make 'Return' less of a special case

(don't let the slot contents have an effect on the number of slots)
pull/728/head
Daniel Grunwald 10 years ago
parent
commit
e2c0f40f71
  1. 2
      ICSharpCode.Decompiler/IL/Instructions/ILInstruction.cs
  2. 19
      ICSharpCode.Decompiler/IL/Instructions/Return.cs

2
ICSharpCode.Decompiler/IL/Instructions/ILInstruction.cs

@ -407,7 +407,7 @@ namespace ICSharpCode.Decompiler.IL
protected internal void SetChildInstruction(ref ILInstruction childPointer, ILInstruction newValue, int index) protected internal void SetChildInstruction(ref ILInstruction childPointer, ILInstruction newValue, int index)
{ {
ILInstruction oldValue = childPointer; ILInstruction oldValue = childPointer;
Debug.Assert(this is Return || oldValue == GetChild(index)); Debug.Assert(oldValue == GetChild(index));
if (oldValue == newValue) if (oldValue == newValue)
return; return;
childPointer = newValue; childPointer = newValue;

19
ICSharpCode.Decompiler/IL/Instructions/Return.cs

@ -26,6 +26,7 @@ namespace ICSharpCode.Decompiler.IL
{ {
public static readonly SlotInfo ReturnValueSlot = new SlotInfo("ReturnValue", canInlineInto: true); public static readonly SlotInfo ReturnValueSlot = new SlotInfo("ReturnValue", canInlineInto: true);
readonly bool hasArgument;
ILInstruction returnValue; ILInstruction returnValue;
/// <summary> /// <summary>
@ -34,9 +35,12 @@ namespace ICSharpCode.Decompiler.IL
public ILInstruction ReturnValue { public ILInstruction ReturnValue {
get { return returnValue; } get { return returnValue; }
set { set {
if (value != null) if (hasArgument) {
ValidateChild(value); ValidateChild(value);
SetChildInstruction(ref returnValue, value, 0); SetChildInstruction(ref returnValue, value, 0);
} else {
Debug.Assert(value == null);
}
} }
} }
@ -46,13 +50,14 @@ namespace ICSharpCode.Decompiler.IL
public Return(ILInstruction argument) : base(OpCode.Return) public Return(ILInstruction argument) : base(OpCode.Return)
{ {
this.hasArgument = true;
this.ReturnValue = argument; this.ReturnValue = argument;
} }
public override ILInstruction Clone() public override ILInstruction Clone()
{ {
Return clone = (Return)ShallowClone(); Return clone = (Return)ShallowClone();
if (returnValue != null) if (hasArgument)
clone.ReturnValue = returnValue.Clone(); clone.ReturnValue = returnValue.Clone();
return clone; return clone;
} }
@ -60,7 +65,7 @@ namespace ICSharpCode.Decompiler.IL
protected override InstructionFlags ComputeFlags() protected override InstructionFlags ComputeFlags()
{ {
InstructionFlags flags = InstructionFlags.MayBranch | InstructionFlags.EndPointUnreachable; InstructionFlags flags = InstructionFlags.MayBranch | InstructionFlags.EndPointUnreachable;
if (returnValue != null) { if (hasArgument) {
flags |= returnValue.Flags; flags |= returnValue.Flags;
} }
return flags; return flags;
@ -78,12 +83,12 @@ namespace ICSharpCode.Decompiler.IL
protected override int GetChildCount() protected override int GetChildCount()
{ {
return returnValue != null ? 1 : 0; return hasArgument ? 1 : 0;
} }
protected override ILInstruction GetChild(int index) protected override ILInstruction GetChild(int index)
{ {
if (index == 0 && returnValue != null) if (index == 0 && hasArgument)
return returnValue; return returnValue;
else else
throw new IndexOutOfRangeException(); throw new IndexOutOfRangeException();
@ -91,7 +96,7 @@ namespace ICSharpCode.Decompiler.IL
protected override void SetChild(int index, ILInstruction value) protected override void SetChild(int index, ILInstruction value)
{ {
if (index == 0 && returnValue != null) if (index == 0 && hasArgument)
ReturnValue = value; ReturnValue = value;
else else
throw new IndexOutOfRangeException(); throw new IndexOutOfRangeException();

Loading…
Cancel
Save