Module Name: src Committed By: rillig Date: Fri Jun 16 23:51:32 UTC 2023
Modified Files: src/distrib/sets/lists/tests: mi src/tests/usr.bin/indent: Makefile fmt_decl.c src/usr.bin/indent: debug.c indent.c indent.h lexi.c Added Files: src/tests/usr.bin/indent: lsym_type.c Removed Files: src/tests/usr.bin/indent: lsym_type_in_parentheses.c lsym_type_outside_parentheses.c Log Message: indent: merge lexer symbols for type in/outside parentheses To generate a diff of this commit: cvs rdiff -u -r1.1270 -r1.1271 src/distrib/sets/lists/tests/mi cvs rdiff -u -r1.48 -r1.49 src/tests/usr.bin/indent/Makefile cvs rdiff -u -r1.58 -r1.59 src/tests/usr.bin/indent/fmt_decl.c cvs rdiff -u -r0 -r1.1 src/tests/usr.bin/indent/lsym_type.c cvs rdiff -u -r1.4 -r0 src/tests/usr.bin/indent/lsym_type_in_parentheses.c cvs rdiff -u -r1.7 -r0 \ src/tests/usr.bin/indent/lsym_type_outside_parentheses.c cvs rdiff -u -r1.65 -r1.66 src/usr.bin/indent/debug.c cvs rdiff -u -r1.378 -r1.379 src/usr.bin/indent/indent.c cvs rdiff -u -r1.201 -r1.202 src/usr.bin/indent/indent.h cvs rdiff -u -r1.229 -r1.230 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/distrib/sets/lists/tests/mi diff -u src/distrib/sets/lists/tests/mi:1.1270 src/distrib/sets/lists/tests/mi:1.1271 --- src/distrib/sets/lists/tests/mi:1.1270 Fri Jun 16 20:38:19 2023 +++ src/distrib/sets/lists/tests/mi Fri Jun 16 23:51:31 2023 @@ -1,4 +1,4 @@ -# $NetBSD: mi,v 1.1270 2023/06/16 20:38:19 wiz Exp $ +# $NetBSD: mi,v 1.1271 2023/06/16 23:51:31 rillig Exp $ # # Note: don't delete entries from here - mark them as "obsolete" instead. # @@ -4973,8 +4973,9 @@ ./usr/tests/usr.bin/indent/lsym_string_prefix.c tests-obsolete obsolete,atf ./usr/tests/usr.bin/indent/lsym_switch.c tests-usr.bin-tests compattestfile,atf ./usr/tests/usr.bin/indent/lsym_tag.c tests-usr.bin-tests compattestfile,atf -./usr/tests/usr.bin/indent/lsym_type_in_parentheses.c tests-usr.bin-tests compattestfile,atf -./usr/tests/usr.bin/indent/lsym_type_outside_parentheses.c tests-usr.bin-tests compattestfile,atf +./usr/tests/usr.bin/indent/lsym_type.c tests-usr.bin-tests compattestfile,atf +./usr/tests/usr.bin/indent/lsym_type_in_parentheses.c tests-obsolete obsolete,atf +./usr/tests/usr.bin/indent/lsym_type_outside_parentheses.c tests-obsolete obsolete,atf ./usr/tests/usr.bin/indent/lsym_typedef.c tests-usr.bin-tests compattestfile,atf ./usr/tests/usr.bin/indent/lsym_unary_op.c tests-usr.bin-tests compattestfile,atf ./usr/tests/usr.bin/indent/lsym_while.c tests-usr.bin-tests compattestfile,atf Index: src/tests/usr.bin/indent/Makefile diff -u src/tests/usr.bin/indent/Makefile:1.48 src/tests/usr.bin/indent/Makefile:1.49 --- src/tests/usr.bin/indent/Makefile:1.48 Wed Jun 14 07:20:55 2023 +++ src/tests/usr.bin/indent/Makefile Fri Jun 16 23:51:32 2023 @@ -1,4 +1,4 @@ -# $NetBSD: Makefile,v 1.48 2023/06/14 07:20:55 rillig Exp $ +# $NetBSD: Makefile,v 1.49 2023/06/16 23:51:32 rillig Exp $ .include <bsd.own.mk> @@ -48,8 +48,7 @@ FILES+= lsym_sizeof.c FILES+= lsym_storage_class.c FILES+= lsym_switch.c FILES+= lsym_tag.c -FILES+= lsym_type_in_parentheses.c -FILES+= lsym_type_outside_parentheses.c +FILES+= lsym_type.c FILES+= lsym_typedef.c FILES+= lsym_unary_op.c FILES+= lsym_while.c Index: src/tests/usr.bin/indent/fmt_decl.c diff -u src/tests/usr.bin/indent/fmt_decl.c:1.58 src/tests/usr.bin/indent/fmt_decl.c:1.59 --- src/tests/usr.bin/indent/fmt_decl.c:1.58 Fri Jun 16 12:30:45 2023 +++ src/tests/usr.bin/indent/fmt_decl.c Fri Jun 16 23:51:32 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: fmt_decl.c,v 1.58 2023/06/16 12:30:45 rillig Exp $ */ +/* $NetBSD: fmt_decl.c,v 1.59 2023/06/16 23:51:32 rillig Exp $ */ /* * Tests for declarations of global variables, external functions, and local @@ -927,10 +927,6 @@ ch_isalpha(char ch) //indent run -i4 -di0 // $ FIXME: 'buffer' is classified as 'word'. // $ -// $ XXX: 'char' is classified as 'type_in_parentheses'; check whether -// $ XXX: lsym_type_in_parentheses should only be used for types in cast -// $ XXX: expressions. -// $ // $ FIXME: 'size_t' is classified as 'word'. void buf_add_chars(struct buffer *, const char *, size_t); Index: src/usr.bin/indent/debug.c diff -u src/usr.bin/indent/debug.c:1.65 src/usr.bin/indent/debug.c:1.66 --- src/usr.bin/indent/debug.c:1.65 Fri Jun 16 23:17:22 2023 +++ src/usr.bin/indent/debug.c Fri Jun 16 23:51:32 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: debug.c,v 1.65 2023/06/16 23:17:22 rillig Exp $ */ +/* $NetBSD: debug.c,v 1.66 2023/06/16 23:51:32 rillig Exp $ */ /*- * Copyright (c) 2023 The NetBSD Foundation, Inc. @@ -30,7 +30,7 @@ */ #include <sys/cdefs.h> -__RCSID("$NetBSD: debug.c,v 1.65 2023/06/16 23:17:22 rillig Exp $"); +__RCSID("$NetBSD: debug.c,v 1.66 2023/06/16 23:51:32 rillig Exp $"); #include <stdarg.h> #include <string.h> @@ -70,8 +70,7 @@ const char *const lsym_name[] = { "typedef", "modifier", "tag", - "type_outside_parentheses", - "type_in_parentheses", + "type", "word", "funcname", "label_colon", Index: src/usr.bin/indent/indent.c diff -u src/usr.bin/indent/indent.c:1.378 src/usr.bin/indent/indent.c:1.379 --- src/usr.bin/indent/indent.c:1.378 Fri Jun 16 23:07:52 2023 +++ src/usr.bin/indent/indent.c Fri Jun 16 23:51:32 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: indent.c,v 1.378 2023/06/16 23:07:52 rillig Exp $ */ +/* $NetBSD: indent.c,v 1.379 2023/06/16 23:51:32 rillig Exp $ */ /*- * SPDX-License-Identifier: BSD-4-Clause @@ -38,7 +38,7 @@ */ #include <sys/cdefs.h> -__RCSID("$NetBSD: indent.c,v 1.378 2023/06/16 23:07:52 rillig Exp $"); +__RCSID("$NetBSD: indent.c,v 1.379 2023/06/16 23:51:32 rillig Exp $"); #include <sys/param.h> #include <err.h> @@ -345,7 +345,7 @@ update_ps_lbrace_kind(lexer_symbol lsym) ps.lbrace_kind = token.s[0] == 's' ? psym_lbrace_struct : token.s[0] == 'u' ? psym_lbrace_union : psym_lbrace_enum; - } else if (lsym == lsym_type_outside_parentheses + } else if ((lsym == lsym_type && ps.paren.len == 0) || lsym == lsym_word || lsym == lsym_lbrace) { /* Keep the current '{' kind. */ @@ -1054,11 +1054,12 @@ process_lsym(lexer_symbol lsym) if (ps.paren.len > 0) goto copy_token; /* FALLTHROUGH */ - case lsym_type_outside_parentheses: - process_type_outside_parentheses(); - goto copy_token; - - case lsym_type_in_parentheses: + case lsym_type: + if (ps.paren.len == 0) { + process_type_outside_parentheses(); + goto copy_token; + } + /* FALLTHROUGH */ case lsym_sizeof: case lsym_offsetof: case lsym_word: Index: src/usr.bin/indent/indent.h diff -u src/usr.bin/indent/indent.h:1.201 src/usr.bin/indent/indent.h:1.202 --- src/usr.bin/indent/indent.h:1.201 Fri Jun 16 12:30:45 2023 +++ src/usr.bin/indent/indent.h Fri Jun 16 23:51:32 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: indent.h,v 1.201 2023/06/16 12:30:45 rillig Exp $ */ +/* $NetBSD: indent.h,v 1.202 2023/06/16 23:51:32 rillig Exp $ */ /*- * SPDX-License-Identifier: BSD-2-Clause-FreeBSD @@ -94,8 +94,7 @@ typedef enum lexer_symbol { lsym_typedef, lsym_modifier, /* modifiers for types, functions, variables */ lsym_tag, /* 'struct', 'union' or 'enum' */ - lsym_type_outside_parentheses, - lsym_type_in_parentheses, + lsym_type, lsym_word, /* identifier, constant or string */ lsym_funcname, /* name of a function being defined */ lsym_label_colon, /* the ':' after a label */ Index: src/usr.bin/indent/lexi.c diff -u src/usr.bin/indent/lexi.c:1.229 src/usr.bin/indent/lexi.c:1.230 --- src/usr.bin/indent/lexi.c:1.229 Wed Jun 14 16:14:30 2023 +++ src/usr.bin/indent/lexi.c Fri Jun 16 23:51:32 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: lexi.c,v 1.229 2023/06/14 16:14:30 rillig Exp $ */ +/* $NetBSD: lexi.c,v 1.230 2023/06/16 23:51:32 rillig Exp $ */ /*- * SPDX-License-Identifier: BSD-4-Clause @@ -38,16 +38,13 @@ */ #include <sys/cdefs.h> -__RCSID("$NetBSD: lexi.c,v 1.229 2023/06/14 16:14:30 rillig Exp $"); +__RCSID("$NetBSD: lexi.c,v 1.230 2023/06/16 23:51:32 rillig Exp $"); #include <stdlib.h> #include <string.h> #include "indent.h" -/* In lexi_alnum, this constant marks a type, independent of parentheses. */ -#define lsym_type lsym_type_outside_parentheses - /* must be sorted alphabetically, is used in binary search */ static const struct keyword { const char name[12]; @@ -398,7 +395,7 @@ lexi_alnum(void) || ps.prev_lsym == lsym_typedef; if (ps.prev_lsym == lsym_tag && ps.paren.len == 0) - return lsym_type_outside_parentheses; + return lsym_type; token_add_char('\0'); token.len--; @@ -407,7 +404,7 @@ lexi_alnum(void) lexer_symbol lsym = lsym_word; if (kw != NULL) { if (kw->lsym == lsym_type) - lsym = lsym_type_in_parentheses; + lsym = lsym_type; ps.next_unary = true; if (kw->lsym == lsym_tag || kw->lsym == lsym_type) goto found_typename; @@ -415,7 +412,7 @@ lexi_alnum(void) } if (is_typename()) { - lsym = lsym_type_in_parentheses; + lsym = lsym_type; ps.next_unary = true; found_typename: if (ps.paren.len > 0) { @@ -431,7 +428,7 @@ found_typename: if (kw != NULL && kw->lsym == lsym_tag) return lsym_tag; if (ps.paren.len == 0) - return lsym_type_outside_parentheses; + return lsym_type; } } @@ -447,7 +444,7 @@ found_typename: } else if (ps.paren.len == 0 && probably_typename()) { ps.next_unary = true; - return lsym_type_outside_parentheses; + return lsym_type; } return lsym; Added files: Index: src/tests/usr.bin/indent/lsym_type.c diff -u /dev/null src/tests/usr.bin/indent/lsym_type.c:1.1 --- /dev/null Fri Jun 16 23:51:32 2023 +++ src/tests/usr.bin/indent/lsym_type.c Fri Jun 16 23:51:32 2023 @@ -0,0 +1,63 @@ +/* $NetBSD: lsym_type.c,v 1.1 2023/06/16 23:51:32 rillig Exp $ */ + +/* + * Tests for the token lsym_type, which represents a type name in the following + * contexts: + * + * In a declaration that is not for a function. + * + * As part of a parameter list of a function prototype. + * + * In a cast expression. + * + * In a compound expression (since C99). + * + * See also: + * fmt_decl + * lex_ident + * lsym_word + * opt_ta + * opt_T + */ + +/* + * Indent has to guess which identifiers are types and which are variables. + */ +//indent input +t1 *no_init_ptr; +t2 *init_ptr = 0; +const t3 *const_no_init_ptr; +static t4 *static_no_init_ptr; +typedef t5 *typedef_no_init_ptr; + +// $ XXX: There's no point aligning the word 'const' with the other names. +const char *const names[3]; +//indent end + +//indent run-equals-input -di24 + + +//indent input +{ +{} +size_t hello; +} +//indent end + +//indent run +{ + { + } + size_t hello; +} +//indent end + + +/* + * In a sizeof expression, a type argument must be enclosed in parentheses. + */ +//indent input +int sizeof_int = sizeof int; +//indent end + +//indent run-equals-input -di0