Browse Source

Improve IL mapping:

- Use the widest sequence point containing the IL offset
 - Ignore the newline which was printed at the end of the statement
pull/32/merge
David Srbecký 13 years ago
parent
commit
87e8f5a54c
  1. 13
      src/AddIns/DisplayBindings/ILSpyAddIn/ILSpySymbolSource.cs
  2. 7
      src/Libraries/ICSharpCode.Decompiler/Ast/TextOutputFormatter.cs

13
src/AddIns/DisplayBindings/ILSpyAddIn/ILSpySymbolSource.cs

@ -31,11 +31,18 @@ namespace ICSharpCode.ILSpyAddIn @@ -31,11 +31,18 @@ namespace ICSharpCode.ILSpyAddIn
return null;
var content = DecompiledViewContent.Get(method);
var seq = symbols.SequencePoints.FirstOrDefault(p => p.ILRanges.Any(r => r.From <= iloffset && iloffset < r.To));
var seqs = symbols.SequencePoints;
var seq = seqs.FirstOrDefault(p => p.ILRanges.Any(r => r.From <= iloffset && iloffset < r.To));
if (seq == null)
seq = symbols.SequencePoints.FirstOrDefault(p => iloffset <= p.ILOffset);
if (seq != null)
seq = seqs.FirstOrDefault(p => iloffset <= p.ILOffset);
if (seq != null) {
// Use the widest sequence point containing the IL offset
iloffset = seq.ILOffset;
seq = seqs.Where(p => p.ILRanges.Any(r => r.From <= iloffset && iloffset < r.To))
.OrderByDescending(p => p.ILRanges.Last().To - p.ILRanges.First().From)
.FirstOrDefault();
return seq.ToDebugger(symbols, content.VirtualFileName);
}
return null;
}

7
src/Libraries/ICSharpCode.Decompiler/Ast/TextOutputFormatter.cs

@ -36,6 +36,8 @@ namespace ICSharpCode.Decompiler.Ast @@ -36,6 +36,8 @@ namespace ICSharpCode.Decompiler.Ast
bool firstUsingDeclaration;
bool lastUsingDeclaration;
TextLocation? lastEndOfLine;
public bool FoldBraces = false;
public TextOutputFormatter(ITextOutput output)
@ -217,6 +219,7 @@ namespace ICSharpCode.Decompiler.Ast @@ -217,6 +219,7 @@ namespace ICSharpCode.Decompiler.Ast
output.MarkFoldEnd();
lastUsingDeclaration = false;
}
lastEndOfLine = output.Location;
output.WriteLine();
}
@ -305,11 +308,13 @@ namespace ICSharpCode.Decompiler.Ast @@ -305,11 +308,13 @@ namespace ICSharpCode.Decompiler.Ast
// code mappings
var ranges = node.Annotation<List<ILRange>>();
if (symbolsStack.Count > 0 && ranges != null && ranges.Count > 0) {
// Ignore the newline which was printed at the end of the statement
TextLocation endLocation = (node is Statement) ? (lastEndOfLine ?? output.Location) : output.Location;
symbolsStack.Peek().SequencePoints.Add(
new SequencePoint() {
ILRanges = ILRange.OrderAndJoin(ranges).ToArray(),
StartLocation = startLocation,
EndLocation = output.Location
EndLocation = endLocation
});
}

Loading…
Cancel
Save