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: make variable names more expressive



details:   https://anonhg.NetBSD.org/src/rev/08a3a1de55d1
branches:  trunk
changeset: 1023964:08a3a1de55d1
user:      rillig <rillig%NetBSD.org@localhost>
date:      Tue Oct 05 16:33:25 2021 +0000

description:
indent: make variable names more expressive

The abbreviation 'dec' looked too much like 'decimal' instead of the
intended 'declaration'.

No functional change.

diffstat:

 usr.bin/indent/indent.c |  107 +++++++++++++++++++++++------------------------
 1 files changed, 53 insertions(+), 54 deletions(-)

diffs (truncated from 363 to 300 lines):

diff -r 109ee7d9ebef -r 08a3a1de55d1 usr.bin/indent/indent.c
--- a/usr.bin/indent/indent.c   Tue Oct 05 14:18:17 2021 +0000
+++ b/usr.bin/indent/indent.c   Tue Oct 05 16:33:25 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: indent.c,v 1.104 2021/10/05 07:05:51 rillig Exp $      */
+/*     $NetBSD: indent.c,v 1.105 2021/10/05 16:33:25 rillig Exp $      */
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -43,7 +43,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__NetBSD__)
-__RCSID("$NetBSD: indent.c,v 1.104 2021/10/05 07:05:51 rillig Exp $");
+__RCSID("$NetBSD: indent.c,v 1.105 2021/10/05 16:33:25 rillig Exp $");
 #elif defined(__FreeBSD__)
 __FBSDID("$FreeBSD: head/usr.bin/indent/indent.c 340138 2018-11-04 19:24:49Z oshogbo $");
 #endif
@@ -605,7 +605,7 @@
 }
 
 static void
