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
return null; return null;
var content = DecompiledViewContent.Get(method); 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) if (seq == null)
seq = symbols.SequencePoints.FirstOrDefault(p => iloffset <= p.ILOffset); seq = seqs.FirstOrDefault(p => iloffset <= p.ILOffset);
if (seq != null) 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 seq.ToDebugger(symbols, content.VirtualFileName);
}
return null; return null;
} }

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

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

Loading…
Cancel
Save