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: split declare_local into smaller f...



details:   https://anonhg.NetBSD.org/src/rev/8ee4a017ab25
branches:  trunk
changeset: 1023345:8ee4a017ab25
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sat Sep 04 12:05:54 2021 +0000

description:
lint: split declare_local into smaller functions

diffstat:

 usr.bin/xlint/lint1/decl.c |  131 +++++++++++++++++++++-----------------------
 1 files changed, 64 insertions(+), 67 deletions(-)

diffs (159 lines):

diff -r 2cf0f784a032 -r 8ee4a017ab25 usr.bin/xlint/lint1/decl.c
--- a/usr.bin/xlint/lint1/decl.c        Sat Sep 04 10:26:44 2021 +0000
+++ b/usr.bin/xlint/lint1/decl.c        Sat Sep 04 12:05:54 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: decl.c,v 1.228 2021/08/29 15:49:04 rillig Exp $ */
+/* $NetBSD: decl.c,v 1.229 2021/09/04 12:05:54 rillig Exp $ */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
@@ -38,7 +38,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: decl.c,v 1.228 2021/08/29 15:49:04 rillig Exp $");
+__RCSID("$NetBSD: decl.c,v 1.229 2021/09/04 12:05:54 rillig Exp $");
 #endif
 
 #include <sys/param.h>
@@ -2656,6 +2656,66 @@
        return msg;
 }
 
+static void
+check_local_hiding(const sym_t *dsym)
+{
+       switch (dsym->s_scl) {
+       case AUTO:
+               /* automatic hides external declaration: %s */
+               warning(86, dsym->s_name);
+               break;
+       case STATIC:
+               /* static hides external declaration: %s */
+               warning(87, dsym->s_name);
+               break;
+       case TYPEDEF:
+               /* typedef hides external declaration: %s */
+               warning(88, dsym->s_name);
+               break;
+       case EXTERN:
+               /* Already checked in declare_external_in_block. */
+               break;
+       default:
+               lint_assert(/*CONSTCOND*/false);
+       }
+}
+
+static void
+check_local_redeclaration(const sym_t *dsym, sym_t *rsym)
+{
+       if (rsym->s_block_level == 0) {
+               if (hflag)
+                       check_local_hiding(dsym);
+
+       } else if (rsym->s_block_level == block_level) {
+
+               /* no hflag, because it's illegal! */
+               if (rsym->s_arg) {
+                       /*
+                        * if !tflag, a "redeclaration of %s" error
+                        * is produced below
+                        */
+                       if (tflag) {
+                               if (hflag)
+                                       /* decl. hides parameter: %s */
+                                       warning(91, dsym->s_name);
+                               rmsym(rsym);
+                       }
+               }
+
+       } else if (rsym->s_block_level < block_level) {
+               if (hflag)
+                       /* declaration hides earlier one: %s */
+                       warning(95, dsym->s_name);
+       }
+
+       if (rsym->s_block_level == block_level) {
+               /* redeclaration of %s */
+               error(27, dsym->s_name);
+               rmsym(rsym);
+       }
+}
+
 /*
  * Completes a single local declaration/definition.
  */
@@ -2717,71 +2777,8 @@
                }
        }
 
-       if (dcs->d_redeclared_symbol != NULL) {
-
-               if (dcs->d_redeclared_symbol->s_block_level == 0) {
-
-                       switch (dsym->s_scl) {
-                       case AUTO:
-                               if (hflag)
-                                       /* automatic hides external decl.: %s */
-                                       warning(86, dsym->s_name);
-                               break;
-                       case STATIC:
-                               if (hflag)
-                                       /* static hides external decl.: %s */
-                                       warning(87, dsym->s_name);
-                               break;
-                       case TYPEDEF:
-                               if (hflag)
-                                       /* typedef hides external decl.: %s */
-                                       warning(88, dsym->s_name);
-                               break;
-                       case EXTERN:
-                               /*
-                                * Warnings and errors are printed in
-                                * declare_external_in_block()
-                                */
-                               break;
-                       default:
-                               lint_assert(/*CONSTCOND*/false);
-                       }
-
-               } else if (dcs->d_redeclared_symbol->s_block_level ==
-                          block_level) {
-
-                       /* no hflag, because it's illegal! */
-                       if (dcs->d_redeclared_symbol->s_arg) {
-                               /*
-                                * if !tflag, a "redeclaration of %s" error
-                                * is produced below
-                                */
-                               if (tflag) {
-                                       if (hflag)
-                                               /* decl. hides parameter: %s */
-                                               warning(91, dsym->s_name);
-                                       rmsym(dcs->d_redeclared_symbol);
-                               }
-                       }
-
-               } else if (dcs->d_redeclared_symbol->s_block_level <
-                          block_level) {
-
-                       if (hflag)
-                               /* declaration hides earlier one: %s */
-                               warning(95, dsym->s_name);
-
-               }
-
-               if (dcs->d_redeclared_symbol->s_block_level == block_level) {
-
-                       /* redeclaration of %s */
-                       error(27, dsym->s_name);
-                       rmsym(dcs->d_redeclared_symbol);
-
-               }
-
-       }
+       if (dcs->d_redeclared_symbol != NULL)
+               check_local_redeclaration(dsym, dcs->d_redeclared_symbol);
 
        if (initflg && !check_init(dsym)) {
                dsym->s_def = DEF;



Home | Main Index | Thread Index | Old Index