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: fix spacing for unknown type names in...



details:   https://anonhg.NetBSD.org/src/rev/8a70368600b5
branches:  trunk
changeset: 1026454:8a70368600b5
user:      rillig <rillig%NetBSD.org@localhost>
date:      Thu Nov 25 16:41:33 2021 +0000

description:
indent: fix spacing for unknown type names in declarations

diffstat:

 tests/usr.bin/indent/fmt_decl.c |  93 +++++++++++++++++++---------------------
 usr.bin/indent/lexi.c           |   7 +-
 2 files changed, 48 insertions(+), 52 deletions(-)

diffs (195 lines):

diff -r b36f287e23d7 -r 8a70368600b5 tests/usr.bin/indent/fmt_decl.c
--- a/tests/usr.bin/indent/fmt_decl.c   Thu Nov 25 16:09:02 2021 +0000
+++ b/tests/usr.bin/indent/fmt_decl.c   Thu Nov 25 16:41:33 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: fmt_decl.c,v 1.25 2021/11/25 16:05:07 rillig Exp $     */
+/*     $NetBSD: fmt_decl.c,v 1.26 2021/11/25 16:41:33 rillig Exp $     */
 /* $FreeBSD: head/usr.bin/indent/tests/declarations.0 334478 2018-06-01 09:41:15Z pstef $ */
 
 /*
@@ -558,16 +558,25 @@
  * similar to the binary operator '*' because it was surrounded by two
  * identifiers.
  *
- * As of 2021-11-21, indent interprets the '*' in the function declaration in
- * line 1 as a binary operator, even though it is followed by a ',' directly.
- * In the function declaration in line 2, as well as the function definition
- * in line 4, indent interprets the '*' as a binary operator as well, which
- * kind of makes sense since it is surrounded by words, but it's still in a
- * declaration.
+ * As of 2021-11-21, indent interpreted the '*' in the function declaration in
+ * line 1 as a binary operator, even though the '*' was followed by a ','
+ * directly. This was not visible in the output though since indent never
+ * outputs a space before a comma.
  *
- * Essentially, as of 2021, indent has missed the last 31 years of advances in
- * the C programming language.  Instead, the workaround has been to pass all
- * type names via the options '-ta' and '-T'.
+ * In the function declaration in line 2 and the function definition in line
+ * 5, indent interpreted the '*' as a binary operator as well and accordingly
+ * placed spaces around the '*'. On a very low syntactical analysis level,
+ * this may have made sense since the '*' was surrounded by words, but still
+ * the '*' is part of a declaration, where a binary operator does not make
+ * sense.
+ *
+ * Essentially, as of 2021, indent had missed the last 31 years of advances in
+ * the C programming language, in particular the invention of function
+ * prototypes. Instead, the workaround had been to require all type names to
+ * be specified via the options '-ta' and '-T'. This put the burden on the
+ * user instead of the implementer.
+ *
+ * Fixed in lexi.c 1.156 from 2021-11-25.
  */
 #indent input
 void           buffer_add(buffer *, char);
@@ -580,16 +589,8 @@
 }
 #indent end
 
-#indent run
-void           buffer_add(buffer *, char);
-void           buffer_add(buffer * buf, char ch);
-
-void
-buffer_add(buffer * buf, char ch)
-{
-       *buf->e++ = ch;
-}
-#indent end
+/* Before lexi.c 1.156 from 2021-11-25, indent generated 'buffer * buf'. */
+#indent run-equals-input
 
 
 /*
@@ -642,7 +643,9 @@
 
 
 /*
- * Indent gets easily confused by unknown type names in declarations.
+ * Before lexi.c 1.156 from 2021-11-25, indent easily got confused by unknown
+ * type names in declarations and generated 'HashEntry * he' with an extra
+ * space.
  */
 #indent input
 static CachedDir *
@@ -656,7 +659,9 @@
 
 
 /*
- * Indent gets easily confused by unknown type names in function declarations.
+ * Before lexi.c 1.156 from 2021-11-25, indent easily got confused by unknown
+ * type names in declarations and generated 'CachedDir * dir' with an extra
+ * space.
  */
 #indent input
 static CachedDir *
