diff --git a/ICSharpCode.Decompiler/IL/Instructions/ILInstruction.cs b/ICSharpCode.Decompiler/IL/Instructions/ILInstruction.cs index c35c701ee..b7a96a8df 100644 --- a/ICSharpCode.Decompiler/IL/Instructions/ILInstruction.cs +++ b/ICSharpCode.Decompiler/IL/Instructions/ILInstruction.cs @@ -214,24 +214,29 @@ namespace ICSharpCode.Decompiler.IL public void AddILRange(Interval newRange) { - if (this.ILRange.IsEmpty) { - this.ILRange = newRange; - return; + this.ILRange = CombineILRange(this.ILRange, newRange); + } + + protected static Interval CombineILRange(Interval oldRange, Interval newRange) + { + if (oldRange.IsEmpty) { + return newRange; } if (newRange.IsEmpty) { - return; + return oldRange; } - if (newRange.Start <= this.StartILOffset) { - if (newRange.End < this.StartILOffset) { - this.ILRange = newRange; // use the earlier range + if (newRange.Start <= oldRange.Start) { + if (newRange.End < oldRange.Start) { + return newRange; // use the earlier range } else { // join overlapping ranges - this.ILRange = new Interval(newRange.Start, Math.Max(newRange.End, this.ILRange.End)); + return new Interval(newRange.Start, Math.Max(newRange.End, oldRange.End)); } - } else if (newRange.Start <= this.ILRange.End) { + } else if (newRange.Start <= oldRange.End) { // join overlapping ranges - this.ILRange = new Interval(this.StartILOffset, Math.Max(newRange.End, this.ILRange.End)); + return new Interval(oldRange.Start, Math.Max(newRange.End, oldRange.End)); } + return oldRange; } public void AddILRange(ILInstruction sourceInstruction) diff --git a/ICSharpCode.Decompiler/IL/Instructions/TryInstruction.cs b/ICSharpCode.Decompiler/IL/Instructions/TryInstruction.cs index fe7753b2c..4b519af43 100644 --- a/ICSharpCode.Decompiler/IL/Instructions/TryInstruction.cs +++ b/ICSharpCode.Decompiler/IL/Instructions/TryInstruction.cs @@ -19,6 +19,7 @@ using System; using System.Diagnostics; using System.Linq; +using ICSharpCode.Decompiler.Util; namespace ICSharpCode.Decompiler.IL { @@ -175,6 +176,17 @@ namespace ICSharpCode.Decompiler.IL output.Write(' '); body.WriteTo(output, options); } + + /// + /// Gets the ILRange of the instructions at the start of the catch-block, + /// that take the exception object and store it in the exception variable slot. + /// + public Interval ExceptionSpecifierILRange { get; private set; } + + public void AddExceptionSpecifierILRange(Interval newRange) + { + ExceptionSpecifierILRange = CombineILRange(ExceptionSpecifierILRange, newRange); + } } partial class TryFinally