1158421Swollman/*	$NetBSD: inittyp.c,v 1.42 2024/01/20 10:25:57 rillig Exp $	*/
2153761Swollman
3153761Swollman/*
42742Swollman * Copyright (c) 1994, 1995 Jochen Pohl
586464Swollman * All Rights Reserved.
62742Swollman *
72742Swollman * Redistribution and use in source and binary forms, with or without
82742Swollman * modification, are permitted provided that the following conditions
92742Swollman * are met:
102742Swollman * 1. Redistributions of source code must retain the above copyright
112742Swollman *    notice, this list of conditions and the following disclaimer.
1286222Swollman * 2. Redistributions in binary form must reproduce the above copyright
1386222Swollman *    notice, this list of conditions and the following disclaimer in the
142742Swollman *    documentation and/or other materials provided with the distribution.
1558787Sru * 3. All advertising materials mentioning features or use of this software
162742Swollman *    must display the following acknowledgement:
172742Swollman *	This product includes software developed by Jochen Pohl for
182742Swollman *	The NetBSD Project.
192742Swollman * 4. The name of the author may not be used to endorse or promote products
202742Swollman *    derived from this software without specific prior written permission.
212742Swollman *
2258787Sru * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
2358787Sru * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
2458787Sru * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
252742Swollman * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
262742Swollman * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
279908Swollman * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
282742Swollman * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
2930711Swollman * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
302742Swollman * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
319908Swollman * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
322742Swollman */
3358787Sru
3458787Sru#if HAVE_NBTOOL_CONFIG_H
3514343Swollman#include "nbtool_config.h"
3614343Swollman#endif
3714343Swollman
3814343Swollman#include <sys/cdefs.h>
3914343Swollman#if defined(__RCSID)
402742Swollman__RCSID("$NetBSD: inittyp.c,v 1.42 2024/01/20 10:25:57 rillig Exp $");
419908Swollman#endif
4220094Swollman
43149514Swollman#if IS_LINT1
4420094Swollman#include "lint1.h"
4520094Swollman#else
4620094Swollman#include "lint2.h"
4720094Swollman#endif
4820094Swollman
4920094Swollman#define INT_RANK	(/*CONSTCOND*/INTPTR_TSPEC == LONG ? 4 : 5)
5020094Swollman
5120094Swollman#if IS_LINT1
5220094Swollman#define typeinfo(name, signed_type, unsigned_type, size_in_bits, rv, c) \
5320094Swollman	{ /*CONSTCOND*/ \
5420094Swollman		size_in_bits, \
5558787Sru		(c) == 'u' || (c) == 's' || (c) == 'p' ? RK_INTEGER : \
5658787Sru		    (c) == 'f' ? RK_FLOATING : \
5721217Swollman		    (c) == 'c' ? RK_COMPLEX : \
5821217Swollman		    RK_NONE, \
5958787Sru		rv, \
6058787Sru		signed_type, unsigned_type, \
612742Swollman		(c) == 's' || (c) == 'u', \
6258787Sru		(c) == 'u' || (c) == 'p', \
6321217Swollman		(c) == 'f' || (c) == 'c', \
6420094Swollman		(c) == 's' || (c) == 'u' || (c) == 'f' || \
6558787Sru		    (c) == 'c', \
6658787Sru		(c) == 's' || (c) == 'u' || (c) == 'f' || \
6720094Swollman		    (c) == 'c' || (c) == 'p', \
682742Swollman		(c) == 'c', \
699908Swollman		name, \
702742Swollman	}
7114343Swollman#else
7214343Swollman#define typeinfo(name, signed_type, unsigned_type, size_in_bits, rank, c) \
7314343Swollman	{ /*CONSTCOND*/ \
7414343Swollman		signed_type, unsigned_type, \
7514343Swollman		(c) == 's' || (c) == 'u', \
7614343Swollman		name, \
7764499Swollman	}
7864499Swollman#endif
7964499Swollman
8064499Swollman/* various type information */
8164499Swollmanttab_t ttab[NTSPEC] = {
82149514Swollman	typeinfo(NULL, NO_TSPEC, NO_TSPEC, 0, 0, ' '),
83149514Swollman	typeinfo("signed", SIGNED, UNSIGN, 0, 0, ' '),
84149514Swollman	typeinfo("unsigned", SIGNED, UNSIGN, 0, 0, ' '),
852742Swollman	typeinfo("_Bool", BOOL, BOOL, CHAR_SIZE, 1, 'u'),
862742Swollman	typeinfo("char", SCHAR, UCHAR, CHAR_SIZE, 2,
872742Swollman	    TARG_CHAR_MIN == 0 ? 'u' : 's'),
8858787Sru	typeinfo("signed char", SCHAR, UCHAR, CHAR_SIZE, 2, 's'),
892742Swollman	typeinfo("unsigned char", SCHAR, UCHAR, CHAR_SIZE, 2, 'u'),
902742Swollman	typeinfo("short", SHORT, USHORT, SHORT_SIZE, 3, 's'),
919908Swollman	typeinfo("unsigned short", SHORT, USHORT, SHORT_SIZE, 3, 'u'),
92149514Swollman	typeinfo("int", INT, UINT, INT_SIZE, INT_RANK, 's'),
93149514Swollman	typeinfo("unsigned int", INT, UINT, INT_SIZE, INT_RANK, 'u'),
94149514Swollman	typeinfo("long", LONG, ULONG, LONG_SIZE, 5, 's'),
95149514Swollman	typeinfo("unsigned long", LONG, ULONG, LONG_SIZE, 5, 'u'),
96149514Swollman	typeinfo("long long", LLONG, ULLONG, LLONG_SIZE, 6, 's'),
972742Swollman	typeinfo("unsigned long long", LLONG, ULLONG, LLONG_SIZE, 6, 'u'),
9858787Sru#ifdef INT128_SIZE
9958787Sru	typeinfo("__int128_t", INT128, UINT128, INT128_SIZE, 7, 's'),
10014343Swollman	typeinfo("__uint128_t", INT128, UINT128, INT128_SIZE, 7, 'u'),
10114343Swollman#endif
10258787Sru	typeinfo("float", FLOAT, FLOAT, FLOAT_SIZE, 1, 'f'),
10314343Swollman	typeinfo("double", DOUBLE, DOUBLE, DOUBLE_SIZE, 2, 'f'),
10414343Swollman	typeinfo("long double", LDOUBLE, LDOUBLE, LDOUBLE_SIZE, 3, 'f'),
10514343Swollman#ifdef DEBUG
10658787Sru	typeinfo("_Complex", NO_TSPEC, NO_TSPEC, 0, 0, ' '),
10714343Swollman#else
10858787Sru	typeinfo(NULL, NO_TSPEC, NO_TSPEC, 0, 0, ' '),
10958787Sru#endif
11058787Sru	typeinfo("float _Complex", FCOMPLEX, FCOMPLEX,
111149514Swollman	    FLOAT_SIZE * 2, 1, 'c'),
11258787Sru	typeinfo("double _Complex", DCOMPLEX, DCOMPLEX,
11358787Sru	    DOUBLE_SIZE * 2, 2, 'c'),
114149514Swollman	typeinfo("long double _Complex", LCOMPLEX, LCOMPLEX,
115149514Swollman	    LDOUBLE_SIZE * 2, 3, 'c'),
1162742Swollman	typeinfo("void", VOID, VOID, 0, 0, ' '),
1172742Swollman	typeinfo("struct", STRUCT, STRUCT, 0, 0, ' '),
11858787Sru	typeinfo("union", UNION, UNION, 0, 0, ' '),
11958787Sru	// Will become more complicated in C23, which allows to choose the
12058787Sru	// underlying type.
1212742Swollman	typeinfo("enum", ENUM, ENUM, ENUM_SIZE, INT_RANK, 's'),
122149514Swollman	// Same as 'unsigned long', which matches all supported platforms.
123149514Swollman	typeinfo("pointer", PTR, PTR, PTR_SIZE, 5, 'p'),
124149514Swollman	typeinfo("array", ARRAY, ARRAY, 0, 0, ' '),
125149514Swollman	typeinfo("function", FUNC, FUNC, 0, 0, ' '),
126149514Swollman};
1272742Swollman#undef typeinfo
1289908Swollman