Module Name:    src
Committed By:   rillig
Date:           Fri Mar 26 17:44:52 UTC 2021

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

Log Message:
lint: rename pushdecl and popdecl to be more expressive

The previous names were highly ambiguous.  The 'decl' could have meant
'declaration', which would be the usual abbreviation.  It could also be
split into 'dec' and 'l', meaning 'declaration level', which would make
more sense in this particular context.

To avoid having to guess anything about these names, rename the
functions.  Instead of 'push' and 'pop', I renamed them to 'begin' and
'end' since these are the high-level operation that are of interest.
That the hierarchy of declaration levels is implemented as a stack is
nice to know but not as important to understand the whole situation.

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.201 -r1.202 src/usr.bin/xlint/lint1/cgram.y
cvs rdiff -u -r1.159 -r1.160 src/usr.bin/xlint/lint1/decl.c
cvs rdiff -u -r1.85 -r1.86 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.201 src/usr.bin/xlint/lint1/cgram.y:1.202
--- src/usr.bin/xlint/lint1/cgram.y:1.201	Fri Mar 26 16:05:19 2021
+++ src/usr.bin/xlint/lint1/cgram.y	Fri Mar 26 17:44:52 2021
@@ -1,5 +1,5 @@
 %{
-/* $NetBSD: cgram.y,v 1.201 2021/03/26 16:05:19 rillig Exp $ */
+/* $NetBSD: cgram.y,v 1.202 2021/03/26 17:44:52 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.201 2021/03/26 16:05:19 rillig Exp $");
+__RCSID("$NetBSD: cgram.y,v 1.202 2021/03/26 17:44:52 rillig Exp $");
 #endif
 
 #include <limits.h>
@@ -439,11 +439,11 @@ function_definition:		/* C99 6.9.1 */
 		}
 		funcdef($1);
 		block_level++;
-		pushdecl(ARG);
+		begin_declaration_level(ARG);
 		if (lwarn == LWARN_NONE)
 			$1->s_used = true;
 	  } arg_declaration_list_opt {
-		popdecl();
+		end_declaration_level();
 		block_level--;
 		check_func_lint_directives();
 		check_func_old_style_arguments();
@@ -703,11 +703,11 @@ notype_typespec:
 		$$ = $2->tn_type;
 	  }
 	| struct_spec {
-		popdecl();
+		end_declaration_level();
 		$$ = $1;
 	  }
 	| enum_spec {
-		popdecl();
+		end_declaration_level();
 		$$ = $1;
 	  }
 	;
@@ -743,7 +743,7 @@ struct:
 	  struct type_attribute
 	| T_STRUCT_OR_UNION {
 		symtyp = FTAG;
-		pushdecl($1 == STRUCT ? MOS : MOU);
+		begin_declaration_level($1 == STRUCT ? MOS : MOU);
 		dcs->d_offset = 0;
 		dcs->d_stralign = CHAR_SIZE;
 		$$ = $1;
@@ -940,7 +940,7 @@ enum_spec:
 enum:
 	  T_ENUM {
 		symtyp = FTAG;
-		pushdecl(CTCONST);
+		begin_declaration_level(CTCONST);
 	  }
 	;
 
@@ -1072,7 +1072,7 @@ notype_direct_decl:
 	  }
 	| notype_direct_decl param_list opt_asm_or_symbolrename {
 		$$ = add_function(symbolrename($1, $3), $2);
-		popdecl();
+		end_declaration_level();
 		block_level--;
 	  }
 	| notype_direct_decl type_attribute_list
@@ -1105,7 +1105,7 @@ type_direct_decl:
 	  }
 	| type_direct_decl param_list opt_asm_or_symbolrename {
 		$$ = add_function(symbolrename($1, $3), $2);
-		popdecl();
+		end_declaration_level();
 		block_level--;
 	  }
 	| type_direct_decl type_attribute_list
