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: rename ps.dumped_decl_indent and inde...



details:   https://anonhg.NetBSD.org/src/rev/91f1d685e201
branches:  trunk
changeset: 990512:91f1d685e201
user:      rillig <rillig%NetBSD.org@localhost>
date:      Fri Oct 29 17:32:22 2021 +0000

description:
indent: rename ps.dumped_decl_indent and indent_declaration

The word 'dump' in 'ps.dumped_decl_indent' was too close to dump_line,
which led to confusion since the variable controls whether the
indentation has been added to the code buffer, which happens way before
actually dumping the current line to the output file.

The function name 'indent_declaration' was too unspecific, it did not
reveal where the indentation of the declaration actually happened.

No functional change.

diffstat:

 usr.bin/indent/indent.c |  39 +++++++++++++++++++--------------------
 usr.bin/indent/indent.h |   5 +++--
 usr.bin/indent/io.c     |   6 +++---
 3 files changed, 25 insertions(+), 25 deletions(-)

diffs (147 lines):

diff -r cb12edb9f68f -r 91f1d685e201 usr.bin/indent/indent.c
--- a/usr.bin/indent/indent.c   Fri Oct 29 17:29:45 2021 +0000
+++ b/usr.bin/indent/indent.c   Fri Oct 29 17:32:22 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: indent.c,v 1.169 2021/10/29 16:59:35 rillig Exp $      */
+/*     $NetBSD: indent.c,v 1.170 2021/10/29 17:32:22 rillig Exp $      */
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -43,7 +43,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__NetBSD__)
-__RCSID("$NetBSD: indent.c,v 1.169 2021/10/29 16:59:35 rillig Exp $");
+__RCSID("$NetBSD: indent.c,v 1.170 2021/10/29 17:32:22 rillig Exp $");
 #elif defined(__FreeBSD__)
 __FBSDID("$FreeBSD: head/usr.bin/indent/indent.c 340138 2018-11-04 19:24:49Z oshogbo $");
 #endif
@@ -604,7 +604,7 @@
 }
 
 static void
-indent_declaration(int cur_decl_ind, bool tabs_to_var)
+code_add_decl_indent(int cur_decl_ind, bool tabs_to_var)
 {
     int ind = (int)buf_len(&code);
     char *orig_code_e = code.e;
@@ -728,11 +728,11 @@
     }
 
     if (token.s[0] == '(' && ps.in_decl
-       && !ps.block_init && !ps.dumped_decl_indent &&
+       && !ps.block_init && !ps.decl_indent_done &&
        ps.procname[0] == '\0' && ps.paren_level == 0) {
        /* function pointer declarations */
-       indent_declaration(decl_ind, tabs_to_var);
-       ps.dumped_decl_indent = true;
+       code_add_decl_indent(decl_ind, tabs_to_var);
+       ps.decl_indent_done = true;
     } else if (want_blank_before_lparen())
        *code.e++ = ' ';
     ps.want_blank = false;
