Module Name:    src
Committed By:   rillig
Date:           Wed Jun 14 08:36:51 UTC 2023

Modified Files:
        src/usr.bin/indent: debug.c indent.c indent.h lexi.c pr_comment.c

Log Message:
indent: remove another flag from parser state

When processing a comment, the flag ps.next_col_1 was not used for the
next token, but for a line within a comment.  As its scope was limited
to a single comment, there is no need to store it any longer than that

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.55 -r1.56 src/usr.bin/indent/debug.c
cvs rdiff -u -r1.358 -r1.359 src/usr.bin/indent/indent.c
cvs rdiff -u -r1.190 -r1.191 src/usr.bin/indent/indent.h
cvs rdiff -u -r1.226 -r1.227 src/usr.bin/indent/lexi.c
cvs rdiff -u -r1.162 -r1.163 src/usr.bin/indent/pr_comment.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/debug.c
diff -u src/usr.bin/indent/debug.c:1.55 src/usr.bin/indent/debug.c:1.56
--- src/usr.bin/indent/debug.c:1.55	Wed Jun 14 08:25:15 2023
+++ src/usr.bin/indent/debug.c	Wed Jun 14 08:36:51 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: debug.c,v 1.55 2023/06/14 08:25:15 rillig Exp $	*/
+/*	$NetBSD: debug.c,v 1.56 2023/06/14 08:36:51 rillig Exp $	*/
 
 /*-
  * Copyright (c) 2023 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: debug.c,v 1.55 2023/06/14 08:25:15 rillig Exp $");
+__RCSID("$NetBSD: debug.c,v 1.56 2023/06/14 08:36:51 rillig Exp $");
 
 #include <stdarg.h>
 #include <string.h>
@@ -374,9 +374,6 @@ debug_parser_state(void)
 	debug_ps_enum(declaration, declaration_name);
 	debug_ps_bool(blank_line_after_decl);
 
-	state.heading = "comments";
-	debug_ps_bool(next_col_1);
-
 	state.heading = NULL;
 	debug_blank_line();
 

Index: src/usr.bin/indent/indent.c
diff -u src/usr.bin/indent/indent.c:1.358 src/usr.bin/indent/indent.c:1.359
--- src/usr.bin/indent/indent.c:1.358	Wed Jun 14 07:20:55 2023
+++ src/usr.bin/indent/indent.c	Wed Jun 14 08:36:51 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: indent.c,v 1.358 2023/06/14 07:20:55 rillig Exp $	*/
+/*	$NetBSD: indent.c,v 1.359 2023/06/14 08:36:51 rillig Exp $	*/
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -38,7 +38,7 @@
  */
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: indent.c,v 1.358 2023/06/14 07:20:55 rillig Exp $");
+__RCSID("$NetBSD: indent.c,v 1.359 2023/06/14 08:36:51 rillig Exp $");
 
 #include <sys/param.h>
 #include <err.h>
@@ -186,7 +186,6 @@ init_globals(void)
 {
 	ps.psyms.sym[0] = psym_stmt;
 	ps.prev_lsym = lsym_semicolon;
-	ps.next_col_1 = true;
 	ps.lbrace_kind = psym_lbrace_block;
 
 	const char *suffix = getenv("SIMPLE_BACKUP_SUFFIX");

Index: src/usr.bin/indent/indent.h
diff -u src/usr.bin/indent/indent.h:1.190 src/usr.bin/indent/indent.h:1.191
--- src/usr.bin/indent/indent.h:1.190	Wed Jun 14 08:25:15 2023
+++ src/usr.bin/indent/indent.h	Wed Jun 14 08:36:51 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: indent.h,v 1.190 2023/06/14 08:25:15 rillig Exp $	*/
+/*	$NetBSD: indent.h,v 1.191 2023/06/14 08:36:51 rillig Exp $	*/
 
 /*-
  * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
@@ -402,11 +402,6 @@ extern struct parser_state {
 		decl_end,	/* finished a declaration */
 	} declaration;
 	bool blank_line_after_decl;
