Browse Source

Added indentation support to the logging.

pull/144/merge
triton 12 years ago
parent
commit
da2c6b0602
  1. 28
      src/Core/Diagnostics.cs
  2. 3
      src/Generator/Driver.cs

28
src/Core/Diagnostics.cs

@ -1,4 +1,7 @@ @@ -1,4 +1,7 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
namespace CppSharp
{
@ -41,6 +44,8 @@ namespace CppSharp @@ -41,6 +44,8 @@ namespace CppSharp
public interface IDiagnosticConsumer
{
void Emit(DiagnosticInfo info);
void PushIndent(int level);
void PopIndent();
}
public static class DiagnosticExtensions
@ -139,14 +144,33 @@ namespace CppSharp @@ -139,14 +144,33 @@ namespace CppSharp
public class TextDiagnosticPrinter : IDiagnosticConsumer
{
public bool Verbose;
public Stack<int> Indents;
public TextDiagnosticPrinter()
{
Indents = new Stack<int>();
}
public void Emit(DiagnosticInfo info)
{
if (info.Kind == DiagnosticKind.Debug && !Verbose)
return;
Console.WriteLine(info.Message);
System.Diagnostics.Debug.WriteLine(info.Message);
var currentIndent = Indents.Sum();
var message = new string(' ', currentIndent) + info.Message;
Console.WriteLine(message);
Debug.WriteLine(message);
}
public void PushIndent(int level)
{
Indents.Push(level);
}
public void PopIndent()
{
Indents.Pop();
}
}
}

3
src/Generator/Driver.cs

@ -236,7 +236,10 @@ namespace CppSharp @@ -236,7 +236,10 @@ namespace CppSharp
TranslationUnitPasses.RunPasses(pass =>
{
Diagnostics.Debug("Pass '{0}'", pass);
Diagnostics.PushIndent(4);
pass.VisitLibrary(ASTContext);
Diagnostics.PopIndent();
});
Generator.Process();
}

Loading…
Cancel
Save