Fri Jun 16 23:51:32 2023 UTC ()
indent: merge lexer symbols for type in/outside parentheses
(rillig)
diff -r1.1270 -r1.1271 src/distrib/sets/lists/tests/mi
diff -r1.48 -r1.49 src/tests/usr.bin/indent/Makefile
diff -r1.58 -r1.59 src/tests/usr.bin/indent/fmt_decl.c
diff -r0 -r1.1 src/tests/usr.bin/indent/lsym_type.c
diff -r1.4 -r0 src/tests/usr.bin/indent/lsym_type_in_parentheses.c
diff -r1.7 -r0 src/tests/usr.bin/indent/lsym_type_outside_parentheses.c
diff -r1.65 -r1.66 src/usr.bin/indent/debug.c
diff -r1.378 -r1.379 src/usr.bin/indent/indent.c
diff -r1.201 -r1.202 src/usr.bin/indent/indent.h
diff -r1.229 -r1.230 src/usr.bin/indent/lexi.c
--- src/distrib/sets/lists/tests/mi 2023/06/16 20:38:19 1.1270
+++ src/distrib/sets/lists/tests/mi 2023/06/16 23:51:31 1.1271
@@ -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
--- src/tests/usr.bin/indent/Makefile 2023/06/14 07:20:55 1.48
+++ src/tests/usr.bin/indent/Makefile 2023/06/16 23:51:32 1.49
@@ -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_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
--- src/tests/usr.bin/indent/fmt_decl.c 2023/06/16 12:30:45 1.58
+++ src/tests/usr.bin/indent/fmt_decl.c 2023/06/16 23:51:32 1.59
@@ -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
@@ -926,10 +926,6 @@
//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);
/* $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
--- src/usr.bin/indent/debug.c 2023/06/16 23:17:22 1.65
+++ src/usr.bin/indent/debug.c 2023/06/16 23:51:32 1.66
@@ -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 @@
"typedef",
"modifier",
"tag",
- "type_outside_parentheses",
- "type_in_parentheses",
+ "type",
"word",
"funcname",
"label_colon",
--- src/usr.bin/indent/indent.c 2023/06/16 23:07:52 1.378
+++ src/usr.bin/indent/indent.c 2023/06/16 23:51:32 1.379
@@ -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 @@
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 @@
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:
--- src/usr.bin/indent/indent.h 2023/06/16 12:30:45 1.201
+++ src/usr.bin/indent/indent.h 2023/06/16 23:51:32 1.202
@@ -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 @@
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 */
--- src/usr.bin/indent/lexi.c 2023/06/14 16:14:30 1.229
+++ src/usr.bin/indent/lexi.c 2023/06/16 23:51:32 1.230
@@ -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 @@
|| 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 @@
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 @@
}
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 @@
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 @@
} else if (ps.paren.len == 0 && probably_typename()) {
ps.next_unary = true;
- return lsym_type_outside_parentheses;
+ return lsym_type;
}
return lsym;