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: separate detection of function defini...



details:   https://anonhg.NetBSD.org/src/rev/57955f9eae17
branches:  trunk
changeset: 375894:57955f9eae17
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sat May 20 00:17:56 2023 +0000

description:
indent: separate detection of function definitions from lexing '*'

No functional change.

diffstat:

 usr.bin/indent/indent.h |  10 ++++++++--
 usr.bin/indent/lexi.c   |  37 ++++++++++++++++++++-----------------
 2 files changed, 28 insertions(+), 19 deletions(-)

diffs (89 lines):

diff -r 3738954345c7 -r 57955f9eae17 usr.bin/indent/indent.h
--- a/usr.bin/indent/indent.h   Fri May 19 23:28:20 2023 +0000
+++ b/usr.bin/indent/indent.h   Sat May 20 00:17:56 2023 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: indent.h,v 1.150 2023/05/18 08:09:28 rillig Exp $      */
+/*     $NetBSD: indent.h,v 1.151 2023/05/20 00:17:56 rillig Exp $      */
 
 /*-
  * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
@@ -286,7 +286,13 @@ extern struct parser_state {
        int quest_level;        /* when this is positive, we have seen a '?'
                                 * without the matching ':' in a '?:'
                                 * expression */
-       bool is_function_definition;
+       bool is_function_definition;    /* starts either at the 'name(' from a
+                                        * function definition if it occurs at
+                                        * the beginning of a line, or at the
+                                        * first '*' from inside a declaration
+                                        * when the line starts with words
+                                        * followed by a '('; ends at the end
+                                        * of that line */
        bool block_init;        /* whether inside a block initialization */
        int block_init_level;   /* the level of brace nesting in an
                                 * initialization */
diff -r 3738954345c7 -r 57955f9eae17 usr.bin/indent/lexi.c
--- a/usr.bin/indent/lexi.c     Fri May 19 23:28:20 2023 +0000
+++ b/usr.bin/indent/lexi.c     Sat May 20 00:17:56 2023 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: lexi.c,v 1.199 2023/05/18 05:33:27 rillig Exp $        */
+/*     $NetBSD: lexi.c,v 1.200 2023/05/20 00:17:56 rillig Exp $        */
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -38,7 +38,7 @@
  */
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: lexi.c,v 1.199 2023/05/18 05:33:27 rillig Exp $");
+__RCSID("$NetBSD: lexi.c,v 1.200 2023/05/20 00:17:56 rillig Exp $");
 
 #include <stdlib.h>
 #include <string.h>
@@ -447,6 +447,22 @@ is_asterisk_unary(void)
        return ps.in_decl && ps.nparen > 0;
 }
 
+static bool
+probably_in_function_definition(void)
+{
+       for (const char *tp = inp.st; *tp != '\n';) {
+               if (ch_isspace(*tp))
+                       tp++;
+               else if (is_identifier_start(*tp)) {
+                       tp++;
+                       while (is_identifier_part(*tp))
+                               tp++;
+               } else
+                       return *tp == '(';
+       }
+       return false;
+}
+
 static void
 lex_asterisk_unary(void)
 {
@@ -456,21 +472,8 @@ lex_asterisk_unary(void)
                inp_skip();
        }
 
-       if (ps.in_decl) {
-               for (const char *tp = inp.st; *tp != '\n';) {
-                       if (ch_isspace(*tp))
-                               tp++;
-                       else if (is_identifier_start(*tp)) {
-                               tp++;
-                               while (is_identifier_part(*tp))
-                                       tp++;
-                       } else {
-                               if (*tp == '(')
-                                       ps.is_function_definition = true;
-                               break;
-                       }
-               }
-       }
+       if (ps.in_decl && probably_in_function_definition())
+               ps.is_function_definition = true;
 }
 
 static void



Home | Main Index | Thread Index | Old Index