-
-	/* Comments */
-
-	bool next_col_1;	/* whether the next token starts in column 1 of
-				 * the original input */
 } ps;
 
 extern struct output_state {

Index: src/usr.bin/indent/lexi.c
diff -u src/usr.bin/indent/lexi.c:1.226 src/usr.bin/indent/lexi.c:1.227
--- src/usr.bin/indent/lexi.c:1.226	Wed Jun 14 08:25:15 2023
+++ src/usr.bin/indent/lexi.c	Wed Jun 14 08:36:51 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: lexi.c,v 1.226 2023/06/14 08:25:15 rillig Exp $	*/
+/*	$NetBSD: lexi.c,v 1.227 2023/06/14 08:36:51 rillig Exp $	*/
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -38,7 +38,7 @@
  */
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: lexi.c,v 1.226 2023/06/14 08:25:15 rillig Exp $");
+__RCSID("$NetBSD: lexi.c,v 1.227 2023/06/14 08:36:51 rillig Exp $");
 
 #include <stdlib.h>
 #include <string.h>
@@ -532,7 +532,6 @@ lexer_symbol
 lexi(void)
 {
 	buf_clear(&token);
-	ps.next_col_1 = false;
 
 	for (;;) {
 		if (ch_isblank(inp_p[0]))
@@ -567,7 +566,6 @@ lexi(void)
 		/* if data has been exhausted, the '\n' is a dummy. */
 		lsym = had_eof ? lsym_eof : lsym_newline;
 		next_unary = ps.next_unary;
-		ps.next_col_1 = true;
 		break;
 
 	/* INDENT OFF */

Index: src/usr.bin/indent/pr_comment.c
diff -u src/usr.bin/indent/pr_comment.c:1.162 src/usr.bin/indent/pr_comment.c:1.163
--- src/usr.bin/indent/pr_comment.c:1.162	Wed Jun 14 08:25:15 2023
+++ src/usr.bin/indent/pr_comment.c	Wed Jun 14 08:36:51 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: pr_comment.c,v 1.162 2023/06/14 08:25:15 rillig Exp $	*/
+/*	$NetBSD: pr_comment.c,v 1.163 2023/06/14 08:36:51 rillig Exp $	*/
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -38,7 +38,7 @@
  */
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: pr_comment.c,v 1.162 2023/06/14 08:25:15 rillig Exp $");
+__RCSID("$NetBSD: pr_comment.c,v 1.163 2023/06/14 08:36:51 rillig Exp $");
 
 #include <string.h>
 
@@ -178,8 +178,6 @@ copy_comment_wrap_text(int line_length, 
 			break;
 	}
 
-	ps.next_col_1 = false;
-
 	if (now_len <= line_length)
 		return;
 	if (ch_isspace(com.s[com.len - 1]))
@@ -206,10 +204,10 @@ copy_comment_wrap_text(int line_length, 
 }
 
 static bool
-copy_comment_wrap_newline(ssize_t *last_blank)
+copy_comment_wrap_newline(ssize_t *last_blank, bool *seen_newline)
 {
 	*last_blank = -1;
-	if (ps.next_col_1) {
+	if (*seen_newline) {
 		if (com.len == 0)
 			com_add_char(' ');	/* force empty output line */
 		if (com.len > 3) {
@@ -219,7 +217,7 @@ copy_comment_wrap_newline(ssize_t *last_
 		output_line();
 		com_add_delim();
 	} else {
-		ps.next_col_1 = true;
+		*seen_newline = true;
 		if (!(com.len > 0 && ch_isblank(com.s[com.len - 1])))
 			com_add_char(' ');
 		*last_blank = (int)com.len - 1;
@@ -282,17 +280,21 @@ static void
 copy_comment_wrap(int line_length, bool delim)
 {
 	ssize_t last_blank = -1;	/* index of the last blank in 'com' */
+	bool seen_newline = false;
 
 	for (;;) {
 		if (inp_p[0] == '\n') {
 			if (had_eof)
 				goto unterminated_comment;
-			if (!copy_comment_wrap_newline(&last_blank))
+			if (!copy_comment_wrap_newline(&last_blank,
+			    &seen_newline))
 				goto end_of_comment;
 		} else if (inp_p[0] == '*' && inp_p[1] == '/')
 			goto end_of_comment;
-		else
+		else {
 			copy_comment_wrap_text(line_length, &last_blank);
+			seen_newline = false;
+		}
 	}
 
 end_of_comment:

Reply via email to