diff --git a/usr.bin/xlint/lint1/cgram.y b/usr.bin/xlint/lint1/cgram.y index 5fdfbd6e7f0a..0eacce04635f 100644 --- a/usr.bin/xlint/lint1/cgram.y +++ b/usr.bin/xlint/lint1/cgram.y @@ -1,5 +1,5 @@ %{ -/* $NetBSD: cgram.y,v 1.479 2024/01/11 23:06:19 rillig Exp $ */ +/* $NetBSD: cgram.y,v 1.480 2024/01/11 23:26:39 rillig Exp $ */ /* * Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved. @@ -35,7 +35,7 @@ #include #if defined(__RCSID) -__RCSID("$NetBSD: cgram.y,v 1.479 2024/01/11 23:06:19 rillig Exp $"); +__RCSID("$NetBSD: cgram.y,v 1.480 2024/01/11 23:26:39 rillig Exp $"); #endif #include @@ -512,17 +512,17 @@ primary_expression: member_designator: identifier { $$ = (designation) { .dn_len = 0 }; - designation_push(&$$, DK_STRUCT /* or union */, getsym($1), 0); + designation_push(&$$, DK_MEMBER, getsym($1), 0); } | member_designator T_LBRACK range T_RBRACK { $$ = $1; - designation_push(&$$, DK_ARRAY, NULL, $3.lo); + designation_push(&$$, DK_SUBSCRIPT, NULL, $3.lo); } | member_designator T_POINT { set_symtyp(FMEMBER); } identifier { $$ = $1; - designation_push(&$$, DK_STRUCT /* or union */, getsym($4), 0); + designation_push(&$$, DK_MEMBER, getsym($4), 0); } ; diff --git a/usr.bin/xlint/lint1/init.c b/usr.bin/xlint/lint1/init.c index 7f9f590f7cfc..7b6bc0e13318 100644 --- a/usr.bin/xlint/lint1/init.c +++ b/usr.bin/xlint/lint1/init.c @@ -1,4 +1,4 @@ -/* $NetBSD: init.c,v 1.254 2024/01/09 23:46:54 rillig Exp $ */ +/* $NetBSD: init.c,v 1.255 2024/01/11 23:26:39 rillig Exp $ */ /* * Copyright (c) 1994, 1995 Jochen Pohl @@ -38,7 +38,7 @@ #include #if defined(__RCSID) -__RCSID("$NetBSD: init.c,v 1.254 2024/01/09 23:46:54 rillig Exp $"); +__RCSID("$NetBSD: init.c,v 1.255 2024/01/11 23:26:39 rillig Exp $"); #endif #include @@ -311,7 +311,7 @@ designator_type(const designator *dr, const type_t *tp) switch (tp->t_tspec) { case STRUCT: case UNION: - if (dr->dr_kind != DK_STRUCT && dr->dr_kind != DK_UNION) { + if (dr->dr_kind != DK_MEMBER) { const sym_t *fmem = first_named_member(tp); /* syntax error '%s' */ error(249, "designator '[...]' is only for arrays"); @@ -321,7 +321,7 @@ designator_type(const designator *dr, const type_t *tp) lint_assert(dr->dr_member != NULL); return dr->dr_member->s_type; case ARRAY: - if (dr->dr_kind != DK_ARRAY) { + if (dr->dr_kind != DK_SUBSCRIPT) { /* syntax error '%s' */ error(249, "designator '.member' is only for struct/union"); @@ -344,13 +344,13 @@ static void designator_debug(const designator *dr) { - if (dr->dr_kind == DK_STRUCT || dr->dr_kind == DK_UNION) { + if (dr->dr_kind == DK_MEMBER) { lint_assert(dr->dr_subscript == 0); debug_printf(".%s", dr->dr_member != NULL ? dr->dr_member->s_name : ""); - } else if (dr->dr_kind == DK_ARRAY) { + } else if (dr->dr_kind == DK_SUBSCRIPT) { lint_assert(dr->dr_member == NULL); debug_printf("[%zu]", dr->dr_subscript); } else { @@ -421,10 +421,9 @@ designation_descend(designation *dn, const type_t *tp) const sym_t *member = first_named_member(tp); if (member == NULL) return false; - designation_push(dn, - tp->t_tspec == STRUCT ? DK_STRUCT : DK_UNION, member, 0); + designation_push(dn, DK_MEMBER, member, 0); } else if (tp->t_tspec == ARRAY) - designation_push(dn, DK_ARRAY, NULL, 0); + designation_push(dn, DK_SUBSCRIPT, NULL, 0); else designation_push(dn, DK_SCALAR, NULL, 0); return true; @@ -550,10 +549,10 @@ static void warn_too_many_initializers(designator_kind kind, const type_t *tp) { - if (kind == DK_STRUCT || kind == DK_UNION) { + if (kind == DK_MEMBER) { /* too many struct/union initializers */ error(172); - } else if (kind == DK_ARRAY) { + } else if (kind == DK_SUBSCRIPT) { lint_assert(tp->t_tspec == ARRAY); lint_assert(!tp->t_incomplete_array); /* too many array initializers, expected %d */ @@ -816,8 +815,7 @@ proceed:; return; } - designation_push(&bl->bl_designation, - tp->t_tspec == STRUCT ? DK_STRUCT : DK_UNION, member, 0); + designation_push(&bl->bl_designation, DK_MEMBER, member, 0); } static void @@ -847,7 +845,7 @@ initialization_add_designator_subscript(initialization *in, size_t subscript) if (tp->t_incomplete_array && subscript > in->in_max_subscript) in->in_max_subscript = subscript; - designation_push(&bl->bl_designation, DK_ARRAY, NULL, subscript); + designation_push(&bl->bl_designation, DK_SUBSCRIPT, NULL, subscript); } /* diff --git a/usr.bin/xlint/lint1/lint1.h b/usr.bin/xlint/lint1/lint1.h index 0683a348609a..7a15b1a90c3d 100644 --- a/usr.bin/xlint/lint1/lint1.h +++ b/usr.bin/xlint/lint1/lint1.h @@ -1,4 +1,4 @@ -/* $NetBSD: lint1.h,v 1.207 2024/01/09 23:46:54 rillig Exp $ */ +/* $NetBSD: lint1.h,v 1.208 2024/01/11 23:26:39 rillig Exp $ */ /* * Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved. @@ -481,12 +481,11 @@ typedef struct { } range_t; typedef enum designator_kind { - DK_STRUCT, /* .member */ - DK_UNION, /* .member */ - DK_ARRAY, /* [subscript] */ - /* TODO: actually necessary? */ + DK_MEMBER, /* .member */ + DK_SUBSCRIPT, /* [subscript] */ DK_SCALAR /* no textual representation, not generated by - * the parser */ + * the parser; used for scalar initializer + * expressions surrounded by braces */ } designator_kind; /* @@ -497,8 +496,8 @@ typedef enum designator_kind { */ typedef struct designator { designator_kind dr_kind; - const sym_t *dr_member; /* for DK_STRUCT and DK_UNION */ - size_t dr_subscript; /* for DK_ARRAY */ + const sym_t *dr_member; /* for DK_MEMBER */ + size_t dr_subscript; /* for DK_SUBSCRIPT */ bool dr_done; } designator; diff --git a/usr.bin/xlint/lint1/tree.c b/usr.bin/xlint/lint1/tree.c index e73a3e4db0ff..963a3cd04cc6 100644 --- a/usr.bin/xlint/lint1/tree.c +++ b/usr.bin/xlint/lint1/tree.c @@ -1,4 +1,4 @@ -/* $NetBSD: tree.c,v 1.594 2024/01/11 23:06:19 rillig Exp $ */ +/* $NetBSD: tree.c,v 1.595 2024/01/11 23:26:39 rillig Exp $ */ /* * Copyright (c) 1994, 1995 Jochen Pohl @@ -37,7 +37,7 @@ #include #if defined(__RCSID) -__RCSID("$NetBSD: tree.c,v 1.594 2024/01/11 23:06:19 rillig Exp $"); +__RCSID("$NetBSD: tree.c,v 1.595 2024/01/11 23:26:39 rillig Exp $"); #endif #include @@ -3900,7 +3900,7 @@ build_offsetof(const type_t *tp, designation dn) } for (size_t i = 0; i < dn.dn_len; i++) { const designator *dr = dn.dn_items + i; - if (dr->dr_kind == DK_ARRAY) { + if (dr->dr_kind == DK_SUBSCRIPT) { if (tp->t_tspec != ARRAY) goto proceed; /* silent error */ tp = tp->t_subt;