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: fix joining of adjacent unary '+' ope...



details:   https://anonhg.NetBSD.org/src/rev/622095224fd3
branches:  trunk
changeset: 991034:622095224fd3
user:      rillig <rillig%NetBSD.org@localhost>
date:      Thu Nov 04 17:12:12 2021 +0000

description:
indent: fix joining of adjacent unary '+' operators

diffstat:

 tests/usr.bin/indent/token_binary_op.c |   4 ++--
 tests/usr.bin/indent/token_unary_op.c  |   6 ++----
 usr.bin/indent/indent.c                |  16 +++++++++++++---
 3 files changed, 17 insertions(+), 9 deletions(-)

diffs (80 lines):

diff -r c0680ddb0aa9 -r 622095224fd3 tests/usr.bin/indent/token_binary_op.c
--- a/tests/usr.bin/indent/token_binary_op.c    Thu Nov 04 17:10:37 2021 +0000
+++ b/tests/usr.bin/indent/token_binary_op.c    Thu Nov 04 17:12:12 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: token_binary_op.c,v 1.6 2021/10/30 22:36:07 rillig Exp $ */
+/* $NetBSD: token_binary_op.c,v 1.7 2021/11/04 17:12:12 rillig Exp $ */
 /* $FreeBSD$ */
 
 /*
@@ -214,7 +214,7 @@
         *
         * See lexi.c, lexi, "case '+':".
         */
-       if (a++ ++ +++b)
+       if (a++ ++ ++ +b)
                return;
 }
 #indent end
diff -r c0680ddb0aa9 -r 622095224fd3 tests/usr.bin/indent/token_unary_op.c
--- a/tests/usr.bin/indent/token_unary_op.c     Thu Nov 04 17:10:37 2021 +0000
+++ b/tests/usr.bin/indent/token_unary_op.c     Thu Nov 04 17:12:12 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: token_unary_op.c,v 1.1 2021/10/18 22:30:34 rillig Exp $ */
+/* $NetBSD: token_unary_op.c,v 1.2 2021/11/04 17:12:12 rillig Exp $ */
 /* $FreeBSD$ */
 
 /*
@@ -16,7 +16,5 @@
 int var = +3;
 int mixed = +-+-+-+-+-+-+-+-+-+-+-+-+-3;
 int count = ~-~-~-~-~-~-~-~-~-~-~-~-~-3;
-/* $ FIXME: There must be spaces between adjacent '+'. */
-/* $ FIXME: There must be spaces between adjacent '-'. */
-int same = +++++-----3;
+int same = + + + + +- - - - -3;
 #indent end
diff -r c0680ddb0aa9 -r 622095224fd3 usr.bin/indent/indent.c
--- a/usr.bin/indent/indent.c   Thu Nov 04 17:10:37 2021 +0000
+++ b/usr.bin/indent/indent.c   Thu Nov 04 17:12:12 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: indent.c,v 1.205 2021/11/03 21:47:35 rillig Exp $      */
+/*     $NetBSD: indent.c,v 1.206 2021/11/04 17:12:12 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.205 2021/11/03 21:47:35 rillig Exp $");
+__RCSID("$NetBSD: indent.c,v 1.206 2021/11/04 17:12:12 rillig Exp $");
 #elif defined(__FreeBSD__)
 __FBSDID("$FreeBSD: head/usr.bin/indent/indent.c 340138 2018-11-04 19:24:49Z oshogbo $");
 #endif
@@ -834,6 +834,16 @@
     ps.search_stmt = opt.brace_same_line;
 }
 
+static bool
+want_blank_before_unary_op(void)
+{
+    if (ps.want_blank)
+       return true;
+    if (token.s[0] == '+' || token.s[0] == '-')
+       return code.e[-1] == token.s[0];
+    return false;
+}
+
 static void
 process_unary_op(int decl_ind, bool tabs_to_var)
 {
@@ -842,7 +852,7 @@
        /* pointer declarations */
        code_add_decl_indent(decl_ind - (int)buf_len(&token), tabs_to_var);
        ps.decl_indent_done = true;
-    } else if (ps.want_blank)
+    } else if (want_blank_before_unary_op())
        *code.e++ = ' ';
 
     buf_add_buf(&code, &token);



Home | Main Index | Thread Index | Old Index