From e2c0f40f71352fca10b7f903c07a840a67a58227 Mon Sep 17 00:00:00 2001 From: Daniel Grunwald Date: Sat, 11 Jun 2016 20:02:53 +0200 Subject: [PATCH] ILAst: make 'Return' less of a special case (don't let the slot contents have an effect on the number of slots) --- .../IL/Instructions/ILInstruction.cs | 2 +- .../IL/Instructions/Return.cs | 19 ++++++++++++------- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/ICSharpCode.Decompiler/IL/Instructions/ILInstruction.cs b/ICSharpCode.Decompiler/IL/Instructions/ILInstruction.cs index 0961a0a36..574b6d094 100644 --- a/ICSharpCode.Decompiler/IL/Instructions/ILInstruction.cs +++ b/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) { ILInstruction oldValue = childPointer; - Debug.Assert(this is Return || oldValue == GetChild(index)); + Debug.Assert(oldValue == GetChild(index)); if (oldValue == newValue) return; childPointer = newValue; diff --git a/ICSharpCode.Decompiler/IL/Instructions/Return.cs b/ICSharpCode.Decompiler/IL/Instructions/Return.cs index 776acab4c..d683dcfb9 100644 --- a/ICSharpCode.Decompiler/IL/Instructions/Return.cs +++ b/ICSharpCode.Decompiler/IL/Instructions/Return.cs @@ -26,6 +26,7 @@ namespace ICSharpCode.Decompiler.IL { public static readonly SlotInfo ReturnValueSlot = new SlotInfo("ReturnValue", canInlineInto: true); + readonly bool hasArgument; ILInstruction returnValue; /// @@ -34,9 +35,12 @@ namespace ICSharpCode.Decompiler.IL public ILInstruction ReturnValue { get { return returnValue; } set { - if (value != null) + if (hasArgument) { 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) { + this.hasArgument = true; this.ReturnValue = argument; } public override ILInstruction Clone() { Return clone = (Return)ShallowClone(); - if (returnValue != null) + if (hasArgument) clone.ReturnValue = returnValue.Clone(); return clone; } @@ -60,7 +65,7 @@ namespace ICSharpCode.Decompiler.IL protected override InstructionFlags ComputeFlags() { InstructionFlags flags = InstructionFlags.MayBranch | InstructionFlags.EndPointUnreachable; - if (returnValue != null) { + if (hasArgument) { flags |= returnValue.Flags; } return flags; @@ -78,12 +83,12 @@ namespace ICSharpCode.Decompiler.IL protected override int GetChildCount() { - return returnValue != null ? 1 : 0; + return hasArgument ? 1 : 0; } protected override ILInstruction GetChild(int index) { - if (index == 0 && returnValue != null) + if (index == 0 && hasArgument) return returnValue; else throw new IndexOutOfRangeException(); @@ -91,7 +96,7 @@ namespace ICSharpCode.Decompiler.IL protected override void SetChild(int index, ILInstruction value) { - if (index == 0 && returnValue != null) + if (index == 0 && hasArgument) ReturnValue = value; else throw new IndexOutOfRangeException();