inittyp.c revision 1.24 1 /* $NetBSD: inittyp.c,v 1.24 2021/06/30 10:56:24 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 #endif
37
38 #include <sys/cdefs.h>
39 #if defined(__RCSID) && !defined(lint)
40 __RCSID("$NetBSD: inittyp.c,v 1.24 2021/06/30 10:56:24 rillig Exp $");
41 #endif
42
43 #include <limits.h>
44 #include <stdlib.h>
45
46 #include "lint.h"
47
48 /* various type information */
49 ttab_t ttab[NTSPEC];
50
51 #define INT_RSIZE (/*CONSTCOND*/INTPTR_TSPEC == LONG ? 3 : 4)
52
53 void
54 inittyp(void)
55 {
56 size_t i;
57 static const struct {
58 tspec_t it_tspec;
59 ttab_t it_ttab;
60 } ittab[NTSPEC] = {
61 #define typeinfo( \
62 tspec, signed_type, unsigned_type, \
63 size_in_bits, portable_size_in_bits, \
64 in, un, fl, ar, sc, co, name) \
65 { \
66 tspec, { \
67 size_in_bits, portable_size_in_bits, \
68 signed_type, unsigned_type, \
69 (in) > 0, (un) > 0, (fl) > 0, (ar) > 0, (sc) > 0, (co) > 0, \
70 name, \
71 } \
72 }
73 typeinfo(SIGNED, SIGNED, UNSIGN, 0, 0,
74 0, 0, 0, 0, 0, 0, "signed"),
75 typeinfo(UNSIGN, SIGNED, UNSIGN, 0, 0,
76 0, 0, 0, 0, 0, 0, "unsigned"),
77 typeinfo(BOOL, BOOL, BOOL, CHAR_SIZE, 1,
78 1, 1, 0, 1, 1, 0, "_Bool"),
79 typeinfo(CHAR, SCHAR, UCHAR, CHAR_SIZE, 8,
80 1, /*CONSTCOND*/ TARG_CHAR_MIN == 0 ? 1 : 0,
81 /* */ 0, 1, 1, 0, "char"),
82 typeinfo(SCHAR, SCHAR, UCHAR, CHAR_SIZE, 8,
83 1, 0, 0, 1, 1, 0, "signed char"),
84 typeinfo(UCHAR, SCHAR, UCHAR, CHAR_SIZE, 8,
85 1, 1, 0, 1, 1, 0, "unsigned char"),
86 typeinfo(SHORT, SHORT, USHORT, SHORT_SIZE, 16,
87 1, 0, 0, 1, 1, 0, "short"),
88 typeinfo(USHORT, SHORT, USHORT, SHORT_SIZE, 16,
89 1, 1, 0, 1, 1, 0, "unsigned short"),
90 typeinfo(INT, INT, UINT, INT_SIZE, INT_RSIZE * 8,
91 1, 0, 0, 1, 1, 0, "int"),
92 typeinfo(UINT, INT, UINT, INT_SIZE, INT_RSIZE * 8,
93 1, 1, 0, 1, 1, 0, "unsigned int"),
94 typeinfo(LONG, LONG, ULONG, LONG_SIZE, 32,
95 1, 0, 0, 1, 1, 0, "long"),
96 typeinfo(ULONG, LONG, ULONG, LONG_SIZE, 32,
97 1, 1, 0, 1, 1, 0, "unsigned long"),
98 typeinfo(QUAD, QUAD, UQUAD, QUAD_SIZE, 64,
99 1, 0, 0, 1, 1, 0, "long long"),
100 typeinfo(UQUAD, QUAD, UQUAD, QUAD_SIZE, 64,
101 1, 1, 0, 1, 1, 0, "unsigned long long"),
102 #ifdef INT128_SIZE
103 typeinfo(INT128, INT128, UINT128, INT128_SIZE, 128,
104 1, 0, 0, 1, 1, 0, "__int128_t"),
105 typeinfo(UINT128, INT128, UINT128, INT128_SIZE, 128,
106 1, 1, 0, 1, 1, 0, "__uint128_t"),
107 #endif
108 typeinfo(FLOAT, FLOAT, FLOAT, FLOAT_SIZE, 32,
109 0, 0, 1, 1, 1, 0, "float"),
110 typeinfo(DOUBLE, DOUBLE, DOUBLE, DOUBLE_SIZE, 64,
111 0, 0, 1, 1, 1, 0, "double"),
112 typeinfo(LDOUBLE, LDOUBLE, LDOUBLE, LDOUBLE_SIZE, 80,
113 0, 0, 1, 1, 1, 0, "long double"),
114 typeinfo(FCOMPLEX, FCOMPLEX, FCOMPLEX, FLOAT_SIZE * 2, 32 * 2,
115 0, 0, 1, 1, 1, 1, "float _Complex"),
116 typeinfo(DCOMPLEX, DCOMPLEX, DCOMPLEX, DOUBLE_SIZE * 2, 64 * 2,
117 0, 0, 1, 1, 1, 1, "double _Complex"),
118 typeinfo(LCOMPLEX, LCOMPLEX, LCOMPLEX,
119 LDOUBLE_SIZE * 2, 80 * 2,
120 0, 0, 1, 1, 1, 1, "long double _Complex"),
121 typeinfo(VOID, VOID, VOID, -1, -1,
122 0, 0, 0, 0, 0, 0, "void"),
123 typeinfo(STRUCT, STRUCT, STRUCT, -1, -1,
124 0, 0, 0, 0, 0, 0, "struct"),
125 typeinfo(UNION, UNION, UNION, -1, -1,
126 0, 0, 0, 0, 0, 0, "union"),
127 typeinfo(ENUM, ENUM, ENUM, ENUM_SIZE, 24,
128 1, 0, 0, 1, 1, 0, "enum"),
129 typeinfo(PTR, PTR, PTR, PTR_SIZE, 32,
130 0, 1, 0, 0, 1, 0, "pointer"),
131 typeinfo(ARRAY, ARRAY, ARRAY, -1, -1,
132 0, 0, 0, 0, 0, 0, "array"),
133 typeinfo(FUNC, FUNC, FUNC, -1, -1,
134 0, 0, 0, 0, 0, 0, "function"),
135 #undef typeinfo
136 };
137
138 for (i = 0; i < sizeof(ittab) / sizeof(ittab[0]); i++)
139 ttab[ittab[i].it_tspec] = ittab[i].it_ttab;
140 if (!pflag) {
141 for (i = 0; i < NTSPEC; i++)
142 ttab[i].tt_portable_size_in_bits =
143 ttab[i].tt_size_in_bits;
144 }
145 if (Tflag) {
146 ttab[BOOL].tt_is_integer = false;
147 ttab[BOOL].tt_is_uinteger = false;
148 ttab[BOOL].tt_is_arithmetic = false;
149 }
150 }
151