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