Module Name: src
Committed By: rillig
Date: Fri Feb 19 22:16:12 UTC 2021
Modified Files:
src/usr.bin/xlint/common: tyname.c
src/usr.bin/xlint/lint1: cgram.y decl.c emit1.c init.c lint1.h tree.c
Log Message:
lint: rename str_t and its members to be more expressive
No functional change.
To generate a diff of this commit:
cvs rdiff -u -r1.26 -r1.27 src/usr.bin/xlint/common/tyname.c
cvs rdiff -u -r1.160 -r1.161 src/usr.bin/xlint/lint1/cgram.y
cvs rdiff -u -r1.133 -r1.134 src/usr.bin/xlint/lint1/decl.c
cvs rdiff -u -r1.39 -r1.40 src/usr.bin/xlint/lint1/emit1.c
cvs rdiff -u -r1.66 -r1.67 src/usr.bin/xlint/lint1/init.c
cvs rdiff -u -r1.61 -r1.62 src/usr.bin/xlint/lint1/lint1.h
cvs rdiff -u -r1.207 -r1.208 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/common/tyname.c
diff -u src/usr.bin/xlint/common/tyname.c:1.26 src/usr.bin/xlint/common/tyname.c:1.27
--- src/usr.bin/xlint/common/tyname.c:1.26 Tue Jan 26 18:38:57 2021
+++ src/usr.bin/xlint/common/tyname.c Fri Feb 19 22:16:12 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: tyname.c,v 1.26 2021/01/26 18:38:57 rillig Exp $ */
+/* $NetBSD: tyname.c,v 1.27 2021/02/19 22:16:12 rillig Exp $ */
/*-
* Copyright (c) 2005 The NetBSD Foundation, Inc.
@@ -35,7 +35,7 @@
#include <sys/cdefs.h>
#if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: tyname.c,v 1.26 2021/01/26 18:38:57 rillig Exp $");
+__RCSID("$NetBSD: tyname.c,v 1.27 2021/02/19 22:16:12 rillig Exp $");
#endif
#include <limits.h>
@@ -238,8 +238,8 @@ sametype(const type_t *t1, const type_t
case STRUCT:
case UNION:
#ifdef t_str
- return strcmp(t1->t_str->stag->s_name,
- t2->t_str->stag->s_name) == 0;
+ return strcmp(t1->t_str->sou_tag->s_name,
+ t2->t_str->sou_tag->s_name) == 0;
#else
return true;
#endif
@@ -349,7 +349,7 @@ type_name(const type_t *tp)
case UNION:
buf_add(&buf, " ");
#ifdef t_str
- buf_add(&buf, tp->t_str->stag->s_name);
+ buf_add(&buf, tp->t_str->sou_tag->s_name);
#else
buf_add(&buf,
tp->t_isuniqpos ? "*anonymous*" : tp->t_tag->h_name);
Index: src/usr.bin/xlint/lint1/cgram.y
diff -u src/usr.bin/xlint/lint1/cgram.y:1.160 src/usr.bin/xlint/lint1/cgram.y:1.161
--- src/usr.bin/xlint/lint1/cgram.y:1.160 Sun Jan 31 12:44:34 2021
+++ src/usr.bin/xlint/lint1/cgram.y Fri Feb 19 22:16:12 2021
@@ -1,5 +1,5 @@
%{
-/* $NetBSD: cgram.y,v 1.160 2021/01/31 12:44:34 rillig Exp $ */
+/* $NetBSD: cgram.y,v 1.161 2021/02/19 22:16:12 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.160 2021/01/31 12:44:34 rillig Exp $");
+__RCSID("$NetBSD: cgram.y,v 1.161 2021/02/19 22:16:12 rillig Exp $");
#endif
#include <limits.h>
@@ -802,7 +802,7 @@ member_declaration:
/* anonymous struct/union members is a C9X feature */
warning(49);
/* add all the members of the anonymous struct/union */
- $$ = dcs->d_type->t_str->memb;
+ $$ = dcs->d_type->t_str->sou_first_member;
anonymize($$);
}
| noclass_declspecs deftyp opt_type_attribute {
@@ -811,7 +811,7 @@ member_declaration:
if (!Sflag)
/* anonymous struct/union members is a C9X feature */
warning(49);
- $$ = dcs->d_type->t_str->memb;
+ $$ = dcs->d_type->t_str->sou_first_member;
/* add all the members of the anonymous struct/union */
anonymize($$);
}
Index: src/usr.bin/xlint/lint1/decl.c
diff -u src/usr.bin/xlint/lint1/decl.c:1.133 src/usr.bin/xlint/lint1/decl.c:1.134
--- src/usr.bin/xlint/lint1/decl.c:1.133 Sun Jan 31 11:23:01 2021
+++ src/usr.bin/xlint/lint1/decl.c Fri Feb 19 22:16:12 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: decl.c,v 1.133 2021/01/31 11:23:01 rillig Exp $ */
+/* $NetBSD: decl.c,v 1.134 2021/02/19 22:16:12 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.133 2021/01/31 11:23:01 rillig Exp $");
+__RCSID("$NetBSD: decl.c,v 1.134 2021/02/19 22:16:12 rillig Exp $");
#endif
#include <sys/param.h>
@@ -181,7 +181,7 @@ is_incomplete(const type_t *tp)
} else if (t == ARRAY) {
return tp->t_aincompl;
} else if (t == STRUCT || t == UNION) {
- return tp->t_str->sincompl;
+ return tp->t_str->sou_incomplete;
} else if (t == ENUM) {
return tp->t_enum->eincompl;
}
@@ -199,7 +199,7 @@ setcomplete(type_t *tp, bool complete)
if ((t = tp->t_tspec) == ARRAY) {
tp->t_aincompl = !complete;
} else if (t == STRUCT || t == UNION) {
- tp->t_str->sincompl = !complete;
+ tp->t_str->sou_incomplete = !complete;
} else {
lint_assert(t == ENUM);
tp->t_enum->eincompl = !complete;
@@ -482,8 +482,8 @@ settdsym(type_t *tp, sym_t *sym)
tspec_t t;
if ((t = tp->t_tspec) == STRUCT || t == UNION) {
- if (tp->t_str->stdef == NULL)
- tp->t_str->stdef = sym;
+ if (tp->t_str->sou_first_typedef == NULL)
+ tp->t_str->sou_first_typedef = sym;
} else if (t == ENUM) {
if (tp->t_enum->etdef == NULL)
tp->t_enum->etdef = sym;
@@ -504,25 +504,26 @@ bitfieldsize(sym_t **mem)
static void
setpackedsize(type_t *tp)
{
- str_t *sp;
+ struct_or_union *sp;
sym_t *mem;
switch (tp->t_tspec) {
case STRUCT:
case UNION:
sp = tp->t_str;
- sp->size = 0;
- for (mem = sp->memb; mem != NULL; mem = mem->s_next) {
+ sp->sou_size_in_bit = 0;
+ for (mem = sp->sou_first_member;
+ mem != NULL; mem = mem->s_next) {
if (mem->s_type->t_bitfield) {
- sp->size += bitfieldsize(&mem);
+ sp->sou_size_in_bit += bitfieldsize(&mem);
if (mem == NULL)
break;
}
size_t x = (size_t)tsize(mem->s_type);
if (tp->t_tspec == STRUCT)
- sp->size += x;
- else if (x > sp->size)
- sp->size = x;
+ sp->sou_size_in_bit += x;
+ else if (x > sp->sou_size_in_bit)
+ sp->sou_size_in_bit = x;
}
break;
default:
@@ -905,9 +906,9 @@ length(const type_t *tp, const char *nam
case UNION:
if (is_incomplete(tp) && name != NULL) {
/* incomplete structure or union %s: %s */
- error(31, tp->t_str->stag->s_name, name);
+ error(31, tp->t_str->sou_tag->s_name, name);
}
- elsz = tp->t_str->size;
+ elsz = tp->t_str->sou_size_in_bit;
break;
case ENUM:
if (is_incomplete(tp) && name != NULL) {
@@ -940,7 +941,7 @@ getbound(const type_t *tp)
return -1;
if ((t = tp->t_tspec) == STRUCT || t == UNION) {
- a = tp->t_str->align;
+ a = tp->t_str->sou_align_in_bit;
} else if (t == FUNC) {
/* compiler takes alignment of function */
error(14);
@@ -1660,9 +1661,9 @@ mktag(sym_t *tag, tspec_t kind, bool dec
if (tp->t_tspec == NOTSPEC) {
tp->t_tspec = kind;
if (kind != ENUM) {
- tp->t_str = getblk(sizeof (str_t));
- tp->t_str->align = CHAR_SIZE;
- tp->t_str->stag = tag;
+ tp->t_str = getblk(sizeof (struct_or_union));
+ tp->t_str->sou_align_in_bit = CHAR_SIZE;
+ tp->t_str->sou_tag = tag;
} else {
tp->t_isenum = true;
tp->t_enum = getblk(sizeof(*tp->t_enum));
@@ -1763,7 +1764,7 @@ type_t *
complete_tag_struct_or_union(type_t *tp, sym_t *fmem)
{
tspec_t t;
- str_t *sp;
+ struct_or_union *sp;
int n;
sym_t *mem;
@@ -1772,14 +1773,14 @@ complete_tag_struct_or_union(type_t *tp,
t = tp->t_tspec;
align(dcs->d_stralign, 0);
sp = tp->t_str;
- sp->align = dcs->d_stralign;
- sp->memb = fmem;
+ sp->sou_align_in_bit = dcs->d_stralign;
+ sp->sou_first_member = fmem;
if (tp->t_packed)
setpackedsize(tp);
else
- sp->size = dcs->d_offset;
+ sp->sou_size_in_bit = dcs->d_offset;
- if (sp->size == 0) {
+ if (sp->sou_size_in_bit == 0) {
/* zero sized %s is a C9X feature */
c99ism(47, ttab[t].tt_name);
}
@@ -1790,17 +1791,17 @@ complete_tag_struct_or_union(type_t *tp,
if (mem->s_styp == NULL) {
mem->s_styp = sp;
if (mem->s_type->t_bitfield) {
- sp->size += bitfieldsize(&mem);
+ sp->sou_size_in_bit += bitfieldsize(&mem);
if (mem == NULL)
break;
}
- sp->size += tsize(mem->s_type);
+ sp->sou_size_in_bit += tsize(mem->s_type);
}
if (mem->s_name != unnamed)
n++;
}
- if (n == 0 && sp->size != 0) {
+ if (n == 0 && sp->sou_size_in_bit != 0) {
/* %s has no named members */
warning(65, t == STRUCT ? "structure" : "union");
}
Index: src/usr.bin/xlint/lint1/emit1.c
diff -u src/usr.bin/xlint/lint1/emit1.c:1.39 src/usr.bin/xlint/lint1/emit1.c:1.40
--- src/usr.bin/xlint/lint1/emit1.c:1.39 Sun Jan 17 14:50:11 2021
+++ src/usr.bin/xlint/lint1/emit1.c Fri Feb 19 22:16:12 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: emit1.c,v 1.39 2021/01/17 14:50:11 rillig Exp $ */
+/* $NetBSD: emit1.c,v 1.40 2021/02/19 22:16:12 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: emit1.c,v 1.39 2021/01/17 14:50:11 rillig Exp $");
+__RCSID("$NetBSD: emit1.c,v 1.40 2021/02/19 22:16:12 rillig Exp $");
#endif
#include <ctype.h>
@@ -142,7 +142,7 @@ outtype(const type_t *tp)
} else if (ts == ENUM) {
outtt(tp->t_enum->etag, tp->t_enum->etdef);
} else if (ts == STRUCT || ts == UNION) {
- outtt(tp->t_str->stag, tp->t_str->stdef);
+ outtt(tp->t_str->sou_tag, tp->t_str->sou_first_typedef);
} else if (ts == FUNC && tp->t_proto) {
na = 0;
for (arg = tp->t_args; arg != NULL; arg = arg->s_next)
Index: src/usr.bin/xlint/lint1/init.c
diff -u src/usr.bin/xlint/lint1/init.c:1.66 src/usr.bin/xlint/lint1/init.c:1.67
--- src/usr.bin/xlint/lint1/init.c:1.66 Sun Jan 31 12:44:34 2021
+++ src/usr.bin/xlint/lint1/init.c Fri Feb 19 22:16:12 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: init.c,v 1.66 2021/01/31 12:44:34 rillig Exp $ */
+/* $NetBSD: init.c,v 1.67 2021/02/19 22:16:12 rillig Exp $ */
/*
* Copyright (c) 1994, 1995 Jochen Pohl
@@ -37,7 +37,7 @@
#include <sys/cdefs.h>
#if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: init.c,v 1.66 2021/01/31 12:44:34 rillig Exp $");
+__RCSID("$NetBSD: init.c,v 1.67 2021/02/19 22:16:12 rillig Exp $");
#endif
#include <stdlib.h>
@@ -236,7 +236,8 @@ initstack_pop_item(void)
__func__, istk->i_remaining,
type_name(istk->i_type), namedmem->n_name));
- for (m = istk->i_type->t_str->memb; m != NULL; m = m->s_next) {
+ for (m = istk->i_type->t_str->sou_first_member;
+ m != NULL; m = m->s_next) {
DPRINTF(("%s: pop lhs.name=%s rhs.name=%s\n", __func__,
m->s_name, namedmem->n_name));
if (m->s_bitfield && m->s_name == unnamed)
@@ -380,7 +381,8 @@ again:
DPRINTF(("%s: lookup type=%s, name=%s named=%d\n", __func__,
type_name(istk->i_type),
namedmem ? namedmem->n_name : "*none*", istk->i_namedmem));
- for (m = istk->i_type->t_str->memb; m != NULL; m = m->s_next) {
+ for (m = istk->i_type->t_str->sou_first_member;
+ m != NULL; m = m->s_next) {
if (m->s_bitfield && m->s_name == unnamed)
continue;
if (namedmem != NULL) {
Index: src/usr.bin/xlint/lint1/lint1.h
diff -u src/usr.bin/xlint/lint1/lint1.h:1.61 src/usr.bin/xlint/lint1/lint1.h:1.62
--- src/usr.bin/xlint/lint1/lint1.h:1.61 Fri Feb 19 21:35:44 2021
+++ src/usr.bin/xlint/lint1/lint1.h Fri Feb 19 22:16:12 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: lint1.h,v 1.61 2021/02/19 21:35:44 rillig Exp $ */
+/* $NetBSD: lint1.h,v 1.62 2021/02/19 22:16:12 rillig Exp $ */
/*
* Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved.
@@ -116,7 +116,7 @@ typedef struct {
#define v_ldbl v_u._v_ldbl
/*
- * Structures of type str_t uniquely identify structures. This can't
+ * Structures of type struct_or_union uniquely identify structures. This can't
* be done in structures of type type_t, because these are copied
* if they must be modified. So it would not be possible to check
* if two structures are identical by comparing the pointers to
@@ -126,13 +126,13 @@ typedef struct {
* the structure type in pass 2.
*/
typedef struct {
- u_int size; /* size in bit */
- u_int align : 15; /* alignment in bit */
- bool sincompl : 1; /* set if incomplete type */
- struct sym *memb; /* list of members */
- struct sym *stag; /* symbol table entry of tag */
- struct sym *stdef; /* symbol table entry of first typename */
-} str_t;
+ u_int sou_size_in_bit;
+ u_int sou_align_in_bit : 15;
+ bool sou_incomplete : 1;
+ struct sym *sou_first_member;
+ struct sym *sou_tag;
+ struct sym *sou_first_typedef;
+} struct_or_union;
/*
* same as above for enums
@@ -161,7 +161,7 @@ struct type {
bool t_packed : 1;
union {
int _t_dim; /* dimension */
- str_t *_t_str; /* struct/union tag */
+ struct_or_union *_t_str; /* struct/union tag */
tenum_t *_t_enum; /* enum tag */
struct sym *_t_args; /* arguments (if t_proto) */
} t_u;
@@ -246,7 +246,7 @@ typedef struct sym {
type_t *s_type;
val_t s_value; /* value (if enum or bool constant) */
union {
- str_t *_s_st; /* tag, if it is a struct/union member */
+ struct_or_union *_s_st;
tenum_t *_s_et; /* tag, if it is an enumerator */
tspec_t _s_tsp; /* type (only for keywords) */
tqual_t _s_tqu; /* qualifier (only for keywords) */
Index: src/usr.bin/xlint/lint1/tree.c
diff -u src/usr.bin/xlint/lint1/tree.c:1.207 src/usr.bin/xlint/lint1/tree.c:1.208
--- src/usr.bin/xlint/lint1/tree.c:1.207 Mon Feb 15 07:40:18 2021
+++ src/usr.bin/xlint/lint1/tree.c Fri Feb 19 22:16:12 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: tree.c,v 1.207 2021/02/15 07:40:18 rillig Exp $ */
+/* $NetBSD: tree.c,v 1.208 2021/02/19 22:16:12 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.207 2021/02/15 07:40:18 rillig Exp $");
+__RCSID("$NetBSD: tree.c,v 1.208 2021/02/19 22:16:12 rillig Exp $");
#endif
#include <float.h>
@@ -335,7 +335,7 @@ new_string_node(strg_t *strg)
sym_t *
struct_or_union_member(tnode_t *tn, op_t op, sym_t *msym)
{
- str_t *str;
+ struct_or_union *str;
type_t *tp;
sym_t *sym, *csym;
bool eq;
@@ -351,9 +351,9 @@ struct_or_union_member(tnode_t *tn, op_t
rmsym(msym);
msym->s_kind = FMEMBER;
msym->s_scl = MOS;
- msym->s_styp = tgetblk(sizeof (str_t));
- msym->s_styp->stag = tgetblk(sizeof (sym_t));
- msym->s_styp->stag->s_name = unnamed;
+ msym->s_styp = tgetblk(sizeof (struct_or_union));
+ msym->s_styp->sou_tag = tgetblk(sizeof (sym_t));
+ msym->s_styp->sou_tag->s_name = unnamed;
msym->s_value.v_tspec = INT;
return msym;
}
@@ -2626,7 +2626,7 @@ has_constant_member(const type_t *tp)
lint_assert((t = tp->t_tspec) == STRUCT || t == UNION);
- for (m = tp->t_str->memb; m != NULL; m = m->s_next) {
+ for (m = tp->t_str->sou_first_member; m != NULL; m = m->s_next) {
tp = m->s_type;
if (tp->t_const)
return true;
@@ -2987,7 +2987,7 @@ plength(type_t *tp)
break;
case STRUCT:
case UNION:
- if ((elsz = tp->t_str->size) == 0)
+ if ((elsz = tp->t_str->sou_size_in_bit) == 0)
/* cannot do pointer arithmetic on operand of ... */
error(136);
break;
@@ -3362,7 +3362,7 @@ tsize(type_t *tp)
error(143);
elsz = 1;
} else {
- elsz = tp->t_str->size;
+ elsz = tp->t_str->sou_size_in_bit;
}
break;
case ENUM:
@@ -3453,13 +3453,13 @@ cast(tnode_t *tn, type_t *tp)
*/
} else if (nt == UNION) {
sym_t *m;
- str_t *str = tp->t_str;
+ struct_or_union *str = tp->t_str;
if (!Sflag) {
/* union cast is a C9X feature */
error(328);
return NULL;
}
- for (m = str->memb; m != NULL; m = m->s_next) {
+ for (m = str->sou_first_member; m != NULL; m = m->s_next) {
if (sametype(m->s_type, tn->tn_type)) {
tn = getnode();
tn->tn_op = CVT;