inittyp.c revision 1.19 1 1.19 rillig /* $NetBSD: inittyp.c,v 1.19 2021/02/20 19:10:37 rillig Exp $ */
2 1.1 thorpej
3 1.1 thorpej /*
4 1.1 thorpej * Copyright (c) 1994, 1995 Jochen Pohl
5 1.1 thorpej * All Rights Reserved.
6 1.1 thorpej *
7 1.1 thorpej * Redistribution and use in source and binary forms, with or without
8 1.1 thorpej * modification, are permitted provided that the following conditions
9 1.1 thorpej * are met:
10 1.1 thorpej * 1. Redistributions of source code must retain the above copyright
11 1.1 thorpej * notice, this list of conditions and the following disclaimer.
12 1.1 thorpej * 2. Redistributions in binary form must reproduce the above copyright
13 1.1 thorpej * notice, this list of conditions and the following disclaimer in the
14 1.1 thorpej * documentation and/or other materials provided with the distribution.
15 1.1 thorpej * 3. All advertising materials mentioning features or use of this software
16 1.1 thorpej * must display the following acknowledgement:
17 1.1 thorpej * This product includes software developed by Jochen Pohl for
18 1.1 thorpej * The NetBSD Project.
19 1.1 thorpej * 4. The name of the author may not be used to endorse or promote products
20 1.1 thorpej * derived from this software without specific prior written permission.
21 1.1 thorpej *
22 1.1 thorpej * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
23 1.1 thorpej * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
24 1.1 thorpej * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
25 1.1 thorpej * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
26 1.1 thorpej * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
27 1.1 thorpej * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 1.1 thorpej * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 1.1 thorpej * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 1.1 thorpej * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
31 1.1 thorpej * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 1.1 thorpej */
33 1.1 thorpej
34 1.6 jmc #if HAVE_NBTOOL_CONFIG_H
35 1.6 jmc #include "nbtool_config.h"
36 1.6 jmc #endif
37 1.6 jmc
38 1.1 thorpej #include <sys/cdefs.h>
39 1.4 tv #if defined(__RCSID) && !defined(lint)
40 1.19 rillig __RCSID("$NetBSD: inittyp.c,v 1.19 2021/02/20 19:10:37 rillig Exp $");
41 1.1 thorpej #endif
42 1.1 thorpej
43 1.1 thorpej #include <limits.h>
44 1.2 tv #include <stdlib.h>
45 1.1 thorpej
46 1.1 thorpej #include "lint.h"
47 1.1 thorpej
48 1.1 thorpej /* various type information */
49 1.1 thorpej ttab_t ttab[NTSPEC];
50 1.1 thorpej
51 1.19 rillig #define INT_RSIZE (/*CONSTCOND*/INTPTR_TSPEC == LONG ? 3 : 4)
52 1.5 christos
53 1.1 thorpej void
54 1.1 thorpej inittyp(void)
55 1.1 thorpej {
56 1.11 christos size_t i;
57 1.1 thorpej static const struct {
58 1.1 thorpej tspec_t it_tspec;
59 1.1 thorpej ttab_t it_ttab;
60 1.1 thorpej } ittab[NTSPEC] = {
61 1.1 thorpej { SIGNED, { 0, 0,
62 1.1 thorpej SIGNED, UNSIGN,
63 1.9 christos 0, 0, 0, 0, 0, 0, "signed" } },
64 1.1 thorpej { UNSIGN, { 0, 0,
65 1.1 thorpej SIGNED, UNSIGN,
66 1.9 christos 0, 0, 0, 0, 0, 0, "unsigned" } },
67 1.7 yamt { BOOL, { CHAR_SIZE, 1,
68 1.7 yamt BOOL, BOOL,
69 1.9 christos 1, 1, 0, 1, 1, 0, "_Bool" } },
70 1.16 rillig { CHAR, { CHAR_SIZE, 8,
71 1.1 thorpej SCHAR, UCHAR,
72 1.9 christos 1, 0, 0, 1, 1, 0, "char" } },
73 1.16 rillig { SCHAR, { CHAR_SIZE, 8,
74 1.1 thorpej SCHAR, UCHAR,
75 1.9 christos 1, 0, 0, 1, 1, 0, "signed char" } },
76 1.16 rillig { UCHAR, { CHAR_SIZE, 8,
77 1.1 thorpej SCHAR, UCHAR,
78 1.9 christos 1, 1, 0, 1, 1, 0, "unsigned char" } },
79 1.16 rillig { SHORT, { SHORT_SIZE, 16,
80 1.1 thorpej SHORT, USHORT,
81 1.9 christos 1, 0, 0, 1, 1, 0, "short" } },
82 1.16 rillig { USHORT, { SHORT_SIZE, 16,
83 1.1 thorpej SHORT, USHORT,
84 1.9 christos 1, 1, 0, 1, 1, 0, "unsigned short" } },
85 1.16 rillig { INT, { INT_SIZE, INT_RSIZE * 8,
86 1.1 thorpej INT, UINT,
87 1.9 christos 1, 0, 0, 1, 1, 0, "int" } },
88 1.16 rillig { UINT, { INT_SIZE, INT_RSIZE * 8,
89 1.1 thorpej INT, UINT,
90 1.9 christos 1, 1, 0, 1, 1, 0, "unsigned int" } },
91 1.16 rillig { LONG, { LONG_SIZE, 32,
92 1.1 thorpej LONG, ULONG,
93 1.9 christos 1, 0, 0, 1, 1, 0, "long" } },
94 1.16 rillig { ULONG, { LONG_SIZE, 32,
95 1.1 thorpej LONG, ULONG,
96 1.9 christos 1, 1, 0, 1, 1, 0, "unsigned long" } },
97 1.16 rillig { QUAD, { QUAD_SIZE, 64,
98 1.1 thorpej QUAD, UQUAD,
99 1.9 christos 1, 0, 0, 1, 1, 0, "long long" } },
100 1.16 rillig { UQUAD, { QUAD_SIZE, 64,
101 1.1 thorpej QUAD, UQUAD,
102 1.9 christos 1, 1, 0, 1, 1, 0, "unsigned long long" } },
103 1.12 christos #ifdef INT128_SIZE
104 1.16 rillig { INT128, { INT128_SIZE, 128,
105 1.12 christos INT128, UINT128,
106 1.12 christos 1, 0, 0, 1, 1, 0, "__int128_t" } },
107 1.16 rillig { UINT128, { INT128_SIZE, 128,
108 1.12 christos INT128, UINT128,
109 1.12 christos 1, 1, 0, 1, 1, 0, "__uint128_t" } },
110 1.12 christos #endif
111 1.12 christos
112 1.16 rillig { FLOAT, { FLOAT_SIZE, 32,
113 1.1 thorpej FLOAT, FLOAT,
114 1.9 christos 0, 0, 1, 1, 1, 0, "float" } },
115 1.16 rillig { DOUBLE, { DOUBLE_SIZE, 64,
116 1.1 thorpej DOUBLE, DOUBLE,
117 1.9 christos 0, 0, 1, 1, 1, 0, "double" } },
118 1.16 rillig { LDOUBLE, { LDOUBLE_SIZE, 80,
119 1.1 thorpej LDOUBLE, LDOUBLE,
120 1.9 christos 0, 0, 1, 1, 1, 0, "long double" } },
121 1.16 rillig { FCOMPLEX, { FLOAT_SIZE * 2, 32 * 2,
122 1.9 christos FCOMPLEX, FCOMPLEX,
123 1.9 christos 0, 0, 1, 1, 1, 1, "float _Complex" } },
124 1.16 rillig { DCOMPLEX, { DOUBLE_SIZE * 2, 64 * 2,
125 1.9 christos DCOMPLEX, DCOMPLEX,
126 1.9 christos 0, 0, 1, 1, 1, 1, "double _Complex" } },
127 1.16 rillig /*
128 1.16 rillig * XXX: with -p, LCOMPLEX.tt_psz != 2 * LDOUBLE.tt_psz.
129 1.16 rillig * This may or may not have been intentional.
130 1.16 rillig */
131 1.16 rillig { LCOMPLEX, { LDOUBLE_SIZE * 2, 64 * 2,
132 1.10 matt LCOMPLEX, LCOMPLEX,
133 1.10 matt 0, 0, 1, 1, 1, 1, "long double _Complex" } },
134 1.1 thorpej { VOID, { -1, -1,
135 1.1 thorpej VOID, VOID,
136 1.9 christos 0, 0, 0, 0, 0, 0, "void" } },
137 1.1 thorpej { STRUCT, { -1, -1,
138 1.1 thorpej STRUCT, STRUCT,
139 1.9 christos 0, 0, 0, 0, 0, 0, "struct" } },
140 1.1 thorpej { UNION, { -1, -1,
141 1.1 thorpej UNION, UNION,
142 1.9 christos 0, 0, 0, 0, 0, 0, "union" } },
143 1.16 rillig { ENUM, { ENUM_SIZE, 24,
144 1.1 thorpej ENUM, ENUM,
145 1.9 christos 1, 0, 0, 1, 1, 0, "enum" } },
146 1.16 rillig { PTR, { PTR_SIZE, 32,
147 1.1 thorpej PTR, PTR,
148 1.9 christos 0, 1, 0, 0, 1, 0, "pointer" } },
149 1.1 thorpej { ARRAY, { -1, -1,
150 1.1 thorpej ARRAY, ARRAY,
151 1.9 christos 0, 0, 0, 0, 0, 0, "array" } },
152 1.1 thorpej { FUNC, { -1, -1,
153 1.1 thorpej FUNC, FUNC,
154 1.9 christos 0, 0, 0, 0, 0, 0, "function" } },
155 1.1 thorpej };
156 1.1 thorpej
157 1.1 thorpej for (i = 0; i < sizeof (ittab) / sizeof (ittab[0]); i++)
158 1.13 rillig ttab[ittab[i].it_tspec] = ittab[i].it_ttab;
159 1.1 thorpej if (!pflag) {
160 1.1 thorpej for (i = 0; i < NTSPEC; i++)
161 1.1 thorpej ttab[i].tt_psz = ttab[i].tt_sz;
162 1.1 thorpej }
163 1.17 rillig if (Tflag) {
164 1.17 rillig ttab[BOOL].tt_is_integer = false;
165 1.17 rillig ttab[BOOL].tt_is_uinteger = false;
166 1.17 rillig ttab[BOOL].tt_is_arithmetic = false;
167 1.17 rillig }
168 1.1 thorpej }
169