Module Name:    src
Committed By:   rillig
Date:           Sat Sep 25 20:56:53 UTC 2021

Modified Files:
        src/usr.bin/indent: indent.c indent_globs.h io.c parse.c

Log Message:
indent: un-abbreviate a few parser_state members, clean up comments

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.78 -r1.79 src/usr.bin/indent/indent.c
cvs rdiff -u -r1.34 -r1.35 src/usr.bin/indent/indent_globs.h
cvs rdiff -u -r1.63 -r1.64 src/usr.bin/indent/io.c
cvs rdiff -u -r1.25 -r1.26 src/usr.bin/indent/parse.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/indent/indent.c
diff -u src/usr.bin/indent/indent.c:1.78 src/usr.bin/indent/indent.c:1.79
--- src/usr.bin/indent/indent.c:1.78	Sat Sep 25 20:23:42 2021
+++ src/usr.bin/indent/indent.c	Sat Sep 25 20:56:53 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: indent.c,v 1.78 2021/09/25 20:23:42 rillig Exp $	*/
+/*	$NetBSD: indent.c,v 1.79 2021/09/25 20:56:53 rillig Exp $	*/
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -43,7 +43,7 @@ static char sccsid[] = "@(#)indent.c	5.1
 
 #include <sys/cdefs.h>
 #if defined(__NetBSD__)
-__RCSID("$NetBSD: indent.c,v 1.78 2021/09/25 20:23:42 rillig Exp $");
+__RCSID("$NetBSD: indent.c,v 1.79 2021/09/25 20:56:53 rillig Exp $");
 #elif defined(__FreeBSD__)
 __FBSDID("$FreeBSD: head/usr.bin/indent/indent.c 340138 2018-11-04 19:24:49Z oshogbo $");
 #endif
@@ -498,7 +498,7 @@ main_prepare_parsing(void)
 	p++;
     }
     if (col > opt.indent_size)
-	ps.ind_level = ps.i_l_follow = col / opt.indent_size;
+	ps.ind_level = ps.ind_level_follow = col / opt.indent_size;
 }
 
 static void __attribute__((__noreturn__))
