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 unnecessary assignments to las...



details:   https://anonhg.NetBSD.org/src/rev/20b7463dd29f
branches:  trunk
changeset: 374754:20b7463dd29f
user:      rillig <rillig%NetBSD.org@localhost>
date:      Thu May 11 10:39:25 2023 +0000

description:
indent: remove unnecessary assignments to last_else

No functional change intended.

diffstat:

 tests/usr.bin/indent/lsym_do.c |  23 ++++++++++++++++++++++-
 usr.bin/indent/indent.c        |  17 ++++++++---------
 2 files changed, 30 insertions(+), 10 deletions(-)

diffs (107 lines):

diff -r 56d18d052d5f -r 20b7463dd29f tests/usr.bin/indent/lsym_do.c
--- a/tests/usr.bin/indent/lsym_do.c    Thu May 11 10:08:34 2023 +0000
+++ b/tests/usr.bin/indent/lsym_do.c    Thu May 11 10:39:25 2023 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: lsym_do.c,v 1.4 2022/04/24 10:36:37 rillig Exp $ */
+/* $NetBSD: lsym_do.c,v 1.5 2023/05/11 10:39:26 rillig Exp $ */
 
 /*
  * Tests for the token lsym_do, which represents the keyword 'do' that starts
@@ -28,3 +28,24 @@ function(void)
        while (cond);
 }
 //indent end
+
+
+//indent input
+void
+else_do(int i)
+{
+       if (i > 0) return; else do {} while (0);
+}
+//indent end
+
+//indent run
+void
+else_do(int i)
+{
+       if (i > 0)
+               return;
+       else
+               do {
+               } while (0);
+}
+//indent end
diff -r 56d18d052d5f -r 20b7463dd29f usr.bin/indent/indent.c
--- a/usr.bin/indent/indent.c   Thu May 11 10:08:34 2023 +0000
+++ b/usr.bin/indent/indent.c   Thu May 11 10:39:25 2023 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: indent.c,v 1.246 2023/05/11 09:28:53 rillig Exp $      */
+/*     $NetBSD: indent.c,v 1.247 2023/05/11 10:39:25 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.246 2023/05/11 09:28:53 rillig Exp $");
+__RCSID("$NetBSD: indent.c,v 1.247 2023/05/11 10:39:25 rillig Exp $");
 #elif defined(__FreeBSD__)
 __FBSDID("$FreeBSD: head/usr.bin/indent/indent.c 340138 2018-11-04 19:24:49Z oshogbo $");
 #endif
@@ -794,7 +794,7 @@ process_rbrace(bool *spaced_expr, int *d
 }
 
 static void
-process_do(bool *force_nl, bool *last_else)
+process_do(bool *force_nl)
 {
     ps.in_stmt_or_decl = false;
 
@@ -806,12 +806,11 @@ process_do(bool *force_nl, bool *last_el
     }
 
     *force_nl = true;          /* following stuff must go onto new line */
-    *last_else = false;
     parse(psym_do);
 }
 
 static void
-process_else(bool *force_nl, bool *last_else)
+process_else(bool *force_nl)
 {
     ps.in_stmt_or_decl = false;
 
@@ -823,7 +822,6 @@ process_else(bool *force_nl, bool *last_
     }
 
     *force_nl = true;          /* following stuff must go onto new line */
-    *last_else = true;
     parse(psym_else);
 }
 
@@ -1057,7 +1055,7 @@ process_preprocessing(void)
      */
 }
 
-static void __attribute__((__noreturn__))
+__dead static void
 main_loop(void)
 {
     bool force_nl = false;     /* when true, code must be broken */
@@ -1181,11 +1179,12 @@ main_loop(void)
            goto copy_token;
 
        case lsym_do:
-           process_do(&force_nl, &last_else);
+           process_do(&force_nl);
            goto copy_token;
 
        case lsym_else:
-           process_else(&force_nl, &last_else);
+           process_else(&force_nl);
+           last_else = true;
            goto copy_token;
 
        case lsym_typedef:



Home | Main Index | Thread Index | Old Index