From b394749f470959a416d33b662cb6bf0bf25f3954 Mon Sep 17 00:00:00 2001 From: Eusebiu Marcu Date: Fri, 22 Jul 2011 23:20:40 +0200 Subject: [PATCH] create a new TextOutputLocation class for storing the location in the output text instead of Tuple --- .../Ast/TextOutputFormatter.cs | 8 +++---- .../Disassembler/MethodBodyDisassembler.cs | 4 ++-- ICSharpCode.Decompiler/ITextOutput.cs | 9 ++++++-- ICSharpCode.Decompiler/PlainTextOutput.cs | 21 +++++++------------ 4 files changed, 21 insertions(+), 21 deletions(-) diff --git a/ICSharpCode.Decompiler/Ast/TextOutputFormatter.cs b/ICSharpCode.Decompiler/Ast/TextOutputFormatter.cs index 98a5db66e..ec83e695c 100644 --- a/ICSharpCode.Decompiler/Ast/TextOutputFormatter.cs +++ b/ICSharpCode.Decompiler/Ast/TextOutputFormatter.cs @@ -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 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); diff --git a/ICSharpCode.Decompiler/Disassembler/MethodBodyDisassembler.cs b/ICSharpCode.Decompiler/Disassembler/MethodBodyDisassembler.cs index 2fcde2335..0872cba16 100644 --- a/ICSharpCode.Decompiler/Disassembler/MethodBodyDisassembler.cs +++ b/ICSharpCode.Decompiler/Disassembler/MethodBodyDisassembler.cs @@ -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 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 }); diff --git a/ICSharpCode.Decompiler/ITextOutput.cs b/ICSharpCode.Decompiler/ITextOutput.cs index 608a45c64..cfbd5751a 100644 --- a/ICSharpCode.Decompiler/ITextOutput.cs +++ b/ICSharpCode.Decompiler/ITextOutput.cs @@ -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 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) diff --git a/ICSharpCode.Decompiler/PlainTextOutput.cs b/ICSharpCode.Decompiler/PlainTextOutput.cs index 86a28a5c8..d8b001167 100644 --- a/ICSharpCode.Decompiler/PlainTextOutput.cs +++ b/ICSharpCode.Decompiler/PlainTextOutput.cs @@ -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 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 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 { 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)