@@ -769,7 +769,7 @@ process_semicolon(bool *inout_scase, int
 		  token_type hd_type,
 		  bool *inout_force_nl)
 {
-    if (ps.dec_nest == 0)
+    if (ps.decl_nest == 0)
 	ps.in_or_st = false;	/* we are not in an initialization or
 				 * structure declaration */
     *inout_scase = false; /* these will only need resetting in an error */
@@ -789,7 +789,7 @@ process_semicolon(bool *inout_scase, int
 	ps.dumped_decl_indent = true;
     }
 
-    ps.in_decl = (ps.dec_nest > 0);	/* if we were in a first level
+    ps.in_decl = (ps.decl_nest > 0);	/* if we were in a first level
 						 * structure declaration, we
 						 * arent any more */
 
@@ -837,7 +837,7 @@ process_lbrace(bool *inout_force_nl, boo
 	    dump_line();
 	    ps.want_blank = false;
 	} else if (ps.in_parameter_declaration && !ps.in_or_st) {
-	    ps.i_l_follow = 0;
+	    ps.ind_level_follow = 0;
 	    if (opt.function_brace_split) { /* dump the line prior
 				 * to the brace ... */
 		dump_line();
@@ -856,7 +856,7 @@ process_lbrace(bool *inout_force_nl, boo
 	if (*inout_sp_sw) {	/* check for unclosed if, for, etc. */
 	    *inout_sp_sw = false;
 	    parse(hd_type);
-	    ps.ind_level = ps.i_l_follow;
+	    ps.ind_level = ps.ind_level_follow;
 	}
     }
     if (code.s == code.e)
@@ -864,11 +864,11 @@ process_lbrace(bool *inout_force_nl, boo
 				 * with '{' */
     if (ps.in_decl && ps.in_or_st) {	/* this is either a structure
 				 * declaration or an init */
-	di_stack[ps.dec_nest] = *inout_dec_ind;
-	if (++ps.dec_nest == di_stack_cap) {
+	di_stack[ps.decl_nest] = *inout_dec_ind;
+	if (++ps.decl_nest == di_stack_cap) {
 	    diag(0, "Reached internal limit of %d struct levels",
 		 di_stack_cap);
-	    ps.dec_nest--;
+	    ps.decl_nest--;
 	}
 	/* ?		dec_ind = 0; */
     } else {
@@ -913,9 +913,9 @@ process_rbrace(bool *inout_sp_sw, int *i
     *code.e++ = '}';
     ps.want_blank = true;
     ps.in_stmt = ps.ind_stmt = false;
-    if (ps.dec_nest > 0) { /* we are in multi-level structure declaration */
-	*inout_dec_ind = di_stack[--ps.dec_nest];
-	if (ps.dec_nest == 0 && !ps.in_parameter_declaration)
+    if (ps.decl_nest > 0) { /* we are in multi-level structure declaration */
+	*inout_dec_ind = di_stack[--ps.decl_nest];
+	if (ps.decl_nest == 0 && !ps.in_parameter_declaration)
 	    ps.just_saw_decl = 2;
 	ps.in_decl = true;
     }
@@ -924,7 +924,7 @@ process_rbrace(bool *inout_sp_sw, int *i
     ps.search_brace = opt.cuddle_else
 		      && ps.p_stack[ps.tos] == if_expr_stmt
 		      && ps.il[ps.tos] >= ps.ind_level;
-    if (ps.tos <= 1 && opt.blanklines_after_procs && ps.dec_nest <= 0)
+    if (ps.tos <= 1 && opt.blanklines_after_procs && ps.decl_nest <= 0)
 	postfix_blankline_requested = true;
 }
 
@@ -965,20 +965,21 @@ process_decl(int *out_dec_ind, bool *out
 	    ps.want_blank = false;
 	}
     }
-    if (ps.in_parameter_declaration && opt.indent_parameters && ps.dec_nest == 0) {
-	ps.ind_level = ps.i_l_follow = 1;
+    if (ps.in_parameter_declaration && opt.indent_parameters &&
+	ps.decl_nest == 0) {
+	ps.ind_level = ps.ind_level_follow = 1;
 	ps.ind_stmt = false;
     }
     ps.in_or_st = true;		/* this might be a structure or initialization
 				 * declaration */
     ps.in_decl = ps.decl_on_line = ps.last_token != type_def;
-    if ( /* !ps.in_or_st && */ ps.dec_nest <= 0)
+    if ( /* !ps.in_or_st && */ ps.decl_nest <= 0)
 	ps.just_saw_decl = 2;
     prefix_blankline_requested = false;
     int i;
     for (i = 0; token.s[i++] != '\0';);	/* get length of token */
 
-    if (ps.ind_level == 0 || ps.dec_nest > 0) {
+    if (ps.ind_level == 0 || ps.decl_nest > 0) {
 	/* global variable or struct member in local variable */
 	*out_dec_ind = opt.decl_indent > 0 ? opt.decl_indent : i;
 	*out_tabs_to_var = opt.use_tabs ? opt.decl_indent > 0 : false;
@@ -1235,7 +1236,7 @@ main_loop(void)
 
     sp_sw = force_nl = false;
     dec_ind = 0;
-    di_stack[ps.dec_nest = 0] = 0;
+    di_stack[ps.decl_nest = 0] = 0;
     scase = false;
     squest = 0;
     tabs_to_var = false;

Index: src/usr.bin/indent/indent_globs.h
diff -u src/usr.bin/indent/indent_globs.h:1.34 src/usr.bin/indent/indent_globs.h:1.35
--- src/usr.bin/indent/indent_globs.h:1.34	Sat Sep 25 20:23:42 2021
+++ src/usr.bin/indent/indent_globs.h	Sat Sep 25 20:56:53 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: indent_globs.h,v 1.34 2021/09/25 20:23:42 rillig Exp $	*/
+/*	$NetBSD: indent_globs.h,v 1.35 2021/09/25 20:56:53 rillig Exp $	*/
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -99,7 +99,7 @@ extern struct options {
     int         decl_comment_column; /* the column in which comments after
 				 * declarations should be put */
     bool	cuddle_else;	/* whether 'else' should cuddle up to '}' */
-    int         continuation_indent; /* set to the indentation between the
+    int         continuation_indent; /* the indentation between the
 				 * edge of code and continuation lines */
     float       case_indent;	/* The distance (measured in tabsize) to
 				 * indent case labels from the switch
@@ -179,13 +179,13 @@ extern bool        prefix_blankline_requ
 extern bool        postfix_blankline_requested;
 extern bool        break_comma;	/* when true and not in parens, break after a
 				 * comma */
-extern float       case_ind;		/* indentation level to be used for a "case
+extern float       case_ind;	/* indentation level to be used for a "case
 				 * n:" */
-extern bool        had_eof;		/* set to true when input is exhausted */
+extern bool        had_eof;		/* whether input is exhausted */
 extern int         line_no;		/* the current line number. */
 extern bool        inhibit_formatting;	/* true if INDENT OFF is in effect */
-extern int         suppress_blanklines;/* set iff following blanklines should be
-				 * suppressed */
+extern int         suppress_blanklines;/* set iff following blanklines should
+				 * be suppressed */
 
 #define	STACKSIZE 256
 
@@ -217,25 +217,25 @@ extern struct parser_state {
 				 * paren since the last semicolon. When true,
 				 * a '{' is starting a structure definition or
 				 * an initialization list */
-    bool	col_1;		/* set to true if the last token started in
+    bool	col_1;		/* whether the last token started in
 				 * column 1 */
     int         com_col;	/* this is the column in which the current
 				 * comment should start */
-    int         dec_nest;	/* current nesting level for structure or init */
-    bool	decl_on_line;	/* set to true if this line of code has part
+    int         decl_nest;	/* current nesting level for structure or init */
+    bool	decl_on_line;	/* whether this line of code has part
 				 * of a declaration on it */
-    int         i_l_follow;	/* the level to which ind_level should be set
+    int         ind_level_follow; /* the level to which ind_level should be set
 				 * after the current line is printed */
-    bool	in_decl;	/* set to true when we are in a declaration
-				 * stmt.  The processing of braces is then
-				 * slightly different */
-    bool	in_stmt;	/* set to 1 while in a stmt */
+    bool	in_decl;	/* whether we are in a declaration stmt.
+				 * The processing of braces is then slightly
+				 * different */
+    bool	in_stmt;	/* whether in a stmt */
     int         ind_level;	/* the current indentation level */
-    bool	ind_stmt;	/* set to 1 if next line should have an extra
+    bool	ind_stmt;	/* whether the next line should have an extra
 				 * indentation level because we are in the
 				 * middle of a stmt */
-    bool	last_u_d;	/* set to true after scanning a token which
-				 * forces a following operator to be unary */
+    bool	last_u_d;	/* whether the following operator should be
+				 * unary */
     int         p_l_follow;	/* used to remember how to indent the
 				 * following statement */
     int         paren_level;	/* parenthesization level. used to indent
@@ -243,15 +243,15 @@ extern struct parser_state {
     short       paren_indents[20]; /* indentation of the operand/argument of
 				 * each level of parentheses or brackets,
 				 * relative to the enclosing statement */
-    bool	pcase;		/* set to 1 if the current line label is a
+    bool	pcase;		/* whether the current line label is a
 				 * case.  It is printed differently from a
 				 * regular label */
-    bool	search_brace;	/* set to true by parse when it is necessary
+    bool	search_brace;	/* whether it is necessary
 				 * to buffer up all info up to the start of a
 				 * stmt after an if, while, etc */
-    bool	use_ff;		/* set to one if the current line should be
+    bool	use_ff;		/* whether the current line should be
 				 * terminated with a form feed */
-    bool	want_blank;	/* set to true when the following token should
+    bool	want_blank;	/* whether the following token should
 				 * be prefixed by a blank. (Said prefixing is
 				 * ignored in some cases.) */
     enum rwcode keyword;	/* the type of a keyword or 0 */

Index: src/usr.bin/indent/io.c
diff -u src/usr.bin/indent/io.c:1.63 src/usr.bin/indent/io.c:1.64
--- src/usr.bin/indent/io.c:1.63	Sat Sep 25 20:23:42 2021
+++ src/usr.bin/indent/io.c	Sat Sep 25 20:56:53 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: io.c,v 1.63 2021/09/25 20:23:42 rillig Exp $	*/
+/*	$NetBSD: io.c,v 1.64 2021/09/25 20:56:53 rillig Exp $	*/
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -43,7 +43,7 @@ static char sccsid[] = "@(#)io.c	8.1 (Be
 
 #include <sys/cdefs.h>
 #if defined(__NetBSD__)
-__RCSID("$NetBSD: io.c,v 1.63 2021/09/25 20:23:42 rillig Exp $");
+__RCSID("$NetBSD: io.c,v 1.64 2021/09/25 20:56:53 rillig Exp $");
 #elif defined(__FreeBSD__)
 __FBSDID("$FreeBSD: head/usr.bin/indent/io.c 334927 2018-06-10 16:44:18Z pstef $");
 #endif
@@ -268,7 +268,7 @@ dump_line(void)
     *(lab.e = lab.s) = '\0';	/* reset buffers */
     *(code.e = code.s) = '\0';
     *(com.e = com.s = com.buf + 1) = '\0';
-    ps.ind_level = ps.i_l_follow;
+    ps.ind_level = ps.ind_level_follow;
     ps.paren_level = ps.p_l_follow;
     if (ps.paren_level > 0) {
         /* TODO: explain what negative indentation means */

Index: src/usr.bin/indent/parse.c
diff -u src/usr.bin/indent/parse.c:1.25 src/usr.bin/indent/parse.c:1.26
--- src/usr.bin/indent/parse.c:1.25	Sat Sep 25 17:36:51 2021
+++ src/usr.bin/indent/parse.c	Sat Sep 25 20:56:53 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: parse.c,v 1.25 2021/09/25 17:36:51 rillig Exp $	*/
+/*	$NetBSD: parse.c,v 1.26 2021/09/25 20:56:53 rillig Exp $	*/
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -83,7 +83,7 @@ parse(token_type ttype)
 	    break_comma = true;	/* while in declaration, newline should be
 				 * forced after comma */
 	    ps.p_stack[++ps.tos] = decl;
-	    ps.il[ps.tos] = ps.i_l_follow;
+	    ps.il[ps.tos] = ps.ind_level_follow;
 
 	    if (opt.ljust_decl) {/* only do if we want left justified
 				 * declarations */
@@ -92,7 +92,7 @@ parse(token_type ttype)
 		    if (ps.p_stack[i] == decl)
 			++ps.ind_level;	/* indentation is number of
 					 * declaration levels deep we are */
-		ps.i_l_follow = ps.ind_level;
+		ps.ind_level_follow = ps.ind_level;
 	    }
 	}
 	break;
@@ -104,15 +104,15 @@ parse(token_type ttype)
 	     * reducing "else if" to "if". This saves a lot of stack space
 	     * in case of a long "if-else-if ... else-if" sequence.
 	     */
-	    ps.i_l_follow = ps.il[ps.tos--];
+	    ps.ind_level_follow = ps.il[ps.tos--];
 	}
 	/* the rest is the same as for keyword_do and for_exprs */
 	/* FALLTHROUGH */
     case keyword_do:		/* 'do' */
     case for_exprs:		/* 'for' (...) */
 	ps.p_stack[++ps.tos] = ttype;
-	ps.il[ps.tos] = ps.ind_level = ps.i_l_follow;
-	++ps.i_l_follow;	/* subsequent statements should be indented 1 */
+	ps.il[ps.tos] = ps.ind_level = ps.ind_level_follow;
+	++ps.ind_level_follow;	/* subsequent statements should be indented 1 */
 	ps.search_brace = opt.btype_2;
 	break;
 
@@ -120,8 +120,8 @@ parse(token_type ttype)
 	break_comma = false;	/* don't break comma in an initial list */
 	if (ps.p_stack[ps.tos] == stmt || ps.p_stack[ps.tos] == decl
 		|| ps.p_stack[ps.tos] == stmt_list)
-	    ++ps.i_l_follow;	/* it is a random, isolated stmt group or a
-				 * declaration */
+	    ++ps.ind_level_follow;	/* it is a random, isolated stmt
+				 * group or a declaration */
 	else {
 	    if (code.s == code.e) {
 		/*
@@ -143,19 +143,19 @@ parse(token_type ttype)
 	ps.il[ps.tos] = ps.ind_level;
 	ps.p_stack[++ps.tos] = stmt;
 	/* allow null stmt between braces */
-	ps.il[ps.tos] = ps.i_l_follow;
+	ps.il[ps.tos] = ps.ind_level_follow;
 	break;
 
     case while_expr:		/* 'while' '(' <expr> ')' */
 	if (ps.p_stack[ps.tos] == do_stmt) {
 	    /* it is matched with do stmt */
-	    ps.ind_level = ps.i_l_follow = ps.il[ps.tos];
+	    ps.ind_level = ps.ind_level_follow = ps.il[ps.tos];
 	    ps.p_stack[++ps.tos] = while_expr;
-	    ps.il[ps.tos] = ps.ind_level = ps.i_l_follow;
+	    ps.il[ps.tos] = ps.ind_level = ps.ind_level_follow;
 	} else {		/* it is a while loop */
 	    ps.p_stack[++ps.tos] = while_expr;
-	    ps.il[ps.tos] = ps.i_l_follow;
-	    ++ps.i_l_follow;
+	    ps.il[ps.tos] = ps.ind_level_follow;
+	    ++ps.ind_level_follow;
 	    ps.search_brace = opt.btype_2;
 	}
 
@@ -167,8 +167,8 @@ parse(token_type ttype)
 	else {
 	    ps.ind_level = ps.il[ps.tos];	/* indentation for else should
 						 * be same as for if */
-	    ps.i_l_follow = ps.ind_level + 1;	/* everything following should
-						 * be in 1 level */
+	    ps.ind_level_follow = ps.ind_level + 1; /* everything following
+				 * should be 1 level deeper */
 	    ps.p_stack[ps.tos] = if_expr_stmt_else;
 	    /* remember if with else */
 	    ps.search_brace = opt.btype_2 | opt.else_if;
@@ -178,7 +178,7 @@ parse(token_type ttype)
     case rbrace:		/* scanned a } */
 	/* stack should have <lbrace> <stmt> or <lbrace> <stmt_list> */
 	if (ps.tos > 0 && ps.p_stack[ps.tos - 1] == lbrace) {
-	    ps.ind_level = ps.i_l_follow = ps.il[--ps.tos];
+	    ps.ind_level = ps.ind_level_follow = ps.il[--ps.tos];
 	    ps.p_stack[ps.tos] = stmt;
 	} else
 	    diag(1, "Statement nesting error");
@@ -188,12 +188,11 @@ parse(token_type ttype)
 	ps.p_stack[++ps.tos] = switch_expr;
 	ps.cstk[ps.tos] = case_ind;
 	/* save current case indent level */
-	ps.il[ps.tos] = ps.i_l_follow;
-	case_ind = ps.i_l_follow + opt.case_indent;	/* cases should be one
-							 * level down from
-							 * switch */
-	ps.i_l_follow += opt.case_indent + 1;	/* statements should be two
-						 * levels in */
+	ps.il[ps.tos] = ps.ind_level_follow;
+	case_ind = ps.ind_level_follow + opt.case_indent; /* cases should be
+				 * one level deeper than the switch */
+	ps.ind_level_follow += opt.case_indent + 1; /* statements should be
+				 * two levels deeper */
 	ps.search_brace = opt.btype_2;
 	break;
 
@@ -246,7 +245,7 @@ reduce_stmt(void)
 
     case keyword_do:	/* 'do' <stmt> */
 	ps.p_stack[--ps.tos] = do_stmt;
-	ps.i_l_follow = ps.il[ps.tos];
+	ps.ind_level_follow = ps.il[ps.tos];
 	return true;
 
     case if_expr:	/* 'if' '(' <expr> ')' <stmt> */
@@ -256,7 +255,7 @@ reduce_stmt(void)
 	       ps.p_stack[i] != stmt_list &&
 	       ps.p_stack[i] != lbrace)
 	    --i;
-	ps.i_l_follow = ps.il[i];
+	ps.ind_level_follow = ps.il[i];
 	/*
 	 * for the time being, we will assume that there is no else on
 	 * this if, and set the indentation level accordingly. If an
@@ -272,7 +271,7 @@ reduce_stmt(void)
     case for_exprs:	/* 'for' '(' ... ')' <stmt> */
     case while_expr:	/* 'while' '(' <expr> ')' <stmt> */
 	ps.p_stack[--ps.tos] = stmt;
-	ps.i_l_follow = ps.il[ps.tos];
+	ps.ind_level_follow = ps.il[ps.tos];
 	return true;
 
     default:		/* <anything else> <stmt> */

Reply via email to