xref: /netbsd-src/usr.bin/xlint/common/inittyp.c (revision d710132b4b8ce7f7cccaaf660cb16aa16b4077a0)
1 /*	$NetBSD: inittyp.c,v 1.5 2003/05/29 18:12:17 christos 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 #include <sys/cdefs.h>
35 #if defined(__RCSID) && !defined(lint)
36 __RCSID("$NetBSD: inittyp.c,v 1.5 2003/05/29 18:12:17 christos Exp $");
37 #endif
38 
39 #include <ctype.h>
40 #include <limits.h>
41 #include <stdlib.h>
42 
43 #include "lint.h"
44 
45 /* various type information */
46 ttab_t	ttab[NTSPEC];
47 
48 #if INTPTR_IS_LONG
49 #define INT_RSIZE	3
50 #else
51 #define INT_RSIZE	4
52 #endif
53 
54 void
55 inittyp(void)
56 {
57 	int	i;
58 	static const struct {
59 		tspec_t	it_tspec;
60 		ttab_t	it_ttab;
61 	} ittab[NTSPEC] = {
62 		{ SIGNED,   { 0, 0,
63 				      SIGNED, UNSIGN,
64 				      0, 0, 0, 0, 0, "signed" } },
65 		{ UNSIGN,   { 0, 0,
66 				      SIGNED, UNSIGN,
67 				      0, 0, 0, 0, 0, "unsigned" } },
68 		{ CHAR,	    { CHAR_SIZE, CHAR_BIT,
69 				      SCHAR, UCHAR,
70 				      1, 0, 0, 1, 1, "char" } },
71 		{ SCHAR,    { CHAR_SIZE, CHAR_BIT,
72 				      SCHAR, UCHAR,
73 				      1, 0, 0, 1, 1, "signed char" } },
74 		{ UCHAR,    { CHAR_SIZE, CHAR_BIT,
75 				      SCHAR, UCHAR,
76 				      1, 1, 0, 1, 1, "unsigned char" } },
77 		{ SHORT,    { SHORT_SIZE, 2 * CHAR_BIT,
78 				      SHORT, USHORT,
79 				      1, 0, 0, 1, 1, "short" } },
80 		{ USHORT,   { SHORT_SIZE, 2 * CHAR_BIT,
81 				      SHORT, USHORT,
82 				      1, 1, 0, 1, 1, "unsigned short" } },
83 		{ INT,      { INT_SIZE, INT_RSIZE * CHAR_BIT,
84 				      INT, UINT,
85 				      1, 0, 0, 1, 1, "int" } },
86 		{ UINT,     { INT_SIZE, INT_RSIZE * CHAR_BIT,
87 				      INT, UINT,
88 				      1, 1, 0, 1, 1, "unsigned int" } },
89 		{ LONG,     { LONG_SIZE, 4 * CHAR_BIT,
90 				      LONG, ULONG,
91 				      1, 0, 0, 1, 1, "long" } },
92 		{ ULONG,    { LONG_SIZE, 4 * CHAR_BIT,
93 				      LONG, ULONG,
94 				      1, 1, 0, 1, 1, "unsigned long" } },
95 		{ QUAD,     { QUAD_SIZE, 8 * CHAR_BIT,
96 				      QUAD, UQUAD,
97 				      1, 0, 0, 1, 1, "long long" } },
98 		{ UQUAD,    { QUAD_SIZE, 8 * CHAR_BIT,
99 				      QUAD, UQUAD,
100 				      1, 1, 0, 1, 1, "unsigned long long" } },
101 		{ FLOAT,    { FLOAT_SIZE, 4 * CHAR_BIT,
102 				      FLOAT, FLOAT,
103 				      0, 0, 1, 1, 1, "float" } },
104 		{ DOUBLE,   { DOUBLE_SIZE, 8 * CHAR_BIT,
105 				      DOUBLE, DOUBLE,
106 				      0, 0, 1, 1, 1, "double" } },
107 		{ LDOUBLE,  { LDOUBLE_SIZE, 10 * CHAR_BIT,
108 				      LDOUBLE, LDOUBLE,
109 				      0, 0, 1, 1, 1, "long double" } },
110 		{ VOID,     { -1, -1,
111 				      VOID, VOID,
112 				      0, 0, 0, 0, 0, "void" } },
113 		{ STRUCT,   { -1, -1,
114 				      STRUCT, STRUCT,
115 				      0, 0, 0, 0, 0, "struct" } },
116 		{ UNION,    { -1, -1,
117 				      UNION, UNION,
118 				      0, 0, 0, 0, 0, "union" } },
119 		{ ENUM,     { ENUM_SIZE, 3 * CHAR_BIT,
120 				      ENUM, ENUM,
121 				      1, 0, 0, 1, 1, "enum" } },
122 		{ PTR,      { PTR_SIZE, 4 * CHAR_BIT,
123 				      PTR, PTR,
124 				      0, 1, 0, 0, 1, "pointer" } },
125 		{ ARRAY,    { -1, -1,
126 				      ARRAY, ARRAY,
127 				      0, 0, 0, 0, 0, "array" } },
128 		{ FUNC,     { -1, -1,
129 				      FUNC, FUNC,
130 				      0, 0, 0, 0, 0, "function" } },
131 	};
132 
133 	for (i = 0; i < sizeof (ittab) / sizeof (ittab[0]); i++)
134 		STRUCT_ASSIGN(ttab[ittab[i].it_tspec], ittab[i].it_ttab);
135 	if (!pflag) {
136 		for (i = 0; i < NTSPEC; i++)
137 			ttab[i].tt_psz = ttab[i].tt_sz;
138 	}
139 }
140