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