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 lex_asterisk_unary into separ...
details: https://anonhg.NetBSD.org/src/rev/9fc33f864139
branches: trunk
changeset: 1026460:9fc33f864139
user: rillig <rillig%NetBSD.org@localhost>
date: Thu Nov 25 17:46:51 2021 +0000
description:
indent: extract lex_asterisk_unary into separate function
No functional change.
diffstat:
tests/usr.bin/indent/lsym_binary_op.c | 15 ++++++++-
usr.bin/indent/lexi.c | 57 +++++++++++++++++++---------------
2 files changed, 45 insertions(+), 27 deletions(-)
diffs (111 lines):
diff -r 68c861a675d5 -r 9fc33f864139 tests/usr.bin/indent/lsym_binary_op.c
--- a/tests/usr.bin/indent/lsym_binary_op.c Thu Nov 25 17:35:46 2021 +0000
+++ b/tests/usr.bin/indent/lsym_binary_op.c Thu Nov 25 17:46:51 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: lsym_binary_op.c,v 1.1 2021/11/18 21:19:19 rillig Exp $ */
+/* $NetBSD: lsym_binary_op.c,v 1.2 2021/11/25 17:46:51 rillig Exp $ */
/* $FreeBSD$ */
/*
@@ -27,3 +27,16 @@
#indent end
#indent run-equals-input
+
+
+/*
+ * If a '*' is immediately followed by another '*', they still form separate
+ * operators. The first is a binary operator, the second is unary.
+ */
+#indent input
+int var = expr**ptr;
+#indent end
+
+#indent run -di0
+int var = expr * *ptr;
+#indent end
diff -r 68c861a675d5 -r 9fc33f864139 usr.bin/indent/lexi.c
--- a/usr.bin/indent/lexi.c Thu Nov 25 17:35:46 2021 +0000
+++ b/usr.bin/indent/lexi.c Thu Nov 25 17:46:51 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: lexi.c,v 1.160 2021/11/25 17:35:46 rillig Exp $ */
+/* $NetBSD: lexi.c,v 1.161 2021/11/25 17:46:51 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.160 2021/11/25 17:35:46 rillig Exp $");
+__RCSID("$NetBSD: lexi.c,v 1.161 2021/11/25 17:46:51 rillig Exp $");
#elif defined(__FreeBSD__)
__FBSDID("$FreeBSD: head/usr.bin/indent/lexi.c 337862 2018-08-15 18:19:45Z pstef $");
#endif
@@ -552,6 +552,34 @@
return is_type ? lsym_type_in_parentheses : lsym_word;
}
+static void
+lex_asterisk_unary(void)
+{
+ while (inp_peek() == '*' || ch_isspace(inp_peek())) {
+ if (inp_peek() == '*')
+ token_add_char('*');
+ inp_skip();
+ }
+
+ if (ps.in_decl) {
+ const char *tp = inp_p(), *e = inp_line_end();
+
+ while (tp < e) {
+ if (ch_isspace(*tp))
+ tp++;
+ else if (is_identifier_start(*tp)) {
+ tp++;
+ while (tp < e && is_identifier_part(*tp))
+ tp++;
+ } else
+ break;
+ }
+
+ if (tp < e && *tp == '(')
+ ps.is_function_definition = true;
+ }
+}
+
/* Reads the next token, placing it in the global variable "token". */
lexer_symbol
lexi(void)
@@ -675,30 +703,7 @@
break;
}
- while (inp_peek() == '*' || ch_isspace(inp_peek())) {
- if (inp_peek() == '*')
- token_add_char('*');
- inp_skip();
- }
-
- if (ps.in_decl) {
- const char *tp = inp_p(), *e = inp_line_end();
-
- while (tp < e) {
- if (ch_isspace(*tp))
- tp++;
- else if (is_identifier_start(*tp)) {
- tp++;
- while (tp < e && is_identifier_part(*tp))
- tp++;
- } else
- break;
- }
-
- if (tp < e && *tp == '(')
- ps.is_function_definition = true;
- }
-
+ lex_asterisk_unary();
lsym = lsym_unary_op;
next_unary = true;
break;
Home |
Main Index |
Thread Index |
Old Index