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: extract duplicate code for modifyi...
details: https://anonhg.NetBSD.org/src/rev/9880948dafb2
branches: trunk
changeset: 984937:9880948dafb2
user: rillig <rillig%NetBSD.org@localhost>
date: Sun Aug 01 06:58:58 2021 +0000
description:
lint: extract duplicate code for modifying the symbol table
No functional change.
diffstat:
usr.bin/xlint/lint1/lex.c | 63 ++++++++++++++++++++++------------------------
1 files changed, 30 insertions(+), 33 deletions(-)
diffs (161 lines):
diff -r d77ab5e99f99 -r 9880948dafb2 usr.bin/xlint/lint1/lex.c
--- a/usr.bin/xlint/lint1/lex.c Sun Aug 01 06:40:37 2021 +0000
+++ b/usr.bin/xlint/lint1/lex.c Sun Aug 01 06:58:58 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: lex.c,v 1.59 2021/08/01 06:40:37 rillig Exp $ */
+/* $NetBSD: lex.c,v 1.60 2021/08/01 06:58:58 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.59 2021/08/01 06:40:37 rillig Exp $");
+__RCSID("$NetBSD: lex.c,v 1.60 2021/08/01 06:58:58 rillig Exp $");
#endif
#include <ctype.h>
@@ -259,10 +259,28 @@
static void
+symtab_add_hash(sym_t *sym, size_t h)
+{
+
+ if ((sym->s_link = symtab[h]) != NULL)
+ symtab[h]->s_rlink = &sym->s_link;
+ sym->s_rlink = &symtab[h];
+ symtab[h] = sym;
+}
+
+static void
+symtab_add(sym_t *sym)
+{
+ size_t h;
+
+ h = hash(sym->s_name);
+ symtab_add_hash(sym, h);
+}
+
+static void
add_keyword(const struct kwtab *kw, u_int deco)
{
sym_t *sym;
- size_t h;
char buf[256];
const char *name;
@@ -298,11 +316,8 @@
} else if (kw->kw_token == T_QUAL) {
sym->s_tqual = kw->kw_tqual;
}
- h = hash(sym->s_name);
- if ((sym->s_link = symtab[h]) != NULL)
- symtab[h]->s_rlink = &sym->s_link;
- sym->s_rlink = &symtab[h];
- symtab[h] = sym;
+
+ symtab_add(sym);
}
/*
@@ -1380,15 +1395,15 @@
}
/*
- * As noted above the scanner does not create new symbol table entries
+ * As noted above, the scanner does not create new symbol table entries
* for symbols it cannot find in the symbol table. This is to avoid
* putting undeclared symbols into the symbol table if a syntax error
* occurs.
*
- * getsym() is called as soon as it is probably ok to put the symbol to the
+ * getsym() is called as soon as it is probably ok to put the symbol in the
* symbol table. It is still possible that symbols are put in the symbol
* table that are not completely declared due to syntax errors. To avoid too
- * many problems in this case, symbols get type int in getsym().
+ * many problems in this case, symbols get type 'int' in getsym().
*
* XXX calls to getsym() should be delayed until decl1*() is called.
*/
@@ -1446,10 +1461,7 @@
symtyp = FVFT;
- if ((sym->s_link = symtab[sb->sb_hash]) != NULL)
- symtab[sb->sb_hash]->s_rlink = &sym->s_link;
- sym->s_rlink = &symtab[sb->sb_hash];
- symtab[sb->sb_hash] = sym;
+ symtab_add_hash(sym, sb->sb_hash);
*di->d_ldlsym = sym;
di->d_ldlsym = &sym->s_dlnxt;
@@ -1466,13 +1478,11 @@
mktempsym(type_t *t)
{
static int n = 0;
- int h;
char *s = getlblk(block_level, 64);
sym_t *sym = getblk(sizeof(*sym));
scl_t scl;
(void)snprintf(s, 64, "%.8d_tmp", n++);
- h = hash(s);
scl = dcs->d_scl;
if (scl == NOSCL)
@@ -1486,10 +1496,7 @@
sym->s_used = true;
sym->s_set = true;
- if ((sym->s_link = symtab[h]) != NULL)
- symtab[h]->s_rlink = &sym->s_link;
- sym->s_rlink = &symtab[h];
- symtab[h] = sym;
+ symtab_add(sym);
*dcs->d_ldlsym = sym;
dcs->d_ldlsym = &sym->s_dlnxt;
@@ -1542,15 +1549,10 @@
void
inssym(int bl, sym_t *sym)
{
- int h;
debug_step("inssym '%s' %d '%s'",
sym->s_name, sym->s_kind, type_name(sym->s_type));
- h = hash(sym->s_name);
- if ((sym->s_link = symtab[h]) != NULL)
- symtab[h]->s_rlink = &sym->s_link;
- sym->s_rlink = &symtab[h];
- symtab[h] = sym;
+ symtab_add(sym);
sym->s_block_level = bl;
lint_assert(sym->s_link == NULL ||
sym->s_block_level >= sym->s_link->s_block_level);
@@ -1589,12 +1591,10 @@
sym_t *
pushdown(const sym_t *sym)
{
- int h;
sym_t *nsym;
debug_step("pushdown '%s' %d '%s'",
sym->s_name, (int)sym->s_kind, type_name(sym->s_type));
- h = hash(sym->s_name);
nsym = getblk(sizeof(*nsym));
lint_assert(sym->s_block_level <= block_level);
nsym->s_name = sym->s_name;
@@ -1602,10 +1602,7 @@
nsym->s_kind = sym->s_kind;
nsym->s_block_level = block_level;
- if ((nsym->s_link = symtab[h]) != NULL)
- symtab[h]->s_rlink = &nsym->s_link;
- nsym->s_rlink = &symtab[h];
- symtab[h] = nsym;
+ symtab_add(nsym);
*dcs->d_ldlsym = nsym;
dcs->d_ldlsym = &nsym->s_dlnxt;
Home |
Main Index |
Thread Index |
Old Index