Browse Source

Use new ILRange methods

pull/191/merge
Eusebiu Marcu 15 years ago
parent
commit
64d92bf919
  1. 2
      ICSharpCode.Decompiler/Ast/AstMethodBodyBuilder.cs
  2. 2
      ICSharpCode.Decompiler/Ast/TextOutputFormatter.cs
  3. 29
      ICSharpCode.Decompiler/CodeMappings.cs

2
ICSharpCode.Decompiler/Ast/AstMethodBodyBuilder.cs

@ -177,7 +177,7 @@ namespace ICSharpCode.Decompiler.Ast
Expression astExpr = node as Expression; Expression astExpr = node as Expression;
// get IL ranges - used in debugger // get IL ranges - used in debugger
List<ILRange> ilRanges = expr.GetILRanges(); List<ILRange> ilRanges = ILRange.OrderAndJoint(expr.GetSelfAndChildrenRecursive<ILExpression>().SelectMany(e => e.ILRanges));
AstNode result; AstNode result;
if (astExpr != null) if (astExpr != null)

2
ICSharpCode.Decompiler/Ast/TextOutputFormatter.cs

@ -134,8 +134,8 @@ namespace ICSharpCode.Decompiler.Ast
MemberMapping mapping = n.Annotation<MemberMapping>(); MemberMapping mapping = n.Annotation<MemberMapping>();
foreach (var range in ranges) { foreach (var range in ranges) {
// make sure we have one ILRange per source code line
var map = mapping.MemberCodeMappings.Find(s => s.SourceCodeLine == output.CurrentLine); var map = mapping.MemberCodeMappings.Find(s => s.SourceCodeLine == output.CurrentLine);
if (map == null) { if (map == null) {
// check if the range is in previous mapping // check if the range is in previous mapping
var prevmap = mapping.MemberCodeMappings.Find(m => m.ILInstructionOffset.From <= range.From && var prevmap = mapping.MemberCodeMappings.Find(m => m.ILInstructionOffset.From <= range.From &&

29
ICSharpCode.Decompiler/CodeMappings.cs

@ -49,11 +49,20 @@ 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 list = MemberMapping.MemberCodeMappings.ConvertAll<ILRange>(s => new ILRange { From = s.ILInstructionOffset.From, To = s.ILInstructionOffset.To });
var map = MemberMapping.MemberCodeMappings.Find(m => m.ILInstructionOffset.From >= ILInstructionOffset.To);
if (map != null && map.ILInstructionOffset.From != ILInstructionOffset.To) { var invertedList = ILRange.Invert(list, MemberMapping.CodeSize);
resultList.Add(ILInstructionOffset.To); if (invertedList != null && invertedList.Count() > 0) {
resultList.Add(map.ILInstructionOffset.From); foreach (var range in invertedList) {
resultList.Add(range.From);
resultList.Add(range.To);
}
}
// remove last gap - step on the last line
if (resultList[resultList.Count - 1] == MemberMapping.CodeSize) {
resultList.RemoveAt(resultList.Count - 1);
resultList.RemoveAt(resultList.Count - 1);
} }
return resultList.ToArray(); return resultList.ToArray();
@ -75,6 +84,11 @@ namespace ICSharpCode.Decompiler
/// </summary> /// </summary>
public uint MetadataToken { get; set; } public uint MetadataToken { get; set; }
/// <summary>
/// Gets or sets the code size for the member mapping.
/// </summary>
public int CodeSize { get; set; }
/// <summary> /// <summary>
/// Gets or sets the source code mappings. /// Gets or sets the source code mappings.
/// </summary> /// </summary>
@ -107,7 +121,7 @@ namespace ICSharpCode.Decompiler
/// <param name="method">Method to create the mapping for.</param> /// <param name="method">Method to create the mapping for.</param>
/// <param name="sourceCodeMappings">Source code mapping storage.</param> /// <param name="sourceCodeMappings">Source code mapping storage.</param>
public static MemberMapping CreateCodeMapping( public static MemberMapping CreateCodeMapping(
this MemberReference member, this MethodDefinition member,
ConcurrentDictionary<string, List<MemberMapping>> codeMappings) ConcurrentDictionary<string, List<MemberMapping>> codeMappings)
{ {
// create IL/CSharp code mappings - used in debugger // create IL/CSharp code mappings - used in debugger
@ -118,7 +132,8 @@ namespace ICSharpCode.Decompiler
currentMemberMapping = new MemberMapping() { currentMemberMapping = new MemberMapping() {
MetadataToken = (uint)member.MetadataToken.ToInt32(), MetadataToken = (uint)member.MetadataToken.ToInt32(),
Type = member.DeclaringType.Resolve(), Type = member.DeclaringType.Resolve(),
MemberCodeMappings = new List<SourceCodeMapping>() MemberCodeMappings = new List<SourceCodeMapping>(),
CodeSize = member.Body.CodeSize
}; };
mapping.Add(currentMemberMapping); mapping.Add(currentMemberMapping);
} }

Loading…
Cancel
Save