Module Name: src Committed By: rillig Date: Thu Oct 28 21:51:43 UTC 2021
Modified Files: src/usr.bin/indent: indent.c indent.h parse.c Log Message: indent: clean up comments and function names Having accurate names for the lexer symbols and the parser symbols makes most of the comments redundant. Remove these. Rename process_decl to process_type, to match the name of the corresponding lexer symbol. In this phase, it's just a single type token, not a whole declaration. No functional change. To generate a diff of this commit: cvs rdiff -u -r1.163 -r1.164 src/usr.bin/indent/indent.c cvs rdiff -u -r1.52 -r1.53 src/usr.bin/indent/indent.h cvs rdiff -u -r1.42 -r1.43 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.163 src/usr.bin/indent/indent.c:1.164 --- src/usr.bin/indent/indent.c:1.163 Thu Oct 28 21:32:49 2021 +++ src/usr.bin/indent/indent.c Thu Oct 28 21:51:43 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: indent.c,v 1.163 2021/10/28 21:32:49 rillig Exp $ */ +/* $NetBSD: indent.c,v 1.164 2021/10/28 21:51:43 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.163 2021/10/28 21:32:49 rillig Exp $"); +__RCSID("$NetBSD: indent.c,v 1.164 2021/10/28 21:51:43 rillig Exp $"); #elif defined(__FreeBSD__) __FBSDID("$FreeBSD: head/usr.bin/indent/indent.c 340138 2018-11-04 19:24:49Z oshogbo $"); #endif @@ -341,6 +341,12 @@ search_stmt_lookahead(lexer_symbol *lsym } } +/* + * Move newlines and comments following an 'if (expr)', 'while (expr)', + * 'else', etc. up to the start of the following statement to a buffer. This + * allows proper handling of both kinds of brace placement (-br, -bl) and + * "cuddling else" (-ce). + */ static void search_stmt(lexer_symbol *lsym, bool *force_nl, bool *comment_buffered, bool *last_else) @@ -1070,7 +1076,7 @@ process_keyword_else(bool *force_nl, boo } static void -process_decl(int *decl_ind, bool *tabs_to_var) +process_type(int *decl_ind, bool *tabs_to_var) { parse(psym_decl); /* let the parser worry about indentation */ @@ -1350,12 +1356,6 @@ main_loop(void) * characters read are stored in * "token". */ - /* - * Move newlines and comments following an if (), while (), else, etc. - * up to the start of the following stmt to a buffer. This allows - * proper handling of both kinds of brace placement (-br, -bl) and - * cuddling "else" (-ce). - */ search_stmt(&lsym, &force_nl, &comment_buffered, &last_else); if (lsym == lsym_eof) { @@ -1405,7 +1405,7 @@ main_loop(void) process_question(&quest_level); break; - case lsym_case_label: /* got word 'case' or 'default' */ + case lsym_case_label: seen_case = true; goto copy_token; @@ -1431,7 +1431,7 @@ main_loop(void) spaced_expr = true; /* the interesting stuff is done after the * expressions are scanned */ hd = hd_switch; /* remember the type of header for later use - * by parser */ + * by the parser */ goto copy_token; case lsym_for: @@ -1467,11 +1467,11 @@ main_loop(void) goto copy_token; /* FALLTHROUGH */ case lsym_type: - process_decl(&decl_ind, &tabs_to_var); + process_type(&decl_ind, &tabs_to_var); goto copy_token; case lsym_funcname: - case lsym_ident: /* an identifier, constant or string */ + case lsym_ident: process_ident(lsym, decl_ind, tabs_to_var, &spaced_expr, &force_nl, hd); copy_token: @@ -1492,11 +1492,11 @@ main_loop(void) process_comma(decl_ind, tabs_to_var, &force_nl); break; - case lsym_preprocessing: /* the initial '#' */ + case lsym_preprocessing: process_preprocessing(); break; - case lsym_comment: /* the initial '/' '*' or '//' of a comment */ + case lsym_comment: process_comment(); break; Index: src/usr.bin/indent/indent.h diff -u src/usr.bin/indent/indent.h:1.52 src/usr.bin/indent/indent.h:1.53 --- src/usr.bin/indent/indent.h:1.52 Tue Oct 26 20:43:35 2021 +++ src/usr.bin/indent/indent.h Thu Oct 28 21:51:43 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: indent.h,v 1.52 2021/10/26 20:43:35 rillig Exp $ */ +/* $NetBSD: indent.h,v 1.53 2021/10/28 21:51:43 rillig Exp $ */ /*- * SPDX-License-Identifier: BSD-2-Clause-FreeBSD @@ -75,7 +75,7 @@ typedef enum lexer_symbol { lsym_preprocessing, /* '#' */ lsym_newline, lsym_form_feed, - lsym_comment, + lsym_comment, /* the initial '/' '*' or '//' of a comment */ lsym_lparen_or_lbracket, lsym_rparen_or_rbracket, lsym_lbrace, @@ -91,8 +91,8 @@ typedef enum lexer_symbol { lsym_typedef, lsym_storage_class, lsym_type, - lsym_tag, /* 'struct', 'union', 'enum' */ - lsym_case_label, + lsym_tag, /* 'struct', 'union' or 'enum' */ + lsym_case_label, /* 'case' or 'default' */ lsym_string_prefix, /* 'L' */ lsym_ident, /* identifier, constant or string */ lsym_funcname, Index: src/usr.bin/indent/parse.c diff -u src/usr.bin/indent/parse.c:1.42 src/usr.bin/indent/parse.c:1.43 --- src/usr.bin/indent/parse.c:1.42 Tue Oct 26 19:36:30 2021 +++ src/usr.bin/indent/parse.c Thu Oct 28 21:51:43 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: parse.c,v 1.42 2021/10/26 19:36:30 rillig Exp $ */ +/* $NetBSD: parse.c,v 1.43 2021/10/28 21:51:43 rillig Exp $ */ /*- * SPDX-License-Identifier: BSD-4-Clause @@ -270,17 +270,17 @@ reduce_stmt(void) { switch (ps.s_sym[ps.tos - 1]) { - case psym_stmt: /* stmt stmt */ - case psym_stmt_list: /* stmt_list stmt */ + case psym_stmt: + case psym_stmt_list: ps.s_sym[--ps.tos] = psym_stmt_list; return true; - case psym_do: /* 'do' <stmt> */ + case psym_do: ps.s_sym[--ps.tos] = psym_do_stmt; ps.ind_level_follow = ps.s_ind_level[ps.tos]; return true; - case psym_if_expr: /* 'if' '(' <expr> ')' <stmt> */ + case psym_if_expr: ps.s_sym[--ps.tos] = psym_if_expr_stmt; int i = ps.tos - 1; while (ps.s_sym[i] != psym_stmt && @@ -289,25 +289,24 @@ reduce_stmt(void) --i; ps.ind_level_follow = ps.s_ind_level[i]; /* - * for the time being, we will assume that there is no else on this - * if, and set the indentation level accordingly. If an 'else' is - * scanned, it will be fixed up later + * For the time being, assume that there is no 'else' on this 'if', + * and set the indentation level accordingly. If an 'else' is + * scanned, it will be fixed up later. */ return true; - case psym_switch_expr: /* 'switch' '(' <expr> ')' <stmt> */ + case psym_switch_expr: case_ind = ps.s_case_ind_level[ps.tos - 1]; /* FALLTHROUGH */ case psym_decl: /* finish of a declaration */ - case psym_if_expr_stmt_else: /* 'if' '(' <expr> ')' <stmt> 'else' - * <stmt> */ - case psym_for_exprs: /* 'for' '(' ... ')' <stmt> */ - case psym_while_expr: /* 'while' '(' <expr> ')' <stmt> */ + case psym_if_expr_stmt_else: + case psym_for_exprs: + case psym_while_expr: ps.s_sym[--ps.tos] = psym_stmt; ps.ind_level_follow = ps.s_ind_level[ps.tos]; return true; - default: /* <anything else> <stmt> */ + default: return false; } }