Browse Source

do some cleanup in code

pull/191/merge
Eusebiu Marcu 15 years ago
parent
commit
7a087cd459
  1. 2
      ICSharpCode.Decompiler/Ast/TextOutputFormatter.cs
  2. 39
      ICSharpCode.Decompiler/CodeMappings.cs

2
ICSharpCode.Decompiler/Ast/TextOutputFormatter.cs

@ -132,10 +132,10 @@ namespace ICSharpCode.Decompiler.Ast
var n = node.Ancestors.FirstOrDefault(a => a.Annotation<MemberMapping>() != null); var n = node.Ancestors.FirstOrDefault(a => a.Annotation<MemberMapping>() != null);
if (n != default(AstType)) { if (n != default(AstType)) {
MemberMapping mapping = n.Annotation<MemberMapping>(); MemberMapping mapping = n.Annotation<MemberMapping>();
var map = mapping.MemberCodeMappings.Find(s => s.SourceCodeLine == output.CurrentLine);
foreach (var range in ranges) { foreach (var range in ranges) {
// make sure we have one ILRange per source code line // make sure we have one ILRange per source code line
var map = mapping.MemberCodeMappings.Find(s => s.SourceCodeLine == output.CurrentLine);
if (map == null) { if (map == null) {
mapping.MemberCodeMappings.Add(new SourceCodeMapping { mapping.MemberCodeMappings.Add(new SourceCodeMapping {
ILInstructionOffset = range, ILInstructionOffset = range,

39
ICSharpCode.Decompiler/CodeMappings.cs

@ -49,16 +49,13 @@ namespace ICSharpCode.Decompiler
resultList.Add(ILInstructionOffset.From); resultList.Add(ILInstructionOffset.From);
resultList.Add(ILInstructionOffset.To); resultList.Add(ILInstructionOffset.To);
// add the next gap if exists
var map = MemberMapping.MemberCodeMappings.Find(m => m.ILInstructionOffset.From >= ILInstructionOffset.To); var map = MemberMapping.MemberCodeMappings.Find(m => m.ILInstructionOffset.From >= ILInstructionOffset.To);
if (map != null && map.ILInstructionOffset.From != ILInstructionOffset.To) { if (map != null && map.ILInstructionOffset.From != ILInstructionOffset.To) {
resultList.Add(ILInstructionOffset.To); resultList.Add(ILInstructionOffset.To);
resultList.Add(map.ILInstructionOffset.From); resultList.Add(map.ILInstructionOffset.From);
} }
// var tempList = MemberMapping.GetAllUnknownMappings(ILInstructionOffset.To);
// if (tempList.Count != 0)
// resultList.AddRange(tempList);
return resultList.ToArray(); return resultList.ToArray();
} }
} }
@ -82,40 +79,6 @@ namespace ICSharpCode.Decompiler
/// Gets or sets the source code mappings. /// Gets or sets the source code mappings.
/// </summary> /// </summary>
public List<SourceCodeMapping> MemberCodeMappings { get; set; } public List<SourceCodeMapping> MemberCodeMappings { get; set; }
/// <summary>
/// Gets the list of all unknown/gaps code mappings greater than a value.<br/>
/// Eg.: for (0-9, 11-14, 16-27) the return list is (9,11,14,16) for start value 0 (or lower than 9).
/// </summary>
/// <param name="startValue">Start value.</param>
/// <returns></returns>
public List<int> GetAllUnknownMappings(int startValue)
{
var result = new List<int>();
var data = MemberCodeMappings.OrderBy(m => m.ILInstructionOffset.From);
var prevMap = data.ElementAt(0);
for (int i = 1; i < data.Count(); ++i) {
var map = data.ElementAt(i);
// consider only the next mappings
if (map.ILInstructionOffset.To <= startValue) {
prevMap = map;
continue;
}
// if there is not gap, move on
if (prevMap.ILInstructionOffset.To == map.ILInstructionOffset.From) {
prevMap = map;
continue;
}
result.Add(prevMap.ILInstructionOffset.To);
result.Add(map.ILInstructionOffset.From);
prevMap = map;
}
return result;
}
} }
public static class CodeMappings public static class CodeMappings

Loading…
Cancel
Save