Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.bin/xlint/lint1 lint: rename pushdecl and popdecl to be ...



details:   https://anonhg.NetBSD.org/src/rev/53f1bd85af0a
branches:  trunk
changeset: 953969:53f1bd85af0a
user:      rillig <rillig%NetBSD.org@localhost>
date:      Fri Mar 26 17:44:52 2021 +0000

description:
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.

diffstat:

 usr.bin/xlint/lint1/cgram.y    |  46 +++++++++++++++++++++---------------------
 usr.bin/xlint/lint1/decl.c     |  32 +++++++++++++++-------------
 usr.bin/xlint/lint1/externs1.h |   6 ++--
 3 files changed, 43 insertions(+), 41 deletions(-)

diffs (292 lines):

diff -r 484bbe1196ea -r 53f1bd85af0a usr.bin/xlint/lint1/cgram.y
--- a/usr.bin/xlint/lint1/cgram.y       Fri Mar 26 16:59:18 2021 +0000
+++ b/usr.bin/xlint/lint1/cgram.y       Fri Mar 26 17:44:52 2021 +0000
@@ -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 @@
                }
                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 @@
                $$ = $2->tn_type;
          }
        | struct_spec {
-               popdecl();
+               end_declaration_level();
                $$ = $1;
          }
        | enum_spec {
-               popdecl();
+               end_declaration_level();
                $$ = $1;
          }
        ;
@@ -743,7 +743,7 @@
          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:
          T_ENUM {
                symtyp = FTAG;
-               pushdecl(CTCONST);
+               begin_declaration_level(CTCONST);
          }
        ;
 
@@ -1072,7 +1072,7 @@
          }
        | 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 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 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 param_list opt_asm_or_symbolrename {
                $$ = add_function(symbolrename($1, $3), $2);
-               popdecl();
+               end_declaration_level();
                block_level--;
          }
        ;
@@ -1236,7 +1236,7 @@
 id_list_lparen:
          T_LPAREN {
                block_level++;
-               pushdecl(PROTO_ARG);
+               begin_declaration_level(PROTO_ARG);
          }
        ;
 
@@ -1268,7 +1268,7 @@
 abstract_decl_lparen:
          T_LPAREN {
                block_level++;
-               pushdecl(PROTO_ARG);
+               begin_declaration_level(PROTO_ARG);
          }
        ;
 
@@ -1420,9 +1420,9 @@
 
 type_name:
          {
-               pushdecl(ABSTRACT);
+               begin_declaration_level(ABSTRACT);
          } abstract_declaration {
-               popdecl();
+               end_declaration_level();
                $$ = $2->s_type;
          }
        ;
@@ -1478,12 +1478,12 @@
          }
        | 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 @@
          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 @@
        | 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 @@
 
 for_start:
          T_FOR T_LPAREN {
-               pushdecl(AUTO);
+               begin_declaration_level(AUTO);
                block_level++;
          }
        ;
diff -r 484bbe1196ea -r 53f1bd85af0a usr.bin/xlint/lint1/decl.c
--- a/usr.bin/xlint/lint1/decl.c        Fri Mar 26 16:59:18 2021 +0000
+++ b/usr.bin/xlint/lint1/decl.c        Fri Mar 26 17:44:52 2021 +0000
@@ -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 @@
  * argument declaration lists ...)
  */
 void
-pushdecl(scl_t sc)
+begin_declaration_level(scl_t sc)
 {
        dinfo_t *di;
 
@@ -599,7 +599,8 @@
        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 @@
  * 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 @@
        }
 
        /*
-        * 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 @@
 {
 
        while (dcs->d_next != NULL)
-               popdecl();
+               end_declaration_level();
 
        cleanup();
        block_level = 0;
diff -r 484bbe1196ea -r 53f1bd85af0a usr.bin/xlint/lint1/externs1.h
--- a/usr.bin/xlint/lint1/externs1.h    Fri Mar 26 16:59:18 2021 +0000
+++ b/usr.bin/xlint/lint1/externs1.h    Fri Mar 26 17:44:52 2021 +0000
@@ -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_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);



Home | Main Index | Thread Index | Old Index