Skip to content

Commit 9ea1821

Browse files
committed
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.
1 parent 5a190bf commit 9ea1821

File tree

3 files changed

+5
-24
lines changed

3 files changed

+5
-24
lines changed

src/Generator/Generators/CodeGenerator.cs

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -83,22 +83,18 @@ public virtual void GenerateFilePreamble(CommentKind kind, string generatorName
8383
public virtual void GenerateDeclarationCommon(Declaration decl)
8484
{
8585
if (decl.Comment != null)
86-
{
8786
GenerateComment(decl.Comment);
88-
GenerateDebug(decl);
89-
}
87+
88+
GenerateDebug(decl);
9089
}
9190

9291
public virtual void GenerateDebug(Declaration decl)
9392
{
9493
if (Options.GenerateDebugOutput && !string.IsNullOrWhiteSpace(decl.DebugText))
9594
{
96-
char[] newLineChars = {'\r', '\n'};
97-
var text = decl.DebugText;
98-
var index = text.IndexOfAny(newLineChars);
99-
if (index >= 0)
100-
text = text.Substring(0, index);
101-
WriteLine("// DEBUG: " + text);
95+
var debugText = decl.DebugText;
96+
debugText = Regex.Replace(debugText.Trim(), "\r?\n", "\n// DEBUG: ");
97+
WriteLine($"// DEBUG: {debugText}");
10298
}
10399
}
104100

src/Generator/Passes/CleanInvalidDeclNamesPass.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ public override bool VisitDeclaration(Declaration decl)
5353
(method == null || method.Kind == CXXMethodKind.Normal))
5454
decl.Name = CheckName(decl.Name);
5555

56-
StringHelpers.CleanupText(ref decl.DebugText);
5756
return true;
5857
}
5958

src/Generator/Utils/Utils.cs

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -43,20 +43,6 @@ public static string CommonPrefix(this string[] ss)
4343
return ss[0]; // all strings identical
4444
}
4545

46-
public static void CleanupText(ref string debugText)
47-
{
48-
// Strip off newlines from the debug text.
49-
if (string.IsNullOrWhiteSpace(debugText))
50-
{
51-
debugText = string.Empty;
52-
return;
53-
}
54-
55-
// TODO: Make this transformation in the output.
56-
debugText = Regex.Replace(debugText, " {2,}", " ");
57-
debugText = debugText.Replace("\n", "");
58-
}
59-
6046
public static string[] SplitCamelCase(string input)
6147
{
6248
var str = Regex.Replace(input, "([A-Z])", " $1", RegexOptions.Compiled);

0 commit comments

Comments
 (0)