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: merge lexer symbols for type in/outsi...



details:   https://anonhg.NetBSD.org/src/rev/7ad05f028c53
branches:  trunk
changeset: 376421:7ad05f028c53
user:      rillig <rillig%NetBSD.org@localhost>
date:      Fri Jun 16 23:51:31 2023 +0000

description:
indent: merge lexer symbols for type in/outside parentheses

diffstat:

 distrib/sets/lists/tests/mi                          |   7 +-
 tests/usr.bin/indent/Makefile                        |   5 +-
 tests/usr.bin/indent/fmt_decl.c                      |   6 +-
 tests/usr.bin/indent/lsym_type.c                     |  63 ++++++++++++++++++++
 tests/usr.bin/indent/lsym_type_in_parentheses.c      |  18 -----
 tests/usr.bin/indent/lsym_type_outside_parentheses.c |  57 ------------------
 usr.bin/indent/debug.c                               |   7 +-
 usr.bin/indent/indent.c                              |  17 ++--
 usr.bin/indent/indent.h                              |   5 +-
 usr.bin/indent/lexi.c                                |  17 ++---
 10 files changed, 91 insertions(+), 111 deletions(-)

diffs (truncated from 374 to 300 lines):

diff -r 02b8afddb457 -r 7ad05f028c53 distrib/sets/lists/tests/mi
--- a/distrib/sets/lists/tests/mi       Fri Jun 16 23:36:26 2023 +0000
+++ b/distrib/sets/lists/tests/mi       Fri Jun 16 23:51:31 2023 +0000
@@ -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
diff -r 02b8afddb457 -r 7ad05f028c53 tests/usr.bin/indent/Makefile
--- a/tests/usr.bin/indent/Makefile     Fri Jun 16 23:36:26 2023 +0000
+++ b/tests/usr.bin/indent/Makefile     Fri Jun 16 23:51:31 2023 +0000
@@ -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
diff -r 02b8afddb457 -r 7ad05f028c53 tests/usr.bin/indent/fmt_decl.c
--- a/tests/usr.bin/indent/fmt_decl.c   Fri Jun 16 23:36:26 2023 +0000
+++ b/tests/usr.bin/indent/fmt_decl.c   Fri Jun 16 23:51:31 2023 +0000
@@ -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);
 
diff -r 02b8afddb457 -r 7ad05f028c53 tests/usr.bin/indent/lsym_type.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/usr.bin/indent/lsym_type.c  Fri Jun 16 23:51:31 2023 +0000
@@ -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
diff -r 02b8afddb457 -r 7ad05f028c53 tests/usr.bin/indent/lsym_type_in_parentheses.c
--- a/tests/usr.bin/indent/lsym_type_in_parentheses.c   Fri Jun 16 23:36:26 2023 +0000
+++ /dev/null   Thu Jan 01 00:00:00 1970 +0000
@@ -1,18 +0,0 @@
-/* $NetBSD: lsym_type_in_parentheses.c,v 1.4 2023/05/21 10:18:44 rillig Exp $ */
-
-/*
- * Tests for the token lsym_type_in_parentheses, which represents a type name
- * inside parentheses in the following contexts:
- *
- * As part of a parameter list of a function prototype.
- *
- * In a cast expression.
- *
- * In a compound expression (since C99).
- */
-
-//indent input
-// TODO: add input
-//indent end
-
-//indent run-equals-input
diff -r 02b8afddb457 -r 7ad05f028c53 tests/usr.bin/indent/lsym_type_outside_parentheses.c
--- a/tests/usr.bin/indent/lsym_type_outside_parentheses.c      Fri Jun 16 23:36:26 2023 +0000
+++ /dev/null   Thu Jan 01 00:00:00 1970 +0000
@@ -1,57 +0,0 @@
-/* $NetBSD: lsym_type_outside_parentheses.c,v 1.7 2023/06/15 09:19:07 rillig Exp $ */
-
-/*
- * Tests for the token lsym_type_outside_parentheses, which represents a type
- * name outside parentheses, such as in a declaration that is not for a
- * function.
- *
- * See also:
- *     fmt_decl
- *     lex_ident
- *     lsym_type_in_parentheses
- *     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
diff -r 02b8afddb457 -r 7ad05f028c53 usr.bin/indent/debug.c
--- a/usr.bin/indent/debug.c    Fri Jun 16 23:36:26 2023 +0000
+++ b/usr.bin/indent/debug.c    Fri Jun 16 23:51:31 2023 +0000
@@ -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",
diff -r 02b8afddb457 -r 7ad05f028c53 usr.bin/indent/indent.c
--- a/usr.bin/indent/indent.c   Fri Jun 16 23:36:26 2023 +0000
+++ b/usr.bin/indent/indent.c   Fri Jun 16 23:51:31 2023 +0000
@@ -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:
diff -r 02b8afddb457 -r 7ad05f028c53 usr.bin/indent/indent.h
--- a/usr.bin/indent/indent.h   Fri Jun 16 23:36:26 2023 +0000
+++ b/usr.bin/indent/indent.h   Fri Jun 16 23:51:31 2023 +0000
@@ -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 */



Home | Main Index | Thread Index | Old Index