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: improve heuristics of classifying '*'...
details: https://anonhg.NetBSD.org/src/rev/b9d6dc6e12f7
branches: trunk
changeset: 376128:b9d6dc6e12f7
user: rillig <rillig%NetBSD.org@localhost>
date: Fri Jun 02 14:21:55 2023 +0000
description:
indent: improve heuristics of classifying '*' as pointer or operator
diffstat:
tests/usr.bin/indent/fmt_decl.c | 15 ++-------------
tests/usr.bin/indent/lsym_unary_op.c | 5 ++---
usr.bin/indent/indent.c | 8 ++++----
usr.bin/indent/indent.h | 8 ++++----
4 files changed, 12 insertions(+), 24 deletions(-)
diffs (99 lines):
diff -r 9093ba91a030 -r b9d6dc6e12f7 tests/usr.bin/indent/fmt_decl.c
--- a/tests/usr.bin/indent/fmt_decl.c Fri Jun 02 13:59:33 2023 +0000
+++ b/tests/usr.bin/indent/fmt_decl.c Fri Jun 02 14:21:55 2023 +0000
@@ -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
/*
diff -r 9093ba91a030 -r b9d6dc6e12f7 tests/usr.bin/indent/lsym_unary_op.c
--- a/tests/usr.bin/indent/lsym_unary_op.c Fri Jun 02 13:59:33 2023 +0000
+++ b/tests/usr.bin/indent/lsym_unary_op.c Fri Jun 02 14:21:55 2023 +0000
@@ -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
diff -r 9093ba91a030 -r b9d6dc6e12f7 usr.bin/indent/indent.c
--- a/usr.bin/indent/indent.c Fri Jun 02 13:59:33 2023 +0000
+++ b/usr.bin/indent/indent.c Fri Jun 02 14:21:55 2023 +0000
@@ -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;
diff -r 9093ba91a030 -r b9d6dc6e12f7 usr.bin/indent/indent.h
--- a/usr.bin/indent/indent.h Fri Jun 02 13:59:33 2023 +0000
+++ b/usr.bin/indent/indent.h Fri Jun 02 14:21:55 2023 +0000
@@ -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
Home |
Main Index |
Thread Index |
Old Index