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: remove another flag from parser state



details:   https://anonhg.NetBSD.org/src/rev/f0063f894f42
branches:  trunk
changeset: 376366:f0063f894f42
user:      rillig <rillig%NetBSD.org@localhost>
date:      Wed Jun 14 08:36:51 2023 +0000

description:
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.

diffstat:

 usr.bin/indent/debug.c      |   7 ++-----
 usr.bin/indent/indent.c     |   5 ++---
 usr.bin/indent/indent.h     |   7 +------
 usr.bin/indent/lexi.c       |   6 ++----
 usr.bin/indent/pr_comment.c |  20 +++++++++++---------
 5 files changed, 18 insertions(+), 27 deletions(-)

diffs (182 lines):

diff -r 8a567c5cc9c7 -r f0063f894f42 usr.bin/indent/debug.c
--- a/usr.bin/indent/debug.c    Wed Jun 14 08:25:15 2023 +0000
+++ b/usr.bin/indent/debug.c    Wed Jun 14 08:36:51 2023 +0000
@@ -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();
 
diff -r 8a567c5cc9c7 -r f0063f894f42 usr.bin/indent/indent.c
--- a/usr.bin/indent/indent.c   Wed Jun 14 08:25:15 2023 +0000
+++ b/usr.bin/indent/indent.c   Wed Jun 14 08:36:51 2023 +0000
@@ -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");
diff -r 8a567c5cc9c7 -r f0063f894f42 usr.bin/indent/indent.h
--- a/usr.bin/indent/indent.h   Wed Jun 14 08:25:15 2023 +0000
+++ b/usr.bin/indent/indent.h   Wed Jun 14 08:36:51 2023 +0000
@@ -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 {
diff -r 8a567c5cc9c7 -r f0063f894f42 usr.bin/indent/lexi.c
--- a/usr.bin/indent/lexi.c     Wed Jun 14 08:25:15 2023 +0000
+++ b/usr.bin/indent/lexi.c     Wed Jun 14 08:36:51 2023 +0000
@@ -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 */
diff -r 8a567c5cc9c7 -r f0063f894f42 usr.bin/indent/pr_comment.c
--- a/usr.bin/indent/pr_comment.c       Wed Jun 14 08:25:15 2023 +0000
+++ b/usr.bin/indent/pr_comment.c       Wed Jun 14 08:36:51 2023 +0000
@@ -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:



Home | Main Index | Thread Index | Old Index