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 missing blank after 'return' (sin...



details:   https://anonhg.NetBSD.org/src/rev/976849330f1b
branches:  trunk
changeset: 1024747:976849330f1b
user:      rillig <rillig%NetBSD.org@localhost>
date:      Mon Nov 01 23:44:08 2021 +0000

description:
indent: fix missing blank after 'return' (since 2021-10-31)

In indent.c 1.200 from 2021-10-31, the subtypes of identifier tokens
were removed since they were redundant. An unintended side effect was
that a parenthesized expression after 'return' was no longer separated
by a blank.

Before that change, 'return' was tokenized as an lsym_ident with subtype
kw_other, and want_space_before_lparen handled this case in the last
line. After the change, 'return' was treated as an ordinary identifier,
and unless the option '-pcs' (blank after function call) was given, the
blank was removed.

The other keywords that had kw_other are not affected since they do not
expect a '(' afterwards. These keywords are 'break', 'continue', 'goto',
'inline' and 'restrict'.

Curiously, there was not a single test case that covered 'return(expr)'.

While here, remove the trailing ',' from the enum lexer_symbol, which is
not allowed in standard C, it is a GNU extension. Lint doesn't complain
about this since the default LINTFLAGS include '-g' for GCC mode.

diffstat:

 tests/usr.bin/indent/opt_ci.c |  24 ++++++++++++------------
 usr.bin/indent/indent.c       |   5 +++--
 usr.bin/indent/indent.h       |   3 ++-
 usr.bin/indent/lexi.c         |   7 ++++---
 4 files changed, 21 insertions(+), 18 deletions(-)

diffs (140 lines):

diff -r 01c96e3ea690 -r 976849330f1b tests/usr.bin/indent/opt_ci.c
--- a/tests/usr.bin/indent/opt_ci.c     Mon Nov 01 22:48:56 2021 +0000
+++ b/tests/usr.bin/indent/opt_ci.c     Mon Nov 01 23:44:08 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: opt_ci.c,v 1.2 2021/11/01 22:48:56 rillig Exp $ */
+/* $NetBSD: opt_ci.c,v 1.3 2021/11/01 23:44:08 rillig Exp $ */
 /* $FreeBSD$ */
 
 /*
@@ -136,11 +136,11 @@
 int
 sum(int a, int b)
 {
-       return(a +
-              b);
-       return(first +
-              second + (
-                        third));
+       return (a +
+               b);
+       return (first +
+               second + (
+                         third));
 }
 #indent end
 #indent run-equals-prev-output -ci2
@@ -151,9 +151,9 @@
 int
 sum(int a, int b)
 {
-       return(a +
+       return (a +
          b);
-       return(first +
+       return (first +
          second + (
            third));
 }
@@ -169,9 +169,9 @@
 int
 sum(int a, int b)
 {
-       return(a +
+       return (a +
            b);
-       return(first +
+       return (first +
            second + (
            third));
 }
@@ -181,9 +181,9 @@
 int
 sum(int a, int b)
 {
-       return(a +
+       return (a +
                b);
-       return(first +
+       return (first +
                second + (
                        third));
 }
diff -r 01c96e3ea690 -r 976849330f1b usr.bin/indent/indent.c
--- a/usr.bin/indent/indent.c   Mon Nov 01 22:48:56 2021 +0000
+++ b/usr.bin/indent/indent.c   Mon Nov 01 23:44:08 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: indent.c,v 1.203 2021/10/31 22:38:12 rillig Exp $      */
+/*     $NetBSD: indent.c,v 1.204 2021/11/01 23:44:08 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.203 2021/10/31 22:38:12 rillig Exp $");
+__RCSID("$NetBSD: indent.c,v 1.204 2021/11/01 23:44:08 rillig Exp $");
 #elif defined(__FreeBSD__)
 __FBSDID("$FreeBSD: head/usr.bin/indent/indent.c 340138 2018-11-04 19:24:49Z oshogbo $");
 #endif
@@ -1501,6 +1501,7 @@
        case lsym_sizeof:
        case lsym_ident:
        case lsym_funcname:
+       case lsym_return:
            process_ident(lsym, decl_ind, tabs_to_var, &spaced_expr,
                &force_nl, hd);
     copy_token:
diff -r 01c96e3ea690 -r 976849330f1b usr.bin/indent/indent.h
--- a/usr.bin/indent/indent.h   Mon Nov 01 22:48:56 2021 +0000
+++ b/usr.bin/indent/indent.h   Mon Nov 01 23:44:08 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: indent.h,v 1.74 2021/10/31 22:38:12 rillig Exp $       */
+/*     $NetBSD: indent.h,v 1.75 2021/11/01 23:44:08 rillig Exp $       */
 
 /*-
  * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
@@ -105,6 +105,7 @@
     lsym_if,
     lsym_switch,
     lsym_while,
+    lsym_return
 } lexer_symbol;
 
 typedef enum parser_symbol {
diff -r 01c96e3ea690 -r 976849330f1b usr.bin/indent/lexi.c
--- a/usr.bin/indent/lexi.c     Mon Nov 01 22:48:56 2021 +0000
+++ b/usr.bin/indent/lexi.c     Mon Nov 01 23:44:08 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: lexi.c,v 1.128 2021/10/31 22:38:12 rillig Exp $        */
+/*     $NetBSD: lexi.c,v 1.129 2021/11/01 23:44:08 rillig Exp $        */
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -43,7 +43,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__NetBSD__)
-__RCSID("$NetBSD: lexi.c,v 1.128 2021/10/31 22:38:12 rillig Exp $");
+__RCSID("$NetBSD: lexi.c,v 1.129 2021/11/01 23:44:08 rillig Exp $");
 #elif defined(__FreeBSD__)
 __FBSDID("$FreeBSD: head/usr.bin/indent/lexi.c 337862 2018-08-15 18:19:45Z pstef $");
 #endif
@@ -93,7 +93,7 @@
     {"offsetof", lsym_offsetof},
     {"register", lsym_storage_class},
     {"restrict", lsym_ident},
-    {"return", lsym_ident},
+    {"return", lsym_return},
     {"short", lsym_type},
     {"signed", lsym_type},
     {"sizeof", lsym_sizeof},
@@ -252,6 +252,7 @@
        "if",
        "switch",
        "while",
+       "return",
     };
 
     return name[sym];



Home | Main Index | Thread Index | Old Index