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: sort functions in call order



details:   https://anonhg.NetBSD.org/src/rev/2011622382ed
branches:  trunk
changeset: 376246:2011622382ed
user:      rillig <rillig%NetBSD.org@localhost>
date:      Tue Jun 06 05:11:11 2023 +0000

description:
indent: sort functions in call order

No functional change.

diffstat:

 usr.bin/indent/debug.c |    5 +-
 usr.bin/indent/io.c    |  189 ++++++++++++++++++++++++------------------------
 usr.bin/indent/lexi.c  |    5 +-
 usr.bin/indent/parse.c |  130 ++++++++++++++++-----------------
 4 files changed, 165 insertions(+), 164 deletions(-)

diffs (truncated from 447 to 300 lines):

diff -r 6380d5f91a87 -r 2011622382ed usr.bin/indent/debug.c
--- a/usr.bin/indent/debug.c    Tue Jun 06 04:37:26 2023 +0000
+++ b/usr.bin/indent/debug.c    Tue Jun 06 05:11:11 2023 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: debug.c,v 1.36 2023/06/05 14:40:13 rillig Exp $        */
+/*     $NetBSD: debug.c,v 1.37 2023/06/06 05:11:11 rillig Exp $        */
 
 /*-
  * Copyright (c) 2023 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: debug.c,v 1.36 2023/06/05 14:40:13 rillig Exp $");
+__RCSID("$NetBSD: debug.c,v 1.37 2023/06/06 05:11:11 rillig Exp $");
 
 #include <stdarg.h>
 
@@ -144,6 +144,7 @@ static const char *const decl_ptr_name[]
 
 static unsigned wrote_newlines = 1;
 
+
 void
 debug_printf(const char *fmt, ...)
 {
diff -r 6380d5f91a87 -r 2011622382ed usr.bin/indent/io.c
--- a/usr.bin/indent/io.c       Tue Jun 06 04:37:26 2023 +0000
+++ b/usr.bin/indent/io.c       Tue Jun 06 05:11:11 2023 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: io.c,v 1.199 2023/06/06 04:37:26 rillig Exp $  */
+/*     $NetBSD: io.c,v 1.200 2023/06/06 05:11:11 rillig Exp $  */
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -38,7 +38,7 @@
  */
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: io.c,v 1.199 2023/06/06 04:37:26 rillig Exp $");
+__RCSID("$NetBSD: io.c,v 1.200 2023/06/06 05:11:11 rillig Exp $");
 
 #include <stdio.h>
 
