Module Name: src
Committed By: rillig
Date: Thu Jul 6 07:59:00 UTC 2023
Modified Files:
src/usr.bin/xlint/common: externs.h lint.h
Log Message:
lint: add type safety for accessing properties of basic types
No functional change.
To generate a diff of this commit:
cvs rdiff -u -r1.27 -r1.28 src/usr.bin/xlint/common/externs.h
cvs rdiff -u -r1.38 -r1.39 src/usr.bin/xlint/common/lint.h
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/usr.bin/xlint/common/externs.h
diff -u src/usr.bin/xlint/common/externs.h:1.27 src/usr.bin/xlint/common/externs.h:1.28
--- src/usr.bin/xlint/common/externs.h:1.27 Thu Jun 29 10:31:32 2023
+++ src/usr.bin/xlint/common/externs.h Thu Jul 6 07:59:00 2023
@@ -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
Index: src/usr.bin/xlint/common/lint.h
diff -u src/usr.bin/xlint/common/lint.h:1.38 src/usr.bin/xlint/common/lint.h:1.39
--- src/usr.bin/xlint/common/lint.h:1.38 Mon Jul 3 07:03:19 2023
+++ src/usr.bin/xlint/common/lint.h Thu Jul 6 07:59:00 2023
@@ -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)
-
-#if defined(IS_LINT1) || defined(IS_LINT2)
extern ttab_t ttab[];
-#endif
+
+static inline const ttab_t *
+type_properties(tspec_t t) {
+ return ttab + t;
+}
+
+#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"