1 /* $NetBSD: emit2.c,v 1.8 2002/01/21 19:49:52 tv Exp $ */
4 * Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved.
5 * Copyright (c) 1994, 1995 Jochen Pohl
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. All advertising materials mentioning features or use of this software
17 * must display the following acknowledgement:
18 * This product includes software developed by Jochen Pohl for
20 * 4. The name of the author may not be used to endorse or promote products
21 * derived from this software without specific prior written permission.
23 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
24 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
25 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
26 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
27 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
28 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
32 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35 #include <sys/cdefs.h>
36 #if defined(__RCSID) && !defined(lint)
37 __RCSID("$NetBSD: emit2.c,v 1.8 2002/01/21 19:49:52 tv Exp $");
39 __FBSDID("$FreeBSD$");
45 static void outtype(type_t *);
46 static void outdef(hte_t *, sym_t *);
47 static void dumpname(hte_t *);
48 static void outfiles(void);
51 * Write type into the output buffer.
61 if ((ts = tp->t_tspec) == INT && tp->t_isenum)
64 case CHAR: t = 'C'; s = '\0'; break;
65 case SCHAR: t = 'C'; s = 's'; break;
66 case UCHAR: t = 'C'; s = 'u'; break;
67 case SHORT: t = 'S'; s = '\0'; break;
68 case USHORT: t = 'S'; s = 'u'; break;
69 case INT: t = 'I'; s = '\0'; break;
70 case UINT: t = 'I'; s = 'u'; break;
71 case LONG: t = 'L'; s = '\0'; break;
72 case ULONG: t = 'L'; s = 'u'; break;
73 case QUAD: t = 'Q'; s = '\0'; break;
74 case UQUAD: t = 'Q'; s = 'u'; break;
75 case FLOAT: t = 'D'; s = 's'; break;
76 case DOUBLE: t = 'D'; s = '\0'; break;
77 case LDOUBLE: t = 'D'; s = 'l'; break;
78 case VOID: t = 'V'; s = '\0'; break;
79 case PTR: t = 'P'; s = '\0'; break;
80 case ARRAY: t = 'A'; s = '\0'; break;
81 case ENUM: t = 'T'; s = 'e'; break;
82 case STRUCT: t = 'T'; s = 's'; break;
83 case UNION: t = 'T'; s = 'u'; break;
85 if (tp->t_args != NULL && !tp->t_proto) {
93 errx(1, "internal error: outtype() 1");
104 } else if (ts == ENUM || ts == STRUCT || ts == UNION) {
107 outname(tp->t_tag->h_name);
108 } else if (tp->t_istynam) {
110 outname(tp->t_tynam->h_name);
111 } else if (tp->t_isuniqpos) {
113 outint(tp->t_uniqpos.p_line);
115 outint(tp->t_uniqpos.p_file);
117 outint(tp->t_uniqpos.p_uniq);
119 errx(1, "internal error: outtype() 2");
120 } else if (ts == FUNC && tp->t_args != NULL) {
122 for (ap = tp->t_args; *ap != NULL; ap++)
127 for (ap = tp->t_args; *ap != NULL; ap++)
137 * Write a definition.
140 outdef(hte_t *hte, sym_t *sym)
143 /* reset output buffer */
146 /* line number in C source file */
149 /* this is a definition */
152 /* index of file where symbol was defined and line number of def. */
159 outchar('v'); /* varargs */
163 outchar('S'); /* scanflike */
164 outint(sym->s_nscfl);
167 outchar('P'); /* printflike */
168 outint(sym->s_nprfl);
170 /* definition or tentative definition */
171 outchar(sym->s_def == DEF ? 'd' : 't');
172 if (TP(sym->s_type)->t_tspec == FUNC) {
174 outchar('r'); /* fkt. has return value */
176 outchar('o'); /* old style definition */
178 outchar('u'); /* used (no warning if not used) */
181 outname(hte->h_name);
184 outtype(TP(sym->s_type));
188 * Write the first definition of a name into the lint library.
195 /* static and undefined symbols are not written */
196 if (hte->h_static || !hte->h_def)
200 * If there is a definition, write it. Otherwise write a tentative
201 * definition. This is necessary because more than one tentative
202 * definition is allowed (except with sflag).
205 for (sym = hte->h_syms; sym != NULL; sym = sym->s_nxt) {
206 if (sym->s_def == DEF) {
210 if (sym->s_def == TDEF && def == NULL)
214 errx(1, "internal error: dumpname() %s", hte->h_name);
220 * Write a new lint library.
223 outlib(const char *name)
225 /* Open of output file and initialisation of the output buffer */
228 /* write name of lint library */
231 /* name of lint lib has index 0 */
238 * print the names of all files references by unnamed
239 * struct/union/enum declarations.
243 /* write all definitions with external linkage */
246 /* close the output */
251 * Write out the name of a file referenced by a type.
255 struct outflist *ofl_next;
257 static struct outflist *outflist;
260 addoutfile(short num)
262 struct outflist *ofl, **pofl;
267 i = 1; /* library is 0 */
269 while (ofl != NULL) {
270 if (ofl->ofl_num == num)
273 pofl = &ofl->ofl_next;
279 ofl = *pofl = xmalloc(sizeof (struct outflist));
281 ofl->ofl_next = NULL;
289 struct outflist *ofl;
292 for (ofl = outflist, i = 1; ofl != NULL; ofl = ofl->ofl_next, i++) {
293 /* reset output buffer */
298 outstrg(fnames[ofl->ofl_num]);