Module Name: src Committed By: rillig Date: Thu Jun 29 05:03:03 UTC 2023
Modified Files: src/usr.bin/xlint/lint1: cgram.y decl.c externs1.h Log Message: lint: clean up completion of struct, union and enum declarations No functional change. To generate a diff of this commit: cvs rdiff -u -r1.436 -r1.437 src/usr.bin/xlint/lint1/cgram.y cvs rdiff -u -r1.318 -r1.319 src/usr.bin/xlint/lint1/decl.c cvs rdiff -u -r1.178 -r1.179 src/usr.bin/xlint/lint1/externs1.h 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.436 src/usr.bin/xlint/lint1/cgram.y:1.437 --- src/usr.bin/xlint/lint1/cgram.y:1.436 Mon May 22 17:47:27 2023 +++ src/usr.bin/xlint/lint1/cgram.y Thu Jun 29 05:03:03 2023 @@ -1,5 +1,5 @@ %{ -/* $NetBSD: cgram.y,v 1.436 2023/05/22 17:47:27 rillig Exp $ */ +/* $NetBSD: cgram.y,v 1.437 2023/06/29 05:03:03 rillig Exp $ */ /* * Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved. @@ -35,7 +35,7 @@ #include <sys/cdefs.h> #if defined(__RCSID) -__RCSID("$NetBSD: cgram.y,v 1.436 2023/05/22 17:47:27 rillig Exp $"); +__RCSID("$NetBSD: cgram.y,v 1.437 2023/06/29 05:03:03 rillig Exp $"); #endif #include <limits.h> @@ -888,12 +888,12 @@ struct_or_union_specifier: /* C99 6.7.2. | struct_or_union identifier_sym { dcs->d_tagtyp = make_tag_type($2, $1, true, false); } braced_struct_declaration_list { - $$ = complete_tag_struct_or_union(dcs->d_tagtyp, $4); + $$ = complete_struct_or_union($4); } | struct_or_union { dcs->d_tagtyp = make_tag_type(NULL, $1, true, false); } braced_struct_declaration_list { - $$ = complete_tag_struct_or_union(dcs->d_tagtyp, $3); + $$ = complete_struct_or_union($3); } | struct_or_union error { symtyp = FVFT; @@ -1040,12 +1040,12 @@ enum_specifier: /* C99 6.7.2.2 */ | enum gcc_attribute_specifier_list_opt identifier_sym { dcs->d_tagtyp = make_tag_type($3, ENUM, true, false); } enum_declaration /*gcc_attribute_specifier_list_opt*/ { - $$ = complete_tag_enum(dcs->d_tagtyp, $5); + $$ = complete_enum($5); } | enum gcc_attribute_specifier_list_opt { dcs->d_tagtyp = make_tag_type(NULL, ENUM, true, false); } enum_declaration /*gcc_attribute_specifier_list_opt*/ { - $$ = complete_tag_enum(dcs->d_tagtyp, $4); + $$ = complete_enum($4); } | enum error { symtyp = FVFT; Index: src/usr.bin/xlint/lint1/decl.c diff -u src/usr.bin/xlint/lint1/decl.c:1.318 src/usr.bin/xlint/lint1/decl.c:1.319 --- src/usr.bin/xlint/lint1/decl.c:1.318 Sat Jun 24 06:55:34 2023 +++ src/usr.bin/xlint/lint1/decl.c Thu Jun 29 05:03:03 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: decl.c,v 1.318 2023/06/24 06:55:34 rillig Exp $ */ +/* $NetBSD: decl.c,v 1.319 2023/06/29 05:03:03 rillig Exp $ */ /* * Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved. @@ -38,7 +38,7 @@ #include <sys/cdefs.h> #if defined(__RCSID) -__RCSID("$NetBSD: decl.c,v 1.318 2023/06/24 06:55:34 rillig Exp $"); +__RCSID("$NetBSD: decl.c,v 1.319 2023/06/29 05:03:03 rillig Exp $"); #endif #include <sys/param.h> @@ -1182,7 +1182,7 @@ declarator_1_struct_union(sym_t *dsym) } /* - * Aligns next structure element as required. + * Aligns the next structure element as required. * * al contains the required alignment, len the length of a bit-field. */ @@ -1559,7 +1559,6 @@ declarator_name(sym_t *sym) /* Set parent */ sym->u.s_member.sm_sou_type = dcs->d_tagtyp->t_sou; sym->s_def = DEF; - /* XXX: Where is sym->u.s_member.sm_offset_in_bits set? */ sc = dcs->d_kind == DK_STRUCT_MEMBER ? STRUCT_MEMBER : UNION_MEMBER; @@ -1808,27 +1807,20 @@ storage_class_name(scl_t sc) /* NOTREACHED */ } -/* - * tp points to the type of the tag, fmem to the list of members. - */ type_t * -complete_tag_struct_or_union(type_t *tp, sym_t *fmem) +complete_struct_or_union(sym_t *first_member) { + type_t *tp = dcs->d_tagtyp; if (tp == NULL) /* in case of syntax errors */ return gettyp(INT); - if (tp->t_tspec == ENUM) - tp->t_enum->en_incomplete = false; - else - tp->t_sou->sou_incomplete = false; - - tspec_t t = tp->t_tspec; dcs_align((u_int)dcs->d_sou_align_in_bits, 0); struct_or_union *sp = tp->t_sou; sp->sou_align_in_bits = dcs->d_sou_align_in_bits; - sp->sou_first_member = fmem; + sp->sou_incomplete = false; + sp->sou_first_member = first_member; if (tp->t_packed) set_packed_size(tp); else @@ -1836,11 +1828,11 @@ complete_tag_struct_or_union(type_t *tp, if (sp->sou_size_in_bits == 0) { /* zero sized %s is a C99 feature */ - c99ism(47, ttab[t].tt_name); + c99ism(47, tspec_name(tp->t_tspec)); } int n = 0; - for (sym_t *mem = fmem; mem != NULL; mem = mem->s_next) { + for (sym_t *mem = first_member; mem != NULL; mem = mem->s_next) { /* bind anonymous members to the structure */ if (mem->u.s_member.sm_sou_type == NULL) { mem->u.s_member.sm_sou_type = sp; @@ -1864,9 +1856,10 @@ complete_tag_struct_or_union(type_t *tp, } type_t * -complete_tag_enum(type_t *tp, sym_t *first_enumerator) +complete_enum(sym_t *first_enumerator) { + type_t *tp = dcs->d_tagtyp; tp->t_enum->en_incomplete = false; tp->t_enum->en_first_enumerator = first_enumerator; return tp; Index: src/usr.bin/xlint/lint1/externs1.h diff -u src/usr.bin/xlint/lint1/externs1.h:1.178 src/usr.bin/xlint/lint1/externs1.h:1.179 --- src/usr.bin/xlint/lint1/externs1.h:1.178 Sat Jun 24 07:15:08 2023 +++ src/usr.bin/xlint/lint1/externs1.h Thu Jun 29 05:03:03 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: externs1.h,v 1.178 2023/06/24 07:15:08 rillig Exp $ */ +/* $NetBSD: externs1.h,v 1.179 2023/06/29 05:03:03 rillig Exp $ */ /* * Copyright (c) 1994, 1995 Jochen Pohl @@ -214,8 +214,8 @@ sym_t *declarator_name(sym_t *); sym_t *old_style_function_name(sym_t *); type_t *make_tag_type(sym_t *, tspec_t, bool, bool); const char *storage_class_name(scl_t); -type_t *complete_tag_struct_or_union(type_t *, sym_t *); -type_t *complete_tag_enum(type_t *, sym_t *); +type_t *complete_struct_or_union(sym_t *); +type_t *complete_enum(sym_t *); sym_t *enumeration_constant(sym_t *, int, bool); void declare(sym_t *, bool, sbuf_t *); void copy_usage_info(sym_t *, sym_t *);