Module Name:    src
Committed By:   rillig
Date:           Fri Jun  2 14:21:55 UTC 2023

Modified Files:
        src/tests/usr.bin/indent: fmt_decl.c lsym_unary_op.c
        src/usr.bin/indent: indent.c indent.h

Log Message:
indent: improve heuristics of classifying '*' as pointer or operator


To generate a diff of this commit:
cvs rdiff -u -r1.46 -r1.47 src/tests/usr.bin/indent/fmt_decl.c
cvs rdiff -u -r1.7 -r1.8 src/tests/usr.bin/indent/lsym_unary_op.c
cvs rdiff -u -r1.312 -r1.313 src/usr.bin/indent/indent.c
cvs rdiff -u -r1.161 -r1.162 src/usr.bin/indent/indent.h

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/fmt_decl.c
diff -u src/tests/usr.bin/indent/fmt_decl.c:1.46 src/tests/usr.bin/indent/fmt_decl.c:1.47
--- src/tests/usr.bin/indent/fmt_decl.c:1.46	Tue May 23 16:53:57 2023
+++ src/tests/usr.bin/indent/fmt_decl.c	Fri Jun  2 14:21:55 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: fmt_decl.c,v 1.46 2023/05/23 16:53:57 rillig Exp $	*/
+/*	$NetBSD: fmt_decl.c,v 1.47 2023/06/02 14:21:55 rillig Exp $	*/
 
 /*
  * Tests for declarations of global variables, external functions, and local
@@ -570,18 +570,7 @@ buffer_add(buffer *buf, char ch)
 }
 //indent end
 
-/* Before lexi.c 1.156 from 2021-11-25, indent generated 'buffer * buf'. */
-//indent run
-void		buffer_add(buffer *, char);
-/* $ FIXME: space after '*' */
-void		buffer_add(buffer * buf, char ch);
-
-void
-buffer_add(buffer *buf, char ch)
-{
-	*buf->e++ = ch;
-}
-//indent end
+//indent run-equals-input
 
 
 /*

Index: src/tests/usr.bin/indent/lsym_unary_op.c
diff -u src/tests/usr.bin/indent/lsym_unary_op.c:1.7 src/tests/usr.bin/indent/lsym_unary_op.c:1.8
--- src/tests/usr.bin/indent/lsym_unary_op.c:1.7	Tue May 23 06:18:00 2023
+++ src/tests/usr.bin/indent/lsym_unary_op.c	Fri Jun  2 14:21:55 2023
@@ -1,4 +1,4 @@
-/* $NetBSD: lsym_unary_op.c,v 1.7 2023/05/23 06:18:00 rillig Exp $ */
+/* $NetBSD: lsym_unary_op.c,v 1.8 2023/06/02 14:21:55 rillig Exp $ */
 
 /*
  * Tests for the token lsym_unary_op, which represents a unary operator.
@@ -87,8 +87,7 @@ sbuf_t *sb = *(sbuf_t **)sp;
 
 //indent run -di0
 {
-// $ FIXME: Wrong spacing between the '*'.
 // $ FIXME: Wrong spacing after the cast.
-	sbuf_t *sb = *(sbuf_t * *) sp;
+	sbuf_t *sb = *(sbuf_t **) sp;
 }
 //indent end

Index: src/usr.bin/indent/indent.c
diff -u src/usr.bin/indent/indent.c:1.312 src/usr.bin/indent/indent.c:1.313
--- src/usr.bin/indent/indent.c:1.312	Fri Jun  2 13:59:33 2023
+++ src/usr.bin/indent/indent.c	Fri Jun  2 14:21:55 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: indent.c,v 1.312 2023/06/02 13:59:33 rillig Exp $	*/
+/*	$NetBSD: indent.c,v 1.313 2023/06/02 14:21:55 rillig Exp $	*/
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -38,7 +38,7 @@
  */
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: indent.c,v 1.312 2023/06/02 13:59:33 rillig Exp $");
+__RCSID("$NetBSD: indent.c,v 1.313 2023/06/02 14:21:55 rillig Exp $");
 
 #include <sys/param.h>
 #include <err.h>
@@ -362,8 +362,8 @@ update_ps_decl_ptr(lexer_symbol lsym)
 	case dp_other:
 		if (lsym == lsym_semicolon || lsym == lsym_rbrace)
 			ps.decl_ptr = dp_start;
-		if (lsym == lsym_lparen_or_lbracket
-		    && ps.prev_token == lsym_for)
+		if (lsym == lsym_lparen_or_lbracket && token.st[0] == '('
+		    && ps.prev_token != lsym_sizeof)
 			ps.decl_ptr = dp_start;
 		if (lsym == lsym_comma && ps.in_decl)
 			ps.decl_ptr = dp_start;

Index: src/usr.bin/indent/indent.h
diff -u src/usr.bin/indent/indent.h:1.161 src/usr.bin/indent/indent.h:1.162
--- src/usr.bin/indent/indent.h:1.161	Fri Jun  2 13:59:33 2023
+++ src/usr.bin/indent/indent.h	Fri Jun  2 14:21:55 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: indent.h,v 1.161 2023/06/02 13:59:33 rillig Exp $	*/
+/*	$NetBSD: indent.h,v 1.162 2023/06/02 14:21:55 rillig Exp $	*/
 
 /*-
  * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
@@ -370,9 +370,9 @@ extern struct parser_state {
 				 * remaining lines of the statement,
 				 * initializer or declaration */
 	enum {
-	    dp_start,
-	    dp_word,
-	    dp_word_asterisk,
+	    dp_start,		/* the beginning of a declaration */
+	    dp_word,		/* seen a type name */
+	    dp_word_asterisk,	/* seen a type name and some '*' */
 	    dp_other,
 	} decl_ptr;		/* detects declarations like 'typename *x',
 				 * to prevent the '*' from being interpreted as

Reply via email to