Module Name: src Committed By: rillig Date: Fri Jun 30 21:39:54 UTC 2023
Modified Files: src/tests/usr.bin/xlint/lint1: decl_enum.c src/usr.bin/xlint/lint1: cgram.y debug.c decl.c externs1.h func.c lex.c lint1.h tree.c Log Message: lint: clean up names related to declaration levels The previous prefix 'DK_' (declaration level kind) had a conflict with the 'DK_' (designator kind) in init.c, so change the prefix to 'DLK_'. The new name for dinfo_t is decl_level, which is more expressive. No functional change. To generate a diff of this commit: cvs rdiff -u -r1.3 -r1.4 src/tests/usr.bin/xlint/lint1/decl_enum.c cvs rdiff -u -r1.442 -r1.443 src/usr.bin/xlint/lint1/cgram.y cvs rdiff -u -r1.39 -r1.40 src/usr.bin/xlint/lint1/debug.c cvs rdiff -u -r1.329 -r1.330 src/usr.bin/xlint/lint1/decl.c cvs rdiff -u -r1.182 -r1.183 src/usr.bin/xlint/lint1/externs1.h cvs rdiff -u -r1.159 -r1.160 src/usr.bin/xlint/lint1/func.c cvs rdiff -u -r1.163 -r1.164 src/usr.bin/xlint/lint1/lex.c cvs rdiff -u -r1.172 -r1.173 src/usr.bin/xlint/lint1/lint1.h cvs rdiff -u -r1.537 -r1.538 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/tests/usr.bin/xlint/lint1/decl_enum.c diff -u src/tests/usr.bin/xlint/lint1/decl_enum.c:1.3 src/tests/usr.bin/xlint/lint1/decl_enum.c:1.4 --- src/tests/usr.bin/xlint/lint1/decl_enum.c:1.3 Sat Apr 16 09:22:25 2022 +++ src/tests/usr.bin/xlint/lint1/decl_enum.c Fri Jun 30 21:39:54 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: decl_enum.c,v 1.3 2022/04/16 09:22:25 rillig Exp $ */ +/* $NetBSD: decl_enum.c,v 1.4 2023/06/30 21:39:54 rillig Exp $ */ # 3 "decl_enum.c" /* @@ -39,7 +39,7 @@ enum outer { * enum constant would become the value of the last seen inner enum * constant. This is because 'enumval' is a simple scalar variable, * not a stack. If it should ever become necessary to account for - * nested enum declarations, a field should be added in dinfo_t. + * nested enum declarations, a field should be added in decl_level. */ o2 __attribute__((__deprecated__)), o3 = i3 Index: src/usr.bin/xlint/lint1/cgram.y diff -u src/usr.bin/xlint/lint1/cgram.y:1.442 src/usr.bin/xlint/lint1/cgram.y:1.443 --- src/usr.bin/xlint/lint1/cgram.y:1.442 Fri Jun 30 21:06:18 2023 +++ src/usr.bin/xlint/lint1/cgram.y Fri Jun 30 21:39:54 2023 @@ -1,5 +1,5 @@ %{ -/* $NetBSD: cgram.y,v 1.442 2023/06/30 21:06:18 rillig Exp $ */ +/* $NetBSD: cgram.y,v 1.443 2023/06/30 21:39:54 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.442 2023/06/30 21:06:18 rillig Exp $"); +__RCSID("$NetBSD: cgram.y,v 1.443 2023/06/30 21:39:54 rillig Exp $"); #endif #include <limits.h> @@ -897,9 +897,7 @@ struct_or_union_specifier: /* C99 6.7.2. struct_or_union: /* C99 6.7.2.1 */ T_STRUCT_OR_UNION { symtyp = FTAG; - begin_declaration_level($1 == STRUCT - ? DK_STRUCT_MEMBER - : DK_UNION_MEMBER); + begin_declaration_level($1 == STRUCT ? DLK_STRUCT : DLK_UNION); dcs->d_offset_in_bits = 0; dcs->d_sou_align_in_bits = CHAR_SIZE; $$ = $1; @@ -1047,7 +1045,7 @@ enum_specifier: /* C99 6.7.2.2 */ enum: /* helper for C99 6.7.2.2 */ T_ENUM { symtyp = FTAG; - begin_declaration_level(DK_ENUM_CONSTANT); + begin_declaration_level(DLK_ENUM); } ; @@ -1318,7 +1316,7 @@ param_list: id_list_lparen: T_LPAREN { block_level++; - begin_declaration_level(DK_PROTO_ARG); + begin_declaration_level(DLK_PROTO_PARAMS); } ; @@ -1370,7 +1368,7 @@ identifier_list: /* C99 6.7.5 */ /* XXX: C99 requires an additional specifier-qualifier-list. */ type_name: /* C99 6.7.6 */ { - begin_declaration_level(DK_ABSTRACT); + begin_declaration_level(DLK_ABSTRACT); } abstract_declaration { end_declaration_level(); $$ = $2->s_type; @@ -1453,7 +1451,7 @@ abstract_decl_param_list: /* specific to abstract_decl_lparen: /* specific to lint */ T_LPAREN { block_level++; - begin_declaration_level(DK_PROTO_ARG); + begin_declaration_level(DLK_PROTO_PARAMS); } ; @@ -1669,7 +1667,7 @@ compound_statement_lbrace: T_LBRACE { block_level++; mem_block_level++; - begin_declaration_level(DK_AUTO); + begin_declaration_level(DLK_AUTO); } ; @@ -1819,7 +1817,7 @@ do_while_expr: /* see C99 6.8.5 */ for_start: /* see C99 6.8.5 */ T_FOR T_LPAREN { - begin_declaration_level(DK_AUTO); + begin_declaration_level(DLK_AUTO); block_level++; } ; @@ -1960,7 +1958,7 @@ function_definition: /* C99 6.9.1 */ } begin_function($1); block_level++; - begin_declaration_level(DK_OLD_STYLE_ARG); + begin_declaration_level(DLK_OLD_STYLE_ARGS); if (lwarn == LWARN_NONE) $1->s_used = true; } arg_declaration_list_opt { Index: src/usr.bin/xlint/lint1/debug.c diff -u src/usr.bin/xlint/lint1/debug.c:1.39 src/usr.bin/xlint/lint1/debug.c:1.40 --- src/usr.bin/xlint/lint1/debug.c:1.39 Fri Jun 30 21:06:18 2023 +++ src/usr.bin/xlint/lint1/debug.c Fri Jun 30 21:39:54 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: debug.c,v 1.39 2023/06/30 21:06:18 rillig Exp $ */ +/* $NetBSD: debug.c,v 1.40 2023/06/30 21:39:54 rillig Exp $ */ /*- * Copyright (c) 2021 The NetBSD Foundation, Inc. @@ -35,7 +35,7 @@ #include <sys/cdefs.h> #if defined(__RCSID) -__RCSID("$NetBSD: debug.c,v 1.39 2023/06/30 21:06:18 rillig Exp $"); +__RCSID("$NetBSD: debug.c,v 1.40 2023/06/30 21:39:54 rillig Exp $"); #endif #include <stdlib.h> @@ -250,20 +250,20 @@ def_name(def_t def) } const char * -declaration_kind_name(declaration_kind dk) +decl_level_kind_name(decl_level_kind kind) { static const char *const name[] = { "extern", - "member-of-struct", - "member-of-union", - "enum-constant", - "old-style-function-argument", - "prototype-argument", + "struct", + "union", + "enum", + "old-style-function-arguments", + "prototype-parameters", "auto", "abstract", }; - return name[dk]; + return name[kind]; } const char * @@ -395,62 +395,62 @@ debug_sym(const char *prefix, const sym_ } void -debug_dinfo(const dinfo_t *d) // NOLINT(misc-no-recursion) +debug_dinfo(const decl_level *dl) { debug_print_indent(); - debug_printf("dinfo: %s", declaration_kind_name(d->d_kind)); - if (d->d_scl != NOSCL) - debug_printf(" %s", scl_name(d->d_scl)); - if (d->d_type != NULL) { - debug_printf(" '%s'", type_name(d->d_type)); - } else { - if (d->d_abstract_type != NO_TSPEC) - debug_printf(" %s", tspec_name(d->d_abstract_type)); - if (d->d_complex_mod != NO_TSPEC) - debug_printf(" %s", tspec_name(d->d_complex_mod)); - if (d->d_sign_mod != NO_TSPEC) - debug_printf(" %s", tspec_name(d->d_sign_mod)); - if (d->d_rank_mod != NO_TSPEC) - debug_printf(" %s", tspec_name(d->d_rank_mod)); + debug_printf("decl_level: %s", decl_level_kind_name(dl->d_kind)); + if (dl->d_scl != NOSCL) + debug_printf(" %s", scl_name(dl->d_scl)); + if (dl->d_type != NULL) + debug_printf(" '%s'", type_name(dl->d_type)); + else { + if (dl->d_abstract_type != NO_TSPEC) + debug_printf(" %s", tspec_name(dl->d_abstract_type)); + if (dl->d_complex_mod != NO_TSPEC) + debug_printf(" %s", tspec_name(dl->d_complex_mod)); + if (dl->d_sign_mod != NO_TSPEC) + debug_printf(" %s", tspec_name(dl->d_sign_mod)); + if (dl->d_rank_mod != NO_TSPEC) + debug_printf(" %s", tspec_name(dl->d_rank_mod)); } - if (d->d_redeclared_symbol != NULL) - debug_sym(" redeclared=(", d->d_redeclared_symbol, ")"); - if (d->d_offset_in_bits != 0) - debug_printf(" offset=%u", d->d_offset_in_bits); - if (d->d_sou_align_in_bits != 0) - debug_printf(" align=%u", (unsigned)d->d_sou_align_in_bits); - - debug_word(d->d_const, "const"); - debug_word(d->d_volatile, "volatile"); - debug_word(d->d_inline, "inline"); - debug_word(d->d_multiple_storage_classes, "multiple_storage_classes"); - debug_word(d->d_invalid_type_combination, "invalid_type_combination"); - debug_word(d->d_nonempty_decl, "nonempty_decl"); - debug_word(d->d_vararg, "vararg"); - debug_word(d->d_prototype, "prototype"); - debug_word(d->d_no_type_specifier, "no_type_specifier"); - debug_word(d->d_asm, "asm"); - debug_word(d->d_packed, "packed"); - debug_word(d->d_used, "used"); - - if (d->d_tag_type != NULL) - debug_printf(" tag_type='%s'", type_name(d->d_tag_type)); - for (const sym_t *arg = d->d_func_args; + if (dl->d_redeclared_symbol != NULL) + debug_sym(" redeclared=(", dl->d_redeclared_symbol, ")"); + if (dl->d_offset_in_bits != 0) + debug_printf(" offset=%u", dl->d_offset_in_bits); + if (dl->d_sou_align_in_bits != 0) + debug_printf(" align=%u", (unsigned)dl->d_sou_align_in_bits); + + debug_word(dl->d_const, "const"); + debug_word(dl->d_volatile, "volatile"); + debug_word(dl->d_inline, "inline"); + debug_word(dl->d_multiple_storage_classes, "multiple_storage_classes"); + debug_word(dl->d_invalid_type_combination, "invalid_type_combination"); + debug_word(dl->d_nonempty_decl, "nonempty_decl"); + debug_word(dl->d_vararg, "vararg"); + debug_word(dl->d_prototype, "prototype"); + debug_word(dl->d_no_type_specifier, "no_type_specifier"); + debug_word(dl->d_asm, "asm"); + debug_word(dl->d_packed, "packed"); + debug_word(dl->d_used, "used"); + + if (dl->d_tag_type != NULL) + debug_printf(" tag_type='%s'", type_name(dl->d_tag_type)); + for (const sym_t *arg = dl->d_func_args; arg != NULL; arg = arg->s_next) debug_sym(" arg(", arg, ")"); - if (d->d_func_def_pos.p_file != NULL) - debug_printf(" func_def_pos=%s:%d:%d", - d->d_func_def_pos.p_file, d->d_func_def_pos.p_line, - d->d_func_def_pos.p_uniq); - for (const sym_t *sym = d->d_func_proto_syms; + if (dl->d_func_def_pos.p_file != NULL) + debug_printf(" func_def_pos=%s:%dl:%dl", + dl->d_func_def_pos.p_file, dl->d_func_def_pos.p_line, + dl->d_func_def_pos.p_uniq); + for (const sym_t *sym = dl->d_func_proto_syms; sym != NULL; sym = sym->s_next) debug_sym(" func_proto_sym(", sym, ")"); debug_printf("\n"); - if (d->d_enclosing != NULL) { + if (dl->d_enclosing != NULL) { debug_indent_inc(); - debug_dinfo(d->d_enclosing); + debug_dinfo(dl->d_enclosing); debug_indent_dec(); } } Index: src/usr.bin/xlint/lint1/decl.c diff -u src/usr.bin/xlint/lint1/decl.c:1.329 src/usr.bin/xlint/lint1/decl.c:1.330 --- src/usr.bin/xlint/lint1/decl.c:1.329 Fri Jun 30 21:06:18 2023 +++ src/usr.bin/xlint/lint1/decl.c Fri Jun 30 21:39:54 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: decl.c,v 1.329 2023/06/30 21:06:18 rillig Exp $ */ +/* $NetBSD: decl.c,v 1.330 2023/06/30 21:39:54 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.329 2023/06/30 21:06:18 rillig Exp $"); +__RCSID("$NetBSD: decl.c,v 1.330 2023/06/30 21:39:54 rillig Exp $"); #endif #include <sys/param.h> @@ -57,10 +57,11 @@ static type_t typetab[NTSPEC]; int enumval; /* - * pointer to innermost element of a stack which contains information local - * to nested declarations + * Points to the innermost element of a stack that contains information about + * nested declarations, such as struct declarations, function prototypes, + * local variables. */ -dinfo_t *dcs; +decl_level *dcs; static type_t *typedef_error(type_t *, tspec_t); static void set_first_typedef(type_t *, sym_t *); @@ -94,7 +95,7 @@ initdecl(void) /* declaration stack */ dcs = xcalloc(1, sizeof(*dcs)); - dcs->d_kind = DK_EXTERN; + dcs->d_kind = DLK_EXTERN; dcs->d_last_dlsym = &dcs->d_first_dlsym; if (!pflag) { @@ -511,41 +512,41 @@ dcs_add_qualifier(tqual_t q) } void -begin_declaration_level(declaration_kind dk) +begin_declaration_level(decl_level_kind kind) { - dinfo_t *di = xcalloc(1, sizeof(*di)); - di->d_enclosing = dcs; - di->d_kind = dk; - di->d_last_dlsym = &di->d_first_dlsym; - dcs = di; - debug_step("%s(%s)", __func__, declaration_kind_name(dk)); + decl_level *dl = xcalloc(1, sizeof(*dl)); + dl->d_enclosing = dcs; + dl->d_kind = kind; + dl->d_last_dlsym = &dl->d_first_dlsym; + dcs = dl; + debug_step("%s(%s)", __func__, decl_level_kind_name(kind)); } void end_declaration_level(void) { - dinfo_t *di; + decl_level *dl; - debug_step("%s(%s)", __func__, declaration_kind_name(dcs->d_kind)); + debug_step("%s(%s)", __func__, decl_level_kind_name(dcs->d_kind)); lint_assert(dcs->d_enclosing != NULL); - di = dcs; - dcs = di->d_enclosing; + dl = dcs; + dcs = dl->d_enclosing; - switch (di->d_kind) { - case DK_STRUCT_MEMBER: - case DK_UNION_MEMBER: - case DK_ENUM_CONSTANT: + switch (dl->d_kind) { + case DLK_STRUCT: + case DLK_UNION: + case DLK_ENUM: /* * Symbols declared in (nested) structs or enums are part of * the next level (they are removed from the symbol table if * the symbols of the outer level are removed). */ - if ((*dcs->d_last_dlsym = di->d_first_dlsym) != NULL) - dcs->d_last_dlsym = di->d_last_dlsym; + if ((*dcs->d_last_dlsym = dl->d_first_dlsym) != NULL) + dcs->d_last_dlsym = dl->d_last_dlsym; break; - case DK_OLD_STYLE_ARG: + case DLK_OLD_STYLE_ARGS: /* * All symbols in dcs->d_first_dlsym are introduced in * old-style argument declarations (it's not clean, but @@ -553,12 +554,12 @@ end_declaration_level(void) * in an old-style argument identifier list or a new-style * parameter type list. */ - if (di->d_first_dlsym != NULL) { - *di->d_last_dlsym = dcs->d_func_proto_syms; - dcs->d_func_proto_syms = di->d_first_dlsym; + if (dl->d_first_dlsym != NULL) { + *dl->d_last_dlsym = dcs->d_func_proto_syms; + dcs->d_func_proto_syms = dl->d_first_dlsym; } break; - case DK_ABSTRACT: /* casts and sizeof */ + case DLK_ABSTRACT: /* * Append all symbols declared in the abstract declaration to * the list of symbols declared in the surrounding declaration @@ -567,23 +568,23 @@ end_declaration_level(void) * XXX I'm not sure whether they should be removed from the * symbol table now or later. */ - if ((*dcs->d_last_dlsym = di->d_first_dlsym) != NULL) - dcs->d_last_dlsym = di->d_last_dlsym; + if ((*dcs->d_last_dlsym = dl->d_first_dlsym) != NULL) + dcs->d_last_dlsym = dl->d_last_dlsym; break; - case DK_AUTO: - check_usage(di); + case DLK_AUTO: + check_usage(dl); /* FALLTHROUGH */ - case DK_PROTO_ARG: + case DLK_PROTO_PARAMS: /* usage of arguments will be checked by end_function() */ - rmsyms(di->d_first_dlsym); + rmsyms(dl->d_first_dlsym); break; - case DK_EXTERN: + case DLK_EXTERN: /* there is nothing around an external declarations */ /* FALLTHROUGH */ default: lint_assert(/*CONSTCOND*/false); } - free(di); + free(dl); } /* @@ -593,19 +594,19 @@ end_declaration_level(void) * compound statements, asm statements. For these compound statements, no * warnings about unused or uninitialized variables are printed. * - * There is no need to clear d_asm in dinfo structs with context AUTO, because + * There is no need to clear d_asm in decl_level structs with context AUTO, as * these structs are freed at the end of the compound statement. But it must be - * cleared in the outermost dinfo struct, which has context EXTERN. This could - * be done in dcs_begin_type and would work for C90, but not for C99 or C++ - * (due to mixed statements and declarations). Thus, we clear it in + * cleared in the outermost decl_level struct, which has context EXTERN. This + * could be done in dcs_begin_type and would work for C90, but not for C99 or + * C++ (due to mixed statements and declarations). Thus, we clear it in * global_clean_up_decl. */ void dcs_set_asm(void) { - for (dinfo_t *di = dcs; di != NULL; di = di->d_enclosing) - di->d_asm = true; + for (decl_level *dl = dcs; dl != NULL; dl = dl->d_enclosing) + dl->d_asm = true; } void @@ -630,14 +631,14 @@ dcs_begin_type(void) static void dcs_adjust_storage_class(void) { - if (dcs->d_kind == DK_EXTERN) { + if (dcs->d_kind == DLK_EXTERN) { if (dcs->d_scl == REG || dcs->d_scl == AUTO) { /* illegal storage class */ error(8); dcs->d_scl = NOSCL; } - } else if (dcs->d_kind == DK_OLD_STYLE_ARG || - dcs->d_kind == DK_PROTO_ARG) { + } else if (dcs->d_kind == DLK_OLD_STYLE_ARGS || + dcs->d_kind == DLK_PROTO_PARAMS) { if (dcs->d_scl != NOSCL && dcs->d_scl != REG) { /* only register valid as formal parameter ... */ error(9); @@ -907,14 +908,14 @@ check_type(sym_t *sym) * length_in_bits already does this. */ } else if (to == NO_TSPEC && t == VOID) { - if (dcs->d_kind == DK_PROTO_ARG) { + if (dcs->d_kind == DLK_PROTO_PARAMS) { if (sym->s_scl != ABSTRACT) { lint_assert(sym->s_name != unnamed); /* void parameter '%s' cannot ... */ error(61, sym->s_name); *tpp = gettyp(INT); } - } else if (dcs->d_kind == DK_ABSTRACT) { + } else if (dcs->d_kind == DLK_ABSTRACT) { /* ok */ } else if (sym->s_scl != TYPEDEF) { /* void type for '%s' */ @@ -1023,7 +1024,7 @@ dcs_add_member(sym_t *mem) type_t *tp = mem->s_type; unsigned int union_offset = 0; - if (dcs->d_kind == DK_UNION_MEMBER) { + if (dcs->d_kind == DLK_UNION) { union_offset = dcs->d_offset_in_bits; dcs->d_offset_in_bits = 0; } @@ -1338,7 +1339,7 @@ add_function(sym_t *decl, sym_t *args) * because *dcs is the declaration stack element created for the list * of params and is removed after add_function.) */ - if (dcs->d_enclosing->d_kind == DK_EXTERN && + if (dcs->d_enclosing->d_kind == DLK_EXTERN && decl->s_type == dcs->d_enclosing->d_type) { dcs->d_enclosing->d_func_proto_syms = dcs->d_first_dlsym; dcs->d_enclosing->d_func_args = args; @@ -1407,7 +1408,7 @@ old_style_function(sym_t *decl, sym_t *a * Remember the list of parameters only if this really seems to be a * function definition. */ - if (dcs->d_enclosing->d_kind == DK_EXTERN && + if (dcs->d_enclosing->d_kind == DLK_EXTERN && decl->s_type == dcs->d_enclosing->d_type) { /* * Assume that this becomes a function definition. If not, it @@ -1462,16 +1463,14 @@ declarator_name(sym_t *sym) } switch (dcs->d_kind) { - case DK_STRUCT_MEMBER: - case DK_UNION_MEMBER: + case DLK_STRUCT: + case DLK_UNION: /* Set parent */ sym->u.s_member.sm_sou_type = dcs->d_tag_type->t_sou; sym->s_def = DEF; - sc = dcs->d_kind == DK_STRUCT_MEMBER - ? STRUCT_MEMBER - : UNION_MEMBER; + sc = dcs->d_kind == DLK_STRUCT ? STRUCT_MEMBER : UNION_MEMBER; break; - case DK_EXTERN: + case DLK_EXTERN: /* * static and external symbols without "extern" are considered * to be tentatively defined, external symbols with "extern" @@ -1491,10 +1490,10 @@ declarator_name(sym_t *sym) sym->s_def = DECL; } break; - case DK_PROTO_ARG: + case DLK_PROTO_PARAMS: sym->s_arg = true; /* FALLTHROUGH */ - case DK_OLD_STYLE_ARG: + case DLK_OLD_STYLE_ARGS: if ((sc = dcs->d_scl) == NOSCL) sc = AUTO; else { @@ -1504,7 +1503,7 @@ declarator_name(sym_t *sym) } sym->s_def = DEF; break; - case DK_AUTO: + case DLK_AUTO: if ((sc = dcs->d_scl) == NOSCL) { /* * XXX somewhat ugly because we don't know whether this @@ -1526,7 +1525,7 @@ declarator_name(sym_t *sym) } break; default: - lint_assert(dcs->d_kind == DK_ABSTRACT); + lint_assert(dcs->d_kind == DLK_ABSTRACT); /* try to continue after syntax errors */ sc = NOSCL; } @@ -1962,17 +1961,17 @@ void declare(sym_t *decl, bool has_initializer, sbuf_t *renaming) { - if (dcs->d_kind == DK_EXTERN) + if (dcs->d_kind == DLK_EXTERN) declare_extern(decl, has_initializer, renaming); - else if (dcs->d_kind == DK_OLD_STYLE_ARG || - dcs->d_kind == DK_PROTO_ARG) { + else if (dcs->d_kind == DLK_OLD_STYLE_ARGS || + dcs->d_kind == DLK_PROTO_PARAMS) { if (renaming != NULL) { /* symbol renaming can't be used on function arguments */ error(310); } else (void)declare_argument(decl, has_initializer); } else { - lint_assert(dcs->d_kind == DK_AUTO); + lint_assert(dcs->d_kind == DLK_AUTO); if (renaming != NULL) { /* symbol renaming can't be used on automatic variables */ error(311); @@ -2759,7 +2758,7 @@ check_init(sym_t *sym) return true; } if (sym->s_scl == EXTERN && sym->s_def == DECL) { - if (dcs->d_kind == DK_EXTERN) { + if (dcs->d_kind == DLK_EXTERN) { /* cannot initialize extern declaration '%s' */ warning(26, sym->s_name); } else { @@ -2777,14 +2776,15 @@ sym_t * abstract_name(void) { - lint_assert(dcs->d_kind == DK_ABSTRACT || dcs->d_kind == DK_PROTO_ARG); + lint_assert(dcs->d_kind == DLK_ABSTRACT + || dcs->d_kind == DLK_PROTO_PARAMS); sym_t *sym = block_zero_alloc(sizeof(*sym)); sym->s_name = unnamed; sym->s_def = DEF; sym->s_scl = ABSTRACT; sym->s_block_level = -1; - sym->s_arg = dcs->d_kind == DK_PROTO_ARG; + sym->s_arg = dcs->d_kind == DLK_PROTO_PARAMS; /* * At this point, dcs->d_type contains only the basic type. That @@ -2879,16 +2879,16 @@ mark_as_used(sym_t *sym, bool fcall, boo /* Warns about variables and labels that are not used or only set. */ void -check_usage(dinfo_t *di) +check_usage(decl_level *dl) { /* for this warning LINTED has no effect */ int saved_lwarn = lwarn; lwarn = LWARN_ALL; debug_step("begin lwarn %d", lwarn); - for (sym_t *sym = di->d_first_dlsym; + for (sym_t *sym = dl->d_first_dlsym; sym != NULL; sym = sym->s_level_next) - check_usage_sym(di->d_asm, sym); + check_usage_sym(dl->d_asm, sym); lwarn = saved_lwarn; debug_step("end lwarn %d", lwarn); } @@ -3020,7 +3020,7 @@ check_tag_usage(sym_t *sym) return; /* always complain about incomplete tags declared inside blocks */ - if (!zflag || dcs->d_kind != DK_EXTERN) + if (!zflag || dcs->d_kind != DLK_EXTERN) return; switch (sym->s_type->t_tspec) { @@ -3203,7 +3203,7 @@ to_int_constant(tnode_t *tn, bool requir * We don't free blocks that are inside casts because these * will be used later to match types. */ - if (tn->tn_op != CON && dcs->d_kind != DK_ABSTRACT) + if (tn->tn_op != CON && dcs->d_kind != DLK_ABSTRACT) expr_free_all(); tspec_t t = v->v_tspec; Index: src/usr.bin/xlint/lint1/externs1.h diff -u src/usr.bin/xlint/lint1/externs1.h:1.182 src/usr.bin/xlint/lint1/externs1.h:1.183 --- src/usr.bin/xlint/lint1/externs1.h:1.182 Fri Jun 30 21:06:18 2023 +++ src/usr.bin/xlint/lint1/externs1.h Fri Jun 30 21:39:54 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: externs1.h,v 1.182 2023/06/30 21:06:18 rillig Exp $ */ +/* $NetBSD: externs1.h,v 1.183 2023/06/30 21:39:54 rillig Exp $ */ /* * Copyright (c) 1994, 1995 Jochen Pohl @@ -118,11 +118,11 @@ void expr_restore_memory(memory_pool); */ #ifdef DEBUG -const char *declaration_kind_name(declaration_kind); +const char *decl_level_kind_name(decl_level_kind); const char *scl_name(scl_t); const char *symt_name(symt_t); const char *tqual_name(tqual_t); -void debug_dinfo(const dinfo_t *); +void debug_dinfo(const decl_level *); void debug_node(const tnode_t *); void debug_type(const type_t *); void debug_sym(const char *, const sym_t *, const char *); @@ -179,7 +179,7 @@ void enable_queries(const char *); /* * decl.c */ -extern dinfo_t *dcs; +extern decl_level *dcs; extern const char unnamed[]; extern int enumval; @@ -194,7 +194,7 @@ void dcs_add_type(type_t *); void dcs_add_qualifier(tqual_t); void dcs_add_packed(void); void dcs_set_used(void); -void begin_declaration_level(declaration_kind); +void begin_declaration_level(decl_level_kind); void end_declaration_level(void); void dcs_set_asm(void); void dcs_begin_type(void); @@ -235,7 +235,7 @@ sym_t *declare_abstract_type(sym_t *); void check_size(sym_t *); void mark_as_set(sym_t *); void mark_as_used(sym_t *, bool, bool); -void check_usage(dinfo_t *); +void check_usage(decl_level *); void check_usage_sym(bool, sym_t *); void check_global_symbols(void); void print_previous_declaration(const sym_t *); Index: src/usr.bin/xlint/lint1/func.c diff -u src/usr.bin/xlint/lint1/func.c:1.159 src/usr.bin/xlint/lint1/func.c:1.160 --- src/usr.bin/xlint/lint1/func.c:1.159 Thu Jun 29 22:52:44 2023 +++ src/usr.bin/xlint/lint1/func.c Fri Jun 30 21:39:54 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: func.c,v 1.159 2023/06/29 22:52:44 rillig Exp $ */ +/* $NetBSD: func.c,v 1.160 2023/06/30 21:39:54 rillig Exp $ */ /* * Copyright (c) 1994, 1995 Jochen Pohl @@ -37,7 +37,7 @@ #include <sys/cdefs.h> #if defined(__RCSID) -__RCSID("$NetBSD: func.c,v 1.159 2023/06/29 22:52:44 rillig Exp $"); +__RCSID("$NetBSD: func.c,v 1.160 2023/06/30 21:39:54 rillig Exp $"); #endif #include <stdlib.h> @@ -420,7 +420,7 @@ end_function(void) * the symbol table */ lint_assert(dcs->d_enclosing == NULL); - lint_assert(dcs->d_kind == DK_EXTERN); + lint_assert(dcs->d_kind == DLK_EXTERN); rmsyms(dcs->d_func_proto_syms); /* must be set on level 0 */ @@ -1144,7 +1144,7 @@ argsused(int n) if (n == -1) n = 0; - if (dcs->d_kind != DK_EXTERN) { + if (dcs->d_kind != DLK_EXTERN) { /* comment ** %s ** must be outside function */ warning(280, "ARGSUSED"); return; @@ -1170,7 +1170,7 @@ varargs(int n) if (n == -1) n = 0; - if (dcs->d_kind != DK_EXTERN) { + if (dcs->d_kind != DLK_EXTERN) { /* comment ** %s ** must be outside function */ warning(280, "VARARGS"); return; @@ -1196,7 +1196,7 @@ printflike(int n) if (n == -1) n = 0; - if (dcs->d_kind != DK_EXTERN) { + if (dcs->d_kind != DLK_EXTERN) { /* comment ** %s ** must be outside function */ warning(280, "PRINTFLIKE"); return; @@ -1222,7 +1222,7 @@ scanflike(int n) if (n == -1) n = 0; - if (dcs->d_kind != DK_EXTERN) { + if (dcs->d_kind != DLK_EXTERN) { /* comment ** %s ** must be outside function */ warning(280, "SCANFLIKE"); return; @@ -1277,7 +1277,7 @@ void lintlib(int n) { - if (dcs->d_kind != DK_EXTERN) { + if (dcs->d_kind != DLK_EXTERN) { /* comment ** %s ** must be outside function */ warning(280, "LINTLIBRARY"); return; @@ -1317,7 +1317,7 @@ void protolib(int n) { - if (dcs->d_kind != DK_EXTERN) { + if (dcs->d_kind != DLK_EXTERN) { /* comment ** %s ** must be outside function */ warning(280, "PROTOLIB"); return; Index: src/usr.bin/xlint/lint1/lex.c diff -u src/usr.bin/xlint/lint1/lex.c:1.163 src/usr.bin/xlint/lint1/lex.c:1.164 --- src/usr.bin/xlint/lint1/lex.c:1.163 Fri Jun 30 19:43:00 2023 +++ src/usr.bin/xlint/lint1/lex.c Fri Jun 30 21:39:54 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: lex.c,v 1.163 2023/06/30 19:43:00 rillig Exp $ */ +/* $NetBSD: lex.c,v 1.164 2023/06/30 21:39:54 rillig Exp $ */ /* * Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved. @@ -38,7 +38,7 @@ #include <sys/cdefs.h> #if defined(__RCSID) -__RCSID("$NetBSD: lex.c,v 1.163 2023/06/30 19:43:00 rillig Exp $"); +__RCSID("$NetBSD: lex.c,v 1.164 2023/06/30 21:39:54 rillig Exp $"); #endif #include <ctype.h> @@ -1315,23 +1315,23 @@ getsym(sbuf_t *sb) /* create a new symbol table entry */ /* labels must always be allocated at level 1 (outermost block) */ - dinfo_t *di; + decl_level *dl; if (symtyp == FLABEL) { sym = level_zero_alloc(1, sizeof(*sym)); char *s = level_zero_alloc(1, sb->sb_len + 1); (void)memcpy(s, sb->sb_name, sb->sb_len + 1); sym->s_name = s; sym->s_block_level = 1; - di = dcs; - while (di->d_enclosing != NULL && - di->d_enclosing->d_enclosing != NULL) - di = di->d_enclosing; - lint_assert(di->d_kind == DK_AUTO); + dl = dcs; + while (dl->d_enclosing != NULL && + dl->d_enclosing->d_enclosing != NULL) + dl = dl->d_enclosing; + lint_assert(dl->d_kind == DLK_AUTO); } else { sym = block_zero_alloc(sizeof(*sym)); sym->s_name = sb->sb_name; sym->s_block_level = block_level; - di = dcs; + dl = dcs; } sym->s_def_pos = unique_curr_pos(); @@ -1343,8 +1343,8 @@ getsym(sbuf_t *sb) if (!in_gcc_attribute) { symtab_add(sym); - *di->d_last_dlsym = sym; - di->d_last_dlsym = &sym->s_level_next; + *dl->d_last_dlsym = sym; + dl->d_last_dlsym = &sym->s_level_next; } free(sb); Index: src/usr.bin/xlint/lint1/lint1.h diff -u src/usr.bin/xlint/lint1/lint1.h:1.172 src/usr.bin/xlint/lint1/lint1.h:1.173 --- src/usr.bin/xlint/lint1/lint1.h:1.172 Fri Jun 30 19:43:00 2023 +++ src/usr.bin/xlint/lint1/lint1.h Fri Jun 30 21:39:54 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: lint1.h,v 1.172 2023/06/30 19:43:00 rillig Exp $ */ +/* $NetBSD: lint1.h,v 1.173 2023/06/30 21:39:54 rillig Exp $ */ /* * Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved. @@ -324,18 +324,19 @@ struct array_size { int dim; }; -typedef enum declaration_kind { - DK_EXTERN, /* global variable or function */ - DK_STRUCT_MEMBER, - DK_UNION_MEMBER, - DK_ENUM_CONSTANT, - DK_OLD_STYLE_ARG, /* argument in an old-style function +typedef enum decl_level_kind { + DLK_EXTERN, /* global types, variables or functions */ + DLK_STRUCT, /* members */ + DLK_UNION, /* members */ + DLK_ENUM, /* constants */ + DLK_OLD_STYLE_ARGS, /* arguments in an old-style function * definition */ - DK_PROTO_ARG, /* argument in a prototype function + DLK_PROTO_PARAMS, /* parameters in a prototype function * definition */ - DK_AUTO, /* local symbol */ - DK_ABSTRACT /* abstract declaration; type name */ -} declaration_kind; + DLK_AUTO, /* local types or variables */ + DLK_ABSTRACT /* abstract (unnamed) declaration; type name; + * used in casts and sizeof */ +} decl_level_kind; /* * A declaration level describes a struct, union, enum, block, argument @@ -344,8 +345,8 @@ typedef enum declaration_kind { * For nested declarations, the global 'dcs' holds all information needed for * the current level, the outer levels are available via 'd_enclosing'. */ -typedef struct dinfo { - declaration_kind d_kind; +typedef struct decl_level { + decl_level_kind d_kind; tspec_t d_abstract_type;/* VOID, BOOL, CHAR, INT or COMPLEX */ tspec_t d_complex_mod; /* FLOAT or DOUBLE */ tspec_t d_sign_mod; /* SIGNED or UNSIGN */ @@ -377,8 +378,8 @@ typedef struct dinfo { sym_t **d_last_dlsym; /* points to s_level_next in the last symbol declaration at this level */ sym_t *d_func_proto_syms; /* symbols defined in prototype */ - struct dinfo *d_enclosing; /* the enclosing declaration level */ -} dinfo_t; + struct decl_level *d_enclosing; /* the enclosing declaration level */ +} decl_level; /* One level of pointer indirection in declarators, including qualifiers. */ typedef struct qual_ptr { Index: src/usr.bin/xlint/lint1/tree.c diff -u src/usr.bin/xlint/lint1/tree.c:1.537 src/usr.bin/xlint/lint1/tree.c:1.538 --- src/usr.bin/xlint/lint1/tree.c:1.537 Fri Jun 30 21:06:18 2023 +++ src/usr.bin/xlint/lint1/tree.c Fri Jun 30 21:39:54 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: tree.c,v 1.537 2023/06/30 21:06:18 rillig Exp $ */ +/* $NetBSD: tree.c,v 1.538 2023/06/30 21:39:54 rillig Exp $ */ /* * Copyright (c) 1994, 1995 Jochen Pohl @@ -37,7 +37,7 @@ #include <sys/cdefs.h> #if defined(__RCSID) -__RCSID("$NetBSD: tree.c,v 1.537 2023/06/30 21:06:18 rillig Exp $"); +__RCSID("$NetBSD: tree.c,v 1.538 2023/06/30 21:39:54 rillig Exp $"); #endif #include <float.h> @@ -4399,7 +4399,7 @@ expr(tnode_t *tn, bool vctx, bool cond, } /* expr() is also called in global initializations */ - if (dcs->d_kind != DK_EXTERN && !is_do_while) + if (dcs->d_kind != DLK_EXTERN && !is_do_while) check_statement_reachable(); check_expr_misc(tn, vctx, cond, !cond, false, false, false); @@ -4512,8 +4512,8 @@ check_expr_load(const tnode_t *ln) static bool is_asm_around(void) { - for (dinfo_t *di = dcs; di != NULL; di = di->d_enclosing) - if (di->d_asm) + for (decl_level *dl = dcs; dl != NULL; dl = dl->d_enclosing) + if (dl->d_asm) return true; return false; }