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: merge duplicate code for removing ...



details:   https://anonhg.NetBSD.org/src/rev/563b1a0b400c
branches:  trunk
changeset: 1022664:563b1a0b400c
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sun Aug 01 07:46:51 2021 +0000

description:
lint: merge duplicate code for removing a symbol from the table

No functional change.

diffstat:

 usr.bin/xlint/lint1/lex.c |  36 +++++++++++++++++++-----------------
 1 files changed, 19 insertions(+), 17 deletions(-)

diffs (85 lines):

diff -r 4ff88d55faa7 -r 563b1a0b400c usr.bin/xlint/lint1/lex.c
--- a/usr.bin/xlint/lint1/lex.c Sun Aug 01 06:58:58 2021 +0000
+++ b/usr.bin/xlint/lint1/lex.c Sun Aug 01 07:46:51 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: lex.c,v 1.60 2021/08/01 06:58:58 rillig Exp $ */
+/* $NetBSD: lex.c,v 1.61 2021/08/01 07:46:51 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: lex.c,v 1.60 2021/08/01 06:58:58 rillig Exp $");
+__RCSID("$NetBSD: lex.c,v 1.61 2021/08/01 07:46:51 rillig Exp $");
 #endif
 
 #include <ctype.h>
@@ -278,6 +278,16 @@
 }
 
 static void
+symtab_remove(sym_t *sym)
+{
+
+       if ((*sym->s_rlink = sym->s_link) != NULL)
+               sym->s_link->s_rlink = sym->s_rlink;
+       sym->s_link = NULL;
+}
+
+
+static void
 add_keyword(const struct kwtab *kw, u_int deco)
 {
        sym_t *sym;
@@ -1504,21 +1514,17 @@
        return sym;
 }
 
-/*
- * Remove a symbol forever from the symbol table. s_block_level
- * is set to -1 to avoid that the symbol will later be put
- * back to the symbol table.
- */
+/* Remove a symbol forever from the symbol table. */
 void
 rmsym(sym_t *sym)
 {
 
        debug_step("rmsym '%s' %d '%s'",
            sym->s_name, (int)sym->s_kind, type_name(sym->s_type));
-       if ((*sym->s_rlink = sym->s_link) != NULL)
-               sym->s_link->s_rlink = sym->s_rlink;
+       symtab_remove(sym);
+
+       /* avoid that the symbol will later be put back to the symbol table */
        sym->s_block_level = -1;
-       sym->s_link = NULL;
 }
 
 /*
@@ -1535,9 +1541,7 @@
                        debug_step("rmsyms '%s' %d '%s'",
                            sym->s_name, (int)sym->s_kind,
                            type_name(sym->s_type));
-                       if ((*sym->s_rlink = sym->s_link) != NULL)
-                               sym->s_link->s_rlink = sym->s_rlink;
-                       sym->s_link = NULL;
+                       symtab_remove(sym);
                        sym->s_rlink = NULL;
                }
        }
@@ -1574,10 +1578,8 @@
        for (i = 0; i < HSHSIZ1; i++) {
                for (sym = symtab[i]; sym != NULL; sym = nsym) {
                        nsym = sym->s_link;
-                       if (sym->s_block_level >= 1) {
-                               if ((*sym->s_rlink = nsym) != NULL)
-                                       nsym->s_rlink = sym->s_rlink;
-                       }
+                       if (sym->s_block_level >= 1)
+                               symtab_remove(sym);
                }
        }
 



Home | Main Index | Thread Index | Old Index