Module Name:    src
Committed By:   rillig
Date:           Mon Nov  1 23:44:08 UTC 2021

Modified Files:
        src/tests/usr.bin/indent: opt_ci.c
        src/usr.bin/indent: indent.c indent.h lexi.c

Log Message:
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.


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/tests/usr.bin/indent/opt_ci.c
cvs rdiff -u -r1.203 -r1.204 src/usr.bin/indent/indent.c
cvs rdiff -u -r1.74 -r1.75 src/usr.bin/indent/indent.h
cvs rdiff -u -r1.128 -r1.129 src/usr.bin/indent/lexi.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/usr.bin/indent/opt_ci.c
diff -u src/tests/usr.bin/indent/opt_ci.c:1.2 src/tests/usr.bin/indent/opt_ci.c:1.3
--- src/tests/usr.bin/indent/opt_ci.c:1.2	Mon Nov  1 22:48:56 2021
+++ src/tests/usr.bin/indent/opt_ci.c	Mon Nov  1 23:44:08 2021
@@ -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 @@ sum(int a, int b)
 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 @@ sum(int a, int b)
 int
 sum(int a, int b)
 {
-	return(a +
+	return (a +
 	  b);
-	return(first +
+	return (first +
 	  second + (
 	    third));
 }
@@ -169,9 +169,9 @@ sum(int a, int b)
 int
 sum(int a, int b)
 {
-	return(a +
+	return (a +
 	    b);
-	return(first +
+	return (first +
 	    second + (
 	    third));
 }
@@ -181,9 +181,9 @@ sum(int a, int b)
 int
 sum(int a, int b)
 {
-	return(a +
+	return (a +
 		b);
-	return(first +
+	return (first +
 		second + (
 			third));
 }

Index: src/usr.bin/indent/indent.c
diff -u src/usr.bin/indent/indent.c:1.203 src/usr.bin/indent/indent.c:1.204
--- src/usr.bin/indent/indent.c:1.203	Sun Oct 31 22:38:12 2021
+++ src/usr.bin/indent/indent.c	Mon Nov  1 23:44:08 2021
@@ -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 @@ static char sccsid[] = "@(#)indent.c	5.1
 
 #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 @@ main_loop(void)
 	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:

Index: src/usr.bin/indent/indent.h
diff -u src/usr.bin/indent/indent.h:1.74 src/usr.bin/indent/indent.h:1.75
--- src/usr.bin/indent/indent.h:1.74	Sun Oct 31 22:38:12 2021
+++ src/usr.bin/indent/indent.h	Mon Nov  1 23:44:08 2021
@@ -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 @@ typedef enum lexer_symbol {
     lsym_if,
     lsym_switch,
     lsym_while,
+    lsym_return
 } lexer_symbol;
 
 typedef enum parser_symbol {

Index: src/usr.bin/indent/lexi.c
diff -u src/usr.bin/indent/lexi.c:1.128 src/usr.bin/indent/lexi.c:1.129
--- src/usr.bin/indent/lexi.c:1.128	Sun Oct 31 22:38:12 2021
+++ src/usr.bin/indent/lexi.c	Mon Nov  1 23:44:08 2021
@@ -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 @@ static char sccsid[] = "@(#)lexi.c	8.1 (
 
 #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 @@ static const struct keyword {
     {"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 @@ lsym_name(lexer_symbol sym)
 	"if",
 	"switch",
 	"while",
+	"return",
     };
 
     return name[sym];

Reply via email to