Source-Changes-HG archive

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

[src/trunk]: src/usr.bin/xlint/common lint: add type safety for accessing pro...



details:   https://anonhg.NetBSD.org/src/rev/8475a93247e9
branches:  trunk
changeset: 377304:8475a93247e9
user:      rillig <rillig%NetBSD.org@localhost>
date:      Thu Jul 06 07:59:00 2023 +0000

description:
lint: add type safety for accessing properties of basic types

No functional change.

diffstat:

 usr.bin/xlint/common/externs.h |   6 ++++--
 usr.bin/xlint/common/lint.h    |  33 +++++++++++++++++++--------------
 2 files changed, 23 insertions(+), 16 deletions(-)

diffs (83 lines):

diff -r d966d6b8894b -r 8475a93247e9 usr.bin/xlint/common/externs.h
--- a/usr.bin/xlint/common/externs.h    Thu Jul 06 07:33:36 2023 +0000
+++ b/usr.bin/xlint/common/externs.h    Thu Jul 06 07:59:00 2023 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: externs.h,v 1.27 2023/06/29 10:31:32 rillig Exp $      */
+/*     $NetBSD: externs.h,v 1.28 2023/07/06 07:59:00 rillig Exp $      */
 
 /*
  * Copyright (c) 1994, 1995 Jochen Pohl
@@ -34,8 +34,10 @@
 /*
  * tyname.c
  */
+#if defined(IS_LINT1) || defined(IS_LINT2)
 const char *type_name(const type_t *);
-const  char *tspec_name(tspec_t);
+const char *tspec_name(tspec_t);
+#endif
 
 /*
  * mem.c
diff -r d966d6b8894b -r 8475a93247e9 usr.bin/xlint/common/lint.h
--- a/usr.bin/xlint/common/lint.h       Thu Jul 06 07:33:36 2023 +0000
+++ b/usr.bin/xlint/common/lint.h       Thu Jul 06 07:59:00 2023 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: lint.h,v 1.38 2023/07/03 07:03:19 rillig Exp $ */
+/*     $NetBSD: lint.h,v 1.39 2023/07/06 07:59:00 rillig Exp $ */
 
 /*
  * Copyright (c) 1994, 1995 Jochen Pohl
@@ -47,6 +47,7 @@
 
 #include "param.h"
 
+#if defined(IS_LINT1) || defined(IS_LINT2)
 /*
  * Type specifiers, used in type structures (type_t) and elsewhere.
  */
@@ -110,20 +111,23 @@ typedef   struct {
        const char *tt_name;            /* name of the type */
 } ttab_t;
 
-#define size_in_bits(t)                (ttab[t].tt_size_in_bits)
-#define portable_size_in_bits(t) (ttab[t].tt_portable_size_in_bits)
-#define signed_type(t)         (ttab[t].tt_signed_counterpart)
-#define unsigned_type(t)       (ttab[t].tt_unsigned_counterpart)
-#define is_integer(t)          (ttab[t].tt_is_integer)
-#define is_uinteger(t)         (ttab[t].tt_is_uinteger)
-#define is_floating(t)         (ttab[t].tt_is_floating)
-#define is_arithmetic(t)       (ttab[t].tt_is_arithmetic)
-#define is_complex(t)          (ttab[t].tt_is_complex)
-#define is_scalar(t)           (ttab[t].tt_is_scalar)
+extern ttab_t  ttab[];
+
+static inline const ttab_t *
+type_properties(tspec_t t) {
+       return ttab + t;
+}
 
-#if defined(IS_LINT1) || defined(IS_LINT2)
-extern ttab_t  ttab[];
-#endif
+#define size_in_bits(t)                (type_properties(t)->tt_size_in_bits)
+#define portable_size_in_bits(t) (type_properties(t)->tt_portable_size_in_bits)
+#define signed_type(t)         (type_properties(t)->tt_signed_counterpart)
+#define unsigned_type(t)       (type_properties(t)->tt_unsigned_counterpart)
+#define is_integer(t)          (type_properties(t)->tt_is_integer)
+#define is_uinteger(t)         (type_properties(t)->tt_is_uinteger)
+#define is_floating(t)         (type_properties(t)->tt_is_floating)
+#define is_arithmetic(t)       (type_properties(t)->tt_is_arithmetic)
+#define is_complex(t)          (type_properties(t)->tt_is_complex)
+#define is_scalar(t)           (type_properties(t)->tt_is_scalar)
 
 
 typedef        enum {
@@ -146,6 +150,7 @@ typedef struct lint1_type type_t;
 #else
 typedef struct lint2_type type_t;
 #endif
+#endif
 
 #include "externs.h"
 



Home | Main Index | Thread Index | Old Index