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 i_infinite to i_maybe_endless



details:   https://anonhg.NetBSD.org/src/rev/1b6a1f9e9b46
branches:  trunk
changeset: 1019831:1b6a1f9e9b46
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sun Mar 21 12:03:56 2021 +0000

description:
lint: rename i_infinite to i_maybe_endless

Not every loop that has 'while (1)' is an endless loop.  It may still
contain a 'return' somewhere.

diffstat:

 usr.bin/xlint/lint1/func.c  |  19 ++++++++++---------
 usr.bin/xlint/lint1/lint1.h |  11 +++++------
 2 files changed, 15 insertions(+), 15 deletions(-)

diffs (99 lines):

diff -r 03447c7574c6 -r 1b6a1f9e9b46 usr.bin/xlint/lint1/func.c
--- a/usr.bin/xlint/lint1/func.c        Sun Mar 21 11:55:59 2021 +0000
+++ b/usr.bin/xlint/lint1/func.c        Sun Mar 21 12:03:56 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: func.c,v 1.83 2021/03/21 11:55:59 rillig Exp $ */
+/*     $NetBSD: func.c,v 1.84 2021/03/21 12:03:56 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.83 2021/03/21 11:55:59 rillig Exp $");
+__RCSID("$NetBSD: func.c,v 1.84 2021/03/21 12:03:56 rillig Exp $");
 #endif
 
 #include <stdlib.h>
@@ -761,7 +761,7 @@
        pushctrl(T_WHILE);
        cstmt->c_loop = true;
        if (tn != NULL && tn->tn_op == CON)
-               cstmt->c_infinite = constant_is_nonzero(tn);
+               cstmt->c_maybe_endless = constant_is_nonzero(tn);
 
        check_getopt_begin_while(tn);
        expr(tn, false, true, true, false);
@@ -779,7 +779,7 @@
         * The end of the loop can be reached if it is no endless loop
         * or there was a break statement which was reached.
         */
-       reached = !cstmt->c_infinite || cstmt->c_break;
+       reached = !cstmt->c_maybe_endless || cstmt->c_break;
        rchflg = false;
 
        check_getopt_end_while();
@@ -822,15 +822,15 @@
                tn = check_controlling_expression(tn);
 
        if (tn != NULL && tn->tn_op == CON) {
-               cstmt->c_infinite = constant_is_nonzero(tn);
-               if (!cstmt->c_infinite && cstmt->c_cont)
+               cstmt->c_maybe_endless = constant_is_nonzero(tn);
+               if (!cstmt->c_maybe_endless && cstmt->c_cont)
                        /* continue in 'do ... while (0)' loop */
                        error(323);
        }
 
        expr(tn, false, true, true, true);
 
-       if (cstmt->c_infinite)
+       if (cstmt->c_maybe_endless)
                reached = false;
        if (cstmt->c_break)
                reached = true;
@@ -877,7 +877,7 @@
        if (tn2 != NULL)
                expr(tn2, false, true, true, false);
 
-       cstmt->c_infinite =
+       cstmt->c_maybe_endless =
            tn2 == NULL || (tn2->tn_op == CON && constant_is_nonzero(tn2));
 
        /* Checking the reinitialization expression is done in for2() */
@@ -924,7 +924,8 @@
        csrc_pos = cspos;
 
        /* An endless loop without break will never terminate */
-       reached = cstmt->c_break || !cstmt->c_infinite;
+       /* TODO: What if the loop contains a 'return'? */
+       reached = cstmt->c_break || !cstmt->c_maybe_endless;
        rchflg = false;
 
        popctrl(T_FOR);
diff -r 03447c7574c6 -r 1b6a1f9e9b46 usr.bin/xlint/lint1/lint1.h
--- a/usr.bin/xlint/lint1/lint1.h       Sun Mar 21 11:55:59 2021 +0000
+++ b/usr.bin/xlint/lint1/lint1.h       Sun Mar 21 12:03:56 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: lint1.h,v 1.81 2021/03/21 11:55:59 rillig Exp $ */
+/* $NetBSD: lint1.h,v 1.82 2021/03/21 12:03:56 rillig Exp $ */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
@@ -390,11 +390,10 @@
                                         * reachable? */
        bool    c_cont : 1;             /* loop has continue */
        bool    c_default : 1;          /* switch has default */
-       bool    c_infinite : 1;         /* controlling expression always false
-                                        * (as in for (;;) or while (1)),
-                                        * there may be break statements
-                                        * though.
-                                        * TODO: rename to c_maybe_infinite */
+       bool    c_maybe_endless : 1;    /* the controlling expression is
+                                        * always true (as in 'for (;;)' or
+                                        * 'while (1)'), there may be break
+                                        * statements though */
        bool    c_rchif : 1;            /* end of if-branch reached */
        bool    c_had_return_noval : 1; /* had "return;" */
        bool    c_had_return_value : 1; /* had "return (e);" */



Home | Main Index | Thread Index | Old Index