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: reduce verbose switch statement to...



details:   https://anonhg.NetBSD.org/src/rev/6f7aedcbd6db
branches:  trunk
changeset: 1023282:6f7aedcbd6db
user:      rillig <rillig%NetBSD.org@localhost>
date:      Tue Aug 31 23:10:52 2021 +0000

description:
lint: reduce verbose switch statement to table lookup

No functional change.

diffstat:

 usr.bin/xlint/lint1/emit1.c |  54 +++++++++++++-------------------------------
 1 files changed, 16 insertions(+), 38 deletions(-)

diffs (85 lines):

diff -r 39ea5516875f -r 6f7aedcbd6db usr.bin/xlint/lint1/emit1.c
--- a/usr.bin/xlint/lint1/emit1.c       Tue Aug 31 19:34:42 2021 +0000
+++ b/usr.bin/xlint/lint1/emit1.c       Tue Aug 31 23:10:52 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: emit1.c,v 1.52 2021/08/30 19:48:21 rillig Exp $ */
+/* $NetBSD: emit1.c,v 1.53 2021/08/31 23:10: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: emit1.c,v 1.52 2021/08/30 19:48:21 rillig Exp $");
+__RCSID("$NetBSD: emit1.c,v 1.53 2021/08/31 23:10:52 rillig Exp $");
 #endif
 
 #include "lint1.h"
@@ -92,52 +92,30 @@
 void
 outtype(const type_t *tp)
 {
-       int     t, s, na;
+       /* Available letters: ------GH--K-MNO--R--U-W-YZ */
+#ifdef INT128_SIZE
+       static const char tt[NTSPEC] = "???BCCCSSIILLQQJJDDDVTTTPAF?XXX";
+       static const char ss[NTSPEC] = "???  su u u u u us l sue   ?s l";
+#else
+       static const char tt[NTSPEC] = "???BCCCSSIILLQQDDDVTTTPAF?XXX";
+       static const char ss[NTSPEC] = "???  su u u u us l sue   ?s l";
+#endif
+       char    t, s;
+       int     na;
        sym_t   *arg;
        tspec_t ts;
 
        while (tp != NULL) {
                if ((ts = tp->t_tspec) == INT && tp->t_is_enum)
                        ts = ENUM;
-               /* Available letters: ------GH--K-MNO--R--U-W-YZ */
-               switch (ts) {
-               case BOOL:      t = 'B';        s = '\0';       break;
-               case CHAR:      t = 'C';        s = '\0';       break;
-               case SCHAR:     t = 'C';        s = 's';        break;
-               case UCHAR:     t = 'C';        s = 'u';        break;
-               case SHORT:     t = 'S';        s = '\0';       break;
-               case USHORT:    t = 'S';        s = 'u';        break;
-               case INT:       t = 'I';        s = '\0';       break;
-               case UINT:      t = 'I';        s = 'u';        break;
-               case LONG:      t = 'L';        s = '\0';       break;
-               case ULONG:     t = 'L';        s = 'u';        break;
-               case QUAD:      t = 'Q';        s = '\0';       break;
-               case UQUAD:     t = 'Q';        s = 'u';        break;
-#ifdef INT128_SIZE
-               case INT128:    t = 'J';        s = '\0';       break;
-               case UINT128:   t = 'J';        s = 'u';        break;
-#endif
-               case FLOAT:     t = 'D';        s = 's';        break;
-               case DOUBLE:    t = 'D';        s = '\0';       break;
-               case LDOUBLE:   t = 'D';        s = 'l';        break;
-               case VOID:      t = 'V';        s = '\0';       break;
-               case STRUCT:    t = 'T';        s = 's';        break;
-               case UNION:     t = 'T';        s = 'u';        break;
-               case ENUM:      t = 'T';        s = 'e';        break;
-               case PTR:       t = 'P';        s = '\0';       break;
-               case ARRAY:     t = 'A';        s = '\0';       break;
-               case FUNC:      t = 'F';        s = '\0';       break;
-               case FCOMPLEX:  t = 'X';        s = 's';        break;
-               case DCOMPLEX:  t = 'X';        s = '\0';       break;
-               case LCOMPLEX:  t = 'X';        s = 'l';        break;
-               default:
-                       lint_assert(/*CONSTCOND*/false);
-               }
+               t = tt[ts];
+               s = ss[ts];
+               lint_assert(t != '?' && t != '?');
                if (tp->t_const)
                        outchar('c');
                if (tp->t_volatile)
                        outchar('v');
-               if (s != '\0')
+               if (s != ' ')
                        outchar(s);
                outchar(t);
                if (ts == ARRAY) {



Home | Main Index | Thread Index | Old Index