Module Name: src Committed By: rillig Date: Mon May 15 21:51:46 UTC 2023
Modified Files: src/tests/usr.bin/indent: fmt_decl.c src/usr.bin/indent: indent.c Log Message: indent: fix detection of casts A word followed by a '(' does not start a cast expression. To generate a diff of this commit: cvs rdiff -u -r1.41 -r1.42 src/tests/usr.bin/indent/fmt_decl.c cvs rdiff -u -r1.283 -r1.284 src/usr.bin/indent/indent.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/fmt_decl.c diff -u src/tests/usr.bin/indent/fmt_decl.c:1.41 src/tests/usr.bin/indent/fmt_decl.c:1.42 --- src/tests/usr.bin/indent/fmt_decl.c:1.41 Mon May 15 20:50:37 2023 +++ src/tests/usr.bin/indent/fmt_decl.c Mon May 15 21:51:46 2023 @@ -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 Index: src/usr.bin/indent/indent.c diff -u src/usr.bin/indent/indent.c:1.283 src/usr.bin/indent/indent.c:1.284 --- src/usr.bin/indent/indent.c:1.283 Mon May 15 20:50:37 2023 +++ src/usr.bin/indent/indent.c Mon May 15 21:51:45 2023 @@ -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; }