Browse Source

create a new TextOutputLocation class for storing the location in the output text instead of Tuple<int, int>

pull/258/head
Eusebiu Marcu 14 years ago
parent
commit
b394749f47
  1. 8
      ICSharpCode.Decompiler/Ast/TextOutputFormatter.cs
  2. 4
      ICSharpCode.Decompiler/Disassembler/MethodBodyDisassembler.cs
  3. 9
      ICSharpCode.Decompiler/ITextOutput.cs
  4. 21
      ICSharpCode.Decompiler/PlainTextOutput.cs

8
ICSharpCode.Decompiler/Ast/TextOutputFormatter.cs

@ -163,7 +163,7 @@ namespace ICSharpCode.Decompiler.Ast
foreach (var range in ranges) { foreach (var range in ranges) {
mapping.MemberCodeMappings.Add(new SourceCodeMapping { mapping.MemberCodeMappings.Add(new SourceCodeMapping {
ILInstructionOffset = range, ILInstructionOffset = range,
SourceCodeLine = output.CurrentLine, SourceCodeLine = output.Location.Line,
MemberMapping = mapping MemberMapping = mapping
}); });
} }
@ -176,10 +176,10 @@ namespace ICSharpCode.Decompiler.Ast
if (predicate(node)) { if (predicate(node)) {
var n = node as AttributedNode; var n = node as AttributedNode;
int c = 0; int attributesCount = 0;
if (n != null) if (n != null)
c = n.Attributes.Count; attributesCount = n.Attributes.Count;
node.AddAnnotation(Tuple.Create(output.CurrentLine + c, output.CurrentColumn)); node.AddAnnotation(new TextOutputLocation { Line = output.Location.Line + attributesCount, Column = output.Location.Column});
} }
nodeStack.Push(node); nodeStack.Push(node);

4
ICSharpCode.Decompiler/Disassembler/MethodBodyDisassembler.cs

@ -91,7 +91,7 @@ namespace ICSharpCode.Decompiler.Disassembler
// add IL code mappings - used in debugger // add IL code mappings - used in debugger
methodMapping.MemberCodeMappings.Add( methodMapping.MemberCodeMappings.Add(
new SourceCodeMapping() { new SourceCodeMapping() {
SourceCodeLine = output.CurrentLine, SourceCodeLine = output.Location.Line,
ILInstructionOffset = new ILRange { From = inst.Offset, To = inst.Next == null ? method.Body.CodeSize : inst.Next.Offset }, ILInstructionOffset = new ILRange { From = inst.Offset, To = inst.Next == null ? method.Body.CodeSize : inst.Next.Offset },
MemberMapping = methodMapping MemberMapping = methodMapping
}); });
@ -194,7 +194,7 @@ namespace ICSharpCode.Decompiler.Disassembler
if (currentMethodMapping != null) { if (currentMethodMapping != null) {
currentMethodMapping.MemberCodeMappings.Add( currentMethodMapping.MemberCodeMappings.Add(
new SourceCodeMapping() { new SourceCodeMapping() {
SourceCodeLine = output.CurrentLine, SourceCodeLine = output.Location.Line,
ILInstructionOffset = new ILRange { From = inst.Offset, To = inst.Next == null ? codeSize : inst.Next.Offset }, ILInstructionOffset = new ILRange { From = inst.Offset, To = inst.Next == null ? codeSize : inst.Next.Offset },
MemberMapping = currentMethodMapping MemberMapping = currentMethodMapping
}); });

9
ICSharpCode.Decompiler/ITextOutput.cs

@ -23,8 +23,7 @@ namespace ICSharpCode.Decompiler
{ {
public interface ITextOutput public interface ITextOutput
{ {
int CurrentLine { get; } TextOutputLocation Location { get; }
int CurrentColumn { get; }
void Indent(); void Indent();
void Unindent(); void Unindent();
@ -38,6 +37,12 @@ namespace ICSharpCode.Decompiler
void MarkFoldEnd(); void MarkFoldEnd();
} }
public sealed class TextOutputLocation
{
public int Line { get; set; }
public int Column { get; set; }
}
public static class TextOutputExtensions public static class TextOutputExtensions
{ {
public static void Write(this ITextOutput output, string format, params object[] args) public static void Write(this ITextOutput output, string format, params object[] args)

21
ICSharpCode.Decompiler/PlainTextOutput.cs

@ -28,8 +28,7 @@ namespace ICSharpCode.Decompiler
readonly TextWriter writer; readonly TextWriter writer;
int indent; int indent;
bool needsIndent; bool needsIndent;
int lineNumber = 1; TextOutputLocation location = new TextOutputLocation { Line = 1, Column = 1};
int columnNumber = 1;
public PlainTextOutput(TextWriter writer) public PlainTextOutput(TextWriter writer)
{ {
@ -43,12 +42,8 @@ namespace ICSharpCode.Decompiler
this.writer = new StringWriter(); this.writer = new StringWriter();
} }
public int CurrentLine { public TextOutputLocation Location {
get { return lineNumber; } get { return location; }
}
public int CurrentColumn {
get { return columnNumber; }
} }
public override string ToString() public override string ToString()
@ -72,7 +67,7 @@ namespace ICSharpCode.Decompiler
needsIndent = false; needsIndent = false;
for (int i = 0; i < indent; i++) { for (int i = 0; i < indent; i++) {
writer.Write('\t'); writer.Write('\t');
columnNumber += TAB_SIZE - 1; location.Column += TAB_SIZE - 1;
} }
} }
} }
@ -81,22 +76,22 @@ namespace ICSharpCode.Decompiler
{ {
WriteIndent(); WriteIndent();
writer.Write(ch); writer.Write(ch);
columnNumber++; location.Column++;
} }
public void Write(string text) public void Write(string text)
{ {
WriteIndent(); WriteIndent();
writer.Write(text); writer.Write(text);
columnNumber += text.Length; location.Column += text.Length;
} }
public void WriteLine() public void WriteLine()
{ {
lineNumber++; location.Line++;
writer.WriteLine(); writer.WriteLine();
needsIndent = true; needsIndent = true;
columnNumber = TAB_SIZE * indent; location.Column = TAB_SIZE * indent;
} }
public void WriteDefinition(string text, object definition) public void WriteDefinition(string text, object definition)

Loading…
Cancel
Save