@@ -804,11 +804,11 @@
 static void
 process_unary_op(int decl_ind, bool tabs_to_var)
 {
-    if (!ps.dumped_decl_indent && ps.in_decl && !ps.block_init &&
+    if (!ps.decl_indent_done && ps.in_decl && !ps.block_init &&
        ps.procname[0] == '\0' && ps.paren_level == 0) {
        /* pointer declarations */
-       indent_declaration(decl_ind - (int)buf_len(&token), tabs_to_var);
-       ps.dumped_decl_indent = true;
+       code_add_decl_indent(decl_ind - (int)buf_len(&token), tabs_to_var);
+       ps.decl_indent_done = true;
     } else if (ps.want_blank)
        *code.e++ = ' ';
 
@@ -890,10 +890,10 @@
     ps.just_saw_decl--;
 
     if (ps.in_decl && code.s == code.e && !ps.block_init &&
-       !ps.dumped_decl_indent && ps.paren_level == 0) {
+       !ps.decl_indent_done && ps.paren_level == 0) {
        /* indent stray semicolons in declarations */
-       indent_declaration(decl_ind - 1, tabs_to_var);
-       ps.dumped_decl_indent = true;
+       code_add_decl_indent(decl_ind - 1, tabs_to_var);
+       ps.decl_indent_done = true;
     }
 
     ps.in_decl = ps.decl_nest > 0;     /* if we were in a first level
@@ -1122,11 +1122,10 @@
            }
            ps.want_blank = false;
 
-       } else if (!ps.block_init && !ps.dumped_decl_indent &&
-           ps.paren_level == 0) {      /* if we are in a declaration, we must
-                                        * indent identifier */
-           indent_declaration(decl_ind, tabs_to_var);
-           ps.dumped_decl_indent = true;
+       } else if (!ps.block_init && !ps.decl_indent_done &&
+           ps.paren_level == 0) {
+           code_add_decl_indent(decl_ind, tabs_to_var);
+           ps.decl_indent_done = true;
            ps.want_blank = false;
        }
 
@@ -1170,10 +1169,10 @@
                                         * does not start the line */
 
     if (ps.in_decl && ps.procname[0] == '\0' && !ps.block_init &&
-       !ps.dumped_decl_indent && ps.paren_level == 0) {
+       !ps.decl_indent_done && ps.paren_level == 0) {
        /* indent leading commas and not the actual identifiers */
-       indent_declaration(decl_ind - 1, tabs_to_var);
-       ps.dumped_decl_indent = true;
+       code_add_decl_indent(decl_ind - 1, tabs_to_var);
+       ps.decl_indent_done = true;
     }
 
     *code.e++ = ',';
diff -r cb12edb9f68f -r 91f1d685e201 usr.bin/indent/indent.h
--- a/usr.bin/indent/indent.h   Fri Oct 29 17:29:45 2021 +0000
+++ b/usr.bin/indent/indent.h   Fri Oct 29 17:32:22 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: indent.h,v 1.57 2021/10/29 16:59:35 rillig Exp $       */
+/*     $NetBSD: indent.h,v 1.58 2021/10/29 17:32:22 rillig Exp $       */
 
 /*-
  * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
@@ -335,7 +335,8 @@
                                 * ignored in some cases.) */
     enum keyword_kind prev_keyword;
     enum keyword_kind curr_keyword;
-    bool dumped_decl_indent;
+    bool decl_indent_done;     /* whether the indentation for a declaration
+                                * has been added to the code buffer. */
     bool in_parameter_declaration;
     char procname[100];                /* The name of the current procedure */
     int just_saw_decl;
diff -r cb12edb9f68f -r 91f1d685e201 usr.bin/indent/io.c
--- a/usr.bin/indent/io.c       Fri Oct 29 17:29:45 2021 +0000
+++ b/usr.bin/indent/io.c       Fri Oct 29 17:32:22 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: io.c,v 1.103 2021/10/27 00:04:51 rillig Exp $  */
+/*     $NetBSD: io.c,v 1.104 2021/10/29 17:32:22 rillig Exp $  */
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -43,7 +43,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__NetBSD__)
-__RCSID("$NetBSD: io.c,v 1.103 2021/10/27 00:04:51 rillig Exp $");
+__RCSID("$NetBSD: io.c,v 1.104 2021/10/29 17:32:22 rillig Exp $");
 #elif defined(__FreeBSD__)
 __FBSDID("$FreeBSD: head/usr.bin/indent/io.c 334927 2018-06-10 16:44:18Z pstef $");
 #endif
@@ -264,7 +264,7 @@
 
     ps.decl_on_line = ps.in_decl;      /* for proper comment indentation */
     ps.ind_stmt = ps.in_stmt && !ps.in_decl;
-    ps.dumped_decl_indent = false;
+    ps.decl_indent_done = false;
 
     *(lab.e = lab.s) = '\0';   /* reset buffers */
     *(code.e = code.s) = '\0';



Home | Main Index | Thread Index | Old Index