Module Name:    src
Committed By:   rillig
Date:           Fri Oct 29 17:32:22 UTC 2021

Modified Files:
        src/usr.bin/indent: indent.c indent.h io.c

Log Message:
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.


To generate a diff of this commit:
cvs rdiff -u -r1.169 -r1.170 src/usr.bin/indent/indent.c
cvs rdiff -u -r1.57 -r1.58 src/usr.bin/indent/indent.h
cvs rdiff -u -r1.103 -r1.104 src/usr.bin/indent/io.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/indent/indent.c
diff -u src/usr.bin/indent/indent.c:1.169 src/usr.bin/indent/indent.c:1.170
--- src/usr.bin/indent/indent.c:1.169	Fri Oct 29 16:59:35 2021
+++ src/usr.bin/indent/indent.c	Fri Oct 29 17:32:22 2021
@@ -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 @@ static char sccsid[] = "@(#)indent.c	5.1
 
 #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 @@ main_prepare_parsing(void)
 }
 
 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 @@ process_lparen_or_lbracket(int decl_ind,
     }
 
     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 @@ process_rparen_or_rbracket(bool *spaced_
 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 @@ process_semicolon(bool *seen_case, int *
     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 @@ process_ident(lexer_symbol lsym, int dec
 	    }
 	    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 @@ process_comma(int decl_ind, bool tabs_to
 					 * 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++ = ',';

Index: src/usr.bin/indent/indent.h
diff -u src/usr.bin/indent/indent.h:1.57 src/usr.bin/indent/indent.h:1.58
--- src/usr.bin/indent/indent.h:1.57	Fri Oct 29 16:59:35 2021
+++ src/usr.bin/indent/indent.h	Fri Oct 29 17:32:22 2021
@@ -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 @@ extern struct parser_state {
 				 * 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;

Index: src/usr.bin/indent/io.c
diff -u src/usr.bin/indent/io.c:1.103 src/usr.bin/indent/io.c:1.104
--- src/usr.bin/indent/io.c:1.103	Wed Oct 27 00:04:51 2021
+++ src/usr.bin/indent/io.c	Fri Oct 29 17:32:22 2021
@@ -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 @@ static char sccsid[] = "@(#)io.c	8.1 (Be
 
 #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 @@ output_line(char line_terminator)
 
     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';

Reply via email to