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