Module Name:    src
Committed By:   rillig
Date:           Mon Jun 26 20:23:41 UTC 2023

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

Log Message:
indent: improve heuristics for '*' as pointer in for loops


To generate a diff of this commit:
cvs rdiff -u -r1.8 -r1.9 src/tests/usr.bin/indent/lsym_for.c
cvs rdiff -u -r1.238 -r1.239 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/lsym_for.c
diff -u src/tests/usr.bin/indent/lsym_for.c:1.8 src/tests/usr.bin/indent/lsym_for.c:1.9
--- src/tests/usr.bin/indent/lsym_for.c:1.8	Mon Jun 26 20:10:23 2023
+++ src/tests/usr.bin/indent/lsym_for.c	Mon Jun 26 20:23:40 2023
@@ -1,4 +1,4 @@
-/* $NetBSD: lsym_for.c,v 1.8 2023/06/26 20:10:23 rillig Exp $ */
+/* $NetBSD: lsym_for.c,v 1.9 2023/06/26 20:23:40 rillig Exp $ */
 
 /*
  * Tests for the token lsym_for, which represents the keyword 'for' that
@@ -103,17 +103,4 @@ function(void)
 }
 //indent end
 
-//indent run
-{
-	for (const list_item *i = first; i != NULL; i = i->next) {
-	}
-// $ FIXME: There should be no space after the '*'.
-	for (list_item * *i = first; i != NULL; i = i->next) {
-	}
-// $ FIXME: There should be no space after the '*'.
-	for (list_item * const *i = first; i != NULL; i = i->next) {
-	}
-	for (const char *const *i = first; i != NULL; i = i->next) {
-	}
-}
-//indent end
+//indent run-equals-input

Index: src/usr.bin/indent/lexi.c
diff -u src/usr.bin/indent/lexi.c:1.238 src/usr.bin/indent/lexi.c:1.239
--- src/usr.bin/indent/lexi.c:1.238	Mon Jun 26 20:10:23 2023
+++ src/usr.bin/indent/lexi.c	Mon Jun 26 20:23:40 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: lexi.c,v 1.238 2023/06/26 20:10:23 rillig Exp $	*/
+/*	$NetBSD: lexi.c,v 1.239 2023/06/26 20:23:40 rillig Exp $	*/
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -38,7 +38,7 @@
  */
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: lexi.c,v 1.238 2023/06/26 20:10:23 rillig Exp $");
+__RCSID("$NetBSD: lexi.c,v 1.239 2023/06/26 20:23:40 rillig Exp $");
 
 #include <stdlib.h>
 #include <string.h>
@@ -406,6 +406,12 @@ lexi_alnum(void)
 
 	if (ps.prev_lsym == lsym_tag && ps.paren.len == 0)
 		return lsym_type;
+	if (ps.spaced_expr_psym == psym_for_exprs
+	    && ps.prev_lsym == lsym_lparen && ps.paren.len == 1
+	    && *inp_p == '*') {
+		ps.next_unary = true;
+		return lsym_type;
+	}
 
 	token_add_char('\0');	// Terminate in non-debug mode as well.
 	token.len--;

Reply via email to