@@ -1145,7 +1145,7 @@ direct_param_decl:
 	  }
 	| direct_param_decl param_list opt_asm_or_symbolrename {
 		$$ = add_function(symbolrename($1, $3), $2);
-		popdecl();
+		end_declaration_level();
 		block_level--;
 	  }
 	;
@@ -1174,7 +1174,7 @@ direct_notype_param_decl:
 	  }
 	| direct_notype_param_decl param_list opt_asm_or_symbolrename {
 		$$ = add_function(symbolrename($1, $3), $2);
-		popdecl();
+		end_declaration_level();
 		block_level--;
 	  }
 	;
@@ -1236,7 +1236,7 @@ param_list:
 id_list_lparen:
 	  T_LPAREN {
 		block_level++;
-		pushdecl(PROTO_ARG);
+		begin_declaration_level(PROTO_ARG);
 	  }
 	;
 
@@ -1268,7 +1268,7 @@ abstract_decl_param_list:
 abstract_decl_lparen:
 	  T_LPAREN {
 		block_level++;
-		pushdecl(PROTO_ARG);
+		begin_declaration_level(PROTO_ARG);
 	  }
 	;
 
@@ -1420,9 +1420,9 @@ init_rbrace:
 
 type_name:
 	  {
-		pushdecl(ABSTRACT);
+		begin_declaration_level(ABSTRACT);
 	  } abstract_declaration {
-		popdecl();
+		end_declaration_level();
 		$$ = $2->s_type;
 	  }
 	;
@@ -1478,12 +1478,12 @@ direct_abstract_decl:
 	  }
 	| abstract_decl_param_list opt_asm_or_symbolrename {
 		$$ = add_function(symbolrename(abstract_name(), $2), $1);
-		popdecl();
+		end_declaration_level();
 		block_level--;
 	  }
 	| direct_abstract_decl abstract_decl_param_list opt_asm_or_symbolrename {
 		$$ = add_function(symbolrename($1, $3), $2);
-		popdecl();
+		end_declaration_level();
 		block_level--;
 	  }
 	| direct_abstract_decl type_attribute_list