@@ -665,18 +670,16 @@
 }
 #indent end
 
-/* FIXME: Extraneous ' ' between '*' and 'dir'. */
-#indent run
-static CachedDir *
-CachedDir_Ref(CachedDir * dir)
-{
-}
-#indent end
+#indent run-equals-input
 
 
 /*
- * In some cases, indent does not get confused by unknown type names. At least
- * it gets the placement of the '{' correct in this example.
+ * Before lexi.c 1.156 from 2021-11-25, indent easily got confused by unknown
+ * type names in declarations and generated 'HashEntry * he' with an extra
+ * space.
+ *
+ * Before lexi.c 1.153 from 2021-11-25, indent also placed the '{' at the end
+ * of the line.
  */
 #indent input
 static bool
@@ -685,17 +688,13 @@
 }
 #indent end
 
-#indent run
-static bool
-HashEntry_KeyEquals(const HashEntry * he, Substring key)
-{
-}
-#indent end
+#indent run-equals-input
 
 
 /*
- * Indent doesn't notice that the two '*' are in a declaration, instead it
- * interprets the first '*' as a binary operator.
+ * Before lexi.c 1.156 from 2021-11-25, indent didn't notice that the two '*'
+ * are in a declaration, instead it interpreted the first '*' as a binary
+ * operator, therefore generating 'CachedDir * *var' with an extra space.
  */
 #indent input
 static void
@@ -704,14 +703,7 @@
 }
 #indent end
 
-/* FIXME: Extraneous space between '*' and '*'. */
-#indent run
-static void
-CachedDir_Assign(CachedDir * *var, CachedDir * dir)
-{
-}
-#indent end
-
+#indent run-equals-input
 #indent run-equals-input -TCachedDir
 
 
@@ -760,12 +752,15 @@
 GNode_VarTarget(GNode *gn) { return GNode_ValueDirect(gn, TARGET); }
 #indent end
 
+/*
+ * Before lexi.c 1.156 from 2021-11-25, indent generated 'GNode * gn' with an
+ * extra space.
+ */
 /* FIXME: The function name must be in column 1 of a separate line. */
 /* FIXME: The '{' must be in column 1 of the next line. */
-/* FIXME: The '*' before 'gn' is extraneous. */
 /* FIXME: The indentation depends on the function body; try 'return 0'. */
 #indent run
-MAKE_INLINE const char *GNode_VarTarget(GNode * gn) {
+MAKE_INLINE const char *GNode_VarTarget(GNode *gn) {
        return GNode_ValueDirect(gn, TARGET);
 }
 #indent end
diff -r b36f287e23d7 -r 8a70368600b5 usr.bin/indent/lexi.c
--- a/usr.bin/indent/lexi.c     Thu Nov 25 16:09:02 2021 +0000
+++ b/usr.bin/indent/lexi.c     Thu Nov 25 16:41:33 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: lexi.c,v 1.155 2021/11/25 16:09:02 rillig Exp $        */
+/*     $NetBSD: lexi.c,v 1.156 2021/11/25 16:41:33 rillig Exp $        */
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -43,7 +43,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__NetBSD__)
-__RCSID("$NetBSD: lexi.c,v 1.155 2021/11/25 16:09:02 rillig Exp $");
+__RCSID("$NetBSD: lexi.c,v 1.156 2021/11/25 16:41:33 rillig Exp $");
 #elif defined(__FreeBSD__)
 __FBSDID("$FreeBSD: head/usr.bin/indent/lexi.c 337862 2018-08-15 18:19:45Z pstef $");
 #endif
@@ -678,7 +678,8 @@
 
     case '*':
        unary_delim = true;
-       if (!ps.next_unary) {
+       if (!ps.next_unary && !ps.in_parameter_declaration &&
+               !(ps.in_decl && ps.p_l_follow > 0)) {
            if (inp_peek() == '=')
                *token.e++ = inp_next();
            lsym = lsym_binary_op;



Home | Main Index | Thread Index | Old Index