1/*	$NetBSD: inittyp.c,v 1.42 2024/01/20 10:25:57 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.42 2024/01/20 10:25:57 rillig Exp $");
41#endif
42
43#if IS_LINT1
44#include "lint1.h"
45#else
46#include "lint2.h"
47#endif
48
49#define INT_RANK	(/*CONSTCOND*/INTPTR_TSPEC == LONG ? 4 : 5)
50
51#if IS_LINT1
52#define typeinfo(name, signed_type, unsigned_type, size_in_bits, rv, c) \
53	{ /*CONSTCOND*/ \
54		size_in_bits, \
55		(c) == 'u' || (c) == 's' || (c) == 'p' ? RK_INTEGER : \
56		    (c) == 'f' ? RK_FLOATING : \
57		    (c) == 'c' ? RK_COMPLEX : \
58		    RK_NONE, \
59		rv, \
60		signed_type, unsigned_type, \
61		(c) == 's' || (c) == 'u', \
62		(c) == 'u' || (c) == 'p', \
63		(c) == 'f' || (c) == 'c', \
64		(c) == 's' || (c) == 'u' || (c) == 'f' || \
65		    (c) == 'c', \
66		(c) == 's' || (c) == 'u' || (c) == 'f' || \
67		    (c) == 'c' || (c) == 'p', \
68		(c) == 'c', \
69		name, \
70	}
71#else
72#define typeinfo(name, signed_type, unsigned_type, size_in_bits, rank, c) \
73	{ /*CONSTCOND*/ \
74		signed_type, unsigned_type, \
75		(c) == 's' || (c) == 'u', \
76		name, \
77	}
78#endif
79
80/* various type information */
81ttab_t ttab[NTSPEC] = {
82	typeinfo(NULL, NO_TSPEC, NO_TSPEC, 0, 0, ' '),
83	typeinfo("signed", SIGNED, UNSIGN, 0, 0, ' '),
84	typeinfo("unsigned", SIGNED, UNSIGN, 0, 0, ' '),
85	typeinfo("_Bool", BOOL, BOOL, CHAR_SIZE, 1, 'u'),
86	typeinfo("char", SCHAR, UCHAR, CHAR_SIZE, 2,
87	    TARG_CHAR_MIN == 0 ? 'u' : 's'),
88	typeinfo("signed char", SCHAR, UCHAR, CHAR_SIZE, 2, 's'),
89	typeinfo("unsigned char", SCHAR, UCHAR, CHAR_SIZE, 2, 'u'),
90	typeinfo("short", SHORT, USHORT, SHORT_SIZE, 3, 's'),
91	typeinfo("unsigned short", SHORT, USHORT, SHORT_SIZE, 3, 'u'),
92	typeinfo("int", INT, UINT, INT_SIZE, INT_RANK, 's'),
93	typeinfo("unsigned int", INT, UINT, INT_SIZE, INT_RANK, 'u'),
94	typeinfo("long", LONG, ULONG, LONG_SIZE, 5, 's'),
95	typeinfo("unsigned long", LONG, ULONG, LONG_SIZE, 5, 'u'),
96	typeinfo("long long", LLONG, ULLONG, LLONG_SIZE, 6, 's'),
97	typeinfo("unsigned long long", LLONG, ULLONG, LLONG_SIZE, 6, 'u'),
98#ifdef INT128_SIZE
99	typeinfo("__int128_t", INT128, UINT128, INT128_SIZE, 7, 's'),
100	typeinfo("__uint128_t", INT128, UINT128, INT128_SIZE, 7, 'u'),
101#endif
102	typeinfo("float", FLOAT, FLOAT, FLOAT_SIZE, 1, 'f'),
103	typeinfo("double", DOUBLE, DOUBLE, DOUBLE_SIZE, 2, 'f'),
104	typeinfo("long double", LDOUBLE, LDOUBLE, LDOUBLE_SIZE, 3, 'f'),
105#ifdef DEBUG
106	typeinfo("_Complex", NO_TSPEC, NO_TSPEC, 0, 0, ' '),
107#else
108	typeinfo(NULL, NO_TSPEC, NO_TSPEC, 0, 0, ' '),
109#endif
110	typeinfo("float _Complex", FCOMPLEX, FCOMPLEX,
111	    FLOAT_SIZE * 2, 1, 'c'),
112	typeinfo("double _Complex", DCOMPLEX, DCOMPLEX,
113	    DOUBLE_SIZE * 2, 2, 'c'),
114	typeinfo("long double _Complex", LCOMPLEX, LCOMPLEX,
115	    LDOUBLE_SIZE * 2, 3, 'c'),
116	typeinfo("void", VOID, VOID, 0, 0, ' '),
117	typeinfo("struct", STRUCT, STRUCT, 0, 0, ' '),
118	typeinfo("union", UNION, UNION, 0, 0, ' '),
119	// Will become more complicated in C23, which allows to choose the
120	// underlying type.
121	typeinfo("enum", ENUM, ENUM, ENUM_SIZE, INT_RANK, 's'),
122	// Same as 'unsigned long', which matches all supported platforms.
123	typeinfo("pointer", PTR, PTR, PTR_SIZE, 5, 'p'),
124	typeinfo("array", ARRAY, ARRAY, 0, 0, ' '),
125	typeinfo("function", FUNC, FUNC, 0, 0, ' '),
126};
127#undef typeinfo
128