Module Name: src
Committed By: rillig
Date: Sat Apr 9 13:38:17 UTC 2022
Modified Files:
src/usr.bin/xlint/lint1: cgram.y debug.c decl.c func.c lex.c lint1.h
tree.c
Log Message:
lint: inline member access macros for sym_t
Having the 'u.' explicitly in the code serves as a reminder that these
members are only defined under certain conditions.
No functional change.
To generate a diff of this commit:
cvs rdiff -u -r1.388 -r1.389 src/usr.bin/xlint/lint1/cgram.y
cvs rdiff -u -r1.11 -r1.12 src/usr.bin/xlint/lint1/debug.c
cvs rdiff -u -r1.270 -r1.271 src/usr.bin/xlint/lint1/decl.c
cvs rdiff -u -r1.130 -r1.131 src/usr.bin/xlint/lint1/func.c
cvs rdiff -u -r1.115 -r1.116 src/usr.bin/xlint/lint1/lex.c
cvs rdiff -u -r1.144 -r1.145 src/usr.bin/xlint/lint1/lint1.h
cvs rdiff -u -r1.419 -r1.420 src/usr.bin/xlint/lint1/tree.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/usr.bin/xlint/lint1/cgram.y
diff -u src/usr.bin/xlint/lint1/cgram.y:1.388 src/usr.bin/xlint/lint1/cgram.y:1.389
--- src/usr.bin/xlint/lint1/cgram.y:1.388 Wed Mar 9 00:20:48 2022
+++ src/usr.bin/xlint/lint1/cgram.y Sat Apr 9 13:38:17 2022
@@ -1,5 +1,5 @@
%{
-/* $NetBSD: cgram.y,v 1.388 2022/03/09 00:20:48 rillig Exp $ */
+/* $NetBSD: cgram.y,v 1.389 2022/04/09 13:38:17 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.388 2022/03/09 00:20:48 rillig Exp $");
+__RCSID("$NetBSD: cgram.y,v 1.389 2022/04/09 13:38:17 rillig Exp $");
#endif
#include <limits.h>
@@ -114,7 +114,7 @@ static void
anonymize(sym_t *s)
{
for ( ; s != NULL; s = s->s_next)
- s->s_sou_type = NULL;
+ s->u.s_sou_type = NULL;
}
#if defined(YYDEBUG) && (defined(YYBYACC) || defined(YYBISON))
Index: src/usr.bin/xlint/lint1/debug.c
diff -u src/usr.bin/xlint/lint1/debug.c:1.11 src/usr.bin/xlint/lint1/debug.c:1.12
--- src/usr.bin/xlint/lint1/debug.c:1.11 Sat Apr 2 14:28:30 2022
+++ src/usr.bin/xlint/lint1/debug.c Sat Apr 9 13:38:17 2022
@@ -1,4 +1,4 @@
-/* $NetBSD: debug.c,v 1.11 2022/04/02 14:28:30 rillig Exp $ */
+/* $NetBSD: debug.c,v 1.12 2022/04/09 13:38:17 rillig Exp $ */
/*-
* Copyright (c) 2021 The NetBSD Foundation, Inc.
@@ -35,7 +35,7 @@
#include <sys/cdefs.h>
#if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: debug.c,v 1.11 2022/04/02 14:28:30 rillig Exp $");
+__RCSID("$NetBSD: debug.c,v 1.12 2022/04/09 13:38:17 rillig Exp $");
#endif
#include <stdlib.h>
@@ -275,9 +275,9 @@ debug_sym(const char *prefix, const sym_
debug_printf(" value=%d", (int)sym->s_value.v_quad);
if ((sym->s_scl == MOS || sym->s_scl == MOU) &&
- sym->s_sou_type != NULL) {
- const char *tag = sym->s_sou_type->sou_tag->s_name;
- const sym_t *def = sym->s_sou_type->sou_first_typedef;
+ sym->u.s_sou_type != NULL) {
+ const char *tag = sym->u.s_sou_type->sou_tag->s_name;
+ const sym_t *def = sym->u.s_sou_type->sou_first_typedef;
if (tag == unnamed && def != NULL)
debug_printf(" sou='typedef %s'", def->s_name);
else
@@ -287,12 +287,13 @@ debug_sym(const char *prefix, const sym_
if (sym->s_keyword != NULL) {
int t = (int)sym->s_value.v_quad;
if (t == T_TYPE || t == T_STRUCT_OR_UNION)
- debug_printf(" %s", tspec_name(sym->s_tspec));
+ debug_printf(" %s", tspec_name(sym->u.s_tspec));
else if (t == T_QUAL)
- debug_printf(" %s", tqual_name(sym->s_tqual));
+ debug_printf(" %s", tqual_name(sym->u.s_qualifier));
}
- debug_word(sym->s_osdef && sym->s_args != NULL, "old-style-args");
+ debug_word(sym->s_osdef && sym->u.s_old_style_args != NULL,
+ "old-style-args");
debug_printf("%s", suffix);
}
Index: src/usr.bin/xlint/lint1/decl.c
diff -u src/usr.bin/xlint/lint1/decl.c:1.270 src/usr.bin/xlint/lint1/decl.c:1.271
--- src/usr.bin/xlint/lint1/decl.c:1.270 Sat Apr 9 13:22:05 2022
+++ src/usr.bin/xlint/lint1/decl.c Sat Apr 9 13:38:17 2022
@@ -1,4 +1,4 @@
-/* $NetBSD: decl.c,v 1.270 2022/04/09 13:22:05 rillig Exp $ */
+/* $NetBSD: decl.c,v 1.271 2022/04/09 13:38:17 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.270 2022/04/09 13:22:05 rillig Exp $");
+__RCSID("$NetBSD: decl.c,v 1.271 2022/04/09 13:38:17 rillig Exp $");
#endif
#include <sys/param.h>
@@ -1130,7 +1130,8 @@ declarator_1_struct_union(sym_t *dsym)
lint_assert(dcs->d_redeclared_symbol->s_scl == MOS ||
dcs->d_redeclared_symbol->s_scl == MOU);
- if (dsym->s_sou_type == dcs->d_redeclared_symbol->s_sou_type) {
+ if (dsym->u.s_sou_type ==
+ dcs->d_redeclared_symbol->u.s_sou_type) {
/* duplicate member name: %s */
error(33, dsym->s_name);
rmsym(dcs->d_redeclared_symbol);
@@ -1521,7 +1522,7 @@ old_style_function(sym_t *decl, sym_t *a
*/
if (args != NULL) {
decl->s_osdef = true;
- decl->s_args = args;
+ decl->u.s_old_style_args = args;
}
} else {
if (args != NULL)
@@ -1545,7 +1546,7 @@ check_function_definition(sym_t *sym, bo
error(22);
}
sym->s_osdef = false;
- sym->s_args = NULL;
+ sym->u.s_old_style_args = NULL;
}
}
@@ -1574,7 +1575,7 @@ declarator_name(sym_t *sym)
case MOS:
case MOU:
/* Set parent */
- sym->s_sou_type = dcs->d_tagtyp->t_str;
+ sym->u.s_sou_type = dcs->d_tagtyp->t_str;
sym->s_def = DEF;
sym->s_value.v_tspec = INT;
sc = dcs->d_ctx;
@@ -1857,8 +1858,8 @@ complete_tag_struct_or_union(type_t *tp,
n = 0;
for (mem = fmem; mem != NULL; mem = mem->s_next) {
/* bind anonymous members to the structure */
- if (mem->s_sou_type == NULL) {
- mem->s_sou_type = sp;
+ if (mem->u.s_sou_type == NULL) {
+ mem->u.s_sou_type = sp;
if (mem->s_type->t_bitfield) {
sp->sou_size_in_bits += bitfieldsize(&mem);
if (mem == NULL)
@@ -1993,8 +1994,9 @@ declare_extern(sym_t *dsym, bool initflg
/*
* If the old symbol stems from an old style function
- * definition, we have remembered the params in rdsym->s_args
- * and compare them with the params of the prototype.
+ * definition, we have remembered the params in
+ * rdsym->s_old_style_args and compare them with the params
+ * of the prototype.
*/
if (rdsym->s_osdef && dsym->s_type->t_proto) {
redec = check_old_style_definition(rdsym, dsym);
@@ -2021,7 +2023,8 @@ declare_extern(sym_t *dsym, bool initflg
*/
if (rdsym->s_osdef && !dsym->s_type->t_proto) {
dsym->s_osdef = rdsym->s_osdef;
- dsym->s_args = rdsym->s_args;
+ dsym->u.s_old_style_args =
+ rdsym->u.s_old_style_args;
dsym->s_def_pos = rdsym->s_def_pos;
}
@@ -2347,7 +2350,7 @@ check_old_style_definition(sym_t *rdsym,
int narg, nparg, n;
bool dowarn, msg;
- args = rdsym->s_args;
+ args = rdsym->u.s_old_style_args;
pargs = dsym->s_type->t_args;
msg = false;
@@ -2576,7 +2579,7 @@ check_func_old_style_arguments(void)
int narg, nparg;
bool msg;
- args = funcsym->s_args;
+ args = funcsym->u.s_old_style_args;
pargs = funcsym->s_type->t_args;
/*
@@ -2627,7 +2630,7 @@ check_func_old_style_arguments(void)
/* from now on the prototype is valid */
funcsym->s_osdef = false;
- funcsym->s_args = NULL;
+ funcsym->u.s_old_style_args = NULL;
}
}
Index: src/usr.bin/xlint/lint1/func.c
diff -u src/usr.bin/xlint/lint1/func.c:1.130 src/usr.bin/xlint/lint1/func.c:1.131
--- src/usr.bin/xlint/lint1/func.c:1.130 Sat Apr 2 20:12:46 2022
+++ src/usr.bin/xlint/lint1/func.c Sat Apr 9 13:38:17 2022
@@ -1,4 +1,4 @@
-/* $NetBSD: func.c,v 1.130 2022/04/02 20:12:46 rillig Exp $ */
+/* $NetBSD: func.c,v 1.131 2022/04/09 13:38:17 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.130 2022/04/02 20:12:46 rillig Exp $");
+__RCSID("$NetBSD: func.c,v 1.131 2022/04/09 13:38:17 rillig Exp $");
#endif
#include <stdlib.h>
@@ -248,7 +248,7 @@ funcdef(sym_t *fsym)
* style function definition or only an old style declaration,
* if there are no arguments inside the argument list ("f()").
*/
- if (!fsym->s_type->t_proto && fsym->s_args == NULL)
+ if (!fsym->s_type->t_proto && fsym->u.s_old_style_args == NULL)
fsym->s_osdef = true;
check_type(fsym);
Index: src/usr.bin/xlint/lint1/lex.c
diff -u src/usr.bin/xlint/lint1/lex.c:1.115 src/usr.bin/xlint/lint1/lex.c:1.116
--- src/usr.bin/xlint/lint1/lex.c:1.115 Sat Apr 2 14:28:30 2022
+++ src/usr.bin/xlint/lint1/lex.c Sat Apr 9 13:38:17 2022
@@ -1,4 +1,4 @@
-/* $NetBSD: lex.c,v 1.115 2022/04/02 14:28:30 rillig Exp $ */
+/* $NetBSD: lex.c,v 1.116 2022/04/09 13:38:17 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.115 2022/04/02 14:28:30 rillig Exp $");
+__RCSID("$NetBSD: lex.c,v 1.116 2022/04/09 13:38:17 rillig Exp $");
#endif
#include <ctype.h>
@@ -395,11 +395,11 @@ add_keyword(const struct keyword *kw, bo
sym->s_keyword = kw;
sym->s_value.v_quad = kw->kw_token;
if (kw->kw_token == T_TYPE || kw->kw_token == T_STRUCT_OR_UNION) {
- sym->s_tspec = kw->kw_tspec;
+ sym->u.s_tspec = kw->kw_tspec;
} else if (kw->kw_token == T_SCLASS) {
sym->s_scl = kw->kw_scl;
} else if (kw->kw_token == T_QUAL) {
- sym->s_tqual = kw->kw_tqual;
+ sym->u.s_qualifier = kw->kw_tqual;
}
symtab_add(sym);
@@ -457,9 +457,9 @@ lex_keyword(sym_t *sym)
if ((t = (int)sym->s_value.v_quad) == T_SCLASS) {
yylval.y_scl = sym->s_scl;
} else if (t == T_TYPE || t == T_STRUCT_OR_UNION) {
- yylval.y_tspec = sym->s_tspec;
+ yylval.y_tspec = sym->u.s_tspec;
} else if (t == T_QUAL) {
- yylval.y_tqual = sym->s_tqual;
+ yylval.y_tqual = sym->u.s_qualifier;
}
return t;
}
Index: src/usr.bin/xlint/lint1/lint1.h
diff -u src/usr.bin/xlint/lint1/lint1.h:1.144 src/usr.bin/xlint/lint1/lint1.h:1.145
--- src/usr.bin/xlint/lint1/lint1.h:1.144 Sat Apr 2 22:15:57 2022
+++ src/usr.bin/xlint/lint1/lint1.h Sat Apr 9 13:38:17 2022
@@ -1,4 +1,4 @@
-/* $NetBSD: lint1.h,v 1.144 2022/04/02 22:15:57 rillig Exp $ */
+/* $NetBSD: lint1.h,v 1.145 2022/04/09 13:38:17 rillig Exp $ */
/*
* Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved.
@@ -246,11 +246,11 @@ typedef struct sym {
val_t s_value; /* value (if enum or bool constant) */
union {
/* XXX: what is the difference to s_type->t_str? */
- struct_or_union *_s_st;
- tspec_t _s_tsp; /* type (only for keywords) */
- tqual_t _s_tqu; /* qualifier (only for keywords) */
- struct sym *_s_args; /* arguments in old style function
- definitions */
+ struct_or_union *s_sou_type;
+ tspec_t s_tspec; /* type (only for keywords) */
+ tqual_t s_qualifier; /* qualifier (only for keywords) */
+ struct sym *s_old_style_args; /* arguments in old style
+ * function definitions */
} u;
struct sym *s_symtab_next; /* next symbol with same hash value */
struct sym **s_symtab_ref; /* pointer to s_symtab_next of the
@@ -261,11 +261,6 @@ typedef struct sym {
* level */
} sym_t;
-#define s_sou_type u._s_st
-#define s_tspec u._s_tsp
-#define s_tqual u._s_tqu
-#define s_args u._s_args
-
/*
* Used to keep some information about symbols before they are entered
* into the symbol table.
Index: src/usr.bin/xlint/lint1/tree.c
diff -u src/usr.bin/xlint/lint1/tree.c:1.419 src/usr.bin/xlint/lint1/tree.c:1.420
--- src/usr.bin/xlint/lint1/tree.c:1.419 Sat Apr 9 13:22:05 2022
+++ src/usr.bin/xlint/lint1/tree.c Sat Apr 9 13:38:17 2022
@@ -1,4 +1,4 @@
-/* $NetBSD: tree.c,v 1.419 2022/04/09 13:22:05 rillig Exp $ */
+/* $NetBSD: tree.c,v 1.420 2022/04/09 13:38:17 rillig Exp $ */
/*
* Copyright (c) 1994, 1995 Jochen Pohl
@@ -37,7 +37,7 @@
#include <sys/cdefs.h>
#if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: tree.c,v 1.419 2022/04/09 13:22:05 rillig Exp $");
+__RCSID("$NetBSD: tree.c,v 1.420 2022/04/09 13:38:17 rillig Exp $");
#endif
#include <float.h>
@@ -350,10 +350,10 @@ struct_or_union_member(tnode_t *tn, op_t
rmsym(msym);
msym->s_kind = FMEMBER;
msym->s_scl = MOS;
- msym->s_sou_type = expr_zero_alloc(sizeof(*msym->s_sou_type));
- msym->s_sou_type->sou_tag = expr_zero_alloc(
- sizeof(*msym->s_sou_type->sou_tag));
- msym->s_sou_type->sou_tag->s_name = unnamed;
+ msym->u.s_sou_type = expr_zero_alloc(sizeof(*msym->u.s_sou_type));
+ msym->u.s_sou_type->sou_tag = expr_zero_alloc(
+ sizeof(*msym->u.s_sou_type->sou_tag));
+ msym->u.s_sou_type->sou_tag->s_name = unnamed;
msym->s_value.v_tspec = INT;
return msym;
}
@@ -377,7 +377,7 @@ struct_or_union_member(tnode_t *tn, op_t
for (sym = msym; sym != NULL; sym = sym->s_symtab_next) {
if (sym->s_scl != MOS && sym->s_scl != MOU)
continue;
- if (sym->s_sou_type != str)
+ if (sym->u.s_sou_type != str)
continue;
if (strcmp(sym->s_name, msym->s_name) != 0)
continue;