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 pqinf_t to qual_ptr and cle...



details:   https://anonhg.NetBSD.org/src/rev/34b1e3ee48bb
branches:  trunk
changeset: 984218:34b1e3ee48bb
user:      rillig <rillig%NetBSD.org@localhost>
date:      Mon Jun 28 08:52:55 2021 +0000

description:
lint: rename pqinf_t to qual_ptr and clean up code

The 'inf' from the type name meant 'information' and was redundant. Each
object of that type represents a single pointer level, which made the
documentation about 'pointers' a bit confusing.

The members of struct qual_ptr are now in the canonical reading order,
which is 'const volatile pointer'.

No functional change.

diffstat:

 usr.bin/xlint/lint1/cgram.y    |  26 ++++++--------
 usr.bin/xlint/lint1/decl.c     |  73 +++++++++++++++++++++--------------------
 usr.bin/xlint/lint1/externs1.h |   6 +-
 usr.bin/xlint/lint1/lint1.h    |  15 +++-----
 4 files changed, 58 insertions(+), 62 deletions(-)

diffs (251 lines):

diff -r 74a50afe813b -r 34b1e3ee48bb usr.bin/xlint/lint1/cgram.y
--- a/usr.bin/xlint/lint1/cgram.y       Mon Jun 28 07:55:05 2021 +0000
+++ b/usr.bin/xlint/lint1/cgram.y       Mon Jun 28 08:52:55 2021 +0000
@@ -1,5 +1,5 @@
 %{
-/* $NetBSD: cgram.y,v 1.242 2021/06/28 07:55:05 rillig Exp $ */
+/* $NetBSD: cgram.y,v 1.243 2021/06/28 08:52:55 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.242 2021/06/28 07:55:05 rillig Exp $");
+__RCSID("$NetBSD: cgram.y,v 1.243 2021/06/28 08:52:55 rillig Exp $");
 #endif
 
 #include <limits.h>
@@ -137,7 +137,7 @@
        tnode_t *y_tnode;
        range_t y_range;
        strg_t  *y_string;
-       pqinf_t *y_pqinf;
+       qual_ptr *y_qual_ptr;
        bool    y_seen_statement;
        struct generic_association_types *y_types;
 };
@@ -306,16 +306,16 @@
 %type  <y_sym>         enumeration_constant
 %type  <y_sym>         notype_direct_decl
 %type  <y_sym>         type_direct_decl
-%type  <y_pqinf>       pointer
-%type  <y_pqinf>       asterisk
+%type  <y_qual_ptr>    pointer
+%type  <y_qual_ptr>    asterisk
 %type  <y_sym>         param_decl
 %type  <y_sym>         param_list
 %type  <y_sym>         abstract_decl_param_list
 %type  <y_sym>         direct_param_decl
 %type  <y_sym>         notype_param_decl
 %type  <y_sym>         direct_notype_param_decl
-%type  <y_pqinf>       type_qualifier_list
-%type  <y_pqinf>       type_qualifier
+%type  <y_qual_ptr>    type_qualifier_list
+%type  <y_qual_ptr>    type_qualifier
 %type  <y_sym>         identifier_list
 %type  <y_sym>         abstract_decl
 %type  <y_sym>         direct_abstract_decl
@@ -1203,16 +1203,14 @@
 pointer:
          asterisk
        | asterisk type_qualifier_list {
-               /* TODO: rename pqinf_t to be more expressive */
-               /* TODO: then rename the merge function */
-               $$ = merge_pointers_and_qualifiers($1, $2);
+               $$ = merge_qualified_pointer($1, $2);
          }
        | asterisk pointer {
-               $$ = merge_pointers_and_qualifiers($1, $2);
+               $$ = merge_qualified_pointer($1, $2);
          }
        | asterisk type_qualifier_list pointer {
-               $$ = merge_pointers_and_qualifiers($1, $2);
-               $$ = merge_pointers_and_qualifiers($$, $3);
+               $$ = merge_qualified_pointer($1, $2);
+               $$ = merge_qualified_pointer($$, $3);
          }
        ;
 
@@ -1227,7 +1225,7 @@
 type_qualifier_list:
          type_qualifier
        | type_qualifier_list type_qualifier {
-               $$ = merge_pointers_and_qualifiers($1, $2);
+               $$ = merge_qualified_pointer($1, $2);
          }
        ;
 
diff -r 74a50afe813b -r 34b1e3ee48bb usr.bin/xlint/lint1/decl.c
--- a/usr.bin/xlint/lint1/decl.c        Mon Jun 28 07:55:05 2021 +0000
+++ b/usr.bin/xlint/lint1/decl.c        Mon Jun 28 08:52:55 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: decl.c,v 1.189 2021/06/27 08:20:50 rillig Exp $ */
+/* $NetBSD: decl.c,v 1.190 2021/06/28 08:52:55 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.189 2021/06/27 08:20:50 rillig Exp $");
+__RCSID("$NetBSD: decl.c,v 1.190 2021/06/28 08:52:55 rillig Exp $");
 #endif
 
 #include <sys/param.h>
@@ -1286,40 +1286,41 @@
 }
 
 /*
- * Collect information about a sequence of asterisks and qualifiers in a
- * list of type pqinf_t.
- * Qualifiers always refer to the left asterisk.
- * The rightmost asterisk will be at the top of the list.
+ * A sequence of asterisks and qualifiers, from right to left.  For example,
+ * 'const ***volatile **const volatile' results in [cvp, p, vp, p, p].  The
+ * leftmost 'const' is not included in this list, it is stored in dcs->d_const
+ * instead.
  */
