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