@@ -55,22 +55,6 @@ static unsigned wrote_newlines = 2;  /* 0
 static int paren_indent;
 
 
-void
-inp_skip(void)
-{
-       inp_p++;
-       if ((size_t)(inp_p - inp.s) >= inp.len)
-               inp_read_line();
-}
-
-char
-inp_next(void)
-{
-       char ch = inp_p[0];
-       inp_skip();
-       return ch;
-}
-
 static void
 inp_read_next_line(FILE *f)
 {
@@ -95,6 +79,32 @@ inp_read_next_line(FILE *f)
        inp_p = inp.s;
 }
 
+void
+inp_read_line(void)
+{
+       if (indent_enabled == indent_on)
+               out.indent_off_text.len = 0;
+       buf_add_chars(&out.indent_off_text, inp.s, inp.len);
+       inp_read_next_line(input);
+}
+
+void
+inp_skip(void)
+{
+       inp_p++;
+       if ((size_t)(inp_p - inp.s) >= inp.len)
+               inp_read_line();
+}
+
+char
+inp_next(void)
+{
+       char ch = inp_p[0];
+       inp_skip();
+       return ch;
+}
+
+
 static void
 output_newline(void)
 {
@@ -176,6 +186,26 @@ is_blank_line_optional(void)
        return wrote_newlines >= 3;
 }
 
+static int
+compute_case_label_indent(void)
+{
+       int i = ps.tos;
+       while (i > 0 && ps.s_sym[i] != psym_switch_expr)
+               i--;
+       float case_ind = (float)ps.s_ind_level[i] + opt.case_indent;
+       return (int)(case_ind * (float)opt.indent_size);
+}
+
+int
+compute_label_indent(void)
+{
+       if (out.line_kind == lk_case_or_default)
+               return compute_case_label_indent();
+       if (lab.s[0] == '#')
+               return 0;
+       return opt.indent_size * (ps.ind_level - 2);
+}
+
 static void
 output_line_label(void)
 {
@@ -183,6 +213,53 @@ output_line_label(void)
        output_range(lab.s, lab.len);
 }
 
+static int
+compute_code_indent_lineup(int base_ind)
+{
+       int ind = paren_indent;
+       int overflow = ind_add(ind, code.s, code.len) - opt.max_line_length;
+       if (overflow < 0)
+               return ind;
+
+       if (ind_add(base_ind, code.s, code.len) < opt.max_line_length) {
+               ind -= overflow + 2;
+               if (ind > base_ind)
+                       return ind;
+               return base_ind;
+       }
+
+       return ind;
+}
+
+int
+compute_code_indent(void)
+{
+       int base_ind = ps.ind_level * opt.indent_size;
+
+       if (ps.line_start_nparen == 0) {
+               if (ps.tos >= 1 && ps.s_sym[ps.tos - 1] == psym_lbrace_enum)
+                       return base_ind;
+               if (ps.in_stmt_cont)
+                       return base_ind + opt.continuation_indent;
+               return base_ind;
+       }
+
+       if (opt.lineup_to_parens) {
+               if (opt.lineup_to_parens_always)
+                       return paren_indent;
+               return compute_code_indent_lineup(base_ind);
+       }
+
+       if (ps.extra_expr_indent != eei_no)
+               return base_ind + 2 * opt.continuation_indent;
+
+       if (2 * opt.continuation_indent == opt.indent_size)
+               return base_ind + opt.continuation_indent;
+       else
+               return base_ind +
+                   opt.continuation_indent * ps.line_start_nparen;
+}
+
 static void
 output_line_code(void)
 {
@@ -314,79 +391,3 @@ dont_write_line:
        ps.want_blank = false;
        out.line_kind = lk_other;
 }
-
-static int
-compute_code_indent_lineup(int base_ind)
-{
-       int ind = paren_indent;
-       int overflow = ind_add(ind, code.s, code.len) - opt.max_line_length;
-       if (overflow < 0)
-               return ind;
-
-       if (ind_add(base_ind, code.s, code.len) < opt.max_line_length) {
-               ind -= overflow + 2;
-               if (ind > base_ind)
-                       return ind;
-               return base_ind;
-       }
-
-       return ind;
-}
-
-int
-compute_code_indent(void)
-{
-       int base_ind = ps.ind_level * opt.indent_size;
-
-       if (ps.line_start_nparen == 0) {
-               if (ps.tos >= 1 && ps.s_sym[ps.tos - 1] == psym_lbrace_enum)
-                       return base_ind;
-               if (ps.in_stmt_cont)
-                       return base_ind + opt.continuation_indent;
-               return base_ind;
-       }
-
-       if (opt.lineup_to_parens) {
-               if (opt.lineup_to_parens_always)
-                       return paren_indent;
-               return compute_code_indent_lineup(base_ind);
-       }
-
-       if (ps.extra_expr_indent != eei_no)
-               return base_ind + 2 * opt.continuation_indent;
-
-       if (2 * opt.continuation_indent == opt.indent_size)
-               return base_ind + opt.continuation_indent;
-       else
-               return base_ind +
-                   opt.continuation_indent * ps.line_start_nparen;
-}
-
-static int
-compute_case_label_indent(void)
-{
-       int i = ps.tos;
-       while (i > 0 && ps.s_sym[i] != psym_switch_expr)
-               i--;
-       float case_ind = (float)ps.s_ind_level[i] + opt.case_indent;
-       return (int)(case_ind * (float)opt.indent_size);
-}
-
-int
-compute_label_indent(void)
-{
-       if (out.line_kind == lk_case_or_default)
-               return compute_case_label_indent();
-       if (lab.s[0] == '#')
-               return 0;
-       return opt.indent_size * (ps.ind_level - 2);
-}
-
-void
-inp_read_line(void)
-{
-       if (indent_enabled == indent_on)
-               out.indent_off_text.len = 0;
-       buf_add_chars(&out.indent_off_text, inp.s, inp.len);
-       inp_read_next_line(input);
-}
diff -r 6380d5f91a87 -r 2011622382ed usr.bin/indent/lexi.c
--- a/usr.bin/indent/lexi.c     Tue Jun 06 04:37:26 2023 +0000
+++ b/usr.bin/indent/lexi.c     Tue Jun 06 05:11:11 2023 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: lexi.c,v 1.214 2023/06/04 22:57:18 rillig Exp $        */
+/*     $NetBSD: lexi.c,v 1.215 2023/06/06 05:11:11 rillig Exp $        */
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -38,7 +38,7 @@
  */
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: lexi.c,v 1.214 2023/06/04 22:57:18 rillig Exp $");
+__RCSID("$NetBSD: lexi.c,v 1.215 2023/06/06 05:11:11 rillig Exp $");
 
 #include <stdlib.h>
 #include <string.h>
@@ -166,6 +166,7 @@ static const unsigned char lex_number_ro
        ['.'] = 15,
 };
 
+
 static void
 token_add_char(char ch)
 {
diff -r 6380d5f91a87 -r 2011622382ed usr.bin/indent/parse.c
--- a/usr.bin/indent/parse.c    Tue Jun 06 04:37:26 2023 +0000
+++ b/usr.bin/indent/parse.c    Tue Jun 06 05:11:11 2023 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: parse.c,v 1.67 2023/06/06 04:37:26 rillig Exp $        */
+/*     $NetBSD: parse.c,v 1.68 2023/06/06 05:11:11 rillig Exp $        */
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -38,13 +38,57 @@
  */
 
 #include <sys/cdefs.h>



Home | Main Index | Thread Index | Old Index