Module Name:    src
Committed By:   rillig
Date:           Sat Apr  9 23:41:22 UTC 2022

Modified Files:
        src/usr.bin/xlint/lint1: cgram.y debug.c decl.c externs1.h func.c lex.c
            lint1.h tree.c

Log Message:
lint: distinguish between storage class and declaration kind

These types overlap but are not the same.

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.392 -r1.393 src/usr.bin/xlint/lint1/cgram.y
cvs rdiff -u -r1.16 -r1.17 src/usr.bin/xlint/lint1/debug.c
cvs rdiff -u -r1.275 -r1.276 src/usr.bin/xlint/lint1/decl.c
cvs rdiff -u -r1.153 -r1.154 src/usr.bin/xlint/lint1/externs1.h
cvs rdiff -u -r1.131 -r1.132 src/usr.bin/xlint/lint1/func.c
cvs rdiff -u -r1.117 -r1.118 src/usr.bin/xlint/lint1/lex.c
cvs rdiff -u -r1.149 -r1.150 src/usr.bin/xlint/lint1/lint1.h
cvs rdiff -u -r1.423 -r1.424 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.392 src/usr.bin/xlint/lint1/cgram.y:1.393
--- src/usr.bin/xlint/lint1/cgram.y:1.392	Sat Apr  9 21:19:52 2022
+++ src/usr.bin/xlint/lint1/cgram.y	Sat Apr  9 23:41:22 2022
@@ -1,5 +1,5 @@
 %{
-/* $NetBSD: cgram.y,v 1.392 2022/04/09 21:19:52 rillig Exp $ */
+/* $NetBSD: cgram.y,v 1.393 2022/04/09 23:41:22 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.392 2022/04/09 21:19:52 rillig Exp $");
+__RCSID("$NetBSD: cgram.y,v 1.393 2022/04/09 23:41:22 rillig Exp $");
 #endif
 
 #include <limits.h>
@@ -920,7 +920,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 ? MOS : MOU);
+		begin_declaration_level($1 == STRUCT ? DK_MOS : DK_MOU);
 		dcs->d_offset_in_bits = 0;
 		dcs->d_sou_align_in_bits = CHAR_SIZE;
 		$$ = $1;
@@ -1069,7 +1069,7 @@ enum_specifier:			/* C99 6.7.2.2 */
 enum:				/* helper for C99 6.7.2.2 */
 	  T_ENUM {
 		symtyp = FTAG;
-		begin_declaration_level(ENUM_CONST);
+		begin_declaration_level(DK_ENUM_CONST);
 	  }
 	;
 
@@ -1329,7 +1329,7 @@ param_list:
 id_list_lparen:
 	  T_LPAREN {
 		block_level++;
-		begin_declaration_level(PROTO_ARG);
+		begin_declaration_level(DK_PROTO_ARG);
 	  }
 	;
 
@@ -1380,7 +1380,7 @@ identifier_list:		/* C99 6.7.5 */
 /* XXX: C99 requires an additional specifier-qualifier-list. */
 type_name:			/* C99 6.7.6 */
 	  {
-		begin_declaration_level(ABSTRACT);
+		begin_declaration_level(DK_ABSTRACT);
 	  } abstract_declaration {
 		end_declaration_level();
 		$$ = $2->s_type;
@@ -1460,7 +1460,7 @@ abstract_decl_param_list:	/* specific to
 abstract_decl_lparen:		/* specific to lint */
 	  T_LPAREN {
 		block_level++;
-		begin_declaration_level(PROTO_ARG);
+		begin_declaration_level(DK_PROTO_ARG);
 	  }
 	;
 
@@ -1674,7 +1674,7 @@ compound_statement_lbrace:
 	  T_LBRACE {
 		block_level++;
 		mem_block_level++;
-		begin_declaration_level(AUTO);
+		begin_declaration_level(DK_AUTO);
 	  }
 	;
 
@@ -1824,7 +1824,7 @@ do_while_expr:			/* see C99 6.8.5 */
 
 for_start:			/* see C99 6.8.5 */
 	  T_FOR T_LPAREN {
-		begin_declaration_level(AUTO);
+		begin_declaration_level(DK_AUTO);
 		block_level++;
 	  }
 	;
@@ -1960,7 +1960,7 @@ function_definition:		/* C99 6.9.1 */
 		}
 		funcdef($1);
 		block_level++;
-		begin_declaration_level(OLD_STYLE_ARG);
+		begin_declaration_level(DK_OLD_STYLE_ARG);
 		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.16 src/usr.bin/xlint/lint1/debug.c:1.17
--- src/usr.bin/xlint/lint1/debug.c:1.16	Sat Apr  9 21:19:52 2022
+++ src/usr.bin/xlint/lint1/debug.c	Sat Apr  9 23:41:22 2022
@@ -1,4 +1,4 @@
-/* $NetBSD: debug.c,v 1.16 2022/04/09 21:19:52 rillig Exp $ */
+/* $NetBSD: debug.c,v 1.17 2022/04/09 23:41:22 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.16 2022/04/09 21:19:52 rillig Exp $");
+__RCSID("$NetBSD: debug.c,v 1.17 2022/04/09 23:41:22 rillig Exp $");
 #endif
 
 #include <stdlib.h>
@@ -177,6 +177,23 @@ def_name(def_t def)
 }
 
 const char *
+declaration_kind_name(declaration_kind dk)
+{
+	static const char *const name[] = {
+		"extern",
+		"member-of-struct",
+		"member-of-union",
+		"enum-constant",
+		"old-style-function-argument",
+		"prototype-argument",
+		"auto",
+		"abstract",
+	};
+
+	return name[dk];
+}
+
+const char *
 scl_name(scl_t scl)
 {
 	static const char *const name[] = {
@@ -191,8 +208,6 @@ scl_name(scl_t scl)
 		"enum",
 		"member-of-struct",
 		"member-of-union",
-		"bool-constant",
-		"enum-constant",
 		"abstract",
 		"old-style-function-argument",
 		"prototype-argument",
@@ -308,7 +323,7 @@ debug_dinfo(const dinfo_t *d) // NOLINT(
 {
 
 	debug_print_indent();
-	debug_printf("dinfo: %s", scl_name(d->d_ctx));
+	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) {

Index: src/usr.bin/xlint/lint1/decl.c
diff -u src/usr.bin/xlint/lint1/decl.c:1.275 src/usr.bin/xlint/lint1/decl.c:1.276
--- src/usr.bin/xlint/lint1/decl.c:1.275	Sat Apr  9 21:19:52 2022
+++ src/usr.bin/xlint/lint1/decl.c	Sat Apr  9 23:41:22 2022
@@ -1,4 +1,4 @@
-/* $NetBSD: decl.c,v 1.275 2022/04/09 21:19:52 rillig Exp $ */
+/* $NetBSD: decl.c,v 1.276 2022/04/09 23:41:22 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.275 2022/04/09 21:19:52 rillig Exp $");
+__RCSID("$NetBSD: decl.c,v 1.276 2022/04/09 23:41:22 rillig Exp $");
 #endif
 
 #include <sys/param.h>
@@ -95,7 +95,7 @@ initdecl(void)
 
 	/* declaration stack */
 	dcs = xcalloc(1, sizeof(*dcs));
-	dcs->d_ctx = EXTERN;
+	dcs->d_kind = DK_EXTERN;
 	dcs->d_ldlsym = &dcs->d_dlsyms;
 
 	/* type information and classification */
@@ -574,7 +574,7 @@ add_qualifier(tqual_t q)
  * argument declaration lists ...)
  */
 void
