Home | History | Annotate | Line # | Download | only in common
inittyp.c revision 1.25
      1  1.25    rillig /*	$NetBSD: inittyp.c,v 1.25 2021/08/22 14:50:06 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.4        tv #if defined(__RCSID) && !defined(lint)
     40  1.25    rillig __RCSID("$NetBSD: inittyp.c,v 1.25 2021/08/22 14:50:06 rillig Exp $");
     41   1.1   thorpej #endif
     42   1.1   thorpej 
     43   1.1   thorpej #include <limits.h>
     44   1.2        tv #include <stdlib.h>
     45   1.1   thorpej 
     46  1.25    rillig #if defined(IS_LINT1)
     47  1.25    rillig #include "lint1.h"
     48  1.25    rillig #else
     49  1.25    rillig #include "lint2.h"
     50  1.25    rillig #endif
     51   1.1   thorpej 
     52   1.1   thorpej /* various type information */
     53   1.1   thorpej ttab_t	ttab[NTSPEC];
     54   1.1   thorpej 
     55  1.19    rillig #define INT_RSIZE	(/*CONSTCOND*/INTPTR_TSPEC == LONG ? 3 : 4)
     56   1.5  christos 
     57   1.1   thorpej void
     58   1.1   thorpej inittyp(void)
     59   1.1   thorpej {
     60  1.11  christos 	size_t	i;
     61   1.1   thorpej 	static const struct {
     62   1.1   thorpej 		tspec_t	it_tspec;
     63   1.1   thorpej 		ttab_t	it_ttab;
     64   1.1   thorpej 	} ittab[NTSPEC] = {
     65  1.21    rillig #define typeinfo( \
     66  1.21    rillig 	    tspec, signed_type, unsigned_type, \
     67  1.21    rillig 	    size_in_bits, portable_size_in_bits, \
     68  1.21    rillig 	    in, un, fl, ar, sc, co, name) \
     69  1.21    rillig 	{ \
     70  1.21    rillig 	    tspec, { \
     71  1.21    rillig 		size_in_bits, portable_size_in_bits, \
     72  1.21    rillig 		signed_type, unsigned_type, \
     73  1.21    rillig 		(in) > 0, (un) > 0, (fl) > 0, (ar) > 0, (sc) > 0, (co) > 0, \
     74  1.21    rillig 		name, \
     75  1.21    rillig 	    } \
     76  1.21    rillig 	}
     77  1.21    rillig 		typeinfo(SIGNED, SIGNED, UNSIGN, 0, 0,
     78  1.21    rillig 		    0, 0, 0, 0, 0, 0, "signed"),
     79  1.21    rillig 		typeinfo(UNSIGN, SIGNED, UNSIGN, 0, 0,
     80  1.21    rillig 		    0, 0, 0, 0, 0, 0, "unsigned"),
     81  1.21    rillig 		typeinfo(BOOL, BOOL, BOOL, CHAR_SIZE, 1,
     82  1.21    rillig 		    1, 1, 0, 1, 1, 0, "_Bool"),
     83  1.21    rillig 		typeinfo(CHAR, SCHAR, UCHAR, CHAR_SIZE, 8,
     84  1.23    rillig 		    1, /*CONSTCOND*/ TARG_CHAR_MIN == 0 ? 1 : 0,
     85  1.23    rillig 		    /* */ 0, 1, 1, 0, "char"),
     86  1.21    rillig 		typeinfo(SCHAR, SCHAR, UCHAR, CHAR_SIZE, 8,
     87  1.21    rillig 		    1, 0, 0, 1, 1, 0, "signed char"),
     88  1.21    rillig 		typeinfo(UCHAR, SCHAR, UCHAR, CHAR_SIZE, 8,
     89  1.21    rillig 		    1, 1, 0, 1, 1, 0, "unsigned char"),
     90  1.21    rillig 		typeinfo(SHORT, SHORT, USHORT, SHORT_SIZE, 16,
     91  1.21    rillig 		    1, 0, 0, 1, 1, 0, "short"),
     92  1.21    rillig 		typeinfo(USHORT, SHORT, USHORT, SHORT_SIZE, 16,
     93  1.21    rillig 		    1, 1, 0, 1, 1, 0, "unsigned short"),
     94  1.21    rillig 		typeinfo(INT, INT, UINT, INT_SIZE, INT_RSIZE * 8,
     95  1.21    rillig 		    1, 0, 0, 1, 1, 0, "int"),
     96  1.21    rillig 		typeinfo(UINT, INT, UINT, INT_SIZE, INT_RSIZE * 8,
     97  1.21    rillig 		    1, 1, 0, 1, 1, 0, "unsigned int"),
     98  1.21    rillig 		typeinfo(LONG, LONG, ULONG, LONG_SIZE, 32,
     99  1.21    rillig 		    1, 0, 0, 1, 1, 0, "long"),
    100  1.21    rillig 		typeinfo(ULONG, LONG, ULONG, LONG_SIZE, 32,
    101  1.21    rillig 		    1, 1, 0, 1, 1, 0, "unsigned long"),
    102  1.21    rillig 		typeinfo(QUAD, QUAD, UQUAD, QUAD_SIZE, 64,
    103  1.21    rillig 		    1, 0, 0, 1, 1, 0, "long long"),
    104  1.21    rillig 		typeinfo(UQUAD, QUAD, UQUAD, QUAD_SIZE, 64,
    105  1.21    rillig 		    1, 1, 0, 1, 1, 0, "unsigned long long"),
    106  1.12  christos #ifdef INT128_SIZE
    107  1.21    rillig 		typeinfo(INT128, INT128, UINT128, INT128_SIZE, 128,
    108  1.21    rillig 		    1, 0, 0, 1, 1, 0, "__int128_t"),
    109  1.21    rillig 		typeinfo(UINT128, INT128, UINT128, INT128_SIZE, 128,
    110  1.21    rillig 		    1, 1, 0, 1, 1, 0, "__uint128_t"),
    111  1.12  christos #endif
    112  1.21    rillig 		typeinfo(FLOAT, FLOAT, FLOAT, FLOAT_SIZE, 32,
    113  1.21    rillig 		    0, 0, 1, 1, 1, 0, "float"),
    114  1.21    rillig 		typeinfo(DOUBLE, DOUBLE, DOUBLE, DOUBLE_SIZE, 64,
    115  1.21    rillig 		    0, 0, 1, 1, 1, 0, "double"),
    116  1.21    rillig 		typeinfo(LDOUBLE, LDOUBLE, LDOUBLE, LDOUBLE_SIZE, 80,
    117  1.21    rillig 		    0, 0, 1, 1, 1, 0, "long double"),
    118  1.21    rillig 		typeinfo(FCOMPLEX, FCOMPLEX, FCOMPLEX, FLOAT_SIZE * 2, 32 * 2,
    119  1.21    rillig 		    0, 0, 1, 1, 1, 1, "float _Complex"),
    120  1.21    rillig 		typeinfo(DCOMPLEX, DCOMPLEX, DCOMPLEX, DOUBLE_SIZE * 2, 64 * 2,
    121  1.21    rillig 		    0, 0, 1, 1, 1, 1, "double _Complex"),
    122  1.21    rillig 		typeinfo(LCOMPLEX, LCOMPLEX, LCOMPLEX,
    123  1.24    rillig 		    LDOUBLE_SIZE * 2, 80 * 2,
    124  1.21    rillig 		    0, 0, 1, 1, 1, 1, "long double _Complex"),
    125  1.21    rillig 		typeinfo(VOID, VOID, VOID, -1, -1,
    126  1.21    rillig 		    0, 0, 0, 0, 0, 0, "void"),
    127  1.21    rillig 		typeinfo(STRUCT, STRUCT, STRUCT, -1, -1,
    128  1.21    rillig 		    0, 0, 0, 0, 0, 0, "struct"),
    129  1.21    rillig 		typeinfo(UNION, UNION, UNION, -1, -1,
    130  1.21    rillig 		    0, 0, 0, 0, 0, 0, "union"),
    131  1.21    rillig 		typeinfo(ENUM, ENUM, ENUM, ENUM_SIZE, 24,
    132  1.21    rillig 		    1, 0, 0, 1, 1, 0, "enum"),
    133  1.21    rillig 		typeinfo(PTR, PTR, PTR, PTR_SIZE, 32,
    134  1.21    rillig 		    0, 1, 0, 0, 1, 0, "pointer"),
    135  1.21    rillig 		typeinfo(ARRAY, ARRAY, ARRAY, -1, -1,
    136  1.21    rillig 		    0, 0, 0, 0, 0, 0, "array"),
    137  1.21    rillig 		typeinfo(FUNC, FUNC, FUNC, -1, -1,
    138  1.21    rillig 		    0, 0, 0, 0, 0, 0, "function"),
    139  1.21    rillig #undef typeinfo
    140   1.1   thorpej 	};
    141   1.1   thorpej 
    142  1.22    rillig 	for (i = 0; i < sizeof(ittab) / sizeof(ittab[0]); i++)
    143  1.13    rillig 		ttab[ittab[i].it_tspec] = ittab[i].it_ttab;
    144   1.1   thorpej 	if (!pflag) {
    145   1.1   thorpej 		for (i = 0; i < NTSPEC; i++)
    146  1.20    rillig 			ttab[i].tt_portable_size_in_bits =
    147  1.20    rillig 			    ttab[i].tt_size_in_bits;
    148   1.1   thorpej 	}
    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