@@ -1537,13 +1537,13 @@ compound_statement_lbrace:
 	  T_LBRACE {
 		block_level++;
 		mem_block_level++;
-		pushdecl(AUTO);
+		begin_declaration_level(AUTO);
 	  }
 	;
 
 compound_statement_rbrace:
 	  T_RBRACE {
-		popdecl();
+		end_declaration_level();
 		freeblk();
 		mem_block_level--;
 		block_level--;
@@ -1696,13 +1696,13 @@ iteration_statement:		/* C99 6.8.5 */
 	| for_exprs statement {
 		clear_warning_flags();
 		for2();
-		popdecl();
+		end_declaration_level();
 		block_level--;
 	  }
 	| for_exprs error {
 		clear_warning_flags();
 		for2();
-		popdecl();
+		end_declaration_level();
 		block_level--;
 	  }
 	;
@@ -1728,7 +1728,7 @@ do_while_expr:
 
 for_start:
 	  T_FOR T_LPAREN {
-		pushdecl(AUTO);
+		begin_declaration_level(AUTO);
 		block_level++;
 	  }
 	;

Index: src/usr.bin/xlint/lint1/decl.c
diff -u src/usr.bin/xlint/lint1/decl.c:1.159 src/usr.bin/xlint/lint1/decl.c:1.160
--- src/usr.bin/xlint/lint1/decl.c:1.159	Tue Mar 23 18:40:50 2021
+++ src/usr.bin/xlint/lint1/decl.c	Fri Mar 26 17:44:52 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: decl.c,v 1.159 2021/03/23 18:40:50 rillig Exp $ */
+/* $NetBSD: decl.c,v 1.160 2021/03/26 17:44:52 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.159 2021/03/23 18:40:50 rillig Exp $");
+__RCSID("$NetBSD: decl.c,v 1.160 2021/03/26 17:44:52 rillig Exp $");
 #endif
 
 #include <sys/param.h>
@@ -588,7 +588,7 @@ add_qualifier(tqual_t q)
  * argument declaration lists ...)
  */
 void
-pushdecl(scl_t sc)
+begin_declaration_level(scl_t sc)
 {
 	dinfo_t	*di;
 
@@ -599,7 +599,8 @@ pushdecl(scl_t sc)
 	di->d_ctx = sc;
 	di->d_ldlsym = &di->d_dlsyms;
 	if (dflag)
-		(void)printf("pushdecl(%p %d)\n", dcs, (int)sc);
+		(void)printf("begin_declaration_level(%p %d)\n",
+		    dcs, (int)sc);
 
 }
 
@@ -607,12 +608,13 @@ pushdecl(scl_t sc)
  * Go back to previous declaration level
  */
 void
-popdecl(void)
+end_declaration_level(void)
 {
 	dinfo_t	*di;
 
 	if (dflag)
-		(void)printf("popdecl(%p %d)\n", dcs, (int)dcs->d_ctx);
+		(void)printf("end_declaration_level(%p %d)\n",
+		    dcs, (int)dcs->d_ctx);
 
 	lint_assert(dcs->d_next != NULL);
 	di = dcs;
@@ -1393,14 +1395,14 @@ add_function(sym_t *decl, sym_t *args)
 	}
 
 	/*
-	 * The symbols are removed from the symbol table by popdecl() after
-	 * add_function(). To be able to restore them if this is a function
-	 * definition, a pointer to the list of all symbols is stored in
-	 * dcs->d_next->d_func_proto_syms. Also a list of the arguments
-	 * (concatenated by s_next) is stored in dcs->d_next->d_func_args.
-	 * (dcs->d_next must be used because *dcs is the declaration stack
-	 * element created for the list of params and is removed after
-	 * add_function())
+	 * The symbols are removed from the symbol table by
+	 * end_declaration_level after add_function. To be able to restore
+	 * them if this is a function definition, a pointer to the list of all
+	 * symbols is stored in dcs->d_next->d_func_proto_syms. Also a list of
+	 * the arguments (concatenated by s_next) is stored in
+	 * dcs->d_next->d_func_args. (dcs->d_next must be used because *dcs is
+	 * the declaration stack element created for the list of params and is
+	 * removed after add_function.)
 	 */
 	if (dcs->d_next->d_ctx == EXTERN &&
 	    decl->s_type == dcs->d_next->d_type) {
@@ -2895,7 +2897,7 @@ global_clean_up(void)
 {
 
 	while (dcs->d_next != NULL)
-		popdecl();
+		end_declaration_level();
 
 	cleanup();
 	block_level = 0;

Index: src/usr.bin/xlint/lint1/externs1.h
diff -u src/usr.bin/xlint/lint1/externs1.h:1.85 src/usr.bin/xlint/lint1/externs1.h:1.86
--- src/usr.bin/xlint/lint1/externs1.h:1.85	Thu Mar 25 21:51:55 2021
+++ src/usr.bin/xlint/lint1/externs1.h	Fri Mar 26 17:44:52 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: externs1.h,v 1.85 2021/03/25 21:51:55 rillig Exp $	*/
+/*	$NetBSD: externs1.h,v 1.86 2021/03/26 17:44:52 rillig Exp $	*/
 
 /*
  * Copyright (c) 1994, 1995 Jochen Pohl
@@ -148,8 +148,8 @@ extern	void	add_type(type_t *);
 extern	void	add_qualifier(tqual_t);
 extern	void	addpacked(void);
 extern	void	add_attr_used(void);
-extern	void	pushdecl(scl_t);
-extern	void	popdecl(void);
+extern	void	begin_declaration_level(scl_t);
+extern	void	end_declaration_level(void);
 extern	void	setasm(void);
 extern	void	clrtyp(void);
 extern	void	deftyp(void);

Reply via email to