Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/usr.bin/indent lint: use separate lexer symbols for 'case' a...
details: https://anonhg.NetBSD.org/src/rev/5d9f5a3dae7f
branches: trunk
changeset: 376196:5d9f5a3dae7f
user: rillig <rillig%NetBSD.org@localhost>
date: Sun Jun 04 12:46:57 2023 +0000
description:
lint: use separate lexer symbols for 'case' and 'default'
It's not strictly necessary since these tokens behave in the same way,
still, the code is more straight-forward when there are separate tokens.
diffstat:
tests/usr.bin/indent/lsym_case_label.c | 7 +++----
usr.bin/indent/debug.c | 7 ++++---
usr.bin/indent/indent.c | 7 ++++---
usr.bin/indent/indent.h | 13 +++++++------
usr.bin/indent/lexi.c | 8 ++++----
5 files changed, 22 insertions(+), 20 deletions(-)
diffs (153 lines):
diff -r a0aea2e814c1 -r 5d9f5a3dae7f tests/usr.bin/indent/lsym_case_label.c
--- a/tests/usr.bin/indent/lsym_case_label.c Sun Jun 04 11:45:00 2023 +0000
+++ b/tests/usr.bin/indent/lsym_case_label.c Sun Jun 04 12:46:57 2023 +0000
@@ -1,9 +1,8 @@
-/* $NetBSD: lsym_case_label.c,v 1.6 2022/04/24 09:04:12 rillig Exp $ */
+/* $NetBSD: lsym_case_label.c,v 1.7 2023/06/04 12:46:57 rillig Exp $ */
/*
- * Tests for the token lsym_case_label, which represents either the keyword
- * 'case' or the keyword 'default', which are both used in 'switch'
- * statements.
+ * Tests for the tokens lsym_case and lsym_default, which represent the
+ * keywords 'case' and 'default', which are both used in 'switch' statements.
*
* Since C11, the keyword 'default' is used in _Generic selections as well.
*
diff -r a0aea2e814c1 -r 5d9f5a3dae7f usr.bin/indent/debug.c
--- a/usr.bin/indent/debug.c Sun Jun 04 11:45:00 2023 +0000
+++ b/usr.bin/indent/debug.c Sun Jun 04 12:46:57 2023 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: debug.c,v 1.29 2023/06/04 11:45:00 rillig Exp $ */
+/* $NetBSD: debug.c,v 1.30 2023/06/04 12:46:57 rillig Exp $ */
/*-
* Copyright (c) 2023 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
*/
#include <sys/cdefs.h>
-__RCSID("$NetBSD: debug.c,v 1.29 2023/06/04 11:45:00 rillig Exp $");
+__RCSID("$NetBSD: debug.c,v 1.30 2023/06/04 12:46:57 rillig Exp $");
#include <stdarg.h>
@@ -70,7 +70,8 @@ const char *const lsym_name[] = {
"type_outside_parentheses",
"type_in_parentheses",
"tag",
- "case_label",
+ "case",
+ "default",
"sizeof",
"offsetof",
"word",
diff -r a0aea2e814c1 -r 5d9f5a3dae7f usr.bin/indent/indent.c
--- a/usr.bin/indent/indent.c Sun Jun 04 11:45:00 2023 +0000
+++ b/usr.bin/indent/indent.c Sun Jun 04 12:46:57 2023 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: indent.c,v 1.321 2023/06/04 11:45:00 rillig Exp $ */
+/* $NetBSD: indent.c,v 1.322 2023/06/04 12:46:57 rillig Exp $ */
/*-
* SPDX-License-Identifier: BSD-4-Clause
@@ -38,7 +38,7 @@
*/
#include <sys/cdefs.h>
-__RCSID("$NetBSD: indent.c,v 1.321 2023/06/04 11:45:00 rillig Exp $");
+__RCSID("$NetBSD: indent.c,v 1.322 2023/06/04 12:46:57 rillig Exp $");
#include <sys/param.h>
#include <err.h>
@@ -1134,7 +1134,8 @@ process_lsym(lexer_symbol lsym)
process_question();
break;
- case lsym_case_label:
+ case lsym_case:
+ case lsym_default:
ps.seen_case = true;
goto copy_token;
diff -r a0aea2e814c1 -r 5d9f5a3dae7f usr.bin/indent/indent.h
--- a/usr.bin/indent/indent.h Sun Jun 04 11:45:00 2023 +0000
+++ b/usr.bin/indent/indent.h Sun Jun 04 12:46:57 2023 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: indent.h,v 1.166 2023/06/04 11:45:00 rillig Exp $ */
+/* $NetBSD: indent.h,v 1.167 2023/06/04 12:46:57 rillig Exp $ */
/*-
* SPDX-License-Identifier: BSD-2-Clause-FreeBSD
@@ -70,7 +70,7 @@
typedef enum lexer_symbol {
lsym_eof,
- lsym_preprocessing, /* '#' */
+ lsym_preprocessing, /* the initial '#' of a preprocessing line */
lsym_newline,
lsym_comment, /* the initial '/ *' or '//' of a comment */
lsym_lparen,
@@ -97,7 +97,8 @@ typedef enum lexer_symbol {
lsym_type_outside_parentheses,
lsym_type_in_parentheses,
lsym_tag, /* 'struct', 'union' or 'enum' */
- lsym_case_label, /* 'case' or 'default' */
+ lsym_case,
+ lsym_default,
lsym_sizeof,
lsym_offsetof,
lsym_word, /* identifier, constant or string */
@@ -108,7 +109,7 @@ typedef enum lexer_symbol {
lsym_if,
lsym_switch,
lsym_while,
- lsym_return
+ lsym_return,
} lexer_symbol;
typedef enum parser_symbol {
@@ -316,8 +317,8 @@ extern struct parser_state {
* processing of braces is then slightly
* different */
bool in_func_def_params;
- bool seen_case; /* set to true when we see a 'case', so we know
- * what to do with the following colon */
+ bool seen_case; /* whether there was a 'case' or 'default',
+ * to properly space the following ':' */
parser_symbol spaced_expr_psym; /* the parser symbol to be shifted
* after the parenthesized expression
* from a 'for', 'if', 'switch' or
diff -r a0aea2e814c1 -r 5d9f5a3dae7f usr.bin/indent/lexi.c
--- a/usr.bin/indent/lexi.c Sun Jun 04 11:45:00 2023 +0000
+++ b/usr.bin/indent/lexi.c Sun Jun 04 12:46:57 2023 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: lexi.c,v 1.209 2023/06/04 11:45:00 rillig Exp $ */
+/* $NetBSD: lexi.c,v 1.210 2023/06/04 12:46:57 rillig Exp $ */
/*-
* SPDX-License-Identifier: BSD-4-Clause
@@ -38,7 +38,7 @@
*/
#include <sys/cdefs.h>
-__RCSID("$NetBSD: lexi.c,v 1.209 2023/06/04 11:45:00 rillig Exp $");
+__RCSID("$NetBSD: lexi.c,v 1.210 2023/06/04 12:46:57 rillig Exp $");
#include <stdlib.h>
#include <string.h>
@@ -59,12 +59,12 @@ static const struct keyword {
{"auto", lsym_modifier},
{"bool", lsym_type},
{"break", lsym_word},
- {"case", lsym_case_label},
+ {"case", lsym_case},
{"char", lsym_type},
{"complex", lsym_type},
{"const", lsym_modifier},
{"continue", lsym_word},
- {"default", lsym_case_label},
+ {"default", lsym_default},
{"do", lsym_do},
{"double", lsym_type},
{"else", lsym_else},
Home |
Main Index |
Thread Index |
Old Index