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