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 between function prototyp...



details:   https://anonhg.NetBSD.org/src/rev/9e60a4a00e70
branches:  trunk
changeset: 375356:9e60a4a00e70
user:      rillig <rillig%NetBSD.org@localhost>
date:      Mon May 15 14:55:47 2023 +0000

description:
indent: fix spacing between function prototype and attributes

diffstat:

 tests/usr.bin/indent/fmt_decl.c     |  20 ++++++++++----------
 tests/usr.bin/indent/opt_pcs.c      |   5 +++--
 tests/usr.bin/indent/opt_ta.c       |   4 ++--
 tests/usr.bin/indent/ps_ind_level.c |  15 +++------------
 usr.bin/indent/indent.c             |   7 +++++--
 5 files changed, 23 insertions(+), 28 deletions(-)

diffs (148 lines):

diff -r 1d282c52c6c3 -r 9e60a4a00e70 tests/usr.bin/indent/fmt_decl.c
--- a/tests/usr.bin/indent/fmt_decl.c   Mon May 15 14:27:29 2023 +0000
+++ b/tests/usr.bin/indent/fmt_decl.c   Mon May 15 14:55:47 2023 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: fmt_decl.c,v 1.38 2023/05/13 06:52:48 rillig Exp $     */
+/*     $NetBSD: fmt_decl.c,v 1.39 2023/05/15 14:55:47 rillig Exp $     */
 
 /*
  * Tests for declarations of global variables, external functions, and local
@@ -164,17 +164,18 @@ MAXALIGN(offsetof(int, test)) + MAXIMUM_
  * sensible way.
  */
 //indent input
+void single_param(int) __attribute__((__noreturn__)) ;
+void function(const char *, ...) __attribute__((format(printf, 1, 2))) ;
+//indent end
+
+//indent run -di0
+void single_param(int) __attribute__((__noreturn__));
 void function(const char *, ...) __attribute__((format(printf, 1, 2)));
 //indent end
 
-/* FIXME: missing space before '__attribute__' */
-//indent run -di0
-void function(const char *, ...)__attribute__((format(printf, 1, 2)));
-//indent end
-
-/* FIXME: missing space before '__attribute__' */
 //indent run
-void           function(const char *, ...)__attribute__((format(printf, 1, 2)));
+void           single_param(int) __attribute__((__noreturn__));
+void           function(const char *, ...) __attribute__((format(printf, 1, 2)));
 //indent end
 
 
@@ -734,8 +735,7 @@ static void JobRestartJobs(void);
 //indent end
 
 //indent run
-/* $ FIXME: Missing space before 'MAKE_ATTR_DEAD'. */
-static void    JobInterrupt(bool, int)MAKE_ATTR_DEAD;
+static void    JobInterrupt(bool, int) MAKE_ATTR_DEAD;
 static void    JobRestartJobs(void);
 //indent end
 
diff -r 1d282c52c6c3 -r 9e60a4a00e70 tests/usr.bin/indent/opt_pcs.c
--- a/tests/usr.bin/indent/opt_pcs.c    Mon May 15 14:27:29 2023 +0000
+++ b/tests/usr.bin/indent/opt_pcs.c    Mon May 15 14:55:47 2023 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: opt_pcs.c,v 1.13 2022/04/24 09:04:12 rillig Exp $ */
+/* $NetBSD: opt_pcs.c,v 1.14 2023/05/15 14:55:47 rillig Exp $ */
 
 /*
  * Tests for the options '-pcs' and '-npcs'.
@@ -48,7 +48,8 @@ int var = (function)(arg);
 
 //indent run -di0 -pcs
 void (*signal (void (*handler) (int))) (int);
-int var = (function) (arg);
+// $ This may be a function call or a cast, depending on the context.
+int var = (function)(arg);
 //indent end
 
 //indent run -di0 -npcs
diff -r 1d282c52c6c3 -r 9e60a4a00e70 tests/usr.bin/indent/opt_ta.c
--- a/tests/usr.bin/indent/opt_ta.c     Mon May 15 14:27:29 2023 +0000
+++ b/tests/usr.bin/indent/opt_ta.c     Mon May 15 14:55:47 2023 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: opt_ta.c,v 1.4 2022/04/24 09:04:12 rillig Exp $ */
+/* $NetBSD: opt_ta.c,v 1.5 2023/05/15 14:55:47 rillig Exp $ */
 
 /*
  * Tests for the option '-ta', which assumes that all identifiers that end in
@@ -20,7 +20,7 @@ example(void *arg)
 void
 example(void *arg)
 {
-       int             mult = (unknown_type_name) * arg;
+       int             mult = (unknown_type_name)*arg;
 
        int             cast = (unknown_type_name_t)*arg;
 }
diff -r 1d282c52c6c3 -r 9e60a4a00e70 tests/usr.bin/indent/ps_ind_level.c
--- a/tests/usr.bin/indent/ps_ind_level.c       Mon May 15 14:27:29 2023 +0000
+++ b/tests/usr.bin/indent/ps_ind_level.c       Mon May 15 14:55:47 2023 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: ps_ind_level.c,v 1.6 2022/04/24 09:04:12 rillig Exp $ */
+/* $NetBSD: ps_ind_level.c,v 1.7 2023/05/15 14:55:47 rillig Exp $ */
 
 /*
  * The indentation of the very first line of a file determines the
@@ -24,18 +24,9 @@ void function_in_column_1(void){}
 //indent run -i5 -ts8
                    int             indented_by_24;
 
-                   void            function_in_column_1(void){
+                   void            function_in_column_1(void) {
                    }
 //indent end
-/*
- * In the above function declaration, the space between '){' is missing. This
- * is because the tokenizer only recognizes function definitions if they start
- * at indentation level 0, but this declaration starts at indentation level 4,
- * due to the indentation in line 1. It's an edge case that is probably not
- * worth fixing.
- *
- * See 'in_func_def_params = true'.
- */
 
 
 /*
@@ -54,7 +45,7 @@ label:;
 //indent run -i8 -ts8 -di0
                        int indent_by_24;
 
-                       void function(void){
+                       void function(void) {
                label:          ;
                        }
 //indent end
diff -r 1d282c52c6c3 -r 9e60a4a00e70 usr.bin/indent/indent.c
--- a/usr.bin/indent/indent.c   Mon May 15 14:27:29 2023 +0000
+++ b/usr.bin/indent/indent.c   Mon May 15 14:55:47 2023 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: indent.c,v 1.278 2023/05/15 14:12:03 rillig Exp $      */
+/*     $NetBSD: indent.c,v 1.279 2023/05/15 14:55:47 rillig Exp $      */
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -38,7 +38,7 @@
  */
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: indent.c,v 1.278 2023/05/15 14:12:03 rillig Exp $");
+__RCSID("$NetBSD: indent.c,v 1.279 2023/05/15 14:55:47 rillig Exp $");
 
 #include <sys/param.h>
 #include <err.h>
@@ -464,6 +464,9 @@ process_rparen_or_rbracket(void)
        goto unbalanced;        /* TODO: better exit immediately */
     }
 
+    if (ps.nparen > 0 && ps.decl_on_line && !ps.block_init)
+       ps.paren[ps.nparen - 1].no_cast = true;
+
     if (ps.paren[ps.nparen - 1].maybe_cast &&
            !ps.paren[ps.nparen - 1].no_cast) {
        ps.next_unary = true;



Home | Main Index | Thread Index | Old Index