Permalink
Browse files

create a new TextOutputLocation class for storing the location in the…

… output text instead of Tuple<int, int>
  • Loading branch information...
1 parent 87abf56 commit b394749f470959a416d33b662cb6bf0bf25f3954 @eusebiu eusebiu committed Jul 22, 2011
@@ -163,7 +163,7 @@ public void StartNode(AstNode node)
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 @@ public void StartNode(AstNode node)
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);
@@ -91,7 +91,7 @@ public void Disassemble(MethodBody body, MemberMapping methodMapping)
// 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 @@ void WriteStructureBody(ILStructure s, HashSet<int> branchTargets, ref Instructi
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
});
@@ -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 @@ public interface ITextOutput
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)
@@ -28,8 +28,7 @@ public sealed class PlainTextOutput : ITextOutput
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 @@ public PlainTextOutput()
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 @@ void WriteIndent()
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 @@ public void Write(char ch)
{
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)

0 comments on commit b394749

Please sign in to comment.