From 9ea1821cb3d95dea60b1771c82125f7a1618a8e3 Mon Sep 17 00:00:00 2001 From: Rokas Kupstys Date: Sun, 10 Dec 2017 15:22:20 +0200 Subject: [PATCH] Fix debug output not being generated when AST element had no comment. Also debug text cleaning moved to CodeGenerator.cs and is done when printing bindings. New lines are not stripped out, instead each line is prepended with "// DEBUG: ". Now debug info is properly formatted, easy to read and full. --- src/Generator/Generators/CodeGenerator.cs | 14 +++++--------- src/Generator/Passes/CleanInvalidDeclNamesPass.cs | 1 - src/Generator/Utils/Utils.cs | 14 -------------- 3 files changed, 5 insertions(+), 24 deletions(-) diff --git a/src/Generator/Generators/CodeGenerator.cs b/src/Generator/Generators/CodeGenerator.cs index d102055f..61d5cd17 100644 --- a/src/Generator/Generators/CodeGenerator.cs +++ b/src/Generator/Generators/CodeGenerator.cs @@ -83,22 +83,18 @@ namespace CppSharp.Generators public virtual void GenerateDeclarationCommon(Declaration decl) { if (decl.Comment != null) - { GenerateComment(decl.Comment); - GenerateDebug(decl); - } + + GenerateDebug(decl); } public virtual void GenerateDebug(Declaration decl) { if (Options.GenerateDebugOutput && !string.IsNullOrWhiteSpace(decl.DebugText)) { - char[] newLineChars = {'\r', '\n'}; - var text = decl.DebugText; - var index = text.IndexOfAny(newLineChars); - if (index >= 0) - text = text.Substring(0, index); - WriteLine("// DEBUG: " + text); + var debugText = decl.DebugText; + debugText = Regex.Replace(debugText.Trim(), "\r?\n", "\n// DEBUG: "); + WriteLine($"// DEBUG: {debugText}"); } } diff --git a/src/Generator/Passes/CleanInvalidDeclNamesPass.cs b/src/Generator/Passes/CleanInvalidDeclNamesPass.cs index 52462e7f..9851e3c3 100644 --- a/src/Generator/Passes/CleanInvalidDeclNamesPass.cs +++ b/src/Generator/Passes/CleanInvalidDeclNamesPass.cs @@ -53,7 +53,6 @@ namespace CppSharp.Passes (method == null || method.Kind == CXXMethodKind.Normal)) decl.Name = CheckName(decl.Name); - StringHelpers.CleanupText(ref decl.DebugText); return true; } diff --git a/src/Generator/Utils/Utils.cs b/src/Generator/Utils/Utils.cs index c555e2d9..b8f8ed17 100644 --- a/src/Generator/Utils/Utils.cs +++ b/src/Generator/Utils/Utils.cs @@ -43,20 +43,6 @@ namespace CppSharp return ss[0]; // all strings identical } - public static void CleanupText(ref string debugText) - { - // Strip off newlines from the debug text. - if (string.IsNullOrWhiteSpace(debugText)) - { - debugText = string.Empty; - return; - } - - // TODO: Make this transformation in the output. - debugText = Regex.Replace(debugText, " {2,}", " "); - debugText = debugText.Replace("\n", ""); - } - public static string[] SplitCamelCase(string input) { var str = Regex.Replace(input, "([A-Z])", " $1", RegexOptions.Compiled);