Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.bin/indent indent: add debug output for tracking comment...



details:   https://anonhg.NetBSD.org/src/rev/6a1e38b6c85d
branches:  trunk
changeset: 374763:6a1e38b6c85d
user:      rillig <rillig%NetBSD.org@localhost>
date:      Thu May 11 17:22:56 2023 +0000

description:
indent: add debug output for tracking comments and braces

diffstat:

 tests/usr.bin/indent/opt_bl_br.c |  109 ++++++++++++++++++++++++++++++++++++--
 usr.bin/indent/indent.h          |    4 +-
 usr.bin/indent/io.c              |   12 +++-
 3 files changed, 114 insertions(+), 11 deletions(-)

diffs (214 lines):

diff -r 2d53ad572a83 -r 6a1e38b6c85d tests/usr.bin/indent/opt_bl_br.c
--- a/tests/usr.bin/indent/opt_bl_br.c  Thu May 11 16:18:31 2023 +0000
+++ b/tests/usr.bin/indent/opt_bl_br.c  Thu May 11 17:22:56 2023 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: opt_bl_br.c,v 1.7 2023/05/11 09:28:53 rillig Exp $ */
+/* $NetBSD: opt_bl_br.c,v 1.8 2023/05/11 17:22:56 rillig Exp $ */
 
 //indent input
 void
@@ -44,7 +44,7 @@ standard_style(int n)
  */
 //indent input
 void
-example(int n)
+condensed_style(int n)
 {
        if (n > 99) { print("large"); }
        else if (n > 9) { print("double-digit"); }
@@ -55,7 +55,7 @@ example(int n)
 
 //indent run -bl
 void
-example(int n)
+condensed_style(int n)
 {
        if (n > 99)
        {
@@ -76,7 +76,7 @@ example(int n)
 
 //indent run -br
 void
-example(int n)
+condensed_style(int n)
 {
        if (n > 99) {
                print("large");
@@ -98,7 +98,8 @@ example(int n)
  * line.
  */
 //indent input
-void function(void)
+void
+eol_comment(void)
 {
        if (expr) // C99 comment
                stmt();
@@ -110,9 +111,9 @@ void function(void)
 }
 //indent end
 
-//indent run
+//indent run -br
 void
-function(void)
+eol_comment(void)
 {
        if (expr)               // C99 comment
                stmt();
@@ -124,6 +125,8 @@ function(void)
 }
 //indent end
 
+//indent run-equals-prev-output -bl
+
 
 /*
  * Test multiple mixed comments after 'if (expr)'.
@@ -173,3 +176,95 @@ function(void)
 
 /* TODO: Remove the newline between ')' and '{'. */
 //indent run-equals-input -br
+
+
+//indent input
+void
+comments(void)
+{
+       if(cond){}
+
+       if (cond)
+       {}
+
+       if (cond) /* comment */
+       {}
+
+       if (cond)
+       /* comment */
+       {}
+
+       if (cond)
+       // comment1
+       // comment2
+       {}
+
+       if (cond) // comment
+       {}
+}
+//indent end
+
+//indent run -bl
+void
+comments(void)
+{
+       if (cond)
+       {
+       }
+
+       if (cond)
+       {
+       }
+
+       if (cond)               /* comment */
+       {
+       }
+
+       if (cond)
+               /* comment */
+       {
+       }
+
+       if (cond)
+               // comment1
+               // comment2
+       {
+       }
+
+       if (cond)               // comment
+       {
+       }
+}
+//indent end
+
+//indent run -br
+void
+comments(void)
+{
+       if (cond) {
+       }
+
+       if (cond)
+       {
+       }
+
+       if (cond)               /* comment */
+       {
+       }
+
+       if (cond)
+               /* comment */
+       {
+       }
+
+       if (cond)
+               // comment1
+               // comment2
+       {
+       }
+
+       if (cond)               // comment
+       {
+       }
+}
+//indent end
diff -r 2d53ad572a83 -r 6a1e38b6c85d usr.bin/indent/indent.h
--- a/usr.bin/indent/indent.h   Thu May 11 16:18:31 2023 +0000
+++ b/usr.bin/indent/indent.h   Thu May 11 17:22:56 2023 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: indent.h,v 1.115 2023/05/11 11:25:47 rillig Exp $      */
+/*     $NetBSD: indent.h,v 1.116 2023/05/11 17:22:56 rillig Exp $      */
 
 /*-
  * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
@@ -279,7 +279,7 @@ extern struct parser_state {
 
     bool force_nl;             /* when true, the following token goes to the
                                 * next line, unless it is a '{' and
-                                * opt.brace_right is set. */
+                                * opt.brace_same_line is set. */
 
     int line_start_nparen;     /* the number of parentheses or brackets that
                                 * were already open at the beginning of the
diff -r 2d53ad572a83 -r 6a1e38b6c85d usr.bin/indent/io.c
--- a/usr.bin/indent/io.c       Thu May 11 16:18:31 2023 +0000
+++ b/usr.bin/indent/io.c       Thu May 11 17:22:56 2023 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: io.c,v 1.148 2022/04/23 06:43:22 rillig Exp $  */
+/*     $NetBSD: io.c,v 1.149 2023/05/11 17:22:56 rillig Exp $  */
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -43,7 +43,7 @@ static char sccsid[] = "@(#)io.c      8.1 (Be
 
 #include <sys/cdefs.h>
 #if defined(__NetBSD__)
-__RCSID("$NetBSD: io.c,v 1.148 2022/04/23 06:43:22 rillig Exp $");
+__RCSID("$NetBSD: io.c,v 1.149 2023/05/11 17:22:56 rillig Exp $");
 #elif defined(__FreeBSD__)
 __FBSDID("$FreeBSD: head/usr.bin/indent/io.c 334927 2018-06-10 16:44:18Z pstef $");
 #endif
@@ -514,6 +514,14 @@ output_complete_line(char line_terminato
 
     ps.is_function_definition = false;
 
+    debug_println("%s: %d %s%s%s%s",
+       __func__,
+       out.blank_lines_to_output,
+       out.blank_lines_to_output == 1 ? "line" : "lines",
+       out.blank_line_before ? ", before" : "",
+       out.blank_line_after ? ", after" : "",
+       out.suppress_blanklines ? ", suppress" : "");
+
     if (code.s == code.e && lab.s == lab.e && com.s == com.e) {
        if (out.suppress_blanklines)
            out.suppress_blanklines = false;



Home | Main Index | Thread Index | Old Index