Module Name: src
Committed By: rillig
Date: Sat May 20 00:17:56 UTC 2023
Modified Files:
src/usr.bin/indent: indent.h lexi.c
Log Message:
indent: separate detection of function definitions from lexing '*'
No functional change.
To generate a diff of this commit:
cvs rdiff -u -r1.150 -r1.151 src/usr.bin/indent/indent.h
cvs rdiff -u -r1.199 -r1.200 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/usr.bin/indent/indent.h
diff -u src/usr.bin/indent/indent.h:1.150 src/usr.bin/indent/indent.h:1.151
--- src/usr.bin/indent/indent.h:1.150 Thu May 18 08:09:28 2023
+++ src/usr.bin/indent/indent.h Sat May 20 00:17:56 2023
@@ -1,4 +1,4 @@
-/* $NetBSD: indent.h,v 1.150 2023/05/18 08:09:28 rillig Exp $ */
+/* $NetBSD: indent.h,v 1.151 2023/05/20 00:17:56 rillig Exp $ */
/*-
* SPDX-License-Identifier: BSD-2-Clause-FreeBSD
@@ -286,7 +286,13 @@ extern struct parser_state {
int quest_level; /* when this is positive, we have seen a '?'
* without the matching ':' in a '?:'
* expression */
- bool is_function_definition;
+ bool is_function_definition; /* starts either at the 'name(' from a
+ * function definition if it occurs at
+ * the beginning of a line, or at the
+ * first '*' from inside a declaration
+ * when the line starts with words
+ * followed by a '('; ends at the end
+ * of that line */
bool block_init; /* whether inside a block initialization */
int block_init_level; /* the level of brace nesting in an
* initialization */
Index: src/usr.bin/indent/lexi.c
diff -u src/usr.bin/indent/lexi.c:1.199 src/usr.bin/indent/lexi.c:1.200
--- src/usr.bin/indent/lexi.c:1.199 Thu May 18 05:33:27 2023
+++ src/usr.bin/indent/lexi.c Sat May 20 00:17:56 2023
@@ -1,4 +1,4 @@
-/* $NetBSD: lexi.c,v 1.199 2023/05/18 05:33:27 rillig Exp $ */
+/* $NetBSD: lexi.c,v 1.200 2023/05/20 00:17:56 rillig Exp $ */
/*-
* SPDX-License-Identifier: BSD-4-Clause
@@ -38,7 +38,7 @@
*/
#include <sys/cdefs.h>
-__RCSID("$NetBSD: lexi.c,v 1.199 2023/05/18 05:33:27 rillig Exp $");
+__RCSID("$NetBSD: lexi.c,v 1.200 2023/05/20 00:17:56 rillig Exp $");
#include <stdlib.h>
#include <string.h>
@@ -447,6 +447,22 @@ is_asterisk_unary(void)
return ps.in_decl && ps.nparen > 0;
}
+static bool
+probably_in_function_definition(void)
+{
+ for (const char *tp = inp.st; *tp != '\n';) {
+ if (ch_isspace(*tp))
+ tp++;
+ else if (is_identifier_start(*tp)) {
+ tp++;
+ while (is_identifier_part(*tp))
+ tp++;
+ } else
+ return *tp == '(';
+ }
+ return false;
+}
+
static void
lex_asterisk_unary(void)
{
@@ -456,21 +472,8 @@ lex_asterisk_unary(void)
inp_skip();
}
- if (ps.in_decl) {
- for (const char *tp = inp.st; *tp != '\n';) {
- if (ch_isspace(*tp))
- tp++;
- else if (is_identifier_start(*tp)) {
- tp++;
- while (is_identifier_part(*tp))
- tp++;
- } else {
- if (*tp == '(')
- ps.is_function_definition = true;
- break;
- }
- }
- }
+ if (ps.in_decl && probably_in_function_definition())
+ ps.is_function_definition = true;
}
static void