-begin_declaration_level(scl_t sc)
+begin_declaration_level(declaration_kind dk)
 {
 	dinfo_t	*di;
 
@@ -582,9 +582,9 @@ begin_declaration_level(scl_t sc)
 	di = xcalloc(1, sizeof(*di));
 	di->d_enclosing = dcs;
 	dcs = di;
-	di->d_ctx = sc;
+	di->d_kind = dk;
 	di->d_ldlsym = &di->d_dlsyms;
-	debug_step("%s(%s)", __func__, scl_name(sc));
+	debug_step("%s(%s)", __func__, declaration_kind_name(dk));
 }
 
 /*
@@ -595,15 +595,15 @@ end_declaration_level(void)
 {
 	dinfo_t	*di;
 
-	debug_step("%s(%s)", __func__, scl_name(dcs->d_ctx));
+	debug_step("%s(%s)", __func__, declaration_kind_name(dcs->d_kind));
 
 	lint_assert(dcs->d_enclosing != NULL);
 	di = dcs;
 	dcs = di->d_enclosing;
-	switch (di->d_ctx) {
-	case MOS:
-	case MOU:
-	case ENUM_CONST:
+	switch (di->d_kind) {
+	case DK_MOS:
+	case DK_MOU:
+	case DK_ENUM_CONST:
 		/*
 		 * Symbols declared in (nested) structs or enums are
 		 * part of the next level (they are removed from the
@@ -613,7 +613,7 @@ end_declaration_level(void)
 		if ((*dcs->d_ldlsym = di->d_dlsyms) != NULL)
 			dcs->d_ldlsym = di->d_ldlsym;
 		break;
-	case OLD_STYLE_ARG:
+	case DK_OLD_STYLE_ARG:
 		/*
 		 * All symbols in dcs->d_dlsyms are introduced in old style
 		 * argument declarations (it's not clean, but possible).
@@ -626,7 +626,7 @@ end_declaration_level(void)
 			dcs->d_func_proto_syms = di->d_dlsyms;
 		}
 		break;
-	case ABSTRACT:
+	case DK_ABSTRACT:
 		/*
 		 * casts and sizeof
 		 * Append all symbols declared in the abstract declaration
@@ -638,15 +638,15 @@ end_declaration_level(void)
 		if ((*dcs->d_ldlsym = di->d_dlsyms) != NULL)
 			dcs->d_ldlsym = di->d_ldlsym;
 		break;
-	case AUTO:
+	case DK_AUTO:
 		/* check usage of local vars */
 		check_usage(di);
 		/* FALLTHROUGH */
