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