-process_lparen_or_lbracket(int dec_ind, bool tabs_to_var, bool sp_sw)
+process_lparen_or_lbracket(int decl_ind, bool tabs_to_var, bool sp_sw)
 {
     if (++ps.p_l_follow == nitems(ps.paren_indents)) {
        diag(0, "Reached internal limit of %zu unclosed parens",
@@ -616,7 +616,7 @@
        && !ps.block_init && !ps.dumped_decl_indent &&
        ps.procname[0] == '\0' && ps.paren_level == 0) {
        /* function pointer declarations */
-       indent_declaration(dec_ind, tabs_to_var);
+       indent_declaration(decl_ind, tabs_to_var);
        ps.dumped_decl_indent = true;
     } else if (want_blank_before_lparen())
        *code.e++ = ' ';
@@ -686,12 +686,12 @@
 }
 
 static void
-process_unary_op(int dec_ind, bool tabs_to_var)
+process_unary_op(int decl_ind, bool tabs_to_var)
 {
     if (!ps.dumped_decl_indent && ps.in_decl && !ps.block_init &&
        ps.procname[0] == '\0' && ps.paren_level == 0) {
        /* pointer declarations */
-       indent_declaration(dec_ind - (int)strlen(token.s), tabs_to_var);
+       indent_declaration(decl_ind - (int)strlen(token.s), tabs_to_var);
        ps.dumped_decl_indent = true;
     } else if (ps.want_blank)
        *code.e++ = ' ';
@@ -729,9 +729,9 @@
 }
 
 static void
-process_question(int *squest)
+process_question(int *seen_quest)
 {
-    (*squest)++;               /* this will be used when a later colon
+    (*seen_quest)++;           /* this will be used when a later colon
                                 * appears, so we can distinguish the
                                 * <c>?<n>:<n> construct */
     if (ps.want_blank)
@@ -741,10 +741,10 @@
 }
 
 static void
-process_colon(int *squest, bool *force_nl, bool *scase)
+process_colon(int *seen_quest, bool *force_nl, bool *seen_case)
 {
-    if (*squest > 0) {         /* it is part of the <c>?<n>: <n> construct */
-       --*squest;
+    if (*seen_quest > 0) {     /* it is part of the <c>?<n>: <n> construct */
+       --*seen_quest;
        if (ps.want_blank)
            *code.e++ = ' ';
        *code.e++ = ':';
@@ -771,16 +771,16 @@
        *lab.e = '\0';
        code.e = code.s;
     }
-    ps.pcase = *scase;         /* will be used by dump_line to decide how to
+    ps.pcase = *seen_case;     /* will be used by dump_line to decide how to
                                 * indent the label. */
-    *force_nl = *scase;                /* will force a 'case n:' to be on a
+    *force_nl = *seen_case;    /* will force a 'case n:' to be on a
                                 * line by itself */
-    *scase = false;
+    *seen_case = false;
     ps.want_blank = false;
 }
 
 static void
-process_semicolon(bool *scase, int *squest, int dec_ind,
+process_semicolon(bool *seen_case, int *seen_quest, int decl_ind,
     bool tabs_to_var, bool *sp_sw,
     token_type hd_type,
     bool *force_nl)
@@ -788,8 +788,8 @@
     if (ps.decl_nest == 0)
        ps.in_or_st = false;    /* we are not in an initialization or
                                 * structure declaration */
-    *scase = false;            /* these will only need resetting in an error */
-    *squest = 0;
+    *seen_case = false;                /* these will only need resetting in an error */
+    *seen_quest = 0;
     if (ps.last_token == rparen)
        ps.in_parameter_declaration = false;
     ps.cast_mask = 0;
@@ -801,7 +801,7 @@
     if (ps.in_decl && code.s == code.e && !ps.block_init &&
        !ps.dumped_decl_indent && ps.paren_level == 0) {
        /* indent stray semicolons in declarations */
-       indent_declaration(dec_ind - 1, tabs_to_var);
+       indent_declaration(decl_ind - 1, tabs_to_var);
        ps.dumped_decl_indent = true;
     }
 
@@ -837,7 +837,7 @@
 
 static void
 process_lbrace(bool *force_nl, bool *sp_sw, token_type hd_type,
-    int *di_stack, int di_stack_cap, int *dec_ind)
+    int *di_stack, int di_stack_cap, int *decl_ind)
 {
     ps.in_stmt = false;                /* don't indent the {} */
     if (!ps.block_init)
@@ -879,13 +879,12 @@
                                 * with '{' */
     if (ps.in_decl && ps.in_or_st) {   /* this is either a structure
                                         * declaration or an init */
-       di_stack[ps.decl_nest] = *dec_ind;
+       di_stack[ps.decl_nest] = *decl_ind;
        if (++ps.decl_nest == di_stack_cap) {
            diag(0, "Reached internal limit of %d struct levels",
                di_stack_cap);
            ps.decl_nest--;
        }
-       /* ?            dec_ind = 0; */
     } else {
        ps.decl_on_line = false;        /* we can't be in the middle of a
                                         * declaration, so don't do special
@@ -896,7 +895,7 @@
        ps.in_parameter_declaration = false;
        ps.in_decl = false;
     }
-    *dec_ind = 0;
+    *decl_ind = 0;
     parse(lbrace);             /* let parser know about this */
     if (ps.want_blank)         /* put a blank before '{' if '{' is not at
                                 * start of line */
@@ -907,7 +906,7 @@
 }
 
 static void
-process_rbrace(bool *sp_sw, int *dec_ind, const int *di_stack)
+process_rbrace(bool *sp_sw, int *decl_ind, const int *di_stack)
 {
     if (ps.p_stack[ps.tos] == decl && !ps.block_init)  /* semicolons can be
                                                         * omitted in
@@ -929,7 +928,7 @@
     ps.want_blank = true;
     ps.in_stmt = ps.ind_stmt = false;
     if (ps.decl_nest > 0) { /* we are in multi-level structure declaration */
-       *dec_ind = di_stack[--ps.decl_nest];
+       *decl_ind = di_stack[--ps.decl_nest];
        if (ps.decl_nest == 0 && !ps.in_parameter_declaration)
            ps.just_saw_decl = 2;
        ps.in_decl = true;
@@ -971,7 +970,7 @@
 }
 
 static void
-process_decl(int *out_dec_ind, bool *out_tabs_to_var)
+process_decl(int *out_decl_ind, bool *out_tabs_to_var)
 {
     parse(decl);               /* let parser worry about indentation */
     if (ps.last_token == rparen && ps.tos <= 1) {
@@ -996,12 +995,12 @@
     int ind = ps.ind_level == 0 || ps.decl_nest > 0
            ? opt.decl_indent           /* global variable or local member */
            : opt.local_decl_indent;    /* local variable */
-    *out_dec_ind = ind > 0 ? ind : len;
+    *out_decl_ind = ind > 0 ? ind : len;
     *out_tabs_to_var = opt.use_tabs ? ind > 0 : false;
 }
 
 static void
-process_ident(token_type ttype, int dec_ind, bool tabs_to_var,
+process_ident(token_type ttype, int decl_ind, bool tabs_to_var,
     bool *sp_sw, bool *force_nl, token_type hd_type)
 {
     if (ps.in_decl) {
@@ -1017,7 +1016,7 @@
        } else if (!ps.block_init && !ps.dumped_decl_indent &&
            ps.paren_level == 0) {      /* if we are in a declaration, we must
                                         * indent identifier */
-           indent_declaration(dec_ind, tabs_to_var);
+           indent_declaration(decl_ind, tabs_to_var);
            ps.dumped_decl_indent = true;
            ps.want_blank = false;
        }
@@ -1066,14 +1065,14 @@
 }
 
 static void
-process_comma(int dec_ind, bool tabs_to_var, bool *force_nl)
+process_comma(int decl_ind, bool tabs_to_var, bool *force_nl)
 {
     ps.want_blank = (code.s != code.e);        /* only put blank after comma if comma
                                         * does not start the line */
     if (ps.in_decl && ps.procname[0] == '\0' && !ps.block_init &&
        !ps.dumped_decl_indent && ps.paren_level == 0) {
        /* indent leading commas and not the actual identifiers */
-       indent_declaration(dec_ind - 1, tabs_to_var);
+       indent_declaration(decl_ind - 1, tabs_to_var);
        ps.dumped_decl_indent = true;
     }
     *code.e++ = ',';
@@ -1222,24 +1221,24 @@
     token_type ttype;
     bool force_nl;             /* when true, code must be broken */
     bool last_else = false;    /* true iff last keyword was an else */
-    int dec_ind;               /* current indentation for declarations */
+    int decl_ind;              /* current indentation for declarations */
     int di_stack[20];          /* a stack of structure indentation levels */
     bool tabs_to_var;          /* true if using tabs to indent to var name */
     bool sp_sw;                        /* when true, we are in the expression of
                                 * if(...), while(...), etc. */
     token_type hd_type = end_of_file;  /* used to store type of stmt for if
                                         * (...), for (...), etc */
-    int squest;                        /* when this is positive, we have seen a '?'
+    int seen_quest;            /* when this is positive, we have seen a '?'
                                 * without the matching ':' in a <c>?<s>:<s>
                                 * construct */
-    bool scase;                        /* set to true when we see a 'case', so we
+    bool seen_case;            /* set to true when we see a 'case', so we
                                 * know what to do with the following colon */
 
     sp_sw = force_nl = false;
-    dec_ind = 0;
+    decl_ind = 0;
     di_stack[ps.decl_nest = 0] = 0;
-    scase = false;
-    squest = 0;
+    seen_case = false;
+    seen_quest = 0;
     tabs_to_var = false;
 
     for (;;) {                 /* this is the main loop.  it will go until we
@@ -1293,7 +1292,7 @@
            break;
 
        case lparen:            /* got a '(' or '[' */
-           process_lparen_or_lbracket(dec_ind, tabs_to_var, sp_sw);
+           process_lparen_or_lbracket(decl_ind, tabs_to_var, sp_sw);
            break;
 
        case rparen:            /* got a ')' or ']' */
@@ -1301,7 +1300,7 @@
            break;
 
        case unary_op:          /* this could be any unary operation */
-           process_unary_op(dec_ind, tabs_to_var);
+           process_unary_op(decl_ind, tabs_to_var);
            break;
 
        case binary_op:         /* any binary operation */
@@ -1313,29 +1312,29 @@
            break;
 
        case question:          /* got a ? */
-           process_question(&squest);
+           process_question(&seen_quest);
            break;
 
        case case_label:        /* got word 'case' or 'default' */
-           scase = true;       /* so we can process the later colon properly */
+           seen_case = true;   /* so we can process the later colon properly */
            goto copy_id;
 
        case colon:             /* got a ':' */
-           process_colon(&squest, &force_nl, &scase);
+           process_colon(&seen_quest, &force_nl, &seen_case);
            break;
 
        case semicolon:         /* got a ';' */
-           process_semicolon(&scase, &squest, dec_ind, tabs_to_var, &sp_sw,
-               hd_type, &force_nl);
+           process_semicolon(&seen_case, &seen_quest, decl_ind, tabs_to_var,
+               &sp_sw, hd_type, &force_nl);
            break;
 
        case lbrace:            /* got a '{' */
            process_lbrace(&force_nl, &sp_sw, hd_type, di_stack,
-               (int)nitems(di_stack), &dec_ind);
+               (int)nitems(di_stack), &decl_ind);
            break;
 
        case rbrace:            /* got a '}' */



Home | Main Index | Thread Index | Old Index