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 detection of casts
details: https://anonhg.NetBSD.org/src/rev/bd99a7f10664
branches: trunk
changeset: 375377:bd99a7f10664
user: rillig <rillig%NetBSD.org@localhost>
date: Mon May 15 21:51:45 2023 +0000
description:
indent: fix detection of casts
A word followed by a '(' does not start a cast expression.
diffstat:
tests/usr.bin/indent/fmt_decl.c | 43 ++++++++++++++++++++++++++++++++++++++++-
usr.bin/indent/indent.c | 5 ++-
2 files changed, 45 insertions(+), 3 deletions(-)
diffs (80 lines):
diff -r 4b56a8514a73 -r bd99a7f10664 tests/usr.bin/indent/fmt_decl.c
--- a/tests/usr.bin/indent/fmt_decl.c Mon May 15 21:24:56 2023 +0000
+++ b/tests/usr.bin/indent/fmt_decl.c Mon May 15 21:51:45 2023 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: fmt_decl.c,v 1.41 2023/05/15 20:50:37 rillig Exp $ */
+/* $NetBSD: fmt_decl.c,v 1.42 2023/05/15 21:51:46 rillig Exp $ */
/*
* Tests for declarations of global variables, external functions, and local
@@ -919,3 +919,44 @@ is_identifier_start(char ch)
return ch_isalpha(ch) || ch == '_';
}
//indent end
+
+
+//indent input
+void buf_add_chars(struct buffer *, const char *, size_t);
+
+static inline bool
+ch_isalnum(char ch)
+{
+ return isalnum((unsigned char)ch) != 0;
+}
+
+static inline bool
+ch_isalpha(char ch)
+{
+ return isalpha((unsigned char)ch) != 0;
+}
+//indent end
+
+//indent run -i4 -di0
+// $ FIXME: 'buffer' is classified as 'word'.
+// $
+// $ XXX: 'char' is classified as 'type_in_parentheses'; check whether this
+// $ XXX: lexer symbol should only be used for types in cast expressions.
+// $
+// $ FIXME: 'size_t' is classified as 'word'.
+void buf_add_chars(struct buffer *, const char *, size_t);
+
+static inline bool
+ch_isalnum(char ch)
+{
+ return isalnum((unsigned char)ch) != 0;
+}
+
+static inline bool
+ch_isalpha(char ch)
+{
+ return isalpha((unsigned char)ch) != 0;
+}
+//indent end
+
+//indent run-equals-input -i4 -di0
diff -r 4b56a8514a73 -r bd99a7f10664 usr.bin/indent/indent.c
--- a/usr.bin/indent/indent.c Mon May 15 21:24:56 2023 +0000
+++ b/usr.bin/indent/indent.c Mon May 15 21:51:45 2023 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: indent.c,v 1.283 2023/05/15 20:50:37 rillig Exp $ */
+/* $NetBSD: indent.c,v 1.284 2023/05/15 21:51:45 rillig Exp $ */
/*-
* SPDX-License-Identifier: BSD-4-Clause
@@ -38,7 +38,7 @@
*/
#include <sys/cdefs.h>
-__RCSID("$NetBSD: indent.c,v 1.283 2023/05/15 20:50:37 rillig Exp $");
+__RCSID("$NetBSD: indent.c,v 1.284 2023/05/15 21:51:45 rillig Exp $");
#include <sys/param.h>
#include <err.h>
@@ -467,6 +467,7 @@ process_lparen_or_lbracket(void)
}
if (ps.prev_token == lsym_offsetof || ps.prev_token == lsym_sizeof
+ || ps.prev_token == lsym_word
|| ps.is_function_definition)
ps.paren[ps.nparen - 1].no_cast = true;
}
Home |
Main Index |
Thread Index |
Old Index