From da2c6b0602faf3889f67c84de52d1c9a3592f3f6 Mon Sep 17 00:00:00 2001 From: triton Date: Tue, 24 Dec 2013 16:48:51 +0000 Subject: [PATCH] Added indentation support to the logging. --- src/Core/Diagnostics.cs | 28 ++++++++++++++++++++++++++-- src/Generator/Driver.cs | 3 +++ 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/src/Core/Diagnostics.cs b/src/Core/Diagnostics.cs index 1eb83488..9c92a7a5 100644 --- a/src/Core/Diagnostics.cs +++ b/src/Core/Diagnostics.cs @@ -1,4 +1,7 @@ using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Linq; 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 public class TextDiagnosticPrinter : IDiagnosticConsumer { public bool Verbose; + public Stack Indents; + + public TextDiagnosticPrinter() + { + Indents = new Stack(); + } 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(); } } } diff --git a/src/Generator/Driver.cs b/src/Generator/Driver.cs index f064aab8..8cae5e98 100644 --- a/src/Generator/Driver.cs +++ b/src/Generator/Driver.cs @@ -236,7 +236,10 @@ namespace CppSharp TranslationUnitPasses.RunPasses(pass => { Diagnostics.Debug("Pass '{0}'", pass); + + Diagnostics.PushIndent(4); pass.VisitLibrary(ASTContext); + Diagnostics.PopIndent(); }); Generator.Process(); }