Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.bin/xlint/lint1 lint: rename pushctrl and popctrl to be ...



details:   https://anonhg.NetBSD.org/src/rev/fb09ea3e0696
branches:  trunk
changeset: 953970:fb09ea3e0696
user:      rillig <rillig%NetBSD.org@localhost>
date:      Fri Mar 26 18:54:39 2021 +0000

description:
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.

diffstat:

 usr.bin/xlint/lint1/cgram.y    |   8 ++++----
 usr.bin/xlint/lint1/externs1.h |   6 +++---
 usr.bin/xlint/lint1/func.c     |  32 ++++++++++++++++----------------
 usr.bin/xlint/lint1/lint1.h    |  13 +++++++++++--
 4 files changed, 34 insertions(+), 25 deletions(-)

diffs (222 lines):

diff -r 53f1bd85af0a -r fb09ea3e0696 usr.bin/xlint/lint1/cgram.y
--- a/usr.bin/xlint/lint1/cgram.y       Fri Mar 26 17:44:52 2021 +0000
+++ b/usr.bin/xlint/lint1/cgram.y       Fri Mar 26 18:54:39 2021 +0000
@@ -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 @@
                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);
          }
        ;
 
diff -r 53f1bd85af0a -r fb09ea3e0696 usr.bin/xlint/lint1/externs1.h
--- a/usr.bin/xlint/lint1/externs1.h    Fri Mar 26 17:44:52 2021 +0000
+++ b/usr.bin/xlint/lint1/externs1.h    Fri Mar 26 18:54:39 2021 +0000
@@ -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    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);
diff -r 53f1bd85af0a -r fb09ea3e0696 usr.bin/xlint/lint1/func.c
--- a/usr.bin/xlint/lint1/func.c        Fri Mar 26 17:44:52 2021 +0000
+++ b/usr.bin/xlint/lint1/func.c        Fri Mar 26 18:54:39 2021 +0000
@@ -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 @@
  * 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 @@
  * 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 @@
                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 @@
        else if (!els)
                set_reached(true);
 
-       popctrl(T_IF);
+       end_control_statement(CS_IF);
 }
 
 /*
@@ -695,7 +695,7 @@
        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 @@
                 * if the end of the last statement inside it is reached.
                 */
 
-       popctrl(T_SWITCH);
+       end_control_statement(CS_SWITCH);
 }
 
 /*
@@ -776,7 +776,7 @@
        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 @@
        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 @@
                set_reached(true);
        }
 
-       pushctrl(T_DO);
+       begin_control_statement(CS_DO_WHILE);
        cstmt->c_loop = true;
 }
 
@@ -854,7 +854,7 @@
        if (cstmt->c_break)
                set_reached(true);
 
-       popctrl(T_DO);
+       end_control_statement(CS_DO_WHILE);
 }
 
 /*
@@ -874,7 +874,7 @@
                set_reached(true);
        }
 
-       pushctrl(T_FOR);
+       begin_control_statement(CS_FOR);
        cstmt->c_loop = true;
 
        /*
@@ -944,7 +944,7 @@
        /* 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);
 }
 
 /*
diff -r 53f1bd85af0a -r fb09ea3e0696 usr.bin/xlint/lint1/lint1.h
--- a/usr.bin/xlint/lint1/lint1.h       Fri Mar 26 17:44:52 2021 +0000
+++ b/usr.bin/xlint/lint1/lint1.h       Fri Mar 26 18:54:39 2021 +0000
@@ -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 @@
        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



Home | Main Index | Thread Index | Old Index