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 @@
using System; using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
namespace CppSharp namespace CppSharp
{ {
@ -41,6 +44,8 @@ namespace CppSharp
public interface IDiagnosticConsumer public interface IDiagnosticConsumer
{ {
void Emit(DiagnosticInfo info); void Emit(DiagnosticInfo info);
void PushIndent(int level);
void PopIndent();
} }
public static class DiagnosticExtensions public static class DiagnosticExtensions
@ -139,14 +144,33 @@ namespace CppSharp
public class TextDiagnosticPrinter : IDiagnosticConsumer public class TextDiagnosticPrinter : IDiagnosticConsumer
{ {
public bool Verbose; public bool Verbose;
public Stack<int> Indents;
public TextDiagnosticPrinter()
{
Indents = new Stack<int>();
}
public void Emit(DiagnosticInfo info) public void Emit(DiagnosticInfo info)
{ {
if (info.Kind == DiagnosticKind.Debug && !Verbose) if (info.Kind == DiagnosticKind.Debug && !Verbose)
return; return;
Console.WriteLine(info.Message); var currentIndent = Indents.Sum();
System.Diagnostics.Debug.WriteLine(info.Message); 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
TranslationUnitPasses.RunPasses(pass => TranslationUnitPasses.RunPasses(pass =>
{ {
Diagnostics.Debug("Pass '{0}'", pass); Diagnostics.Debug("Pass '{0}'", pass);
Diagnostics.PushIndent(4);
pass.VisitLibrary(ASTContext); pass.VisitLibrary(ASTContext);
Diagnostics.PopIndent();
}); });
Generator.Process(); Generator.Process();
} }

Loading…
Cancel
Save