diff options
| author | rillig <rillig@NetBSD.org> | 2023-07-06 07:59:00 +0000 |
|---|---|---|
| committer | rillig <rillig@NetBSD.org> | 2023-07-06 07:59:00 +0000 |
| commit | 52bf4f6baab2ede81016e6c10a11509f70255704 (patch) | |
| tree | 686a4fdedb4b0a3384d8d2f51ef2f372aa6451f3 /usr.bin | |
| parent | 96de2b0706056804ef3f627e5b6e1026793cd27d (diff) | |
lint: add type safety for accessing properties of basic types
No functional change.
Diffstat (limited to 'usr.bin')
| -rw-r--r-- | usr.bin/xlint/common/externs.h | 6 | ||||
| -rw-r--r-- | usr.bin/xlint/common/lint.h | 33 |
2 files changed, 23 insertions, 16 deletions
diff --git a/usr.bin/xlint/common/externs.h b/usr.bin/xlint/common/externs.h index 191909ac8b3..8c505c9b57c 100644 --- a/usr.bin/xlint/common/externs.h +++ b/usr.bin/xlint/common/externs.h @@ -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 --git a/usr.bin/xlint/common/lint.h b/usr.bin/xlint/common/lint.h index 6b0871a97f7..6c7c537f377 100644 --- a/usr.bin/xlint/common/lint.h +++ b/usr.bin/xlint/common/lint.h @@ -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" |
