Module Name: src Committed By: rillig Date: Fri Mar 26 18:54:39 UTC 2021
Modified Files: src/usr.bin/xlint/lint1: cgram.y externs1.h func.c lint1.h Log Message: lint: rename pushctrl and popctrl to be more expressive While here, remove the magic number 0 that in this context means "function body". No functional change. To generate a diff of this commit: cvs rdiff -u -r1.202 -r1.203 src/usr.bin/xlint/lint1/cgram.y cvs rdiff -u -r1.86 -r1.87 src/usr.bin/xlint/lint1/externs1.h cvs rdiff -u -r1.95 -r1.96 src/usr.bin/xlint/lint1/func.c cvs rdiff -u -r1.87 -r1.88 src/usr.bin/xlint/lint1/lint1.h 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/xlint/lint1/cgram.y diff -u src/usr.bin/xlint/lint1/cgram.y:1.202 src/usr.bin/xlint/lint1/cgram.y:1.203 --- src/usr.bin/xlint/lint1/cgram.y:1.202 Fri Mar 26 17:44:52 2021 +++ src/usr.bin/xlint/lint1/cgram.y Fri Mar 26 18:54:39 2021 @@ -1,5 +1,5 @@ %{ -/* $NetBSD: cgram.y,v 1.202 2021/03/26 17:44:52 rillig Exp $ */ +/* $NetBSD: cgram.y,v 1.203 2021/03/26 18:54:39 rillig Exp $ */ /* * Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved. @@ -35,7 +35,7 @@ #include <sys/cdefs.h> #if defined(__RCSID) && !defined(lint) -__RCSID("$NetBSD: cgram.y,v 1.202 2021/03/26 17:44:52 rillig Exp $"); +__RCSID("$NetBSD: cgram.y,v 1.203 2021/03/26 18:54:39 rillig Exp $"); #endif #include <limits.h> @@ -447,10 +447,10 @@ function_definition: /* C99 6.9.1 */ block_level--; check_func_lint_directives(); check_func_old_style_arguments(); - pushctrl(0); + begin_control_statement(CS_FUNCTION_BODY); } compound_statement { funcend(); - popctrl(0); + end_control_statement(CS_FUNCTION_BODY); } ; Index: src/usr.bin/xlint/lint1/externs1.h diff -u src/usr.bin/xlint/lint1/externs1.h:1.86 src/usr.bin/xlint/lint1/externs1.h:1.87 --- src/usr.bin/xlint/lint1/externs1.h:1.86 Fri Mar 26 17:44:52 2021 +++ src/usr.bin/xlint/lint1/externs1.h Fri Mar 26 18:54:39 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: externs1.h,v 1.86 2021/03/26 17:44:52 rillig Exp $ */ +/* $NetBSD: externs1.h,v 1.87 2021/03/26 18:54:39 rillig Exp $ */ /* * Copyright (c) 1994, 1995 Jochen Pohl @@ -252,8 +252,8 @@ extern bool bitfieldtype_ok; extern bool plibflg; extern bool quadflg; -extern void pushctrl(int); -extern void popctrl(int); +extern void begin_control_statement(control_statement_kind); +extern void end_control_statement(control_statement_kind); extern void check_statement_reachable(void); extern void funcdef(sym_t *); extern void funcend(void); Index: src/usr.bin/xlint/lint1/func.c diff -u src/usr.bin/xlint/lint1/func.c:1.95 src/usr.bin/xlint/lint1/func.c:1.96 --- src/usr.bin/xlint/lint1/func.c:1.95 Sun Mar 21 19:14:40 2021 +++ src/usr.bin/xlint/lint1/func.c Fri Mar 26 18:54:39 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: func.c,v 1.95 2021/03/21 19:14:40 rillig Exp $ */ +/* $NetBSD: func.c,v 1.96 2021/03/26 18:54:39 rillig Exp $ */ /* * Copyright (c) 1994, 1995 Jochen Pohl @@ -37,7 +37,7 @@ #include <sys/cdefs.h> #if defined(__RCSID) && !defined(lint) -__RCSID("$NetBSD: func.c,v 1.95 2021/03/21 19:14:40 rillig Exp $"); +__RCSID("$NetBSD: func.c,v 1.96 2021/03/26 18:54:39 rillig Exp $"); #endif #include <stdlib.h> @@ -153,12 +153,12 @@ bool quadflg; * Puts a new element at the top of the stack used for control statements. */ void -pushctrl(int env) +begin_control_statement(control_statement_kind kind) { cstk_t *ci; ci = xcalloc(1, sizeof (cstk_t)); - ci->c_env = env; + ci->c_kind = kind; ci->c_surrounding = cstmt; cstmt = ci; } @@ -167,13 +167,13 @@ pushctrl(int env) * Removes the top element of the stack used for control statements. */ void -popctrl(int env) +end_control_statement(control_statement_kind kind) { cstk_t *ci; case_label_t *cl, *next; lint_assert(cstmt != NULL); - lint_assert(cstmt->c_env == env); + lint_assert(cstmt->c_kind == kind); ci = cstmt; cstmt = ci->c_surrounding; @@ -611,7 +611,7 @@ if1(tnode_t *tn) tn = check_controlling_expression(tn); if (tn != NULL) expr(tn, false, true, false, false); - pushctrl(T_IF); + begin_control_statement(CS_IF); if (tn != NULL && tn->tn_op == CON && !tn->tn_system_dependent) { /* XXX: what if inside 'if (0)'? */ @@ -648,7 +648,7 @@ if3(bool els) else if (!els) set_reached(true); - popctrl(T_IF); + end_control_statement(CS_IF); } /* @@ -695,7 +695,7 @@ switch1(tnode_t *tn) check_getopt_begin_switch(); expr(tn, true, false, true, false); - pushctrl(T_SWITCH); + begin_control_statement(CS_SWITCH); cstmt->c_switch = true; cstmt->c_swtype = tp; @@ -755,7 +755,7 @@ switch2(void) * if the end of the last statement inside it is reached. */ - popctrl(T_SWITCH); + end_control_statement(CS_SWITCH); } /* @@ -776,7 +776,7 @@ while1(tnode_t *tn) if (tn != NULL) tn = check_controlling_expression(tn); - pushctrl(T_WHILE); + begin_control_statement(CS_WHILE); cstmt->c_loop = true; cstmt->c_maybe_endless = is_nonzero(tn); body_reached = !is_zero(tn); @@ -802,7 +802,7 @@ while2(void) set_reached(!cstmt->c_maybe_endless || cstmt->c_break); check_getopt_end_while(); - popctrl(T_WHILE); + end_control_statement(CS_WHILE); } /* @@ -818,7 +818,7 @@ do1(void) set_reached(true); } - pushctrl(T_DO); + begin_control_statement(CS_DO_WHILE); cstmt->c_loop = true; } @@ -854,7 +854,7 @@ do2(tnode_t *tn) if (cstmt->c_break) set_reached(true); - popctrl(T_DO); + end_control_statement(CS_DO_WHILE); } /* @@ -874,7 +874,7 @@ for1(tnode_t *tn1, tnode_t *tn2, tnode_t set_reached(true); } - pushctrl(T_FOR); + begin_control_statement(CS_FOR); cstmt->c_loop = true; /* @@ -944,7 +944,7 @@ for2(void) /* TODO: What if the loop contains a 'return'? */ set_reached(cstmt->c_break || !cstmt->c_maybe_endless); - popctrl(T_FOR); + end_control_statement(CS_FOR); } /* Index: src/usr.bin/xlint/lint1/lint1.h diff -u src/usr.bin/xlint/lint1/lint1.h:1.87 src/usr.bin/xlint/lint1/lint1.h:1.88 --- src/usr.bin/xlint/lint1/lint1.h:1.87 Sun Mar 21 15:34:13 2021 +++ src/usr.bin/xlint/lint1/lint1.h Fri Mar 26 18:54:39 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: lint1.h,v 1.87 2021/03/21 15:34:13 rillig Exp $ */ +/* $NetBSD: lint1.h,v 1.88 2021/03/26 18:54:39 rillig Exp $ */ /* * Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved. @@ -378,11 +378,20 @@ typedef struct case_label { struct case_label *cl_next; } case_label_t; +typedef enum { + CS_DO_WHILE, + CS_FOR, + CS_FUNCTION_BODY, + CS_IF, + CS_SWITCH, + CS_WHILE +} control_statement_kind; + /* * Used to keep information about nested control statements. */ typedef struct control_statement { - int c_env; /* type of statement (T_IF, ...) */ + control_statement_kind c_kind; /* to ensure proper nesting */ bool c_loop : 1; /* continue && break are valid */ bool c_switch : 1; /* case && break are valid */ bool c_break : 1; /* the loop/switch has a reachable