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: extract probably_looking_at_definitio...
details: https://anonhg.NetBSD.org/src/rev/b36f287e23d7
branches: trunk
changeset: 1026453:b36f287e23d7
user: rillig <rillig%NetBSD.org@localhost>
date: Thu Nov 25 16:09:02 2021 +0000
description:
indent: extract probably_looking_at_definition to separate function
This heuristic guesses wrong in many cases and will some cleanups.
No functional change.
diffstat:
usr.bin/indent/lexi.c | 28 +++++++++++++++++-----------
1 files changed, 17 insertions(+), 11 deletions(-)
diffs (56 lines):
diff -r 5e2773bb9ce9 -r b36f287e23d7 usr.bin/indent/lexi.c
--- a/usr.bin/indent/lexi.c Thu Nov 25 16:05:07 2021 +0000
+++ b/usr.bin/indent/lexi.c Thu Nov 25 16:09:02 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: lexi.c,v 1.154 2021/11/25 08:08:28 rillig Exp $ */
+/* $NetBSD: lexi.c,v 1.155 2021/11/25 16:09:02 rillig Exp $ */
/*-
* SPDX-License-Identifier: BSD-4-Clause
@@ -43,7 +43,7 @@
#include <sys/cdefs.h>
#if defined(__NetBSD__)
-__RCSID("$NetBSD: lexi.c,v 1.154 2021/11/25 08:08:28 rillig Exp $");
+__RCSID("$NetBSD: lexi.c,v 1.155 2021/11/25 16:09:02 rillig Exp $");
#elif defined(__FreeBSD__)
__FBSDID("$FreeBSD: head/usr.bin/indent/lexi.c 337862 2018-08-15 18:19:45Z pstef $");
#endif
@@ -450,6 +450,15 @@
return strcmp(key, ((const struct keyword *)elem)->name);
}
+static bool
+probably_looking_at_definition(void)
+{
+ for (const char *p = inp_p(), *e = inp_line_end(); p < e;)
+ if (*p++ == ')' && (*p == ';' || *p == ','))
+ return false;
+ return true;
+}
+
/* Read an alphanumeric token into 'token', or return lsym_eof. */
static lexer_symbol
lexi_alnum(void)
@@ -508,15 +517,12 @@
if (inp_peek() == '(' && ps.tos <= 1 && ps.ind_level == 0 &&
!ps.in_parameter_declaration && !ps.block_init) {
- for (const char *p = inp_p(), *e = inp_line_end(); p < e;)
- if (*p++ == ')' && (*p == ';' || *p == ','))
- goto no_function_definition;
-
- ps.is_function_definition = true;
- if (ps.in_decl)
- ps.in_parameter_declaration = true;
- return lsym_funcname;
-no_function_definition:;
+ if (probably_looking_at_definition()) {
+ ps.is_function_definition = true;
+ if (ps.in_decl)
+ ps.in_parameter_declaration = true;
+ return lsym_funcname;
+ }
} else if (ps.p_l_follow == 0 && probably_typename()) {
ps.next_unary = true;
Home |
Main Index |
Thread Index |
Old Index