-pqinf_t *
-merge_pointers_and_qualifiers(pqinf_t *p1, pqinf_t *p2)
+qual_ptr *
+merge_qualified_pointer(qual_ptr *p1, qual_ptr *p2)
 {
-       pqinf_t *p;
+       qual_ptr *tail;
 
        if (p2->p_pointer) {
-               /* left '*' at the end of the list */
-               for (p = p2; p->p_next != NULL; p = p->p_next)
+               /* append p1 to p2, keeping p2 */
+               for (tail = p2; tail->p_next != NULL; tail = tail->p_next)
                        continue;
-               p->p_next = p1;
+               tail->p_next = p1;
                return p2;
-       } else {
-               if (p2->p_const) {
-                       if (p1->p_const) {
-                               /* duplicate '%s' */
-                               warning(10, "const");
-                       }
-                       p1->p_const = true;
+       }
+
+       /* merge p2 into p1, keeping p1 */
+       if (p2->p_const) {
+               if (p1->p_const) {
+                       /* duplicate '%s' */
+                       warning(10, "const");
                }
-               if (p2->p_volatile) {
-                       if (p1->p_volatile) {
-                               /* duplicate '%s' */
-                               warning(10, "volatile");
-                       }
-                       p1->p_volatile = true;
+               p1->p_const = true;
+       }
+       if (p2->p_volatile) {
+               if (p1->p_volatile) {
+                       /* duplicate '%s' */
+                       warning(10, "volatile");
                }
-               free(p2);
-               return p1;
+               p1->p_volatile = true;
        }
+       free(p2);
+       return p1;
 }
 
 /*
@@ -1331,10 +1332,10 @@
  * declarator. The new type extension is inserted between both.
  */
 sym_t *
-add_pointer(sym_t *decl, pqinf_t *pi)
+add_pointer(sym_t *decl, qual_ptr *p)
 {
-       type_t  **tpp, *tp;
-       pqinf_t *npi;
+       type_t **tpp, *tp;
+       qual_ptr *next;
 
        tpp = &decl->s_type;
        while (*tpp != NULL && *tpp != dcs->d_type)
@@ -1342,15 +1343,15 @@
        if (*tpp == NULL)
                return decl;
 
-       while (pi != NULL) {
+       while (p != NULL) {
                *tpp = tp = getblk(sizeof(*tp));
                tp->t_tspec = PTR;
-               tp->t_const = pi->p_const;
-               tp->t_volatile = pi->p_volatile;
+               tp->t_const = p->p_const;
+               tp->t_volatile = p->p_volatile;
                *(tpp = &tp->t_subt) = dcs->d_type;
-               npi = pi->p_next;
-               free(pi);
-               pi = npi;
+               next = p->p_next;
+               free(p);
+               p = next;
        }
        return decl;
 }
diff -r 74a50afe813b -r 34b1e3ee48bb usr.bin/xlint/lint1/externs1.h
--- a/usr.bin/xlint/lint1/externs1.h    Mon Jun 28 07:55:05 2021 +0000
+++ b/usr.bin/xlint/lint1/externs1.h    Mon Jun 28 08:52:55 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: externs1.h,v 1.112 2021/06/27 20:47:13 rillig Exp $    */
+/*     $NetBSD: externs1.h,v 1.113 2021/06/28 08:52:55 rillig Exp $    */
 
 /*
  * Copyright (c) 1994, 1995 Jochen Pohl
@@ -163,8 +163,8 @@
 extern void    check_type(sym_t *);
 extern sym_t   *declarator_1_struct_union(sym_t *);
 extern sym_t   *bitfield(sym_t *, int);
-extern pqinf_t *merge_pointers_and_qualifiers(pqinf_t *, pqinf_t *);
-extern sym_t   *add_pointer(sym_t *, pqinf_t *);
+extern qual_ptr *merge_qualified_pointer(qual_ptr *, qual_ptr *);
+extern sym_t   *add_pointer(sym_t *, qual_ptr *);
 extern sym_t   *add_array(sym_t *, bool, int);
 extern sym_t   *add_function(sym_t *, sym_t *);
 extern void    check_function_definition(sym_t *, bool);
diff -r 74a50afe813b -r 34b1e3ee48bb usr.bin/xlint/lint1/lint1.h
--- a/usr.bin/xlint/lint1/lint1.h       Mon Jun 28 07:55:05 2021 +0000
+++ b/usr.bin/xlint/lint1/lint1.h       Mon Jun 28 08:52:55 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: lint1.h,v 1.107 2021/06/27 20:47:13 rillig Exp $ */
+/* $NetBSD: lint1.h,v 1.108 2021/06/28 08:52:55 rillig Exp $ */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
@@ -374,16 +374,13 @@
        struct  dinfo *d_next;  /* next level */
 } dinfo_t;
 
-/*
- * Used to collect information about pointers and qualifiers in
- * declarators.
- */
-typedef        struct pqinf {
-       bool    p_pointer: 1;
+/* One level of pointer indirection in declarators, including qualifiers. */
+typedef        struct qual_ptr {
        bool    p_const: 1;
        bool    p_volatile: 1;
-       struct  pqinf *p_next;
-} pqinf_t;
+       bool    p_pointer: 1;
+       struct  qual_ptr *p_next;
+} qual_ptr;
 
 /*
  * The values of the 'case' labels, linked via cl_next in reverse order of



Home | Main Index | Thread Index | Old Index