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

4
ICSharpCode.Decompiler/Disassembler/MethodBodyDisassembler.cs

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

9
ICSharpCode.Decompiler/ITextOutput.cs

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

21
ICSharpCode.Decompiler/PlainTextOutput.cs

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

Loading…
Cancel
Save