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_typedef into separat...
details: https://anonhg.NetBSD.org/src/rev/c035d5a9a0e2
branches: trunk
changeset: 1023760:c035d5a9a0e2
user: rillig <rillig%NetBSD.org@localhost>
date: Sat Sep 25 20:05:55 2021 +0000
description:
indent: extract probably_typedef into separate function
This condition is complicated enough that it warrants being split into
several clauses, maybe even with an explanation.
No functional change.
diffstat:
usr.bin/indent/lexi.c | 31 +++++++++++++++++--------------
1 files changed, 17 insertions(+), 14 deletions(-)
diffs (59 lines):
diff -r d5e98e3ac0ea -r c035d5a9a0e2 usr.bin/indent/lexi.c
--- a/usr.bin/indent/lexi.c Sat Sep 25 19:49:13 2021 +0000
+++ b/usr.bin/indent/lexi.c Sat Sep 25 20:05:55 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: lexi.c,v 1.56 2021/09/25 19:49:13 rillig Exp $ */
+/* $NetBSD: lexi.c,v 1.57 2021/09/25 20:05:55 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.56 2021/09/25 19:49:13 rillig Exp $");
+__RCSID("$NetBSD: lexi.c,v 1.57 2021/09/25 20:05:55 rillig Exp $");
#elif defined(__FreeBSD__)
__FBSDID("$FreeBSD: head/usr.bin/indent/lexi.c 337862 2018-08-15 18:19:45Z pstef $");
#endif
@@ -336,6 +336,20 @@
}
}
+/*
+ * This hack attempts to guess whether the current token is in fact a
+ * declaration keyword -- one that has been defined by typedef.
+ */
+static bool
+probably_typedef(const struct parser_state *state)
+{
+ return state->p_l_follow == 0 && !state->block_init && !state->in_stmt &&
+ ((*buf_ptr == '*' && buf_ptr[1] != '=') ||
+ isalpha((unsigned char)*buf_ptr)) &&
+ (state->last_token == semicolon || state->last_token == lbrace ||
+ state->last_token == rbrace);
+}
+
/* Reads the next token, placing it in the global variable "token". */
token_type
lexi(struct parser_state *state)
@@ -460,18 +474,7 @@
state->in_parameter_declaration = true;
return lexi_end(funcname);
not_proc:;
- }
- /*
- * The following hack attempts to guess whether or not the current
- * token is in fact a declaration keyword -- one that has been
- * typedefd
- */
- else if (state->p_l_follow == 0 && !state->block_init &&
- !state->in_stmt &&
- ((*buf_ptr == '*' && buf_ptr[1] != '=') ||
- isalpha((unsigned char)*buf_ptr)) &&
- (state->last_token == semicolon || state->last_token == lbrace ||
- state->last_token == rbrace)) {
+ } else if (probably_typedef(state)) {
state->keyword = rw_type;
state->last_u_d = true;
return lexi_end(decl);
Home |
Main Index |
Thread Index |
Old Index