1 /* $NetBSD: lint.h,v 1.35 2022/02/07 21:57:47 rillig Exp $ */ 2 3 /* 4 * Copyright (c) 1994, 1995 Jochen Pohl 5 * All Rights Reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 1. Redistributions of source code must retain the above copyright 11 * notice, this list of conditions and the following disclaimer. 12 * 2. Redistributions in binary form must reproduce the above copyright 13 * notice, this list of conditions and the following disclaimer in the 14 * documentation and/or other materials provided with the distribution. 15 * 3. All advertising materials mentioning features or use of this software 16 * must display the following acknowledgement: 17 * This product includes software developed by Jochen Pohl for 18 * The NetBSD Project. 19 * 4. The name of the author may not be used to endorse or promote products 20 * derived from this software without specific prior written permission. 21 * 22 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 23 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 24 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 25 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 26 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 27 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 31 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 */ 33 34 #if HAVE_NBTOOL_CONFIG_H 35 #include "nbtool_config.h" 36 #else 37 #define HAVE_DECL_SYS_SIGNAME 1 38 #endif 39 40 #include <sys/types.h> 41 #include <ctype.h> 42 #include <err.h> 43 #include <inttypes.h> 44 #include <stdbool.h> 45 #include <stddef.h> 46 #include <stdio.h> 47 48 #include "param.h" 49 50 /* 51 * Type specifiers, used in type structures (type_t) and elsewhere. 52 */ 53 typedef enum { 54 NOTSPEC = 0, 55 SIGNED, /* keyword "signed", only used in the parser */ 56 UNSIGN, /* keyword "unsigned", only used in the parser */ 57 BOOL, /* _Bool */ 58 CHAR, /* char */ 59 SCHAR, /* signed char */ 60 UCHAR, /* unsigned char */ 61 SHORT, /* (signed) short */ 62 USHORT, /* unsigned short */ 63 INT, /* (signed) int */ 64 UINT, /* unsigned int */ 65 LONG, /* (signed) long */ 66 ULONG, /* unsigned long */ 67 QUAD, /* (signed) long long */ 68 UQUAD, /* unsigned long long */ 69 #ifdef INT128_SIZE 70 INT128, /* (signed) __int128_t */ 71 UINT128, /* __uint128_t */ 72 #endif 73 FLOAT, /* float */ 74 DOUBLE, /* double or, with tflag, long float */ 75 LDOUBLE, /* long double */ 76 VOID, /* void */ 77 STRUCT, /* structure tag */ 78 UNION, /* union tag */ 79 ENUM, /* enum tag */ 80 PTR, /* pointer */ 81 ARRAY, /* array */ 82 FUNC, /* function */ 83 COMPLEX, /* keyword "_Complex", only used in the parser */ 84 FCOMPLEX, /* float _Complex */ 85 DCOMPLEX, /* double _Complex */ 86 LCOMPLEX /* long double _Complex */ 87 #define NTSPEC (LCOMPLEX + 1) 88 } tspec_t; 89 90 91 /* 92 * size of types, name and classification 93 */ 94 typedef struct { 95 #ifdef IS_LINT1 96 unsigned int tt_size_in_bits; 97 unsigned int tt_portable_size_in_bits; /* different from 98 * tt_size_in_bits if pflag is set */ 99 #endif 100 tspec_t tt_signed_counterpart; 101 tspec_t tt_unsigned_counterpart; 102 bool tt_is_integer:1; /* integer type */ 103 #ifdef IS_LINT1 104 bool tt_is_uinteger:1; /* unsigned integer type */ 105 bool tt_is_floating:1; /* floating point type */ 106 bool tt_is_arithmetic:1; /* arithmetic type */ 107 bool tt_is_scalar:1; /* scalar type */ 108 bool tt_is_complex:1; /* complex type */ 109 #endif 110 const char *tt_name; /* name of the type */ 111 } ttab_t; 112 113 #define size_in_bits(t) (ttab[t].tt_size_in_bits) 114 #define portable_size_in_bits(t) (ttab[t].tt_portable_size_in_bits) 115 #define signed_type(t) (ttab[t].tt_signed_counterpart) 116 #define unsigned_type(t) (ttab[t].tt_unsigned_counterpart) 117 #define is_integer(t) (ttab[t].tt_is_integer) 118 #define is_uinteger(t) (ttab[t].tt_is_uinteger) 119 #define is_floating(t) (ttab[t].tt_is_floating) 120 #define is_arithmetic(t) (ttab[t].tt_is_arithmetic) 121 #define is_complex(t) (ttab[t].tt_is_complex) 122 #define is_scalar(t) (ttab[t].tt_is_scalar) 123 124 #if defined(IS_LINT1) || defined(IS_LINT2) 125 extern ttab_t ttab[]; 126 #endif 127 128 129 typedef enum { 130 NODECL, /* not declared until now */ 131 DECL, /* declared */ 132 TDEF, /* tentative defined */ 133 DEF /* defined */ 134 } def_t; 135 136 /* Some data used for the output buffer. */ 137 typedef struct ob { 138 char *o_buf; /* buffer */ 139 char *o_end; /* first byte after buffer */ 140 size_t o_len; /* length of buffer */ 141 char *o_next; /* next free byte in buffer */ 142 } ob_t; 143 144 #if defined(IS_LINT1) 145 typedef struct lint1_type type_t; 146 #else 147 typedef struct lint2_type type_t; 148 #endif 149 150 #include "externs.h" 151 152 static inline bool 153 ch_isalnum(char ch) { return isalnum((unsigned char)ch) != 0; } 154 static inline bool 155 ch_isdigit(char ch) { return isdigit((unsigned char)ch) != 0; } 156 static inline bool 157 ch_isprint(char ch) { return isprint((unsigned char)ch) != 0; } 158 static inline bool 159 ch_isspace(char ch) { return isspace((unsigned char)ch) != 0; } 160 static inline bool 161 ch_isupper(char ch) { return isupper((unsigned char)ch) != 0; } 162