Module Name: src Committed By: rillig Date: Sun Jun 4 12:46:57 UTC 2023
Modified Files: src/tests/usr.bin/indent: lsym_case_label.c src/usr.bin/indent: debug.c indent.c indent.h lexi.c Log Message: 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. To generate a diff of this commit: cvs rdiff -u -r1.6 -r1.7 src/tests/usr.bin/indent/lsym_case_label.c cvs rdiff -u -r1.29 -r1.30 src/usr.bin/indent/debug.c cvs rdiff -u -r1.321 -r1.322 src/usr.bin/indent/indent.c cvs rdiff -u -r1.166 -r1.167 src/usr.bin/indent/indent.h cvs rdiff -u -r1.209 -r1.210 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/tests/usr.bin/indent/lsym_case_label.c diff -u src/tests/usr.bin/indent/lsym_case_label.c:1.6 src/tests/usr.bin/indent/lsym_case_label.c:1.7 --- src/tests/usr.bin/indent/lsym_case_label.c:1.6 Sun Apr 24 09:04:12 2022 +++ src/tests/usr.bin/indent/lsym_case_label.c Sun Jun 4 12:46:57 2023 @@ -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. * Index: src/usr.bin/indent/debug.c diff -u src/usr.bin/indent/debug.c:1.29 src/usr.bin/indent/debug.c:1.30 --- src/usr.bin/indent/debug.c:1.29 Sun Jun 4 11:45:00 2023 +++ src/usr.bin/indent/debug.c Sun Jun 4 12:46:57 2023 @@ -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", Index: src/usr.bin/indent/indent.c diff -u src/usr.bin/indent/indent.c:1.321 src/usr.bin/indent/indent.c:1.322 --- src/usr.bin/indent/indent.c:1.321 Sun Jun 4 11:45:00 2023 +++ src/usr.bin/indent/indent.c Sun Jun 4 12:46:57 2023 @@ -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; Index: src/usr.bin/indent/indent.h diff -u src/usr.bin/indent/indent.h:1.166 src/usr.bin/indent/indent.h:1.167 --- src/usr.bin/indent/indent.h:1.166 Sun Jun 4 11:45:00 2023 +++ src/usr.bin/indent/indent.h Sun Jun 4 12:46:57 2023 @@ -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 Index: src/usr.bin/indent/lexi.c diff -u src/usr.bin/indent/lexi.c:1.209 src/usr.bin/indent/lexi.c:1.210 --- src/usr.bin/indent/lexi.c:1.209 Sun Jun 4 11:45:00 2023 +++ src/usr.bin/indent/lexi.c Sun Jun 4 12:46:57 2023 @@ -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},