-	case PROTO_ARG:
+	case DK_PROTO_ARG:
 		/* usage of arguments will be checked by funcend() */
 		rmsyms(di->d_dlsyms);
 		break;
-	case EXTERN:
+	case DK_EXTERN:
 		/* there is nothing after external declarations */
 		/* FALLTHROUGH */
 	default:
@@ -707,13 +707,14 @@ begin_type(void)
 static void
 dcs_adjust_storage_class(void)
 {
-	if (dcs->d_ctx == EXTERN) {
+	if (dcs->d_kind == DK_EXTERN) {
 		if (dcs->d_scl == REG || dcs->d_scl == AUTO) {
 			/* illegal storage class */
 			error(8);
 			dcs->d_scl = NOSCL;
 		}
-	} else if (dcs->d_ctx == OLD_STYLE_ARG || dcs->d_ctx == PROTO_ARG) {
+	} else if (dcs->d_kind == DK_OLD_STYLE_ARG ||
+		   dcs->d_kind == DK_PROTO_ARG) {
 		if (dcs->d_scl != NOSCL && dcs->d_scl != REG) {
 			/* only register valid as formal parameter storage... */
 			error(9);
@@ -1004,14 +1005,14 @@ check_type(sym_t *sym)
 #endif
 			}
 		} else if (to == NOTSPEC && t == VOID) {
-			if (dcs->d_ctx == PROTO_ARG) {
+			if (dcs->d_kind == DK_PROTO_ARG) {
 				if (sym->s_scl != ABSTRACT) {
 					lint_assert(sym->s_name != unnamed);
 					/* void parameter cannot have ... */
 					error(61, sym->s_name);
 					*tpp = gettyp(INT);
 				}
-			} else if (dcs->d_ctx == ABSTRACT) {
+			} else if (dcs->d_kind == DK_ABSTRACT) {
 				/* ok */
 			} else if (sym->s_scl != TYPEDEF) {
 				/* void type for '%s' */
@@ -1160,7 +1161,7 @@ declarator_1_struct_union(sym_t *dsym)
 		}
 	}
 
-	if (dcs->d_ctx == MOU) {
+	if (dcs->d_kind == DK_MOU) {
 		o = dcs->d_offset_in_bits;
 		dcs->d_offset_in_bits = 0;
 	}
@@ -1176,7 +1177,7 @@ declarator_1_struct_union(sym_t *dsym)
 		dsym->u.s_member.sm_offset_in_bits = dcs->d_offset_in_bits;
 		dcs->d_offset_in_bits += sz;
 	}
-	if (dcs->d_ctx == MOU) {
+	if (dcs->d_kind == DK_MOU) {
 		if (o > dcs->d_offset_in_bits)
 			dcs->d_offset_in_bits = o;
 	}
@@ -1436,7 +1437,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_ctx == EXTERN &&
+	if (dcs->d_enclosing->d_kind == DK_EXTERN &&
 	    decl->s_type == dcs->d_enclosing->d_type) {
 		dcs->d_enclosing->d_func_proto_syms = dcs->d_dlsyms;
 		dcs->d_enclosing->d_func_args = args;
@@ -1513,7 +1514,7 @@ old_style_function(sym_t *decl, sym_t *a
 	 * Remember list of parameters only if this really seems to be a
 	 * function definition.
 	 */
-	if (dcs->d_enclosing->d_ctx == EXTERN &&
+	if (dcs->d_enclosing->d_kind == DK_EXTERN &&
 	    decl->s_type == dcs->d_enclosing->d_type) {
 		/*
 		 * We assume that this becomes a function definition. If
@@ -1570,19 +1571,19 @@ declarator_name(sym_t *sym)
 		sym = pushdown(sym);
 	}
 
-	switch (dcs->d_ctx) {
-	case MOS:
-	case MOU:
+	switch (dcs->d_kind) {
+	case DK_MOS:
+	case DK_MOU:
 		/* Set parent */
 		sym->u.s_member.sm_sou_type = dcs->d_tagtyp->t_str;
 		sym->s_def = DEF;
 		/* XXX: Where is sym->u.s_member.sm_offset_in_bits set? */
-		sc = dcs->d_ctx;
+		sc = dcs->d_kind == DK_MOS ? MOS : MOU;
 		break;
-	case EXTERN:
+	case DK_EXTERN:
 		/*
 		 * static and external symbols without "extern" are
-		 * considered to be tentative defined, external
+		 * considered to be tentatively defined, external
 		 * symbols with "extern" are declared, and typedef names
 		 * are defined. Tentative defined and declared symbols
 		 * may become defined if an initializer is present or
@@ -1600,10 +1601,10 @@ declarator_name(sym_t *sym)
 			sym->s_def = DECL;
 		}
 		break;
-	case PROTO_ARG:
+	case DK_PROTO_ARG:
 		sym->s_arg = true;
 		/* FALLTHROUGH */
-	case OLD_STYLE_ARG:
+	case DK_OLD_STYLE_ARG:
 		if ((sc = dcs->d_scl) == NOSCL) {
 			sc = AUTO;
 		} else {
@@ -1613,7 +1614,7 @@ declarator_name(sym_t *sym)
 		}
 		sym->s_def = DEF;
 		break;
-	case AUTO:
+	case DK_AUTO:
 		if ((sc = dcs->d_scl) == NOSCL) {
 			/*
 			 * XXX somewhat ugly because we dont know whether
@@ -1634,7 +1635,7 @@ declarator_name(sym_t *sym)
 			sym->s_def = DECL;
 		}
 		break;
-	case ABSTRACT:		/* try to continue after syntax errors */
+	case DK_ABSTRACT:	/* try to continue after syntax errors */
 		sc = NOSCL;
 		break;
 	default:
@@ -2071,16 +2072,17 @@ void
 declare(sym_t *decl, bool initflg, sbuf_t *renaming)
 {
 
-	if (dcs->d_ctx == EXTERN) {
+	if (dcs->d_kind == DK_EXTERN) {
 		declare_extern(decl, initflg, renaming);
-	} else if (dcs->d_ctx == OLD_STYLE_ARG || dcs->d_ctx == PROTO_ARG) {
+	} else if (dcs->d_kind == DK_OLD_STYLE_ARG ||
+		   dcs->d_kind == DK_PROTO_ARG) {
 		if (renaming != NULL) {
 			/* symbol renaming can't be used on function arguments */
 			error(310);
 		} else
 			(void)declare_argument(decl, initflg);
 	} else {
-		lint_assert(dcs->d_ctx == AUTO);
+		lint_assert(dcs->d_kind == DK_AUTO);
 		if (renaming != NULL) {
 			/* symbol renaming can't be used on automatic variables */
 			error(311);
@@ -2888,7 +2890,7 @@ check_init(sym_t *sym)
 		erred = true;
 	} else if (sym->s_scl == EXTERN && sym->s_def == DECL) {
 		/* cannot initialize "extern" declaration: %s */
-		if (dcs->d_ctx == EXTERN) {
+		if (dcs->d_kind == DK_EXTERN) {
 			/* cannot initialize extern declaration: %s */
 			warning(26, sym->s_name);
 		} else {
@@ -2909,7 +2911,8 @@ abstract_name(void)
 {
 	sym_t	*sym;
 
-	lint_assert(dcs->d_ctx == ABSTRACT || dcs->d_ctx == PROTO_ARG);
+	lint_assert(dcs->d_kind == DK_ABSTRACT ||
+	    dcs->d_kind == DK_PROTO_ARG);
 
 	sym = block_zero_alloc(sizeof(*sym));
 
@@ -2918,7 +2921,7 @@ abstract_name(void)
 	sym->s_scl = ABSTRACT;
 	sym->s_block_level = -1;
 
-	if (dcs->d_ctx == PROTO_ARG)
+	if (dcs->d_kind == DK_PROTO_ARG)
 		sym->s_arg = true;
 
 	/*
@@ -3183,7 +3186,7 @@ check_tag_usage(sym_t *sym)
 		return;
 
 	/* always complain about incomplete tags declared inside blocks */
-	if (!zflag || dcs->d_ctx != EXTERN)
+	if (!zflag || dcs->d_kind != DK_EXTERN)
 		return;
 
 	switch (sym->s_type->t_tspec) {
@@ -3376,7 +3379,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_ctx != ABSTRACT)
+	if (tn->tn_op != CON && dcs->d_kind != DK_ABSTRACT)
 		expr_free_all();
 
 	if ((t = v->v_tspec) == FLOAT || t == DOUBLE || t == LDOUBLE) {

Index: src/usr.bin/xlint/lint1/externs1.h
diff -u src/usr.bin/xlint/lint1/externs1.h:1.153 src/usr.bin/xlint/lint1/externs1.h:1.154
--- src/usr.bin/xlint/lint1/externs1.h:1.153	Sat Apr  9 13:22:05 2022
+++ src/usr.bin/xlint/lint1/externs1.h	Sat Apr  9 23:41:22 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: externs1.h,v 1.153 2022/04/09 13:22:05 rillig Exp $	*/
+/*	$NetBSD: externs1.h,v 1.154 2022/04/09 23:41:22 rillig Exp $	*/
 
 /*
  * Copyright (c) 1994, 1995 Jochen Pohl
@@ -115,6 +115,7 @@ extern	void	expr_restore_memory(struct m
  */
 
 #ifdef DEBUG
+const char *declaration_kind_name(declaration_kind);
 const char *scl_name(scl_t);
 const char *symt_name(symt_t);
 const char *tqual_name(tqual_t);
@@ -186,7 +187,7 @@ extern	void	add_type(type_t *);
 extern	void	add_qualifier(tqual_t);
 extern	void	addpacked(void);
 extern	void	add_attr_used(void);
-extern	void	begin_declaration_level(scl_t);
+extern	void	begin_declaration_level(declaration_kind);
 extern	void	end_declaration_level(void);
 extern	void	setasm(void);
 extern	void	begin_type(void);

Index: src/usr.bin/xlint/lint1/func.c
diff -u src/usr.bin/xlint/lint1/func.c:1.131 src/usr.bin/xlint/lint1/func.c:1.132
--- src/usr.bin/xlint/lint1/func.c:1.131	Sat Apr  9 13:38:17 2022
+++ src/usr.bin/xlint/lint1/func.c	Sat Apr  9 23:41:22 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: func.c,v 1.131 2022/04/09 13:38:17 rillig Exp $	*/
+/*	$NetBSD: func.c,v 1.132 2022/04/09 23:41:22 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.131 2022/04/09 13:38:17 rillig Exp $");
+__RCSID("$NetBSD: func.c,v 1.132 2022/04/09 23:41:22 rillig Exp $");
 #endif
 
 #include <stdlib.h>
@@ -423,7 +423,7 @@ funcend(void)
 	 * the symbol table
 	 */
 	lint_assert(dcs->d_enclosing == NULL);
-	lint_assert(dcs->d_ctx == EXTERN);
+	lint_assert(dcs->d_kind == DK_EXTERN);
 	rmsyms(dcs->d_func_proto_syms);
 
 	/* must be set on level 0 */
@@ -1178,7 +1178,7 @@ argsused(int n)
 	if (n == -1)
 		n = 0;
 
-	if (dcs->d_ctx != EXTERN) {
+	if (dcs->d_kind != DK_EXTERN) {
 		/* must be outside function: ** %s ** */
 		warning(280, "ARGSUSED");
 		return;
@@ -1204,7 +1204,7 @@ varargs(int n)
 	if (n == -1)
 		n = 0;
 
-	if (dcs->d_ctx != EXTERN) {
+	if (dcs->d_kind != DK_EXTERN) {
 		/* must be outside function: ** %s ** */
 		warning(280, "VARARGS");
 		return;
@@ -1230,7 +1230,7 @@ printflike(int n)
 	if (n == -1)
 		n = 0;
 
-	if (dcs->d_ctx != EXTERN) {
+	if (dcs->d_kind != DK_EXTERN) {
 		/* must be outside function: ** %s ** */
 		warning(280, "PRINTFLIKE");
 		return;
@@ -1256,7 +1256,7 @@ scanflike(int n)
 	if (n == -1)
 		n = 0;
 
-	if (dcs->d_ctx != EXTERN) {
+	if (dcs->d_kind != DK_EXTERN) {
 		/* must be outside function: ** %s ** */
 		warning(280, "SCANFLIKE");
 		return;
@@ -1311,7 +1311,7 @@ void
 lintlib(int n)
 {
 
-	if (dcs->d_ctx != EXTERN) {
+	if (dcs->d_kind != DK_EXTERN) {
 		/* must be outside function: ** %s ** */
 		warning(280, "LINTLIBRARY");
 		return;
@@ -1354,7 +1354,7 @@ void
 protolib(int n)
 {
 
-	if (dcs->d_ctx != EXTERN) {
+	if (dcs->d_kind != DK_EXTERN) {
 		/* must be outside function: ** %s ** */
 		warning(280, "PROTOLIB");
 		return;

Index: src/usr.bin/xlint/lint1/lex.c
diff -u src/usr.bin/xlint/lint1/lex.c:1.117 src/usr.bin/xlint/lint1/lex.c:1.118
--- src/usr.bin/xlint/lint1/lex.c:1.117	Sat Apr  9 15:43:41 2022
+++ src/usr.bin/xlint/lint1/lex.c	Sat Apr  9 23:41:22 2022
@@ -1,4 +1,4 @@
-/* $NetBSD: lex.c,v 1.117 2022/04/09 15:43:41 rillig Exp $ */
+/* $NetBSD: lex.c,v 1.118 2022/04/09 23:41:22 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.117 2022/04/09 15:43:41 rillig Exp $");
+__RCSID("$NetBSD: lex.c,v 1.118 2022/04/09 23:41:22 rillig Exp $");
 #endif
 
 #include <ctype.h>
@@ -1417,7 +1417,7 @@ getsym(sbuf_t *sb)
 		while (di->d_enclosing != NULL &&
 		    di->d_enclosing->d_enclosing != NULL)
 			di = di->d_enclosing;
-		lint_assert(di->d_ctx == AUTO);
+		lint_assert(di->d_kind == DK_AUTO);
 	} else {
 		sym = block_zero_alloc(sizeof(*sym));
 		sym->s_name = sb->sb_name;

Index: src/usr.bin/xlint/lint1/lint1.h
diff -u src/usr.bin/xlint/lint1/lint1.h:1.149 src/usr.bin/xlint/lint1/lint1.h:1.150
--- src/usr.bin/xlint/lint1/lint1.h:1.149	Sat Apr  9 21:19:52 2022
+++ src/usr.bin/xlint/lint1/lint1.h	Sat Apr  9 23:41:22 2022
@@ -1,4 +1,4 @@
-/* $NetBSD: lint1.h,v 1.149 2022/04/09 21:19:52 rillig Exp $ */
+/* $NetBSD: lint1.h,v 1.150 2022/04/09 23:41:22 rillig Exp $ */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
@@ -206,9 +206,6 @@ typedef enum {
 	BOOL_CONST,
 	ENUM_CONST,
 	ABSTRACT,	/* abstract symbol (sizeof, casts, unnamed argument) */
-	OLD_STYLE_ARG,	/* old-style function argument declarations */
-	PROTO_ARG,	/* used in declaration stack during prototype
-			   declaration */
 	INLINE		/* only used by the parser */
 } scl_t;
 
@@ -323,24 +320,26 @@ struct array_size {
 	int dim;
 };
 
+typedef enum declaration_kind {
+	DK_EXTERN,		/* global variable or function */
+	DK_MOS,			/* struct member */
+	DK_MOU,			/* union member */
+	DK_ENUM_CONST,		/* enum constant */
+	DK_OLD_STYLE_ARG,	/* argument in an old-style function
+				 * definition */
+	DK_PROTO_ARG,		/* argument in a prototype function
+				 * definition */
+	DK_AUTO,		/* local symbol */
+	DK_ABSTRACT		/* abstract declaration; type name */
+} declaration_kind;
+
 /*
  * For nested declarations there is a stack that holds all information
  * needed for the current level. dcs points to the innermost element of this
  * stack.
- *
- * d_ctx describes the context of the current declaration. Its value is
- * one of
- *	EXTERN		global declarations
- *	MOS or MOU	declarations of struct or union members
- *	CTCONST		declarations of enums or boolean constants
- *	OLD_STYLE_ARG	declaration of arguments in old-style function
- *			definitions
- *	PROTO_ARG	declaration of arguments in function prototypes
- *	AUTO		declaration of local symbols
- *	ABSTRACT	abstract declarations (sizeof, casts)
- *
  */
 typedef	struct dinfo {
+	declaration_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 */
@@ -352,7 +351,6 @@ typedef	struct dinfo {
 	unsigned int d_offset_in_bits; /* offset of next structure member */
 	unsigned short d_sou_align_in_bits; /* alignment required for current
 				 * structure */
-	scl_t	d_ctx;		/* context of declaration */
 	bool	d_const:1;	/* const in declaration specifiers */
 	bool	d_volatile:1;	/* volatile in declaration specifiers */
 	bool	d_inline:1;	/* inline in declaration specifiers */

Index: src/usr.bin/xlint/lint1/tree.c
diff -u src/usr.bin/xlint/lint1/tree.c:1.423 src/usr.bin/xlint/lint1/tree.c:1.424
--- src/usr.bin/xlint/lint1/tree.c:1.423	Sat Apr  9 16:02:14 2022
+++ src/usr.bin/xlint/lint1/tree.c	Sat Apr  9 23:41:22 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: tree.c,v 1.423 2022/04/09 16:02:14 rillig Exp $	*/
+/*	$NetBSD: tree.c,v 1.424 2022/04/09 23:41:22 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.423 2022/04/09 16:02:14 rillig Exp $");
+__RCSID("$NetBSD: tree.c,v 1.424 2022/04/09 23:41:22 rillig Exp $");
 #endif
 
 #include <float.h>
@@ -3902,7 +3902,7 @@ expr(tnode_t *tn, bool vctx, bool tctx, 
 	}
 
 	/* expr() is also called in global initializations */
-	if (dcs->d_ctx != EXTERN && !is_do_while)
+	if (dcs->d_kind != DK_EXTERN && !is_do_while)
 		check_statement_reachable();
 
 	check_expr_misc(tn, vctx, tctx, !tctx, false, false, false);

Reply via email to