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: split complete_tag into separate f...



details:   https://anonhg.NetBSD.org/src/rev/a85c12277685
branches:  trunk
changeset: 979476:a85c12277685
user:      rillig <rillig%NetBSD.org@localhost>
date:      Tue Dec 29 17:29:31 2020 +0000

description:
lint: split complete_tag into separate functions

diffstat:

 usr.bin/xlint/lint1/cgram.y    |  12 ++--
 usr.bin/xlint/lint1/decl.c     |  86 ++++++++++++++++++++++-------------------
 usr.bin/xlint/lint1/externs1.h |   5 +-
 3 files changed, 55 insertions(+), 48 deletions(-)

diffs (189 lines):

diff -r 2fe7916e058b -r a85c12277685 usr.bin/xlint/lint1/cgram.y
--- a/usr.bin/xlint/lint1/cgram.y       Tue Dec 29 17:17:14 2020 +0000
+++ b/usr.bin/xlint/lint1/cgram.y       Tue Dec 29 17:29:31 2020 +0000
@@ -1,5 +1,5 @@
 %{
-/* $NetBSD: cgram.y,v 1.115 2020/12/29 16:48:53 rillig Exp $ */
+/* $NetBSD: cgram.y,v 1.116 2020/12/29 17:29:31 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.115 2020/12/29 16:48:53 rillig Exp $");
+__RCSID("$NetBSD: cgram.y,v 1.116 2020/12/29 17:29:31 rillig Exp $");
 #endif
 
 #include <limits.h>
@@ -705,12 +705,12 @@
        | struct struct_tag {
                dcs->d_tagtyp = mktag($2, $1, 1, 0);
          } struct_declaration {
-               $$ = complete_tag(dcs->d_tagtyp, $4);
+               $$ = complete_tag_struct_or_union(dcs->d_tagtyp, $4);
          }
        | struct {
                dcs->d_tagtyp = mktag(NULL, $1, 1, 0);
          } struct_declaration {
-               $$ = complete_tag(dcs->d_tagtyp, $3);
+               $$ = complete_tag_struct_or_union(dcs->d_tagtyp, $3);
          }
        | struct error {
                symtyp = FVFT;
@@ -901,12 +901,12 @@
        | enum enum_tag {
                dcs->d_tagtyp = mktag($2, ENUM, 1, 0);
          } enum_declaration {
-               $$ = complete_tag(dcs->d_tagtyp, $4);
+               $$ = complete_tag_enum(dcs->d_tagtyp, $4);
          }
        | enum {
                dcs->d_tagtyp = mktag(NULL, ENUM, 1, 0);
          } enum_declaration {
-               $$ = complete_tag(dcs->d_tagtyp, $3);
+               $$ = complete_tag_enum(dcs->d_tagtyp, $3);
          }
        | enum error {
                symtyp = FVFT;
diff -r 2fe7916e058b -r a85c12277685 usr.bin/xlint/lint1/decl.c
--- a/usr.bin/xlint/lint1/decl.c        Tue Dec 29 17:17:14 2020 +0000
+++ b/usr.bin/xlint/lint1/decl.c        Tue Dec 29 17:29:31 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: decl.c,v 1.77 2020/12/29 13:33:03 rillig Exp $ */
+/* $NetBSD: decl.c,v 1.78 2020/12/29 17:29:31 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.77 2020/12/29 13:33:03 rillig Exp $");
+__RCSID("$NetBSD: decl.c,v 1.78 2020/12/29 17:29:31 rillig Exp $");
 #endif
 
 #include <sys/param.h>
@@ -1773,10 +1773,10 @@
 }
 
 /*
- * tp points to the type of the tag, fmem to the list of members/enums.
+ * tp points to the type of the tag, fmem to the list of members.
  */
 type_t *
-complete_tag(type_t *tp, sym_t *fmem)
+complete_tag_struct_or_union(type_t *tp, sym_t *fmem)
 {
        tspec_t t;
        str_t   *sp;
@@ -1785,47 +1785,53 @@
 
        setcomplete(tp, 1);
 
-       if ((t = tp->t_tspec) != ENUM) {
-               align(dcs->d_stralign, 0);
-               sp = tp->t_str;
-               sp->align = dcs->d_stralign;
-               sp->memb = fmem;
-               if (tp->t_ispacked)
-                       setpackedsize(tp);
-               else
-                       sp->size = dcs->d_offset;
-
-               if (sp->size == 0) {
-                       /* zero sized %s */
-                       (void)c99ism(47, ttab[t].tt_name);
+       t = tp->t_tspec;
+       align(dcs->d_stralign, 0);
+       sp = tp->t_str;
+       sp->align = dcs->d_stralign;
+       sp->memb = fmem;
+       if (tp->t_ispacked)
+               setpackedsize(tp);
+       else
+               sp->size = dcs->d_offset;
+
+       if (sp->size == 0) {
+               /* zero sized %s */
+               (void)c99ism(47, ttab[t].tt_name);
+       }
+
+       n = 0;
+       for (mem = fmem; mem != NULL; mem = mem->s_nxt) {
+               /* bind anonymous members to the structure */
+               if (mem->s_styp == NULL) {
+                       mem->s_styp = sp;
+                       if (mem->s_type->t_isfield) {
+                               sp->size += bitfieldsize(&mem);
+                               if (mem == NULL)
+                                       break;
+                       }
+                       sp->size += tsize(mem->s_type);
                }
-
-               n = 0;
-               for (mem = fmem; mem != NULL; mem = mem->s_nxt) {
-                       /* bind anonymous members to the structure */
-                       if (mem->s_styp == NULL) {
-                               mem->s_styp = sp;
-                               if (mem->s_type->t_isfield) {
-                                       sp->size += bitfieldsize(&mem);
-                                       if (mem == NULL)
-                                               break;
-                               }
-                               sp->size += tsize(mem->s_type);
-                       }
-                       if (mem->s_name != unnamed)
-                               n++;
-               }
-
-               if (n == 0 && sp->size != 0) {
-                       /* %s has no named members */
-                       warning(65, t == STRUCT ? "structure" : "union");
-               }
-       } else {
-               tp->t_enum->elem = fmem;
+               if (mem->s_name != unnamed)
+                       n++;
+       }
+
+       if (n == 0 && sp->size != 0) {
+               /* %s has no named members */
+               warning(65, t == STRUCT ? "structure" : "union");
        }
        return tp;
 }
 
+type_t *
+complete_tag_enum(type_t *tp, sym_t *fmem)
+{
+
+       setcomplete(tp, 1);
+       tp->t_enum->elem = fmem;
+       return tp;
+}
+
 /*
  * Processes the name of an enumerator in an enum declaration.
  *
diff -r 2fe7916e058b -r a85c12277685 usr.bin/xlint/lint1/externs1.h
--- a/usr.bin/xlint/lint1/externs1.h    Tue Dec 29 17:17:14 2020 +0000
+++ b/usr.bin/xlint/lint1/externs1.h    Tue Dec 29 17:29:31 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: externs1.h,v 1.39 2020/12/29 16:48:53 rillig Exp $     */
+/*     $NetBSD: externs1.h,v 1.40 2020/12/29 17:29:31 rillig Exp $     */
 
 /*
  * Copyright (c) 1994, 1995 Jochen Pohl
@@ -166,7 +166,8 @@
 extern sym_t   *old_style_function_name(sym_t *);
 extern type_t  *mktag(sym_t *, tspec_t, int, int);
 extern const   char *storage_class_name(scl_t);
-extern type_t  *complete_tag(type_t *, sym_t *);
+extern type_t  *complete_tag_struct_or_union(type_t *, sym_t *);
+extern type_t  *complete_tag_enum(type_t *, sym_t *);
 extern sym_t   *ename(sym_t *, int, int);
 extern void    decl1ext(sym_t *, int);
 extern void    copy_usage_info(sym_t *, sym_t *);



Home | Main Index | Thread Index | Old Index